Skip to content

Commit

Permalink
linting errors resolved Signed-off-by: leanneeliatra <leanne.laceybyr…
Browse files Browse the repository at this point in the history
[email protected]>

Signed-off-by: leanneeliatra <[email protected]>
  • Loading branch information
leanneeliatra committed Jul 24, 2023
1 parent 4bbd176 commit 45daf83
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { CURRENT_TENANT } from '../../../utils/commands';
import { switchTenantTo } from './switch_tenant';


if (Cypress.env('SECURITY_ENABLED')) {
describe('Switch tenants when visiting copied links: ', () => {
const tenantName = 'private';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export function switchTenantTo(newTenant) {
cy.getElementByTestId('account-popover').click();
cy.intercept({
Expand All @@ -17,8 +17,10 @@ export function switchTenantTo(newTenant) {

cy.getElementByTestId('switch-tenants').click();
//should ensures the dialog window is fully loaded and the radios can be selected.
cy.get('[id="' + newTenant + '"][name="tenantSwitchRadios"]').should('be.enabled');
cy.get('.euiRadio__label[for="' + newTenant + '"]').click();
cy.get('[id="' + newTenant + '"][name="tenantSwitchRadios"]').should(
'be.enabled'
);
cy.get('.euiRadio__label[for="' + newTenant + '"]').click();

cy.intercept({
method: 'POST',
Expand All @@ -28,10 +30,10 @@ export function switchTenantTo(newTenant) {
.find('[data-test-subj="confirm"]')
.click();

cy.wait('@waitForUpdatingTenants')
cy.wait('@waitForUpdatingTenants');

// Make sure dashboards has really reloaded.
// @waitForReloadAfterTenantSwitch should be triggered twice
cy.wait('@waitForDashboardsInfo');
cy.wait('@waitForDashboardsInfo');
}
}
Original file line number Diff line number Diff line change
@@ -1,50 +1,51 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

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

if (Cypress.env('SECURITY_ENABLED')) {
describe('Multi Tenancy Tests: ', () => {
before(() => {
cy.server();
before(() => {
cy.server();

cy.createIndexPattern(
'index-pattern1',
{
title: 's*',
timeFieldName: 'timestamp',
},
indexPatternGlobalTenantHeaderSetUp
);
cy.createIndexPattern(
'index-pattern1',
{
title: 's*',
timeFieldName: 'timestamp',
},
indexPatternGlobalTenantHeaderSetUp
);

cy.createIndexPattern(
'index-pattern2',
{
title: 'se*',
timeFieldName: 'timestamp',
},
indexPatternPrivateTenantHeaderSetUp
);
});
cy.createIndexPattern(
'index-pattern2',
{
title: 'se*',
timeFieldName: 'timestamp',
},
indexPatternPrivateTenantHeaderSetUp
);
});

it('Tests that when the short URL is copied and pasted, it will route correctly with the right tenant', function () {
const randomNumber = Cypress._.random(0, 1e6);
const dashboardName = 'Cypress dashboard - ' + randomNumber;
// We are programmatically creating a dashboard so that the test
// always have the same view. An empty list would show the empty prompt.
// Also, this saves us some typing, clicking and waiting in the test.
cy.createDashboard({
title: dashboardName
}, {
security_tenant: 'private'
})
cy.createDashboard(
{
title: dashboardName,
},
{
security_tenant: 'private',
}
);

// When creating the shortUrl, we don't want to have the security_tenant
// parameter in the url - otherwise it will be stored in the shortUrl
Expand All @@ -67,7 +68,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
'__user__'
);
},
} );
});
// Navigate to the Dashboards app
cy.getElementByTestId('toggleNavButton').should('be.visible').click();
// After clicking the navigation, the security_tenant parameter should be gone
Expand All @@ -76,7 +77,11 @@ if (Cypress.env('SECURITY_ENABLED')) {
// The test subj seems to replace spaces with a dash, so we convert the dashboard name here too.
// Go to the dashboard we have created
const selectorDashboardName = dashboardName.split(' ').join('-');
cy.getElementByTestId('dashboardListingTitleLink-' + selectorDashboardName).should('be.visible').click();
cy.getElementByTestId(
'dashboardListingTitleLink-' + selectorDashboardName
)
.should('be.visible')
.click();

// Open top share navigation to access copy short url
cy.getElementByTestId('shareTopNavButton').should('be.visible').click();
Expand All @@ -90,7 +95,6 @@ if (Cypress.env('SECURITY_ENABLED')) {
cy.getElementByTestId('createShortUrl').click();
cy.wait('@getShortUrl');


//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')
Expand All @@ -109,10 +113,7 @@ if (Cypress.env('SECURITY_ENABLED')) {
},
});

cy.url({ timeout: 10000 }).should(
'contain',
'security_tenant='
);
cy.url({ timeout: 10000 }).should('contain', 'security_tenant=');
cy.getElementByTestId('breadcrumb last').should(
'contain.text',
dashboardName
Expand All @@ -121,4 +122,3 @@ if (Cypress.env('SECURITY_ENABLED')) {
});
});
}

7 changes: 2 additions & 5 deletions cypress/utils/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ Cypress.Commands.add('createIndexPattern', (id, attributes, header = {}) => {
const url = `${
Cypress.config().baseUrl
}/api/saved_objects/index-pattern/${id}?overwrite=true`; // When running tests locally if ran multiple times the tests fail. The fix is to set Overwrite to true.


cy.request({
method: 'POST',
Expand All @@ -355,10 +354,8 @@ Cypress.Commands.add('createIndexPattern', (id, attributes, header = {}) => {
});
});

Cypress.Commands.add('createDashboard', (attributes= {}, headers = {}) => {
const url = `${
Cypress.config().baseUrl
}/api/saved_objects/dashboard`;
Cypress.Commands.add('createDashboard', (attributes = {}, headers = {}) => {
const url = `${Cypress.config().baseUrl}/api/saved_objects/dashboard`;

cy.request({
method: 'POST',
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"cypress:open": "cypress open",
"cypress:run-without-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --headless --env SECURITY_ENABLED=false",
"cypress:run-with-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --headless --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200",
"cypress:run-with-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200",
"cypress:run-with-security-and-aggregation-view": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --headless --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200,AGGREGATION_VIEW=true",
"cypress:run-plugin-tests-without-security": "yarn cypress:run-without-security --spec 'cypress/integration/plugins/*/*.js'",
"cypress:run-plugin-tests-with-security": "yarn cypress:run-with-security --spec 'cypress/integration/plugins/*/*.js'",
Expand Down

0 comments on commit 45daf83

Please sign in to comment.