-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SECURITY SOLEIL] Fix selection of event type when no siem index sign…
…al created (#68291) * fix selection of event type when no siem index signal created * including the term signal for the old timeline * fix import path * Add a specific msg in the inspect modal if we do not have the alert index created * fix import if eventType is siganl to match it to alert * forget to update test * fix signal view Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
eaca7ee
commit e3d88a4
Showing
9 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
x-pack/plugins/security_solution/public/timelines/components/timeline/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* 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 { mount } from 'enzyme'; | ||
import React from 'react'; | ||
import { MockedProvider } from 'react-apollo/test-utils'; | ||
import { act } from 'react-dom/test-utils'; | ||
import useResizeObserver from 'use-resize-observer/polyfilled'; | ||
|
||
import { | ||
useSignalIndex, | ||
ReturnSignalIndex, | ||
} from '../../../alerts/containers/detection_engine/alerts/use_signal_index'; | ||
import { mocksSource } from '../../../common/containers/source/mock'; | ||
import { wait } from '../../../common/lib/helpers'; | ||
import { defaultHeaders, mockTimelineData, TestProviders } from '../../../common/mock'; | ||
import { Direction } from '../../../graphql/types'; | ||
import { timelineQuery } from '../../containers/index.gql_query'; | ||
import { timelineActions } from '../../store/timeline'; | ||
|
||
import { Sort } from './body/sort'; | ||
import { mockDataProviders } from './data_providers/mock/mock_data_providers'; | ||
import { StatefulTimeline, Props as StatefulTimelineProps } from './index'; | ||
import { Timeline } from './timeline'; | ||
|
||
jest.mock('../../../common/lib/kibana'); | ||
|
||
const mockUseResizeObserver: jest.Mock = useResizeObserver as jest.Mock; | ||
jest.mock('use-resize-observer/polyfilled'); | ||
mockUseResizeObserver.mockImplementation(() => ({})); | ||
|
||
const mockUseSignalIndex: jest.Mock = useSignalIndex as jest.Mock<ReturnSignalIndex>; | ||
jest.mock('../../../alerts/containers/detection_engine/alerts/use_signal_index'); | ||
|
||
describe('StatefulTimeline', () => { | ||
let props = {} as StatefulTimelineProps; | ||
const sort: Sort = { | ||
columnId: '@timestamp', | ||
sortDirection: Direction.desc, | ||
}; | ||
const startDate = new Date('2018-03-23T18:49:23.132Z').valueOf(); | ||
const endDate = new Date('2018-03-24T03:33:52.253Z').valueOf(); | ||
|
||
const mocks = [ | ||
{ request: { query: timelineQuery }, result: { data: { events: mockTimelineData } } }, | ||
...mocksSource, | ||
]; | ||
|
||
beforeEach(() => { | ||
props = { | ||
addProvider: timelineActions.addProvider, | ||
columns: defaultHeaders, | ||
createTimeline: timelineActions.createTimeline, | ||
dataProviders: mockDataProviders, | ||
eventType: 'raw', | ||
end: endDate, | ||
filters: [], | ||
id: 'foo', | ||
isLive: false, | ||
itemsPerPage: 5, | ||
itemsPerPageOptions: [5, 10, 20], | ||
kqlMode: 'search', | ||
kqlQueryExpression: '', | ||
onClose: jest.fn(), | ||
onDataProviderEdited: timelineActions.dataProviderEdited, | ||
removeColumn: timelineActions.removeColumn, | ||
removeProvider: timelineActions.removeProvider, | ||
show: true, | ||
showCallOutUnauthorizedMsg: false, | ||
sort, | ||
start: startDate, | ||
updateColumns: timelineActions.updateColumns, | ||
updateDataProviderEnabled: timelineActions.updateDataProviderEnabled, | ||
updateDataProviderExcluded: timelineActions.updateDataProviderExcluded, | ||
updateDataProviderKqlQuery: timelineActions.updateDataProviderKqlQuery, | ||
updateHighlightedDropAndProviderId: timelineActions.updateHighlightedDropAndProviderId, | ||
updateItemsPerPage: timelineActions.updateItemsPerPage, | ||
updateItemsPerPageOptions: timelineActions.updateItemsPerPageOptions, | ||
updateSort: timelineActions.updateSort, | ||
upsertColumn: timelineActions.upsertColumn, | ||
usersViewing: ['elastic'], | ||
}; | ||
}); | ||
|
||
describe('indexToAdd', () => { | ||
test('Make sure that indexToAdd return an unknown index if signalIndex does not exist', async () => { | ||
mockUseSignalIndex.mockImplementation(() => ({ | ||
loading: false, | ||
signalIndexExists: false, | ||
signalIndexName: undefined, | ||
})); | ||
const wrapper = mount( | ||
<TestProviders> | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<StatefulTimeline {...props} /> | ||
</MockedProvider> | ||
</TestProviders> | ||
); | ||
await act(async () => { | ||
await wait(); | ||
wrapper.update(); | ||
const timeline = wrapper.find(Timeline); | ||
expect(timeline.props().indexToAdd).toEqual([ | ||
'no-alert-index-049FC71A-4C2C-446F-9901-37XMC5024C51', | ||
]); | ||
}); | ||
}); | ||
|
||
test('Make sure that indexToAdd return siem signal index if signalIndex exist', async () => { | ||
mockUseSignalIndex.mockImplementation(() => ({ | ||
loading: false, | ||
signalIndexExists: true, | ||
signalIndexName: 'mock-siem-signals-index', | ||
})); | ||
const wrapper = mount( | ||
<TestProviders> | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<StatefulTimeline {...props} /> | ||
</MockedProvider> | ||
</TestProviders> | ||
); | ||
await act(async () => { | ||
await wait(); | ||
wrapper.update(); | ||
const timeline = wrapper.find(Timeline); | ||
expect(timeline.props().indexToAdd).toEqual(['mock-siem-signals-index']); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters