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

Fix generic events on search queries #1698

Merged
merged 3 commits into from
Jul 2, 2020

Conversation

scottinet
Copy link
Contributor

@scottinet scottinet commented Jun 29, 2020

Description

Generic events on the following API routes were handled by a default document extractor, providing incorrect results to plugin developers: document:search, document:deleteByQuery, document:updateByQuery

Changes

  • Remove the default document extractor. Instead, if Kuzzle is tasked to extract documents from an unknown request action, it throws an InternalError with this new error code: core.fatal.assertion_failed. This new error is meant to be used for runtime assertions, making sure that the code performs according to specifications. Here, a default document extractor is clearly not what we want, as it hides potential errors or omissions (and it did exactly that here)
  • Add the missing document extractors for document:search, document:deleteByQuery, document:updateByQuery
  • Blacklist document:updateByQuery from "before" document events, as documents cannot be extracted from requests made to that API route
  • Update the documentation accordingly
  • Reorganize the document extractor unit tests, for better maintenability
  • Add a lot of missing unit tests

@codecov
Copy link

codecov bot commented Jun 29, 2020

Codecov Report

Merging #1698 into 2-dev will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            2-dev    #1698      +/-   ##
==========================================
+ Coverage   93.52%   93.53%   +0.01%     
==========================================
  Files         113      113              
  Lines        7197     7209      +12     
==========================================
+ Hits         6731     6743      +12     
  Misses        466      466              
Impacted Files Coverage Δ
lib/config/documentEventAliases.js 100.00% <ø> (ø)
lib/api/documentExtractor.js 96.20% <100.00%> (+0.68%) ⬆️
lib/api/funnel.js 96.61% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0d91591...9437fad. Read the comment docs.

return request;
},
},
targets: ['search', 'deleteByQuery'],
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought updateByQuery was not eligible either?

Copy link
Contributor Author

@scottinet scottinet Jun 30, 2020

Choose a reason for hiding this comment

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

updateByQuery is handled by the same extractor than mCreate, mReplace, etc. because they share the same format.

The blacklist is done in the documentEventAliases.js file: /~https://github.com/kuzzleio/kuzzle/pull/1698/files#diff-cda9b5cb3d677fb4f72bd365d3318910

So the extractFromRequest and insertInRequest extractor methods cannot be invoked for updateByQuery.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jul 1, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.1% 0.1% Duplication

@scottinet scottinet merged commit e711659 into 2-dev Jul 2, 2020
@scottinet scottinet deleted the fix-generic-events-on-search-queries branch July 2, 2020 07:36
This was referenced Jul 7, 2020
scottinet added a commit that referenced this pull request Jul 8, 2020
# [2.3.2](/~https://github.com/kuzzleio/kuzzle/releases/tag/2.3.2) (2020-07-07)


#### Bug fixes

- [ [#1701](#1701) ] Fix: description should not be required for plugin custom errors   ([scottinet](/~https://github.com/scottinet))
- [ [#1695](#1695) ] Fix dump generation   ([Aschen](/~https://github.com/Aschen))
- [ [#1698](#1698) ] Fix generic events on search queries   ([scottinet](/~https://github.com/scottinet))

#### Enhancements

- [ [#1702](#1702) ] Update search indexes only when the "dynamic" setting changes from false to true/strict   ([Aschen](/~https://github.com/Aschen))
- [ [#1630](#1630) ] Loose coupling: security module   ([scottinet](/~https://github.com/scottinet))
- [ [#1604](#1604) ] Add request ID in log   ([Aschen](/~https://github.com/Aschen))
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants