Skip to content

Commit

Permalink
Additional user retention settings tests
Browse files Browse the repository at this point in the history
  • Loading branch information
izaac committed Aug 27, 2024
1 parent 9d03336 commit a60802e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 7 deletions.
12 changes: 12 additions & 0 deletions cypress/e2e/po/pages/users-and-auth/users.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ export default class UsersPo extends ClusterPage {
userRetentionLink() {
return new LinkPo('[data-testid="router-link-user-retention"]', this.self());
}

accountStatusDisabled(username: string) {
return this.list().resourceTable().sortableTable().rowWithPartialName(username)
.self()
.find('.icon-color-red', { timeout: 90000 });
}

accountStatusEnabled(username) {
return this.list().resourceTable().sortableTable().rowWithPartialName(username)
.self()
.find('.icon-color-green', { timeout: 90000 });
}
}
111 changes: 106 additions & 5 deletions cypress/e2e/tests/pages/users-and-auth/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import UsersPo from '@/cypress/e2e/po/pages/users-and-auth/users.po';
import UserRetentionPo from '@/cypress/e2e/po/pages/users-and-auth/user.retention.po';

describe('Auth Index', { testIsolation: 'off', tags: ['@explorer', '@adminUser'] }, () => {
const runTimestamp = +new Date();
const usernameBlock = `user_to_block_${ runTimestamp }`;
const usernameRetention = `user_retention_access_${ runTimestamp }`;
const userIdsList = [];

before(() => {
cy.login();
});
Expand Down Expand Up @@ -55,12 +60,15 @@ describe('Auth Index', { testIsolation: 'off', tags: ['@explorer', '@adminUser']
});

it('can save user retention settings', () => {
const page = new PagePo('/c/local/auth/user.retention');
const usersPo = new UsersPo();
const userRetentionPo = new UserRetentionPo();

page.goTo();
usersPo.goTo();

const userRetentionPo = new UserRetentionPo();
usersPo.userRetentionLink().checkVisible();
usersPo.userRetentionLink().click();

userRetentionPo.waitForPage();
userRetentionPo.disableAfterPeriodCheckbox().set();
userRetentionPo.disableAfterPeriodInput().set('300h');
userRetentionPo.deleteAfterPeriodCheckbox().set();
Expand All @@ -74,17 +82,110 @@ describe('Auth Index', { testIsolation: 'off', tags: ['@explorer', '@adminUser']

cy.url().should('include', '/management.cattle.io.user');

const usersPo = new UsersPo();

usersPo.userRetentionLink().checkVisible();
usersPo.userRetentionLink().click();

userRetentionPo.waitForPage();
userRetentionPo.disableAfterPeriodCheckbox().checkExists();
userRetentionPo.disableAfterPeriodCheckbox().isChecked();
userRetentionPo.disableAfterPeriodInput().value().should('equal', '300h');
userRetentionPo.deleteAfterPeriodCheckbox().isChecked();
userRetentionPo.deleteAfterPeriodInput().value().should('equal', '600h');
userRetentionPo.userRetentionCron().value().should('equal', '0 0 1 1 *');
userRetentionPo.userLastLoginDefault().value().should('equal', '1718744536000');
userRetentionPo.disableAfterPeriodCheckbox().set();
userRetentionPo.saveButton().expectToBeEnabled();
userRetentionPo.saveButton().click();
usersPo.waitForPage();
usersPo.userRetentionLink().checkVisible();
usersPo.userRetentionLink().click();
userRetentionPo.deleteAfterPeriodCheckbox().set();
userRetentionPo.disableAfterPeriodCheckbox().set();
userRetentionPo.saveButton().expectToBeEnabled();
userRetentionPo.saveButton().click();
usersPo.waitForPage();
});

it('a user account gets blocked after the user retention expires', () => {
const usersPo = new UsersPo();
const userRetentionPo = new UserRetentionPo();

cy.createUser({
username: usernameBlock,
globalRole: { role: 'user' },
projectRole: {
clusterId: 'local',
projectName: 'Default',
role: 'project-member',
}
}).then((resp: Cypress.Response<any>) => {
const userId = resp.body.id;

userIdsList.push(userId);
});

usersPo.goTo();
usersPo.userRetentionLink().click();

userRetentionPo.waitForPage();
userRetentionPo.disableAfterPeriodCheckbox().set();
userRetentionPo.disableAfterPeriodInput().set('0.1m');
userRetentionPo.userRetentionCron().set('* * * * *');
userRetentionPo.userLastLoginDefault().set('1718744536000');

userRetentionPo.saveButton().expectToBeEnabled();
userRetentionPo.saveButton().click();
usersPo.waitForPage();

// logout from admin
cy.logout();

cy.url().should('includes', `${ Cypress.config().baseUrl }/auth/login`);

// login as test user
cy.login(usernameBlock, Cypress.env('password'));

// logout from test user
cy.logout();
cy.url().should('includes', `${ Cypress.config().baseUrl }/auth/login`);

// login back as admin
cy.login();

usersPo.goTo();
usersPo.waitForPage();
usersPo.accountStatusDisabled(usernameBlock).should('be.visible');
});

it('standard user should not have access to user retention page', () => {
const usersPo = new UsersPo();

cy.createUser({
username: usernameRetention,
globalRole: { role: 'user' },
projectRole: {
clusterId: 'local',
projectName: 'Default',
role: 'project-member',
}
}).then((resp: Cypress.Response<any>) => {
const userId = resp.body.id;

userIdsList.push(userId);
});
// logout from admin
cy.logout();

cy.url().should('includes', `${ Cypress.config().baseUrl }/auth/login`);

// login as test user
cy.login(usernameRetention, Cypress.env('password'));
usersPo.goTo();
usersPo.waitForPage();
usersPo.userRetentionLink().checkNotExists();
});

after(() => {
userIdsList.forEach((r) => cy.deleteRancherResource('v3', 'Users', r, false));
});
});
5 changes: 3 additions & 2 deletions cypress/support/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ Cypress.Commands.add('interceptAllRequests', (method = '/GET/POST/PUT/PATCH/', u
* Logout of Rancher
*/
Cypress.Commands.add('logout', () => {
cy.intercept('POST', '/v3/tokens?action=logout').as('loggedOut');
// Commented the incercept here as per issue: https://github.com/rancher/rancher/issues/46795
// cy.intercept('POST', '/v3/tokens?action=logout').as('loggedOut');
cy.visit('/auth/logout?logged-out=true');
cy.wait('@loggedOut').its('response.statusCode').should('eq', 200);
// cy.wait('@loggedOut').its('response.statusCode').should('eq', 200);
});

Cypress.Commands.add('iFrame', () => {
Expand Down

0 comments on commit a60802e

Please sign in to comment.