blob: 31f8820ba1aecca150bc577bb1c68f19ca1cc60c [file] [log] [blame]
Gaetan Rivet9dcb09f2020-02-07 15:37:17 +01001varnishtest "tcp-check expect rule with capture groups"
2#EXCLUDE_TARGETS=freebsd,osx,generic
3#REQUIRE_VERSION=2.2
4#REGTEST_TYPE=slow
5# This script tests expect rules matching a regex with capture groups and
6# defining a comment with backreferences. Text and binary regex are tested.
7feature ignore_unknown_macro
8
9syslog S1 -level notice {
10 recv
11 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be1 started."
12 recv
13 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be1/srv1 failed.*code=400 reason=Bad Request"
14} -start
15
16syslog S2 -level notice {
17 recv
18 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Proxy be2 started."
19 recv
20 expect ~ "[^:\\[ ]\\[${h1_pid}\\]: Health check for server be2/srv1 failed.*code=400 reason=Bad Request"
21} -start
22
23server s1 {
24 rxreq
25 txresp -status 400 -reason "Bad Request"
26} -start
27
28server s2 {
29 rxreq
30 txresp -status 400 -reason "Bad Request"
31} -start
32
33haproxy h1 -conf {
34 defaults
35 timeout client 5s
36 timeout connect 5s
37 timeout server 5s
38 timeout check 5s
39
40 backend be1
41 log ${S1_addr}:${S1_port} len 2048 local0
42 option tcp-check
43 option log-health-checks
44 tcp-check connect
45 tcp-check send "GET / HTTP/1.1\r\n\r\n"
46 tcp-check expect !rstring "HTTP/1\\.1\s+([45][0-9]{2})\s+([^\r\n]*)" comment " Bad response: code=\\1 reason=\\2"
47 server srv1 ${s1_addr}:${s1_port} check inter 1000ms rise 1 fall 1
48
49 backend be2
50 log ${S2_addr}:${S2_port} len 2048 local0
51 option tcp-check
52 option log-health-checks
53 tcp-check connect
54 tcp-check send-binary "474554202f20485454502f312e31200d0a0d0a" # GET / HTTP/1.1\r\n\r\n
55 tcp-check expect !rbinary "485454502F312E3120(34[0-9]{4}|35[0-9]{4})20(([^0].)*)" comment " Bad response: code=\\1 reason=\\2"
56 server srv1 ${s2_addr}:${s2_port} check inter 1000ms rise 1 fall 1
57} -start
58
59syslog S1 -wait
60syslog S2 -wait