-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test to ensure when a shortlink is copied, tenant is changed and shor…
…t link is visited. The tenant from the link is visited. Signed-off-by: leanneeliatra <[email protected]>
- Loading branch information
1 parent
e1fad26
commit 306d79d
Showing
2 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
139 changes: 139 additions & 0 deletions
139
cypress/integration/plugins/security-dashboards-plugin/tenancy_change_on_shortlink.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import { CURRENT_TENANT } from '../../../utils/commands'; | ||
import tenantDescription from '../../../fixtures/plugins/security-dashboards-plugin/tenants/testTenant.json'; | ||
|
||
const tenantName = 'test'; | ||
|
||
if (Cypress.env('SECURITY_ENABLED')) { | ||
describe('Multi Tenancy Tests: ', () => { | ||
before(() => { | ||
cy.server(); | ||
cy.createTenant(tenantName, tenantDescription); | ||
|
||
try { | ||
cy.createIndexPattern( | ||
'index-pattern1', | ||
{ | ||
title: 's*', | ||
timeFieldName: 'timestamp', | ||
}, | ||
indexPatternGlobalTenantHeaderSetUp | ||
); | ||
} catch (error) { | ||
// Ignore | ||
} | ||
try { | ||
cy.createIndexPattern( | ||
'index-pattern2', | ||
{ | ||
title: 'se*', | ||
timeFieldName: 'timestamp', | ||
}, | ||
indexPatternPrivateTenantHeaderSetUp | ||
); | ||
} catch (error) { | ||
// Ignore | ||
} | ||
}); | ||
|
||
it('Tests that when the short URL is copied and pasted, it will route correctly with the right tenant', function () { | ||
cy.visit('/app/dashboards#create', { | ||
excludeTenant: true, | ||
onBeforeLoad(win) { | ||
// set up session storage as we would expect to emulate browser | ||
win.sessionStorage.setItem( | ||
'opendistro::security::tenant::show_popup', | ||
false | ||
); | ||
win.localStorage.setItem( | ||
'opendistro::security::tenant::saved', | ||
'__user__' | ||
); | ||
}, | ||
}); | ||
|
||
// 1. Create a dashboard (to be able to share it later) | ||
cy.getElementByTestId('dashboardSaveMenuItem').click(); | ||
|
||
const randomNumber = Cypress._.random(0, 1e6); | ||
const dashboardName = 'Cypress test: My dashboard - ' + randomNumber; | ||
cy.getElementByTestId('savedObjectTitle').type(dashboardName); | ||
|
||
cy.intercept({ | ||
method: 'POST', | ||
url: '/api/saved_objects/_bulk_get', | ||
}).as('waitForReloadingDashboard'); | ||
cy.getElementByTestId('confirmSaveSavedObjectButton').click(); | ||
cy.wait('@waitForReloadingDashboard'); | ||
|
||
// 2. Open top share navigation to access copy short url | ||
cy.get('[data-test-subj="shareTopNavButton"]').click(); | ||
cy.getElementByTestId('sharePanel-Permalinks').click(); | ||
|
||
// 3. Create the short url, wait for response | ||
cy.intercept('POST', '/api/shorten_url').as('getShortUrl'); | ||
// If the url already contains the tenant parameter, it will be stored in the short url. That will work in the app | ||
// but would render this test useless. We're testing that resolved short urls without the tenant parameter work as well. | ||
cy.url().should('not.contain', 'security_tenant'); | ||
cy.getElementByTestId('createShortUrl').click(); | ||
cy.wait('@getShortUrl'); | ||
|
||
function switchTenantTo(newTenant) { | ||
cy.getElementByTestId('account-popover').click(); | ||
cy.getElementByTestId('switch-tenants').click(); | ||
cy.get('.euiRadio__label[for="' + newTenant + '"]').click(); | ||
cy.intercept({ | ||
method: 'POST', | ||
url: '/api/v1/multitenancy/tenant', | ||
}).as('waitForUpdatingTenants'); | ||
|
||
cy.getElementByTestId('tenant-switch-modal') | ||
.find('[data-test-subj="confirm"]') | ||
.click(); | ||
|
||
cy.wait('@waitForUpdatingTenants'); | ||
cy.intercept({ | ||
method: 'GET', | ||
url: '/api/v1/auth/dashboardsinfo', | ||
}).as('waitForReloadAfterTenantSwitch'); | ||
cy.wait('@waitForReloadAfterTenantSwitch'); | ||
cy.wait('@waitForReloadAfterTenantSwitch'); | ||
} | ||
|
||
//4. Switch tenant & visit shortURL link to ensure tenant from short URL is retained | ||
cy.get('[data-test-subj="copyShareUrlButton"]') | ||
.invoke('attr', 'data-share-url') | ||
.should('contain', '/goto/') | ||
.then((shortUrl) => { | ||
cy.log('Short url is ' + shortUrl); | ||
// Navigate away to avoid the non existing dashboard in the next tenant. | ||
// For some reason, using cy.visit() will break things - Cypress can't find the account-popover unless I wait for N seconds. | ||
cy.waitForLoader(); | ||
switchTenantTo('global'); | ||
// The tests override the cy.visit method, so we need to set the tenant so that the custom command can pick it up. | ||
CURRENT_TENANT.newTenant = 'private'; | ||
cy.visit(shortUrl, { | ||
//waitForGetTenant: true | ||
onBeforeLoad(win) { | ||
// Here we are simulating the new tab scenario which isn't supported by Cypress | ||
win.sessionStorage.clear(); | ||
}, | ||
}); | ||
cy.url({ timeout: 10000 }).should( | ||
'contain', | ||
'security_tenant=__user__' | ||
); | ||
cy.getElementByTestId('breadcrumb last').should( | ||
'contain.text', | ||
dashboardName | ||
); | ||
}); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters