Skip to content

Commit f70c885

Browse files
committed
Add --force to cancel action for Endpoint
1 parent 6f817b0 commit f70c885

3 files changed

Lines changed: 58 additions & 7 deletions

File tree

x-pack/solutions/security/plugins/security_solution/public/management/components/endpoint_responder/command_render_components/cancel_action.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import type { ActionRequestComponentProps } from '../types';
1515
export const CancelActionResult = memo<
1616
ActionRequestComponentProps<{
1717
action: string[];
18+
force?: boolean[];
1819
}>
1920
>(({ command, setStore, store, status, setStatus, ResultComponent }) => {
2021
const actionCreator = useSendCancelRequest();
2122

2223
const actionRequestBody = useMemo<undefined | CancelActionRequestBody>(() => {
2324
const endpointId = command.commandDefinition?.meta?.endpointId;
24-
const { action, comment } = command.args.args;
25+
const { action, comment, force } = command.args.args;
2526
const agentType = command.commandDefinition?.meta?.agentType;
2627

2728
return endpointId
@@ -31,6 +32,7 @@ export const CancelActionResult = memo<
3132
comment: comment?.[0],
3233
parameters: {
3334
id: action[0],
35+
force: force?.[0],
3436
},
3537
}
3638
: undefined;

x-pack/solutions/security/plugins/security_solution/public/management/components/endpoint_responder/command_render_components/integration_tests/cancel_action.test.tsx

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ import {
1414
import React from 'react';
1515
import { getEndpointConsoleCommands } from '../../lib/console_commands_definition';
1616
import { responseActionsHttpMocks } from '../../../../mocks/response_actions_http_mocks';
17-
import { enterConsoleCommand } from '../../../console/mocks';
17+
import { enterConsoleCommand, getConsoleSelectorsAndActionMock } from '../../../console/mocks';
1818
import { waitFor } from '@testing-library/react';
1919
import userEvent, { type UserEvent } from '@testing-library/user-event';
2020
import type { getEndpointAuthzInitialState } from '../../../../../../common/endpoint/service/authz';
2121
import { getEndpointAuthzInitialStateMock } from '../../../../../../common/endpoint/service/authz/mocks';
22-
import type { ResponseActionAgentType } from '../../../../../../common/endpoint/service/response_actions/constants';
22+
import type {
23+
EndpointCapabilities,
24+
ResponseActionAgentType,
25+
} from '../../../../../../common/endpoint/service/response_actions/constants';
2326
import {
2427
ENDPOINT_CAPABILITIES,
2528
RESPONSE_ACTION_AGENT_TYPE,
@@ -58,6 +61,8 @@ describe('When using cancel action from response actions console', () => {
5861
let mockedContext: AppContextTestRender;
5962
let user: UserEvent;
6063
let apiMocks: ReturnType<typeof responseActionsHttpMocks>;
64+
let endpointCapabilities: EndpointCapabilities[];
65+
let consoleMockUtils: ReturnType<typeof getConsoleSelectorsAndActionMock>;
6166

6267
// Simplified render function with minimal setup
6368
const renderConsole = async (
@@ -71,8 +76,8 @@ describe('When using cancel action from response actions console', () => {
7176
'data-test-subj': 'test',
7277
commands: getEndpointConsoleCommands({
7378
agentType,
79+
endpointCapabilities,
7480
endpointAgentId: 'a.b.c',
75-
endpointCapabilities: [...ENDPOINT_CAPABILITIES],
7681
endpointPrivileges: {
7782
...getEndpointAuthzInitialStateMock(),
7883
loading: false,
@@ -85,6 +90,7 @@ describe('When using cancel action from response actions console', () => {
8590
/>
8691
);
8792

93+
consoleMockUtils = getConsoleSelectorsAndActionMock(renderResult, user);
8894
const consoleManagerMockAccess = getConsoleManagerMockRenderResultQueriesAndActions(
8995
user,
9096
renderResult
@@ -107,6 +113,7 @@ describe('When using cancel action from response actions console', () => {
107113
beforeEach(() => {
108114
user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime });
109115
mockedContext = createAppRootMockRenderer();
116+
endpointCapabilities = [...ENDPOINT_CAPABILITIES];
110117

111118
// Set default experimental flags
112119
mockedContext.setExperimentalFlag({
@@ -196,6 +203,22 @@ describe('When using cancel action from response actions console', () => {
196203
expect(renderResult.getByTestId('cancel-action-arg-0')).toBeTruthy();
197204
});
198205
});
206+
207+
if (agentType === 'endpoint') {
208+
it('should have a --force argument available', async () => {
209+
const renderResult = await renderConsole(agentType);
210+
await enterConsoleCommand(renderResult, user, 'cancel --help');
211+
212+
expect(renderResult.getByTestId('test-commandUsage').textContent).toContain('--force');
213+
});
214+
} else {
215+
it('should NOT have a --force argument available', async () => {
216+
const renderResult = await renderConsole(agentType);
217+
await enterConsoleCommand(renderResult, user, 'cancel --help');
218+
219+
expect(renderResult.getByTestId('test-commandUsage').textContent).not.toContain('--force');
220+
});
221+
}
199222
});
200223

201224
describe.each(UNSUPPORTED_AGENT_TYPES)('Unsupported agent type: %s', (agentType) => {
@@ -239,8 +262,18 @@ describe('When using cancel action from response actions console', () => {
239262
});
240263

241264
describe('and agent type is endpoint', () => {
242-
it('should display help panel "+" button disabled if Endpoint does not support runscript', async () => {
243-
//
265+
it('should display help panel "+" button disabled if Endpoint does not support cancel', async () => {
266+
endpointCapabilities = ENDPOINT_CAPABILITIES.filter((capability) => capability !== 'cancel');
267+
const renderResult = await renderConsole('endpoint');
268+
consoleMockUtils.openHelpPanel();
269+
270+
expect(
271+
(
272+
renderResult.getByTestId(
273+
'test-commandList-Responseactions-cancel-addToInput'
274+
) as HTMLButtonElement
275+
).disabled
276+
).toBe(true);
244277
});
245278
});
246279

x-pack/solutions/security/plugins/security_solution/public/management/components/endpoint_responder/lib/console_commands_definition.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,28 @@ export const getEndpointConsoleCommands = ({
692692
mustHaveValue: 'truthy',
693693
SelectorComponent: CancelablePendingActionsSelector,
694694
},
695+
...(agentType === 'endpoint'
696+
? {
697+
force: {
698+
required: false,
699+
allowMultiples: false,
700+
about: i18n.translate(
701+
'xpack.securitySolution.endpointConsoleCommands.cancel.force.about',
702+
{
703+
defaultMessage:
704+
'Forcefully cancel the action, even if it is already in progress.',
705+
}
706+
),
707+
mustHaveValue: false,
708+
},
709+
}
710+
: {}),
695711
...commandCommentArgument(),
696712
},
697713
helpGroupLabel: HELP_GROUPS.responseActions.label,
698714
helpGroupPosition: HELP_GROUPS.responseActions.position,
699715
helpCommandPosition: 10,
700-
helpDisabled: !isSupported,
716+
helpDisabled: !isSupported || !doesEndpointSupportCommand('cancel'),
701717
helpHidden: !isSupported,
702718
validate: capabilitiesAndPrivilegesValidator(agentType),
703719
});

0 commit comments

Comments
 (0)