1 ! Copyright (C) 2021 Your name.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: tools.test http2.hpack http2.hpack.private accessors
7 ! constants are from RFC 7541, appendix C, various sections
8 CONSTANT: c1 B{ 234 31 154 10 42 }
9 CONSTANT: c21 B{ 0x40 0x0a 0x63 0x75 0x73 0x74 0x6f 0x6d 0x2d
10 0x6b 0x65 0x79 0x0d 0x63 0x75 0x73 0x74 0x6f 0x6d 0x2d
11 0x68 0x65 0x61 0x64 0x65 0x72 }
12 CONSTANT: c22 B{ 0x04 0x0c 0x2f 0x73 0x61 0x6d 0x70 0x6c 0x65
13 0x2f 0x70 0x61 0x74 0x68 }
14 CONSTANT: c23 B{ 0x10 0x08 0x70 0x61 0x73 0x73 0x77 0x6f 0x72
15 0x64 0x06 0x73 0x65 0x63 0x72 0x65 0x74 }
16 CONSTANT: c24 B{ 0x82 }
18 CONSTANT: c31 B{ 0x82 0x86 0x84 0x41 0x0f 0x77 0x77 0x77 0x2e
19 0x65 0x78 0x61 0x6d 0x70 0x6c 0x65 0x2e 0x63 0x6f 0x6d }
20 CONSTANT: c32 B{ 0x82 0x86 0x84 0xbe 0x58 0x08 0x6e 0x6f 0x2d
21 0x63 0x61 0x63 0x68 0x65 }
22 CONSTANT: c33 B{ 0x82 0x87 0x85 0xbf 0x40 0x0a 0x63 0x75 0x73
23 0x74 0x6f 0x6d 0x2d 0x6b 0x65 0x79 0x0c 0x63 0x75 0x73
24 0x74 0x6f 0x6d 0x2d 0x76 0x61 0x6c 0x75 0x65 }
26 CONSTANT: c41 B{ 0x82 0x86 0x84 0x41 0x8c 0xf1 0xe3 0xc2 0xe5
27 0xf2 0x3a 0x6b 0xa0 0xab 0x90 0xf4 0xff }
28 CONSTANT: c42 B{ 0x82 0x86 0x84 0xbe 0x58 0x86 0xa8 0xeb 0x10
30 CONSTANT: c43 B{ 0x82 0x87 0x85 0xbf 0x40 0x88 0x25 0xa8 0x49
31 0xe9 0x5b 0xa9 0x7d 0x7f 0x89 0x25 0xa8 0x49 0xe9 0x5b
34 ! These headers are the same as those for section 4
35 CONSTANT: c31h { { ":method" "GET" } { ":scheme" "http" }
36 { ":path" "/" } { ":authority" "www.example.com" } }
37 CONSTANT: c32h { { ":method" "GET" } { ":scheme" "http" }
38 { ":path" "/" } { ":authority" "www.example.com" }
39 { "cache-control" "no-cache" } }
40 CONSTANT: c33h { { ":method" "GET" } { ":scheme" "https" }
41 { ":path" "/index.html" } { ":authority" "www.example.com" }
42 { "custom-key" "custom-value" } }
44 CONSTANT: c51 B{ 0x48 0x03 0x33 0x30 0x32 0x58 0x07 0x70 0x72
45 0x69 0x76 0x61 0x74 0x65 0x61 0x1d 0x4d 0x6f 0x6e 0x2c 0x20 0x32
46 0x31 0x20 0x4f 0x63 0x74 0x20 0x32 0x30 0x31 0x33 0x20 0x32
47 0x30 0x3a 0x31 0x33 0x3a 0x32 0x31 0x20 0x47 0x4d 0x54 0x6e
48 0x17 0x68 0x74 0x74 0x70 0x73 0x3a 0x2f 0x2f 0x77 0x77 0x77
49 0x2e 0x65 0x78 0x61 0x6d 0x70 0x6c 0x65 0x2e 0x63 0x6f 0x6d }
50 CONSTANT: c52 B{ 0x48 0x03 0x33 0x30 0x37 0xc1 0xc0 0xbf }
51 CONSTANT: c53 B{ 0x88 0xc1 0x61 0x1d 0x4d 0x6f 0x6e 0x2c 0x20
52 0x32 0x31 0x20 0x4f 0x63 0x74 0x20 0x32 0x30 0x31 0x33 0x20 0x32
53 0x30 0x3a 0x31 0x33 0x3a 0x32 0x32 0x20 0x47 0x4d 0x54 0xc0
54 0x5a 0x04 0x67 0x7a 0x69 0x70 0x77 0x38 0x66 0x6f 0x6f 0x3d
55 0x41 0x53 0x44 0x4a 0x4b 0x48 0x51 0x4b 0x42 0x5a 0x58 0x4f
56 0x51 0x57 0x45 0x4f 0x50 0x49 0x55 0x41 0x58 0x51 0x57 0x45
57 0x4f 0x49 0x55 0x3b 0x20 0x6d 0x61 0x78 0x2d 0x61 0x67 0x65
58 0x3d 0x33 0x36 0x30 0x30 0x3b 0x20 0x76 0x65 0x72 0x73 0x69
61 CONSTANT: c61 B{ 0x48 0x82 0x64 0x02 0x58 0x85 0xae 0xc3 0x77
62 0x1a 0x4b 0x61 0x96 0xd0 0x7a 0xbe 0x94 0x10 0x54 0xd4
63 0x44 0xa8 0x20 0x05 0x95 0x04 0x0b 0x81 0x66 0xe0 0x82 0xa6
64 0x2d 0x1b 0xff 0x6e 0x91 0x9d 0x29 0xad 0x17 0x18 0x63 0xc7
65 0x8f 0x0b 0x97 0xc8 0xe9 0xae 0x82 0xae 0x43 0xd3 }
66 CONSTANT: c62 B{ 0x48 0x83 0x64 0x0e 0xff 0xc1 0xc0 0xbf }
67 CONSTANT: c63 B{ 0x88 0xc1 0x61 0x96 0xd0 0x7a 0xbe 0x94 0x10
68 0x54 0xd4 0x44 0xa8 0x20 0x05 0x95 0x04 0x0b 0x81 0x66
69 0xe0 0x84 0xa6 0x2d 0x1b 0xff 0xc0 0x5a 0x83 0x9b 0xd9 0xab
70 0x77 0xad 0x94 0xe7 0x82 0x1d 0xd7 0xf2 0xe6 0xc7 0xb3 0x35
71 0xdf 0xdf 0xcd 0x5b 0x39 0x60 0xd5 0xaf 0x27 0x08 0x7f 0x36
72 0x72 0xc1 0xab 0x27 0x0f 0xb5 0x29 0x1f 0x95 0x87 0x31 0x60
73 0x65 0xc0 0x03 0xed 0x4e 0xe5 0xb1 0x06 0x3d 0x50 0x07 }
75 ! These headers are the same as those for section 6
76 CONSTANT: c51h { { ":status" "302" }
77 { "cache-control" "private" }
78 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
79 { "location" "https://www.example.com" } }
80 CONSTANT: c52h { { ":status" "307" }
81 { "cache-control" "private" }
82 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
83 { "location" "https://www.example.com" } }
84 CONSTANT: c53h { { ":status" "200" }
85 { "cache-control" "private" }
86 { "date" "Mon, 21 Oct 2013 20:13:22 GMT" }
87 { "location" "https://www.example.com" }
88 { "content-encoding" "gzip" }
89 { "set-cookie" "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" } }
92 ! tests come from RFC 7541, Appendix C
94 ! RFC7541 Appendex C.1
95 { 1 10 } [ c1 0 5 decode-integer nipd ] unit-test
96 { 4 1337 } [ c1 1 5 decode-integer nipd ] unit-test
97 { 5 42 } [ c1 4 8 decode-integer nipd ] unit-test
100 ! RFC7541 Appendix C.2.1 subset
102 [ c21 1 decode-string nipd ] unit-test
104 ! RFC7541 Appendix C.4.3 subset
105 { 24 "custom-value" }
106 [ c43 14 decode-string nipd ] unit-test
108 ! RFC7541 Appendix C.2.1
109 { T{ hpack-context f 4096 { { "custom-key" "custom-header" } } }
110 26 { "custom-key" "custom-header" } }
111 [ hpack-context new c21 0 decode-field nipd ] unit-test
113 ! RFC7541 Appendix C.2.2
114 { T{ hpack-context f 4096 { } } 14 { ":path" "/sample/path" } }
115 [ hpack-context new c22 0 decode-field nipd ] unit-test
117 ! RFC7541 Appendix C.2.3
118 { T{ hpack-context f 4096 { } } 17 { "password" "secret" } }
119 [ hpack-context new c23 0 decode-field nipd ] unit-test
121 ! RFC7541 Appendix C.2.4
122 { T{ hpack-context f 4096 { } } 1 { ":method" "GET" } }
123 [ hpack-context new c24 0 decode-field nipd ] unit-test
126 ! RFC7541 Appendix C.3
128 { { ":method" "GET" } { ":scheme" "http" }
129 { ":path" "/" } { ":authority" "www.example.com" } }
130 { { ":method" "GET" } { ":scheme" "http" }
131 { ":path" "/" } { ":authority" "www.example.com" }
132 { "cache-control" "no-cache" } }
133 { { ":method" "GET" } { ":scheme" "https" }
134 { ":path" "/index.html" } { ":authority" "www.example.com" }
135 { "custom-key" "custom-value" } }
136 T{ hpack-context f 4096 { { "custom-key" "custom-value" }
137 { "cache-control" "no-cache" }
138 { ":authority" "www.example.com" } } }
140 [ hpack-context new c31 c32 c33 [ hpack-decode swap ] tri@ ] unit-test
142 ! RFC7541 Appendix C.4
144 { { ":method" "GET" } { ":scheme" "http" }
145 { ":path" "/" } { ":authority" "www.example.com" } }
146 { { ":method" "GET" } { ":scheme" "http" }
147 { ":path" "/" } { ":authority" "www.example.com" }
148 { "cache-control" "no-cache" } }
149 { { ":method" "GET" } { ":scheme" "https" }
150 { ":path" "/index.html" } { ":authority" "www.example.com" }
151 { "custom-key" "custom-value" } }
152 T{ hpack-context f 4096 { { "custom-key" "custom-value" }
153 { "cache-control" "no-cache" }
154 { ":authority" "www.example.com" } } }
156 [ hpack-context new c41 c42 c43 [ hpack-decode swap ] tri@ ] unit-test
158 ! RFC7541 Appendix C.5
162 { "cache-control" "private" }
163 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
164 { "location" "https://www.example.com" }
168 { "cache-control" "private" }
169 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
170 { "location" "https://www.example.com" }
174 { "cache-control" "private" }
175 { "date" "Mon, 21 Oct 2013 20:13:22 GMT" }
176 { "location" "https://www.example.com" }
177 { "content-encoding" "gzip" }
178 { "set-cookie" "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" }
180 T{ hpack-context f 256 { { "set-cookie" "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" }
181 { "content-encoding" "gzip" }
182 { "date" "Mon, 21 Oct 2013 20:13:22 GMT" } } }
184 [ hpack-context new 256 >>max-size c51 c52 c53
185 [ hpack-decode swap ] tri@ ] unit-test
187 ! RFC7541 Appendix C.6
191 { "cache-control" "private" }
192 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
193 { "location" "https://www.example.com" }
197 { "cache-control" "private" }
198 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
199 { "location" "https://www.example.com" }
203 { "cache-control" "private" }
204 { "date" "Mon, 21 Oct 2013 20:13:22 GMT" }
205 { "location" "https://www.example.com" }
206 { "content-encoding" "gzip" }
207 { "set-cookie" "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" }
209 T{ hpack-context f 256 { { "set-cookie" "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" }
210 { "content-encoding" "gzip" }
211 { "date" "Mon, 21 Oct 2013 20:13:22 GMT" } } }
213 [ hpack-context new 256 >>max-size c61 c62 c63
214 [ hpack-decode swap ] tri@ ] unit-test
217 ! encoding can be tested primarily by ensuring the encoding and
218 ! decoding of an object yields the same object (since encoding
219 ! does not have a well defined output other then `decodable').
222 ! integer and string encoding tests
223 { B{ 0b00101010 } } [ 0b00100000 10 5 encode-integer ] unit-test
224 { B{ 0b01011111 0b10011010 0b00001010 } } [ 0b01000000 1337 5 encode-integer ] unit-test
225 { B{ 0b00101010 } } [ 0b00000000 42 8 encode-integer ] unit-test
227 { B{ 0x0a 0x63 0x75 0x73 0x74 0x6f 0x6d 0x2d 0x6b 0x65 0x79 } }
228 [ "custom-key" encode-string-raw ] unit-test
230 { B{ 0x88 0x25 0xa8 0x49 0xe9 0x5b 0xa9 0x7d 0x7f } }
231 [ "custom-key" encode-string-huffman ] unit-test
234 ! single header encoding check, mirrors the tests from RFC 7541, Appendix C.2
235 { t t { "custom-key" "custom-header" } }
236 [ hpack-context new { "custom-key" "custom-header" } encode-field
237 hpack-context new swap 0 decode-field
238 [ [ = ] [ swap length = ] 2bi* ] dip ! check contexts are the same and the entire block used for decoding
241 { t t { ":path" "/sample/path" } }
242 [ hpack-context new { ":path" "/sample/path" } encode-field
243 hpack-context new swap 0 decode-field
244 [ [ = ] [ swap length = ] 2bi* ] dip ! check contexts are the same and the entire block used for decoding
247 { t t { "password" "secret" } }
248 [ hpack-context new { "password" "secret" } encode-field
249 hpack-context new swap 0 decode-field
250 [ [ = ] [ swap length = ] 2bi* ] dip ! check contexts are the same and the entire block used for decoding
253 { t t { ":method" "GET" } }
254 [ hpack-context new { ":method" "GET" } encode-field
255 hpack-context new swap 0 decode-field
256 [ [ = ] [ swap length = ] 2bi* ] dip ! check contexts are the same and the entire block used for decoding
260 ! many header encoding check, using same values from RFC7541 Appendix C.3 and C.5
262 { { ":method" "GET" } { ":scheme" "http" }
263 { ":path" "/" } { ":authority" "www.example.com" } }
264 { { ":method" "GET" } { ":scheme" "http" }
265 { ":path" "/" } { ":authority" "www.example.com" }
266 { "cache-control" "no-cache" } }
267 { { ":method" "GET" } { ":scheme" "https" }
268 { ":path" "/index.html" } { ":authority" "www.example.com" }
269 { "custom-key" "custom-value" } }
272 [ hpack-context new c31h c32h c33h [ hpack-encode swap ] tri@
273 [ [ hpack-context new ] 3dip [ hpack-decode swap ] tri@ ] dip
274 = ! check that the encode and decode contexts are identical
280 { "cache-control" "private" }
281 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
282 { "location" "https://www.example.com" }
286 { "cache-control" "private" }
287 { "date" "Mon, 21 Oct 2013 20:13:21 GMT" }
288 { "location" "https://www.example.com" }
292 { "cache-control" "private" }
293 { "date" "Mon, 21 Oct 2013 20:13:22 GMT" }
294 { "location" "https://www.example.com" }
295 { "content-encoding" "gzip" }
296 { "set-cookie" "foo=ASDJKHQKBZXOQWEOPIUAXQWEOIU; max-age=3600; version=1" }
300 [ hpack-context new c51h c52h c53h [ hpack-encode swap ] tri@
301 [ [ hpack-context new ] 3dip [ hpack-decode swap ] tri@ ] dip
302 = ! check that the encode and decode contexts are identical