From 21bf25f9749b8c8b3dda0101102a77f736da141f Mon Sep 17 00:00:00 2001 From: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:59:47 +0100 Subject: [PATCH] Tenant change related integration tests - allow tenant change and retain tenant in shortlink (#736) * Test to ensure when a shortlink is copied, tenant is changed and short link is visited. The tenant from the link is visited. Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * After link copy, allow tenant change Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Addressing comments, removing function to it's own file and removing unneeded code in before. Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Spelling error rectified Signed-off-by: leanneeliatra Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Linting errors resolved Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Update cypress/utils/commands.js Co-authored-by: Yulong Ruan Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Changed data-test-subj to getElementByTestId for consitency Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Switch tenant updated to use interceps and should() for improved test performance Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * switch tenant changed to use intercepts and should() for increaced test performance. Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Adding commen to explain how the addtion of the should() helps Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Global declaration of the tenant removed. The clearing of session storage is not needed actually, cy.visit() does this for us Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Additition of 'createDashboard' method to allow programatic dashboard creation. Also improvements to the test. Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * When testing we are looking for the private tenant. Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * check changed to allow for both 'private' and __user__ Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * linting errors resolved Signed-off-by: leanneeliatra Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * merging in changes on remote Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Adding back --headless parameter. Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * undoing package-lock changes. Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Use library from release tag instead of git reference (#706) The module installed from the OSD test library seems to update or not based on caching issues. Related proposal: https://github.com/opensearch-project/opensearch-dashboards-test-library/issues/36 Signed-off-by: Kawika Avilla Signed-off-by: leanne.laceybyrne@eliatra.com * update testSplitTables test (#731) Signed-off-by: Sirazh Gabdullin Signed-off-by: leanne.laceybyrne@eliatra.com * [Vis Augmenter / Feature Anywhere] Add tests in core OSD and AD plugin (#739) * [Vis Augmenter / Feature Anywhere] Add test suite for vanilla OSD + helper fns for plugins (#725) * feature anywhere initial tests Signed-off-by: Jovan Cvetkovic * Add test suite Signed-off-by: Tyler Ohlsen * Remove unnecessary test case Signed-off-by: Tyler Ohlsen * Optimize getters Signed-off-by: Tyler Ohlsen --------- Signed-off-by: Jovan Cvetkovic Signed-off-by: Tyler Ohlsen Co-authored-by: Jovan Cvetkovic * [Feature Anywhere / Vis Augmenter] Add test flows for integration with AD plugin (#727) * feature anywhere initial tests Signed-off-by: Jovan Cvetkovic * Add test suite Signed-off-by: Tyler Ohlsen * Add AD vis augmenter tests Signed-off-by: Tyler Ohlsen * More refactoring Signed-off-by: Tyler Ohlsen * More tests Signed-off-by: Tyler Ohlsen * Add test for AD cleanup scenario Signed-off-by: Tyler Ohlsen * Set up saved obj test suite Signed-off-by: Tyler Ohlsen * Add reminder TODO Signed-off-by: Tyler Ohlsen * Add tests regarding saved obj visibility Signed-off-by: Tyler Ohlsen * Add view events tests Signed-off-by: Tyler Ohlsen * cleanup Signed-off-by: Tyler Ohlsen * remove import Signed-off-by: Tyler Ohlsen --------- Signed-off-by: Jovan Cvetkovic Signed-off-by: Tyler Ohlsen Co-authored-by: Jovan Cvetkovic --------- Signed-off-by: Jovan Cvetkovic Signed-off-by: Tyler Ohlsen Co-authored-by: Jovan Cvetkovic Signed-off-by: leanne.laceybyrne@eliatra.com * Revert "[Vis Augmenter / Feature Anywhere] Add tests in core OSD and AD plugin (#739)" (#748) This reverts commit 07a67d724710109bd95800dd5ce973e83dbbe10a. Signed-off-by: manasvinibs Signed-off-by: leanne.laceybyrne@eliatra.com * Test sample data with multiple data source enabled on local cluster (#756) Signed-off-by: Kristen Tian Signed-off-by: leanne.laceybyrne@eliatra.com * [Vis Augmenter] Add tests in OSD & AD plugin (#752) * [Vis Augmenter / Feature Anywhere] Add test suite for vanilla OSD + helper fns for plugins (#725) * feature anywhere initial tests Signed-off-by: Jovan Cvetkovic * Add test suite Signed-off-by: Tyler Ohlsen * Remove unnecessary test case Signed-off-by: Tyler Ohlsen * Optimize getters Signed-off-by: Tyler Ohlsen --------- Signed-off-by: Jovan Cvetkovic Signed-off-by: Tyler Ohlsen Co-authored-by: Jovan Cvetkovic * [Feature Anywhere / Vis Augmenter] Add test flows for integration with AD plugin (#727) * feature anywhere initial tests Signed-off-by: Jovan Cvetkovic * Add test suite Signed-off-by: Tyler Ohlsen * Add AD vis augmenter tests Signed-off-by: Tyler Ohlsen * More refactoring Signed-off-by: Tyler Ohlsen * More tests Signed-off-by: Tyler Ohlsen * Add test for AD cleanup scenario Signed-off-by: Tyler Ohlsen * Set up saved obj test suite Signed-off-by: Tyler Ohlsen * Add reminder TODO Signed-off-by: Tyler Ohlsen * Add tests regarding saved obj visibility Signed-off-by: Tyler Ohlsen * Add view events tests Signed-off-by: Tyler Ohlsen * cleanup Signed-off-by: Tyler Ohlsen * remove import Signed-off-by: Tyler Ohlsen --------- Signed-off-by: Jovan Cvetkovic Signed-off-by: Tyler Ohlsen Co-authored-by: Jovan Cvetkovic * Fix NPE Signed-off-by: Tyler Ohlsen * Fix bug of non-empty dashboard; remove unnecessary test Signed-off-by: Tyler Ohlsen * Simplify dashboard creation Signed-off-by: Tyler Ohlsen * Update undefined check Signed-off-by: Tyler Ohlsen --------- Signed-off-by: Jovan Cvetkovic Signed-off-by: Tyler Ohlsen Co-authored-by: Jovan Cvetkovic Signed-off-by: leanne.laceybyrne@eliatra.com * fix: CVE of tough-cookie and word-wrap (#763) Signed-off-by: SuZhou-Joe Signed-off-by: leanne.laceybyrne@eliatra.com * feat: use "overrides" to install desired version of tough-cookie and word-wrap. (#772) * feat: use npm v8 to install and initialize package-lock Signed-off-by: SuZhou-Joe * feat: add Node version requirement in DEVELOPER_GUIDE Signed-off-by: SuZhou-Joe --------- Signed-off-by: SuZhou-Joe Signed-off-by: leanne.laceybyrne@eliatra.com * Improve date selection across versions of OUI (#778) Signed-off-by: Miki Signed-off-by: leanne.laceybyrne@eliatra.com * feat: sync cypress test from notifications-dashboards (#776) (#784) * feat: sync cypress test from notifications-dashboards Signed-off-by: SuZhou-Joe * feat: rename commands Signed-off-by: SuZhou-Joe * feat: update Signed-off-by: SuZhou-Joe * feat: add larger wait time Signed-off-by: SuZhou-Joe * feat: update Signed-off-by: SuZhou-Joe * feat: update Signed-off-by: SuZhou-Joe * feat: update Signed-off-by: SuZhou-Joe * feat: add refresh before delete all notifications configs Signed-off-by: SuZhou-Joe --------- Signed-off-by: SuZhou-Joe (cherry picked from commit 81f70c37fde7b468915b173b0e81f4a609ecea84) Signed-off-by: leanne.laceybyrne@eliatra.com * [Table Visualizations] Tests cleanup (#785) Signed-off-by: Sirazh Gabdullin Signed-off-by: leanne.laceybyrne@eliatra.com * Bump dependency on opensearch-dashboards-test-library (#790) Signed-off-by: Miki Signed-off-by: leanne.laceybyrne@eliatra.com * [Table Visualizations] Test Update (#787) * fix-test * simplify selector --------- Signed-off-by: Sirazh Gabdullin Signed-off-by: leanne.laceybyrne@eliatra.com * fix discover (#803) Signed-off-by: abbyhu2000 Signed-off-by: leanne.laceybyrne@eliatra.com * Change to toast message in Reports (#578) * Change to toast message in Reports download spec Signed-off-by: Kavitha Conjeevaram Mohan * Update test Signed-off-by: Kavitha Conjeevaram Mohan * Fix lint Signed-off-by: Kavitha Conjeevaram Mohan --------- Signed-off-by: Kavitha Conjeevaram Mohan Signed-off-by: leanne.laceybyrne@eliatra.com * fix discover (#807) Signed-off-by: Qingyang(Abby) Hu Signed-off-by: leanne.laceybyrne@eliatra.com * feat: add test cases for remote models (#813) Signed-off-by: Lin Wang Signed-off-by: leanne.laceybyrne@eliatra.com * fix workbench download text and csv schema (#814) (#817) Signed-off-by: Joshua Li (cherry picked from commit 46c0882627b5c8732b48564caf161719c6c3c0c8) Co-authored-by: Joshua Li Signed-off-by: leanne.laceybyrne@eliatra.com * update trace analytics cypress tests according to observability changes (#775) * update ftr Signed-off-by: Derek Ho * revert file Signed-off-by: Derek Ho * update with trace analytics accordian changes Signed-off-by: Derek Ho --------- Signed-off-by: Derek Ho Signed-off-by: leanne.laceybyrne@eliatra.com * Bump semver from 7.3.7 to 7.5.4 (#822) Bumps [semver](https://github.com/npm/node-semver) from 7.3.7 to 7.5.4. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/main/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v7.3.7...v7.5.4) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: leanne.laceybyrne@eliatra.com * [Dashboard] Retry visbuilder dashboard test (#823) Seeing it pass in video replays but occassionally doesn't pass. However, it doesn't pass with security enabled so I'd imagine it could be related to the refreshing of the session. Issue: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/4947 Signed-off-by: Kawika Avilla Signed-off-by: leanne.laceybyrne@eliatra.com * Add new tests for alerting dashboards (#832) Signed-off-by: Ashish Agrawal Signed-off-by: leanne.laceybyrne@eliatra.com * Update source element in import_vector_map_tab.spec.js (#844) * Update source element in import_vector_map_tab.spec.js Signed-off-by: Junqiu Lei * Update source element in import_vector_map_tab.spec.js Signed-off-by: Junqiu Lei --------- Signed-off-by: Junqiu Lei Signed-off-by: leanne.laceybyrne@eliatra.com * Use index pattern id to find page in import_vector_map_tab.spec.js (#847) Signed-off-by: Junqiu Lei Signed-off-by: leanne.laceybyrne@eliatra.com * Buffer `waitForLoader` before checking for icon (#857) (#859) Some async calls occur after navigating and sometimes navigating too quickly prevents the calls from having correct data and therefore the homeIcon is in a bad state. This adds the ability to buffer before checking for the homeIcon. Defaulted to 0 ms, but for `yarn cypress:run-with-security` configures WAIT_FOR_LOADER_BUFFER_MS to be 500 ms Issue resolved: https://github.com/opensearch-project/OpenSearch-Dashboards/issues/5028 Signed-off-by: Kawika Avilla (cherry picked from commit e7c7e59abefa8d17b9d5ee22b9d7c933fdf7b1ad) Co-authored-by: Kawika Avilla Signed-off-by: leanne.laceybyrne@eliatra.com * Overwrite removed and moved to after in unit test Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com * Update dashboard.spec.js Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> * Update dashboard_sample_data_spec.js remove unneeded change Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> --------- Signed-off-by: leanneeliatra Signed-off-by: leanne.laceybyrne@eliatra.com Signed-off-by: leanneeliatra <131779422+leanneeliatra@users.noreply.github.com> Signed-off-by: Kawika Avilla Signed-off-by: Sirazh Gabdullin Signed-off-by: Jovan Cvetkovic Signed-off-by: Tyler Ohlsen Signed-off-by: manasvinibs Signed-off-by: Kristen Tian Signed-off-by: SuZhou-Joe Signed-off-by: Miki Signed-off-by: abbyhu2000 Signed-off-by: Kavitha Conjeevaram Mohan Signed-off-by: Qingyang(Abby) Hu Signed-off-by: Lin Wang Signed-off-by: Derek Ho Signed-off-by: dependabot[bot] Signed-off-by: Ashish Agrawal Signed-off-by: Junqiu Lei Co-authored-by: Yulong Ruan Co-authored-by: Kawika Avilla Co-authored-by: Sirazh Gabdullin Co-authored-by: Tyler Ohlsen Co-authored-by: Jovan Cvetkovic Co-authored-by: Manasvini B Suryanarayana Co-authored-by: Kristen Tian <105667444+kristenTian@users.noreply.github.com> Co-authored-by: SuZhou-Joe Co-authored-by: Miki Co-authored-by: Miki Co-authored-by: Qingyang(Abby) Hu Co-authored-by: Kavitha Conjeevaram Mohan Co-authored-by: Lin Wang Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Co-authored-by: Joshua Li Co-authored-by: Derek Ho Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ashish Agrawal Co-authored-by: Junqiu Lei --- .../change_tenant_successfully.js | 28 ++++ .../switch_tenant.js | 39 +++++ .../tenancy_change_on_shortlink.js | 148 ++++++++++++++++++ cypress/utils/commands.js | 25 ++- cypress/utils/index.d.ts | 14 ++ 5 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 cypress/integration/plugins/security-dashboards-plugin/change_tenant_successfully.js create mode 100644 cypress/integration/plugins/security-dashboards-plugin/switch_tenant.js create mode 100644 cypress/integration/plugins/security-dashboards-plugin/tenancy_change_on_shortlink.js diff --git a/cypress/integration/plugins/security-dashboards-plugin/change_tenant_successfully.js b/cypress/integration/plugins/security-dashboards-plugin/change_tenant_successfully.js new file mode 100644 index 000000000..76e44ae2a --- /dev/null +++ b/cypress/integration/plugins/security-dashboards-plugin/change_tenant_successfully.js @@ -0,0 +1,28 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +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'; + + before(() => { + cy.server(); + }); + it('Checks that the tenant switcher can switch tenants despite a different tenant being present in the tenant query parameter.', function () { + CURRENT_TENANT.newTenant = tenantName; + + cy.visit('/app/home').then(() => { + cy.waitForLoader(); + switchTenantTo('global'); + cy.waitForLoader(); + cy.getElementByTestId('account-popover').click(); + cy.get('#tenantName').should('contain.text', 'Global'); + }); + }); + }); +} diff --git a/cypress/integration/plugins/security-dashboards-plugin/switch_tenant.js b/cypress/integration/plugins/security-dashboards-plugin/switch_tenant.js new file mode 100644 index 000000000..5666eca8f --- /dev/null +++ b/cypress/integration/plugins/security-dashboards-plugin/switch_tenant.js @@ -0,0 +1,39 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export function switchTenantTo(newTenant) { + cy.getElementByTestId('account-popover').click(); + cy.intercept({ + method: 'GET', + url: '/api/v1/auth/dashboardsinfo', + }).as('waitForDashboardsInfo'); + + cy.intercept({ + method: 'GET', + url: '/api/v1/configuration/account', + }).as('waitForAccountInfo'); + + 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.intercept({ + method: 'POST', + url: '/api/v1/multitenancy/tenant', + }).as('waitForUpdatingTenants'); + cy.getElementByTestId('tenant-switch-modal') + .find('[data-test-subj="confirm"]') + .click(); + + cy.wait('@waitForUpdatingTenants'); + + // Make sure dashboards has really reloaded. + // @waitForReloadAfterTenantSwitch should be triggered twice + cy.wait('@waitForDashboardsInfo'); + cy.wait('@waitForDashboardsInfo'); +} diff --git a/cypress/integration/plugins/security-dashboards-plugin/tenancy_change_on_shortlink.js b/cypress/integration/plugins/security-dashboards-plugin/tenancy_change_on_shortlink.js new file mode 100644 index 000000000..eddc3cb94 --- /dev/null +++ b/cypress/integration/plugins/security-dashboards-plugin/tenancy_change_on_shortlink.js @@ -0,0 +1,148 @@ +/* + * 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'; + +if (Cypress.env('SECURITY_ENABLED')) { + describe('Multi Tenancy Tests: ', () => { + before(() => { + cy.server(); + + cy.createIndexPattern( + 'index-pattern1', + { + title: 's*', + timeFieldName: 'timestamp', + }, + indexPatternGlobalTenantHeaderSetUp + ); + + 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', + } + ); + + // 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 + // itself, which would make this test obsolete. + // But it is also hard to get the tests running reliably when opening + // Dashboards without the parameter (tenant selector popup etc.). + // Hence, we do some navigation to "lose" the query parameter. + CURRENT_TENANT.newTenant = 'private'; + cy.visit('/app/home', { + waitForGetTenant: true, + onBeforeLoad(window) { + // set up session storage as we would expect to emulate browser + window.sessionStorage.setItem( + 'opendistro::security::tenant::show_popup', + false + ); + + window.localStorage.setItem( + 'opendistro::security::tenant::saved', + '__user__' + ); + }, + }); + // Navigate to the Dashboards app + cy.getElementByTestId('toggleNavButton').should('be.visible').click(); + // After clicking the navigation, the security_tenant parameter should be gone + cy.get('[href$="/app/dashboards#/list"]').should('be.visible').click(); + + // 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('savedObjectTitle').type(dashboardName); + + cy.intercept({ + method: 'POST', + url: '/api/saved_objects/_bulk_get', + }).as('waitForReloadingDashboard'); + cy.getElementByTestId('confirmSaveSavedObjectButton').click(); + cy.wait('@waitForReloadingDashboard'); + cy.wait(2000); + + // 2. Open top share navigation to access copy short url + cy.getElementByTestId('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'); + + //4. Switch tenant & visit shortURL link to ensure tenant from short URL is retained + cy.getElementByTestId('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. + switchTenantTo('global'); + + // Since we can't reliably read the clipboard data, we have to append the tenant parameter manually + cy.visit(shortUrl + '?security_tenant=private', { + excludeTenant: true, // We are passing the tenant as a query parameter. Mainly because of readability. + onBeforeLoad(window) { + // Here we are simulating the new tab scenario which isn't supported by Cypress + window.sessionStorage.clear(); + }, + }); + + cy.url({ timeout: 10000 }).should('contain', 'security_tenant='); + cy.getElementByTestId('breadcrumb last').should( + 'contain.text', + dashboardName + ); + }); + }); + after(() => { + cy.deleteIndexPattern('index-pattern1', { + headers: { + securitytenant: ['global'], + 'osd-xsrf': true, + }, + }); + cy.deleteIndexPattern('index-pattern2', { + headers: { + securitytenant: ['private'], + 'osd-xsrf': true, + }, + }); + }); + }); +} diff --git a/cypress/utils/commands.js b/cypress/utils/commands.js index cab746dd3..2c9076263 100644 --- a/cypress/utils/commands.js +++ b/cypress/utils/commands.js @@ -46,7 +46,13 @@ Cypress.Commands.overwrite('visit', (orig, url, options) => { auth: ADMIN_AUTH, }; } - newOptions.qs = { security_tenant: CURRENT_TENANT.defaultTenant }; + if (!newOptions.excludeTenant) { + newOptions.qs = { + ...newOptions.qs, + security_tenant: CURRENT_TENANT.defaultTenant, + }; + } + if (waitForGetTenant) { cy.intercept('GET', '/api/v1/multitenancy/tenant').as('getTenant'); orig(url, newOptions); @@ -367,6 +373,23 @@ Cypress.Commands.add('createIndexPattern', (id, attributes, header = {}) => { }); }); +Cypress.Commands.add('createDashboard', (attributes = {}, headers = {}) => { + const url = `${Cypress.config().baseUrl}/api/saved_objects/dashboard`; + + cy.request({ + method: 'POST', + url, + headers: { + 'content-type': 'application/json;charset=UTF-8', + 'osd-xsrf': true, + ...headers, + }, + body: JSON.stringify({ + attributes, + }), + }); +}); + Cypress.Commands.add('changeDefaultTenant', (attributes, header = {}) => { const url = Cypress.env('openSearchUrl') + '/_plugins/_security/api/tenancy/config'; diff --git a/cypress/utils/index.d.ts b/cypress/utils/index.d.ts index d5daf9dfd..8b65b8390 100644 --- a/cypress/utils/index.d.ts +++ b/cypress/utils/index.d.ts @@ -105,6 +105,20 @@ declare namespace Cypress { header: string, ): Chainable; + /** + * Adds a dashboard + * @example + * cy.createDashboard({ title: 'My dashboard'}) + */ + createDashboard( + attributes: { + title: string; + [key: string]: any; + }, + headers?: { + [key: string]: any; + } + ): Chainable; /** * Changes the Default tenant for the domain.