From 9c5dcd3c62906b724b14df81df207b69b33dcab6 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Tue, 28 Nov 2023 09:40:00 -0800 Subject: [PATCH] rename the cypress dir and fix lint Signed-off-by: Ryan Liang --- .cypress/support/index.d.ts | 52 ------------------ cypress.config.js | 8 +-- .../e2e/oidc/oidc_auth_test.spec.js | 39 +++++++------ .../e2e/saml/saml_auth_test.spec.js | 25 ++++----- .../fixtures/saml/samlUserRoleMappiing.json | 0 {.cypress => cypress}/support/commands.js | 22 ++++---- {.cypress => cypress}/support/constants.js | 0 {.cypress => cypress}/support/e2e.js | 0 cypress/support/index.d.ts | 55 +++++++++++++++++++ 9 files changed, 100 insertions(+), 101 deletions(-) delete mode 100644 .cypress/support/index.d.ts rename {.cypress => cypress}/e2e/oidc/oidc_auth_test.spec.js (85%) rename {.cypress => cypress}/e2e/saml/saml_auth_test.spec.js (85%) rename {.cypress => cypress}/fixtures/saml/samlUserRoleMappiing.json (100%) rename {.cypress => cypress}/support/commands.js (84%) rename {.cypress => cypress}/support/constants.js (100%) rename {.cypress => cypress}/support/e2e.js (100%) create mode 100644 cypress/support/index.d.ts diff --git a/.cypress/support/index.d.ts b/.cypress/support/index.d.ts deleted file mode 100644 index e54a2991c..000000000 --- a/.cypress/support/index.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -// type definitions for custom commands like "createDefaultTodos" -/// - -declare namespace Cypress { - interface Chainable { - /** - * Create a test tenant by calling REST API - * @example - * cy.createTenant('test_tenant', tenantJsonFixture ) - */ - createTenant( - tenantID: string, - tenantJson: string - ): Chainable; - } - - interface Chainable { - /** - * Create an internal user by calling REST API - * @example - * cy.createInternalUser('test_user', userJsonFixture ) - */ - createInternalUser( - userID: string, - userJson: string - ): Chainable; - } - - interface Chainable { - /** - * Create a role by calling REST API - * @example - * cy.createRole('role_name', roleJsonFixture ) - */ - createRole( - roleID: string, - roleJson: string - ): Chainable; - } - - interface Chainable { - /** - * Create a role mapping by calling REST API - * @example - * cy.createRoleMapping('role_name', rolemappingJsonFixture ) - */ - createRoleMapping( - roleID: string, - rolemappingJson: string - ): Chainable; - } -} diff --git a/cypress.config.js b/cypress.config.js index 77941deca..dd03c02d8 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -16,16 +16,16 @@ const { defineConfig } = require('cypress'); module.exports = defineConfig({ - screenshotsFolder: '.cypress/screenshots', - downloadsFolder: '.cypress/downloads', + screenshotsFolder: 'cypress/screenshots', + downloadsFolder: 'cypress/downloads', defaultCommandTimeout: 60000, requestTimeout: 60000, responseTimeout: 60000, e2e: { setupNodeEvents(on, config) {}, - supportFile: '.cypress/support/e2e.js', + supportFile: 'cypress/support/e2e.js', baseUrl: 'http://localhost:5601', - specPattern: '.cypress/e2e/**/*.spec.js', + specPattern: 'cypress/e2e/**/*.spec.js', }, env: { openSearchUrl: 'https://localhost:9200', diff --git a/.cypress/e2e/oidc/oidc_auth_test.spec.js b/cypress/e2e/oidc/oidc_auth_test.spec.js similarity index 85% rename from .cypress/e2e/oidc/oidc_auth_test.spec.js rename to cypress/e2e/oidc/oidc_auth_test.spec.js index fde4e6e47..b4c5c80d2 100644 --- a/.cypress/e2e/oidc/oidc_auth_test.spec.js +++ b/cypress/e2e/oidc/oidc_auth_test.spec.js @@ -22,7 +22,6 @@ const login = 'admin'; const password = 'admin'; describe('Log in via OIDC', () => { - afterEach(() => { cy.origin('http://localhost:5601', () => { cy.clearCookies(); @@ -41,15 +40,15 @@ describe('Log in via OIDC', () => { cy.visit('http://localhost:5601/app/opensearch_dashboards_overview', { failOnStatusCode: false, }); - + kcLogin(); cy.origin('http://localhost:5601', () => { - localStorage.setItem("opendistro::security::tenant::saved", "\"\""); - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('opendistro::security::tenant::saved', '""'); + localStorage.setItem('home:newThemeModal:show', 'false'); cy.get('#osdOverviewPageHeader__title').should('be.visible'); - + cy.getCookie('security_authentication').should('exist'); }); }); @@ -62,13 +61,13 @@ describe('Log in via OIDC', () => { kcLogin(); cy.origin('http://localhost:5601', () => { - localStorage.setItem("opendistro::security::tenant::saved", "\"\""); - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('opendistro::security::tenant::saved', '""'); + localStorage.setItem('home:newThemeModal:show', 'false'); cy.visit('http://localhost:5601/app/dev_tools#/console'); - + cy.get('a').contains('Dev Tools').should('be.visible'); - + cy.getCookie('security_authentication').should('exist'); }); }); @@ -81,8 +80,8 @@ describe('Log in via OIDC', () => { kcLogin(); cy.origin('http://localhost:5601', () => { - localStorage.setItem("opendistro::security::tenant::saved", "\"\""); - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('opendistro::security::tenant::saved', '""'); + localStorage.setItem('home:newThemeModal:show', 'false'); cy.get('.euiHeader.euiHeader--default.euiHeader--fixed.primaryHeader').should('be.visible'); @@ -91,33 +90,33 @@ describe('Log in via OIDC', () => { }); it('Tenancy persisted after logout in OIDC', () => { - cy.visit('http://localhost:5601/app/opensearch_dashboards_overview#/', { + cy.visit('http://localhost:5601/app/opensearch_dashboards_overview#/', { failOnStatusCode: false, }); kcLogin(); cy.origin('http://localhost:5601', () => { - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('home:newThemeModal:show', 'false'); cy.get('#private').should('be.enabled'); cy.get('#private').click({ force: true }); cy.get('button[data-test-subj="confirm"]').click(); - + cy.get('#osdOverviewPageHeader__title').should('be.visible'); - + cy.get('button[id="user-icon-btn"]').click(); cy.get('button[data-test-subj^="log-out-"]').click(); - }); + }); + + kcLogin(); - kcLogin(); - - cy.origin('http://localhost:5601', () => { + cy.origin('http://localhost:5601', () => { cy.get('#user-icon-btn').should('be.visible'); cy.get('#user-icon-btn').click(); - + cy.get('#osdOverviewPageHeader__title').should('be.visible'); cy.get('#tenantName').should('have.text', 'Private'); diff --git a/.cypress/e2e/saml/saml_auth_test.spec.js b/cypress/e2e/saml/saml_auth_test.spec.js similarity index 85% rename from .cypress/e2e/saml/saml_auth_test.spec.js rename to cypress/e2e/saml/saml_auth_test.spec.js index b5060a186..925256ee8 100644 --- a/.cypress/e2e/saml/saml_auth_test.spec.js +++ b/cypress/e2e/saml/saml_auth_test.spec.js @@ -20,7 +20,7 @@ import { ALL_ACCESS_ROLE } from '../../support/constants'; -import samlUserRoleMapping from '../../fixtures/saml/samlUserRoleMappiing.json' +import samlUserRoleMapping from '../../fixtures/saml/samlUserRoleMappiing.json'; before(() => { cy.intercept('https://localhost:9200'); @@ -46,13 +46,13 @@ describe('Log in via SAML', () => { }; it('Login to app/opensearch_dashboards_overview#/ when SAML is enabled', () => { - localStorage.setItem("opendistro::security::tenant::saved", "\"__user__\""); - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('opendistro::security::tenant::saved', '"__user__"'); + localStorage.setItem('home:newThemeModal:show', 'false'); cy.visit('http://localhost:5601/app/opensearch_dashboards_overview', { failOnStatusCode: false, }); - + samlLogin(); cy.get('#osdOverviewPageHeader__title').should('be.visible'); @@ -60,13 +60,13 @@ describe('Log in via SAML', () => { }); it('Login to app/dev_tools#/console when SAML is enabled', () => { - localStorage.setItem("opendistro::security::tenant::saved", "\"__user__\""); - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('opendistro::security::tenant::saved', '"__user__"'); + localStorage.setItem('home:newThemeModal:show', 'false'); cy.visit('http://localhost:5601/app/dev_tools#/console', { failOnStatusCode: false, }); - + samlLogin(); cy.get('a.euiBreadcrumb--last').contains('Dev Tools'); @@ -74,24 +74,23 @@ describe('Log in via SAML', () => { }); it('Login to Dashboard with Hash', () => { - localStorage.setItem("opendistro::security::tenant::saved", "\"__user__\""); - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('opendistro::security::tenant::saved', '"__user__"'); + localStorage.setItem('home:newThemeModal:show', 'false'); const urlWithHash = `http://localhost:5601/app/security-dashboards-plugin#/getstarted`; cy.visit(urlWithHash, { failOnStatusCode: false, }); - + samlLogin(); cy.get('h1.euiTitle--large').contains('Get started'); cy.getCookie('security_authentication').should('exist'); - }); it('Tenancy persisted after logout in SAML', () => { - localStorage.setItem("home:newThemeModal:show", "false"); + localStorage.setItem('home:newThemeModal:show', 'false'); cy.visit('http://localhost:5601/app/opensearch_dashboards_overview', { failOnStatusCode: false, @@ -103,7 +102,7 @@ describe('Log in via SAML', () => { cy.get('#private').click({ force: true }); cy.get('button[data-test-subj="confirm"]').click(); - + cy.get('#osdOverviewPageHeader__title').should('be.visible'); cy.get('button[id="user-icon-btn"]').click(); diff --git a/.cypress/fixtures/saml/samlUserRoleMappiing.json b/cypress/fixtures/saml/samlUserRoleMappiing.json similarity index 100% rename from .cypress/fixtures/saml/samlUserRoleMappiing.json rename to cypress/fixtures/saml/samlUserRoleMappiing.json diff --git a/.cypress/support/commands.js b/cypress/support/commands.js similarity index 84% rename from .cypress/support/commands.js rename to cypress/support/commands.js index 2c2dcc8f4..ade3591cf 100644 --- a/.cypress/support/commands.js +++ b/cypress/support/commands.js @@ -18,18 +18,18 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { SEC_API, ADMIN_AUTH } from "./constants"; +import { SEC_API, ADMIN_AUTH } from './constants'; /** * Overwrite request command to support authentication similar to visit. * The request function parameters can be url, or (method, url), or (method, url, body). */ Cypress.Commands.overwrite('request', (originalFn, ...args) => { - let defaults = {}; - defaults.auth = ADMIN_AUTH; + const defaults = {}; + defaults.auth = ADMIN_AUTH; let options = {}; if (typeof args[0] === 'object' && args[0] !== null) { - options = Object.assign({}, args[0]); + options = { ...args[0] }; } else if (args.length === 1) { [options.url] = args; } else if (args.length === 2) { @@ -38,7 +38,7 @@ Cypress.Commands.overwrite('request', (originalFn, ...args) => { [options.method, options.url, options.body] = args; } - return originalFn(Object.assign({}, defaults, options)); + return originalFn({ ...defaults, ...options }); }); Cypress.Commands.add('createTenant', (tenantID, tenantJson) => { @@ -62,13 +62,11 @@ Cypress.Commands.add('createInternalUser', (userID, userJson) => { }); Cypress.Commands.add('createRole', (roleID, roleJson) => { - cy.request( - 'PUT', - `${Cypress.env('openSearchUrl')}${SEC_API.ROLE_BASE}/${roleID}`, - roleJson - ).then((response) => { - expect(response.status).to.eq(200); - }); + cy.request('PUT', `${Cypress.env('openSearchUrl')}${SEC_API.ROLE_BASE}/${roleID}`, roleJson).then( + (response) => { + expect(response.status).to.eq(200); + } + ); }); Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => { diff --git a/.cypress/support/constants.js b/cypress/support/constants.js similarity index 100% rename from .cypress/support/constants.js rename to cypress/support/constants.js diff --git a/.cypress/support/e2e.js b/cypress/support/e2e.js similarity index 100% rename from .cypress/support/e2e.js rename to cypress/support/e2e.js diff --git a/cypress/support/index.d.ts b/cypress/support/index.d.ts new file mode 100644 index 000000000..61362a8c4 --- /dev/null +++ b/cypress/support/index.d.ts @@ -0,0 +1,55 @@ +/* + * Copyright OpenSearch Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +// type definitions for custom commands like "createDefaultTodos" +// / + +declare namespace Cypress { + interface Chainable { + /** + * Create a test tenant by calling REST API + * @example + * cy.createTenant('test_tenant', tenantJsonFixture ) + */ + createTenant(tenantID: string, tenantJson: string): Chainable; + } + + interface Chainable { + /** + * Create an internal user by calling REST API + * @example + * cy.createInternalUser('test_user', userJsonFixture ) + */ + createInternalUser(userID: string, userJson: string): Chainable; + } + + interface Chainable { + /** + * Create a role by calling REST API + * @example + * cy.createRole('role_name', roleJsonFixture ) + */ + createRole(roleID: string, roleJson: string): Chainable; + } + + interface Chainable { + /** + * Create a role mapping by calling REST API + * @example + * cy.createRoleMapping('role_name', rolemappingJsonFixture ) + */ + createRoleMapping(roleID: string, rolemappingJson: string): Chainable; + } +}