|
4 | 4 | PushPromiseFrame, PingFrame, GoAwayFrame, WindowUpdateFrame, HeadersFrame, |
5 | 5 | ContinuationFrame, AltSvcFrame, Origin, BlockedFrame, |
6 | 6 | ) |
7 | | -from hyperframe.exceptions import UnknownFrameError |
| 7 | +from hyperframe.exceptions import UnknownFrameError, InvalidPaddingError |
8 | 8 | import pytest |
9 | 9 |
|
10 | 10 |
|
@@ -146,6 +146,14 @@ def test_body_length_behaves_correctly(self): |
146 | 146 | data = f.serialize() |
147 | 147 | assert f.body_len == 300 |
148 | 148 |
|
| 149 | + def test_data_frame_with_invalid_padding_fails_to_parse(self): |
| 150 | + # This frame has a padding length of 6 bytes, but a total length of |
| 151 | + # only 5. |
| 152 | + data = b'\x00\x00\x05\x00\x0b\x00\x00\x00\x01\x06\x54\x65\x73\x74' |
| 153 | + |
| 154 | + with pytest.raises(InvalidPaddingError): |
| 155 | + decode_frame(data) |
| 156 | + |
149 | 157 |
|
150 | 158 | class TestPriorityFrame(object): |
151 | 159 | payload = b'\x00\x00\x05\x02\x00\x00\x00\x00\x01\x80\x00\x00\x04\x40' |
@@ -308,6 +316,14 @@ def test_push_promise_frame_parses_properly(self): |
308 | 316 | assert f.data == b'hello world' |
309 | 317 | assert f.body_len == 15 |
310 | 318 |
|
| 319 | + def test_push_promise_frame_with_invalid_padding_fails_to_parse(self): |
| 320 | + # This frame has a padding length of 6 bytes, but a total length of |
| 321 | + # only 5. |
| 322 | + data = b'\x00\x00\x05\x05\x08\x00\x00\x00\x01\x06\x54\x65\x73\x74' |
| 323 | + |
| 324 | + with pytest.raises(InvalidPaddingError): |
| 325 | + decode_frame(data) |
| 326 | + |
311 | 327 |
|
312 | 328 | class TestPingFrame(object): |
313 | 329 | def test_ping_frame_has_only_one_flag(self): |
@@ -482,6 +498,14 @@ def test_headers_frame_with_priority_serializes_properly(self): |
482 | 498 |
|
483 | 499 | assert f.serialize() == s |
484 | 500 |
|
| 501 | + def test_headers_frame_with_invalid_padding_fails_to_parse(self): |
| 502 | + # This frame has a padding length of 6 bytes, but a total length of |
| 503 | + # only 5. |
| 504 | + data = b'\x00\x00\x05\x01\x08\x00\x00\x00\x01\x06\x54\x65\x73\x74' |
| 505 | + |
| 506 | + with pytest.raises(InvalidPaddingError): |
| 507 | + decode_frame(data) |
| 508 | + |
485 | 509 |
|
486 | 510 | class TestContinuationFrame(object): |
487 | 511 | def test_continuation_frame_flags(self): |
|
0 commit comments