Skip to content

Commit

Permalink
[Security Solution][Explore] Fixes failing test in MKI environments (#…
Browse files Browse the repository at this point in the history
…186116)

Fix: #179231

##Summary

When we changed the default role used in Cypress from `admin` to
`platform_engineer`, the
`x-pack/test/security_solution_cypress/cypress/e2e/explore/cases/creation.cy.ts`
test started to fail in MKI environments.

The test was failing in both assertions for MKI environments:

cy.get(CASE_DETAILS_USERNAMES).eq(REPORTER).should('contain', username);
cy.get(CASE_DETAILS_USERNAMES).eq(PARTICIPANTS).should('contain',
username);

This was happening because we were hardcoding the username and this is a
thing we should not be doing anymore since we are making the test prone
to failures.

In this PR we are fixing that behavior by using a method that retrieves
the correct value.
  • Loading branch information
MadameSheema authored Jun 26, 2024
1 parent bbafad4 commit 8ada1ac
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,21 @@ import {
fillCasesMandatoryfields,
filterStatusOpen,
} from '../../../tasks/create_new_case';
import { login } from '../../../tasks/login';
import { visit, visitWithTimeRange } from '../../../tasks/navigation';

import { CASES_URL, OVERVIEW_URL } from '../../../urls/navigation';
import { ELASTICSEARCH_USERNAME, IS_SERVERLESS } from '../../../env_var_names_constants';
import { deleteCases } from '../../../tasks/api_calls/cases';
import { login } from '../../../tasks/login';

// https://github.com/elastic/kibana/issues/179231
const isServerless = Cypress.env(IS_SERVERLESS);
const username = isServerless ? 'platform_engineer' : Cypress.env(ELASTICSEARCH_USERNAME);
const getUsername = () => {
if (isServerless) {
return cy.task('getFullname');
} else {
return cy.wrap(Cypress.env(ELASTICSEARCH_USERNAME));
}
};

// Tracked by https://github.com/elastic/security-team/issues/7696
describe('Cases', { tags: ['@ess', '@serverless'] }, () => {
Expand Down Expand Up @@ -109,12 +114,17 @@ describe('Cases', { tags: ['@ess', '@serverless'] }, () => {
cy.get(CASE_DETAILS_PAGE_TITLE).should('have.text', this.mycase.name);
cy.get(CASE_DETAILS_STATUS).should('have.text', 'Open');
cy.get(CASE_DETAILS_USER_ACTION_DESCRIPTION_EVENT).should('have.text', 'Description');

cy.get(CASE_DETAILS_DESCRIPTION).should(
'have.text',
`${this.mycase.description} ${this.mycase.timeline.title}`
);
cy.get(CASE_DETAILS_USERNAMES).eq(REPORTER).should('contain', username);
cy.get(CASE_DETAILS_USERNAMES).eq(PARTICIPANTS).should('contain', username);

getUsername().then((username) => {
cy.get(CASE_DETAILS_USERNAMES).eq(REPORTER).should('contain', username);
cy.get(CASE_DETAILS_USERNAMES).eq(PARTICIPANTS).should('contain', username);
});

cy.get(CASE_DETAILS_TAGS).should('have.text', expectedTags);

EXPECTED_METRICS.forEach((metric) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* 2.0.
*/

import { ROLES } from '@kbn/security-solution-plugin/common/test';

/**
* The `CYPRESS_ELASTICSEARCH_USERNAME` environment variable specifies the
* username to be used when authenticating with Kibana
Expand All @@ -28,3 +30,9 @@ export const IS_SERVERLESS = 'IS_SERVERLESS';
* environment is a real MKI.
*/
export const CLOUD_SERVERLESS = 'CLOUD_SERVERLESS';

/**
* The `DEFAULT_SERVERLESS_ROLE` environment variable specifies the default role used
* on serverless tests/
*/
export const DEFAULT_SERVERLESS_ROLE = ROLES.platform_engineer;
20 changes: 18 additions & 2 deletions x-pack/test/security_solution_cypress/cypress/support/saml_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ToolingLog } from '@kbn/tooling-log';

import { SecurityRoleName } from '@kbn/security-solution-plugin/common/test';
import { HostOptions, SamlSessionManager } from '@kbn/test';
import { DEFAULT_SERVERLESS_ROLE } from '../env_var_names_constants';

export const samlAuthentication = async (
on: Cypress.PluginEvents,
Expand All @@ -28,10 +29,11 @@ export const samlAuthentication = async (
password: config.env.ELASTICSEARCH_PASSWORD,
};

// If config.env.PROXY_ORG is set, it means that proxy service is used to create projects. Define the proxy org filename to override the roles.
const rolesFilename = config.env.PROXY_ORG ? `${config.env.PROXY_ORG}.json` : undefined;

on('task', {
getSessionCookie: async (role: string | SecurityRoleName): Promise<string> => {
// If config.env.PROXY_ORG is set, it means that proxy service is used to create projects. Define the proxy org filename to override the roles.
const rolesFilename = config.env.PROXY_ORG ? `${config.env.PROXY_ORG}.json` : undefined;
const sessionManager = new SamlSessionManager(
{
hostOptions,
Expand All @@ -42,5 +44,19 @@ export const samlAuthentication = async (
);
return sessionManager.getSessionCookieForRole(role);
},
getFullname: async (
role: string | SecurityRoleName = DEFAULT_SERVERLESS_ROLE
): Promise<string> => {
const sessionManager = new SamlSessionManager(
{
hostOptions,
log,
isCloud: config.env.CLOUD_SERVERLESS,
},
rolesFilename
);
const { full_name: fullName } = await sessionManager.getUserData(role);
return fullName;
},
});
};
3 changes: 2 additions & 1 deletion x-pack/test/security_solution_cypress/cypress/tasks/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { KNOWN_SERVERLESS_ROLE_DEFINITIONS } from '@kbn/security-solution-plugin
import { LOGOUT_URL } from '../urls/navigation';
import {
CLOUD_SERVERLESS,
DEFAULT_SERVERLESS_ROLE,
ELASTICSEARCH_PASSWORD,
ELASTICSEARCH_USERNAME,
IS_SERVERLESS,
Expand Down Expand Up @@ -45,7 +46,7 @@ export const login = (role?: SecurityRoleName): void => {

if (Cypress.env(IS_SERVERLESS)) {
if (!role) {
testRole = 'platform_engineer';
testRole = DEFAULT_SERVERLESS_ROLE;
} else {
testRole = role;
}
Expand Down

0 comments on commit 8ada1ac

Please sign in to comment.