Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add auth strategy to the user profile page #1057

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 42 additions & 30 deletions cypress/integration/users-login.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ describe("Users Login", () => {

cy.get("#usernameInput-ldap").type(username).should("have.value", username);

cy.get("#passwordInput-ldap").type("invalid").should("have.value", "invalid");
cy.get("#passwordInput-ldap")
.type("invalid")
.should("have.value", "invalid");

cy.get("button[type=submit]").click();

Expand All @@ -44,7 +46,7 @@ describe("Users Login", () => {
cy.contains(
"Unable to connect to the authentication service. Please try again later or contact website maintainer."
);
}
}
});

cy.get('mat-tab-group [role="tab"]').contains("Local").click();
Expand All @@ -53,7 +55,7 @@ describe("Users Login", () => {

cy.get("#passwordInput").type("invalid").should("have.value", "invalid");

cy.get('.mat-snack-bar-container').should('not.exist');
cy.get(".mat-snack-bar-container").should("not.exist");

cy.get("button[type=submit]").click();

Expand Down Expand Up @@ -101,73 +103,83 @@ describe("Users Login", () => {
cy.url().should("include", "/login");
});

it("logs in with admin account should be able to see all the content properly from user information", ()=>{
it("logs in with admin account should be able to see all the content properly from user information", () => {
cy.visit("/login");

cy.get('mat-tab-group [role="tab"]').contains("Local").click();

cy.get("#usernameInput").type(username).should("have.value", username);

cy.get("#passwordInput").type(password).should("have.value", password);

cy.get("button[type=submit]").click();

cy.get(".user-button").should("contain.text", username).click();

cy.get("[data-cy=setting-button]").click();

cy.get("[data-cy=user-name]").should("contain.text", username);

cy.get("[data-cy=user-email]").invoke('text').should("not.be.empty");
cy.get("[data-cy=user-email]").invoke("text").should("not.be.empty");

cy.get("[data-cy=user-id]").invoke('text').should("not.be.empty");
cy.get("[data-cy=user-id]").invoke("text").should("not.be.empty");

cy.get("[data-cy=user-accessGroup]").invoke('text').should("not.be.empty");
cy.get("[data-cy=user-accessGroup]").invoke("text").should("not.be.empty");

cy.get(".copy-button").click();

cy.get("[data-cy=user-token]").invoke('text').then((token) => {
cy.window().then((win) => {
win.navigator.clipboard.readText().then((clipboardText) => {
expect(clipboardText).to.equal(token);
cy.get("[data-cy=user-token]")
.invoke("text")
.then((token) => {
cy.window().then((win) => {
win.navigator.clipboard.readText().then((clipboardText) => {
expect(clipboardText).to.equal(token);
});
});
});
});

})

it("logs in with normal user account should be able to see all the content properly from user information", ()=>{
cy.get("[data-cy=auth-strategy]").contains("local");
});

it("logs in with normal user account should be able to see all the content properly from user information", () => {
cy.visit("/login");

cy.get('mat-tab-group [role="tab"]').contains("Local").click();

cy.get("#usernameInput").type(guestUsername).should("have.value", guestUsername);
cy.get("#usernameInput")
.type(guestUsername)
.should("have.value", guestUsername);

cy.get("#passwordInput")
.type(guestPassword)
.should("have.value", guestPassword);

cy.get("#passwordInput").type(guestPassword).should("have.value", guestPassword);

cy.get("button[type=submit]").click();

cy.get(".user-button").should("contain.text", guestUsername).click();

cy.get("[data-cy=setting-button]").click();

cy.get("[data-cy=user-name]").should("contain.text", guestUsername);

cy.get("[data-cy=user-email]").invoke('text').should("not.be.empty");
cy.get("[data-cy=user-email]").invoke("text").should("not.be.empty");

cy.get("[data-cy=user-id]").invoke('text').should("not.be.empty");
cy.get("[data-cy=user-id]").invoke("text").should("not.be.empty");

cy.get("[data-cy=user-accessGroup]").invoke('text').should("not.be.empty");
cy.get("[data-cy=user-accessGroup]").invoke("text").should("not.be.empty");

cy.get(".copy-button").click();

cy.get("[data-cy=user-token]").invoke('text').then((token) => {
cy.window().then((win) => {
win.navigator.clipboard.readText().then((clipboardText) => {
expect(clipboardText).to.equal(token);
cy.get("[data-cy=user-token]")
.invoke("text")
.then((token) => {
cy.window().then((win) => {
win.navigator.clipboard.readText().then((clipboardText) => {
expect(clipboardText).to.equal(token);
});
});
});
});
})

cy.get("[data-cy=auth-strategy]").contains("local");
});
});
255 changes: 128 additions & 127 deletions src/app/shared/sdk/models/User.ts
Original file line number Diff line number Diff line change
@@ -1,127 +1,128 @@
/* eslint-disable */
import {
UserSetting,
UserIdentity,
UserCredential
} from '../index';

declare var Object: any;
export interface UserInterface {
"realm"?: string;
"username"?: string;
"email": string;
"emailVerified"?: boolean;
"id"?: any;
"password"?: string;
accessTokens?: any[];
settings?: UserSetting;
identities?: UserIdentity[];
credentials?: UserCredential[];
}

export class User implements UserInterface {
"realm": string;
"username": string;
"email": string;
"emailVerified": boolean;
"id": any;
"password": string;
accessTokens: any[];
settings: UserSetting;
identities: UserIdentity[];
credentials: UserCredential[];
constructor(data?: UserInterface) {
Object.assign(this, data);
}
/**
* The name of the model represented by this $resource,
* i.e. `User`.
*/
public static getModelName() {
return "User";
}
/**
* @method factory
* @author Jonathan Casarrubias
* @license MIT
* This method creates an instance of User for dynamic purposes.
**/
public static factory(data: UserInterface): User{
return new User(data);
}
/**
* @method getModelDefinition
* @author Julien Ledun
* @license MIT
* This method returns an object that represents some of the model
* definitions.
**/
public static getModelDefinition() {
return {
name: 'User',
plural: 'Users',
path: 'Users',
idName: 'id',
properties: {
"realm": {
name: 'realm',
type: 'string'
},
"username": {
name: 'username',
type: 'string'
},
"email": {
name: 'email',
type: 'string'
},
"emailVerified": {
name: 'emailVerified',
type: 'boolean'
},
"id": {
name: 'id',
type: 'any'
},
"password": {
name: 'password',
type: 'string'
},
},
relations: {
accessTokens: {
name: 'accessTokens',
type: 'any[]',
model: '',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'userId'
},
settings: {
name: 'settings',
type: 'UserSetting',
model: 'UserSetting',
relationType: 'hasOne',
keyFrom: 'id',
keyTo: 'userId'
},
identities: {
name: 'identities',
type: 'UserIdentity[]',
model: 'UserIdentity',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'userId'
},
credentials: {
name: 'credentials',
type: 'UserCredential[]',
model: 'UserCredential',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'userId'
},
}
}
}
}
/* eslint-disable */
import {
UserSetting,
UserIdentity,
UserCredential
} from '../index';

declare var Object: any;
export interface UserInterface {
"realm"?: string;
"username"?: string;
"email": string;
"emailVerified"?: boolean;
"id"?: any;
"password"?: string;
accessTokens?: any[];
settings?: UserSetting;
identities?: UserIdentity[];
credentials?: UserCredential[];
}

export class User implements UserInterface {
"realm": string;
"username": string;
"email": string;
"emailVerified": boolean;
"id": any;
"password": string;
"authStrategy"?: string;
accessTokens: any[];
settings: UserSetting;
identities: UserIdentity[];
credentials: UserCredential[];
constructor(data?: UserInterface) {
Object.assign(this, data);
}
/**
* The name of the model represented by this $resource,
* i.e. `User`.
*/
public static getModelName() {
return "User";
}
/**
* @method factory
* @author Jonathan Casarrubias
* @license MIT
* This method creates an instance of User for dynamic purposes.
**/
public static factory(data: UserInterface): User{
return new User(data);
}
/**
* @method getModelDefinition
* @author Julien Ledun
* @license MIT
* This method returns an object that represents some of the model
* definitions.
**/
public static getModelDefinition() {
return {
name: 'User',
plural: 'Users',
path: 'Users',
idName: 'id',
properties: {
"realm": {
name: 'realm',
type: 'string'
},
"username": {
name: 'username',
type: 'string'
},
"email": {
name: 'email',
type: 'string'
},
"emailVerified": {
name: 'emailVerified',
type: 'boolean'
},
"id": {
name: 'id',
type: 'any'
},
"password": {
name: 'password',
type: 'string'
},
},
relations: {
accessTokens: {
name: 'accessTokens',
type: 'any[]',
model: '',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'userId'
},
settings: {
name: 'settings',
type: 'UserSetting',
model: 'UserSetting',
relationType: 'hasOne',
keyFrom: 'id',
keyTo: 'userId'
},
identities: {
name: 'identities',
type: 'UserIdentity[]',
model: 'UserIdentity',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'userId'
},
credentials: {
name: 'credentials',
type: 'UserCredential[]',
model: 'UserCredential',
relationType: 'hasMany',
keyFrom: 'id',
keyTo: 'userId'
},
}
}
}
}
Loading