Skip to content

Commit

Permalink
[Security Solution][Endpoint] Move additinal (batch 3) APIs to versio…
Browse files Browse the repository at this point in the history
…ned router (elastic#160326)

## Summary

Moves the following APIs to the versioned router:

- `POST  /api/endpoint/isolate` (old route)
- `POST  /api/endpoint/unisolate` (old route)
- `POST  /api/endpoint/action/isolate`
- `POST  /api/endpoint/action/unisolate`
- `POST  /api/endpoint/action/kill_process`
- `POST  /api/endpoint/action/suspend_process`
- `POST  /api/endpoint/action/running_procs`
- `POST  /api/endpoint/action/get_file`

---------

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
paul-tavares and kibanamachine authored Jun 27, 2023
1 parent 514db6f commit d1e9c87
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import { KibanaServices } from '../kibana';
import { coreMock } from '@kbn/core/public/mocks';
import { isolateHost, unIsolateHost } from '.';
import { ISOLATE_HOST_ROUTE, UNISOLATE_HOST_ROUTE } from '../../../../common/endpoint/constants';
import { hostIsolationRequestBodyMock } from './mocks';
import {
ISOLATE_HOST_ROUTE_V2,
UNISOLATE_HOST_ROUTE_V2,
} from '../../../../common/endpoint/constants';

jest.mock('../kibana');

Expand All @@ -24,17 +27,19 @@ describe('When using Host Isolation library', () => {
const requestBody = hostIsolationRequestBodyMock();
await isolateHost(requestBody);

expect(mockKibanaServices().http.post).toHaveBeenCalledWith(ISOLATE_HOST_ROUTE, {
expect(mockKibanaServices().http.post).toHaveBeenCalledWith(ISOLATE_HOST_ROUTE_V2, {
body: JSON.stringify(requestBody),
version: '2023-10-31',
});
});

it('should send an un-isolate POST request', async () => {
const requestBody = hostIsolationRequestBodyMock();
await unIsolateHost(requestBody);

expect(mockKibanaServices().http.post).toHaveBeenCalledWith(UNISOLATE_HOST_ROUTE, {
expect(mockKibanaServices().http.post).toHaveBeenCalledWith(UNISOLATE_HOST_ROUTE_V2, {
body: JSON.stringify(requestBody),
version: '2023-10-31',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ import type {
ResponseActionApiResponse,
} from '../../../../common/endpoint/types';
import { KibanaServices } from '../kibana';
import { ISOLATE_HOST_ROUTE, UNISOLATE_HOST_ROUTE } from '../../../../common/endpoint/constants';
import {
ISOLATE_HOST_ROUTE_V2,
UNISOLATE_HOST_ROUTE_V2,
} from '../../../../common/endpoint/constants';

/** Isolates a Host running either elastic endpoint or fleet agent */
export const isolateHost = async (
params: HostIsolationRequestBody
): Promise<ResponseActionApiResponse> => {
return KibanaServices.get().http.post<ResponseActionApiResponse>(ISOLATE_HOST_ROUTE, {
return KibanaServices.get().http.post<ResponseActionApiResponse>(ISOLATE_HOST_ROUTE_V2, {
body: JSON.stringify(params),
version: '2023-10-31',
});
};

/** Un-isolates a Host running either elastic endpoint or fleet agent */
export const unIsolateHost = async (
params: HostIsolationRequestBody
): Promise<ResponseActionApiResponse> => {
return KibanaServices.get().http.post<ResponseActionApiResponse>(UNISOLATE_HOST_ROUTE, {
return KibanaServices.get().http.post<ResponseActionApiResponse>(UNISOLATE_HOST_ROUTE_V2, {
body: JSON.stringify(params),
version: '2023-10-31',
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {
} from '../../../../common/endpoint/types';
import type { ResponseProvidersInterface } from '../../mock/endpoint/http_handler_mock_factory';
import { httpHandlerMockFactory } from '../../mock/endpoint/http_handler_mock_factory';
import { ISOLATE_HOST_ROUTE, UNISOLATE_HOST_ROUTE } from '../../../../common/endpoint/constants';
import {
ISOLATE_HOST_ROUTE_V2,
UNISOLATE_HOST_ROUTE_V2,
} from '../../../../common/endpoint/constants';

export const hostIsolationRequestBodyMock = (): HostIsolationRequestBody => {
return {
Expand All @@ -37,13 +40,13 @@ export const hostIsolationHttpMocks = httpHandlerMockFactory<HostIsolationHttpMo
{
id: 'isolateHost',
method: 'post',
path: ISOLATE_HOST_ROUTE,
path: ISOLATE_HOST_ROUTE_V2,
handler: () => hostIsolationResponseMock(),
},
{
id: 'unIsolateHost',
method: 'post',
path: UNISOLATE_HOST_ROUTE,
path: UNISOLATE_HOST_ROUTE_V2,
handler: () => hostIsolationResponseMock(),
},
]);
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const killProcess = (
): Promise<ResponseActionApiResponse> => {
return KibanaServices.get().http.post<ResponseActionApiResponse>(KILL_PROCESS_ROUTE, {
body: JSON.stringify(params),
version: '2023-10-31',
});
};

Expand All @@ -27,5 +28,6 @@ export const suspendProcess = (
): Promise<ResponseActionApiResponse> => {
return KibanaServices.get().http.post<ResponseActionApiResponse>(SUSPEND_PROCESS_ROUTE, {
body: JSON.stringify(params),
version: '2023-10-31',
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ describe('Detections Alerts API', () => {
comment: 'commento',
caseIds: ['88c04a90-b19c-11eb-b838-bf3c7840b969'],
});
expect(postMock).toHaveBeenCalledWith('/api/endpoint/isolate', {
expect(postMock).toHaveBeenCalledWith('/api/endpoint/action/isolate', {
body: '{"endpoint_ids":["fd8a122b-4c54-4c05-b295-e5f8381fc59d"],"comment":"commento","case_ids":["88c04a90-b19c-11eb-b838-bf3c7840b969"]}',
version: '2023-10-31',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ describe('When using get-file action from response actions console', () => {
expect(apiMocks.responseProvider.getFile).toHaveBeenCalledWith({
body: '{"endpoint_ids":["a.b.c"],"parameters":{"path":"one/two"}}',
path: GET_FILE_ROUTE,
version: '2023-10-31',
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const useSendGetEndpointProcessesRequest = (
ResponseActionApiResponse<GetProcessesActionOutputContent>
>(GET_PROCESSES_ROUTE, {
body: JSON.stringify(getRunningProcessesData),
version: '2023-10-31',
});
}, customOptions);
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const useSendGetFileRequest = (
(reqBody) => {
return KibanaServices.get().http.post<ResponseActionApiResponse>(GET_FILE_ROUTE, {
body: JSON.stringify(reqBody),
version: '2023-10-31',
});
},
customOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
ACTION_STATUS_ROUTE,
GET_PROCESSES_ROUTE,
BASE_ENDPOINT_ACTION_ROUTE,
ISOLATE_HOST_ROUTE,
UNISOLATE_HOST_ROUTE,
KILL_PROCESS_ROUTE,
SUSPEND_PROCESS_ROUTE,
GET_FILE_ROUTE,
ACTION_AGENT_FILE_INFO_ROUTE,
EXECUTE_ROUTE,
UPLOAD_ROUTE,
ISOLATE_HOST_ROUTE_V2,
UNISOLATE_HOST_ROUTE_V2,
} from '../../../common/endpoint/constants';
import type { ResponseProvidersInterface } from '../../common/mock/endpoint/http_handler_mock_factory';
import { httpHandlerMockFactory } from '../../common/mock/endpoint/http_handler_mock_factory';
Expand Down Expand Up @@ -71,15 +71,15 @@ export type ResponseActionsHttpMocksInterface = ResponseProvidersInterface<{
export const responseActionsHttpMocks = httpHandlerMockFactory<ResponseActionsHttpMocksInterface>([
{
id: 'isolateHost',
path: ISOLATE_HOST_ROUTE,
path: ISOLATE_HOST_ROUTE_V2,
method: 'post',
handler: (): ResponseActionApiResponse => {
return { action: '1-2-3', data: { id: '1-2-3' } as ResponseActionApiResponse['data'] };
},
},
{
id: 'releaseHost',
path: UNISOLATE_HOST_ROUTE,
path: UNISOLATE_HOST_ROUTE_V2,
method: 'post',
handler: (): ResponseActionApiResponse => {
return { action: '3-2-1', data: { id: '3-2-1' } as ResponseActionApiResponse['data'] };
Expand Down
Loading

0 comments on commit d1e9c87

Please sign in to comment.