Skip to content

Commit

Permalink
Enhancement proposal/user auth uncheck default stduser (#17)
Browse files Browse the repository at this point in the history
* Uncheck "Standard User" role marked by default when creating an user.
* Create logout function
* Adding unit tests
Signed-off-by: Manuel Martín <[email protected]>
  • Loading branch information
mmartin24 authored May 14, 2024
1 parent 51155d9 commit fa01d08
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
38 changes: 38 additions & 0 deletions cypress/e2e/unit-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,44 @@ describe('Cypress Library e2e tests', () => {
cypressLib.deleteUser('mytestuserwithoutrole');
});

it('Check createUser/deleteUser function with "User-Base" role and uncheck "Standard User"', () => {
cy.login();
cypressLib.burgerMenuToggle();
cypressLib.createUser('mytestuserwithrole', 'mytestpassword', 'User-Base', true);
// Log out with admin role and login with "User-Base" role to check
// "User-base" does not have these options available
cypressLib.logout();
cy.login('mytestuserwithrole', 'mytestpassword');
cypressLib.burgerMenuToggle();
cy.contains('Continue Delivery').should('not.exist');
cy.contains('Cluster Management').should('not.exist');
// Log out as user and login back as admin to delete created user
cypressLib.logout();
cy.login();
cypressLib.burgerMenuToggle();
cypressLib.deleteUser('mytestuserwithrole');
});

it('Check createUser/deleteUser function with "Standard User" role', () => {
cy.login();
cypressLib.burgerMenuToggle();
// Given that Standard User is checked by default, no need to add role
cypressLib.createUser('mytestuserwithrole', 'mytestpassword');
// Log out with admin role and login with "Standard User" role to check
// "Standard User" does not have some options available and has some others
cypressLib.logout();
cy.login('mytestuserwithrole', 'mytestpassword');
cypressLib.burgerMenuToggle();
cy.contains('Continue Delivery').should('not.exist');
cy.contains('Extensions').should('not.exist');
cy.contains('Cluster Management').should('exist');
// Log out as user and login back as admin to delete created user
cypressLib.logout();
cy.login();
cypressLib.burgerMenuToggle();
cypressLib.deleteUser('mytestuserwithrole');
});

it('Check enableExtensionSupport function with rancher repo activated', () => {
cy.login();
cypressLib.burgerMenuToggle();
Expand Down
20 changes: 18 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,10 @@ export function confirmDelete() {
* @param username : Name of the user
* @param password : Password of the user
* @param role : Role of the user
* @param uncheckStandardUser : Uncheck "Standard User" marked by default
*/
// TODO: Add the possibility to add multiple roles
export function createUser(username, password, role) {
export function createUser(username, password, role, uncheckStandardUser=false) {
cy.contains('Users & Authentication')
.click();
cy.contains('.title', 'Users')
Expand All @@ -145,7 +146,12 @@ export function createUser(username, password, role) {
cy.typeValue('Confirm Password', password);
if (role) {
cy.contains(role)
.click();
.click();
}
if (uncheckStandardUser === true) {
cy.get('span[aria-label="Standard User"]').scrollIntoView();
cy.contains('Standard User').should('exist');
cy.get('span[aria-label="Standard User"]').click();
}
cy.getBySel('form-save')
.contains('Create')
Expand Down Expand Up @@ -173,6 +179,16 @@ export function deleteUser(username) {
cy.contains(username).should('not.exist');
}

/**
* Logout with the current user
* @remarks : Useful when testing role changes
*/
export function logout() {
cy.get('.user.user-menu').click({ force: true });
cy.contains('Log Out').should('be.visible').click({ force: true });
cy.contains('You have been logged out.').should('be.visible');
}

/**
* Enable the extension support
* @remarks : Disable the Rancher Repo if you provide your own repo
Expand Down

0 comments on commit fa01d08

Please sign in to comment.