From fadc91737d585185c13f221007106c68313a134c Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Thu, 20 Oct 2022 19:37:27 -0400 Subject: [PATCH] Modify the constants path and fix the 'createIndexPattern()' command Signed-off-by: Ryan Liang --- cypress.json | 2 +- .../indexPatternTenantHeader.json | 2 +- .../roles/roleWithTest.json | 40 +++++++------- .../roles/roleWithoutTest.json | 32 ++++++------ .../rolesmapping/kibanauserRoleMapping.json | 6 +-- .../rolesmapping/roleWithTestMapping.json | 2 +- .../rolesmapping/roleWithoutTestMapping.json | 2 +- .../tenants/testTenant.json | 2 +- .../aggregation_view.js | 26 +++++----- cypress/utils/commands.js | 21 +------- cypress/utils/dashboards/constants.js | 8 +++ cypress/utils/index.d.ts | 11 +--- .../security-dashboards-plugin/commands.js | 5 +- .../security-dashboards-plugin/index.d.ts | 52 +++++++++++++++++++ cypress/utils/plugins/security/constants.js | 6 --- 15 files changed, 124 insertions(+), 93 deletions(-) create mode 100644 cypress/utils/plugins/security-dashboards-plugin/index.d.ts diff --git a/cypress.json b/cypress.json index 2179e1cd6..42419584d 100644 --- a/cypress.json +++ b/cypress.json @@ -20,4 +20,4 @@ "VISBUILDER_ENABLED": false, "DATASOURCE_MANAGEMENT_ENABLED": false } -} \ No newline at end of file +} diff --git a/cypress/fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternTenantHeader.json b/cypress/fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternTenantHeader.json index 75bbd655c..2cc458c24 100644 --- a/cypress/fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternTenantHeader.json +++ b/cypress/fixtures/plugins/security-dashboards-plugin/indexpatterns/indexPatternTenantHeader.json @@ -1,3 +1,3 @@ { "securitytenant": ["test"] -} \ No newline at end of file +} diff --git a/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithTest.json b/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithTest.json index 99d0a9be5..6f7c17249 100644 --- a/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithTest.json +++ b/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithTest.json @@ -2,23 +2,23 @@ "cluster_permissions": [ "cluster_all" ], - "index_permissions": [{ - "index_patterns": [ - "*" - ], - "dls": "", - "fls": [], - "masked_fields": [], - "allowed_actions": [ - "indices_all" - ] - }], - "tenant_permissions": [{ - "tenant_patterns": [ - "test" - ], - "allowed_actions": [ - "kibana_all_write" - ] - }] -} \ No newline at end of file + "index_permissions": [{ + "index_patterns": [ + "*" + ], + "dls": "", + "fls": [], + "masked_fields": [], + "allowed_actions": [ + "indices_all" + ] + }], + "tenant_permissions": [{ + "tenant_patterns": [ + "test" + ], + "allowed_actions": [ + "kibana_all_write" + ] + }] +} diff --git a/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithoutTest.json b/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithoutTest.json index 2a2f454aa..e2fb1f663 100644 --- a/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithoutTest.json +++ b/cypress/fixtures/plugins/security-dashboards-plugin/roles/roleWithoutTest.json @@ -2,19 +2,19 @@ "cluster_permissions": [ "cluster_all" ], - "index_permissions": [{ - "index_patterns": [ - "*" - ], - "dls": "", - "fls": [], - "masked_fields": [], - "allowed_actions": [ - "indices_all" - ] - }], - "tenant_permissions": [{ - "tenant_patterns": [], - "allowed_actions": [] - }] - } \ No newline at end of file + "index_permissions": [{ + "index_patterns": [ + "*" + ], + "dls": "", + "fls": [], + "masked_fields": [], + "allowed_actions": [ + "indices_all" + ] + }], + "tenant_permissions": [{ + "tenant_patterns": [], + "allowed_actions": [] + }] +} diff --git a/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/kibanauserRoleMapping.json b/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/kibanauserRoleMapping.json index 872b3a3dc..ffc55576c 100644 --- a/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/kibanauserRoleMapping.json +++ b/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/kibanauserRoleMapping.json @@ -1,4 +1,4 @@ { - "backend_roles" : [ "kibanauser" ], - "users" : [ "test1", "test2" ] - } \ No newline at end of file + "backend_roles" : [ "kibanauser" ], + "users" : [ "test1", "test2" ] +} diff --git a/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithTestMapping.json b/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithTestMapping.json index 1f9a0f3d6..5d5417d57 100644 --- a/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithTestMapping.json +++ b/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithTestMapping.json @@ -1,3 +1,3 @@ { "users" : [ "test1" ] -} \ No newline at end of file +} diff --git a/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithoutTestMapping.json b/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithoutTestMapping.json index 5ffe43731..f8a3c10b7 100644 --- a/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithoutTestMapping.json +++ b/cypress/fixtures/plugins/security-dashboards-plugin/rolesmapping/roleWithoutTestMapping.json @@ -1,3 +1,3 @@ { "users" : [ "test2" ] -} \ No newline at end of file +} diff --git a/cypress/fixtures/plugins/security-dashboards-plugin/tenants/testTenant.json b/cypress/fixtures/plugins/security-dashboards-plugin/tenants/testTenant.json index 695740e4b..343803a12 100644 --- a/cypress/fixtures/plugins/security-dashboards-plugin/tenants/testTenant.json +++ b/cypress/fixtures/plugins/security-dashboards-plugin/tenants/testTenant.json @@ -1,3 +1,3 @@ { "description": "This test tenant for aggregation view feature testing." -} \ No newline at end of file +} diff --git a/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js b/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js index d7fb02219..8c5750a96 100644 --- a/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js +++ b/cypress/integration/plugins/security-dashboards-plugin/aggregation_view.js @@ -5,7 +5,7 @@ import { SAVED_OBJECTS_PATH, -} from '../../../utils/constants'; +} from '../../../utils/dashboards/constants'; import { ADMIN_AUTH, @@ -37,6 +37,17 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { cy.server(); cy.createTenant(tenantName, tenantDescription); + cy.createIndexPattern('index-pattern1', { + title: 's*', + timeFieldName: 'timestamp', + }); + cy.createIndexPattern('index-pattern2', { + title: 'se*', + timeFieldName: 'timestamp', + }, + indexPatternTenantHeaderSetUp + ); + cy.createInternalUser(userName1, testUsersSetUp); cy.createInternalUser(userName2, testUsersSetUp); @@ -47,16 +58,7 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { cy.createRoleMapping(roleName1, roleWithTestMappingSetUp); cy.createRoleMapping(roleName2, roleWithoutTestMappingSetUp); - cy.createIndexPattern('index-pattern1', { - title: 's*', - timeFieldName: 'timestamp', - }); - cy.createIndexPatternWithTenantHeader('index-pattern2', { - title: 'se*', - timeFieldName: 'timestamp', - }, - indexPatternTenantHeaderSetUp - ); + cy.wait(300000); }); it('should check the saved objects as global tenant', () => { @@ -103,4 +105,4 @@ if (Cypress.env('SECURITY_ENABLED') && Cypress.env('AGGREGATION_VIEW')) { CURRENT_TENANT.newTenant = 'private'; }); }); -} \ No newline at end of file +} diff --git a/cypress/utils/commands.js b/cypress/utils/commands.js index b1c09133f..c9d9003cb 100644 --- a/cypress/utils/commands.js +++ b/cypress/utils/commands.js @@ -198,26 +198,7 @@ Cypress.Commands.add('bulkUploadDocs', (fixturePath, index) => { }); }); -Cypress.Commands.add('createIndexPattern', (id, attributes) => { - const url = `${ - Cypress.config().baseUrl - }/api/saved_objects/index-pattern/${id}`; - - cy.request({ - method: 'POST', - url, - headers: { - 'content-type': 'application/json;charset=UTF-8', - 'osd-xsrf': true, - }, - body: JSON.stringify({ - attributes, - references: [], - }), - }); -}); - -Cypress.Commands.add('createIndexPatternWithTenantHeader', (id, attributes, header = {}) => { +Cypress.Commands.add('createIndexPattern', (id, attributes, header = {}) => { const url = `${ Cypress.config().baseUrl }/api/saved_objects/index-pattern/${id}`; diff --git a/cypress/utils/dashboards/constants.js b/cypress/utils/dashboards/constants.js index a850c1690..9b2450cdd 100644 --- a/cypress/utils/dashboards/constants.js +++ b/cypress/utils/dashboards/constants.js @@ -2,3 +2,11 @@ * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ + +import { BASE_PATH } from '../base_constants'; + +// STACK MANAGEMENT PATH +export const STACK_MANAGEMENT_PATH = BASE_PATH + '/app/management'; + +export const INDEX_PATTERN_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/indexPatterns'; +export const SAVED_OBJECTS_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/objects'; diff --git a/cypress/utils/index.d.ts b/cypress/utils/index.d.ts index 6ad99c329..5b314b6e5 100644 --- a/cypress/utils/index.d.ts +++ b/cypress/utils/index.d.ts @@ -46,18 +46,9 @@ declare namespace Cypress { /** * Adds an index pattern * @example - * cy.createIndexPattern('patterId', 'patt*', 'timestamp') + * cy.createIndexPattern('patterId', { title: 'patt*', timeFieldName: 'timestamp' }) */ createIndexPattern( - id: string, - attributes: { - title: string; - timeFieldName?: string; - [key: string]: any; - } - ): Chainable; - - createIndexPatternWithTenantHeader( id: string, attributes: { title: string; diff --git a/cypress/utils/plugins/security-dashboards-plugin/commands.js b/cypress/utils/plugins/security-dashboards-plugin/commands.js index 0717a05bf..4d432210b 100644 --- a/cypress/utils/plugins/security-dashboards-plugin/commands.js +++ b/cypress/utils/plugins/security-dashboards-plugin/commands.js @@ -17,6 +17,7 @@ import { SEC_API } from '../../constants'; `${Cypress.env('openSearchUrl')}${SEC_API.TENANTS_BASE}/${tenantID}`, tenantJson ); + cy.wait(10000); }); Cypress.Commands.add('createInternalUser', (userID, userJson) => { @@ -25,6 +26,7 @@ Cypress.Commands.add('createInternalUser', (userID, userJson) => { `${Cypress.env('openSearchUrl')}${SEC_API.INTERNALUSERS_BASE}/${userID}`, userJson ); + cy.wait(10000); }); Cypress.Commands.add('createRole', (roleID, roleJson) => { @@ -33,6 +35,7 @@ Cypress.Commands.add('createRole', (roleID, roleJson) => { `${Cypress.env('openSearchUrl')}${SEC_API.ROLE_BASE}/${roleID}`, roleJson ); + cy.wait(10000); }); Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => { @@ -41,5 +44,5 @@ Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => { `${Cypress.env('openSearchUrl')}${SEC_API.ROLE_MAPPING_BASE}/${roleID}`, rolemappingJson ); + cy.wait(10000); }); - diff --git a/cypress/utils/plugins/security-dashboards-plugin/index.d.ts b/cypress/utils/plugins/security-dashboards-plugin/index.d.ts new file mode 100644 index 000000000..e54a2991c --- /dev/null +++ b/cypress/utils/plugins/security-dashboards-plugin/index.d.ts @@ -0,0 +1,52 @@ +// 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/utils/plugins/security/constants.js b/cypress/utils/plugins/security/constants.js index 7b31285d4..1f8009ba0 100644 --- a/cypress/utils/plugins/security/constants.js +++ b/cypress/utils/plugins/security/constants.js @@ -65,9 +65,3 @@ export const SEC_API_CACHE_PURGE_PATH = BASE_SEC_API_PATH + '/cache'; export const SEC_API_AUTHINFO_PATH = BASE_PATH + '/api/v1/auth/authinfo'; export const SEC_API_TENANT_PATH = BASE_PATH + '/api/v1/multitenancy/tenant'; - -// STACK MANAGEMENT PATH -export const STACK_MANAGEMENT_PATH = BASE_PATH + '/app/management'; - -export const INDEX_PATTERN_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/indexPatterns'; -export const SAVED_OBJECTS_PATH = STACK_MANAGEMENT_PATH + '/opensearch-dashboards/objects';