-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Entity details] - move osquery, response and inve…
…stigation guide related hooks and components to flyout folder
- Loading branch information
1 parent
29c5381
commit 4ef5bc0
Showing
13 changed files
with
307 additions
and
82 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
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
158 changes: 158 additions & 0 deletions
158
...ugins/security_solution/public/flyout/document_details/left/hooks/use_osquery_tab.test.ts
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,158 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useOsqueryTab } from './use_osquery_tab'; | ||
import { mockSearchHit } from '../../shared/mocks/mock_search_hit'; | ||
import { mockDataAsNestedObject } from '../../shared/mocks/mock_data_as_nested_object'; | ||
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; | ||
import { useKibana } from '../../../../common/lib/kibana'; | ||
import type { ExperimentalFeatures } from '../../../../../common'; | ||
import { allowedExperimentalValues } from '../../../../../common'; | ||
import { ResponseActionTypesEnum } from '../../../../../common/api/detection_engine'; | ||
|
||
const ecsData = mockDataAsNestedObject; | ||
const rawEventData = mockSearchHit; | ||
|
||
jest.mock('../../../../common/hooks/use_experimental_features', () => ({ | ||
useIsExperimentalFeatureEnabled: jest.fn().mockReturnValue(true), | ||
})); | ||
jest.mock('../../../../management/hooks/response_actions/use_get_automated_action_list'); | ||
jest.mock('../../../../common/lib/kibana'); | ||
|
||
const rawEventDataWithResponseActions = { | ||
...rawEventData, | ||
fields: { | ||
'kibana.alert.rule.parameters': [ | ||
{ | ||
response_actions: [ | ||
{ | ||
action_type_id: ResponseActionTypesEnum['.osquery'], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
describe('useOsqueryTab', () => { | ||
beforeEach(() => { | ||
(useIsExperimentalFeatureEnabled as jest.Mock).mockImplementation( | ||
jest.fn((feature: keyof ExperimentalFeatures) => { | ||
if (feature === 'responseActionsEnabled') return true; | ||
if (feature === 'endpointResponseActionsEnabled') return false; | ||
return allowedExperimentalValues[feature]; | ||
}) | ||
); | ||
(useKibana as jest.Mock).mockReturnValue({ | ||
services: { | ||
osquery: { | ||
OsqueryResults: {}, | ||
fetchAllLiveQueries: jest.fn().mockReturnValue({ data: { data: {} } }), | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return the normal component', () => { | ||
const { result } = renderHook(() => | ||
useOsqueryTab({ | ||
ecsData, | ||
rawEventData: rawEventDataWithResponseActions, | ||
}) | ||
); | ||
|
||
expect(result.current?.id).toEqual('osquery-results-view'); | ||
expect(result.current?.name).toEqual('Osquery Results'); | ||
expect(result.current?.append).toBeDefined(); | ||
expect(result.current?.content).toBeDefined(); | ||
}); | ||
|
||
it('should return undefined if rawEventData is undefined', () => { | ||
const { result } = renderHook(() => | ||
useOsqueryTab({ | ||
ecsData, | ||
rawEventData: undefined, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual(undefined); | ||
}); | ||
|
||
it('should return undefined if responseActionsEnabled feature flag is off', () => { | ||
(useIsExperimentalFeatureEnabled as jest.Mock).mockImplementation( | ||
jest.fn((feature: keyof ExperimentalFeatures) => { | ||
if (feature === 'responseActionsEnabled') return false; | ||
return allowedExperimentalValues[feature]; | ||
}) | ||
); | ||
|
||
const { result } = renderHook(() => | ||
useOsqueryTab({ | ||
ecsData, | ||
rawEventData: rawEventDataWithResponseActions, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual(undefined); | ||
}); | ||
|
||
it('should return undefined if endpointResponseActionsEnabled feature flag is on', () => { | ||
(useIsExperimentalFeatureEnabled as jest.Mock).mockImplementation( | ||
jest.fn((feature: keyof ExperimentalFeatures) => { | ||
if (feature === 'endpointResponseActionsEnabled') return true; | ||
return allowedExperimentalValues[feature]; | ||
}) | ||
); | ||
|
||
const { result } = renderHook(() => | ||
useOsqueryTab({ | ||
ecsData, | ||
rawEventData: rawEventDataWithResponseActions, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual(undefined); | ||
}); | ||
|
||
it('should return undefined if ecsData is undefined', () => { | ||
const { result } = renderHook(() => | ||
useOsqueryTab({ | ||
ecsData: null, | ||
rawEventData: rawEventDataWithResponseActions, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual(undefined); | ||
}); | ||
|
||
it('should return undefined if there are no response actions', () => { | ||
const rawEventDataWithNoResponseActions = { | ||
...rawEventData, | ||
fields: { | ||
'kibana.alert.rule.parameters': [ | ||
{ | ||
response_actions: [], | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
const { result } = renderHook(() => | ||
useOsqueryTab({ | ||
ecsData, | ||
rawEventData: rawEventDataWithNoResponseActions, | ||
}) | ||
); | ||
|
||
expect(result.current).toEqual(undefined); | ||
}); | ||
}); |
81 changes: 81 additions & 0 deletions
81
.../security_solution/public/flyout/document_details/left/hooks/use_response_actions.test.ts
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,81 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useResponseActionsView } from './use_response_actions_view'; | ||
import { mockSearchHit } from '../../shared/mocks/mock_search_hit'; | ||
import { mockDataAsNestedObject } from '../../shared/mocks/mock_data_as_nested_object'; | ||
import { useGetAutomatedActionList } from '../../../../management/hooks/response_actions/use_get_automated_action_list'; | ||
import { useIsExperimentalFeatureEnabled } from '../../../../common/hooks/use_experimental_features'; | ||
|
||
const ecsData = mockDataAsNestedObject; | ||
const rawEventData = mockSearchHit; | ||
|
||
jest.mock('../../../../common/hooks/use_experimental_features'); | ||
jest.mock('../../../../management/hooks/response_actions/use_get_automated_action_list'); | ||
|
||
describe('useResponseActionsView', () => { | ||
it('should return the normal component', () => { | ||
(useIsExperimentalFeatureEnabled as jest.Mock).mockReturnValue(true); | ||
(useGetAutomatedActionList as jest.Mock).mockReturnValue({ | ||
data: [], | ||
isFetched: true, | ||
}); | ||
|
||
const { result } = renderHook(() => | ||
useResponseActionsView({ | ||
ecsData, | ||
rawEventData, | ||
}) | ||
); | ||
|
||
expect(result.current.id).toEqual('response-actions-results-view'); | ||
expect(result.current.name).toEqual('Response Results'); | ||
expect(result.current.append).toBeDefined(); | ||
expect(result.current.content).toBeDefined(); | ||
}); | ||
|
||
it('returns early return if rawEventData is undefined', () => { | ||
(useIsExperimentalFeatureEnabled as jest.Mock).mockReturnValue(true); | ||
(useGetAutomatedActionList as jest.Mock).mockReturnValue({ | ||
data: [], | ||
isFetched: true, | ||
}); | ||
|
||
const { result } = renderHook(() => | ||
useResponseActionsView({ | ||
ecsData, | ||
rawEventData: undefined, | ||
}) | ||
); | ||
|
||
expect(result.current.id).toEqual('response-actions-results-view'); | ||
expect(result.current.name).toEqual('Response Results'); | ||
expect(result.current.append).not.toBeDefined(); | ||
expect(result.current.content).toBeDefined(); | ||
}); | ||
|
||
it('returns early return if endpointResponseActionsEnabled feature flag is off', () => { | ||
(useIsExperimentalFeatureEnabled as jest.Mock).mockReturnValue(false); | ||
(useGetAutomatedActionList as jest.Mock).mockReturnValue({ | ||
data: [], | ||
isFetched: true, | ||
}); | ||
|
||
const { result } = renderHook(() => | ||
useResponseActionsView({ | ||
ecsData, | ||
rawEventData, | ||
}) | ||
); | ||
|
||
expect(result.current.id).toEqual('response-actions-results-view'); | ||
expect(result.current.name).toEqual('Response Results'); | ||
expect(result.current.append).not.toBeDefined(); | ||
expect(result.current.content).toBeDefined(); | ||
}); | ||
}); |
Oops, something went wrong.