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

Commit 876e607

Browse files
committed
Add test for unexpected stream id
1 parent ed3aff9 commit 876e607

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

hyper/http20/connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .stream import Stream
1919
from .response import HTTP20Response, HTTP20Push
2020
from .window import FlowControlManager
21-
from .exceptions import ConnectionError
21+
from .exceptions import ConnectionError, ProtocolError
2222
from . import errors
2323

2424
import errno
@@ -558,7 +558,6 @@ def _consume_frame_payload(self, frame, data):
558558
This builds and handles a frame.
559559
"""
560560
frame.parse_body(data)
561-
562561
log.info(
563562
"Received frame %s on stream %d",
564563
frame.__class__.__name__,
@@ -593,7 +592,9 @@ def _consume_frame_payload(self, frame, data):
593592
f = RstStreamFrame(frame.stream_id)
594593
f.error_code = 1 # PROTOCOL_ERROR
595594
self._send_cb(f)
596-
log.warning("Unexpected stream identifier %d", frame.stream_id)
595+
error_string = ("Unexpected stream identifier %d" %
596+
(frame.stream_id))
597+
raise ProtocolError(error_string)
597598
else:
598599
self.receive_frame(frame)
599600

test/test_hyper.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,21 @@ def test_goaway_frame_invalid_error_code(self):
12611261
assert 'data about non existing error code' in err_msg
12621262
assert str(f.error_code) in err_msg
12631263

1264+
def test_receive_unexpected_stream_id(self):
1265+
frames = []
1266+
1267+
def data_callback(frame):
1268+
frames.append(frame)
1269+
1270+
c = HTTP20Connection('www.google.com')
1271+
c._send_cb = data_callback
1272+
1273+
f = DataFrame(-1)
1274+
data = memoryview(b"hi there sir")
1275+
1276+
with pytest.raises(ProtocolError):
1277+
c._consume_frame_payload(f, data)
1278+
12641279
# Some utility classes for the tests.
12651280
class NullEncoder(object):
12661281
@staticmethod

0 commit comments

Comments
 (0)