File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed
Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
2+ from hpack .exceptions import HPACKDecodingError
23from hpack .huffman_table import decode_huffman
34from hpack .huffman import HuffmanEncoder
45from hpack .huffman_constants import REQUEST_CODES , REQUEST_CODES_LENGTH
56
7+ from hypothesis import given , example
8+ from hypothesis .strategies import binary
9+
610
711class TestHuffman (object ):
812
@@ -18,3 +22,24 @@ def test_request_huffman_encode(self):
1822 assert encoder .encode (b"no-cache" ) == b'\xa8 \xeb \x10 d\x9c \xbf '
1923 assert encoder .encode (b"custom-key" ) == b'%\xa8 I\xe9 [\xa9 }\x7f '
2024 assert encoder .encode (b"custom-value" ) == b'%\xa8 I\xe9 [\xb8 \xe8 \xb4 \xbf '
25+
26+
27+ class TestHuffmanDecoder (object ):
28+ @given (data = binary ())
29+ @example (b'\xff ' )
30+ @example (b'\x5f \xff \xff \xff \xff ' )
31+ @example (b'\x00 \x3f \xff \xff \xff ' )
32+ def test_huffman_decoder_properly_handles_all_bytestrings (self , data ):
33+ """
34+ When given random bytestrings, either we get HPACKDecodingError or we
35+ get a bytestring back.
36+ """
37+ # The examples aren't special, they're just known to hit specific error
38+ # paths through the state machine. Basically, they are strings that are
39+ # definitely invalid.
40+ try :
41+ result = decode_huffman (data )
42+ except HPACKDecodingError :
43+ result = b''
44+
45+ assert isinstance (result , bytes )
You can’t perform that action at this time.
0 commit comments