Skip to content

Commit ed49fa5

Browse files
cwperksSuZhou-Joederek-ho
authored
Allow URL params for Security plugin intercept calls (#1276)
* Allow url params in intercept Signed-off-by: Craig Perkins <[email protected]> * Disable home modal Signed-off-by: Craig Perkins <[email protected]> * Update cypress/integration/plugins/security-dashboards-plugin/change_tenant_successfully.js Signed-off-by: SuZhou-Joe <[email protected]> * Fix CI check on main Signed-off-by: Craig Perkins <[email protected]> * Change text back Signed-off-by: Craig Perkins <[email protected]> * Move tenancy test over Signed-off-by: Derek Ho <[email protected]> * Use correct header when creating dashboard in tenancy_change_on_shortlink.js Signed-off-by: Craig Perkins <[email protected]> * Adjust import Signed-off-by: Craig Perkins <[email protected]> * Remove @ Signed-off-by: Craig Perkins <[email protected]> * Add wildcard Signed-off-by: Craig Perkins <[email protected]> * Fix sanity_tests.spec.js Signed-off-by: Craig Perkins <[email protected]> * Close the modal Signed-off-by: Craig Perkins <[email protected]> --------- Signed-off-by: Craig Perkins <[email protected]> Signed-off-by: SuZhou-Joe <[email protected]> Signed-off-by: Derek Ho <[email protected]> Co-authored-by: SuZhou-Joe <[email protected]> Co-authored-by: Derek Ho <[email protected]>
1 parent 5c156d1 commit ed49fa5

File tree

13 files changed

+50
-74
lines changed

13 files changed

+50
-74
lines changed

cypress.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"remoteDataSourceBasicAuthPassword": "admin",
1818
"SECURITY_ENABLED": false,
1919
"AGGREGATION_VIEW": false,
20+
"MULTITENANCY_ENABLED": true,
2021
"username": "admin",
2122
"password": "myStrongPassword123!",
2223
"ENDPOINT_WITH_PROXY": false,

cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) {
117117
ADMIN_AUTH.newUser = Cypress.env('username');
118118
ADMIN_AUTH.newPassword = Cypress.env('password');
119119
CURRENT_TENANT.newTenant = 'private';
120+
cy.deleteIndexPattern('index-pattern1', { failOnStatusCode: false });
121+
cy.deleteIndexPattern('index-pattern2', { failOnStatusCode: false });
120122
});
121123
});
122124
}

cypress/integration/plugins/security-dashboards-plugin/change_tenant_successfully.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ if (Cypress.env('SECURITY_ENABLED')) {
1212

1313
before(() => {
1414
cy.server();
15+
localStorage.setItem('home:welcome:show', false);
16+
localStorage.setItem('home:newThemeModal:show', false);
1517
});
1618
it('Checks that the tenant switcher can switch tenants despite a different tenant being present in the tenant query parameter.', function () {
1719
CURRENT_TENANT.newTenant = tenantName;

cypress/integration/plugins/security-dashboards-plugin/multi_tenancy.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ if (Cypress.env('SECURITY_ENABLED')) {
3939
indexPatternPrivateTenantHeaderSetUp
4040
);
4141
});
42+
after(() => {
43+
cy.deleteIndexPattern('index-pattern1', { failOnStatusCode: false });
44+
cy.deleteIndexPattern('index-pattern2', { failOnStatusCode: false });
45+
});
4246
it('Test 1 Disable Multi Tenancy ', () => {
4347
CURRENT_TENANT.newTenant = 'private';
4448

cypress/integration/plugins/security-dashboards-plugin/readonly.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
6262
`"${TEST_CONFIG.tenant.name}"`
6363
);
6464
window.localStorage.setItem('home:newThemeModal:show', false);
65+
window.localStorage.setItem('home:welcome:show', false);
6566
},
6667
});
6768
cy.waitForLoader();

cypress/integration/plugins/security-dashboards-plugin/sanity_tests.spec.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import {
77
BASE_PATH,
88
SEC_UI_TENANTS_PATH,
9-
SEC_TENANTS_FIXTURES_PATH,
109
SEC_INTERNALUSERS_FIXTURES_PATH,
11-
SEC_API_INTERNAL_USERS_PATH,
10+
SEC_API_INTERNAL_ACCOUNTS_PATH,
1211
} from '../../../utils/constants';
1312

