blob: bb346dda7399bdf89dd6b54a21997aea987d993a [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 {
Willy Tarreaue1465c12021-05-09 14:41:41 +020010 global
11 # WT: limit false-positives causing "HTTP header incomplete" due to
12 # idle server connections being randomly used and randomly expiring
13 # under us.
14 tune.idle-pool.shared off
15
Christopher Faulet3820ff82021-02-26 12:23:17 +010016 defaults
17 mode http
18 timeout connect 1s
19 timeout client 1s
20 timeout server 1s
21
22 frontend fe1
23 bind "fd@${fe1}"
24 http-request set-src hdr(x-src)
25 http-request set-dst hdr(x-dst)
26 use_backend be1 if { path /req1 }
27 use_backend be2 if { path /req2 }
28 use_backend be3 if { path /req3 }
29 use_backend be4 if { path /req4 }
30 use_backend be5 if { path /req5 }
31
32 frontend fe2
33 bind "fd@${fe2}"
34 http-request return status 200 hdr x-ff "%[req.hdr(x-forwarded-for)]" hdr x-ot "%[req.hdr(x-original-to)]"
35
36 backend be1
37 option forwardfor except 127.0.0.1
38 option originalto except 127.0.0.1
39 server s1 ${h1_fe2_addr}:${h1_fe2_port}
40
41 backend be2
42 option forwardfor except 10.0.0.1/25
43 option originalto except 10.0.0.1/25
44 server s1 ${h1_fe2_addr}:${h1_fe2_port}
45
46 backend be3
47 option forwardfor except ::1
48 option originalto except ::1
49 server s1 ${h1_fe2_addr}:${h1_fe2_port}
50
51 backend be4
52 option forwardfor except 2001:db8::1:0:0:1
53 option originalto except 2001:db8::1:0:0:1
54 server s1 ${h1_fe2_addr}:${h1_fe2_port}
55
56 backend be5
57 option forwardfor except 2001:db8:1f89::/48
58 option originalto except 2001:db8:1f89::/48
59 server s1 ${h1_fe2_addr}:${h1_fe2_port}
60} -start
61
62client c1 -connect ${h1_fe1_sock} {
63 txreq -req GET -url /req1 \
64 -hdr "x-src: 127.0.0.1" \
65 -hdr "x-dst: 127.0.0.1"
66 rxresp
67 expect resp.status == 200
68 expect resp.http.x-ff == <undef>
69 expect resp.http.x-ot == <undef>
70
71 txreq -req GET -url /req1 \
72 -hdr "x-src: 127.0.0.2" \
73 -hdr "x-dst: 127.0.0.2"
74 rxresp
75 expect resp.status == 200
76 expect resp.http.x-ff == "127.0.0.2"
77 expect resp.http.x-ot == "127.0.0.2"
78
79
80 txreq -req GET -url /req2 \
81 -hdr "x-src: 10.0.0.1" \
82 -hdr "x-dst: 10.0.0.1"
83 rxresp
84 expect resp.status == 200
85 expect resp.http.x-ff == <undef>
86 expect resp.http.x-ot == <undef>
87
88 txreq -req GET -url /req2 \
89 -hdr "x-src: 10.0.0.128" \
90 -hdr "x-dst: 10.0.0.128"
91 rxresp
92 expect resp.status == 200
93 expect resp.http.x-ff == "10.0.0.128"
94 expect resp.http.x-ot == "10.0.0.128"
95
96 txreq -req GET -url /req3 \
97 -hdr "x-src: ::1" \
98 -hdr "x-dst: ::1"
99 rxresp
100 expect resp.status == 200
101 expect resp.http.x-ff == <undef>
102 expect resp.http.x-ot == <undef>
103
104 txreq -req GET -url /req3 \
105 -hdr "x-src: ::2" \
106 -hdr "x-dst: ::2"
107 rxresp
108 expect resp.status == 200
109 expect resp.http.x-ff == "::2"
110 expect resp.http.x-ot == "::2"
111
112 txreq -req GET -url /req4 \
113 -hdr "x-src: 2001:db8::1:0:0:1" \
114 -hdr "x-dst: 2001:db8::1:0:0:1"
115 rxresp
116 expect resp.status == 200
117 expect resp.http.x-ff == <undef>
118 expect resp.http.x-ot == <undef>
119
120 txreq -req GET -url /req4 \
121 -hdr "x-src: 2001:db8::1:0:0:2" \
122 -hdr "x-dst: 2001:db8::1:0:0:2"
123 rxresp
124 expect resp.status == 200
125 expect resp.http.x-ff == "2001:db8::1:0:0:2"
126 expect resp.http.x-ot == "2001:db8::1:0:0:2"
127
128 txreq -req GET -url /req5 \
129 -hdr "x-src: 2001:db8:1f89::1" \
130 -hdr "x-dst: 2001:db8:1f89::1"
131 rxresp
132 expect resp.status == 200
133 expect resp.http.x-ff == <undef>
134 expect resp.http.x-ot == <undef>
135
136 txreq -req GET -url /req5 \
137 -hdr "x-src: 2001:db8:1f90::1" \
138 -hdr "x-dst: 2001:db8:1f90::1"
139 rxresp
140 expect resp.status == 200
141 expect resp.http.x-ff == "2001:db8:1f90::1"
142 expect resp.http.x-ot == "2001:db8:1f90::1"
143} -run