From 88b1e6523f40b22601f1ab2802a04113e76795c4 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Fri, 24 Nov 2023 10:54:55 -0800 Subject: [PATCH] Add more security commands Signed-off-by: Ryan Liang --- .cypress/support/commands.js | 27 +++++++++++++++++++++ .cypress/support/index.d.ts | 46 ++++++++++++++++++++++++++++++++---- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/.cypress/support/commands.js b/.cypress/support/commands.js index dcd94d171..fa6b6e6c7 100644 --- a/.cypress/support/commands.js +++ b/.cypress/support/commands.js @@ -41,6 +41,33 @@ Cypress.Commands.overwrite('request', (originalFn, ...args) => { return originalFn(Object.assign({}, defaults, options)); }); +Cypress.Commands.add('createTenant', (tenantID, tenantJson) => { + cy.request( + 'PUT', + `${Cypress.env('openSearchUrl')}${SEC_API.TENANTS_BASE}/${tenantID}`, + tenantJson + ); + cy.wait(10000); +}); + +Cypress.Commands.add('createInternalUser', (userID, userJson) => { + cy.request( + 'PUT', + `${Cypress.env('openSearchUrl')}${SEC_API.INTERNALUSERS_BASE}/${userID}`, + userJson + ); + cy.wait(10000); +}); + +Cypress.Commands.add('createRole', (roleID, roleJson) => { + cy.request( + 'PUT', + `${Cypress.env('openSearchUrl')}${SEC_API.ROLE_BASE}/${roleID}`, + roleJson + ); + cy.wait(10000); +}); + Cypress.Commands.add('createRoleMapping', (roleID, rolemappingJson) => { cy.request( 'PUT', diff --git a/.cypress/support/index.d.ts b/.cypress/support/index.d.ts index 3a6ba4f71..e54a2991c 100644 --- a/.cypress/support/index.d.ts +++ b/.cypress/support/index.d.ts @@ -2,15 +2,51 @@ /// 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; + createRoleMapping( + roleID: string, + rolemappingJson: string + ): Chainable; } -} \ No newline at end of file +}