Skip to content

[Security Solution][Detection Engine] Fixes indicator matches mapping UI where invalid list values can cause overwrites of other values#89066

Merged
FrankHassanabad merged 16 commits intoelastic:masterfrom
FrankHassanabad:fix-ui-react-keys
Jan 30, 2021
Merged

Conversation

@FrankHassanabad
Copy link
Copy Markdown
Contributor

@FrankHassanabad FrankHassanabad commented Jan 22, 2021

Summary

This fixes the ReactJS keys to not use array indexes for the ReactJS keys which fixes #84893 as well as a few other bugs that I will show below. The fix for the ReactJS keys is to add a unique id version 4 uuid.v4() to the incoming threat_mapping and the entities. On save out to elastic I remove the id. This is considered better practices for ReactJS keys

Down the road we might augment the arrays to have that id information but for now I add them when we get the data and then remove them as we save the data.

This PR also:

  • Fixes tech debt around the hooks to remove the disabling of the react-hooks/exhaustive-deps in a few areas
  • Fixes one React Hook misnamed that would not have triggered React linter rules (_useRuleAsyn)
  • Adds 23 new Cypress e2e tests
  • Adds a new pattern of dealing with on button clicks for the Cypress tests that are make it less flakey
cy.get(`button[title="${indexField}"]`)
      .should('be.visible')
      .then(([e]) => e.click());
  • Adds several new utilities to Cypress for testing rows for indicator matches and other Cypress utils to improve velocity and ergonomics
fillIndicatorMatchRow
getDefineContinueButton
getIndicatorInvalidationText
getIndicatorIndexComboField
getIndicatorDeleteButton
getIndicatorOrButton
getIndicatorAndButton

Bug 1

Deleting row 1 can cause row 2 to be cleared out or only partial data to stick around.

Before:
im_bug_1

After:
im_fix_1_1

Bug 2

Deleting row 2 in the middle of 3 rows did not shift the value up correctly

Before:
im_bug_2

After:
im_fix_2

Bug 3

When using OR with values it does not shift up correctly similar to AND

Before:
im_bug_3

After:
im_fix_3

Checklist

Delete any items that are not applicable to this PR.

@FrankHassanabad FrankHassanabad changed the title Fix UI react keys [Security Solution][Detection Engine] Fixes indicator matches mapping UI where invalid list values can cause overwrites Jan 26, 2021
@FrankHassanabad FrankHassanabad changed the title [Security Solution][Detection Engine] Fixes indicator matches mapping UI where invalid list values can cause overwrites [Security Solution][Detection Engine] Fixes indicator matches mapping UI where invalid list values can cause overwrites of other values Jan 26, 2021
@FrankHassanabad FrankHassanabad self-assigned this Jan 26, 2021
@FrankHassanabad FrankHassanabad added v8.0.0 v7.12.0 Feature:Indicator Match Rule Security Solution Indicator Match rule type release_note:skip Skip the PR/issue when compiling release notes release_note:fix labels Jan 26, 2021
@FrankHassanabad FrankHassanabad marked this pull request as ready for review January 26, 2021 23:47
@FrankHassanabad FrankHassanabad requested review from a team as code owners January 26, 2021 23:47
@FrankHassanabad FrankHassanabad requested a review from rylnd January 27, 2021 20:05
@FrankHassanabad FrankHassanabad added the Team:Detections and Resp Security Detection Response Team label Jan 28, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@FrankHassanabad
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@FrankHassanabad
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@FrankHassanabad
Copy link
Copy Markdown
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

expected head sha didn’t match current head ref.

Copy link
Copy Markdown
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.

Tested this locally and the bugs look fixed! Thank you for the review notes, they were incredibly helpful ❤️ .

I had a few nits/hemming/hawing about the cypress stuff, but at the end of the day: it's more test coverage and it can be refactored later if need be. As long as CI is happy, this LGTM.

);
});

it('Does NOT show invalidation text on initial page load', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Broad comment: these narrowly-focused tests are great for legibility and test isolation but likely terrible for CI speed. My preference for these types of tests is to walk through a particular user workflow, making assertions along the way until we get to a terminal point, e.g.:

  • sign in, define rule, about rule, go back to define step and assert values are repopulated, create rule, assert rule created

This seems to be the predominant pattern in our cypress suite right now, so these new tests are a divergence from that. Neither's objectively correct, certainly, and I don't think these need to change, but I wanted to call out the difference. @MadameSheema may have a stronger opinion here 😉

* in the form of:
* flow(addIdToThreatMatchArray, myNewTransform)(rule)
*
* @param rule The rule to transform the output of
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💯 on the JSDoc here, much appreciated 👍

@rylnd rylnd requested a review from MadameSheema January 29, 2021 01:33
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2175 2177 +2

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.5MB 7.5MB +3.7KB

History

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

@FrankHassanabad FrankHassanabad merged commit 2f80e44 into elastic:master Jan 30, 2021
@FrankHassanabad FrankHassanabad deleted the fix-ui-react-keys branch January 30, 2021 02:16
FrankHassanabad added a commit to FrankHassanabad/kibana that referenced this pull request Jan 30, 2021
… UI where invalid list values can cause overwrites of other values (elastic#89066)

## Summary

This fixes the ReactJS keys to not use array indexes for the ReactJS keys which fixes  elastic#84893 as well as a few other bugs that I will show below. The fix for the ReactJS keys is to add a unique id version 4 `uuid.v4()` to the incoming threat_mapping and the entities. On save out to elastic I remove the id. This is considered [better practices for ReactJS keys](https://reactjs.org/docs/lists-and-keys.html)

Down the road we might augment the arrays to have that id information but for now I add them when we get the data and then remove them as we save the data.

This PR also:
* Fixes tech debt around the hooks to remove the disabling of the `react-hooks/exhaustive-deps` in a few areas
* Fixes one React Hook misnamed that would not have triggered React linter rules (_useRuleAsyn)
* Adds 23 new Cypress e2e tests
* Adds a new pattern of dealing with on button clicks for the Cypress tests that are make it less flakey
```ts
cy.get(`button[title="${indexField}"]`)
      .should('be.visible')
      .then(([e]) => e.click());
```
* Adds several new utilities to Cypress for testing rows for indicator matches and other Cypress utils to improve velocity and ergonomics
```ts
fillIndicatorMatchRow
getDefineContinueButton
getIndicatorInvalidationText
getIndicatorIndexComboField
getIndicatorDeleteButton
getIndicatorOrButton
getIndicatorAndButton
``` 

## Bug 1
Deleting row 1 can cause row 2 to be cleared out or only partial data to stick around.

Before:
![im_bug_1](https://user-images.githubusercontent.com/1151048/105916137-c57b1d80-5fed-11eb-95b7-ad25b71cf4b8.gif)

After:
![im_fix_1_1](https://user-images.githubusercontent.com/1151048/105917509-9fef1380-5fef-11eb-98eb-025c226f79fe.gif)

## Bug 2 
Deleting row 2 in the middle of 3 rows did not shift the value up correctly

Before:
![im_bug_2](https://user-images.githubusercontent.com/1151048/105917584-c01ed280-5fef-11eb-8c5b-fefb36f81008.gif)

After: 
![im_fix_2](https://user-images.githubusercontent.com/1151048/105917650-e0e72800-5fef-11eb-9fd3-020d52e4e3b1.gif)

## Bug 3
When using OR with values it does not shift up correctly similar to AND

Before:
![im_bug_3](https://user-images.githubusercontent.com/1151048/105917691-f2303480-5fef-11eb-9368-b11d23159606.gif)

After: 
![im_fix_3](https://user-images.githubusercontent.com/1151048/105917714-f9574280-5fef-11eb-9be4-1f56c207525a.gif)

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
FrankHassanabad added a commit that referenced this pull request Jan 30, 2021
… UI where invalid list values can cause overwrites of other values (#89066) (#89817)

## Summary

This fixes the ReactJS keys to not use array indexes for the ReactJS keys which fixes  #84893 as well as a few other bugs that I will show below. The fix for the ReactJS keys is to add a unique id version 4 `uuid.v4()` to the incoming threat_mapping and the entities. On save out to elastic I remove the id. This is considered [better practices for ReactJS keys](https://reactjs.org/docs/lists-and-keys.html)

Down the road we might augment the arrays to have that id information but for now I add them when we get the data and then remove them as we save the data.

This PR also:
* Fixes tech debt around the hooks to remove the disabling of the `react-hooks/exhaustive-deps` in a few areas
* Fixes one React Hook misnamed that would not have triggered React linter rules (_useRuleAsyn)
* Adds 23 new Cypress e2e tests
* Adds a new pattern of dealing with on button clicks for the Cypress tests that are make it less flakey
```ts
cy.get(`button[title="${indexField}"]`)
      .should('be.visible')
      .then(([e]) => e.click());
```
* Adds several new utilities to Cypress for testing rows for indicator matches and other Cypress utils to improve velocity and ergonomics
```ts
fillIndicatorMatchRow
getDefineContinueButton
getIndicatorInvalidationText
getIndicatorIndexComboField
getIndicatorDeleteButton
getIndicatorOrButton
getIndicatorAndButton
``` 

## Bug 1
Deleting row 1 can cause row 2 to be cleared out or only partial data to stick around.

Before:
![im_bug_1](https://user-images.githubusercontent.com/1151048/105916137-c57b1d80-5fed-11eb-95b7-ad25b71cf4b8.gif)

After:
![im_fix_1_1](https://user-images.githubusercontent.com/1151048/105917509-9fef1380-5fef-11eb-98eb-025c226f79fe.gif)

## Bug 2 
Deleting row 2 in the middle of 3 rows did not shift the value up correctly

Before:
![im_bug_2](https://user-images.githubusercontent.com/1151048/105917584-c01ed280-5fef-11eb-8c5b-fefb36f81008.gif)

After: 
![im_fix_2](https://user-images.githubusercontent.com/1151048/105917650-e0e72800-5fef-11eb-9fd3-020d52e4e3b1.gif)

## Bug 3
When using OR with values it does not shift up correctly similar to AND

Before:
![im_bug_3](https://user-images.githubusercontent.com/1151048/105917691-f2303480-5fef-11eb-9368-b11d23159606.gif)

After: 
![im_fix_3](https://user-images.githubusercontent.com/1151048/105917714-f9574280-5fef-11eb-9be4-1f56c207525a.gif)

### Checklist

Delete any items that are not applicable to this PR.

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
yctercero added a commit that referenced this pull request Feb 25, 2021
…nvalid values can cause overwrites of other values (#90634)

### Summary

This PR is a follow-up to #89066 - which fixed the same issue occurring with indicator match lists UI. The lack of stable ids for exception item entries resulted in some funky business by where invalid values could overwrite other values when deleting entries in the builder.
yctercero added a commit to yctercero/kibana that referenced this pull request Feb 25, 2021
…nvalid values can cause overwrites of other values (elastic#90634)

### Summary

This PR is a follow-up to elastic#89066 - which fixed the same issue occurring with indicator match lists UI. The lack of stable ids for exception item entries resulted in some funky business by where invalid values could overwrite other values when deleting entries in the builder.
yctercero added a commit to yctercero/kibana that referenced this pull request Feb 25, 2021
…nvalid values can cause overwrites of other values (elastic#90634)

### Summary

This PR is a follow-up to elastic#89066 - which fixed the same issue occurring with indicator match lists UI. The lack of stable ids for exception item entries resulted in some funky business by where invalid values could overwrite other values when deleting entries in the builder.
yctercero added a commit that referenced this pull request Feb 25, 2021
…nvalid values can cause overwrites of other values (#90634) (#92749)

### Summary

This PR is a follow-up to #89066 - which fixed the same issue occurring with indicator match lists UI. The lack of stable ids for exception item entries resulted in some funky business by where invalid values could overwrite other values when deleting entries in the builder.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
yctercero added a commit that referenced this pull request Feb 25, 2021
…nvalid values can cause overwrites of other values (#90634) (#92750)

### Summary

This PR is a follow-up to #89066 - which fixed the same issue occurring with indicator match lists UI. The lack of stable ids for exception item entries resulted in some funky business by where invalid values could overwrite other values when deleting entries in the builder.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@FrankHassanabad FrankHassanabad removed the release_note:skip Skip the PR/issue when compiling release notes label Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Indicator Match Rule Security Solution Indicator Match rule type release_note:fix Team:Detections and Resp Security Detection Response Team v7.12.0 v8.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security Solution] The values for Field & Indicator index field are not mapped correctly under the indicator mapping section.

4 participants