blob: 0c8a4b162f8fdf1ccfbcbf62ec4a9952d6912865 [file] [log] [blame]
Tim Duesterhus84ebc132020-05-19 13:49:41 +02001varnishtest "Lua: set_var"
Christopher Faulet80f59e52020-05-26 11:11:23 +02002#REQUIRE_VERSION=2.2
Tim Duesterhus84ebc132020-05-19 13:49:41 +02003#REQUIRE_OPTIONS=LUA
4
5feature ignore_unknown_macro
6
7haproxy h1 -conf {
8 global
Willy Tarreaue1465c12021-05-09 14:41:41 +02009 # WT: limit false-positives causing "HTTP header incomplete" due to
10 # idle server connections being randomly used and randomly expiring
11 # under us.
12 tune.idle-pool.shared off
13
14 global
Tim Duesterhus84ebc132020-05-19 13:49:41 +020015 lua-load ${testdir}/set_var.lua
16
17 frontend fe1
18 mode http
Tim Duesterhus84ebc132020-05-19 13:49:41 +020019 bind "fd@${fe1}"
20
21 http-request use-service lua.set_var
Tim Duesterhus4e172c92020-05-19 13:49:42 +020022
23 frontend fe2
24 mode http
Tim Duesterhus4e172c92020-05-19 13:49:42 +020025 bind "fd@${fe2}"
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020026 # just make sure the variable exists
27 http-request set-header Dummy %[var(proc.fe2_foo)]
Tim Duesterhus4e172c92020-05-19 13:49:42 +020028
29 http-request use-service lua.set_var_ifexist
Tim Duesterhus84ebc132020-05-19 13:49:41 +020030} -start
31
32client c0 -connect ${h1_fe1_sock} {
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020033 # create var
Tim Duesterhus84ebc132020-05-19 13:49:41 +020034 txreq -url "/" \
Tim Duesterhus4e172c92020-05-19 13:49:42 +020035 -hdr "Var: txn.fe1_foo"
Tim Duesterhus84ebc132020-05-19 13:49:41 +020036 rxresp
37 expect resp.status == 202
38 expect resp.http.echo == "value"
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020039
40 # rewrite var
41 txreq -url "/" \
42 -hdr "Var: txn.fe1_foo"
43 rxresp
44 expect resp.status == 202
45 expect resp.http.echo == "value"
46
47 # create var under scope "proc"
48 txreq -url "/" \
49 -hdr "Var: proc.fe1_foo"
50 rxresp
51 expect resp.status == 202
52 expect resp.http.echo == "value"
53
54 # fail to create bad scope
Tim Duesterhus84ebc132020-05-19 13:49:41 +020055 txreq -url "/" \
56 -hdr "Var: invalid.var"
57 rxresp
58 expect resp.status == 400
59 expect resp.http.echo == "(nil)"
60} -run
Tim Duesterhus4e172c92020-05-19 13:49:42 +020061
62client c1 -connect ${h1_fe2_sock} {
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020063 # this one exists in the conf, it must succeed
Tim Duesterhus4e172c92020-05-19 13:49:42 +020064 txreq -url "/" \
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020065 -hdr "Var: proc.fe2_foo"
Tim Duesterhus4e172c92020-05-19 13:49:42 +020066 rxresp
67 expect resp.status == 202
68 expect resp.http.echo == "value"
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020069
70 # this one does not exist in the conf, it must fail
Tim Duesterhus4e172c92020-05-19 13:49:42 +020071 txreq -url "/" \
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020072 -hdr "Var: proc.fe2_bar"
Tim Duesterhus4e172c92020-05-19 13:49:42 +020073 rxresp
74 expect resp.status == 400
75 expect resp.http.echo == "(nil)"
Willy Tarreau3a4bedc2021-08-31 08:51:02 +020076
77 # this one is under txn, it must succeed
78 txreq -url "/" \
79 -hdr "Var: txn.fe2_foo"
80 rxresp
81 expect resp.status == 202
82 expect resp.http.echo == "value"
Tim Duesterhus4e172c92020-05-19 13:49:42 +020083} -run