-
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][Endpoint] Add Host Isolation related data to the …
…endpoint generator and test data loader (#100727) * Generate random isolation values for endpoint metadata * Generator for Fleet Actions * Added creation of actions to the index test data loader
- Loading branch information
1 parent
7fd6539
commit 57f59bd
Showing
5 changed files
with
145 additions
and
2 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
62 changes: 62 additions & 0 deletions
62
x-pack/plugins/security_solution/common/endpoint/data_generators/fleet_action_generator.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,62 @@ | ||
/* | ||
* 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 { DeepPartial } from 'utility-types'; | ||
import { merge } from 'lodash'; | ||
import { BaseDataGenerator } from './base_data_generator'; | ||
import { EndpointAction, EndpointActionResponse, ISOLATION_ACTIONS } from '../types'; | ||
|
||
const ISOLATION_COMMANDS: ISOLATION_ACTIONS[] = ['isolate', 'unisolate']; | ||
|
||
export class FleetActionGenerator extends BaseDataGenerator { | ||
/** Generate an Action */ | ||
generate(overrides: DeepPartial<EndpointAction> = {}): EndpointAction { | ||
const timeStamp = new Date(this.randomPastDate()); | ||
|
||
return merge( | ||
{ | ||
action_id: this.randomUUID(), | ||
'@timestamp': timeStamp.toISOString(), | ||
expiration: this.randomFutureDate(timeStamp), | ||
type: 'INPUT_ACTION', | ||
input_type: 'endpoint', | ||
agents: [this.randomUUID()], | ||
user_id: 'elastic', | ||
data: { | ||
command: this.randomIsolateCommand(), | ||
comment: this.randomString(15), | ||
}, | ||
}, | ||
overrides | ||
); | ||
} | ||
|
||
/** Generates an action response */ | ||
generateResponse(overrides: DeepPartial<EndpointActionResponse> = {}): EndpointActionResponse { | ||
const timeStamp = new Date(); | ||
|
||
return merge( | ||
{ | ||
action_data: { | ||
command: this.randomIsolateCommand(), | ||
comment: '', | ||
}, | ||
action_id: this.randomUUID(), | ||
agent_id: this.randomUUID(), | ||
started_at: this.randomPastDate(), | ||
completed_at: timeStamp.toISOString(), | ||
error: 'some error happen', | ||
'@timestamp': timeStamp.toISOString(), | ||
}, | ||
overrides | ||
); | ||
} | ||
|
||
protected randomIsolateCommand() { | ||
return this.randomChoice(ISOLATION_COMMANDS); | ||
} | ||
} |
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