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

Improves the formatting of array values and JSON in the Event and Alert Details panels #115141

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.
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 @@ -5,14 +5,14 @@
* 2.0.
*/

import { ALERT_FLYOUT, CELL_TEXT, JSON_LINES, TABLE_ROWS } from '../../screens/alerts_details';
import { ALERT_FLYOUT, CELL_TEXT, JSON_TEXT, TABLE_ROWS } from '../../screens/alerts_details';

import {
expandFirstAlert,
waitForAlertsIndexToBeCreated,
waitForAlertsPanelToBeLoaded,
} from '../../tasks/alerts';
import { openJsonView, openTable, scrollJsonViewToBottom } from '../../tasks/alerts_details';
import { openJsonView, openTable } from '../../tasks/alerts_details';
import { createCustomRuleActivated } from '../../tasks/api_calls/rules';
import { cleanKibana } from '../../tasks/common';
import { esArchiverLoad } from '../../tasks/es_archiver';
Expand All @@ -36,20 +36,14 @@ describe('Alert details with unmapped fields', () => {
});

it('Displays the unmapped field on the JSON view', () => {
const expectedUnmappedField = { line: 2, text: ' "unmapped": "This is the unmapped field"' };
const expectedUnmappedValue = 'This is the unmapped field';

openJsonView();
scrollJsonViewToBottom();

cy.get(ALERT_FLYOUT)
.find(JSON_LINES)
.then((elements) => {
const length = elements.length;
cy.wrap(elements)
.eq(length - expectedUnmappedField.line)
.invoke('text')
.should('include', expectedUnmappedField.text);
});
cy.get(JSON_TEXT).then((x) => {
const parsed = JSON.parse(x.text());
expect(parsed._source.unmapped).to.equal(expectedUnmappedValue);
});
});

it('Displays the unmapped field on the table', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { cleanKibana, reload } from '../../tasks/common';
import { esArchiverLoad, esArchiverUnload } from '../../tasks/es_archiver';
import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
import {
JSON_LINES,
JSON_TEXT,
TABLE_CELL,
TABLE_ROWS,
THREAT_DETAILS_VIEW,
Expand All @@ -28,11 +28,7 @@ import {
viewThreatIntelTab,
} from '../../tasks/alerts';
import { createCustomIndicatorRule } from '../../tasks/api_calls/rules';
import {
openJsonView,
openThreatIndicatorDetails,
scrollJsonViewToBottom,
} from '../../tasks/alerts_details';
import { openJsonView, openThreatIndicatorDetails } from '../../tasks/alerts_details';

import { ALERTS_URL } from '../../urls/navigation';
import { addsFieldsToTimeline } from '../../tasks/rule_details';
Expand Down Expand Up @@ -76,26 +72,39 @@ describe('CTI Enrichment', () => {

it('Displays persisted enrichments on the JSON view', () => {
const expectedEnrichment = [
{ line: 4, text: ' "threat": {' },
{
line: 3,
text: ' "enrichments": "{\\"indicator\\":{\\"first_seen\\":\\"2021-03-10T08:02:14.000Z\\",\\"file\\":{\\"size\\":80280,\\"pe\\":{},\\"type\\":\\"elf\\",\\"hash\\":{\\"sha256\\":\\"a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3\\",\\"tlsh\\":\\"6D7312E017B517CC1371A8353BED205E9128223972AE35302E97528DF957703BAB2DBE\\",\\"ssdeep\\":\\"1536:87vbq1lGAXSEYQjbChaAU2yU23M51DjZgSQAvcYkFtZTjzBht5:8D+CAXFYQChaAUk5ljnQssL\\",\\"md5\\":\\"9b6c3518a91d23ed77504b5416bfb5b3\\"}},\\"type\\":\\"file\\"},\\"matched\\":{\\"atomic\\":\\"a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3\\",\\"field\\":\\"myhash.mysha256\\",\\"id\\":\\"84cf452c1e0375c3d4412cb550bd1783358468a3b3b777da4829d72c7d6fb74f\\",\\"index\\":\\"logs-ti_abusech.malware\\",\\"type\\":\\"indicator_match_rule\\"}}"',
indicator: {
first_seen: '2021-03-10T08:02:14.000Z',
file: {
size: 80280,
pe: {},
type: 'elf',
hash: {
sha256: 'a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3',
tlsh: '6D7312E017B517CC1371A8353BED205E9128223972AE35302E97528DF957703BAB2DBE',
ssdeep:
'1536:87vbq1lGAXSEYQjbChaAU2yU23M51DjZgSQAvcYkFtZTjzBht5:8D+CAXFYQChaAUk5ljnQssL',
md5: '9b6c3518a91d23ed77504b5416bfb5b3',
},
},
type: 'file',
},
matched: {
atomic: 'a04ac6d98ad989312783d4fe3456c53730b212c79a426fb215708b6c6daa3de3',
field: 'myhash.mysha256',
id: '84cf452c1e0375c3d4412cb550bd1783358468a3b3b777da4829d72c7d6fb74f',
index: 'logs-ti_abusech.malware',
type: 'indicator_match_rule',
},
},
{ line: 2, text: ' }' },
];

expandFirstAlert();
openJsonView();
scrollJsonViewToBottom();

cy.get(JSON_LINES).then((elements) => {
const length = elements.length;
expectedEnrichment.forEach((enrichment) => {
cy.wrap(elements)
.eq(length - enrichment.line)
.invoke('text')
.should('include', enrichment.text);
});

cy.get(JSON_TEXT).then((x) => {
const parsed = JSON.parse(x.text());
expect(parsed._source.threat.enrichments).to.deep.equal(expectedEnrichment);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const JSON_LINES = '.euiCodeBlock__line';

export const JSON_VIEW_TAB = '[data-test-subj="jsonViewTab"]';

export const JSON_TEXT = '[data-test-subj="jsonView"]';

export const TABLE_CELL = '.euiTableRowCell';

export const TABLE_TAB = '[data-test-subj="tableTab"]';
Expand Down
Loading