Debian Codegraph @

testing/web-platform/tests/tools/third_party/hpack/test/test_hpack_integration.py

raw
1 # -*- coding: utf-8 -*-
2 """
3 This module defines substantial HPACK integration tests. These can take a very
4 long time to run, so they're outside the main test suite, but they need to be
5 run before every change to HPACK.
6 """
7 from binascii import unhexlify
8 from pytest import skip
9
10 from hpack import Decoder, Encoder, HeaderTuple
11
12
13 class TestHPACKDecoderIntegration:
14 def test_can_decode_a_story(self, story):
15 d = Decoder()
16
17 # We test against draft 9 of the HPACK spec.
18 if story['draft'] != 9:
19 skip("We test against draft 9, not draft %d" % story['draft'])
20
21 for case in story['cases']:
22 try:
23 d.header_table_size = case['header_table_size']
24 except KeyError:
25 pass
26 decoded_headers = d.decode(unhexlify(case['wire']))
27
28 # The correct headers are a list of dicts, which is annoying.
29 correct_headers = [
30 (item[0], item[1])
31 for header in case['headers']
32 for item in header.items()
33 ]
34 correct_headers = correct_headers
35 assert correct_headers == decoded_headers
36 assert all(
37 isinstance(header, HeaderTuple) for header in decoded_headers
38 )
39
40 def test_can_encode_a_story_no_huffman(self, raw_story):
41 d = Decoder()
42 e = Encoder()
43
44 for case in raw_story['cases']:
45 # The input headers are a list of dicts, which is annoying.
46 input_headers = [
47 (item[0], item[1])
48 for header in case['headers']
49 for item in header.items()
50 ]
51
52 encoded = e.encode(input_headers, huffman=False)
53 decoded_headers = d.decode(encoded)
54
55 assert input_headers == decoded_headers
56 assert all(
57 isinstance(header, HeaderTuple) for header in decoded_headers
58 )
59
60 def test_can_encode_a_story_with_huffman(self, raw_story):
61 d = Decoder()
62 e = Encoder()
63
64 for case in raw_story['cases']:
65 # The input headers are a list of dicts, which is annoying.
66 input_headers = [
67 (item[0], item[1])
68 for header in case['headers']
69 for item in header.items()
70 ]
71
72 encoded = e.encode(input_headers, huffman=True)
73 decoded_headers = d.decode(encoded)
74
75 assert input_headers == decoded_headers