Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Security solution] Explore cypress, fix more flakes #173539

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const useOsqueryTab = ({
: undefined;

const responseActions =
expandedEventFieldsObject?.kibana?.alert?.rule?.parameters?.[0].response_actions;
expandedEventFieldsObject?.kibana?.alert?.rule?.parameters?.[0]?.response_actions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this error when fixing Cypress tests for guided onboarding tour
Screenshot 2024-04-22 at 12 48 12


const shouldEarlyReturn =
!rawEventData ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const useResponseActionsView = <T extends object = JSX.Element>({
: undefined;

const responseActions =
expandedEventFieldsObject?.kibana?.alert?.rule?.parameters?.[0].response_actions;
expandedEventFieldsObject?.kibana?.alert?.rule?.parameters?.[0]?.response_actions;
const shouldEarlyReturn = !rawEventData || !responseActionsEnabled;

const alertId = rawEventData?._id ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
*/
import { ROLES, SecurityRoleName } from '@kbn/security-solution-plugin/common/test';

import { getNewRule } from '../../../objects/rule';

import { expandFirstAlertActions } from '../../../tasks/alerts';
import { createRule } from '../../../tasks/api_calls/rules';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
import { login } from '../../../tasks/login';
import { visit } from '../../../tasks/navigation';
import { visitWithTimeRange } from '../../../tasks/navigation';

import { ALERTS_URL } from '../../../urls/navigation';
import { ATTACH_ALERT_TO_CASE_BUTTON, TIMELINE_CONTEXT_MENU_BTN } from '../../../screens/alerts';
Expand All @@ -21,22 +18,32 @@ import { deleteAlertsAndRules } from '../../../tasks/api_calls/common';

const loadDetectionsPage = (role: SecurityRoleName) => {
login(role);
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
waitForAlertsToPopulate();
};

describe('Alerts timeline', { tags: ['@ess'] }, () => {
const cleanKibana = () => {
cy.task('esArchiverUnload', { archiveName: 'query_alert' });
deleteAlertsAndRules();
};

describe('Alerts timeline', { tags: ['@ess', '@serverless'] }, () => {
beforeEach(() => {
// First we login as a privileged user to create alerts.
deleteAlertsAndRules();
createRule(getNewRule());
cleanKibana();
cy.task('esArchiverLoad', { archiveName: 'query_alert', useCreate: true, docsOnly: true });

login();
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
waitForAlertsToPopulate();
});

context('Privileges: read only', () => {
afterEach(() => {
cleanKibana();
});

context('Privileges: read only', { tags: ['@ess'] }, () => {
beforeEach(() => {
// ess only role
loadDetectionsPage(ROLES.reader);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,33 @@ import {
goToStep,
startTour,
} from '../../../tasks/guided_onboarding';
import { createRule } from '../../../tasks/api_calls/rules';
import { getNewRule } from '../../../objects/rule';
import { ALERTS_URL, DASHBOARDS_URL } from '../../../urls/navigation';
import { waitForAlertsToPopulate } from '../../../tasks/create_new_rule';
import { login } from '../../../tasks/login';
import { visit } from '../../../tasks/navigation';
import { visitWithTimeRange } from '../../../tasks/navigation';
import { startAlertsCasesTour } from '../../../tasks/api_calls/tour';
import { deleteAlertsAndRules } from '../../../tasks/api_calls/common';

const cleanUpKibana = () => {
cy.task('esArchiverUnload', { archiveName: 'query_alert' });
deleteAlertsAndRules();
};

describe('Guided onboarding tour', { tags: ['@ess'] }, () => {
beforeEach(() => {
deleteAlertsAndRules();
createRule(getNewRule({ query: 'user.name:*' }));
cleanUpKibana();
cy.task('esArchiverLoad', { archiveName: 'query_alert', useCreate: true, docsOnly: true });
login();
disableExpandableFlyout();
startAlertsCasesTour();
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
waitForAlertsToPopulate();
});

afterEach(() => {
cleanUpKibana();
});

it('Completes the tour with next button clicks', () => {
startTour();
completeTourWithNextButton();
Expand Down