-
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.
[8.8] [Defend Workflows][E2E]Endpoint e2e response console multipass (#…
…155519) (#155975) # Backport This will backport the following commits from `main` to `8.8`: - [[Defend Workflows][E2E]Endpoint e2e response console multipass (#155519)](#155519) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Konrad Szwarc","email":"konrad.szwarc@elastic.co"},"sourceCommit":{"committedDate":"2023-04-27T08:27:21Z","message":"[Defend Workflows][E2E]Endpoint e2e response console multipass (#155519)\n\nThis PR adds e2e test run on real endpoint for coverage of isolate,\r\nprocesses, kill-process and suspend-process commands from respond\r\nconsole.\r\n\r\nDepends on https://github.com/elastic/kibana/pull/155360","sha":"d80fdd6bceec438cae572ba13eae3ee3a9d3c5c3","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Defend Workflows","v8.8.0","v8.9.0"],"number":155519,"url":"https://github.com/elastic/kibana/pull/155519","mergeCommit":{"message":"[Defend Workflows][E2E]Endpoint e2e response console multipass (#155519)\n\nThis PR adds e2e test run on real endpoint for coverage of isolate,\r\nprocesses, kill-process and suspend-process commands from respond\r\nconsole.\r\n\r\nDepends on https://github.com/elastic/kibana/pull/155360","sha":"d80fdd6bceec438cae572ba13eae3ee3a9d3c5c3"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/155519","number":155519,"mergeCommit":{"message":"[Defend Workflows][E2E]Endpoint e2e response console multipass (#155519)\n\nThis PR adds e2e test run on real endpoint for coverage of isolate,\r\nprocesses, kill-process and suspend-process commands from respond\r\nconsole.\r\n\r\nDepends on https://github.com/elastic/kibana/pull/155360","sha":"d80fdd6bceec438cae572ba13eae3ee3a9d3c5c3"}}]}] BACKPORT--> Co-authored-by: Konrad Szwarc <konrad.szwarc@elastic.co> Co-authored-by: Patryk Kopyciński <contact@patrykkopycinski.com>
- Loading branch information
1 parent
a675560
commit 742d261
Showing
5 changed files
with
258 additions
and
26 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
170 changes: 170 additions & 0 deletions
170
...k/plugins/security_solution/public/management/cypress/e2e/endpoint/response_console.cy.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,170 @@ | ||
/* | ||
* 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 type { Agent } from '@kbn/fleet-plugin/common'; | ||
import { | ||
inputConsoleCommand, | ||
openResponseConsoleFromEndpointList, | ||
performCommandInputChecks, | ||
submitCommand, | ||
waitForCommandToBeExecuted, | ||
waitForEndpointListPageToBeLoaded, | ||
} from '../../tasks/response_console'; | ||
import type { IndexedFleetEndpointPolicyResponse } from '../../../../../common/endpoint/data_loaders/index_fleet_endpoint_policy'; | ||
import { | ||
getAgentByHostName, | ||
getEndpointIntegrationVersion, | ||
reassignAgentPolicy, | ||
} from '../../tasks/fleet'; | ||
import { | ||
checkEndpointListForOnlyIsolatedHosts, | ||
checkEndpointListForOnlyUnIsolatedHosts, | ||
createAgentPolicyTask, | ||
} from '../../tasks/isolate'; | ||
import { login } from '../../tasks/login'; | ||
import { ENDPOINT_VM_NAME } from '../../tasks/common'; | ||
|
||
describe('Response console', () => { | ||
const endpointHostname = Cypress.env(ENDPOINT_VM_NAME); | ||
|
||
beforeEach(() => { | ||
login(); | ||
}); | ||
|
||
describe('User journey for Isolate command: isolate and release an endpoint', () => { | ||
let response: IndexedFleetEndpointPolicyResponse; | ||
let initialAgentData: Agent; | ||
|
||
before(() => { | ||
getAgentByHostName(endpointHostname).then((agentData) => { | ||
initialAgentData = agentData; | ||
}); | ||
|
||
getEndpointIntegrationVersion().then((version) => | ||
createAgentPolicyTask(version).then((data) => { | ||
response = data; | ||
}) | ||
); | ||
}); | ||
|
||
after(() => { | ||
if (initialAgentData?.policy_id) { | ||
reassignAgentPolicy(initialAgentData.id, initialAgentData.policy_id); | ||
} | ||
if (response) { | ||
cy.task('deleteIndexedFleetEndpointPolicies', response); | ||
} | ||
}); | ||
|
||
it('should isolate host from response console', () => { | ||
waitForEndpointListPageToBeLoaded(endpointHostname); | ||
checkEndpointListForOnlyUnIsolatedHosts(); | ||
openResponseConsoleFromEndpointList(); | ||
performCommandInputChecks('isolate'); | ||
submitCommand(); | ||
waitForCommandToBeExecuted(); | ||
waitForEndpointListPageToBeLoaded(endpointHostname); | ||
checkEndpointListForOnlyIsolatedHosts(); | ||
}); | ||
|
||
it('should release host from response console', () => { | ||
waitForEndpointListPageToBeLoaded(endpointHostname); | ||
checkEndpointListForOnlyIsolatedHosts(); | ||
openResponseConsoleFromEndpointList(); | ||
performCommandInputChecks('release'); | ||
submitCommand(); | ||
waitForCommandToBeExecuted(); | ||
waitForEndpointListPageToBeLoaded(endpointHostname); | ||
checkEndpointListForOnlyUnIsolatedHosts(); | ||
}); | ||
}); | ||
|
||
describe('User journey for Processes commands: list, kill and suspend process.', () => { | ||
let response: IndexedFleetEndpointPolicyResponse; | ||
let initialAgentData: Agent; | ||
let cronPID: string; | ||
let newCronPID: string; | ||
|
||
before(() => { | ||
getAgentByHostName(endpointHostname).then((agentData) => { | ||
initialAgentData = agentData; | ||
}); | ||
|
||
getEndpointIntegrationVersion().then((version) => | ||
createAgentPolicyTask(version).then((data) => { | ||
response = data; | ||
}) | ||
); | ||
}); | ||
|
||
after(() => { | ||
if (initialAgentData?.policy_id) { | ||
reassignAgentPolicy(initialAgentData.id, initialAgentData.policy_id); | ||
} | ||
if (response) { | ||
cy.task('deleteIndexedFleetEndpointPolicies', response); | ||
} | ||
}); | ||
|
||
it('"processes" - should obtain a list of processes', () => { | ||
waitForEndpointListPageToBeLoaded(endpointHostname); | ||
openResponseConsoleFromEndpointList(); | ||
performCommandInputChecks('processes'); | ||
submitCommand(); | ||
cy.contains('Action pending.').should('exist'); | ||
cy.getByTestSubj('getProcessesSuccessCallout', { timeout: 120000 }).within(() => { | ||
['USER', 'PID', 'ENTITY ID', 'COMMAND'].forEach((header) => { | ||
cy.contains(header); | ||
}); | ||
|
||
cy.get('tbody > tr').should('have.length.greaterThan', 0); | ||
cy.get('tbody > tr > td').should('contain', '/usr/sbin/cron'); | ||
cy.get('tbody > tr > td') | ||
.contains('/usr/sbin/cron') | ||
.parents('td') | ||
.siblings('td') | ||
.eq(1) | ||
.find('span') | ||
.then((span) => { | ||
cronPID = span.text(); | ||
}); | ||
}); | ||
}); | ||
|
||
it('"kill-process --pid" - should kill a process', () => { | ||
waitForEndpointListPageToBeLoaded(endpointHostname); | ||
openResponseConsoleFromEndpointList(); | ||
inputConsoleCommand(`kill-process --pid ${cronPID}`); | ||
submitCommand(); | ||
waitForCommandToBeExecuted(); | ||
|
||
performCommandInputChecks('processes'); | ||
submitCommand(); | ||
|
||
cy.getByTestSubj('getProcessesSuccessCallout', { timeout: 120000 }).within(() => { | ||
cy.get('tbody > tr > td') | ||
.contains('/usr/sbin/cron') | ||
.parents('td') | ||
.siblings('td') | ||
.eq(1) | ||
.find('span') | ||
.then((span) => { | ||
newCronPID = span.text(); | ||
}); | ||
}); | ||
expect(newCronPID).to.not.equal(cronPID); | ||
}); | ||
|
||
it('"suspend-process --pid" - should suspend a process', () => { | ||
waitForEndpointListPageToBeLoaded(endpointHostname); | ||
openResponseConsoleFromEndpointList(); | ||
inputConsoleCommand(`suspend-process --pid ${newCronPID}`); | ||
submitCommand(); | ||
waitForCommandToBeExecuted(); | ||
}); | ||
}); | ||
}); |
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
58 changes: 58 additions & 0 deletions
58
x-pack/plugins/security_solution/public/management/cypress/tasks/response_console.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,58 @@ | ||
/* | ||
* 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 { closeAllToasts } from './close_all_toasts'; | ||
import { APP_ENDPOINTS_PATH } from '../../../../common/constants'; | ||
|
||
export const waitForEndpointListPageToBeLoaded = (endpointHostname: string): void => { | ||
cy.visit(APP_ENDPOINTS_PATH); | ||
closeAllToasts(); | ||
cy.contains(endpointHostname).should('exist'); | ||
}; | ||
export const openResponseConsoleFromEndpointList = (): void => { | ||
cy.getByTestSubj('endpointTableRowActions').first().click(); | ||
cy.contains('Respond').click(); | ||
}; | ||
|
||
export const inputConsoleCommand = (command: string): void => { | ||
cy.getByTestSubj('endpointResponseActionsConsole-inputCapture').click().type(command); | ||
}; | ||
|
||
export const clearConsoleCommandInput = (): void => { | ||
cy.getByTestSubj('endpointResponseActionsConsole-inputCapture') | ||
.click() | ||
.type(`{selectall}{backspace}`); | ||
}; | ||
|
||
export const selectCommandFromHelpMenu = (command: string): void => { | ||
cy.getByTestSubj('endpointResponseActionsConsole-header-helpButton').click(); | ||
cy.getByTestSubj( | ||
`endpointResponseActionsConsole-commandList-Responseactions-${command}-addToInput` | ||
).click(); | ||
}; | ||
|
||
export const checkInputForCommandPresence = (command: string): void => { | ||
cy.getByTestSubj('endpointResponseActionsConsole-cmdInput-leftOfCursor') | ||
.invoke('text') | ||
.should('eq', `${command} `); // command in the cli input is followed by a space | ||
}; | ||
|
||
export const submitCommand = (): void => { | ||
cy.getByTestSubj('endpointResponseActionsConsole-inputTextSubmitButton').click(); | ||
}; | ||
|
||
export const waitForCommandToBeExecuted = (): void => { | ||
cy.contains('Action pending.').should('exist'); | ||
cy.contains('Action completed.', { timeout: 120000 }).should('exist'); | ||
}; | ||
|
||
export const performCommandInputChecks = (command: string) => { | ||
inputConsoleCommand(command); | ||
clearConsoleCommandInput(); | ||
selectCommandFromHelpMenu(command); | ||
checkInputForCommandPresence(command); | ||
}; |