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

[8.0] [Security Solution] Open alerts with an associated template in the template view (#123333) #123689

Merged
merged 1 commit into from
Jan 25, 2022
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 @@ -15,6 +15,7 @@ import {
mockEcsDataWithAlert,
mockTimelineDetails,
mockTimelineResult,
mockAADEcsDataWithAlert,
} from '../../../common/mock/';
import { CreateTimeline, UpdateTimelineLoading } from './types';
import { Ecs } from '../../../../common/ecs';
Expand Down Expand Up @@ -268,6 +269,9 @@ describe('alert actions', () => {
updateTimelineIsLoading,
searchStrategyClient,
});
const defaultTimelinePropsWithoutNote = { ...defaultTimelineProps };

delete defaultTimelinePropsWithoutNote.ruleNote;

expect(updateTimelineIsLoading).toHaveBeenCalledWith({
id: TimelineId.active,
Expand All @@ -278,7 +282,17 @@ describe('alert actions', () => {
isLoading: false,
});
expect(createTimeline).toHaveBeenCalledTimes(1);
expect(createTimeline).toHaveBeenCalledWith(defaultTimelineProps);
expect(createTimeline).toHaveBeenCalledWith({
...defaultTimelinePropsWithoutNote,
timeline: {
...defaultTimelinePropsWithoutNote.timeline,
dataProviders: [],
kqlQuery: {
filterQuery: null,
},
resolveTimelineConfig: undefined,
},
});
});
});

Expand All @@ -289,8 +303,7 @@ describe('alert actions', () => {
signal: {
rule: {
...mockEcsDataWithAlert.signal?.rule,
// @ts-expect-error
timeline_id: null,
timeline_id: [''],
},
},
};
Expand Down Expand Up @@ -362,6 +375,7 @@ describe('alert actions', () => {
...defaultTimelineProps,
timeline: {
...defaultTimelineProps.timeline,
resolveTimelineConfig: undefined,
dataProviders: [
{
and: [],
Expand Down Expand Up @@ -424,14 +438,53 @@ describe('alert actions', () => {
});

test('it uses original_time and threshold_result.from for threshold alerts', async () => {
const ecsDataMock = getThresholdDetectionAlertAADMock();
const ecsDataMockWithNoTemplateTimeline = getThresholdDetectionAlertAADMock({
...mockAADEcsDataWithAlert,
kibana: {
alert: {
...mockAADEcsDataWithAlert.kibana?.alert,
rule: {
...mockAADEcsDataWithAlert.kibana?.alert?.rule,
parameters: {
...mockAADEcsDataWithAlert.kibana?.alert?.rule?.parameters,
threshold: {
field: ['destination.ip'],
value: 1,
},
},
name: ['mock threshold rule'],
saved_id: [],
type: ['threshold'],
uuid: ['c5ba41ab-aaf3-4f43-971b-bdf9434ce0ea'],
timeline_id: undefined,
timeline_title: undefined,
},
threshold_result: {
count: 99,
from: '2021-01-10T21:11:45.839Z',
cardinality: [
{
field: 'source.ip',
value: 1,
},
],
terms: [
{
field: 'destination.ip',
value: 1,
},
],
},
},
},
});

const expectedFrom = '2021-01-10T21:11:45.839Z';
const expectedTo = '2021-01-10T21:12:45.839Z';

await sendAlertToTimelineAction({
createTimeline,
ecsData: ecsDataMock,
ecsData: ecsDataMockWithNoTemplateTimeline,
updateTimelineIsLoading,
searchStrategyClient,
});
Expand Down
Loading