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][Notes] - fix incorrect get_notes api for documentIds and savedObjectIds query parameters and adding api integration tests #196225

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

PhilippeOberti
Copy link
Contributor

@PhilippeOberti PhilippeOberti commented Oct 14, 2024

Summary

While working on adding api integration tests for this PR, I realized that the current logic in the getNotes endpoint is not always correct. Here are the issues:

  • when retrieving notes for a list of documentIds by passing one or multiple documentIds query parameters (used for example when the UI wants to retrieve all the notes for all the alerts in the alerts table), we were actually searching for the values of the documentIds in all the fields, instead of just in the eventId field. That means that if a user had used the document id value in the note itself (the text part) this value would be returned. The new logic only looks at the eventId attributes to return only the necessary notes. I did not do and performance comparison, but I would assume that looking at a specific field vs all the fields would be much more efficient
  • the same mistake was done on the savedObjectIds query parameter, where we were searching for the values passed within all the fields of the notes objects, instead of just looking for the references to other saved object ids

This PR fixes the 2 issues above and adds a lot of api integration tests to check the above behavior as well as testing other query parameters (like sortField, sortOrder, perPage, page and search).

Checklist

@PhilippeOberti PhilippeOberti added backport release_note:skip Skip the PR/issue when compiling release notes v9.0.0 Team:Threat Hunting:Investigations Security Solution Investigations Team v8.16.0 labels Oct 14, 2024
@PhilippeOberti PhilippeOberti requested review from a team as code owners October 14, 2024 23:56
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-threat-hunting-investigations (Team:Threat Hunting:Investigations)

const filter = queryParams?.filter;
const options = {

// searching for all the notes associated with a specific for saved object id
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// searching for all the notes associated with a specific for saved object id
// searching for all the notes associated with a specific saved object id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in this commit

.patch(NOTE_URL)
.set('kbn-xsrf', 'true')
.send({
note: {
Copy link
Contributor

Choose a reason for hiding this comment

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

💅 You could use the actual request body types here and in the cases below, so that it will be easier to refactor these tests once we are changing the request body types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, fixed here

Comment on lines +502 to +413
// TODO should add more tests for the filter query parameter (I don't know how it's supposed to work)

// TODO should add more tests for the MAX_UNASSOCIATED_NOTES advanced settings values
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you still want to do this before this PR is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no, there are some unknowns on my side, I just added these todos when we revisit the api, probably around 9.0

Copy link
Contributor

@janmonschke janmonschke left a comment

Choose a reason for hiding this comment

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

Nice catch! I left some small comments but feel free to ignore them or tackle them after merging this PR.

…Ids and savedObjectIds query parameters and adding api integration tests
@PhilippeOberti
Copy link
Contributor Author

Nice catch! I left some small comments but feel free to ignore them or tackle them after merging this PR.

thanks! I actually made some changes like wrapping the creation of the notes by Promise.all like you suggested in my other PR. A couple of tests purposefully do not use that though, because I want to ensure the order in which the notes are ingested (to test the pagination).

},
updatedBy: note.user || 'elastic',
note: note.text,
} as BareNote,
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be PersistNoteRouteRequestBody

Copy link
Contributor Author

@PhilippeOberti PhilippeOberti Oct 15, 2024

Choose a reason for hiding this comment

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

that makes sense, if that's ok I made the change in this other PR (here) that way it saves some CI time as this PR is nearly done... ?

@PhilippeOberti PhilippeOberti merged commit 0764261 into elastic:main Oct 15, 2024
42 checks passed
@PhilippeOberti PhilippeOberti deleted the notes-api-tests branch October 15, 2024 17:09
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/11350967812

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

  • 💚 Build #242390 succeeded 6b89eb7a8401a8ebf9f812a9d379433a27231f25

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 15, 2024
…Ids and savedObjectIds query parameters and adding api integration tests (elastic#196225)

(cherry picked from commit 0764261)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Oct 15, 2024
…cumentIds and savedObjectIds query parameters and adding api integration tests (#196225) (#196394)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution][Notes] - fix incorrect get_notes api for
documentIds and savedObjectIds query parameters and adding api
integration tests
(#196225)](#196225)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Philippe
Oberti","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-15T17:09:22Z","message":"[Security
Solution][Notes] - fix incorrect get_notes api for documentIds and
savedObjectIds query parameters and adding api integration tests
(#196225)","sha":"07642611899034fd4d9ab8362b6303405871c055","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["backport","release_note:skip","v9.0.0","Team:Threat
Hunting:Investigations","v8.16.0"],"title":"[Security Solution][Notes] -
fix incorrect get_notes api for documentIds and savedObjectIds query
parameters and adding api integration
tests","number":196225,"url":"https://github.com/elastic/kibana/pull/196225","mergeCommit":{"message":"[Security
Solution][Notes] - fix incorrect get_notes api for documentIds and
savedObjectIds query parameters and adding api integration tests
(#196225)","sha":"07642611899034fd4d9ab8362b6303405871c055"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/196225","number":196225,"mergeCommit":{"message":"[Security
Solution][Notes] - fix incorrect get_notes api for documentIds and
savedObjectIds query parameters and adding api integration tests
(#196225)","sha":"07642611899034fd4d9ab8362b6303405871c055"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Philippe Oberti <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport release_note:skip Skip the PR/issue when compiling release notes Team:Threat Hunting:Investigations Security Solution Investigations Team v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants