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][Detections] Improves indicator match Cypress tests #94913

Merged
merged 11 commits into from
Mar 25, 2021

Conversation

MadameSheema
Copy link
Member

@MadameSheema MadameSheema commented Mar 18, 2021

Summary

In this PR we are extending the current Indicator Match rules cypress tests:

  • Using filebeat threat intel data
  • Adding a test to check the enriched fields are correctly displayed on the timeline
  • Adding a test to check the enrichment is properly displayed on the json view

Pending to add a test to test the investigate on timeline as soon as the following bug is fixed: #95095

indicatorMapping: 'agent.id',
indicatorIndexField: 'agent.threat',
indicatorIndexPattern: ['filebeat-*'],
indicatorMapping: 'myhash.mysha256',
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize this isn't a new field, but the data structure we're using here conflicts with the terminology in the application: a mapping contains a "field" and a "value", which here correspond to `indicatorMapping" and "indicatorIndexField", respectively

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 that the disconnect between cypress' typings and the actual application typings is expected/desired, but I wanted to call this out as a potential source of confusion moving forward.

"type": "doc",
"value": {
"id": "_eZE7mwBOpWiDweStB_c",
"index": "threat-data-001",
Copy link
Contributor

Choose a reason for hiding this comment

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

threat-data is not very descriptive, especially when paired with threat_indicator. Perhaps we could call this suspicious_source_events or something like that?


export const JSON_CONTENT = '.ace_content';

export const JSON_VIEW_TAB = '#json-view';
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to add data-test-subjs for these tabs, but it looks like it would have to go into the tab's contents.

"id": "_uZE6nwBOpWiDweSth_D",
"index": "threat-indicator-0001",
"id": "84cf452c1e0375c3d4412cb550bd1783358468a3b3b777da4829d72c7d6fb74f",
"index": "filebeat-7.12.0-2021.03.10-000001",
Copy link
Contributor

Choose a reason for hiding this comment

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

The mappings for this index is currently 25k LOC; I think you can copy/paste/slightly modify the FTR mappings to reduce that file by two orders of magnitude 😉

@MadameSheema
Copy link
Member Author

@elasticmachine merge upstream

@MadameSheema MadameSheema force-pushed the improves-indicator-match branch from d8da4a3 to 9e7968b Compare March 24, 2021 17:21
@MadameSheema MadameSheema changed the title Improves indicator match Cypress tests [Security Solution][Detections] Improves indicator match Cypress tests Mar 24, 2021
@MadameSheema MadameSheema self-assigned this Mar 24, 2021
@MadameSheema MadameSheema added release_note:skip Skip the PR/issue when compiling release notes v7.13.0 v8.0.0 Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detections and Resp Security Detection Response Team labels Mar 24, 2021
@MadameSheema MadameSheema marked this pull request as ready for review March 24, 2021 19:12
@MadameSheema MadameSheema requested a review from a team as a code owner March 24, 2021 19:12
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 7.2MB 7.2MB +31.0B

History

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

cc @MadameSheema

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.

Mostly style questions here, nothing that should block this from getting merged since it's now green! 🍏 📗 💚

I would really like to try and keep the mappings as minimal as possible for these archives, but we can do that in a followup if need be; better to have the coverage now.

Comment on lines +500 to +501
const expectedEnrichment = [
{ line: 4, text: ' "threat": {' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this is an array so the subsequent .forEach reads a little odd.

Suggested change
const expectedEnrichment = [
{ line: 4, text: ' "threat": {' },
const expectedJsonViewRows = [
{ index: 4, text: ' "threat": {' },


export const scrollJsonViewToBottom = () => {
cy.get(JSON_CONTENT).click({ force: true });
cy.get(JSON_CONTENT).type('{pagedown}{pagedown}{pagedown}');
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting! Are there no prebuilt scroll helpers in cypress that would work here?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is but does not work with that concrete element (I don't know why)

} from '../screens/fields_browser';
import { KQL_SEARCH_BAR } from '../screens/hosts/main';

export const addsFields = (fields: string[]) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the tense on these helpers is a little strange; most of these use imperative tense ("add", "remove", "delete"), but several in this file use simple present tense ("adds"). Not the end of the world, just a discrepancy that gave me pause while reviewing.

@@ -92,6 +95,10 @@ export const TIMELINE_TEMPLATE_DETAILS = 'Timeline template';

export const TIMESTAMP_OVERRIDE_DETAILS = 'Timestamp override';

export const TIMELINE_FIELD = (field: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have any standards/guidelines for when to use all caps vs when to use camel case, here? I had assumed that functions would use camelcase as in getDetails below.

"fileset": {
"name": "abusemalware"
},
"threatintel": {
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

"properties": {
"@timestamp": {
"type": "date"
},
"agent": {
"properties": {
"build": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to trim this down further to only the fields that we're using in the accompanying data.json ? I thought that was the consensus but maybe I misunderstood.

@MadameSheema
Copy link
Member Author

Thanks for the review @rylnd I'll merge it to have coverage as soon as possible and we can do all the mentioned changes in a future PR.

@MadameSheema MadameSheema merged commit 6a57148 into elastic:master Mar 25, 2021
@MadameSheema MadameSheema deleted the improves-indicator-match branch March 25, 2021 18:25
MadameSheema added a commit to MadameSheema/kibana that referenced this pull request Mar 25, 2021
elastic#94913)

* updates the data used in the test

* adds matches test

* adds enrichment test

* improves speed and adds missing files

* fixes type check issue

* adds 'data-test-subj' for the json view tab

* refactor

* fixes typecheck issue

* updates tests with latest master changes

Co-authored-by: Kibana Machine <[email protected]>
MadameSheema added a commit that referenced this pull request Mar 25, 2021
#94913) (#95449)

* updates the data used in the test

* adds matches test

* adds enrichment test

* improves speed and adds missing files

* fixes type check issue

* adds 'data-test-subj' for the json view tab

* refactor

* fixes typecheck issue

* updates tests with latest master changes

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

Co-authored-by: Kibana Machine <[email protected]>
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:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution] Default and created timeline template selected by default on rule creation
4 participants