1413
if (Cypress.env('SECURITY_ENABLED')) {
@@ -48,17 +47,14 @@ if (Cypress.env('SECURITY_ENABLED')) {
4847
tenantDescription
4948
);
5049

51-
cy.mockTenantsAction(
52-
SEC_TENANTS_FIXTURES_PATH + '/tenants_post_creation_response.json',
53-
() => {
54-
cy.get('button[id="submit"]').first().click({ force: true });
55-
}
56-
);
50+
cy.get('button[id="submit"]').first().click({ force: true });
5751

5852
cy.url().should((url) => {
5953
expect(url).to.contain('/tenants');
6054
});
6155

56+
cy.reload();
57+
6258
cy.contains('h3', 'Tenants');
6359
// should contain the new tenant that was just created
6460
cy.contains('.euiTableCellContent', tenantName);
@@ -69,7 +65,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
6965
// Navigate to Security/Internal User Database section
7066

7167
cy.visit(`${BASE_PATH}/app/security-dashboards-plugin#/users`);
72-
cy.intercept(SEC_API_INTERNAL_USERS_PATH, {
68+
cy.intercept(`${SEC_API_INTERNAL_ACCOUNTS_PATH}*`, {
7369
fixture:
7470
SEC_INTERNALUSERS_FIXTURES_PATH + '/internalusers_info_response.json',
7571
}).as('listUserResponse');
@@ -85,7 +81,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
8581
// Submit the form to create the user
8682
cy.get('button').contains('Create').click();
8783

88-
cy.intercept(SEC_API_INTERNAL_USERS_PATH, {
84+
cy.intercept(`${SEC_API_INTERNAL_ACCOUNTS_PATH}*`, {
8985
fixture:
9086
SEC_INTERNALUSERS_FIXTURES_PATH +
9187
'/internalusers_response_post_new_user_creation.json',
@@ -161,7 +157,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
161157
// Step 3: Navigate to Manage data to add an index pattern
162158
cy.visit(`${BASE_PATH}/app/home`);
163159
cy.get('button[aria-label="Closes this modal window"]').click();
164-
cy.get('a').contains('Manage').click(); // Adjust the selector as needed
160+
cy.contains('Manage').click(); // Adjust the selector as needed
165161

166162
// Step 4: Add the index pattern
167163
cy.get('[data-test-subj="indexPatterns"]').click();

cypress/integration/plugins/security-dashboards-plugin/switch_tenant.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ export function switchTenantTo(newTenant) {
77
cy.getElementByTestId('account-popover').click();
88
cy.intercept({
99
method: 'GET',
10-
url: '/api/v1/auth/dashboardsinfo',
10+
url: '/api/v1/auth/dashboardsinfo*',
1111
}).as('waitForDashboardsInfo');
1212

1313
cy.intercept({
1414
method: 'GET',
15-
url: '/api/v1/configuration/account',
15+
url: '/api/v1/configuration/account*',
1616
}).as('waitForAccountInfo');
1717

1818
cy.getElementByTestId('switch-tenants').click();
@@ -37,7 +37,7 @@ export function switchTenantTo(newTenant) {
3737

3838
cy.intercept({
3939
method: 'POST',
40-
url: '/api/v1/multitenancy/tenant',
40+
url: '/api/v1/multitenancy/tenant*',
4141
}).as('waitForUpdatingTenants');
4242
cy.getElementByTestId('tenant-switch-modal')
4343
.find('[data-test-subj="confirm"]')

cypress/integration/plugins/security-dashboards-plugin/tenancy_change_on_shortlink.js

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,11 @@
55

66
import { CURRENT_TENANT } from '../../../utils/commands';
77
import { switchTenantTo } from './switch_tenant';
8-
import indexPatternGlobalTenantHeaderSetUp from '../../../fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternGlobalTenantHeader.json';
9-
import indexPatternPrivateTenantHeaderSetUp from '../../../fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternPrivateTenantHeader.json';
108

119
if (Cypress.env('SECURITY_ENABLED')) {
1210
describe('Multi Tenancy Tests: ', () => {
1311
before(() => {
1412
cy.server();
15-
16-
cy.createIndexPattern(
17-
'index-pattern1',
18-
{
19-
title: 's*',
20-
timeFieldName: 'timestamp',
21-
},
22-
indexPatternGlobalTenantHeaderSetUp
23-
);
24-
25-
cy.createIndexPattern(
26-
'index-pattern2',
27-
{
28-
title: 'se*',
29-
timeFieldName: 'timestamp',
30-
},
31-
indexPatternPrivateTenantHeaderSetUp
32-
);
3313
});
3414

3515
it('Tests that when the short URL is copied and pasted, it will route correctly with the right tenant', function () {
@@ -43,7 +23,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
4323
title: dashboardName,
4424
},
4525
{
46-
security_tenant: 'private',
26+
securitytenant: 'private',
4727
}
4828
);
4929

@@ -83,13 +63,10 @@ if (Cypress.env('SECURITY_ENABLED')) {
8363
.should('be.visible')
8464
.click();
8565

86-
cy.getElementByTestId('savedObjectTitle').type(dashboardName);
87-
8866
cy.intercept({
8967
method: 'POST',
9068
url: '/api/saved_objects/_bulk_get',
9169
}).as('waitForReloadingDashboard');
92-
cy.getElementByTestId('confirmSaveSavedObjectButton').click();
9370
cy.wait('@waitForReloadingDashboard');
9471
cy.wait(2000);
9572

@@ -113,36 +90,26 @@ if (Cypress.env('SECURITY_ENABLED')) {
11390
cy.log('Short url is ' + shortUrl);
11491
// Navigate away to avoid the non existing dashboard in the next tenant.
11592
switchTenantTo('global');
93+
cy.waitForLoader();
94+
cy.getElementByTestId('account-popover').click();
95+
cy.get('#tenantName').should('contain.text', 'Global');
11696

11797
// Since we can't reliably read the clipboard data, we have to append the tenant parameter manually
11898
cy.visit(shortUrl + '?security_tenant=private', {
119-
excludeTenant: true, // We are passing the tenant as a query parameter. Mainly because of readability.
120-
onBeforeLoad(window) {
121-
// Here we are simulating the new tab scenario which isn't supported by Cypress
122-
window.sessionStorage.clear();
123-
},
124-
});
99+
waitForGetTenant: true, // We are passing the tenant as a query parameter. Mainly because of readability.
100+
excludeTenant: true,
101+
cache: 'clear',
102+
}).reload();
103+
104+
cy.waitForLoader();
125105

126-
cy.url({ timeout: 10000 }).should('contain', 'security_tenant=');
106+
cy.getElementByTestId('account-popover').should('be.visible').click();
107+
cy.get('#tenantName').should('contain.text', 'Private');
127108
cy.getElementByTestId('breadcrumb last').should(
128109
'contain.text',
129110
dashboardName
130111
);
131112
});
132113
});
133-
after(() => {
134-
cy.deleteIndexPattern('index-pattern1', {
135-
headers: {
136-
securitytenant: ['global'],
137-
'osd-xsrf': true,
138-
},
139-
});
140-
cy.deleteIndexPattern('index-pattern2', {
141-
headers: {
142-
securitytenant: ['private'],
143-
'osd-xsrf': true,
144-
},
145-
});
146-
});
147114
});
148115
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { TENANTS_MANAGE_PATH } from '../../../utils/dashboards/constants';
6+
import { SECURITY_PLUGIN_PATH } from '../../../utils/dashboards/constants';
77

8-
if (Cypress.env('SECURITY_ENABLED')) {
8+
if (Cypress.env('SECURITY_ENABLED') && !Cypress.env('MULTITENANCY_ENABLED')) {
99
describe('Multi Tenancy Tests: ', () => {
1010
before(() => {
1111
cy.server();
1212
});
1313
it('Test Dashboards tenancy features should not be accessible ', () => {
1414
// This test is to ensure tenancy related features are not accessible when opensearch_security.multitenancy.enabled is disabled in the opensearchdashboard.yaml
15-
cy.visit(TENANTS_MANAGE_PATH);
15+
cy.visit(SECURITY_PLUGIN_PATH);
1616
cy.waitForLoader();
1717

18-
cy.contains('You have not enabled multi tenancy').should('exist');
18+
cy.get('[title="Tenants"]').should('not.exist');
1919

2020
// Switch tenants button should not exist when multi-tenancy is disabled.
2121
cy.get('#user-icon-btn').click();

cypress/integration/plugins/security/tenants_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
2424
}
2525
);
2626

27-
cy.contains('h3', 'Dashboards tenants');
27+
cy.contains('h3', 'Tenants');
2828

2929
// One of the many tenants
3030
cy.contains('.euiTableCellContent', 'Global');
@@ -69,7 +69,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
6969
expect(url).to.contain('/tenants');
7070
});
7171

72-
cy.contains('h3', 'Dashboards tenants');
72+
cy.contains('h3', 'Tenants');
7373
// should contain the new tenant that was just created
7474
cy.contains('.euiTableCellContent', tenantName);
7575
cy.contains('span', tenantDescription);

0 commit comments

Comments
 (0)