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 |
| 15 | ${no-htx} option http-use-htx |
| 16 | log global |
| 17 | option httplog |
| 18 | timeout connect 15ms |
| 19 | timeout client 20ms |
| 20 | timeout server 20ms |
| 21 | |
| 22 | frontend fe1 |
| 23 | bind "fd@${fe1}" |
| 24 | |
| 25 | http-request deny if { req.hdr(user-agent) -i -m str -f ${testdir}/agents.acl } |
| 26 | |
| 27 | default_backend be1 |
| 28 | |
| 29 | backend be1 |
| 30 | server s1 ${s1_addr}:${s1_port} |
| 31 | |
| 32 | } -start |
| 33 | |
| 34 | client c1 -connect ${h1_fe1_sock} { |
| 35 | txreq -hdr "User-Agent: Mon User Agent" |
| 36 | rxresp |
| 37 | expect resp.status == 200 |
| 38 | } -run |
| 39 | |
| 40 | haproxy h1 -cli { |
| 41 | send "add acl ${testdir}/agents.acl Mon\\ User\\ Agent\\;" |
| 42 | expect ~ .* |
| 43 | |
| 44 | send "show acl ${testdir}/agents.acl" |
| 45 | expect ~ ".*Mon User Agent.*" |
| 46 | } |
| 47 | |
| 48 | client c1 -connect ${h1_fe1_sock} { |
| 49 | txreq -hdr "User-Agent: Mon User Agent;" |
| 50 | rxresp |
| 51 | expect resp.status == 403 |
| 52 | } -run |
William Lallemand | 5bb21b1 | 2020-06-18 18:56:44 +0200 | [diff] [blame] | 53 | |
| 54 | |
| 55 | haproxy h1 -cli { |
| 56 | send "del acl ${testdir}/agents.acl Mon\\ User\\ Agent\\;" |
| 57 | expect ~ .* |
| 58 | |
| 59 | send "show acl ${testdir}/agents.acl" |
| 60 | expect ~ .* |
| 61 | } |
| 62 | |
| 63 | client c1 -connect ${h1_fe1_sock} { |
| 64 | txreq -hdr "User-Agent: Mon User Agent;" |
| 65 | rxresp |
| 66 | expect resp.status == 200 |
| 67 | } -run |
| 68 | |
| 69 | |
| 70 | # Try it with the master CLI |
| 71 | haproxy h1 -mcli { |
| 72 | send "@1 add acl ${testdir}/agents.acl Mon\\ User\\ Agent\\;;@1 show acl ${testdir}/agents.acl" |
| 73 | expect ~ ".*Mon User Agent;.*" |
| 74 | } |
| 75 | |
| 76 | client c1 -connect ${h1_fe1_sock} { |
| 77 | txreq -hdr "User-Agent: Mon User Agent;" |
| 78 | rxresp |
| 79 | expect resp.status == 403 |
| 80 | } -run |