@@ -27,6 +27,7 @@ import {
2727} from '../../api/endpoint' ;
2828import type { MemoryDumpActionRequestBody } from '../../api/endpoint/actions/response_actions/memory_dump' ;
2929import { MemoryDumpActionRequestSchema } from '../../api/endpoint/actions/response_actions/memory_dump' ;
30+ import { isActionSupportedByAgentType } from '../service/response_actions/is_response_action_supported' ;
3031
3132// NOTE: Even though schemas are kept in common/api/endpoint - we keep tests here, because common/api should import from outside
3233describe ( 'actions schemas' , ( ) => {
@@ -1214,13 +1215,18 @@ describe('actions schemas', () => {
12141215 } ) ;
12151216 } ) ;
12161217 } ) ;
1217- describe ( 'CancelActionRequestSchema' , ( ) => {
1218+
1219+ describe . each (
1220+ RESPONSE_ACTION_AGENT_TYPE . filter ( ( agentType ) =>
1221+ isActionSupportedByAgentType ( agentType , 'cancel' , 'manual' )
1222+ )
1223+ ) ( 'CancelActionRequestSchema for agent type: %s' , ( agentType ) => {
12181224 it ( 'should validate valid cancel request with all base fields' , ( ) => {
12191225 expect ( ( ) => {
12201226 CancelActionRequestSchema . body . validate ( {
12211227 endpoint_ids : [ 'endpoint-123' ] ,
12221228 comment : 'Cancelling action due to change in requirements' ,
1223- agent_type : 'microsoft_defender_endpoint' ,
1229+ agent_type : agentType ,
12241230 parameters : {
12251231 id : '12345678-1234-5678-9012-123456789012' ,
12261232 } ,
@@ -1235,6 +1241,7 @@ describe('actions schemas', () => {
12351241 id : '12345678-1234-5678-9012-123456789012' ,
12361242 } ,
12371243 endpoint_ids : [ 'endpoint-123' ] ,
1244+ agent_type : agentType ,
12381245 } ) ;
12391246 } ) . not . toThrow ( ) ;
12401247 } ) ;
@@ -1245,6 +1252,7 @@ describe('actions schemas', () => {
12451252 parameters : {
12461253 id : '' ,
12471254 } ,
1255+ agent_type : agentType ,
12481256 endpoint_ids : [ 'endpoint-123' ] ,
12491257 } ) ;
12501258 } ) . toThrow ( ) ;
@@ -1257,6 +1265,7 @@ describe('actions schemas', () => {
12571265 id : ' ' ,
12581266 } ,
12591267 endpoint_ids : [ 'endpoint-123' ] ,
1268+ agent_type : agentType ,
12601269 } ) ;
12611270 } ) . toThrow ( ) ;
12621271 } ) ;
@@ -1267,6 +1276,7 @@ describe('actions schemas', () => {
12671276 endpoint_ids : [ 'endpoint-123' ] ,
12681277 comment : 'Cancel reason' ,
12691278 parameters : { } ,
1279+ agent_type : agentType ,
12701280 } ) ;
12711281 } ) . toThrow ( ) ;
12721282 } ) ;
@@ -1278,6 +1288,7 @@ describe('actions schemas', () => {
12781288 id : '12345678-1234-5678-9012-123456789012' ,
12791289 } ,
12801290 endpoint_ids : [ 'endpoint-123' ] ,
1291+ agent_type : agentType ,
12811292 comment : 'Cancelling due to policy change' ,
12821293 } ) ;
12831294 } ) . not . toThrow ( ) ;
@@ -1289,6 +1300,7 @@ describe('actions schemas', () => {
12891300 parameters : {
12901301 id : '12345678-1234-5678-9012-123456789012' ,
12911302 } ,
1303+ agent_type : agentType ,
12921304 endpoint_ids : [ 'endpoint-123' ] ,
12931305 } ) ;
12941306 } ) . not . toThrow ( ) ;
@@ -1301,12 +1313,41 @@ describe('actions schemas', () => {
13011313 id : '12345678-1234-5678-9012-123456789012' ,
13021314 } ,
13031315 endpoint_ids : [ 'endpoint-123' ] ,
1316+ agent_type : agentType ,
13041317 alert_ids : [ 'alert-456' ] ,
13051318 case_ids : [ 'case-789' ] ,
13061319 comment : 'Cancel with related alerts and cases' ,
13071320 } ) ;
13081321 } ) . not . toThrow ( ) ;
13091322 } ) ;
1323+
1324+ if ( agentType === 'endpoint' ) {
1325+ it ( 'should accept `--force` argument is present' , ( ) => {
1326+ expect ( ( ) => {
1327+ CancelActionRequestSchema . body . validate ( {
1328+ parameters : {
1329+ id : '12345678-1234-5678-9012-123456789012' ,
1330+ force : true ,
1331+ } ,
1332+ endpoint_ids : [ 'endpoint-123' ] ,
1333+ agent_type : agentType ,
1334+ } ) ;
1335+ } ) . not . toThrow ( ) ;
1336+ } ) ;
1337+ } else {
1338+ it ( 'should reject if `-force` argument is present' , ( ) => {
1339+ expect ( ( ) => {
1340+ CancelActionRequestSchema . body . validate ( {
1341+ parameters : {
1342+ id : '12345678-1234-5678-9012-123456789012' ,
1343+ force : true ,
1344+ } ,
1345+ endpoint_ids : [ 'endpoint-123' ] ,
1346+ agent_type : agentType ,
1347+ } ) ;
1348+ } ) . toThrow ( ) ;
1349+ } ) ;
1350+ }
13101351 } ) ;
13111352
13121353 describe ( 'MemoryDumpActionRequestSchema' , ( ) => {
0 commit comments