From 80192ed1346088b2c58d1643e1b0123d817d8c76 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Wed, 22 Nov 2023 11:23:12 -0800 Subject: [PATCH] Set up utils for customize commands Signed-off-by: Ryan Liang --- .cypress/utils/commands.js | 30 ++++++++++++++++++++++++++++++ .cypress/utils/constants.js | 34 ++++++++++++++++++++++++++++++++++ .cypress/utils/index.d.ts | 16 ++++++++++++++++ cypress.config.js | 3 +++ 4 files changed, 83 insertions(+) create mode 100644 .cypress/utils/commands.js create mode 100644 .cypress/utils/constants.js create mode 100644 .cypress/utils/index.d.ts diff --git a/.cypress/utils/commands.js b/.cypress/utils/commands.js new file mode 100644 index 000000000..7291d4060 --- /dev/null +++ b/.cypress/utils/commands.js @@ -0,0 +1,30 @@ +/* + * 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. + */ + +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { SEC_API } from "./constants"; + +Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => { + cy.request( + 'PUT', + `${Cypress.env('openSearchUrl')}${SEC_API.ROLE_MAPPING_BASE}/${roleID}`, + rolemappingJson + ); + cy.wait(10000); +}); diff --git a/.cypress/utils/constants.js b/.cypress/utils/constants.js new file mode 100644 index 000000000..b2bef6afc --- /dev/null +++ b/.cypress/utils/constants.js @@ -0,0 +1,34 @@ +/* + * 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. + */ + +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + ***************************** + SECURITY DASHBOARDS PLUGIN CONSTANTS + ***************************** + */ + +//Security API Constants +export const SEC_API_PREFIX = '/_plugins/_security/api'; +export const SEC_API = { + TENANTS_BASE: `${SEC_API_PREFIX}/tenants`, + INTERNALUSERS_BASE: `${SEC_API_PREFIX}/internalusers`, + ROLE_BASE: `${SEC_API_PREFIX}/roles`, + ROLE_MAPPING_BASE: `${SEC_API_PREFIX}/rolesmapping`, +}; diff --git a/.cypress/utils/index.d.ts b/.cypress/utils/index.d.ts new file mode 100644 index 000000000..385ca69fd --- /dev/null +++ b/.cypress/utils/index.d.ts @@ -0,0 +1,16 @@ +// type definitions for custom commands like "createDefaultTodos" +/// + +declare namespace Cypress { + interface Chainable { + /** + * Create a role mapping by calling REST API + * @example + * cy.createRoleMapping('role_name', rolemappingJsonFixture ) + */ + createRoleMapping( + roleID: string, + rolemappingJson: string + ): Chainable; + } +} \ No newline at end of file diff --git a/cypress.config.js b/cypress.config.js index d4c9c3742..14de9819e 100644 --- a/cypress.config.js +++ b/cypress.config.js @@ -27,4 +27,7 @@ module.exports = defineConfig({ baseUrl: 'http://localhost:5601', specPattern: '.cypress/e2e/**/*.spec.js', }, + env: { + openSearchUrl: 'https://localhost:9200', + }, });