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