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] Refactor Cypress tests navigation utilities #166201

Merged
merged 18 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
* 2.0.
*/

import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';
import { openTimelineUsingToggle } from '../../tasks/security_main';
import { openTimelineFieldsBrowser, populateTimeline } from '../../tasks/timeline';

import { HOSTS_URL, ALERTS_URL } from '../../urls/navigation';
import { hostsUrl, ALERTS_URL } from '../../urls/navigation';

import { createRule } from '../../tasks/api_calls/rules';

Expand Down Expand Up @@ -40,7 +41,7 @@ describe(
});

it('adds field to alert table', () => {
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
createRule(getNewRule());
refreshPage();
waitForAlertsToPopulate();
Expand All @@ -50,7 +51,7 @@ describe(
});

it('adds field to timeline', () => {
visit(HOSTS_URL);
visitWithTimeRange(hostsUrl('allHosts'));
openTimelineUsingToggle();
populateTimeline();
openTimelineFieldsBrowser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@

import { DEFAULT_INDEX_PATTERN } from '@kbn/security-solution-plugin/common/constants';

import { login, loginWithUser, visit, visitWithUser } from '../../tasks/login';
import { login, loginWithUser } from '../../tasks/login';
import { visitWithTimeRange, visitWithUser } from '../../tasks/navigation';

import { HOSTS_URL } from '../../urls/navigation';
import { hostsUrl } from '../../urls/navigation';
import {
addIndexToDefault,
deselectSourcererOptions,
Expand Down Expand Up @@ -49,7 +50,7 @@ describe('Sourcerer', { tags: ['@ess', '@serverless', '@skipInServerless'] }, ()
});
it(`role(s) ${secReadCasesAllUser.roles.join()} shows error when user does not have permissions`, () => {
loginWithUser(secReadCasesAllUser);
visitWithUser(HOSTS_URL, secReadCasesAllUser);
visitWithUser(hostsUrl('allHosts'), secReadCasesAllUser);
cy.get(TOASTER).should('have.text', 'Write role required to generate data');
});
});
Expand All @@ -60,7 +61,7 @@ describe('Sourcerer', { tags: ['@ess', '@serverless', '@skipInServerless'] }, ()
beforeEach(() => {
cy.clearLocalStorage();
login();
visit(HOSTS_URL);
visitWithTimeRange(hostsUrl('allHosts'));
});

it('correctly loads SIEM data view', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
DEFAULT_INDEX_PATTERN,
} from '@kbn/security-solution-plugin/common/constants';

import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';

import { TIMELINES_URL } from '../../urls/navigation';
import {
Expand Down Expand Up @@ -43,7 +44,7 @@ describe.skip('Timeline scope', { tags: ['@ess', '@serverless', '@brokenInServer
beforeEach(() => {
cy.clearLocalStorage();
login();
visit(TIMELINES_URL);
visitWithTimeRange(TIMELINES_URL);
});

it('correctly loads SIEM data view', () => {
Expand Down Expand Up @@ -108,7 +109,7 @@ describe.skip('Timeline scope', { tags: ['@ess', '@serverless', '@brokenInServer

beforeEach(() => {
login();
visit(TIMELINES_URL);
visitWithTimeRange(TIMELINES_URL);
refreshUntilAlertsIndexExists();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
DEFAULT_INDEX_PATTERN,
} from '@kbn/security-solution-plugin/common/constants';

import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';

import { TIMELINES_URL } from '../../urls/navigation';
import {
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('Timeline scope', { tags: ['@ess', '@serverless', '@brokenInServerless'
beforeEach(() => {
cy.clearLocalStorage();
login();
visit(TIMELINES_URL);
visitWithTimeRange(TIMELINES_URL);
});

it('correctly loads SIEM data view', () => {
Expand Down Expand Up @@ -108,7 +109,7 @@ describe('Timeline scope', { tags: ['@ess', '@serverless', '@brokenInServerless'

beforeEach(() => {
login();
visit(TIMELINES_URL);
visitWithTimeRange(TIMELINES_URL);
refreshUntilAlertsIndexExists();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
} from '../../tasks/alerts';
import { createRule } from '../../tasks/api_calls/rules';
import { cleanKibana, deleteAlertsAndRules } from '../../tasks/common';
import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';
import { ALERTS_URL } from '../../urls/navigation';
import { waitForAlertsToPopulate } from '../../tasks/create_new_rule';
import {
Expand All @@ -36,7 +37,7 @@ describe('Alert tagging', { tags: ['@ess', '@serverless', '@brokenInServerless']
deleteAlertsAndRules();
cy.task('esArchiverLoad', { archiveName: 'endpoint' });
createRule(getNewRule({ rule_id: 'new custom rule' }));
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
waitForAlertsToPopulate();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
} from '../../tasks/alerts';
import { createRule } from '../../tasks/api_calls/rules';
import { cleanKibana } from '../../tasks/common';
import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';
import { ALERTS_URL } from '../../urls/navigation';
import {
GLOBAL_SEARCH_BAR_FILTER_ITEM,
Expand All @@ -38,7 +39,7 @@ describe(
beforeEach(() => {
login();
createRule(getNewRule({ rule_id: 'new custom rule' }));
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
selectAlertsHistogram();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

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

import { DETECTIONS_RULE_MANAGEMENT_URL, ALERTS_URL, ruleDetailsUrl } from '../../urls/navigation';
import { ALERTS_URL } from '../../urls/navigation';
import { RULES_MANAGEMENT_URL } from '../../urls/rules_management';
import { ruleDetailsUrl } from '../../urls/rule_details';
import { getNewRule } from '../../objects/rule';
import { PAGE_TITLE } from '../../screens/common/page';

import { login, visitWithoutDateRange, waitForPageWithoutDateRange } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visit } from '../../tasks/navigation';

import { createRule, deleteCustomRule } from '../../tasks/api_calls/rules';
import {
getCallOut,
Expand All @@ -21,7 +25,7 @@ import {

const loadPageAsPlatformEngineerUser = (url: string) => {
login(ROLES.soc_manager);
waitForPageWithoutDateRange(url, ROLES.soc_manager);
visit(url, { role: ROLES.soc_manager });
waitForPageTitleToBeShown();
};

Expand All @@ -38,7 +42,7 @@ describe(
// First, we have to open the app on behalf of a privileged user in order to initialize it.
// Otherwise the app will be disabled and show a "welcome"-like page.
login();
visitWithoutDateRange(ALERTS_URL);
visit(ALERTS_URL);
waitForPageTitleToBeShown();
});

Expand Down Expand Up @@ -70,7 +74,7 @@ describe(

context('On Rules Management page', () => {
beforeEach(() => {
loadPageAsPlatformEngineerUser(DETECTIONS_RULE_MANAGEMENT_URL);
loadPageAsPlatformEngineerUser(RULES_MANAGEMENT_URL);
});

it('We show 1 primary callout of need admin', () => {
Expand Down Expand Up @@ -119,7 +123,7 @@ describe(

context('On Rules Management page', () => {
beforeEach(() => {
loadPageAsPlatformEngineerUser(DETECTIONS_RULE_MANAGEMENT_URL);
loadPageAsPlatformEngineerUser(RULES_MANAGEMENT_URL);
});

it('We show 1 primary callout of need admin', () => {
Expand Down Expand Up @@ -168,7 +172,7 @@ describe(

context('On Rules Management page', () => {
beforeEach(() => {
loadPageAsPlatformEngineerUser(DETECTIONS_RULE_MANAGEMENT_URL);
loadPageAsPlatformEngineerUser(RULES_MANAGEMENT_URL);
});

it('We show 1 primary callout of need admin', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { disableExpandableFlyout } from '../../tasks/api_calls/kibana_advanced_settings';
import { getNewThreatIndicatorRule, indicatorRuleMatchingDoc } from '../../objects/rule';
import { cleanKibana } from '../../tasks/common';
import { login, visitWithoutDateRange } from '../../tasks/login';
import { login } from '../../tasks/login';
import {
JSON_TEXT,
TABLE_CELL,
Expand All @@ -23,9 +23,7 @@ import { TIMELINE_FIELD } from '../../screens/rule_details';
import { expandFirstAlert, setEnrichmentDates, viewThreatIntelTab } from '../../tasks/alerts';
import { createRule } from '../../tasks/api_calls/rules';
import { openJsonView, openThreatIndicatorDetails } from '../../tasks/alerts_details';

import { ruleDetailsUrl } from '../../urls/navigation';
import { addsFieldsToTimeline } from '../../tasks/rule_details';
import { addsFieldsToTimeline, visitRuleDetailsPage } from '../../tasks/rule_details';

// TODO: https://github.com/elastic/kibana/issues/161539
describe('CTI Enrichment', { tags: ['@ess', '@serverless', '@brokenInServerless'] }, () => {
Expand All @@ -47,7 +45,7 @@ describe('CTI Enrichment', { tags: ['@ess', '@serverless', '@brokenInServerless'
beforeEach(() => {
login();
createRule({ ...getNewThreatIndicatorRule(), rule_id: 'rule_testing', enabled: true }).then(
(rule) => visitWithoutDateRange(ruleDetailsUrl(rule.body.id))
(rule) => visitRuleDetailsPage(rule.body.id)
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import {
} from '../../tasks/alerts';
import { disableExpandableFlyout } from '../../tasks/api_calls/kibana_advanced_settings';

import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';

import { ALERTS_URL } from '../../urls/navigation';

Expand All @@ -48,7 +49,7 @@ describe('Enrichment', { tags: ['@ess', '@serverless', '@brokenInServerless'] },
deleteAlertsAndRules();
createRule(getNewRule({ rule_id: 'rule1' }));
login();
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
waitForAlertsToPopulate();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@

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

import { DETECTIONS_RULE_MANAGEMENT_URL, ALERTS_URL, ruleDetailsUrl } from '../../urls/navigation';
import { ALERTS_URL } from '../../urls/navigation';
import { RULES_MANAGEMENT_URL } from '../../urls/rules_management';
import { getNewRule } from '../../objects/rule';
import { PAGE_TITLE } from '../../screens/common/page';

import { login, visitWithoutDateRange, waitForPageWithoutDateRange } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visit } from '../../tasks/navigation';
import { createRule, deleteCustomRule } from '../../tasks/api_calls/rules';
import {
getCallOut,
waitForCallOutToBeShown,
dismissCallOut,
MISSING_PRIVILEGES_CALLOUT,
} from '../../tasks/common/callouts';
import { ruleDetailsUrl } from '../../urls/rule_details';

const loadPageAsReadOnlyUser = (url: string) => {
login(ROLES.reader);
waitForPageWithoutDateRange(url, ROLES.reader);
visit(url, { role: ROLES.reader });
waitForPageTitleToBeShown();
};

const loadPageAsPlatformEngineer = (url: string) => {
login(ROLES.platform_engineer);
waitForPageWithoutDateRange(url, ROLES.platform_engineer);
visit(url, { role: ROLES.platform_engineer });
waitForPageTitleToBeShown();
};

Expand All @@ -47,7 +50,7 @@ describe('Detections > Callouts', { tags: ['@ess', '@skipInServerless'] }, () =>
// First, we have to open the app on behalf of a privileged user in order to initialize it.
// Otherwise the app will be disabled and show a "welcome"-like page.
login();
visitWithoutDateRange(ALERTS_URL);
visit(ALERTS_URL);
waitForPageTitleToBeShown();
});

Expand Down Expand Up @@ -115,7 +118,7 @@ describe('Detections > Callouts', { tags: ['@ess', '@skipInServerless'] }, () =>
context('On Rules Management page', () => {
beforeEach(() => {
login(ROLES.platform_engineer);
loadPageAsPlatformEngineer(DETECTIONS_RULE_MANAGEMENT_URL);
loadPageAsPlatformEngineer(RULES_MANAGEMENT_URL);
});

it('We show no callout', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { waitForAlertsToPopulate } from '../../tasks/create_new_rule';
import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';

import { ALERTS_URL, TIMELINES_URL } from '../../urls/navigation';
import { ALERTS_HISTOGRAM_SERIES, ALERT_RULE_NAME, MESSAGE } from '../../screens/alerts';
Expand All @@ -30,7 +31,7 @@ describe(
describe('Ransomware display in Alerts Section', () => {
beforeEach(() => {
login();
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
waitForAlertsToPopulate();
});

Expand All @@ -54,7 +55,7 @@ describe(
describe('Ransomware in Timelines', () => {
before(() => {
login();
visit(TIMELINES_URL);
visitWithTimeRange(TIMELINES_URL);
createTimeline();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import { waitForAlertsToPopulate } from '../../tasks/create_new_rule';
import { login, visit } from '../../tasks/login';
import { login } from '../../tasks/login';
import { visitWithTimeRange } from '../../tasks/navigation';

import { ALERTS_URL, TIMELINES_URL } from '../../urls/navigation';
import { ALERTS_HISTOGRAM_SERIES, ALERT_RULE_NAME, MESSAGE } from '../../screens/alerts';
Expand Down Expand Up @@ -36,7 +37,7 @@ describe(
describe('Ransomware display in Alerts Section', () => {
beforeEach(() => {
login();
visit(ALERTS_URL);
visitWithTimeRange(ALERTS_URL);
waitForAlertsToPopulate();
});

Expand All @@ -60,7 +61,7 @@ describe(
describe('Ransomware in Timelines', () => {
beforeEach(() => {
login();
visit(TIMELINES_URL);
visitWithTimeRange(TIMELINES_URL);

createTimeline();
});
Expand Down