-
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
[Security Solution] Unskip related integrations tests #164933
[Security Solution] Unskip related integrations tests #164933
Conversation
31abd6d
to
6718a67
Compare
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
* | ||
* - open `app/integrations/detail/aws-1.17.0/overview?integration=cloudfront` | ||
* - click the button `Add Amazon CloudFront` | ||
* - fill in `Query URL` |
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.
* - fill in `Query URL` | |
* - fill in `Queue URL` |
/** | ||
* Agent policy and AWS package policy can be generated by Kibana by opening a page | ||
* `app/integrations/detail/aws-1.17.0/overview?integration=cloudfront` then | ||
* click the button `Add Amazon CloudFront` -> fill in `Query URL` -> press `Preview API request` at the bottom. |
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.
* click the button `Add Amazon CloudFront` -> fill in `Query URL` -> press `Preview API request` at the bottom. | |
* click the button `Add Amazon CloudFront` -> fill in `Queue URL` -> press `Preview API request` at the bottom. |
@@ -195,6 +198,18 @@ export const preventPrebuiltRulesPackageInstallation = () => { | |||
cy.intercept('POST', '/api/fleet/epm/packages/security_detection_engine/*', {}); | |||
}; | |||
|
|||
export const addAvailableToInstallPrebuiltRules = ( |
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.
I think the name of the method is a little confusing, if you don't understand the whole idea of first installing the assets, and then installing those assets as prebuilt rules to Kibana.
What do you think about makeRulesAvailableForInstall
?
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.
I ended up with installPrebuiltRuleAssets()
. It better reflects the process under the hood and an explanation comment should give some info. Generally speaking we can change business logic later on so installed assets aren't available to be installed without a flag or something and the function names makeRulesAvailableForInstall
won't do it its name says.
|
||
if (installToKibana) { | ||
cy.log('Install prebuilt rules', rules.length); |
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.
Now that we have addAvailableToInstallPrebuiltRules
, or however we want to call it, I think createAndInstallMockedPrebuiltRules
should always install the rules that were created as assets, without having the optional installToKibana
flag as param. So if you don't actually want to install the rules, you should just use addAvailableToInstallPrebuiltRules
.
Anyways, that is maybe out of scope of this PR, we can follow up on it.
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.
You are right, this is what we want eventually but it's out of scope of this PR. I'll come up with a refactoring PR to get rid of installToKibana
param.
* The contents below is a shrunk copy from the flyout with the only required inputs. | ||
*/ | ||
const AWS_PACKAGE_POLICY: PackagePolicyWithoutAgentPolicyId = { | ||
package: { | ||
name: 'aws', | ||
version: '1.17.0', | ||
}, | ||
name: 'aws-1', | ||
namespace: 'default', | ||
inputs: { | ||
'cloudtrail-aws-s3': { | ||
enabled: false, | ||
streams: { | ||
'aws.cloudtrail': { | ||
enabled: true, | ||
vars: { | ||
fips_enabled: false, | ||
tags: ['forwarded', 'aws-cloudtrail'], | ||
preserve_original_event: false, | ||
cloudtrail_regex: '/CloudTrail/', | ||
cloudtrail_digest_regex: '/CloudTrail-Digest/', | ||
cloudtrail_insight_regex: '/CloudTrail-Insight/', | ||
max_number_of_messages: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
'elb-aws-s3': { | ||
enabled: false, | ||
streams: { | ||
'aws.elb_logs': { | ||
enabled: true, | ||
vars: { | ||
fips_enabled: false, | ||
tags: ['forwarded', 'aws-elb-logs'], | ||
preserve_original_event: false, | ||
max_number_of_messages: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
'firewall-aws-s3': { | ||
enabled: false, | ||
streams: { | ||
'aws.firewall_logs': { | ||
enabled: true, | ||
vars: { | ||
fips_enabled: false, | ||
tags: ['forwarded', 'aws-firewall-logs'], | ||
preserve_original_event: false, | ||
max_number_of_messages: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
's3-aws-s3': { | ||
enabled: false, | ||
streams: { | ||
'aws.s3access': { | ||
enabled: true, | ||
vars: { | ||
fips_enabled: false, | ||
tags: ['forwarded', 'aws-s3access'], | ||
preserve_original_event: false, | ||
max_number_of_messages: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
'waf-aws-s3': { | ||
enabled: false, | ||
streams: { | ||
'aws.waf': { | ||
enabled: true, | ||
vars: { | ||
fips_enabled: false, | ||
tags: ['forwarded', 'aws-waf'], | ||
preserve_original_event: false, | ||
max_number_of_messages: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
'cloudfront-aws-s3': { | ||
enabled: true, | ||
streams: { | ||
'aws.cloudfront_logs': { | ||
enabled: true, | ||
vars: { | ||
queue_url: 'https://example.com', | ||
fips_enabled: false, | ||
tags: ['forwarded', 'aws-cloudfront'], | ||
preserve_original_event: false, | ||
max_number_of_messages: 5, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; |
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.
Can we move these types, utils and mocks to separate files from the main tests? Probably their own integrations.ts
files in the /helpers
and /tasks
dir?
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.
It's related to this test only. Moving it somewhere will reduce test's transparency. It makes sense if there is another test reusing the same policy.
cy.get(INTEGRATIONS_POPOVER).should( | ||
'have.text', | ||
`${rule.enabledIntegrations}/${rule.integrations.length} integrations` | ||
`${RULE_RELATED_INTEGRATIONS.filter((x) => x.enabled).length}/${ | ||
RULE_RELATED_INTEGRATIONS.length | ||
} integrations` |
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.
For readability:
cy.get(INTEGRATIONS_POPOVER).should( | |
'have.text', | |
`${rule.enabledIntegrations}/${rule.integrations.length} integrations` | |
`${RULE_RELATED_INTEGRATIONS.filter((x) => x.enabled).length}/${ | |
RULE_RELATED_INTEGRATIONS.length | |
} integrations` | |
const enabledIntegrations = RULE_RELATED_INTEGRATIONS.filter((x) => x.enabled).length; | |
const totalIntegrations = RULE_RELATED_INTEGRATIONS.length; | |
cy.get(INTEGRATIONS_POPOVER).should( | |
'have.text', | |
`${enabledIntegrations}/${totalIntegrations} integrations` |
cy.get(INTEGRATION_STATUS).should('have.length', RULE_RELATED_INTEGRATIONS.length); | ||
|
||
RULE_RELATED_INTEGRATIONS.forEach((integration, index) => { | ||
cy.get(INTEGRATION_LINK).eq(index).contains(getIntegrationName(integration), { |
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.
Wondering about the use of eq(i)
here (and in the rest of this file)
Can we guarantee that the order of the integrations links is always the same as defined in RULE_RELATED_INTEGRATIONS
? Might it be a cause of flakiness in the future?
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.
As you can see prebuilt rule asset and tests reuse the same constant RULE_RELATED_INTEGRATIONS
. Related integrations rendered in the popover are rendered based on rule.related_integrations
array. This means the order is stable now and we catch any changes here if some refactoring happens in the future.
6718a67
to
a767094
Compare
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.
LGTM
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.
Investigations changes LGTM!
44fe524
to
7f84a6a
Compare
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @maximpn |
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.
DE changes LGTM
💔 All backports failed
Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
**Fixes: elastic#154663 **Fixes: elastic#153684 ## Summary This PR unskips Cypress rule related integration tests ([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)). ## Details Testing approach has changed. Instead of importing a rule and installing agent and package policies via Fleet UI the rule is created by mocking a prebuilt rule asset and Fleet API is used to install required integrations. Along the way it required to add and update some testing selectors as UI had changed while the tests were skipped. ## Flaky test runner [related_integrations.cy.ts (150 runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995) 🟢 (cherry picked from commit 2c3464c) # Conflicts: # x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts # x-pack/test/security_solution_cypress/cypress/tasks/api_calls/prebuilt_rules.ts
#165310) # Backport This will backport the following commits from `main` to `8.10`: - [[Security Solution] Unskip related integrations tests (#164933)](#164933) <!--- Backport version: 8.9.8 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Maxim Palenov","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-31T10:28:16Z","message":"[Security Solution] Unskip related integrations tests (#164933)\n\n**Fixes: https://github.com/elastic/kibana/issues/154663**\r\n**Fixes: https://github.com/elastic/kibana/issues/153684**\r\n\r\n## Summary\r\n\r\nThis PR unskips Cypress rule related integration tests ([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)).\r\n\r\n## Details\r\n\r\nTesting approach has changed. Instead of importing a rule and installing agent and package policies via Fleet UI the rule is created by mocking a prebuilt rule asset and Fleet API is used to install required integrations. Along the way it required to add and update some testing selectors as UI had changed while the tests were skipped.\r\n\r\n## Flaky test runner\r\n\r\n[related_integrations.cy.ts (150 runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995) 🟢","sha":"2c3464ca8457e09f51852c6c0d60ab7f6e21afc0","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["test","release_note:skip","Team:Detections and Resp","Team: SecuritySolution","Feature:Rule Management","Team:Detection Rule Management","v8.10.0","v8.11.0","flake-docs"],"number":164933,"url":"https://github.com/elastic/kibana/pull/164933","mergeCommit":{"message":"[Security Solution] Unskip related integrations tests (#164933)\n\n**Fixes: https://github.com/elastic/kibana/issues/154663**\r\n**Fixes: https://github.com/elastic/kibana/issues/153684**\r\n\r\n## Summary\r\n\r\nThis PR unskips Cypress rule related integration tests ([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)).\r\n\r\n## Details\r\n\r\nTesting approach has changed. Instead of importing a rule and installing agent and package policies via Fleet UI the rule is created by mocking a prebuilt rule asset and Fleet API is used to install required integrations. Along the way it required to add and update some testing selectors as UI had changed while the tests were skipped.\r\n\r\n## Flaky test runner\r\n\r\n[related_integrations.cy.ts (150 runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995) 🟢","sha":"2c3464ca8457e09f51852c6c0d60ab7f6e21afc0"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/164933","number":164933,"mergeCommit":{"message":"[Security Solution] Unskip related integrations tests (#164933)\n\n**Fixes: https://github.com/elastic/kibana/issues/154663**\r\n**Fixes: https://github.com/elastic/kibana/issues/153684**\r\n\r\n## Summary\r\n\r\nThis PR unskips Cypress rule related integration tests ([related_integrations.cy.ts](https://github.com/elastic/kibana/blob/main/x-pack/test/security_solution_cypress/cypress/e2e/detection_response/rule_management/related_integrations/related_integrations.cy.ts)).\r\n\r\n## Details\r\n\r\nTesting approach has changed. Instead of importing a rule and installing agent and package policies via Fleet UI the rule is created by mocking a prebuilt rule asset and Fleet API is used to install required integrations. Along the way it required to add and update some testing selectors as UI had changed while the tests were skipped.\r\n\r\n## Flaky test runner\r\n\r\n[related_integrations.cy.ts (150 runs)](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2995) 🟢","sha":"2c3464ca8457e09f51852c6c0d60ab7f6e21afc0"}}]}] BACKPORT-->
Fixes: #154663
Fixes: #153684
Summary
This PR unskips Cypress rule related integration tests (related_integrations.cy.ts).
Details
Testing approach has changed. Instead of importing a rule and installing agent and package policies via Fleet UI the rule is created by mocking a prebuilt rule asset and Fleet API is used to install required integrations. Along the way it required to add and update some testing selectors as UI had changed while the tests were skipped.
Flaky test runner
related_integrations.cy.ts (150 runs) 🟢