Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_unknown_frames_are_ignored(self, frame_factory, frame_id):
c = h2.connection.H2Connection(config=self.server_config)
c.receive_data(frame_factory.preamble())
c.clear_outbound_data_buffer()
f = frame_factory.build_data_frame(data=b'abcdefghtdst')
f.type = frame_id
events = c.receive_data(f.serialize())
assert not c.data_to_send()
assert len(events) == 1
assert isinstance(events[0], h2.events.UnknownFrameReceived)
assert isinstance(events[0].frame, hyperframe.frame.ExtensionFrame)
)
# When in doubt use dict-dispatch.
self._frame_dispatch_table = {
HeadersFrame: self._receive_headers_frame,
PushPromiseFrame: self._receive_push_promise_frame,
SettingsFrame: self._receive_settings_frame,
DataFrame: self._receive_data_frame,
WindowUpdateFrame: self._receive_window_update_frame,
PingFrame: self._receive_ping_frame,
RstStreamFrame: self._receive_rst_stream_frame,
PriorityFrame: self._receive_priority_frame,
GoAwayFrame: self._receive_goaway_frame,
ContinuationFrame: self._receive_naked_continuation,
AltSvcFrame: self._receive_alt_svc_frame,
ExtensionFrame: self._receive_unknown_frame
}
def test_parse_frame_header_unknown_type(self):
frame, length = Frame.parse_frame_header(
b'\x00\x00\x59\xFF\x00\x00\x00\x00\x01'
)
assert frame.type == 0xFF
assert length == 0x59
assert isinstance(frame, ExtensionFrame)
assert frame.stream_id == 1
fields = _STRUCT_HBBBL.unpack(header)
except struct.error:
raise InvalidFrameError("Invalid frame header")
# First 24 bits are frame length.
length = (fields[0] << 8) + fields[1]
type = fields[2]
flags = fields[3]
stream_id = fields[4] & 0x7FFFFFFF
try:
frame = FRAMES[type](stream_id)
except KeyError:
if strict:
raise UnknownFrameError(type, length)
frame = ExtensionFrame(type=type, stream_id=stream_id)
frame.parse_flags(flags)
return (frame, length)
)
# When in doubt use dict-dispatch.
self._frame_dispatch_table = {
HeadersFrame: self._receive_headers_frame,
PushPromiseFrame: self._receive_push_promise_frame,
SettingsFrame: self._receive_settings_frame,
DataFrame: self._receive_data_frame,
WindowUpdateFrame: self._receive_window_update_frame,
PingFrame: self._receive_ping_frame,
RstStreamFrame: self._receive_rst_stream_frame,
PriorityFrame: self._receive_priority_frame,
GoAwayFrame: self._receive_goaway_frame,
ContinuationFrame: self._receive_naked_continuation,
AltSvcFrame: self._receive_alt_svc_frame,
ExtensionFrame: self._receive_unknown_frame
}
def __init__(self, type, stream_id, **kwargs):
super(ExtensionFrame, self).__init__(stream_id, **kwargs)
self.type = type
self.flag_byte = None