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 Sep 13, 2024
1 parent c6ad2e6 commit bb166fb
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 3 deletions.
101 changes: 100 additions & 1 deletion cypress/e2e/tests/pages/users-and-auth/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,22 @@ import PagePo from '@/cypress/e2e/po/pages/page.po';
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';

function updateUserRetentionSetting(settingId, newValue) {
cy.getRancherResource('v1', 'management.cattle.io.settings').then((data: any) => {
const retentionSetting = data.body.data.find((setting) => setting.id === settingId);

retentionSetting.value = newValue;

cy.setRancherResource('v1', 'management.cattle.io.settings', settingId, retentionSetting);
});
}

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 @@ -66,7 +81,6 @@ describe('Auth Index', { testIsolation: 'off', tags: ['@explorer', '@adminUser']
userRetentionPo.deleteAfterPeriodCheckbox().set();
userRetentionPo.deleteAfterPeriodInput().set('600h');
userRetentionPo.userRetentionCron().set('0 0 1 1 *');
// userRetentionPo.userRetentionDryRun().set('true');
userRetentionPo.userLastLoginDefault().set('1718744536000');

userRetentionPo.saveButton().expectToBeEnabled();
Expand All @@ -87,4 +101,89 @@ describe('Auth Index', { testIsolation: 'off', tags: ['@explorer', '@adminUser']
userRetentionPo.userRetentionCron().value().should('equal', '0 0 1 1 *');
userRetentionPo.userLastLoginDefault().value().should('equal', '1718744536000');
});

it('setup a user account that will be blocked', () => {
const usersPo = new UsersPo();

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);
});

// Initialize the retention settings in case they are not.

updateUserRetentionSetting('disable-inactive-user-after', '50h');

updateUserRetentionSetting('user-retention-cron', '* * * * *');

updateUserRetentionSetting('delete-inactive-user-after', '500h');

usersPo.goTo();

usersPo.waitForPage();

// login as test user once to activate the retention
cy.login(usernameBlock, Cypress.env('password'), false);
});

it('verify the user account has countdown timers', () => {
const usersPo = new UsersPo();

cy.logout();
cy.login();

usersPo.goTo();
usersPo.waitForPage();

// Disable After
usersPo.list().resourceTable().sortableTable().rowWithPartialName(usernameBlock)
.column(7)
.should('not.eq', '-');

// Delete After
usersPo.list().resourceTable().sortableTable().rowWithPartialName(usernameBlock)
.column(8)
.should('not.eq', '-');
});

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 bb166fb

Please sign in to comment.