-
Notifications
You must be signed in to change notification settings - Fork 160
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
Receiving a PUSH_PROMISE from a client is an error #315
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1523,3 +1523,32 @@ def test_receiving_goaway_frame_with_unknown_error(self, frame_factory): | |
assert c.state_machine.state == h2.connection.ConnectionState.CLOSED | ||
|
||
assert not c.data_to_send() | ||
|
||
def test_receiving_push_promise_from_client_is_error(self, frame_factory): | ||
""" | ||
If we are a server, receiving PUSH_PROMISE frames from a client | ||
causes the connection to be closed. | ||
""" | ||
c = h2.connection.H2Connection(client_side=False) | ||
c.initiate_connection() | ||
c.receive_data(frame_factory.preamble()) | ||
|
||
f1 = frame_factory.build_headers_frame( | ||
self.example_request_headers | ||
) | ||
f2 = frame_factory.build_push_promise_frame( | ||
stream_id=1, | ||
promised_stream_id=2, | ||
headers=self.example_request_headers, | ||
flags=['END_HEADERS'], | ||
) | ||
c.receive_data(f1.serialize()) | ||
c.clear_outbound_data_buffer() | ||
|
||
with pytest.raises(h2.exceptions.ProtocolError): | ||
c.receive_data(f2.serialize()) | ||
|
||
expected_frame = frame_factory.build_goaway_frame( | ||
1, h2.errors.ErrorCodes.PROTOCOL_ERROR | ||
) | ||
assert c.data_to_send() == expected_frame.serialize() | ||
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. Running this on my machine shows that this test would have passed before the code change above. Can you check the exception message, which is the substantive part of this change? 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. The test now checks the exception message. |
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.
So, here's my question: is this worth it? I think, ordinarily, an invalid push would hit this code block here. That means that we'd still raise a
ProtocolError
. It also means that now, on push promise receipt, we have an extraif
test that always fires in order to check for an error that we'll then immediately look for.Should we consider whether it'd be better to put the new check into this
if
block? Or, even more aggressively, should we just implement #316? If we implement #316 then, definitionally, a server will be forbidden from settingENABLE_PUSH
to1
(because we'll tell it not to), which means that all servers will automatically fall into theif
block here.