Repository navigation
check for pseudo header in trailer #305
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
Merged
Lukasa
merged 1 commit into
python-hyper:master
from
nateprewitt:263_pseudo_header_in_trailer
Sep 5, 2016
Merged
Changes from all commits
Commits
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 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,37 @@ def test_transfer_encoding_trailers_is_valid(self, frame_factory): | |
| request_event = events[0] | ||
| assert request_event.headers == headers | ||
|
|
||
| def test_pseudo_headers_rejected_in_trailer(self, frame_factory): | ||
| """ | ||
| Ensure we reject pseudo headers included in trailers | ||
| """ | ||
| trailers = [(':path', '/'), ('extra', 'value')] | ||
|
|
||
| c = h2.connection.H2Connection(client_side=False) | ||
| c.receive_data(frame_factory.preamble()) | ||
| c.clear_outbound_data_buffer() | ||
|
|
||
| header_frame = frame_factory.build_headers_frame( | ||
| self.base_request_headers | ||
| ) | ||
| trailer_frame = frame_factory.build_headers_frame( | ||
| trailers, flags=["END_STREAM"] | ||
| ) | ||
| head = header_frame.serialize() | ||
| trailer = trailer_frame.serialize() | ||
|
|
||
| c.receive_data(head) | ||
| # Raise exception if pseudo header in trailer | ||
| with pytest.raises(h2.exceptions.ProtocolError) as e: | ||
| c.receive_data(trailer) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a quick confirmation that we're getting the right exception message here: this can save us from situations where this test stops failing for the reason we expect. |
||
| assert "pseudo-header in trailer" in str(e) | ||
|
|
||
| # Test appropriate response frame is generated | ||
| expected_frame = frame_factory.build_goaway_frame( | ||
| last_stream_id=1, error_code=h2.errors.ErrorCodes.PROTOCOL_ERROR | ||
| ) | ||
| assert c.data_to_send() == expected_frame.serialize() | ||
|
|
||
|
|
||
| class TestSendingInvalidFrameSequences(object): | ||
| """ | ||
|
|
@@ -217,6 +248,14 @@ class TestFilter(object): | |
| ] | ||
| ] | ||
|
|
||
| hdr_validation_no_trailers = [ | ||
| h2.utilities.HeaderValidationFlags(is_client, is_trailer) | ||
| for is_client, is_trailer in [ | ||
| (True, False), | ||
| (False, False) | ||
| ] | ||
| ] | ||
|
|
||
| @pytest.mark.parametrize('validation_function', validation_functions) | ||
| @pytest.mark.parametrize('hdr_validation_flags', hdr_validation_combos) | ||
| @given(headers=HEADERS_STRATEGY) | ||
|
|
@@ -241,7 +280,9 @@ def test_invalid_pseudo_headers(self, hdr_validation_flags): | |
| h2.utilities.validate_headers(headers, hdr_validation_flags) | ||
|
|
||
| @pytest.mark.parametrize('validation_function', validation_functions) | ||
| @pytest.mark.parametrize('hdr_validation_flags', hdr_validation_combos) | ||
| @pytest.mark.parametrize( | ||
| 'hdr_validation_flags', hdr_validation_no_trailers | ||
| ) | ||
| def test_matching_authority_host_headers(self, | ||
| validation_function, | ||
| hdr_validation_flags): | ||
|
|
||
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.
Ok, seeing this change in place I now understand what you were getting at. Yes, there is nothing wrong with closing that stream using trailers, but the trailers that were being sent were not actually valid trailers. This change is better. =)