Skip to content

Commit

Permalink
Revert "fixes"
Browse files Browse the repository at this point in the history
This reverts commit 0cd226d.
  • Loading branch information
MadameSheema committed Dec 4, 2023
1 parent 0cd226d commit 1c81b5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
38 changes: 17 additions & 21 deletions x-pack/test/security_solution_cypress/cypress/tasks/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { constructUrlWithUser, defaultUser } from './login';
import { constructUrlWithUser, getEnvAuth } from './login';

interface User {
username: string;
Expand Down Expand Up @@ -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);
Expand All @@ -208,20 +209,21 @@ 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);
}
};

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')
Expand All @@ -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')
Expand Down

0 comments on commit 1c81b5e

Please sign in to comment.