Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit b62fa4f

Browse files
committed
Fix confusion between MAX_FRAME_SIZE and endpoint settings (unit tests)
1 parent 5ba393f commit b62fa4f

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

test/test_hyper.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import socket
2828
import zlib
2929
from io import BytesIO
30-
30+
import hyper
3131

3232
def decode_frame(frame_data):
3333
f, length = Frame.parse_frame_header(frame_data[:9])
@@ -279,11 +279,9 @@ def test_connections_handle_too_small_max_frame_size_properly(self):
279279
# 2^24-1 octets. Confirm that the max frame size did not increase.
280280
assert c._settings[SettingsFrame.SETTINGS_MAX_FRAME_SIZE] == FRAME_MAX_LEN
281281

282-
# Confirm we got a SETTINGS ACK.
283-
f2 = decode_frame(sock.queue[0])
284-
assert isinstance(f2, SettingsFrame)
285-
assert f2.stream_id == 0
286-
assert f2.flags == set(['ACK'])
282+
# When the setting containing the max frame size value is out of range,
283+
# the spec dictates to tear down the connection.
284+
assert c._sock == None
287285

288286
def test_connections_handle_too_big_max_frame_size_properly(self):
289287
sock = DummySocket()
@@ -299,11 +297,9 @@ def test_connections_handle_too_big_max_frame_size_properly(self):
299297
# 2^24-1 octets. Confirm that the max frame size did not increase.
300298
assert c._settings[SettingsFrame.SETTINGS_MAX_FRAME_SIZE] == FRAME_MAX_LEN
301299

302-
# Confirm we got a SETTINGS ACK.
303-
f2 = decode_frame(sock.queue[0])
304-
assert isinstance(f2, SettingsFrame)
305-
assert f2.stream_id == 0
306-
assert f2.flags == set(['ACK'])
300+
# When the setting containing the max frame size value is out of range,
301+
# the spec dictates to tear down the connection.
302+
assert c._sock == None
307303

308304
def test_connections_handle_resizing_header_tables_properly(self):
309305
sock = DummySocket()
@@ -1345,34 +1341,42 @@ def data_callback(frame):
13451341
def test_connection_sends_rst_frame_if_frame_size_too_large(self):
13461342
sock = DummySocket()
13471343
d = DataFrame(1)
1348-
d.data = b'hi there frame'
1344+
# Create big data frame that exceeds the FRAME_MAX_LEN value in order
1345+
# to trigger the reset frame with error code 6 (FRAME_SIZE_ERROR)
1346+
d.data = b''.join([b"hi there sir" for x in range(40)])
13491347
sock.buffer = BytesIO(d.serialize())
13501348

1349+
frames = []
1350+
13511351
def send_rst_frame(stream_id, error_code):
1352-
assert stream_id == 1
1353-
assert error_code == 6 #FRAME_SIZE_ERROR
1352+
f = RstStreamFrame(stream_id)
1353+
f.error_code = error_code
1354+
frames.append(f)
13541355

13551356
c = HTTP20Connection('www.google.com')
1356-
# Lower the maximum frame size settings in order to force the
1357-
# connection to send a reset frame with FRAME_SIZE_ERROR
1358-
c._settings[SettingsFrame.SETTINGS_MAX_FRAME_SIZE] = 10
13591357
c._sock = sock
13601358
c._send_rst_frame = send_rst_frame
13611359
c.request('GET', '/')
13621360
c._recv_cb()
13631361

1362+
assert len(frames) == 1
1363+
f = frames[0]
1364+
assert isinstance(f, RstStreamFrame)
1365+
assert f.stream_id == 1
1366+
assert f.error_code == 6 #FRAME_SIZE_ERROR
1367+
13641368
def test_connection_stream_is_removed_on_frame_size_error(self):
13651369
sock = DummySocket()
13661370
d = DataFrame(1)
1367-
d.data = b'hi there frame'
1371+
d.data = b''.join([b"hi there sir" for x in range(40)])
13681372
sock.buffer = BytesIO(d.serialize())
13691373

13701374
c = HTTP20Connection('www.google.com')
1371-
c._settings[SettingsFrame.SETTINGS_MAX_FRAME_SIZE] = 10
13721375
c._sock = sock
13731376
c.request('GET', '/')
13741377

13751378
# Make sure the stream gets removed from the map
1379+
# after receiving an out of size data frame
13761380
assert len(c.streams) == 1
13771381
c._recv_cb()
13781382
assert len(c.streams) == 0

0 commit comments

Comments
 (0)