William Lallemand | 5bb21b1 | 2020-06-18 18:56:44 +0200 | [diff] [blame] | 1 | varnishtest "haproxy ACL, CLI and mCLI spaces" |
William Lallemand | 398c5f3 | 2020-06-18 18:52:18 +0200 | [diff] [blame] | 2 | feature ignore_unknown_macro |
| 3 | |
William Lallemand | 5bb21b1 | 2020-06-18 18:56:44 +0200 | [diff] [blame] | 4 | #REQUIRE_VERSION=2.0 |
William Lallemand | 398c5f3 | 2020-06-18 18:52:18 +0200 | [diff] [blame] | 5 | |
| 6 | server s1 { |
| 7 | rxreq |
| 8 | expect req.method == "GET" |
| 9 | txresp |
| 10 | } -repeat 2 -start |
| 11 | |
William Lallemand | 5bb21b1 | 2020-06-18 18:56:44 +0200 | [diff] [blame] | 12 | haproxy h1 -W -S -conf { |
William Lallemand | 398c5f3 | 2020-06-18 18:52:18 +0200 | [diff] [blame] | 13 | defaults |
| 14 | mode http |
William Lallemand | 398c5f3 | 2020-06-18 18:52:18 +0200 | [diff] [blame] | 15 | log global |
| 16 | option httplog |
Willy Tarreau | db522b5 | 2020-09-02 07:26:08 +0200 | [diff] [blame] | 17 | timeout connect 1s |
| 18 | timeout client 1s |
| 19 | timeout server 1s |
William Lallemand | 398c5f3 | 2020-06-18 18:52:18 +0200 | [diff] [blame] | 20 | |
| 21 | frontend fe1 |
| 22 | bind "fd@${fe1}" |
| 23 | |
| 24 | http-request deny if { req.hdr(user-agent) -i -m str -f ${testdir}/agents.acl } |
| 25 | |
| 26 | default_backend be1 |
| 27 | |
| 28 | backend be1 |
| 29 | server s1 ${s1_addr}:${s1_port} |
| 30 | |
| 31 | } -start |
| 32 | |
| 33 | client c1 -connect ${h1_fe1_sock} { |
| 34 | txreq -hdr "User-Agent: Mon User Agent" |
| 35 | rxresp |
| 36 | expect resp.status == 200 |
| 37 | } -run |
| 38 | |
| 39 | haproxy h1 -cli { |
| 40 | send "add acl ${testdir}/agents.acl Mon\\ User\\ Agent\\;" |
| 41 | expect ~ .* |
| 42 | |
| 43 | send "show acl ${testdir}/agents.acl" |
| 44 | expect ~ ".*Mon User Agent.*" |
| 45 | } |
| 46 | |
| 47 | client c1 -connect ${h1_fe1_sock} { |
| 48 | txreq -hdr "User-Agent: Mon User Agent;" |
| 49 | rxresp |
| 50 | expect resp.status == 403 |
| 51 | } -run |
William Lallemand | 5bb21b1 | 2020-06-18 18:56:44 +0200 | [diff] [blame] | 52 | |
| 53 | |
| 54 | haproxy h1 -cli { |
| 55 | send "del acl ${testdir}/agents.acl Mon\\ User\\ Agent\\;" |
| 56 | expect ~ .* |
| 57 | |
| 58 | send "show acl ${testdir}/agents.acl" |
| 59 | expect ~ .* |
| 60 | } |
| 61 | |
| 62 | client c1 -connect ${h1_fe1_sock} { |
| 63 | txreq -hdr "User-Agent: Mon User Agent;" |
| 64 | rxresp |
| 65 | expect resp.status == 200 |
| 66 | } -run |
| 67 | |
| 68 | |
| 69 | # Try it with the master CLI |
| 70 | haproxy h1 -mcli { |
| 71 | send "@1 add acl ${testdir}/agents.acl Mon\\ User\\ Agent\\;;@1 show acl ${testdir}/agents.acl" |
| 72 | expect ~ ".*Mon User Agent;.*" |
| 73 | } |
| 74 | |
| 75 | client c1 -connect ${h1_fe1_sock} { |
| 76 | txreq -hdr "User-Agent: Mon User Agent;" |
| 77 | rxresp |
| 78 | expect resp.status == 403 |
| 79 | } -run |