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] Improves detections tests #77295

Merged
merged 26 commits into from
Sep 29, 2020

Conversation

MadameSheema
Copy link
Member

@MadameSheema MadameSheema commented Sep 13, 2020

Summary

In this PR we are improving some of the the detections Cypress following tests with the following changes:

  • For Creates and activates a new rule test:

    • The rule populates alerts
    • We assert that the rule is generating alerts
    • We assert that the values of the generated alert are the expected ones
  • For Creates and activates a new custom rule with override option:

    • The rule populates alerts
    • We assert that the rule is generating alerts
    • We assert that the values of the generated alert are the expected ones taking into account the override functionality
  • For Creates and activates a new threshold rule:

  • The rule populates alerts

  • We assert that the rule is generating alerts

  • We assert that the values of the generated alert are the expected ones

Also in general we are trying to improve the readability.

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

# Conflicts:
#	x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_custom.spec.ts
#	x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_ml.spec.ts
#	x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_override.spec.ts
#	x-pack/plugins/security_solution/cypress/integration/alerts_detection_rules_threshold.spec.ts
#	x-pack/plugins/security_solution/cypress/screens/rule_details.ts
#	x-pack/plugins/security_solution/cypress/tasks/create_new_rule.ts
@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema MadameSheema self-assigned this Sep 17, 2020
@MadameSheema MadameSheema added Team:SIEM v7.10.0 v8.0.0 release_note:skip Skip the PR/issue when compiling release notes labels Sep 17, 2020
@MadameSheema MadameSheema marked this pull request as ready for review September 17, 2020 19:35
@MadameSheema MadameSheema requested review from a team as code owners September 17, 2020 19:35
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

There looks to be a bad merge conflict in there, so we should address that before merging this.

I had a few nits about lets and I still have a concern about synchronizing the rule execution, as well.

cy.get(SHOWING_ALERTS)
.invoke('text')
.should('eql', `Showing ${expectedNumberOfAlerts.toString()} alerts`);
cy.get(NUMBER_OF_ALERTS).should('have.text', expectedNumberOfAlerts.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume this is the preference for text assertions, now? Is it more robust, or better errors, or both?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes this is the preference now when possible, is more robust because should clause in Cypress will continue to retry its specified assertions until it times out, and also improves the readability of the tests.

cy.get(LOOK_BACK_TIME_TYPE).select(rule.lookBack.timeType);
};

export const expectDefineFormToRepopulateAndContinue = (rule: CustomRule) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these came from a bad merge resolution; they were removed in #77090

Copy link
Member Author

Choose a reason for hiding this comment

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

mmmm you are right! Thanks for catching this :)

