blob: 0e6e66e4c3f5d34d6f54b83115986a1c84e0969f [file] [log] [blame]
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +02001#commit 271022150d7961b9aa39dbfd88e0c6a4bc48c3ee
2# BUG/MINOR: map: fix map_regm with backref
3#
4# Due to a cascade of get_trash_chunk calls the sample is
5# corrupted when we want to read it.
6#
7# The fix consist to use a temporary chunk to copy the sample
8# value and use it.
9
10varnishtest "map_regm get_trash_chunk test"
11feature ignore_unknown_macro
12
Willy Tarreau73cc5452020-09-29 11:00:51 +020013#REQUIRE_VERSION=1.7
Frédéric Lécailledc1a3bd2019-03-29 15:07:24 +010014#REGTEST_TYPE=bug
15
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020016syslog S1 -level notice {
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020017 recv info
18 # not expecting ${h1_pid} with master-worker
19 expect ~ "[^:\\[ ]\\[[[:digit:]]+\\]: .* fe1 be1/s1 [[:digit:]]+/[[:digit:]]+/[[:digit:]]+/[[:digit:]]+/[[:digit:]]+ 200 [[:digit:]]+ - - ---- .* \"GET / HTTP/(1|2)(\\.1)?\""
20} -start
21
22server s1 {
23 rxreq
24 expect req.method == "GET"
25 expect req.http.x-mapped-from-header == example_AND_org
26 expect req.http.x-mapped-from-var == example_AND_org
27 txresp
28
29 rxreq
30 expect req.method == "GET"
31 expect req.http.x-mapped-from-header == www.example_AND_org
32 expect req.http.x-mapped-from-var == www.example_AND_org
33 txresp
34} -start
35
36haproxy h1 -conf {
37 global
38 log ${S1_addr}:${S1_port} local0 debug err
39
40 defaults
41 mode http
42 ${no-htx} option http-use-htx
43 log global
44 option httplog
Willy Tarreaudb522b52020-09-02 07:26:08 +020045 timeout connect 1s
46 timeout client 1s
47 timeout server 1s
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020048
49 frontend fe1
50 bind "fd@${fe1}"
51 # Remove port from Host header
52 http-request replace-value Host '(.*):.*' '\1'
53 # Store host header in variable
54 http-request set-var(txn.host) req.hdr(Host)
55 # This works correctly
Frédéric Lécailleb894f922019-03-29 16:13:48 +010056 http-request set-header X-Mapped-From-Header %[req.hdr(Host),map_regm(${testdir}/map_regm_with_backref.map,"unknown")]
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020057 # This breaks before commit 271022150d7961b9aa39dbfd88e0c6a4bc48c3ee
Frédéric Lécailleb894f922019-03-29 16:13:48 +010058 http-request set-header X-Mapped-From-Var %[var(txn.host),map_regm(${testdir}/map_regm_with_backref.map,"unknown")]
Jarno Huuskonen3f0f5782019-01-09 13:41:19 +020059
60 default_backend be1
61
62 backend be1
63 server s1 ${s1_addr}:${s1_port}
64} -start
65
66client c1 -connect ${h1_fe1_sock} {
67 txreq -hdr "Host: example.org:8443"
68 rxresp
69 expect resp.status == 200
70
71 txreq -hdr "Host: www.example.org"
72 rxresp
73 expect resp.status == 200
74} -run
75