Skip to content

Commit cebeb99

Browse files
Merge pull request #781 from etmurasaki/etmura-OU-1234
OU-1234: perses automation testing - rbac users scenarios added with project selector
2 parents 2ce787b + 85f236d commit cebeb99

20 files changed

Lines changed: 1528 additions & 62 deletions

web/cypress.config.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import * as console from 'console';
44
import * as path from 'path';
55
import registerCypressGrep from '@cypress/grep/src/plugin';
66

7+
const getLoginCredentials = (index: number): { username: string; password: string } => {
8+
const users = (process.env.CYPRESS_LOGIN_USERS || '').split(',').filter(Boolean);
9+
const userEntry = users[index] || '';
10+
const [username = '', password = ''] = userEntry.split(':');
11+
return { username, password };
12+
};
13+
714
export default defineConfig({
815
screenshotsFolder: './cypress/screenshots',
916
screenshotOnRunFailure: true,
@@ -22,15 +29,23 @@ export default defineConfig({
2229
),
2330
// User 0 credentials - as kubeadmin or even non-admin user
2431
// specifically for perses e2e tests, user0 is considered as console admin user to install COO and create RBAC roles and bindings
25-
LOGIN_USERNAME: (process.env.CYPRESS_LOGIN_USERS || '').split(',')[0]?.split(':')[0] || '',
26-
LOGIN_PASSWORD: (process.env.CYPRESS_LOGIN_USERS || '').split(',')[0]?.split(':')[1] || '',
32+
LOGIN_USERNAME: getLoginCredentials(0).username,
33+
LOGIN_PASSWORD: getLoginCredentials(0).password,
2734
// User 1 credentials
2835
// User 2 credentials
2936
// specifically for perses e2e tests, user1 and user2 are considered as perses e2e users to test RBAC access to dashboards
30-
LOGIN_USERNAME1: (process.env.CYPRESS_LOGIN_USERS || '').split(',')[1]?.split(':')[0] || '',
31-
LOGIN_PASSWORD1: (process.env.CYPRESS_LOGIN_USERS || '').split(',')[1]?.split(':')[1] || '',
32-
LOGIN_USERNAME2: (process.env.CYPRESS_LOGIN_USERS || '').split(',')[2]?.split(':')[0] || '',
33-
LOGIN_PASSWORD2: (process.env.CYPRESS_LOGIN_USERS || '').split(',')[2]?.split(':')[1] || '',
37+
LOGIN_USERNAME1: getLoginCredentials(1).username,
38+
LOGIN_PASSWORD1: getLoginCredentials(1).password,
39+
LOGIN_USERNAME2: getLoginCredentials(2).username,
40+
LOGIN_PASSWORD2: getLoginCredentials(2).password,
41+
LOGIN_USERNAME3: getLoginCredentials(3).username,
42+
LOGIN_PASSWORD3: getLoginCredentials(3).password,
43+
LOGIN_USERNAME4: getLoginCredentials(4).username,
44+
LOGIN_PASSWORD4: getLoginCredentials(4).password,
45+
LOGIN_USERNAME5: getLoginCredentials(5).username,
46+
LOGIN_PASSWORD5: getLoginCredentials(5).password,
47+
LOGIN_USERNAME6: getLoginCredentials(6).username,
48+
LOGIN_PASSWORD6: getLoginCredentials(6).password,
3449
TIMEZONE: process.env.CYPRESS_TIMEZONE || 'UTC',
3550
MOCK_NEW_METRICS: process.env.CYPRESS_MOCK_NEW_METRICS || 'false',
3651
COO_NAMESPACE: process.env.CYPRESS_COO_NAMESPACE || 'openshift-cluster-observability-operator',

web/cypress/e2e/perses/99.coo_rbac_perses_user1.cy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const MP = {
1919
};
2020

2121
//TODO: change tag to @smoke, @dashboards, @perses when customizable-dashboards gets merged
22-
describe('BVT: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
22+
describe('RBAC User1: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
2323

2424
before(() => {
2525
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user

web/cypress/e2e/perses/99.coo_rbac_perses_user2.cy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const MP = {
1919
};
2020

2121
//TODO: change tag to @smoke, @dashboards, @perses when customizable-dashboards gets merged
22-
describe('BVT: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
22+
describe('RBAC User2: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
2323

2424
before(() => {
2525
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
@@ -64,6 +64,7 @@ describe('BVT: COO - Dashboards (Perses) - Administrator perspective', { tags: [
6464

6565
beforeEach(() => {
6666
nav.sidenav.clickNavLink(['Observe', 'Dashboards (Perses)']);
67+
cy.changeNamespace('All Projects');
6768
});
6869

6970
after(() => {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { nav } from '../../views/nav';
2+
import { runCOORBACPersesTestsDevUser3 } from '../../support/perses/99.coo_rbac_perses_user3.cy';
3+
4+
5+
// Set constants for the operators that need to be installed for tests.
6+
const MCP = {
7+
namespace: 'openshift-cluster-observability-operator',
8+
packageName: 'cluster-observability-operator',
9+
operatorName: 'Cluster Observability Operator',
10+
config: {
11+
kind: 'UIPlugin',
12+
name: 'monitoring',
13+
},
14+
};
15+
16+
const MP = {
17+
namespace: 'openshift-monitoring',
18+
operatorName: 'Cluster Monitoring Operator',
19+
};
20+
21+
//TODO: change tag to @smoke, @dashboards, @perses when customizable-dashboards gets merged
22+
describe('RBAC User3: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
23+
24+
before(() => {
25+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
26+
// Step 1: Grant temporary cluster-admin role to dev user for COO/Perses installation
27+
// cy.log('Granting temporary cluster-admin role to dev user for setup');
28+
// cy.adminCLI(
29+
// `oc adm policy add-cluster-role-to-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
30+
// );
31+
32+
// Step 2: Setup COO and Perses dashboards (requires admin privileges)
33+
cy.beforeBlockCOO(MCP, MP);
34+
cy.setupPersesRBACandExtraDashboards();
35+
36+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
37+
// Step 3: Remove cluster-admin role - dev user now has limited permissions
38+
// cy.log('Removing cluster-admin role from dev user');
39+
// cy.adminCLI(
40+
// `oc adm policy remove-cluster-role-from-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
41+
// );
42+
43+
// Step 4: Clear Cypress session cache and logout
44+
// This is critical because beforeBlockCOO uses cy.session() which caches the login state
45+
cy.log('Clearing Cypress session cache to ensure fresh login');
46+
Cypress.session.clearAllSavedSessions();
47+
48+
// Clear all cookies and storage to fully reset browser state
49+
cy.clearAllCookies();
50+
cy.clearAllLocalStorage();
51+
cy.clearAllSessionStorage();
52+
53+
// Step 5: Re-login as dev user (now without cluster-admin role)
54+
// Using cy.relogin() because it doesn't require oauthurl and handles the login page directly
55+
cy.log('Re-logging in as dev user with limited permissions');
56+
cy.relogin(
57+
Cypress.env('LOGIN_IDP_DEV_USER'),
58+
Cypress.env('LOGIN_USERNAME3'),
59+
Cypress.env('LOGIN_PASSWORD3'),
60+
);
61+
cy.validateLogin();
62+
cy.closeOnboardingModalIfPresent();
63+
});
64+
65+
beforeEach(() => {
66+
nav.sidenav.clickNavLink(['Observe', 'Dashboards (Perses)']);
67+
});
68+
69+
after(() => {
70+
cy.cleanupExtraDashboards();
71+
});
72+
73+
//TODO: rename after customizable-dashboards gets merged
74+
runCOORBACPersesTestsDevUser3({
75+
name: 'Administrator',
76+
});
77+
78+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { nav } from '../../views/nav';
2+
import { runCOORBACPersesTestsDevUser4 } from '../../support/perses/99.coo_rbac_perses_user4.cy';
3+
4+
5+
// Set constants for the operators that need to be installed for tests.
6+
const MCP = {
7+
namespace: 'openshift-cluster-observability-operator',
8+
packageName: 'cluster-observability-operator',
9+
operatorName: 'Cluster Observability Operator',
10+
config: {
11+
kind: 'UIPlugin',
12+
name: 'monitoring',
13+
},
14+
};
15+
16+
const MP = {
17+
namespace: 'openshift-monitoring',
18+
operatorName: 'Cluster Monitoring Operator',
19+
};
20+
21+
//TODO: change tag to @smoke, @dashboards, @perses when customizable-dashboards gets merged
22+
describe('RBAC User4: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
23+
24+
before(() => {
25+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
26+
// Step 1: Grant temporary cluster-admin role to dev user for COO/Perses installation
27+
// cy.log('Granting temporary cluster-admin role to dev user for setup');
28+
// cy.adminCLI(
29+
// `oc adm policy add-cluster-role-to-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
30+
// );
31+
32+
// Step 2: Setup COO and Perses dashboards (requires admin privileges)
33+
cy.beforeBlockCOO(MCP, MP);
34+
cy.setupPersesRBACandExtraDashboards();
35+
36+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
37+
// Step 3: Remove cluster-admin role - dev user now has limited permissions
38+
// cy.log('Removing cluster-admin role from dev user');
39+
// cy.adminCLI(
40+
// `oc adm policy remove-cluster-role-from-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
41+
// );
42+
43+
// Step 4: Clear Cypress session cache and logout
44+
// This is critical because beforeBlockCOO uses cy.session() which caches the login state
45+
cy.log('Clearing Cypress session cache to ensure fresh login');
46+
Cypress.session.clearAllSavedSessions();
47+
48+
// Clear all cookies and storage to fully reset browser state
49+
cy.clearAllCookies();
50+
cy.clearAllLocalStorage();
51+
cy.clearAllSessionStorage();
52+
53+
// Step 5: Re-login as dev user (now without cluster-admin role)
54+
// Using cy.relogin() because it doesn't require oauthurl and handles the login page directly
55+
cy.log('Re-logging in as dev user with limited permissions');
56+
cy.relogin(
57+
Cypress.env('LOGIN_IDP_DEV_USER'),
58+
Cypress.env('LOGIN_USERNAME4'),
59+
Cypress.env('LOGIN_PASSWORD4'),
60+
);
61+
cy.validateLogin();
62+
cy.closeOnboardingModalIfPresent();
63+
});
64+
65+
beforeEach(() => {
66+
nav.sidenav.clickNavLink(['Observe', 'Dashboards (Perses)']);
67+
});
68+
69+
after(() => {
70+
cy.cleanupExtraDashboards();
71+
});
72+
73+
//TODO: rename after customizable-dashboards gets merged
74+
runCOORBACPersesTestsDevUser4({
75+
name: 'Administrator',
76+
});
77+
78+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { nav } from '../../views/nav';
2+
import { runCOORBACPersesTestsDevUser5 } from '../../support/perses/99.coo_rbac_perses_user5.cy';
3+
4+
5+
// Set constants for the operators that need to be installed for tests.
6+
const MCP = {
7+
namespace: 'openshift-cluster-observability-operator',
8+
packageName: 'cluster-observability-operator',
9+
operatorName: 'Cluster Observability Operator',
10+
config: {
11+
kind: 'UIPlugin',
12+
name: 'monitoring',
13+
},
14+
};
15+
16+
const MP = {
17+
namespace: 'openshift-monitoring',
18+
operatorName: 'Cluster Monitoring Operator',
19+
};
20+
21+
//TODO: change tag to @smoke, @dashboards, @perses when customizable-dashboards gets merged
22+
describe('RBAC User5: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
23+
24+
before(() => {
25+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
26+
// Step 1: Grant temporary cluster-admin role to dev user for COO/Perses installation
27+
// cy.log('Granting temporary cluster-admin role to dev user for setup');
28+
// cy.adminCLI(
29+
// `oc adm policy add-cluster-role-to-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
30+
// );
31+
32+
// Step 2: Setup COO and Perses dashboards (requires admin privileges)
33+
cy.beforeBlockCOO(MCP, MP);
34+
cy.setupPersesRBACandExtraDashboards();
35+
36+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
37+
// Step 3: Remove cluster-admin role - dev user now has limited permissions
38+
// cy.log('Removing cluster-admin role from dev user');
39+
// cy.adminCLI(
40+
// `oc adm policy remove-cluster-role-from-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
41+
// );
42+
43+
// Step 4: Clear Cypress session cache and logout
44+
// This is critical because beforeBlockCOO uses cy.session() which caches the login state
45+
cy.log('Clearing Cypress session cache to ensure fresh login');
46+
Cypress.session.clearAllSavedSessions();
47+
48+
// Clear all cookies and storage to fully reset browser state
49+
cy.clearAllCookies();
50+
cy.clearAllLocalStorage();
51+
cy.clearAllSessionStorage();
52+
53+
// Step 5: Re-login as dev user (now without cluster-admin role)
54+
// Using cy.relogin() because it doesn't require oauthurl and handles the login page directly
55+
cy.log('Re-logging in as dev user with limited permissions');
56+
cy.relogin(
57+
Cypress.env('LOGIN_IDP_DEV_USER'),
58+
Cypress.env('LOGIN_USERNAME5'),
59+
Cypress.env('LOGIN_PASSWORD5'),
60+
);
61+
cy.validateLogin();
62+
cy.closeOnboardingModalIfPresent();
63+
});
64+
65+
beforeEach(() => {
66+
nav.sidenav.clickNavLink(['Observe', 'Dashboards (Perses)']);
67+
});
68+
69+
after(() => {
70+
cy.cleanupExtraDashboards();
71+
});
72+
73+
//TODO: rename after customizable-dashboards gets merged
74+
runCOORBACPersesTestsDevUser5({
75+
name: 'Administrator',
76+
});
77+
78+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import { nav } from '../../views/nav';
2+
import { runCOORBACPersesTestsDevUser6 } from '../../support/perses/99.coo_rbac_perses_user6.cy';
3+
4+
5+
// Set constants for the operators that need to be installed for tests.
6+
const MCP = {
7+
namespace: 'openshift-cluster-observability-operator',
8+
packageName: 'cluster-observability-operator',
9+
operatorName: 'Cluster Observability Operator',
10+
config: {
11+
kind: 'UIPlugin',
12+
name: 'monitoring',
13+
},
14+
};
15+
16+
const MP = {
17+
namespace: 'openshift-monitoring',
18+
operatorName: 'Cluster Monitoring Operator',
19+
};
20+
21+
//TODO: change tag to @smoke, @dashboards, @perses when customizable-dashboards gets merged
22+
describe('RBAC User6: COO - Dashboards (Perses) - Administrator perspective', { tags: ['@smoke-', '@dashboards-', '@perses-dev'] }, () => {
23+
24+
before(() => {
25+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
26+
// Step 1: Grant temporary cluster-admin role to dev user for COO/Perses installation
27+
// cy.log('Granting temporary cluster-admin role to dev user for setup');
28+
// cy.adminCLI(
29+
// `oc adm policy add-cluster-role-to-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
30+
// );
31+
32+
// Step 2: Setup COO and Perses dashboards (requires admin privileges)
33+
cy.beforeBlockCOO(MCP, MP);
34+
cy.setupPersesRBACandExtraDashboards();
35+
36+
//TODO: https://issues.redhat.com/browse/OCPBUGS-58468 - when it gets fixed, installation can be don using non-admin user
37+
// Step 3: Remove cluster-admin role - dev user now has limited permissions
38+
// cy.log('Removing cluster-admin role from dev user');
39+
// cy.adminCLI(
40+
// `oc adm policy remove-cluster-role-from-user cluster-admin ${Cypress.env('LOGIN_USERNAME')}`,
41+
// );
42+
43+
// Step 4: Clear Cypress session cache and logout
44+
// This is critical because beforeBlockCOO uses cy.session() which caches the login state
45+
cy.log('Clearing Cypress session cache to ensure fresh login');
46+
Cypress.session.clearAllSavedSessions();
47+
48+
// Clear all cookies and storage to fully reset browser state
49+
cy.clearAllCookies();
50+
cy.clearAllLocalStorage();
51+
cy.clearAllSessionStorage();
52+
53+
// Step 5: Re-login as dev user (now without cluster-admin role)
54+
// Using cy.relogin() because it doesn't require oauthurl and handles the login page directly
55+
cy.log('Re-logging in as dev user with limited permissions');
56+
cy.relogin(
57+
Cypress.env('LOGIN_IDP_DEV_USER'),
58+
Cypress.env('LOGIN_USERNAME6'),
59+
Cypress.env('LOGIN_PASSWORD6'),
60+
);
61+
cy.validateLogin();
62+
cy.closeOnboardingModalIfPresent();
63+
});
64+
65+
beforeEach(() => {
66+
nav.sidenav.clickNavLink(['Observe', 'Dashboards (Perses)']);
67+
});
68+
69+
after(() => {
70+
cy.cleanupExtraDashboards();
71+
});
72+
73+
//TODO: rename after customizable-dashboards gets merged
74+
runCOORBACPersesTestsDevUser6({
75+
name: 'Administrator',
76+
});
77+
78+
});

0 commit comments

Comments
 (0)