forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.13][Security Solution][Endpoint] Add missing tests for bidirection…
…al connector response actions (elastic#176824) ## Summary Tests for responder action item on alert action menu. for changes in elastic/pull/176405 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
Showing
2 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
140 changes: 140 additions & 0 deletions
140
...olution/public/detections/components/endpoint_responder/use_responder_action_data.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,140 @@ | ||
/* | ||
* 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 { useIsExperimentalFeatureEnabled } from '../../../common/hooks/use_experimental_features'; | ||
import { useResponderActionData } from './use_responder_action_data'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useGetEndpointDetails } from '../../../management/hooks'; | ||
import { HostStatus } from '../../../../common/endpoint/types'; | ||
|
||
jest.mock('../../../common/hooks/use_experimental_features'); | ||
jest.mock('../../../management/hooks', () => ({ | ||
useGetEndpointDetails: (jest.fn() as jest.Mock).mockImplementation(() => ({ enabled: false })), | ||
useWithShowResponder: jest.fn(), | ||
})); | ||
|
||
const useGetEndpointDetailsMock = useGetEndpointDetails as jest.Mock; | ||
const useIsExperimentalFeatureEnabledMock = useIsExperimentalFeatureEnabled as jest.Mock; | ||
|
||
describe('#useResponderActionData', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should return `responder` menu item as `disabled` if agentType is not `endpoint` and feature flag is enabled', () => { | ||
useIsExperimentalFeatureEnabledMock.mockReturnValue(false); | ||
|
||
const { result } = renderHook(() => | ||
useResponderActionData({ | ||
endpointId: 'some-agent-type-id', | ||
// @ts-expect-error this is for testing purpose | ||
agentType: 'some_agent_type', | ||
eventData: [], | ||
}) | ||
); | ||
expect(result.current.isDisabled).toEqual(true); | ||
}); | ||
|
||
describe('when agentType is `endpoint`', () => { | ||
it.each(Object.values(HostStatus).filter((status) => status !== 'unenrolled'))( | ||
'should return `responder` menu item as `enabled `if agentType is `endpoint` when endpoint is %s', | ||
(hostStatus) => { | ||
useGetEndpointDetailsMock.mockReturnValue({ | ||
data: { | ||
host_status: hostStatus, | ||
}, | ||
isFetching: false, | ||
error: undefined, | ||
}); | ||
const { result } = renderHook(() => | ||
useResponderActionData({ | ||
endpointId: 'endpoint-id', | ||
agentType: 'endpoint', | ||
}) | ||
); | ||
expect(result.current.isDisabled).toEqual(false); | ||
} | ||
); | ||
|
||
it('should return responder menu item `disabled` if agentType is `endpoint` when endpoint is `unenrolled`', () => { | ||
useGetEndpointDetailsMock.mockReturnValue({ | ||
data: { | ||
host_status: 'unenrolled', | ||
}, | ||
isFetching: false, | ||
error: undefined, | ||
}); | ||
const { result } = renderHook(() => | ||
useResponderActionData({ | ||
endpointId: 'endpoint-id', | ||
agentType: 'endpoint', | ||
}) | ||
); | ||
expect(result.current.isDisabled).toEqual(true); | ||
}); | ||
|
||
it('should return responder menu item `disabled` if agentType is `endpoint` when endpoint data has error', () => { | ||
useGetEndpointDetailsMock.mockReturnValue({ | ||
data: { | ||
host_status: 'online', | ||
}, | ||
isFetching: false, | ||
error: new Error('uh oh!'), | ||
}); | ||
const { result } = renderHook(() => | ||
useResponderActionData({ | ||
endpointId: 'endpoint-id', | ||
agentType: 'endpoint', | ||
}) | ||
); | ||
expect(result.current.isDisabled).toEqual(true); | ||
}); | ||
|
||
it('should return responder menu item `disabled` if agentType is `endpoint` and endpoint data is fetching', () => { | ||
useGetEndpointDetailsMock.mockReturnValue({ | ||
data: undefined, | ||
isFetching: true, | ||
error: undefined, | ||
}); | ||
|
||
const { result } = renderHook(() => | ||
useResponderActionData({ | ||
endpointId: 'endpoint-id', | ||
agentType: 'endpoint', | ||
}) | ||
); | ||
expect(result.current.isDisabled).toEqual(true); | ||
}); | ||
}); | ||
|
||
describe('when agentType is `sentinel_one`', () => { | ||
it('should return `responder` menu item as `disabled` if agentType is `sentinel_one` and feature flag is disabled', () => { | ||
useIsExperimentalFeatureEnabledMock.mockReturnValue(false); | ||
|
||
const { result } = renderHook(() => | ||
useResponderActionData({ | ||
endpointId: 'sentinel-one-id', | ||
agentType: 'sentinel_one', | ||
eventData: [], | ||
}) | ||
); | ||
expect(result.current.isDisabled).toEqual(true); | ||
}); | ||
|
||
it('should return `responder` menu item as `enabled `if agentType is `sentinel_one` and feature flag is enabled', () => { | ||
useIsExperimentalFeatureEnabledMock.mockReturnValue(true); | ||
const { result } = renderHook(() => | ||
useResponderActionData({ | ||
endpointId: 'sentinel-one-id', | ||
agentType: 'sentinel_one', | ||
eventData: [], | ||
}) | ||
); | ||
expect(result.current.isDisabled).toEqual(false); | ||
}); | ||
}); | ||
}); |
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