Skip to content

Commit 3b8e067

Browse files
machadoumangorayckibanamachine
authored
[Security Solution] Add cypress test to EA and D&R search bar query (#157149)
## Summary Add cypress tests for EA and D&R search bar query. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Angela Chuang <6295984+angorayc@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 3e88052 commit 3b8e067

File tree

6 files changed

+118
-2
lines changed

6 files changed

+118
-2
lines changed

x-pack/plugins/security_solution/cypress/e2e/dashboards/detection_response.cy.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../../screens/common/filter_group';
1414

1515
import {
16+
ALERTS_DONUT_CHART,
1617
HOST_TABLE_HOST_NAME_BTN,
1718
HOST_TABLE_ROW_SEV,
1819
HOST_TABLE_ROW_TOTAL_ALERTS,
@@ -31,17 +32,63 @@ import { cleanKibana } from '../../tasks/common';
3132
import { investigateDashboardItemInTimeline } from '../../tasks/dashboards/common';
3233
import { waitToNavigateAwayFrom } from '../../tasks/kibana_navigation';
3334
import { login, visit } from '../../tasks/login';
34-
import { navigateFromHeaderTo } from '../../tasks/security_header';
35+
import { clearSearchBar, kqlSearch, navigateFromHeaderTo } from '../../tasks/security_header';
3536
import { closeTimeline } from '../../tasks/timeline';
3637
import { ALERTS_URL, DASHBOARDS_URL, DETECTIONS_RESPONSE_URL } from '../../urls/navigation';
3738

39+
const TEST_USER_NAME = 'test';
40+
const SIEM_KIBANA_HOST_NAME = 'siem-kibana';
41+
3842
describe('Detection response view', () => {
3943
before(() => {
4044
cleanKibana();
4145
login();
4246
createRule(getNewRule());
4347
visit(DETECTIONS_RESPONSE_URL);
4448
});
49+
50+
context('KQL search bar', { testIsolation: false }, () => {
51+
it(`filters out hosts with KQL search bar query`, () => {
52+
kqlSearch(`host.name : fakeHostName{enter}`);
53+
54+
cy.get(HOST_TABLE_ROW_TOTAL_ALERTS).should('have.length', 0);
55+
cy.get(RULE_TABLE_ROW_TOTAL_ALERTS).should('have.length', 0);
56+
cy.get(ALERTS_DONUT_CHART).first().should('have.text', 'Open');
57+
58+
clearSearchBar();
59+
});
60+
61+
it(`finds the host when filtering with KQL search bar query`, () => {
62+
kqlSearch(`host.name : ${SIEM_KIBANA_HOST_NAME}{enter}`);
63+
64+
cy.get(HOST_TABLE_ROW_TOTAL_ALERTS).should('have.length', 1);
65+
cy.get(RULE_TABLE_ROW_TOTAL_ALERTS).should('have.text', 2);
66+
cy.get(ALERTS_DONUT_CHART).first().should('include.text', '2Open');
67+
68+
clearSearchBar();
69+
});
70+
71+
it(`filters out the users with KQL search bar query`, () => {
72+
kqlSearch(`user.name : fakeUserName{enter}`);
73+
74+
cy.get(USER_TABLE_ROW_TOTAL_ALERTS).should('have.length', 0);
75+
cy.get(RULE_TABLE_ROW_TOTAL_ALERTS).should('have.length', 0);
76+
cy.get(ALERTS_DONUT_CHART).first().should('have.text', 'Open');
77+
78+
clearSearchBar();
79+
});
80+
81+
it(`finds the user when filtering with KQL search bar query`, () => {
82+
kqlSearch(`user.name : ${TEST_USER_NAME}{enter}`);
83+
84+
cy.get(USER_TABLE_ROW_TOTAL_ALERTS).should('have.length', 1);
85+
cy.get(RULE_TABLE_ROW_TOTAL_ALERTS).should('have.text', 2);
86+
cy.get(ALERTS_DONUT_CHART).first().should('include.text', '2Open');
87+
88+
clearSearchBar();
89+
});
90+
});
91+
4592
context('Open in timeline', { testIsolation: false }, () => {
4693
afterEach(() => {
4794
closeTimeline();
@@ -67,6 +114,7 @@ describe('Detection response view', () => {
67114
});
68115
});
69116
});
117+
70118
it(`opens timeline with correct query count for users by alert severity table`, () => {
71119
cy.get(USER_TABLE_ROW_TOTAL_ALERTS)
72120
.first()

x-pack/plugins/security_solution/cypress/e2e/dashboards/entity_analytics.cy.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,21 @@ import {
3333
ANOMALIES_TABLE_ENABLE_JOB_LOADER,
3434
ANOMALIES_TABLE_COUNT_COLUMN,
3535
} from '../../screens/entity_analytics';
36-
import { openRiskTableFilterAndSelectTheLowOption } from '../../tasks/host_risk';
36+
import { openRiskTableFilterAndSelectTheLowOption, removeLowFilter } from '../../tasks/host_risk';
3737
import { createRule } from '../../tasks/api_calls/rules';
3838
import { waitForAlertsToPopulate } from '../../tasks/create_new_rule';
3939
import { getNewRule } from '../../objects/rule';
4040
import { clickOnFirstHostsAlerts, clickOnFirstUsersAlerts } from '../../tasks/risk_scores';
4141
import { OPTION_LIST_LABELS, OPTION_LIST_VALUES } from '../../screens/common/filter_group';
4242
import { setRowsPerPageTo } from '../../tasks/table_pagination';
43+
import { clearSearchBar, kqlSearch } from '../../tasks/security_header';
44+
import { setEndDate, setEndDateNow, updateDates } from '../../tasks/date_picker';
4345

4446
const TEST_USER_ALERTS = 2;
4547
const TEST_USER_NAME = 'test';
4648
const SIEM_KIBANA_HOST_ALERTS = 2;
4749
const SIEM_KIBANA_HOST_NAME = 'siem-kibana';
50+
const END_DATE = 'Jan 19, 2019 @ 20:33:29.186';
4851

4952
describe('Entity Analytics Dashboard', () => {
5053
before(() => {
@@ -145,6 +148,17 @@ describe('Entity Analytics Dashboard', () => {
145148

146149
cy.get(HOSTS_DONUT_CHART).should('include.text', '1Total');
147150
cy.get(HOSTS_TABLE_ROWS).should('have.length', 1);
151+
152+
removeLowFilter();
153+
});
154+
155+
it('filters the host risk table with KQL search bar query', () => {
156+
kqlSearch(`host.name : ${SIEM_KIBANA_HOST_NAME}{enter}`);
157+
158+
cy.get(HOSTS_DONUT_CHART).should('include.text', '1Total');
159+
cy.get(HOSTS_TABLE_ROWS).should('have.length', 1);
160+
161+
clearSearchBar();
148162
});
149163

150164
describe('With alerts data', () => {
@@ -166,6 +180,17 @@ describe('Entity Analytics Dashboard', () => {
166180
cy.get(HOSTS_TABLE_ALERT_CELL).first().should('include.text', SIEM_KIBANA_HOST_ALERTS);
167181
});
168182

183+
it('filters the alerts count with time range', () => {
184+
setEndDate(END_DATE);
185+
updateDates();
186+
187+
cy.get(HOSTS_TABLE_ALERT_CELL).first().should('include.text', 0);
188+
189+
// CLEAR DATES
190+
setEndDateNow();
191+
updateDates();
192+
});
193+
169194
it('opens alerts page when alerts count is clicked', () => {
170195
clickOnFirstHostsAlerts();
171196
cy.url().should('include', ALERTS_URL);
@@ -209,6 +234,17 @@ describe('Entity Analytics Dashboard', () => {
209234

210235
cy.get(USERS_DONUT_CHART).should('include.text', '2Total');
211236
cy.get(USERS_TABLE_ROWS).should('have.length', 2);
237+
238+
removeLowFilter();
239+
});
240+
241+
it('filters the host risk table with KQL search bar query', () => {
242+
kqlSearch(`user.name : ${TEST_USER_NAME}{enter}`);
243+
244+
cy.get(USERS_DONUT_CHART).should('include.text', '1Total');
245+
cy.get(USERS_TABLE_ROWS).should('have.length', 1);
246+
247+
clearSearchBar();
212248
});
213249

214250
describe('With alerts data', () => {
@@ -230,6 +266,17 @@ describe('Entity Analytics Dashboard', () => {
230266
cy.get(USERS_TABLE_ALERT_CELL).first().should('include.text', TEST_USER_ALERTS);
231267
});
232268

269+
it('filters the alerts count with time range', () => {
270+
setEndDate(END_DATE);
271+
updateDates();
272+
273+
cy.get(USERS_TABLE_ALERT_CELL).first().should('include.text', 0);
274+
275+
// CLEAR DATES
276+
setEndDateNow();
277+
updateDates();
278+
});
279+
233280
it('opens alerts page when alerts count is clicked', () => {
234281
clickOnFirstUsersAlerts();
235282

x-pack/plugins/security_solution/cypress/screens/date_picker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export const DATE_PICKER_APPLY_BUTTON_TIMELINE =
1515

1616
export const DATE_PICKER_ABSOLUTE_TAB = '[data-test-subj="superDatePickerAbsoluteTab"]';
1717

18+
export const DATE_PICKER_NOW_TAB = '[data-test-subj="superDatePickerNowTab"]';
19+
20+
export const DATE_PICKER_NOW_BUTTON = '[data-test-subj="superDatePickerNowButton"]';
21+
1822
export const DATE_PICKER_END_DATE_POPOVER_BUTTON =
1923
'[data-test-subj="globalDatePicker"] [data-test-subj="superDatePickerendDatePopoverButton"]';
2024

x-pack/plugins/security_solution/cypress/screens/detection_response.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ export const RULE_TABLE_VIEW_ALL_OPEN_ALERTS_BTN = getDataTestSubjectSelector(
3939
export const RULE_TABLE_ROW_RULE_NAME_BTN = getDataTestSubjectSelector(
4040
'severityRuleAlertsTable-name'
4141
);
42+
43+
export const ALERTS_DONUT_CHART =
44+
'[data-test-subj="detection-response-alerts-by-status-panel"] [data-test-subj="donut-chart"]';

x-pack/plugins/security_solution/cypress/tasks/date_picker.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
SHOW_DATES_BUTTON,
1818
DATE_PICKER_START_DATE_POPOVER_BUTTON_TIMELINE,
1919
DATE_PICKER_SHOW_DATE_POPOVER_BUTTON,
20+
DATE_PICKER_NOW_TAB,
21+
DATE_PICKER_NOW_BUTTON,
2022
} from '../screens/date_picker';
2123

2224
export const setEndDate = (date: string) => {
@@ -27,6 +29,14 @@ export const setEndDate = (date: string) => {
2729
cy.get(DATE_PICKER_ABSOLUTE_INPUT).click().clear().type(date);
2830
};
2931

32+
export const setEndDateNow = () => {
33+
cy.get(DATE_PICKER_END_DATE_POPOVER_BUTTON).click({ force: true });
34+
35+
cy.get(DATE_PICKER_NOW_TAB).first().click({ force: true });
36+
37+
cy.get(DATE_PICKER_NOW_BUTTON).click();
38+
};
39+
3040
export const setStartDate = (date: string) => {
3141
cy.get(GLOBAL_FILTERS_CONTAINER);
3242
cy.get('.euiSuperDatePicker');

x-pack/plugins/security_solution/cypress/tasks/host_risk.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const openRiskTableFilterAndSelectTheLowOption = () => {
3030
cy.get(HOST_BY_RISK_TABLE_FILTER_LOW).click();
3131
};
3232

33+
export const removeLowFilter = () => {
34+
cy.get(HOST_BY_RISK_TABLE_FILTER_LOW).click();
35+
};
36+
3337
export const removeCriticalFilter = () => {
3438
cy.get(HOST_BY_RISK_TABLE_FILTER_CRITICAL).click();
3539
};

0 commit comments

Comments
 (0)