fwknop: init script improvements
[feed/packages.git] / net / haproxy / patches / 020-REGTEST-add-sample_fetches-hashes-vtc-to-validate-hashes.patch
1 commit 2a8ac8c1000ffe0e2e874146aed012409a0ce251
2 Author: Willy Tarreau <w@1wt.eu>
3 Date: Wed Jan 15 11:31:01 2020 +0100
4
5 REGTEST: add sample_fetches/hashes.vtc to validate hashes
6
7 This regtest validates all hashes that we support, on all input bytes from
8 0x00 to 0xFF. Those supporting avalanche are tested as well. It also tests
9 len(), hex() and base64(). It purposely does not enable sha2() because this
10 one relies on OpenSSL and there's no point in validating that OpenSSL knows
11 how to hash, what matters is that we can test our hashing functions in all
12 cases. However since the tests were written, they're still present and
13 commented out in case that helps.
14
15 It may be backported to supported versions, possibly dropping a few algos
16 that were not supported (e.g. crc32c requires 1.9 minimum).
17
18 Note that this test will fail on crc32/djb2/sdbm/wt6 unless patches
19 "BUG/MINOR: stream: init variables when the list is empty" and
20 "BUG/MAJOR: hashes: fix the signedness of the hash inputs" are included.
21
22 (cherry picked from commit ec9ac54982841d49859747f6a535bf7444284bc3)
23 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
24
25 diff --git a/reg-tests/sample_fetches/hashes.vtc b/reg-tests/sample_fetches/hashes.vtc
26 new file mode 100644
27 index 000000000..874f81e41
28 --- /dev/null
29 +++ b/reg-tests/sample_fetches/hashes.vtc
30 @@ -0,0 +1,97 @@
31 +varnishtest "Hash validity test"
32 +
33 +#REQUIRE_VERSION=1.9
34 +
35 +feature ignore_unknown_macro
36 +
37 +server s1 {
38 + rxreq
39 + txresp
40 +} -start
41 +
42 +haproxy h1 -conf {
43 + defaults
44 + mode http
45 + timeout connect 1s
46 + timeout client 1s
47 + timeout server 1s
48 +
49 + frontend fe
50 + bind "fd@${fe}"
51 +
52 + # base64 encoding of \x00\x01\x02...\xFF
53 + http-response set-var(res.key) "str(AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==),b64dec"
54 +
55 + # length (start:0, next:255)
56 + http-response set-header x-len0 "%[var(res.key),length]"
57 + http-response set-header x-len1 "%[var(res.key),bytes(1),length]"
58 +
59 + # text-based encoding
60 + http-response set-header x-hex "%[var(res.key),hex]"
61 + http-response set-header x-b64 "%[var(res.key),base64]"
62 +
63 + # SHA family
64 + http-response set-header x-sha1 "%[var(res.key),sha1,hex]"
65 + #http-response set-header x-sha2 "%[var(res.key),sha2,hex]"
66 + #http-response set-header x-sha2-224 "%[var(res.key),sha2(224),hex]"
67 + #http-response set-header x-sha2-256 "%[var(res.key),sha2(256),hex]"
68 + #http-response set-header x-sha2-384 "%[var(res.key),sha2(384),hex]"
69 + #http-response set-header x-sha2-512 "%[var(res.key),sha2(512),hex]"
70 +
71 + # 32-bit hashes, and their avalanche variants
72 + http-response set-header x-crc32 "%[var(res.key),crc32]"
73 + http-response set-header x-crc32-1 "%[var(res.key),crc32(1)]"
74 +
75 + http-response set-header x-crc32c "%[var(res.key),crc32c]"
76 + http-response set-header x-crc32c-1 "%[var(res.key),crc32c(1)]"
77 +
78 + http-response set-header x-djb2 "%[var(res.key),djb2]"
79 + http-response set-header x-djb2-1 "%[var(res.key),djb2(1)]"
80 +
81 + http-response set-header x-sdbm "%[var(res.key),sdbm]"
82 + http-response set-header x-sdbm-1 "%[var(res.key),sdbm(1)]"
83 +
84 + http-response set-header x-wt6 "%[var(res.key),wt6]"
85 + http-response set-header x-wt6-1 "%[var(res.key),wt6(1)]"
86 +
87 + # 32/64-bit hashes, with seed variant
88 + http-response set-header x-xxh32 "%[var(res.key),xxh32]"
89 + http-response set-header x-xxh32-1 "%[var(res.key),xxh32(1)]"
90 + http-response set-header x-xxh64 "%[var(res.key),xxh64]"
91 + http-response set-header x-xxh64-1 "%[var(res.key),xxh64(1)]"
92 + default_backend be
93 +
94 + backend be
95 + server srv1 ${s1_addr}:${s1_port}
96 +} -start
97 +
98 +client c1 -connect ${h1_fe_sock} {
99 + txreq -url "/"
100 + rxresp
101 + expect resp.status == 200
102 + expect resp.http.x-len0 == "0"
103 + expect resp.http.x-len1 == "255"
104 + expect resp.http.x-hex == "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF"
105 + expect resp.http.x-b64 == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w=="
106 +
107 + expect resp.http.x-sha1 == "4916D6BDB7F78E6803698CAB32D1586EA457DFC8"
108 + #expect resp.http.x-sha2 == "40AFF2E9D2D8922E47AFD4648E6967497158785FBD1DA870E7110266BF944880"
109 + #expect resp.http.x-sha2-224 == "88702E63237824C4EB0D0FCFE41469A462493E8BEB2A75BBE5981734"
110 + #expect resp.http.x-sha2-256 == "40AFF2E9D2D8922E47AFD4648E6967497158785FBD1DA870E7110266BF944880"
111 + #expect resp.http.x-sha2-384 == "FFDAEBFF65ED05CF400F0221C4CCFB4B2104FB6A51F87E40BE6C4309386BFDEC2892E9179B34632331A59592737DB5C5"
112 + #expect resp.http.x-sha2-512 == "1E7B80BC8EDC552C8FEEB2780E111477E5BC70465FAC1A77B29B35980C3F0CE4A036A6C9462036824BD56801E62AF7E9FEBA5C22ED8A5AF877BF7DE117DCAC6D"
113 + expect resp.http.x-crc32 == "688229491"
114 + expect resp.http.x-crc32-1 == "4230317029"
115 + expect resp.http.x-crc32c == "2621708363"
116 + expect resp.http.x-crc32c-1 == "2242979626"
117 + expect resp.http.x-djb2 == "2589693061"
118 + expect resp.http.x-djb2-1 == "600622701"
119 + expect resp.http.x-sdbm == "905707648"
120 + expect resp.http.x-sdbm-1 == "3103804144"
121 + expect resp.http.x-wt6 == "4090277559"
122 + expect resp.http.x-wt6-1 == "1192658767"
123 + expect resp.http.x-xxh32 == "1497633363"
124 + expect resp.http.x-xxh32-1 == "1070421674"
125 + expect resp.http.x-xxh64 == "2282408585429094475"
126 + expect resp.http.x-xxh64-1 == "-4689339368900765961"
127 +} -run