blob: 019e32ecf15c41160e4f840284be9e246c2ff6f8 [file] [log] [blame]
Jarno Huuskonen3e5c7722019-01-09 13:44:44 +02001varnishtest "Minimal tests for 1.9 converters: ipmask,concat,strcmp,field,word"
2feature ignore_unknown_macro
3
4# concat,strcmp,ipmask(ipv6mask) need 1.9
5#REQUIRE_VERSION=1.9
6
7# ipmask tests server
8server s1 {
9 rxreq
10 expect req.method == "GET"
11 expect req.http.srciphdr == "192.168.1.101"
12 expect req.http.srcmask1 == "192.168.1.0"
13 expect req.http.srcmask2 == "192.168.0.0"
14 expect req.http.srcmask3 == "192.0.0.0"
15
16 expect req.http.test1mask128 == "2001:db8::1"
17 expect req.http.test2mask64 == "2001:db8::"
18 expect req.http.test2mask128 == "2001:db8::bad:c0f:ffff"
19 expect req.http.test2mask120 == "2001:db8::bad:c0f:ff00"
20 expect req.http.test2maskff00 == "2001:db8::bad:c0f:ff00"
21 expect req.http.test2maskfee0 == "2001:db8::bad:c0f:fee0"
22
23 expect req.http.test3mask64 == "2001:db8:c001:c01a::"
24 expect req.http.test3mask64v2 == "2001:db8:c001:c01a::"
25 expect req.http.test3mask64v3 == "2001:db8:c001:c01a::"
26 expect req.http.test3maskff == "2001:db8:c001:c01a:0:ffff:10:0"
27 expect req.http.test3maskv2 == "2001:db8:c001:c01a:c001:c001::"
28
29 expect req.http.test4mask32 == "192.168.1.101"
30
31 expect req.http.test5mask24 == "192.168.1.0"
32 expect req.http.test6mask24 == "192.168.1.0"
33 expect req.http.test6mask25 == "192.168.1.128"
34 txresp
35} -start
36
37# concat,strcmp,field,word tests server
38server s2 {
39 rxreq
40 expect req.method == "GET"
41 expect req.http.fieldconcat == "f1_f2_f3__f5"
42 expect req.http.fieldconcat2 == "f1_f2_f3__f5"
43 expect req.http.fieldconcat3 == "f1_f2_f3__f5"
44 expect req.http.fieldstrcmp == "0"
45
46 # field tests
47 expect req.http.fieldtest1 == "f5"
48 expect req.http.fieldtest2 == "f2_f3__f5"
49 expect req.http.fieldtest3 == "f2_f3"
50 expect req.http.fieldtest4 == "f2_f3_"
51 expect req.http.fieldtest5 == "f1_f2_f3"
52 expect req.http.okfieldtest == "ok"
53 expect req.http.qsfieldtest == "IT_IS"
54 expect req.http.qsfieldconcat == "IT_IS_ok"
55 expect req.http.fieldtest1strcmp == "0"
56
57 # word tests
58 expect req.http.wordtest1 == "f5"
59 expect req.http.wordtest2 == "f2_f3__f5"
60 expect req.http.wordtest3 == "f3__f5"
61 expect req.http.wordtest4 == "f1_f2_f3"
62 expect req.http.wordtest5 == "f1_f2"
63 expect req.http.okwordtest == "OK"
64 expect req.http.qswordtest == "Yes_It"
65 expect req.http.qswordregmtest == "It_Yes"
66 expect req.http.wordtest1strcmp == "0"
67 txresp
68} -start
69
70
71# ipmask tests with accept-proxy bind
72haproxy h1 -conf {
73 defaults
74 mode http
75 ${no-htx} option http-use-htx
76 log global
77 option httplog
78 timeout connect 15ms
79 timeout client 20ms
80 timeout server 20ms
81
82 frontend fe1
83 # accept-proxy so test client can send src ip
84 bind "fd@${fe1}" accept-proxy
85
86 # ipmask tests w/src
87 http-request set-header Srciphdr %[src]
88 http-request set-header Srcmask1 %[src,ipmask(24)] # 192.168.1.0
89 http-request set-header Srcmask2 %[src,ipmask(16)] # 192.168.0.0
90 http-request set-header Srcmask3 %[src,ipmask(8)] # 192.0.0.0
91
92 # ipmask tests from headers
93 http-request set-header Test1mask128 %[req.hdr_ip(Addr1),ipmask(24,128)]
94
95 http-request set-header Test2mask64 %[req.hdr_ip(Addr2),ipmask(24,64)]
96 http-request set-header Test2mask128 %[req.hdr_ip(Addr2),ipmask(24,128)]
97 http-request set-header Test2mask120 %[req.hdr_ip(Addr2),ipmask(24,120)]
98 http-request set-header Test2maskff00 %[req.hdr_ip(Addr2),ipmask(24,ffff:ffff:ffff:ffff:ffff:ffff:ffff:ff00)]
99 http-request set-header Test2maskfee0 %[req.hdr_ip(Addr2),ipmask(24,ffff:ffff:ffff:ffff:ffff:ffff:ffff:fee0)]
100
101 http-request set-header Test3mask64 %[req.hdr_ip(Addr3),ipmask(24,64)]
102 http-request set-header Test3mask64v2 %[req.hdr_ip(Addr3),ipmask(24,ffff:ffff:ffff:ffff:0:0:0:0)]
103 http-request set-header Test3mask64v3 %[req.hdr_ip(Addr3),ipmask(24,ffff:ffff:ffff:ffff::)]
104 http-request set-header Test3maskff %[req.hdr_ip(Addr3),ipmask(24,ffff:ffff:ffff:ffff:0:ffff:ffff:0)]
105 http-request set-header Test3maskv2 %[req.hdr_ip(Addr3),ipmask(24,ffff:ffff:ffff:ffff:c001:c001:0000:0000)]
106
107 # ipv4 mask applied to ipv4 mapped address
108 http-request set-header Test4mask32 %[req.hdr_ip(Addr4),ipmask(32,64)]
109
110 http-request set-header Test5mask24 %[req.hdr_ip(Addr5),ipmask(24)]
111
112 http-request set-header Test6mask24 %[req.hdr_ip(Addr6),ipmask(24)]
113 http-request set-header Test6mask25 %[req.hdr_ip(Addr6),ipmask(25)]
114
115 # track addr/mask in stick table
116 http-request track-sc0 src,ipmask(24) table be1
117 http-request track-sc1 hdr_ip(Addr4),ipmask(32) table be1
118 http-request track-sc2 hdr_ip(Addr3),ipmask(24,64) table be1
119
120 default_backend be1
121
122 backend be1
123 stick-table type ipv6 size 20 expire 360s store gpc0,conn_cnt
124 server s1 ${s1_addr}:${s1_port}
125} -start
126
127# concat,strcmp,word,field haproxy
128haproxy h2 -conf {
129 defaults
130 mode http
131 ${no-htx} option http-use-htx
132 log global
133 option httplog
134 timeout connect 15ms
135 timeout client 20ms
136 timeout server 20ms
137
138 frontend fe2
139 bind "fd@${fe2}"
140
141 # concat f1_f2 + _ + f3__f5 tests
142 http-request set-var(sess.field1) hdr(Field1)
143 http-request set-var(sess.field2) hdr(Field2)
144 http-request set-var(sess.fieldhdr) hdr(Fieldhdr)
145 http-request set-var(sess.fieldconcat) hdr(Field1),concat(_,sess.field2,)
146 http-request set-header Fieldconcat2 %[var(sess.field1),concat(_,sess.field2,)]
147 http-request set-header Fieldconcat3 %[hdr(Field1),concat(_,sess.field2,)]
148 http-request set-header Fieldconcat %[var(sess.fieldconcat)]
149 http-request set-header Fieldstrcmp %[hdr(Fieldhdr),strcmp(sess.fieldconcat)]
150 http-request deny unless { hdr(Fieldhdr),strcmp(sess.fieldconcat) eq 0 }
151
152 # field tests
153 http-request set-header Fieldtest1 %[hdr(Fieldhdr),field(5,_)] #f5
154 http-request set-var(sess.fieldtest1var) hdr(Fieldtest1)
155 http-request set-var(sess.okfield) path,lower,field(4,/,1) #ok
156 http-request set-header Okfieldtest %[var(sess.okfield)] #ok
157 http-request set-var(sess.qsfield) url_param(qs),upper,field(2,_,2) #IT_IS
158 http-request set-header Qsfieldtest %[var(sess.qsfield)] #IT_IS
159 http-request set-header Qsfieldconcat %[var(sess.qsfield),concat(_,sess.okfield,)] #IT_IS_ok
160 http-request set-header Fieldtest2 %[var(sess.fieldhdr),field(2,_,0)] #f2_f3__f5
161 http-request set-header Fieldtest3 %[var(sess.fieldconcat),field(2,_,2)] #f2_f3
162 http-request set-header Fieldtest4 %[hdr(Fieldconcat2),field(-2,_,3)] #f2_f3_
163 http-request set-header Fieldtest5 %[hdr(Fieldconcat3),field(-3,_,0)] #f1_f2_f3
164 http-request set-header Fieldtest1strcmp %[str(f5),strcmp(sess.fieldtest1var)]
165 http-request deny unless { str(f5),strcmp(sess.fieldtest1var) eq 0 }
166 http-request deny unless { str(ok),strcmp(sess.okfield) eq 0 }
167 http-request deny unless { str(IT_IS),strcmp(sess.qsfield) eq 0 }
168
169 # word tests
170 http-request set-header Wordtest1 %[hdr(Fieldhdr),word(4,_)] #f5
171 http-request set-var(sess.wordtest1var) hdr(Wordtest1)
172 http-request set-var(sess.okword) path,upper,word(3,/,1) #OK
173 http-request set-header Okwordtest %[var(sess.okword)] #OK
174 http-request set-var(sess.qsword) url_param(qs),word(1,_,2) #Yes_It
175 http-request set-header Qswordtest %[var(sess.qsword)] #Yes_It
176 http-request set-header Qswordregmtest %[var(sess.qsword),map_regm(${testdir}/h00002.map)] #It_Yes
177 http-request set-header Wordtest2 %[var(sess.fieldhdr),word(2,_,0)] #f2_f3__f5
178 http-request set-header Wordtest3 %[var(sess.fieldconcat),word(3,_,2)] #f3__f5
179 http-request set-header Wordtest4 %[hdr(Fieldconcat2),word(-2,_,3)] #f1_f2_f3
180 http-request set-header Wordtest5 %[hdr(Fieldconcat3),word(-3,_,0)] #f1_f2
181 http-request set-header Wordtest1strcmp %[str(f5),strcmp(sess.wordtest1var)]
182 http-request deny unless { str(f5),strcmp(sess.wordtest1var) eq 0 }
183 http-request deny unless { str(OK),strcmp(sess.okword) eq 0 }
184 http-request deny unless { str(Yes_It),strcmp(sess.qsword) eq 0 }
185
186 default_backend be2
187
188 backend be2
189 server s2 ${s2_addr}:${s2_port}
190} -start
191
192# ipmask tests
193client c1 -connect ${h1_fe1_sock} -proxy2 "192.168.1.101:1234 127.0.0.1:2345" {
194 txreq -hdr "Addr1: 2001:db8::1" \
195 -hdr "Addr2: 2001:db8::bad:c0f:ffff" \
196 -hdr "Addr3: 2001:db8:c001:c01a:ffff:ffff:10:ffff" \
197 -hdr "Addr4: ::FFFF:192.168.1.101" \
198 -hdr "Addr5: 192.168.1.2" \
199 -hdr "Addr6: 192.168.1.255"
200 rxresp
201 expect resp.status == 200
202} -run
203
204# cli show be1 stick table
205haproxy h1 -cli {
206 send "show table be1"
207 expect ~ "^# table: be1, type: ipv6, size:20, used:3\\n0x[a-f0-9]+: key=::ffff:192\\.168\\.1\\.0 use=0 exp=[[:digit:]]+ gpc0=0 conn_cnt=1\\n0x[a-f0-9]+: key=::ffff:192\\.168\\.1\\.101 use=0 exp=[[:digit:]]+ gpc0=0 conn_cnt=1\\n0x[a-f0-9]+: key=2001:db8:c001:c01a:: use=0 exp=[[:digit:]]+ gpc0=0 conn_cnt=1\\n"
208}
209
210# concat,strcmp,word,field tests
211client c2 -connect ${h2_fe2_sock} {
212 txreq -req GET \
213 -url /is/this/Ok/or/not?qs=Yes_It_Is \
214 -hdr "Fieldhdr: f1_f2_f3__f5" \
215 -hdr "Field1: f1_f2" \
216 -hdr "Field2: f3__f5"
217 rxresp
218 expect resp.status == 200
219} -run
220