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.
🧰 What's being changed?
When given
allow_only
orreject
parameters, we want to make surethat the request and response bodies are properly filtered. In order to
do that, we need to be able to parse them. Currently we only support
parsing JSON and form-encoded bodies. If bodies come in as other content
types and a filter is configured, we should not submit the request to
the Readme API because it might contain sensitive data.
If no filter is set, it is safe to just pass-through any bodies to the
Readme API regardless of content type.
Testing this behavior was rather annoying as I had to create new
instances of both app and middleware for each test in order to get
custom response bodies and middleware configurations desired. To make
this nicer I ended up creating a bunch of testing helpers. I also
created two test app classes based on content returned:
JsonApp
andTextApp
.The checking we do around content-types has to happen for both the
request and the response so I pulled it out into a mixin that can be
included into both. Also, as part of this I created an
HttpResponse
class that decorates
Rack::Request
and includes the mixin.🧪 Testing
Create a simple rack app that returns text/plain content and has a reject or allow-only parameter set. When you make a request to it, you should see an error in the logs:
Try various combinations of
reject_params
,allow_only
, text response bodies, and text request bodies.