Skip to content

Commit

Permalink
rename the cypress dir and fix lint
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Liang <[email protected]>
  • Loading branch information
RyanL1997 committed Nov 28, 2023
1 parent b899080 commit 9c5dcd3
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 101 deletions.
52 changes: 0 additions & 52 deletions .cypress/support/index.d.ts

This file was deleted.

8 changes: 4 additions & 4 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const login = 'admin';
const password = 'admin';

describe('Log in via OIDC', () => {

afterEach(() => {
cy.origin('http://localhost:5601', () => {
cy.clearCookies();
Expand All @@ -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');
});
});
Expand All @@ -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');
});
});
Expand All @@ -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');

Expand All @@ -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 });

Check warning on line 103 in cypress/e2e/oidc/oidc_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Do not use force on click and type calls

Check warning on line 103 in cypress/e2e/oidc/oidc_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Do not use force on click and type calls

Check warning on line 103 in cypress/e2e/oidc/oidc_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Do not use force on click and type calls

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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -46,52 +46,51 @@ 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');
cy.getCookie('security_authentication').should('exist');
});

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');
cy.getCookie('security_authentication').should('exist');
});

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,
Expand All @@ -103,7 +102,7 @@ describe('Log in via SAML', () => {
cy.get('#private').click({ force: true });

Check warning on line 102 in cypress/e2e/saml/saml_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (ubuntu-latest)

Do not use force on click and type calls

Check warning on line 102 in cypress/e2e/saml/saml_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (macos-latest)

Do not use force on click and type calls

Check warning on line 102 in cypress/e2e/saml/saml_auth_test.spec.js

View workflow job for this annotation

GitHub Actions / Run unit tests (windows-latest)

Do not use force on click and type calls

cy.get('button[data-test-subj="confirm"]').click();

cy.get('#osdOverviewPageHeader__title').should('be.visible');

cy.get('button[id="user-icon-btn"]').click();
Expand Down
22 changes: 10 additions & 12 deletions .cypress/support/commands.js → cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) => {
Expand All @@ -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) => {
Expand Down
File renamed without changes.
File renamed without changes.
55 changes: 55 additions & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
@@ -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"
// / <reference types="cypress" />

declare namespace Cypress {
interface Chainable<Subject> {
/**
* Create a test tenant by calling REST API
* @example
* cy.createTenant('test_tenant', tenantJsonFixture )
*/
createTenant<S = any>(tenantID: string, tenantJson: string): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create an internal user by calling REST API
* @example
* cy.createInternalUser('test_user', userJsonFixture )
*/
createInternalUser<S = any>(userID: string, userJson: string): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create a role by calling REST API
* @example
* cy.createRole('role_name', roleJsonFixture )
*/
createRole<S = any>(roleID: string, roleJson: string): Chainable<S>;
}

interface Chainable<Subject> {
/**
* Create a role mapping by calling REST API
* @example
* cy.createRoleMapping('role_name', rolemappingJsonFixture )
*/
createRoleMapping<S = any>(roleID: string, rolemappingJson: string): Chainable<S>;
}
}

0 comments on commit 9c5dcd3

Please sign in to comment.