Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 1 | varnishtest "Lua: set_var" |
Christopher Faulet | 80f59e5 | 2020-05-26 11:11:23 +0200 | [diff] [blame] | 2 | #REQUIRE_VERSION=2.2 |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 3 | #REQUIRE_OPTIONS=LUA |
| 4 | |
| 5 | feature ignore_unknown_macro |
| 6 | |
| 7 | haproxy h1 -conf { |
| 8 | global |
Willy Tarreau | e1465c1 | 2021-05-09 14:41:41 +0200 | [diff] [blame] | 9 | # 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 Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 15 | lua-load ${testdir}/set_var.lua |
| 16 | |
| 17 | frontend fe1 |
| 18 | mode http |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 19 | bind "fd@${fe1}" |
| 20 | |
| 21 | http-request use-service lua.set_var |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 22 | |
| 23 | frontend fe2 |
| 24 | mode http |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 25 | bind "fd@${fe2}" |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 26 | # just make sure the variable exists |
| 27 | http-request set-header Dummy %[var(proc.fe2_foo)] |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 28 | |
| 29 | http-request use-service lua.set_var_ifexist |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 30 | } -start |
| 31 | |
| 32 | client c0 -connect ${h1_fe1_sock} { |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 33 | # create var |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 34 | txreq -url "/" \ |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 35 | -hdr "Var: txn.fe1_foo" |
Tim Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 36 | rxresp |
| 37 | expect resp.status == 202 |
| 38 | expect resp.http.echo == "value" |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 39 | |
| 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 Duesterhus | 84ebc13 | 2020-05-19 13:49:41 +0200 | [diff] [blame] | 55 | txreq -url "/" \ |
| 56 | -hdr "Var: invalid.var" |
| 57 | rxresp |
| 58 | expect resp.status == 400 |
| 59 | expect resp.http.echo == "(nil)" |
| 60 | } -run |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 61 | |
| 62 | client c1 -connect ${h1_fe2_sock} { |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 63 | # this one exists in the conf, it must succeed |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 64 | txreq -url "/" \ |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 65 | -hdr "Var: proc.fe2_foo" |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 66 | rxresp |
| 67 | expect resp.status == 202 |
| 68 | expect resp.http.echo == "value" |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 69 | |
| 70 | # this one does not exist in the conf, it must fail |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 71 | txreq -url "/" \ |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 72 | -hdr "Var: proc.fe2_bar" |
Tim Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 73 | rxresp |
| 74 | expect resp.status == 400 |
| 75 | expect resp.http.echo == "(nil)" |
Willy Tarreau | 3a4bedc | 2021-08-31 08:51:02 +0200 | [diff] [blame] | 76 | |
| 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 Duesterhus | 4e172c9 | 2020-05-19 13:49:42 +0200 | [diff] [blame] | 83 | } -run |