File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change 1
1
# -*- coding: utf-8 -*-
2
+ from hpack .exceptions import HPACKDecodingError
2
3
from hpack .huffman_table import decode_huffman
3
4
from hpack .huffman import HuffmanEncoder
4
5
from hpack .huffman_constants import REQUEST_CODES , REQUEST_CODES_LENGTH
5
6
7
+ from hypothesis import given , example
8
+ from hypothesis .strategies import binary
9
+
6
10
7
11
class TestHuffman (object ):
8
12
@@ -18,3 +22,24 @@ def test_request_huffman_encode(self):
18
22
assert encoder .encode (b"no-cache" ) == b'\xa8 \xeb \x10 d\x9c \xbf '
19
23
assert encoder .encode (b"custom-key" ) == b'%\xa8 I\xe9 [\xa9 }\x7f '
20
24
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