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

[Automation] - Additional user retention settings tests #11688

Merged
merged 1 commit into from
Sep 23, 2024
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
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({
izaac marked this conversation as resolved.
Show resolved Hide resolved
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
Loading