From 1c81b5e7d597d6d10c602aed822c17efd18909a2 Mon Sep 17 00:00:00 2001 From: Gloria Hornero <gloria.hornero@elastic.co> Date: Mon, 4 Dec 2023 17:36:32 +0100 Subject: [PATCH] Revert "fixes" This reverts commit 0cd226dfc87654d8e93f4108070b9c9d558e30e2. --- .../e2e/explore/cases/privileges.cy.ts | 2 - .../cypress/tasks/login.ts | 38 +++++++++---------- .../cypress/tasks/privileges.ts | 12 +++--- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/x-pack/test/security_solution_cypress/cypress/e2e/explore/cases/privileges.cy.ts b/x-pack/test/security_solution_cypress/cypress/e2e/explore/cases/privileges.cy.ts index 9da268aebb306..88a3a258a3697 100644 --- a/x-pack/test/security_solution_cypress/cypress/e2e/explore/cases/privileges.cy.ts +++ b/x-pack/test/security_solution_cypress/cypress/e2e/explore/cases/privileges.cy.ts @@ -65,8 +65,6 @@ describe('Cases privileges', { tags: ['@ess'] }, () => { for (const user of [secAllUser, secReadCasesAllUser, secAllCasesNoDeleteUser]) { it(`User ${user.username} with role(s) ${user.roles.join()} can create a case`, () => { - cy.log('asdfasdfasdf'); - cy.log(user); login(user); visit(CASES_URL); goToCreateNewCase(); diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/login.ts b/x-pack/test/security_solution_cypress/cypress/tasks/login.ts index 57f5d39b66691..461ce4db1c423 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/login.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/login.ts @@ -21,31 +21,27 @@ export interface User { password: string; } -export const defaultUser: User = { - username: Cypress.env(ELASTICSEARCH_USERNAME), - password: Cypress.env(ELASTICSEARCH_PASSWORD), -}; - -export const getEnvAuth = (role: SecurityRoleName): User => { - if ( - (Cypress.env(IS_SERVERLESS) || Cypress.env(CLOUD_SERVERLESS)) && - !(role in KNOWN_SERVERLESS_ROLE_DEFINITIONS) - ) { - throw new Error(`An attempt to log in with unsupported by Serverless role "${role}".`); - } +export const getEnvAuth = (role?: SecurityRoleName): User => { const user: User = { - username: role, - password: 'changeme', + username: Cypress.env(ELASTICSEARCH_USERNAME), + password: Cypress.env(ELASTICSEARCH_PASSWORD), }; - return user; -}; - -export const login = (user: User = defaultUser, role?: SecurityRoleName): void => { - let testUser = user; if (role) { - testUser = getEnvAuth(role); + if ( + (Cypress.env(IS_SERVERLESS) || Cypress.env(CLOUD_SERVERLESS)) && + !(role in KNOWN_SERVERLESS_ROLE_DEFINITIONS) + ) { + throw new Error(`An attempt to log in with unsupported by Serverless role "${role}".`); + } + user.username = role; + user.password = 'changeme'; } + return user; +}; + +export const login = (role?: SecurityRoleName, testUser?: User): void => { + const user = testUser ? testUser : getEnvAuth(role); const baseUrl = Cypress.config().baseUrl; if (!baseUrl) { @@ -67,7 +63,7 @@ export const login = (user: User = defaultUser, role?: SecurityRoleName): void = providerType: basicProvider?.type, providerName: basicProvider?.name, currentURL: '/', - params: { username: testUser.username, password: testUser.password }, + params: { username: user.username, password: user.password }, }, headers: API_HEADERS, }); diff --git a/x-pack/test/security_solution_cypress/cypress/tasks/privileges.ts b/x-pack/test/security_solution_cypress/cypress/tasks/privileges.ts index 6164f682904e4..19c056cfba8e3 100644 --- a/x-pack/test/security_solution_cypress/cypress/tasks/privileges.ts +++ b/x-pack/test/security_solution_cypress/cypress/tasks/privileges.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { constructUrlWithUser, defaultUser } from './login'; +import { constructUrlWithUser, getEnvAuth } from './login'; interface User { username: string; @@ -183,13 +183,14 @@ const getUserInfo = (user: User): UserInfo => ({ }); export const createUsersAndRoles = (users: User[], roles: Role[]) => { + const envUser = getEnvAuth(); for (const role of roles) { cy.log(`Creating role: ${JSON.stringify(role)}`); cy.request({ body: role.privileges, headers: { 'kbn-xsrf': 'cypress-creds', 'x-elastic-internal-origin': 'security-solution' }, method: 'PUT', - url: constructUrlWithUser(defaultUser, `/api/security/role/${role.name}`), + url: constructUrlWithUser(envUser, `/api/security/role/${role.name}`), }) .its('status') .should('eql', 204); @@ -208,7 +209,7 @@ export const createUsersAndRoles = (users: User[], roles: Role[]) => { }, headers: { 'kbn-xsrf': 'cypress-creds', 'x-elastic-internal-origin': 'security-solution' }, method: 'POST', - url: constructUrlWithUser(defaultUser, `/internal/security/users/${user.username}`), + url: constructUrlWithUser(envUser, `/internal/security/users/${user.username}`), }) .its('status') .should('eql', 200); @@ -216,12 +217,13 @@ export const createUsersAndRoles = (users: User[], roles: Role[]) => { }; export const deleteUsersAndRoles = (users: User[], roles: Role[]) => { + const envUser = getEnvAuth(); for (const user of users) { cy.log(`Deleting user: ${JSON.stringify(user)}`); cy.request({ headers: { 'kbn-xsrf': 'cypress-creds', 'x-elastic-internal-origin': 'security-solution' }, method: 'DELETE', - url: constructUrlWithUser(defaultUser, `/internal/security/users/${user.username}`), + url: constructUrlWithUser(envUser, `/internal/security/users/${user.username}`), failOnStatusCode: false, }) .its('status') @@ -233,7 +235,7 @@ export const deleteUsersAndRoles = (users: User[], roles: Role[]) => { cy.request({ headers: { 'kbn-xsrf': 'cypress-creds', 'x-elastic-internal-origin': 'security-solution' }, method: 'DELETE', - url: constructUrlWithUser(defaultUser, `/api/security/role/${role.name}`), + url: constructUrlWithUser(envUser, `/api/security/role/${role.name}`), failOnStatusCode: false, }) .its('status')