Skip to content
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] Adds basic test for rule data view #136822

Merged
merged 12 commits into from
Jul 25, 2022

Conversation

MadameSheema
Copy link
Member

@MadameSheema MadameSheema commented Jul 21, 2022

Summary

In this PR we are adding a basic rule data view test in order to use it as a template/inspiration to extend the current coverage.

The test and the code are similar to the current one for creating another type of rule. These are the modifications introduced:

  • To the CustomRule structure we have added dataView as optional and we've made index optional instead of mandatory, since a rule might have one thing or the other. Also, some adjustments to the current code have been done in order to deal with this new structure.

  • On the method that fills the define step when creating a new rule, we check if the rule we are passing has a dataview, if so, we click on the data view selector and we fill that value. If not, we proceed as usual since our tests does not fill the index patterns input and uses the default ones.

  • On the test that creates a rule using a data view, we don't call cleanKibana method on the before hook, instead we call esArchiverReseKibana on the before each one. This is because we are creating a data view we'll use after and cleanKibana does not delete all the data views created, esArchiverReseKibana does. We don't use esArchiverReseKibana in all the tests because is a time-consuming method and we don't need to perform an exhaustive cleaning in all the other tests.

  • The test is the same as the other Custom query rule test but: we are creating a rule with a data view and we check that the data view displayed on the rule details is the expected instead of checking for the index patterns.

@MadameSheema MadameSheema marked this pull request as ready for review July 21, 2022 14:49
@MadameSheema MadameSheema requested review from a team as code owners July 21, 2022 14:49
@MadameSheema MadameSheema requested a review from banderror July 21, 2022 14:49
@MadameSheema MadameSheema self-assigned this Jul 21, 2022
Copy link
Contributor

@dhurley14 dhurley14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and thanks a bunch!

@MadameSheema MadameSheema added release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Security Solution Platform Security Solution Platform Team v8.4.0 labels Jul 22, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema MadameSheema enabled auto-merge (squash) July 22, 2022 14:13
Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few suggestions 🙂

@MadameSheema MadameSheema requested a review from a team as a code owner July 24, 2022 19:47
@MadameSheema
Copy link
Member Author

Thanks for the review @banderror!! The PR is ready to be reviewed again 😊

@@ -41,7 +45,7 @@ export const createCustomRule = (rule: CustomRule, ruleId = 'rule_testing', inte
severity: rule.severity.toLocaleLowerCase(),
type: 'query',
from: 'now-50000h',
index: rule.index,
index: rule.dataSource.type === 'indexPatterns' ? rule.dataSource.index : '',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, why default value for the index is an empty string and why don't we support posting a dataView if it's in the test data?

index: rule.dataSource.type === 'indexPatterns' ? rule.dataSource.index : undefined,
dataView: rule.dataSource.type === 'dataView' ? rule.dataSource.dataView : undefined,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would follow up this in a different/follow up PR, adding the capability of creating also a rule with data view at first glance is more complex, since first, we need to get the data view id.

headers: { 'kbn-xsrf': 'cypress-creds' },
});
export const createEventCorrelationRule = (rule: CustomRule, ruleId = 'rule_testing') => {
if (rule.dataSource.type === 'indexPatterns') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this condition, let's support both index patterns and data views here as in createCustomRule.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to do this on a different PR, since it could be a bit complex and at least we will have a test for data views already in main.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds good to me, thanks @MadameSheema 👍

failOnStatusCode: false,
});
export const createCustomIndicatorRule = (rule: ThreatIndicatorRule, ruleId = 'rule_testing') => {
if (rule.dataSource.type === 'indexPatterns') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this condition, let's support both index patterns and data views here as in createCustomRule.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

failOnStatusCode: false,
});
) => {
if (rule.dataSource.type === 'indexPatterns') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this condition, let's support both index patterns and data views here as in createCustomRule.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @MadameSheema

Copy link
Contributor

@banderror banderror left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing my annoying comments @MadameSheema ❤️
🚀

cy.request({
method: 'POST',
url: `/api/index_patterns/index_pattern`,
body: {
index_pattern: {
fieldAttrs: '{}',
title: indexPattern,
title: dataSource,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: dataViewTitle or just leave it as it was before - indexPattern?

@MadameSheema
Copy link
Member Author

@banderror your comments were not annoying! Lots of thanks for helping to deliver the best solution :)

@MadameSheema MadameSheema deleted the cypress/data-view-rule branch August 31, 2023 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Security Solution Platform Security Solution Platform Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants