Skip to content

Commit

Permalink
clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
MadameSheema committed Dec 4, 2023
1 parent c446690 commit b23f7a7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
23 changes: 0 additions & 23 deletions x-pack/test/security_solution_cypress/cypress/tasks/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,6 @@ export const loginWithUser = (user: User): void => {
});
};

/**
* Builds a URL with basic auth using the passed in user.
*
* @param user the user information to build the basic auth with
* @param route string route to visit
*/
export const constructUrlWithUser = (user: User, route: string): string => {
const url = Cypress.config().baseUrl;
const kibana = new URL(String(url));
const hostname = kibana.hostname;
const username = user.username;
const password = user.password;
const protocol = kibana.protocol.replace(':', '');
const port = kibana.port;

const path = `${route.startsWith('/') ? '' : '/'}${route}`;
const strUrl = `${protocol}://${username}:${password}@${hostname}:${port}${path}`;
const builtUrl = new URL(strUrl);

cy.log(`origin: ${builtUrl.href}`);
return builtUrl.href;
};

export const logout = (): void => {
cy.visit(LOGOUT_URL);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { constructUrlWithUser, defaultUser } from './login';
import { API_AUTH } from './api_calls/common';

interface User {
username: string;
Expand Down Expand Up @@ -189,7 +189,8 @@ export const createUsersAndRoles = (users: User[], roles: Role[]) => {
body: role.privileges,
headers: { 'kbn-xsrf': 'cypress-creds', 'x-elastic-internal-origin': 'security-solution' },
method: 'PUT',
url: constructUrlWithUser(defaultUser, `/api/security/role/${role.name}`),
auth: API_AUTH,
url: `/api/security/role/${role.name}`,
})
.its('status')
.should('eql', 204);
Expand All @@ -208,7 +209,8 @@ 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}`),
auth: API_AUTH,
url: `/internal/security/users/${user.username}`,
})
.its('status')
.should('eql', 200);
Expand All @@ -221,7 +223,8 @@ 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, `/internal/security/users/${user.username}`),
auth: API_AUTH,
url: `/internal/security/users/${user.username}`,
failOnStatusCode: false,
})
.its('status')
Expand All @@ -233,7 +236,8 @@ 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}`),
auth: API_AUTH,
url: `/api/security/role/${role.name}`,
failOnStatusCode: false,
})
.its('status')
Expand Down

0 comments on commit b23f7a7

Please sign in to comment.