forked from gsamokovarov/web-console
-
Notifications
You must be signed in to change notification settings - Fork 177
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 truncated body in exception view #255
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this, so we don't regress again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be glad to do that, but unfortunately I don't have any clue how to test it. 😕
I tried adding a wrong Content-Length to the headers defined in
helper_test.rb
ormiddleware_test.rb
to reproduce the bug in the first place, but even without this fix, the response in the test always contains the correct Content-Length. Maybe somewhere in the test-stack the Content-Length gets re-set to the correct value, where other application servers don't override the Content-Length if it's already set (e.g. puma)? My rails-knowledge isn't really that good...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can explicitly set the
Content-Length
after the injection on line42
ourselves? Then we can test that the content length is extended after the middleware run? That way, we won't depend on someone else to set the proper content length and therefore test our own behavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that I cannot reproduce the bug (without my fix) in a test...
If I set
headers["Content-Length"] = 7
(just an arbitrary obviously wrong value) in the middleware instead of deleting it, the response in the test will always have the correctContent-Length
, not the previously defined value of 7. It seems like something in the test library is settingContent-Length
to the correct value all the time, which is not the same behavior as puma.So if I add a test to check if
Content-Length
is set to the correct value, it will be green even without my fix... which kinda defeats the purpose of writing a test.Personally, I don't think a library or application has to care about setting
Content-Length
, since this is usually the task of a server. That's why I would prefer deleting the header. I would go so far to say that the behavior of Action Pack is wrong, it shouldn't set theContent-Length
in the first place.So to summarize: If we delete
Content-Length
or re-calculate it in the middleware, I have no idea how to write a reasonable middleware test. 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That being said, I only tried to test it using an Integration Test. I don't know how to properly test the middleware with another kind of test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you can try to write a unit test (
ActiveSupport::TestCase
) and execute the middleware manually with rack-test. You can also move this behavior to theWebConsole::Injector
and add another unit test to it, instead to the middleware. I'd be okay with the injector, caring about acting on the content length, even if we have to give it more input/output responsibilities.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added a test without seeing your comment. 😅 But I added the middleware_test which always will be green because of the previously mentioned
IntegrationTest
.Executing it manually sounds like a good plan. I'll add that (later this day, hopefully)