blob: 942c4e2cb817727af6bff8c0d289541644fa5a8d [file] [log] [blame]
Christopher Faulet3820ff82021-02-26 12:23:17 +01001varnishtest "Test IPv4/IPv6 except param for the forwardfor and originalto options"
2#REQUIRE_VERSION=2.4
3
4# This config tests the except parameter for the HTTP forwardfor and originalto
5# options.
6
7feature ignore_unknown_macro
8
9haproxy h1 -conf {
10 defaults
11 mode http
12 timeout connect 1s
13 timeout client 1s
14 timeout server 1s
15
16 frontend fe1
17 bind "fd@${fe1}"
18 http-request set-src hdr(x-src)
19 http-request set-dst hdr(x-dst)
20 use_backend be1 if { path /req1 }
21 use_backend be2 if { path /req2 }
22 use_backend be3 if { path /req3 }
23 use_backend be4 if { path /req4 }
24 use_backend be5 if { path /req5 }
25
26 frontend fe2
27 bind "fd@${fe2}"
28 http-request return status 200 hdr x-ff "%[req.hdr(x-forwarded-for)]" hdr x-ot "%[req.hdr(x-original-to)]"
29
30 backend be1
31 option forwardfor except 127.0.0.1
32 option originalto except 127.0.0.1
33 server s1 ${h1_fe2_addr}:${h1_fe2_port}
34
35 backend be2
36 option forwardfor except 10.0.0.1/25
37 option originalto except 10.0.0.1/25
38 server s1 ${h1_fe2_addr}:${h1_fe2_port}
39
40 backend be3
41 option forwardfor except ::1
42 option originalto except ::1
43 server s1 ${h1_fe2_addr}:${h1_fe2_port}
44
45 backend be4
46 option forwardfor except 2001:db8::1:0:0:1
47 option originalto except 2001:db8::1:0:0:1
48 server s1 ${h1_fe2_addr}:${h1_fe2_port}
49
50 backend be5
51 option forwardfor except 2001:db8:1f89::/48
52 option originalto except 2001:db8:1f89::/48
53 server s1 ${h1_fe2_addr}:${h1_fe2_port}
54} -start
55
56client c1 -connect ${h1_fe1_sock} {
57 txreq -req GET -url /req1 \
58 -hdr "x-src: 127.0.0.1" \
59 -hdr "x-dst: 127.0.0.1"
60 rxresp
61 expect resp.status == 200
62 expect resp.http.x-ff == <undef>
63 expect resp.http.x-ot == <undef>
64
65 txreq -req GET -url /req1 \
66 -hdr "x-src: 127.0.0.2" \
67 -hdr "x-dst: 127.0.0.2"
68 rxresp
69 expect resp.status == 200
70 expect resp.http.x-ff == "127.0.0.2"
71 expect resp.http.x-ot == "127.0.0.2"
72
73
74 txreq -req GET -url /req2 \
75 -hdr "x-src: 10.0.0.1" \
76 -hdr "x-dst: 10.0.0.1"
77 rxresp
78 expect resp.status == 200
79 expect resp.http.x-ff == <undef>
80 expect resp.http.x-ot == <undef>
81
82 txreq -req GET -url /req2 \
83 -hdr "x-src: 10.0.0.128" \
84 -hdr "x-dst: 10.0.0.128"
85 rxresp
86 expect resp.status == 200
87 expect resp.http.x-ff == "10.0.0.128"
88 expect resp.http.x-ot == "10.0.0.128"
89
90 txreq -req GET -url /req3 \
91 -hdr "x-src: ::1" \
92 -hdr "x-dst: ::1"
93 rxresp
94 expect resp.status == 200
95 expect resp.http.x-ff == <undef>
96 expect resp.http.x-ot == <undef>
97
98 txreq -req GET -url /req3 \
99 -hdr "x-src: ::2" \
100 -hdr "x-dst: ::2"
101 rxresp
102 expect resp.status == 200
103 expect resp.http.x-ff == "::2"
104 expect resp.http.x-ot == "::2"
105
106 txreq -req GET -url /req4 \
107 -hdr "x-src: 2001:db8::1:0:0:1" \
108 -hdr "x-dst: 2001:db8::1:0:0:1"
109 rxresp
110 expect resp.status == 200
111 expect resp.http.x-ff == <undef>
112 expect resp.http.x-ot == <undef>
113
114 txreq -req GET -url /req4 \
115 -hdr "x-src: 2001:db8::1:0:0:2" \
116 -hdr "x-dst: 2001:db8::1:0:0:2"
117 rxresp
118 expect resp.status == 200
119 expect resp.http.x-ff == "2001:db8::1:0:0:2"
120 expect resp.http.x-ot == "2001:db8::1:0:0:2"
121
122 txreq -req GET -url /req5 \
123 -hdr "x-src: 2001:db8:1f89::1" \
124 -hdr "x-dst: 2001:db8:1f89::1"
125 rxresp
126 expect resp.status == 200
127 expect resp.http.x-ff == <undef>
128 expect resp.http.x-ot == <undef>
129
130 txreq -req GET -url /req5 \
131 -hdr "x-src: 2001:db8:1f90::1" \
132 -hdr "x-dst: 2001:db8:1f90::1"
133 rxresp
134 expect resp.status == 200
135 expect resp.http.x-ff == "2001:db8:1f90::1"
136 expect resp.http.x-ot == "2001:db8:1f90::1"
137} -run