fix(rails): exclude MimeNegotiation::InvalidType by default#160
Open
moladukes wants to merge 2 commits into
Open
fix(rails): exclude MimeNegotiation::InvalidType by default#160moladukes wants to merge 2 commits into
moladukes wants to merge 2 commits into
Conversation
Raised when a client sends a malformed Accept or Content-Type header (typically scanner/fuzzer traffic). Rails maps it to a 406 via ActionDispatch::ExceptionWrapper.rescue_responses, so it is not an application bug worth capturing.
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
spec/posthog/rails/configuration_spec.rb:15-27
The team's coding standard prefers parameterised tests. The two "excludes … by default" examples are identical in structure and are ideal candidates for a shared iteration. A loop-based approach also makes it trivial to extend coverage to every class in `default_excluded_exceptions` without repeating the expectation.
```suggestion
{
'ActionController::RoutingError' => ActionController::RoutingError.new('No route matches'),
'ActionDispatch::Http::MimeNegotiation::InvalidType' =>
ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type')
}.each do |name, exception|
it "excludes #{name} by default" do
expect(config.should_capture_exception?(exception)).to be false
end
end
```
Reviews (1): Last reviewed commit: "fix(rails): exclude MimeNegotiation::Inv..." | Re-trigger Greptile |
Comment on lines
+15
to
+27
| it 'excludes ActionController::RoutingError by default' do | ||
| exception = ActionController::RoutingError.new('No route matches') | ||
| expect(config.should_capture_exception?(exception)).to be false | ||
| end | ||
|
|
||
| it 'excludes ActionDispatch::Http::MimeNegotiation::InvalidType by default' do | ||
| # Raised when a client sends a malformed Accept / Content-Type header | ||
| # (typically scanner traffic). Rails maps it to a 406 — see | ||
| # ActionDispatch::ExceptionWrapper.rescue_responses — so it is not a | ||
| # bug worth capturing. | ||
| exception = ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type') | ||
| expect(config.should_capture_exception?(exception)).to be false | ||
| end |
There was a problem hiding this comment.
The team's coding standard prefers parameterised tests. The two "excludes … by default" examples are identical in structure and are ideal candidates for a shared iteration. A loop-based approach also makes it trivial to extend coverage to every class in
default_excluded_exceptions without repeating the expectation.
Suggested change
| it 'excludes ActionController::RoutingError by default' do | |
| exception = ActionController::RoutingError.new('No route matches') | |
| expect(config.should_capture_exception?(exception)).to be false | |
| end | |
| it 'excludes ActionDispatch::Http::MimeNegotiation::InvalidType by default' do | |
| # Raised when a client sends a malformed Accept / Content-Type header | |
| # (typically scanner traffic). Rails maps it to a 406 — see | |
| # ActionDispatch::ExceptionWrapper.rescue_responses — so it is not a | |
| # bug worth capturing. | |
| exception = ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type') | |
| expect(config.should_capture_exception?(exception)).to be false | |
| end | |
| { | |
| 'ActionController::RoutingError' => ActionController::RoutingError.new('No route matches'), | |
| 'ActionDispatch::Http::MimeNegotiation::InvalidType' => | |
| ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type') | |
| }.each do |name, exception| | |
| it "excludes #{name} by default" do | |
| expect(config.should_capture_exception?(exception)).to be false | |
| end | |
| end |
Prompt To Fix With AI
This is a comment left during a code review.
Path: spec/posthog/rails/configuration_spec.rb
Line: 15-27
Comment:
The team's coding standard prefers parameterised tests. The two "excludes … by default" examples are identical in structure and are ideal candidates for a shared iteration. A loop-based approach also makes it trivial to extend coverage to every class in `default_excluded_exceptions` without repeating the expectation.
```suggestion
{
'ActionController::RoutingError' => ActionController::RoutingError.new('No route matches'),
'ActionDispatch::Http::MimeNegotiation::InvalidType' =>
ActionDispatch::Http::MimeNegotiation::InvalidType.new('"foo" is not a valid MIME type')
}.each do |name, exception|
it "excludes #{name} by default" do
expect(config.should_capture_exception?(exception)).to be false
end
end
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Author
There was a problem hiding this comment.
Applied in a4027a9 and kept the comment about why InvalidType matters above the hash.
Matches the iteration pattern used elsewhere in the spec suite (e.g. client_spec.rb:628).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #159.
MimeNegotiation::InvalidTypeis raised when a client sends a malformedAccept/Content-Typeheader, almost always scanner traffic. Rails maps it to a 406 viaActionDispatch::ExceptionWrapper.rescue_responses, so it's not an app bug. Same category as the already-excludedBadRequest/UnknownFormat/ParseError.default_excluded_exceptionsspec/posthog/rails/configuration_spec.rbbundle exec rspecandbundle exec rubocoppass locally.