27
27
import socket
28
28
import zlib
29
29
from io import BytesIO
30
-
30
+ import hyper
31
31
32
32
def decode_frame (frame_data ):
33
33
f , length = Frame .parse_frame_header (frame_data [:9 ])
@@ -279,11 +279,9 @@ def test_connections_handle_too_small_max_frame_size_properly(self):
279
279
# 2^24-1 octets. Confirm that the max frame size did not increase.
280
280
assert c ._settings [SettingsFrame .SETTINGS_MAX_FRAME_SIZE ] == FRAME_MAX_LEN
281
281
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
287
285
288
286
def test_connections_handle_too_big_max_frame_size_properly (self ):
289
287
sock = DummySocket ()
@@ -299,11 +297,9 @@ def test_connections_handle_too_big_max_frame_size_properly(self):
299
297
# 2^24-1 octets. Confirm that the max frame size did not increase.
300
298
assert c ._settings [SettingsFrame .SETTINGS_MAX_FRAME_SIZE ] == FRAME_MAX_LEN
301
299
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
307
303
308
304
def test_connections_handle_resizing_header_tables_properly (self ):
309
305
sock = DummySocket ()
@@ -1345,34 +1341,42 @@ def data_callback(frame):
1345
1341
def test_connection_sends_rst_frame_if_frame_size_too_large (self ):
1346
1342
sock = DummySocket ()
1347
1343
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 )])
1349
1347
sock .buffer = BytesIO (d .serialize ())
1350
1348
1349
+ frames = []
1350
+
1351
1351
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 )
1354
1355
1355
1356
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
1359
1357
c ._sock = sock
1360
1358
c ._send_rst_frame = send_rst_frame
1361
1359
c .request ('GET' , '/' )
1362
1360
c ._recv_cb ()
1363
1361
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
+
1364
1368
def test_connection_stream_is_removed_on_frame_size_error (self ):
1365
1369
sock = DummySocket ()
1366
1370
d = DataFrame (1 )
1367
- d .data = b'hi there frame'
1371
+ d .data = b'' . join ([ b" hi there sir" for x in range ( 40 )])
1368
1372
sock .buffer = BytesIO (d .serialize ())
1369
1373
1370
1374
c = HTTP20Connection ('www.google.com' )
1371
- c ._settings [SettingsFrame .SETTINGS_MAX_FRAME_SIZE ] = 10
1372
1375
c ._sock = sock
1373
1376
c .request ('GET' , '/' )
1374
1377
1375
1378
# Make sure the stream gets removed from the map
1379
+ # after receiving an out of size data frame
1376
1380
assert len (c .streams ) == 1
1377
1381
c ._recv_cb ()
1378
1382
assert len (c .streams ) == 0
0 commit comments