-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cloud Security] Cypress Test for Misconfiguration Preview and Table for Contextual Flyout #193125
Changes from 16 commits
f8ed329
80d3a01
011fb8f
d19bbc2
df19df6
6e0ae67
1888ccd
7c2f468
3964c64
39e8233
c3879b2
1b8db59
ef20875
519dec9
a04efbd
f21365a
675f1c0
a6f95ea
499a692
5672e82
61b251e
bf1f173
4c328bb
9292da7
602865d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
steps: | ||
- command: .buildkite/scripts/steps/functional/cloud_security_posture.sh | ||
label: 'Cloud Security Posture Cypress Tests' | ||
agents: | ||
machineType: n2-standard-4 | ||
preemptible: true | ||
depends_on: | ||
- build | ||
- quick_checks | ||
timeout_in_minutes: 60 | ||
parallelism: 1 | ||
retry: | ||
automatic: | ||
- exit_status: '-1' | ||
limit: 1 | ||
|
||
- command: .buildkite/scripts/steps/functional/cloud_security_posture_serverless.sh | ||
label: 'Cloud Security Posture Cypress Tests on Serverless' | ||
agents: | ||
machineType: n2-standard-4 | ||
preemptible: true | ||
depends_on: | ||
- build | ||
- quick_checks | ||
timeout_in_minutes: 60 | ||
parallelism: 1 | ||
retry: | ||
automatic: | ||
- exit_status: '-1' | ||
limit: 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
source .buildkite/scripts/steps/functional/common.sh | ||
|
||
export JOB=kibana-cloud-security-posture-cypress | ||
export KIBANA_INSTALL_DIR=${KIBANA_BUILD_LOCATION} | ||
|
||
echo "--- Cloud Security Posture Workflows Cypress tests" | ||
|
||
cd x-pack/plugins/security_solution | ||
|
||
set +e | ||
|
||
yarn cypress:cloud_security_posture:run:ess; status=$?; yarn junit:merge || :; exit $status |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
source .buildkite/scripts/steps/functional/common.sh | ||
|
||
export JOB=kibana-cloud-security-posture-serverless-cypress | ||
export KIBANA_INSTALL_DIR=${KIBANA_BUILD_LOCATION} | ||
|
||
echo "--- Cloud Security Posture Workflows Cypress tests on Serverless" | ||
|
||
cd x-pack/plugins/security_solution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This path should be changed to: |
||
|
||
set +e | ||
|
||
yarn cypress:cloud_security_posture:run:serverless; status=$?; yarn junit:merge || :; exit $status |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1828,8 +1828,8 @@ x-pack/plugins/osquery @elastic/security-defend-workflows | |
/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/components/cloud_security_posture @elastic/fleet @elastic/kibana-cloud-security-posture | ||
/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/create_package_policy_page/single_page_layout/hooks/setup_technology.* @elastic/fleet @elastic/kibana-cloud-security-posture | ||
/x-pack/plugins/security_solution/public/cloud_security_posture @elastic/kibana-cloud-security-posture | ||
/x-pack/test/security_solution_cypress/cypress/e2e/explore/hosts/vulnerabilities_contextual_flyout.cy.ts @elastic/kibana-cloud-security-posture | ||
|
||
/x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/misconfiguration_contextual_flyout.cy.ts @elastic/kibana-cloud-security-posture | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to move this test to your new folder? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh woops |
||
/x-pack/test/security_solution_cypress/cypress/e2e/investigations/alerts/expandable_flyout/vulnerabilities_contextual_flyout.cy.ts @elastic/kibana-cloud-security-posture | ||
# Security Solution onboarding tour | ||
/x-pack/plugins/security_solution/public/common/components/guided_onboarding @elastic/security-threat-hunting-explore | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ For general guidelines, read [Kibana Testing Guide](https://www.elastic.co/guide | |
1. [End-to-End Tests](../../test/cloud_security_posture_functional/config.ts) | ||
1. [Serverless API Integration tests](../../test_serverless/api_integration/test_suites/security/config.ts) | ||
1. [Serverless End-to-End Tests](../../test_serverless/functional/test_suites/security/config.ts) | ||
1. [Cypress End-to-End Tests (Temporary location)](../../test/security_solution_cypress/cypress/e2e/cloud_security_posture) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this going to be a temporary location? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, this is going to be the permanent location (unless its a problem ?) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not! then let's remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, you mean that text lol |
||
|
||
|
||
### Tools | ||
|
@@ -73,6 +74,15 @@ yarn test:ftr --config x-pack/test_serverless/api_integration/test_suites/securi | |
yarn test:ftr --config x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.ts | ||
``` | ||
|
||
Run [**End-to-End Cypress Tests**](https://github.com/elastic/kibana/tree/main/x-pack/test/security_solution_cypress/cypress): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README inside the |
||
> **Note** | ||
> | ||
> Run this from security_solution_cypress folder | ||
```bash | ||
yarn cypress:open:serverless | ||
yarn cypress:open:ess | ||
``` | ||
|
||
#### Run **FTR tests (integration or e2e) for development** | ||
|
||
Functional test runner (FTR) can be used separately with `ftr:runner` and `ftr:server`. This is convenient while developing tests. | ||
|
@@ -107,4 +117,19 @@ run serverless e2e tests: | |
```bash | ||
yarn test:ftr:server --config x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.ts | ||
yarn test:ftr:runner ---config x-pack/test_serverless/functional/test_suites/security/config.cloud_security_posture.ts | ||
``` | ||
``` | ||
|
||
#### Run **Cypress tests (e2e) for development** | ||
When developing feature outside our plugin folder, instead of using FTRs for e2e test, we may use Cypress. Before running cypress, make sure you have installed it first. Like FTRs, we can run cypress in different environment, for example: | ||
|
||
run ess e2e tests: | ||
```bash | ||
yarn cypress:open:ess | ||
``` | ||
|
||
run serverless e2e tests: | ||
```bash | ||
yarn cypress:open:serverless | ||
``` | ||
|
||
Unlike FTR where we have to set server and runner separately, Cypress handles everything in 1 go, so just running the above the script is enough to get it running |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,6 +119,7 @@ export const MisconfigurationFindingsDetailsTable = memo( | |
METRIC_TYPE.CLICK, | ||
NAV_TO_FINDINGS_BY_RULE_NAME_FRPOM_ENTITY_FLYOUT | ||
); | ||
console.log(navToFindings({ [queryField]: name }, ['rule.name'])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing console? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, will address this |
||
navToFindings({ [queryField]: name }, ['rule.name']); | ||
}; | ||
|
||
|
@@ -190,6 +191,7 @@ export const MisconfigurationFindingsDetailsTable = memo( | |
columns={columns} | ||
pagination={pagination} | ||
onChange={onTableChange} | ||
data-test-subj={'securitySolutionFlyoutMisconfigurationFindingsTable'} | ||
/> | ||
</EuiPanel> | ||
</> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
/* | ||
* 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 { CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN } from '@kbn/cloud-security-posture-common'; | ||
import { createRule } from '../../tasks/api_calls/rules'; | ||
import { getNewRule } from '../../objects/rule'; | ||
import { getDataTestSubjectSelector } from '../../helpers/common'; | ||
|
||
import { rootRequest, deleteAlertsAndRules } from '../../tasks/api_calls/common'; | ||
import { | ||
expandFirstAlertHostFlyout, | ||
expandFirstAlertUserFlyout, | ||
} from '../../tasks/asset_criticality/common'; | ||
import { waitForAlertsToPopulate } from '../../tasks/create_new_rule'; | ||
import { login } from '../../tasks/login'; | ||
import { ALERTS_URL } from '../../urls/navigation'; | ||
import { visit } from '../../tasks/navigation'; | ||
|
||
const CSP_INSIGHT_MISCONFIGURATION_TITLE = getDataTestSubjectSelector( | ||
'securitySolutionFlyoutInsightsMisconfigurationsTitleLink' | ||
); | ||
|
||
const CSP_INSIGHT_TAB_TITLE = getDataTestSubjectSelector('securitySolutionFlyoutInsightInputsTab'); | ||
const CSP_INSIGHT_TABLE = getDataTestSubjectSelector( | ||
'securitySolutionFlyoutMisconfigurationFindingsTable' | ||
); | ||
|
||
const timestamp = Date.now(); | ||
|
||
// Create a Date object using the timestamp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: comments like this doesn't bring any value really as they are just describing the code below as is. So the can be safely removed |
||
const date = new Date(timestamp); | ||
|
||
// Convert the Date object to ISO 8601 format | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: same as the comment about, just stating the obvious |
||
const iso8601String = date.toISOString(); | ||
|
||
const mockFindingHostName = (matches: boolean) => { | ||
return { | ||
'@timestamp': iso8601String, | ||
host: { name: matches ? 'siem-kibana' : 'not-siem-kibana' }, | ||
resource: { | ||
id: '1234ABCD', | ||
name: 'kubelet', | ||
sub_type: 'lower case sub type', | ||
}, | ||
result: { evaluation: matches ? 'passed' : 'failed' }, // Adjusting result based on matches | ||
rule: { | ||
name: 'Upper case rule name', | ||
section: 'Upper case section', | ||
benchmark: { | ||
id: 'cis_k8s', | ||
posture_type: 'kspm', | ||
name: 'CIS Kubernetes V1.23', | ||
version: 'v1.0.0', | ||
}, | ||
type: 'process', | ||
}, | ||
cluster_id: 'Upper case cluster id', | ||
data_stream: { | ||
dataset: 'cloud_security_posture.findings', | ||
}, | ||
}; | ||
}; | ||
|
||
const mockFindingUserName = (matches: boolean) => { | ||
return { | ||
'@timestamp': iso8601String, | ||
user: { name: matches ? 'test' : 'not-test' }, | ||
resource: { | ||
id: '1234ABCD', | ||
name: 'kubelet', | ||
sub_type: 'lower case sub type', | ||
}, | ||
result: { evaluation: matches ? 'passed' : 'failed' }, // Adjusting result based on matches | ||
rule: { | ||
name: 'Upper case rule name', | ||
section: 'Upper case section', | ||
benchmark: { | ||
id: 'cis_k8s', | ||
posture_type: 'kspm', | ||
name: 'CIS Kubernetes V1.23', | ||
version: 'v1.0.0', | ||
}, | ||
type: 'process', | ||
}, | ||
cluster_id: 'Upper case cluster id', | ||
data_stream: { | ||
dataset: 'cloud_security_posture.findings', | ||
}, | ||
}; | ||
}; | ||
|
||
const createMockFinding = (isNameMatches: boolean, findingType: 'host.name' | 'user.name') => { | ||
return rootRequest({ | ||
method: 'POST', | ||
url: `${Cypress.env( | ||
'ELASTICSEARCH_URL' | ||
)}/${CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN}/_doc`, | ||
body: | ||
findingType === 'host.name' | ||
? mockFindingHostName(isNameMatches) | ||
: mockFindingUserName(isNameMatches), | ||
}); | ||
}; | ||
|
||
const deleteDataStream = () => { | ||
return rootRequest({ | ||
method: 'DELETE', | ||
url: `${Cypress.env( | ||
'ELASTICSEARCH_URL' | ||
)}/_data_stream/${CDR_LATEST_NATIVE_MISCONFIGURATIONS_INDEX_PATTERN}`, | ||
}); | ||
}; | ||
|
||
describe('Alert Host details expandable flyout', { tags: ['@ess', '@serverless'] }, () => { | ||
beforeEach(() => { | ||
deleteAlertsAndRules(); | ||
login(); | ||
createRule(getNewRule()); | ||
visit(ALERTS_URL); | ||
waitForAlertsToPopulate(); | ||
}); | ||
|
||
context('Host name - Has misconfiguration findings', () => { | ||
beforeEach(() => { | ||
createMockFinding(true, 'host.name'); | ||
cy.reload(); | ||
expandFirstAlertHostFlyout(); | ||
}); | ||
|
||
afterEach(() => { | ||
deleteDataStream(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here it is worth commenting that we deleting the data stream while we don't create it because the data stream is being created automatically when any |
||
}); | ||
|
||
it('should display Misconfiguration preview under Insights Entities when it has Misconfiguration Findings', () => { | ||
cy.log('check if Misconfiguration preview title shown'); | ||
cy.get(CSP_INSIGHT_MISCONFIGURATION_TITLE).should('be.visible'); | ||
}); | ||
|
||
it('should display insight tabs and findings table upon clicking on misconfiguration accordion', () => { | ||
cy.get(CSP_INSIGHT_MISCONFIGURATION_TITLE).click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Wrap this issue into a task method. |
||
cy.get(CSP_INSIGHT_TAB_TITLE).should('be.visible'); | ||
cy.get(CSP_INSIGHT_TABLE).should('be.visible'); | ||
}); | ||
}); | ||
|
||
context( | ||
'Host name - Has misconfiguration findings but host name is not the same as alert host name', | ||
() => { | ||
beforeEach(() => { | ||
createMockFinding(false, 'host.name'); | ||
cy.reload(); | ||
expandFirstAlertHostFlyout(); | ||
}); | ||
|
||
afterEach(() => { | ||
deleteDataStream(); | ||
}); | ||
|
||
it('should display Misconfiguration preview under Insights Entities when it has Misconfiguration Findings', () => { | ||
expandFirstAlertHostFlyout(); | ||
|
||
cy.log('check if Misconfiguration preview title is not shown'); | ||
cy.get(CSP_INSIGHT_MISCONFIGURATION_TITLE).should('not.exist'); | ||
}); | ||
} | ||
); | ||
|
||
context('User name - Has misconfiguration findings', () => { | ||
beforeEach(() => { | ||
createMockFinding(true, 'user.name'); | ||
cy.reload(); | ||
expandFirstAlertUserFlyout(); | ||
}); | ||
|
||
afterEach(() => { | ||
deleteDataStream(); | ||
}); | ||
|
||
it('should display Misconfiguration preview under Insights Entities when it has Misconfiguration Findings', () => { | ||
cy.log('check if Misconfiguration preview title shown'); | ||
cy.get(CSP_INSIGHT_MISCONFIGURATION_TITLE).should('be.visible'); | ||
}); | ||
|
||
it('should display insight tabs and findings table upon clicking on misconfiguration accordion', () => { | ||
cy.get(CSP_INSIGHT_MISCONFIGURATION_TITLE).click(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
cy.get(CSP_INSIGHT_TAB_TITLE).should('be.visible'); | ||
cy.get(CSP_INSIGHT_TABLE).should('be.visible'); | ||
}); | ||
}); | ||
|
||
context( | ||
'User name - Has misconfiguration findings but host name is not the same as alert host name', | ||
() => { | ||
beforeEach(() => { | ||
createMockFinding(false, 'user.name'); | ||
cy.reload(); | ||
expandFirstAlertHostFlyout(); | ||
}); | ||
|
||
afterEach(() => { | ||
deleteDataStream(); | ||
}); | ||
|
||
it('should display Misconfiguration preview under Insights Entities when it has Misconfiguration Findings', () => { | ||
expandFirstAlertUserFlyout(); | ||
|
||
cy.log('check if Misconfiguration preview title is not shown'); | ||
cy.get(CSP_INSIGHT_MISCONFIGURATION_TITLE).should('not.exist'); | ||
}); | ||
} | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This path should be changed to:
x-pack/test/security_solution_cypress
where the package.json commands and the tests live.