Skip to content

Commit

Permalink
[SIEM] Inspect readable (#56110)
Browse files Browse the repository at this point in the history
* extracts methods to tasks

* uses cypress api for assertions

* refactor

* Inspect refactor

* fixes rebase issue
  • Loading branch information
MadameSheema authored Jan 28, 2020
1 parent ecc8240 commit 24ac6d2
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ import {
INSPECT_MODAL,
INSPECT_NETWORK_BUTTONS_IN_SIEM,
INSPECT_HOSTS_BUTTONS_IN_SIEM,
TIMELINE_SETTINGS_ICON,
TIMELINE_INSPECT_BUTTON,
} from '../../lib/inspect/selectors';
import { DEFAULT_TIMEOUT, loginAndWaitForPage } from '../../lib/util/helpers';
import { executeKQL, hostExistsQuery, toggleTimelineVisibility } from '../../lib/timeline/helpers';
import { closesModal, openStatsAndTables } from '../../lib/inspect/helpers';
} from '../../../screens/inspect';
import {
executeTimelineKQL,
openTimeline,
openTimelineSettings,
openTimelineInspectButton,
} from '../../../tasks/timeline/main';
import { DEFAULT_TIMEOUT, loginAndWaitForPage } from '../../../tasks/login';
import { closesModal, openStatsAndTables } from '../../../tasks/inspect';

describe('Inspect', () => {
context('Hosts stats and tables', () => {
Expand Down Expand Up @@ -51,12 +54,12 @@ describe('Inspect', () => {

context('Timeline', () => {
it('inspects the timeline', () => {
const hostExistsQuery = 'host.name: *';
loginAndWaitForPage(HOSTS_PAGE);
toggleTimelineVisibility();
executeKQL(hostExistsQuery);
cy.get(TIMELINE_SETTINGS_ICON).trigger('click', { force: true });
cy.get(TIMELINE_INSPECT_BUTTON, { timeout: DEFAULT_TIMEOUT }).should('not.be.disabled');
cy.get(TIMELINE_INSPECT_BUTTON).trigger('click', { force: true });
openTimeline();
executeTimelineKQL(hostExistsQuery);
openTimelineSettings();
openTimelineInspectButton();
cy.get(INSPECT_MODAL, { timeout: DEFAULT_TIMEOUT }).should('be.visible');
});
});
Expand Down
87 changes: 87 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/screens/inspect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const INSPECT_BUTTON_ICON = '[data-test-subj="inspect-icon-button"]';
export const INSPECT_MODAL = '[data-test-subj="modal-inspect-euiModal"]';

export interface InspectButtonMetadata {
altInspectId?: string;
id: string;
title: string;
tabId?: string;
}

export const INSPECT_HOSTS_BUTTONS_IN_SIEM: InspectButtonMetadata[] = [
{
id: '[data-test-subj="stat-hosts"]',
title: 'Hosts Stat',
},
{
id: '[data-test-subj="stat-authentication"]',
title: 'User Authentications Stat',
},
{
id: '[data-test-subj="stat-uniqueIps"]',
title: 'Unique IPs Stat',
},
{
id: '[data-test-subj="table-allHosts-loading-false"]',
title: 'All Hosts Table',
tabId: '[data-test-subj="navigation-allHosts"]',
},
{
id: '[data-test-subj="table-authentications-loading-false"]',
title: 'Authentications Table',
tabId: '[data-test-subj="navigation-authentications"]',
},
{
id: '[data-test-subj="table-uncommonProcesses-loading-false"]',
title: 'Uncommon processes Table',
tabId: '[data-test-subj="navigation-uncommonProcesses"]',
},
{
altInspectId: `[data-test-subj="events-viewer-panel"] ${INSPECT_BUTTON_ICON}`,
id: '[data-test-subj="events-container-loading-false"]',
title: 'Events Table',
tabId: '[data-test-subj="navigation-events"]',
},
];

export const INSPECT_NETWORK_BUTTONS_IN_SIEM: InspectButtonMetadata[] = [
{
id: '[data-test-subj="stat-networkEvents"]',
title: 'Network events Stat',
},
{
id: '[data-test-subj="stat-dnsQueries"]',
title: 'DNS queries Stat',
},
{
id: '[data-test-subj="stat-uniqueFlowId"]',
title: 'Unique flow IDs Stat',
},
{
id: '[data-test-subj="stat-tlsHandshakes"]',
title: 'TLS handshakes Stat',
},
{
id: '[data-test-subj="stat-UniqueIps"]',
title: 'Unique private IPs Stat',
},
{
id: '[data-test-subj="table-topNFlowSource-loading-false"]',
title: 'Source IPs Table',
},
{
id: '[data-test-subj="table-topNFlowDestination-loading-false"]',
title: 'Destination IPs Table',
},
{
id: '[data-test-subj="table-dns-loading-false"]',
title: 'Top DNS Domains Table',
tabId: '[data-test-subj="navigation-dns"]',
},
];
4 changes: 4 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/screens/timeline/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export const TIMELINE_FIELDS_BUTTON =

/** The total server-side count of the events matching the timeline's search criteria */
export const SERVER_SIDE_EVENT_COUNT = '[data-test-subj="server-side-event-count"]';

export const TIMELINE_SETTINGS_ICON = '[data-test-subj="settings-gear"]';

export const TIMELINE_INSPECT_BUTTON = '[data-test-subj="inspect-empty-button"]';
29 changes: 29 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/tasks/inspect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { INSPECT_BUTTON_ICON, InspectButtonMetadata } from '../screens/inspect';

import { DEFAULT_TIMEOUT } from '../tasks/login';

export const closesModal = () => {
cy.get('[data-test-subj="modal-inspect-close"]', { timeout: DEFAULT_TIMEOUT }).click();
};

export const openStatsAndTables = (table: InspectButtonMetadata) => {
if (table.tabId) {
cy.get(table.tabId).click({ force: true });
}
cy.get(table.id, { timeout: DEFAULT_TIMEOUT });
if (table.altInspectId) {
cy.get(table.altInspectId, { timeout: DEFAULT_TIMEOUT }).trigger('click', {
force: true,
});
} else {
cy.get(`${table.id} ${INSPECT_BUTTON_ICON}`, {
timeout: DEFAULT_TIMEOUT,
}).trigger('click', { force: true });
}
};
15 changes: 15 additions & 0 deletions x-pack/legacy/plugins/siem/cypress/tasks/timeline/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
SEARCH_OR_FILTER_CONTAINER,
TIMELINE_FIELDS_BUTTON,
SERVER_SIDE_EVENT_COUNT,
TIMELINE_SETTINGS_ICON,
TIMELINE_INSPECT_BUTTON,
} from '../../screens/timeline/main';

export const hostExistsQuery = 'host.name: *';
Expand All @@ -29,3 +31,16 @@ export const populateTimeline = () => {
export const openTimelineFieldsBrowser = () => {
cy.get(TIMELINE_FIELDS_BUTTON).click({ force: true });
};

export const executeTimelineKQL = (query: string) => {
cy.get(`${SEARCH_OR_FILTER_CONTAINER} input`).type(`${query} {enter}`);
};

export const openTimelineSettings = () => {
cy.get(TIMELINE_SETTINGS_ICON).trigger('click', { force: true });
};

export const openTimelineInspectButton = () => {
cy.get(TIMELINE_INSPECT_BUTTON, { timeout: DEFAULT_TIMEOUT }).should('not.be.disabled');
cy.get(TIMELINE_INSPECT_BUTTON).trigger('click', { force: true });
};

0 comments on commit 24ac6d2

Please sign in to comment.