.invoke('text')
.then((ruleStatus) => {
if (ruleStatus !== 'succeeded') {
cy.get('[data-test-subj=refreshButton]').click();
Copy link
Contributor

Choose a reason for hiding this comment

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

Without the commented-out assertion below, there's nothing to synchronize the results of the refresh, right? Here's how I'm picturing it:

  1. page is loaded, rule has not finished executing
  2. we click refresh
  3. We continue on with the test, with no guarantee that the rule has executed

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'll take a deeper look to this.

eqlRule.referenceUrls.forEach((url) => {
expectedUrls = expectedUrls + url;
});
let expectedFalsePositives = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're not expecting these values to change it would be nice use const with a .map or .reduce for these guys. I know these are copy/pasted from elsewhere, but I've got the const version in the EQL rule tests.

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

This looks great! I had one minor quibble about the ordering of test assertions, but nothing that should block this. LGTM.

// cy.get('[data-test-subj=ruleStatus]').should('have.text', 'succeeded')
}
});
cy.get(RULE_STATUS).should((ruleStatus) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

🥇 💯 I was hoping cypress would have have a nice way to do this, but this is better than I expected!

getDescriptionForTitle('Additional look-back time').invoke('text').should('eql', '1m');
getDetails(RUNS_EVERY_DETAILS).should(
'have.text',
`${newRule.runsEvery.interval}${newRule.runsEvery.type}`
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 thanks for adding these scheduling fields!


goToRuleDetails();
waitForTheRuleToBeExecuted();
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put this guard as close to the dependent assertions as possible: since (I think) it's only required for the alerts assertions, I would move this a bit further down.

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id value diff baseline
securitySolution 10.2MB +38.0B 10.2MB

History

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

@MadameSheema MadameSheema merged commit 7285026 into elastic:master Sep 29, 2020
@MadameSheema MadameSheema deleted the improves-detections branch September 29, 2020 08:35
MadameSheema added a commit to MadameSheema/kibana that referenced this pull request Sep 29, 2020
* improves 'Creates and activates a new custom rule' test

* fixes constant problem

* improves 'Creates and activates a new custom rule with override option' test

* improves 'Creates and activates a new threshold rule' test

* refactor

* fixes type check issue

* improves assertions

* removes unused code

* changes variables for constants

* improves 'waitForTheRuleToBeExecuted' test

* improves readability

* fixes jenkins error

* refactor

* refactor

Co-authored-by: Elastic Machine <[email protected]>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Sep 29, 2020
* master: (365 commits)
  making expression debug info serializable (elastic#78727)
  fix lodahs imports in app-arch code (elastic#78582)
  Make Field a React.lazy export (elastic#78483)
  [Security Solution] Improves detections tests (elastic#77295)
  [TSVB] Different field format on different series is ignored (elastic#78138)
  RFC: Improve saved object migrations (elastic#66056)
  [Security Solution] Fixes url timeline flaky test (elastic#78556)
  adds retryability feature (elastic#78611)
  Aligns several module versions across the repository (elastic#78327)
  Empty prompt and loading spinner for service map (elastic#78382)
  Change progress bar to spinner (elastic#78460)
  [QA][Code Coverage] Coverage teams lookup w/o Additional Config (elastic#77111)
  Slim down core bundle (elastic#75912)
  [Alerting] retry internal OCC calls within alertsClient (elastic#77838)
  [kbn/optimizer] only build xpack examples when building xpack plugins (elastic#78656)
  [Ingest Manager] Ingest setup upgrade (elastic#78081)
  [Ingest Manager] Surface saved object client 10,000 limitation to bulk actions UI (elastic#78520)
  fix name without a category or if field end with .text (elastic#78655)
  [Security Solution] [Detections] Log message enhancements (elastic#78429)
  [ML]DF Analytics exploration: default filter of results page by `defaultIsTraining` value in url (elastic#78303)
  ...
MadameSheema added a commit that referenced this pull request Sep 29, 2020
* improves 'Creates and activates a new custom rule' test

* fixes constant problem

* improves 'Creates and activates a new custom rule with override option' test

* improves 'Creates and activates a new threshold rule' test

* refactor

* fixes type check issue

* improves assertions

* removes unused code

* changes variables for constants

* improves 'waitForTheRuleToBeExecuted' test

* improves readability

* fixes jenkins error

* refactor

* refactor

Co-authored-by: Elastic Machine <[email protected]>

Co-authored-by: Elastic Machine <[email protected]>
phillipb added a commit to phillipb/kibana that referenced this pull request Sep 29, 2020
…-to-timeline

* 'master' of github.com:elastic/kibana: (22 commits)
  update apm index pattern (elastic#78732)
  78024: move transform out of dataset (elastic#78216)
  [QA][Code Coverage] Upload the coverage static site before ingestion (elastic#78695)
  [Discover] Make _source field not clickable (elastic#78698)
  [Fleet] Rename Ingest Manager => Fleet, Fleet => Agents in the UI (elastic#78685)
  [APM] Review feedback from distribution + transaction metrics (elastic#78752)
  [Ingest pipelines] Add ability to stop pipeline simulation  (elastic#78183)
  [CSM] Fix core vital legend background (elastic#78273)
  [Usage Collection] [schema] Support spreads + `canvas` definition (elastic#78481)
  fix lodash imports (elastic#78456)
  [Maps] Add layer type preview icons (elastic#78650)
  [APM] Use transaction metrics for distribution charts (elastic#78484)
  [Uptime] Ml anomaly alert edit (elastic#76909)
  [ML] Limit exposing shared static code through ml/public/index.ts. (elastic#77745)
  making expression debug info serializable (elastic#78727)
  fix lodahs imports in app-arch code (elastic#78582)
  Make Field a React.lazy export (elastic#78483)
  [Security Solution] Improves detections tests (elastic#77295)
  [TSVB] Different field format on different series is ignored (elastic#78138)
  RFC: Improve saved object migrations (elastic#66056)
  ...
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 23, 2021
@elasticmachine
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants