mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 16:17:49 +00:00
http2: explicitly mention all arguments in tests
This commit is contained in:
parent
436291764c
commit
b84001e8f0
@ -3,43 +3,59 @@ import tutils
|
|||||||
|
|
||||||
from nose.tools import assert_equal
|
from nose.tools import assert_equal
|
||||||
|
|
||||||
# TODO test stream association if valid or not
|
|
||||||
|
|
||||||
|
|
||||||
def test_invalid_flags():
|
def test_invalid_flags():
|
||||||
tutils.raises(
|
tutils.raises(
|
||||||
ValueError,
|
ValueError,
|
||||||
DataFrame,
|
DataFrame,
|
||||||
ContinuationFrame.FLAG_END_HEADERS,
|
flags=ContinuationFrame.FLAG_END_HEADERS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
'foobar')
|
payload='foobar')
|
||||||
|
|
||||||
|
|
||||||
def test_frame_equality():
|
def test_frame_equality():
|
||||||
a = DataFrame(6, Frame.FLAG_END_STREAM, 0x1234567, 'foobar')
|
a = DataFrame(
|
||||||
b = DataFrame(6, Frame.FLAG_END_STREAM, 0x1234567, 'foobar')
|
length=6,
|
||||||
|
flags=Frame.FLAG_END_STREAM,
|
||||||
|
stream_id=0x1234567,
|
||||||
|
payload='foobar')
|
||||||
|
b = DataFrame(
|
||||||
|
length=6,
|
||||||
|
flags=Frame.FLAG_END_STREAM,
|
||||||
|
stream_id=0x1234567,
|
||||||
|
payload='foobar')
|
||||||
assert_equal(a, b)
|
assert_equal(a, b)
|
||||||
|
|
||||||
|
|
||||||
def test_too_large_frames():
|
def test_too_large_frames():
|
||||||
DataFrame(6, Frame.FLAG_END_STREAM, 0x1234567)
|
DataFrame(
|
||||||
|
length=6,
|
||||||
|
flags=Frame.FLAG_END_STREAM,
|
||||||
|
stream_id=0x1234567)
|
||||||
|
|
||||||
|
|
||||||
def test_data_frame_to_bytes():
|
def test_data_frame_to_bytes():
|
||||||
f = DataFrame(6, Frame.FLAG_END_STREAM, 0x1234567, 'foobar')
|
f = DataFrame(
|
||||||
|
length=6,
|
||||||
|
flags=Frame.FLAG_END_STREAM,
|
||||||
|
stream_id=0x1234567,
|
||||||
|
payload='foobar')
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000006000101234567666f6f626172')
|
assert_equal(f.to_bytes().encode('hex'), '000006000101234567666f6f626172')
|
||||||
|
|
||||||
f = DataFrame(
|
f = DataFrame(
|
||||||
11,
|
length=11,
|
||||||
Frame.FLAG_END_STREAM | Frame.FLAG_PADDED,
|
flags=(Frame.FLAG_END_STREAM | Frame.FLAG_PADDED),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
'foobar',
|
payload='foobar',
|
||||||
pad_length=3)
|
pad_length=3)
|
||||||
assert_equal(
|
assert_equal(
|
||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
'00000a00090123456703666f6f626172000000')
|
'00000a00090123456703666f6f626172000000')
|
||||||
|
|
||||||
f = DataFrame(6, Frame.FLAG_NO_FLAGS, 0x0, 'foobar')
|
f = DataFrame(
|
||||||
|
length=6,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0,
|
||||||
|
payload='foobar')
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -63,26 +79,26 @@ def test_data_frame_from_bytes():
|
|||||||
|
|
||||||
def test_data_frame_human_readable():
|
def test_data_frame_human_readable():
|
||||||
f = DataFrame(
|
f = DataFrame(
|
||||||
11,
|
length=11,
|
||||||
Frame.FLAG_END_STREAM | Frame.FLAG_PADDED,
|
flags=(Frame.FLAG_END_STREAM | Frame.FLAG_PADDED),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
'foobar',
|
payload='foobar',
|
||||||
pad_length=3)
|
pad_length=3)
|
||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
|
||||||
|
|
||||||
def test_headers_frame_to_bytes():
|
def test_headers_frame_to_bytes():
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
6,
|
length=6,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=(Frame.FLAG_NO_FLAGS),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')])
|
headers=[('host', 'foo.bar')])
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000007010001234567668594e75e31d9')
|
assert_equal(f.to_bytes().encode('hex'), '000007010001234567668594e75e31d9')
|
||||||
|
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
10,
|
length=10,
|
||||||
HeadersFrame.FLAG_PADDED,
|
flags=(HeadersFrame.FLAG_PADDED),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
headers=[('host', 'foo.bar')],
|
||||||
pad_length=3)
|
pad_length=3)
|
||||||
assert_equal(
|
assert_equal(
|
||||||
@ -90,9 +106,9 @@ def test_headers_frame_to_bytes():
|
|||||||
'00000b01080123456703668594e75e31d9000000')
|
'00000b01080123456703668594e75e31d9000000')
|
||||||
|
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
10,
|
length=10,
|
||||||
HeadersFrame.FLAG_PRIORITY,
|
flags=(HeadersFrame.FLAG_PRIORITY),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
headers=[('host', 'foo.bar')],
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
@ -102,9 +118,9 @@ def test_headers_frame_to_bytes():
|
|||||||
'00000c012001234567876543212a668594e75e31d9')
|
'00000c012001234567876543212a668594e75e31d9')
|
||||||
|
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
14,
|
length=14,
|
||||||
HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY,
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
headers=[('host', 'foo.bar')],
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
@ -115,9 +131,9 @@ def test_headers_frame_to_bytes():
|
|||||||
'00001001280123456703876543212a668594e75e31d9000000')
|
'00001001280123456703876543212a668594e75e31d9000000')
|
||||||
|
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
14,
|
length=14,
|
||||||
HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY,
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
headers=[('host', 'foo.bar')],
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
@ -127,7 +143,11 @@ def test_headers_frame_to_bytes():
|
|||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
'00001001280123456703076543212a668594e75e31d9000000')
|
'00001001280123456703076543212a668594e75e31d9000000')
|
||||||
|
|
||||||
f = HeadersFrame(6, Frame.FLAG_NO_FLAGS, 0x0, 'foobar')
|
f = HeadersFrame(
|
||||||
|
length=6,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0,
|
||||||
|
headers=[('host', 'foo.bar')])
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -188,9 +208,9 @@ def test_headers_frame_from_bytes():
|
|||||||
|
|
||||||
def test_headers_frame_human_readable():
|
def test_headers_frame_human_readable():
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
7,
|
length=7,
|
||||||
HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY,
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[],
|
headers=[],
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
@ -199,9 +219,9 @@ def test_headers_frame_human_readable():
|
|||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
|
||||||
f = HeadersFrame(
|
f = HeadersFrame(
|
||||||
14,
|
length=14,
|
||||||
HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY,
|
flags=(HeadersFrame.FLAG_PADDED | HeadersFrame.FLAG_PRIORITY),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
headers=[('host', 'foo.bar')],
|
headers=[('host', 'foo.bar')],
|
||||||
pad_length=3,
|
pad_length=3,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
@ -212,27 +232,35 @@ def test_headers_frame_human_readable():
|
|||||||
|
|
||||||
def test_priority_frame_to_bytes():
|
def test_priority_frame_to_bytes():
|
||||||
f = PriorityFrame(
|
f = PriorityFrame(
|
||||||
5,
|
length=5,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=(Frame.FLAG_NO_FLAGS),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
exclusive=True,
|
exclusive=True,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
weight=42)
|
weight=42)
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000005020001234567876543212a')
|
assert_equal(f.to_bytes().encode('hex'), '000005020001234567876543212a')
|
||||||
|
|
||||||
f = PriorityFrame(
|
f = PriorityFrame(
|
||||||
5,
|
length=5,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=(Frame.FLAG_NO_FLAGS),
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
weight=21)
|
weight=21)
|
||||||
assert_equal(f.to_bytes().encode('hex'), '0000050200012345670765432115')
|
assert_equal(f.to_bytes().encode('hex'), '0000050200012345670765432115')
|
||||||
|
|
||||||
f = PriorityFrame(5, Frame.FLAG_NO_FLAGS, 0x0, stream_dependency=0x1234567)
|
f = PriorityFrame(
|
||||||
|
length=5,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0,
|
||||||
|
stream_dependency=0x1234567)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
f = PriorityFrame(5, Frame.FLAG_NO_FLAGS, 0x1234567, stream_dependency=0x0)
|
f = PriorityFrame(
|
||||||
|
length=5,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x1234567,
|
||||||
|
stream_dependency=0x0)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -260,9 +288,9 @@ def test_priority_frame_from_bytes():
|
|||||||
|
|
||||||
def test_priority_frame_human_readable():
|
def test_priority_frame_human_readable():
|
||||||
f = PriorityFrame(
|
f = PriorityFrame(
|
||||||
5,
|
length=5,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
exclusive=False,
|
exclusive=False,
|
||||||
stream_dependency=0x7654321,
|
stream_dependency=0x7654321,
|
||||||
weight=21)
|
weight=21)
|
||||||
@ -270,10 +298,17 @@ def test_priority_frame_human_readable():
|
|||||||
|
|
||||||
|
|
||||||
def test_rst_stream_frame_to_bytes():
|
def test_rst_stream_frame_to_bytes():
|
||||||
f = RstStreamFrame(4, Frame.FLAG_NO_FLAGS, 0x1234567, error_code=0x7654321)
|
f = RstStreamFrame(
|
||||||
|
length=4,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x1234567,
|
||||||
|
error_code=0x7654321)
|
||||||
assert_equal(f.to_bytes().encode('hex'), '00000403000123456707654321')
|
assert_equal(f.to_bytes().encode('hex'), '00000403000123456707654321')
|
||||||
|
|
||||||
f = RstStreamFrame(4, Frame.FLAG_NO_FLAGS, 0x0)
|
f = RstStreamFrame(
|
||||||
|
length=4,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -288,28 +323,39 @@ def test_rst_stream_frame_from_bytes():
|
|||||||
|
|
||||||
|
|
||||||
def test_rst_stream_frame_human_readable():
|
def test_rst_stream_frame_human_readable():
|
||||||
f = RstStreamFrame(4, Frame.FLAG_NO_FLAGS, 0x1234567, error_code=0x7654321)
|
f = RstStreamFrame(
|
||||||
|
length=4,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x1234567,
|
||||||
|
error_code=0x7654321)
|
||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
|
||||||
|
|
||||||
def test_settings_frame_to_bytes():
|
def test_settings_frame_to_bytes():
|
||||||
f = SettingsFrame(0, Frame.FLAG_NO_FLAGS, 0x0)
|
f = SettingsFrame(
|
||||||
|
length=0,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0)
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000000040000000000')
|
assert_equal(f.to_bytes().encode('hex'), '000000040000000000')
|
||||||
|
|
||||||
f = SettingsFrame(0, SettingsFrame.FLAG_ACK, 0x0)
|
f = SettingsFrame(
|
||||||
|
length=0,
|
||||||
|
flags=SettingsFrame.FLAG_ACK,
|
||||||
|
stream_id=0x0)
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000000040100000000')
|
assert_equal(f.to_bytes().encode('hex'), '000000040100000000')
|
||||||
|
|
||||||
f = SettingsFrame(
|
f = SettingsFrame(
|
||||||
6,
|
length=6,
|
||||||
SettingsFrame.FLAG_ACK, 0x0,
|
flags=SettingsFrame.FLAG_ACK,
|
||||||
|
stream_id=0x0,
|
||||||
settings={
|
settings={
|
||||||
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1})
|
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1})
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000006040100000000000200000001')
|
assert_equal(f.to_bytes().encode('hex'), '000006040100000000000200000001')
|
||||||
|
|
||||||
f = SettingsFrame(
|
f = SettingsFrame(
|
||||||
12,
|
length=12,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x0,
|
stream_id=0x0,
|
||||||
settings={
|
settings={
|
||||||
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1,
|
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1,
|
||||||
SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS: 0x12345678})
|
SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS: 0x12345678})
|
||||||
@ -317,7 +363,10 @@ def test_settings_frame_to_bytes():
|
|||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
'00000c040000000000000200000001000312345678')
|
'00000c040000000000000200000001000312345678')
|
||||||
|
|
||||||
f = SettingsFrame(0, Frame.FLAG_NO_FLAGS, 0x1234567)
|
f = SettingsFrame(
|
||||||
|
length=0,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x1234567)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -361,13 +410,17 @@ def test_settings_frame_from_bytes():
|
|||||||
|
|
||||||
|
|
||||||
def test_settings_frame_human_readable():
|
def test_settings_frame_human_readable():
|
||||||
f = SettingsFrame(12, Frame.FLAG_NO_FLAGS, 0x0, settings={})
|
f = SettingsFrame(
|
||||||
|
length=12,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0,
|
||||||
|
settings={})
|
||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
|
||||||
f = SettingsFrame(
|
f = SettingsFrame(
|
||||||
12,
|
length=12,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x0,
|
stream_id=0x0,
|
||||||
settings={
|
settings={
|
||||||
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1,
|
SettingsFrame.SETTINGS.SETTINGS_ENABLE_PUSH: 1,
|
||||||
SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS: 0x12345678})
|
SettingsFrame.SETTINGS.SETTINGS_MAX_CONCURRENT_STREAMS: 0x12345678})
|
||||||
@ -376,30 +429,38 @@ def test_settings_frame_human_readable():
|
|||||||
|
|
||||||
def test_push_promise_frame_to_bytes():
|
def test_push_promise_frame_to_bytes():
|
||||||
f = PushPromiseFrame(
|
f = PushPromiseFrame(
|
||||||
10,
|
length=10,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
0x7654321,
|
promised_stream=0x7654321,
|
||||||
'foobar')
|
header_block_fragment='foobar')
|
||||||
assert_equal(
|
assert_equal(
|
||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
'00000a05000123456707654321666f6f626172')
|
'00000a05000123456707654321666f6f626172')
|
||||||
|
|
||||||
f = PushPromiseFrame(
|
f = PushPromiseFrame(
|
||||||
14,
|
length=14,
|
||||||
HeadersFrame.FLAG_PADDED,
|
flags=HeadersFrame.FLAG_PADDED,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
0x7654321,
|
promised_stream=0x7654321,
|
||||||
'foobar',
|
header_block_fragment='foobar',
|
||||||
pad_length=3)
|
pad_length=3)
|
||||||
assert_equal(
|
assert_equal(
|
||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
'00000e0508012345670307654321666f6f626172000000')
|
'00000e0508012345670307654321666f6f626172000000')
|
||||||
|
|
||||||
f = PushPromiseFrame(4, Frame.FLAG_NO_FLAGS, 0x0, 0x1234567)
|
f = PushPromiseFrame(
|
||||||
|
length=4,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0,
|
||||||
|
promised_stream=0x1234567)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
f = PushPromiseFrame(4, Frame.FLAG_NO_FLAGS, 0x1234567, 0x0)
|
f = PushPromiseFrame(
|
||||||
|
length=4,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x1234567,
|
||||||
|
promised_stream=0x0)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -424,27 +485,38 @@ def test_push_promise_frame_from_bytes():
|
|||||||
|
|
||||||
def test_push_promise_frame_human_readable():
|
def test_push_promise_frame_human_readable():
|
||||||
f = PushPromiseFrame(
|
f = PushPromiseFrame(
|
||||||
14,
|
length=14,
|
||||||
HeadersFrame.FLAG_PADDED,
|
flags=HeadersFrame.FLAG_PADDED,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
0x7654321,
|
promised_stream=0x7654321,
|
||||||
'foobar',
|
header_block_fragment='foobar',
|
||||||
pad_length=3)
|
pad_length=3)
|
||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
|
||||||
|
|
||||||
def test_ping_frame_to_bytes():
|
def test_ping_frame_to_bytes():
|
||||||
f = PingFrame(8, PingFrame.FLAG_ACK, 0x0, payload=b'foobar')
|
f = PingFrame(
|
||||||
|
length=8,
|
||||||
|
flags=PingFrame.FLAG_ACK,
|
||||||
|
stream_id=0x0,
|
||||||
|
payload=b'foobar')
|
||||||
assert_equal(
|
assert_equal(
|
||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
'000008060100000000666f6f6261720000')
|
'000008060100000000666f6f6261720000')
|
||||||
|
|
||||||
f = PingFrame(8, Frame.FLAG_NO_FLAGS, 0x0, payload=b'foobardeadbeef')
|
f = PingFrame(
|
||||||
|
length=8,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x0,
|
||||||
|
payload=b'foobardeadbeef')
|
||||||
assert_equal(
|
assert_equal(
|
||||||
f.to_bytes().encode('hex'),
|
f.to_bytes().encode('hex'),
|
||||||
'000008060000000000666f6f6261726465')
|
'000008060000000000666f6f6261726465')
|
||||||
|
|
||||||
f = PingFrame(8, Frame.FLAG_NO_FLAGS, 0x1234567)
|
f = PingFrame(
|
||||||
|
length=8,
|
||||||
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
|
stream_id=0x1234567)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -467,15 +539,19 @@ def test_ping_frame_from_bytes():
|
|||||||
|
|
||||||
|
|
||||||
def test_ping_frame_human_readable():
|
def test_ping_frame_human_readable():
|
||||||
f = PingFrame(8, PingFrame.FLAG_ACK, 0x0, payload=b'foobar')
|
f = PingFrame(
|
||||||
|
length=8,
|
||||||
|
flags=PingFrame.FLAG_ACK,
|
||||||
|
stream_id=0x0,
|
||||||
|
payload=b'foobar')
|
||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
|
||||||
|
|
||||||
def test_goaway_frame_to_bytes():
|
def test_goaway_frame_to_bytes():
|
||||||
f = GoAwayFrame(
|
f = GoAwayFrame(
|
||||||
8,
|
length=8,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x0,
|
stream_id=0x0,
|
||||||
last_stream=0x1234567,
|
last_stream=0x1234567,
|
||||||
error_code=0x87654321,
|
error_code=0x87654321,
|
||||||
data=b'')
|
data=b'')
|
||||||
@ -484,9 +560,9 @@ def test_goaway_frame_to_bytes():
|
|||||||
'0000080700000000000123456787654321')
|
'0000080700000000000123456787654321')
|
||||||
|
|
||||||
f = GoAwayFrame(
|
f = GoAwayFrame(
|
||||||
14,
|
length=14,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x0,
|
stream_id=0x0,
|
||||||
last_stream=0x1234567,
|
last_stream=0x1234567,
|
||||||
error_code=0x87654321,
|
error_code=0x87654321,
|
||||||
data=b'foobar')
|
data=b'foobar')
|
||||||
@ -495,16 +571,17 @@ def test_goaway_frame_to_bytes():
|
|||||||
'00000e0700000000000123456787654321666f6f626172')
|
'00000e0700000000000123456787654321666f6f626172')
|
||||||
|
|
||||||
f = GoAwayFrame(
|
f = GoAwayFrame(
|
||||||
8,
|
length=8,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
last_stream=0x1234567,
|
last_stream=0x1234567,
|
||||||
error_code=0x87654321)
|
error_code=0x87654321)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
def test_goaway_frame_from_bytes():
|
def test_goaway_frame_from_bytes():
|
||||||
f = Frame.from_bytes('0000080700000000000123456787654321'.decode('hex'))
|
f = Frame.from_bytes(
|
||||||
|
'0000080700000000000123456787654321'.decode('hex'))
|
||||||
assert isinstance(f, GoAwayFrame)
|
assert isinstance(f, GoAwayFrame)
|
||||||
assert_equal(f.length, 8)
|
assert_equal(f.length, 8)
|
||||||
assert_equal(f.TYPE, GoAwayFrame.TYPE)
|
assert_equal(f.TYPE, GoAwayFrame.TYPE)
|
||||||
@ -528,9 +605,9 @@ def test_goaway_frame_from_bytes():
|
|||||||
|
|
||||||
def test_go_away_frame_human_readable():
|
def test_go_away_frame_human_readable():
|
||||||
f = GoAwayFrame(
|
f = GoAwayFrame(
|
||||||
14,
|
length=14,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x0,
|
stream_id=0x0,
|
||||||
last_stream=0x1234567,
|
last_stream=0x1234567,
|
||||||
error_code=0x87654321,
|
error_code=0x87654321,
|
||||||
data=b'foobar')
|
data=b'foobar')
|
||||||
@ -539,23 +616,23 @@ def test_go_away_frame_human_readable():
|
|||||||
|
|
||||||
def test_window_update_frame_to_bytes():
|
def test_window_update_frame_to_bytes():
|
||||||
f = WindowUpdateFrame(
|
f = WindowUpdateFrame(
|
||||||
4,
|
length=4,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x0,
|
stream_id=0x0,
|
||||||
window_size_increment=0x1234567)
|
window_size_increment=0x1234567)
|
||||||
assert_equal(f.to_bytes().encode('hex'), '00000408000000000001234567')
|
assert_equal(f.to_bytes().encode('hex'), '00000408000000000001234567')
|
||||||
|
|
||||||
f = WindowUpdateFrame(
|
f = WindowUpdateFrame(
|
||||||
4,
|
length=4,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
window_size_increment=0x7654321)
|
window_size_increment=0x7654321)
|
||||||
assert_equal(f.to_bytes().encode('hex'), '00000408000123456707654321')
|
assert_equal(f.to_bytes().encode('hex'), '00000408000123456707654321')
|
||||||
|
|
||||||
f = WindowUpdateFrame(
|
f = WindowUpdateFrame(
|
||||||
4,
|
length=4,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x0,
|
stream_id=0x0,
|
||||||
window_size_increment=0xdeadbeef)
|
window_size_increment=0xdeadbeef)
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
@ -575,22 +652,26 @@ def test_window_update_frame_from_bytes():
|
|||||||
|
|
||||||
def test_window_update_frame_human_readable():
|
def test_window_update_frame_human_readable():
|
||||||
f = WindowUpdateFrame(
|
f = WindowUpdateFrame(
|
||||||
4,
|
length=4,
|
||||||
Frame.FLAG_NO_FLAGS,
|
flags=Frame.FLAG_NO_FLAGS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
window_size_increment=0x7654321)
|
window_size_increment=0x7654321)
|
||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
|
||||||
|
|
||||||
def test_continuation_frame_to_bytes():
|
def test_continuation_frame_to_bytes():
|
||||||
f = ContinuationFrame(
|
f = ContinuationFrame(
|
||||||
6,
|
length=6,
|
||||||
ContinuationFrame.FLAG_END_HEADERS,
|
flags=ContinuationFrame.FLAG_END_HEADERS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
'foobar')
|
header_block_fragment='foobar')
|
||||||
assert_equal(f.to_bytes().encode('hex'), '000006090401234567666f6f626172')
|
assert_equal(f.to_bytes().encode('hex'), '000006090401234567666f6f626172')
|
||||||
|
|
||||||
f = ContinuationFrame(6, ContinuationFrame.FLAG_END_HEADERS, 0x0, 'foobar')
|
f = ContinuationFrame(
|
||||||
|
length=6,
|
||||||
|
flags=ContinuationFrame.FLAG_END_HEADERS,
|
||||||
|
stream_id=0x0,
|
||||||
|
header_block_fragment='foobar')
|
||||||
tutils.raises(ValueError, f.to_bytes)
|
tutils.raises(ValueError, f.to_bytes)
|
||||||
|
|
||||||
|
|
||||||
@ -606,8 +687,8 @@ def test_continuation_frame_from_bytes():
|
|||||||
|
|
||||||
def test_continuation_frame_human_readable():
|
def test_continuation_frame_human_readable():
|
||||||
f = ContinuationFrame(
|
f = ContinuationFrame(
|
||||||
6,
|
length=6,
|
||||||
ContinuationFrame.FLAG_END_HEADERS,
|
flags=ContinuationFrame.FLAG_END_HEADERS,
|
||||||
0x1234567,
|
stream_id=0x1234567,
|
||||||
'foobar')
|
header_block_fragment='foobar')
|
||||||
assert f.human_readable()
|
assert f.human_readable()
|
||||||
|
Loading…
Reference in New Issue
Block a user