Esempio n. 1
0
    def test_continuation_frame_parses_properly(self):
        s = b'\x00\x0B\x0A\x04\x00\x00\x00\x01hello world'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, ContinuationFrame)
        assert f.flags == set(['END_HEADERS'])
        assert f.data == b'hello world'
Esempio n. 2
0
    def test_data_frame_parses_properly(self):
        s = b'\x00\x08\x00\x01\x00\x00\x00\x01testdata'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, DataFrame)
        assert f.flags == set(['END_STREAM'])
        assert f.data == b'testdata'
Esempio n. 3
0
    def test_priority_frame_parses_properly(self):
        s = b'\x00\x04\x02\x00\x00\x00\x00\x01\x00\x00\x00\xff'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, PriorityFrame)
        assert f.flags == set()
        assert f.priority == 0xFF
Esempio n. 4
0
    def test_rst_stream_frame_parses_properly(self):
        s = b'\x00\x04\x03\x00\x00\x00\x00\x01\x00\x00\x01\xa4'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, RstStreamFrame)
        assert f.flags == set()
        assert f.error_code == 420
Esempio n. 5
0
    def test_windowupdate_frame_parses_properly(self):
        s = b'\x00\x04\x09\x00\x00\x00\x00\x00\x00\x00\x02\x00'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, WindowUpdateFrame)
        assert f.flags == set()
        assert f.window_increment == 512
Esempio n. 6
0
    def test_ping_frame_parses_properly(self):
        s = b'\x00\x08\x06\x01\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x00\x00'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, PingFrame)
        assert f.flags == set(['ACK'])
        assert f.opaque_data == b'\x01\x02\x00\x00\x00\x00\x00\x00'
Esempio n. 7
0
    def test_rst_stream_frame_parses_properly(self):
        s = b'\x00\x04\x03\x00\x00\x00\x00\x01\x00\x00\x01\xa4'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, RstStreamFrame)
        assert f.flags == set()
        assert f.error_code == 420
Esempio n. 8
0
    def test_ping_frame_parses_properly(self):
        s = b'\x00\x08\x06\x01\x00\x00\x00\x00\x01\x02\x00\x00\x00\x00\x00\x00'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, PingFrame)
        assert f.flags == set(['ACK'])
        assert f.opaque_data == b'\x01\x02\x00\x00\x00\x00\x00\x00'
Esempio n. 9
0
    def test_windowupdate_frame_parses_properly(self):
        s = b'\x00\x04\x09\x00\x00\x00\x00\x00\x00\x00\x02\x00'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, WindowUpdateFrame)
        assert f.flags == set()
        assert f.window_increment == 512
Esempio n. 10
0
    def test_continuation_frame_parses_properly(self):
        s = b'\x00\x0B\x0A\x04\x00\x00\x00\x01hello world'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, ContinuationFrame)
        assert f.flags == set(['END_HEADERS'])
        assert f.data == b'hello world'
Esempio n. 11
0
    def test_priority_frame_parses_properly(self):
        s = b'\x00\x04\x02\x00\x00\x00\x00\x01\x00\x00\x00\xff'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, PriorityFrame)
        assert f.flags == set()
        assert f.priority == 0xFF
Esempio n. 12
0
    def test_data_frame_parses_properly(self):
        s = b'\x00\x08\x00\x01\x00\x00\x00\x01testdata'
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, DataFrame)
        assert f.flags == set(['END_STREAM'])
        assert f.data == b'testdata'
Esempio n. 13
0
    def test_headers_frame_parses_properly(self):
        s = b"\x00\x0F\x01\x0D\x00\x00\x00\x01" + b"\x40\x00\x00\x01" + b"hello world"
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8 : 8 + length])

        assert isinstance(f, HeadersFrame)
        assert f.flags == set(["END_STREAM", "END_HEADERS", "PRIORITY"])
        assert f.priority == (2 ** 30) + 1
        assert f.data == b"hello world"
Esempio n. 14
0
    def test_headers_frame_parses_properly(self):
        s = (b'\x00\x0F\x01\x0D\x00\x00\x00\x01' + b'\x40\x00\x00\x01' +
             b'hello world')
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, HeadersFrame)
        assert f.flags == set(['END_STREAM', 'END_HEADERS', 'PRIORITY'])
        assert f.priority == (2**30) + 1
        assert f.data == b'hello world'
Esempio n. 15
0
    def test_goaway_frame_parses_properly(self):
        s = (
            b'\x00\x0D\x07\x00\x00\x00\x00\x00' +  # Frame header
            b'\x00\x00\x00\x40' +  # Last Stream ID
            b'\x00\x00\x00\x20' +  # Error Code
            b'hello'  # Additional data
        )
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, GoAwayFrame)
        assert f.flags == set()
        assert f.additional_data == b'hello'
Esempio n. 16
0
    def test_goaway_frame_parses_properly(self):
        s = (
            b'\x00\x0D\x07\x00\x00\x00\x00\x00' +  # Frame header
            b'\x00\x00\x00\x40'                 +  # Last Stream ID
            b'\x00\x00\x00\x20'                 +  # Error Code
            b'hello'                               # Additional data
        )
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, GoAwayFrame)
        assert f.flags == set()
        assert f.additional_data == b'hello'
