-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution][Endpoint] Cypress test to validate that Endpoint can stream alerts to ES/Kibana #155455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
paul-tavares
merged 29 commits into
elastic:main
from
paul-tavares:task/olm-6030-test-endpoint-sends-alert-events
Apr 25, 2023
Merged
[Security Solution][Endpoint] Cypress test to validate that Endpoint can stream alerts to ES/Kibana #155455
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
8c95dd8
initial setup for a standalone service to create endpoint host VMs
paul-tavares 931e7a6
Scripts: added `getAgentDownloadUrl()` to `common/fleet_services` (co…
paul-tavares 55fc86c
Scripts: Initial version of reusable Endpoint Host Services service
paul-tavares 03e1b3e
Initial file setup for Endpoint alerts tests
paul-tavares 84be7ed
Added `getLatestAgentDownloadVersion` to scripts fleet services and e…
paul-tavares 740f10b
New `waitForEndpointToStreamData()` to script/common Endpoint Metadat…
paul-tavares 5fe4fbb
Cy endpoint policy task to enable all protections
paul-tavares 86b99cd
Added `dataLoadersForRealEndpoints()` support for endpoint suite
paul-tavares c0a43a1
Cy data load of real endpoint done in test
paul-tavares 1eaa2f9
enable experimental feature in Endpoint Cy config
paul-tavares 7f61e7d
added `waitForActionToComplete` to response actions tasks
paul-tavares 2ec7f54
Added new Cy `waitUntil()` and refactored `waitForActionToComplete()`…
paul-tavares 06e2418
initial structure for checking that alerts are received from endpoint
paul-tavares d41e63c
waits for alert to be streamed by endpoint
paul-tavares 7b31879
cy: additional alerts related tasks
paul-tavares ccb6926
cy: alerts related screen selectors
paul-tavares edd96e4
cy: complete working test for alerts
paul-tavares 731666b
Destroy VM + unenroll fleet agent common script utilities
paul-tavares 43f0355
added Delete VM + unenroll agent + delete policies to the test
paul-tavares a1b5add
Initial work for a `deleteAllEndpointData()` utility
paul-tavares a3ac77e
ability to delete all data associated with an Endpoint ID
paul-tavares 9d5d503
Add deleate all endpoint data task and associated utility function an…
paul-tavares 538a681
Merge branch 'main' into task/olm-6030-test-endpoint-sends-alert-events
paul-tavares 1ea3181
Merge remote-tracking branch 'upstream/main' into task/olm-6030-test-…
paul-tavares 5c4ed33
Merge remote-tracking branch 'origin/task/olm-6030-test-endpoint-send…
paul-tavares 9e863b6
Rename prop of `<EndpointAgentStatusById>`
paul-tavares 74dd339
Merge branch 'main' into task/olm-6030-test-endpoint-sends-alert-events
paul-tavares 745b61c
added code to ignore 404 error only in `waitForEndpointToStreamData`
paul-tavares 7445dce
Merge remote-tracking branch 'origin/task/olm-6030-test-endpoint-send…
paul-tavares File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
107 changes: 107 additions & 0 deletions
107
...ck/plugins/security_solution/public/management/cypress/e2e/endpoint/endpoint_alerts.cy.ts
This file contains hidden or 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,107 @@ | ||
| /* | ||
| * 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 { deleteAllLoadedEndpointData } from '../../tasks/delete_all_endpoint_data'; | ||
| import { getAlertsTableRows, navigateToAlertsList } from '../../screens/alerts'; | ||
| import { waitForEndpointAlerts } from '../../tasks/alerts'; | ||
| import { request } from '../../tasks/common'; | ||
| import { getEndpointIntegrationVersion } from '../../tasks/fleet'; | ||
| import type { IndexedFleetEndpointPolicyResponse } from '../../../../../common/endpoint/data_loaders/index_fleet_endpoint_policy'; | ||
| import { enableAllPolicyProtections } from '../../tasks/endpoint_policy'; | ||
| import type { PolicyData, ResponseActionApiResponse } from '../../../../../common/endpoint/types'; | ||
| import type { CreateAndEnrollEndpointHostResponse } from '../../../../../scripts/endpoint/common/endpoint_host_services'; | ||
| import { login } from '../../tasks/login'; | ||
| import { EXECUTE_ROUTE } from '../../../../../common/endpoint/constants'; | ||
| import { waitForActionToComplete } from '../../tasks/response_actions'; | ||
|
|
||
| describe('Endpoint generated alerts', () => { | ||
| let indexedPolicy: IndexedFleetEndpointPolicyResponse; | ||
| let policy: PolicyData; | ||
| let createdHost: CreateAndEnrollEndpointHostResponse; | ||
|
|
||
| before(() => { | ||
| getEndpointIntegrationVersion().then((version) => { | ||
| const policyName = `alerts test ${Math.random().toString(36).substring(2, 7)}`; | ||
|
|
||
| cy.task<IndexedFleetEndpointPolicyResponse>('indexFleetEndpointPolicy', { | ||
| policyName, | ||
| endpointPackageVersion: version, | ||
| agentPolicyName: policyName, | ||
| }).then((data) => { | ||
| indexedPolicy = data; | ||
| policy = indexedPolicy.integrationPolicies[0]; | ||
|
|
||
| return enableAllPolicyProtections(policy.id).then(() => { | ||
| // Create and enroll a new Endpoint host | ||
| return cy | ||
| .task( | ||
| 'createEndpointHost', | ||
| { | ||
| agentPolicyId: policy.policy_id, | ||
| }, | ||
| { timeout: 180000 } | ||
| ) | ||
| .then((host) => { | ||
| createdHost = host as CreateAndEnrollEndpointHostResponse; | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| after(() => { | ||
| if (createdHost) { | ||
| cy.task('destroyEndpointHost', createdHost).then(() => {}); | ||
| } | ||
|
|
||
| if (indexedPolicy) { | ||
| cy.task('deleteIndexedFleetEndpointPolicies', indexedPolicy); | ||
| } | ||
|
|
||
| if (createdHost) { | ||
| deleteAllLoadedEndpointData({ endpointAgentIds: [createdHost.agentId] }); | ||
| } | ||
| }); | ||
|
|
||
| beforeEach(() => { | ||
| login(); | ||
| }); | ||
|
|
||
| it('should create a Detection Engine alert from an endpoint alert', () => { | ||
| // Triggers a Malicious Behaviour alert on Linux system (`grep *` was added only to identify this specific alert) | ||
| const executeMaliciousCommand = `bash -c cat /dev/tcp/foo | grep ${Math.random() | ||
| .toString(16) | ||
| .substring(2)}`; | ||
|
|
||
| // Send `execute` command that triggers malicious behaviour using the `execute` response action | ||
| request<ResponseActionApiResponse>({ | ||
| method: 'POST', | ||
| url: EXECUTE_ROUTE, | ||
| body: { | ||
| endpoint_ids: [createdHost.agentId], | ||
| parameters: { | ||
| command: executeMaliciousCommand, | ||
| }, | ||
| }, | ||
| }) | ||
| .then((response) => waitForActionToComplete(response.body.data.id)) | ||
| .then(() => { | ||
| return waitForEndpointAlerts(createdHost.agentId, [ | ||
| { | ||
| term: { 'process.group_leader.args': executeMaliciousCommand }, | ||
| }, | ||
| ]); | ||
| }) | ||
| .then(() => { | ||
| return navigateToAlertsList( | ||
| `query=(language:kuery,query:'agent.id: "${createdHost.agentId}" ')` | ||
| ); | ||
| }); | ||
|
|
||
| getAlertsTableRows().should('have.length.greaterThan', 0); | ||
| }); | ||
| }); |
41 changes: 41 additions & 0 deletions
41
x-pack/plugins/security_solution/public/management/cypress/screens/alerts.ts
This file contains hidden or 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,41 @@ | ||
| /* | ||
| * 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 { APP_ALERTS_PATH } from '../../../../common/constants'; | ||
|
|
||
| export const navigateToAlertsList = (urlQueryParams: string = '') => { | ||
| cy.visit(`${APP_ALERTS_PATH}${urlQueryParams ? `?${urlQueryParams}` : ''}`); | ||
| }; | ||
|
|
||
| export const clickAlertListRefreshButton = (): Cypress.Chainable => { | ||
| return cy.getByTestSubj('querySubmitButton').click().should('be.enabled'); | ||
| }; | ||
|
|
||
| /** | ||
| * Waits until the Alerts list has alerts data and return the number of rows that are currently displayed | ||
| * @param timeout | ||
| */ | ||
| export const getAlertsTableRows = (timeout?: number): Cypress.Chainable<JQuery<HTMLDivElement>> => { | ||
| let $rows: JQuery<HTMLDivElement> = Cypress.$(); | ||
|
|
||
| return cy | ||
| .waitUntil( | ||
| () => { | ||
| clickAlertListRefreshButton(); | ||
|
|
||
| return cy | ||
| .getByTestSubj('alertsTable') | ||
| .find<HTMLDivElement>('.euiDataGridRow') | ||
| .then(($rowsFound) => { | ||
| $rows = $rowsFound; | ||
| return Boolean($rows); | ||
| }); | ||
| }, | ||
| { timeout } | ||
| ) | ||
| .then(() => $rows); | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.