Esempio n. 17
0
    def test_headers_frame_parses_properly(self):
        s = (
            b'\x00\x0F\x01\x0D\x00\x00\x00\x01' +
            b'\x40\x00\x00\x01' +
            b'hello world'
        )
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, HeadersFrame)
        assert f.flags == set(['END_STREAM', 'END_HEADERS', 'PRIORITY'])
        assert f.priority == (2 ** 30) + 1
        assert f.data == b'hello world'
Esempio n. 18
0
    def test_settings_frame_parses_properly(self):
        s = (
            b'\x00\x28\x04\x01\x00\x00\x00\x00' +  # Frame header
            b'\x00\x00\x00\x01\x00\x00\x10\x00' +  # HEADER_TABLE_SIZE
            b'\x00\x00\x00\x02\x00\x00\x00\x00' +  # ENABLE_PUSH
            b'\x00\x00\x00\x04\x00\x00\x00\x64' +  # MAX_CONCURRENT_STREAMS
            b'\x00\x00\x00\x0A\x00\x00\x00\x01' +  # FLOW_CONTROL_OPTIONS
            b'\x00\x00\x00\x07\x00\x00\xFF\xFF'    # INITIAL_WINDOW_SIZE
        )
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, SettingsFrame)
        assert f.flags == set(['ACK'])
        assert f.settings == {
            SettingsFrame.HEADER_TABLE_SIZE: 4096,
            SettingsFrame.ENABLE_PUSH: 0,
            SettingsFrame.MAX_CONCURRENT_STREAMS: 100,
            SettingsFrame.INITIAL_WINDOW_SIZE: 65535,
            SettingsFrame.FLOW_CONTROL_OPTIONS: 1,
        }
Esempio n. 19
0
    def test_settings_frame_parses_properly(self):
        s = (
            b'\x00\x28\x04\x01\x00\x00\x00\x00' +  # Frame header
            b'\x00\x00\x00\x01\x00\x00\x10\x00' +  # HEADER_TABLE_SIZE
            b'\x00\x00\x00\x02\x00\x00\x00\x00' +  # ENABLE_PUSH
            b'\x00\x00\x00\x04\x00\x00\x00\x64' +  # MAX_CONCURRENT_STREAMS
            b'\x00\x00\x00\x0A\x00\x00\x00\x01' +  # FLOW_CONTROL_OPTIONS
            b'\x00\x00\x00\x07\x00\x00\xFF\xFF'  # INITIAL_WINDOW_SIZE
        )
        f, length = Frame.parse_frame_header(s[:8])
        f.parse_body(s[8:8 + length])

        assert isinstance(f, SettingsFrame)
        assert f.flags == set(['ACK'])
        assert f.settings == {
            SettingsFrame.HEADER_TABLE_SIZE: 4096,
            SettingsFrame.ENABLE_PUSH: 0,
            SettingsFrame.MAX_CONCURRENT_STREAMS: 100,
            SettingsFrame.INITIAL_WINDOW_SIZE: 65535,
            SettingsFrame.FLOW_CONTROL_OPTIONS: 1,
        }
Esempio n. 20
0
def decode_frame(frame_data):
    f, length = Frame.parse_frame_header(frame_data[:8])
    f.parse_body(frame_data[8 : 8 + length])
    assert 8 + length == len(frame_data)
    return f
Esempio n. 21
0
 def test_base_frame_cant_serialize(self):
     f = Frame(0)
     with pytest.raises(NotImplementedError):
         f.serialize()
Esempio n. 22
0
 def test_base_frame_cant_parse_body(self):
     data = b''
     f = Frame(0)
     with pytest.raises(NotImplementedError):
         f.parse_body(data)
Esempio n. 23
0
 def test_base_frame_ignores_flags(self):
     f = Frame(0)
     flags = f.parse_flags(0xFF)
     assert not flags
     assert isinstance(flags, set)
Esempio n. 24
0
def decode_frame(frame_data):
    f, length = Frame.parse_frame_header(frame_data[:8])
    f.parse_body(frame_data[8:8 + length])
    assert 8 + length == len(frame_data)
    return f
Esempio n. 25
0
 def test_base_frame_ignores_flags(self):
     f = Frame(0)
     flags = f.parse_flags(0xFF)
     assert not flags
     assert isinstance(flags, set)
Esempio n. 26
0
 def test_base_frame_cant_serialize(self):
     f = Frame(0)
     with pytest.raises(NotImplementedError):
         f.serialize()
Esempio n. 27
0
 def test_base_frame_cant_parse_body(self):
     data = b""
     f = Frame(0)
     with pytest.raises(NotImplementedError):
         f.parse_body(data)
Esempio n. 28
0
 def test_receiving_a_frame_queues_it(self):
     s = Stream(1, None, None, None, None)
     s.receive_frame(Frame(0))
     assert len(s._queued_frames) == 1
Esempio n. 29
0
def decode_frame(frame_data):
    f, length = Frame.parse_frame_header(frame_data[:9])
    f.parse_body(memoryview(frame_data[9:9 + length]))
    assert 9 + length == len(frame_data)
    return f