blob: 811d9db634d96c8ed8222176e4aeaaa780ba6edf [file] [log] [blame]
Amaury Denoyelle69352ec2021-10-18 14:40:29 +02001# This reg-test checks websocket support in regards with the server keyword
2# 'ws'
3
4varnishtest "h2 backend websocket management via server keyword"
5
6feature ignore_unknown_macro
7
8#REQUIRE_VERSION=2.4
9#REQUIRE_OPTION=OPENSSL
10
11# haproxy server
12haproxy hapsrv -conf {
13 defaults
14 mode http
15 timeout connect 5s
16 timeout client 5s
17 timeout server 5s
18
19 frontend fe
20 bind "fd@${fe}"
21 bind "fd@${fessl}" ssl crt ${testdir}/common.pem alpn h2,http/1.1
22 capture request header sec-websocket-key len 128
23 http-request set-var(txn.ver) req.ver
24 use_backend be
25
26 backend be
27 # define websocket ACL
28 acl ws_handshake hdr(upgrade) -m str websocket
29
30 # handle non-ws streams
31 http-request return status 200 if !ws_handshake
32
33 # handle ws streams
34 #capture request header sec-websocket-key len 128
35 http-request return status 200 hdr connection upgrade hdr upgrade websocket hdr sec-websocket-accept "%[capture.req.hdr(0),concat(258EAFA5-E914-47DA-95CA-C5AB0DC85B11,,),sha1,base64]" if ws_handshake
36 http-after-response set-status 101 if { status eq 200 } { res.hdr(upgrade) -m str websocket }
37 http-after-response set-header x-backend-protocol "%[var(txn.ver)]"
38} -start
39
40# haproxy LB
41haproxy hap -conf {
42 defaults
43 mode http
44 timeout connect 1s
45 timeout client 1s
46 timeout server 1s
47
48 # proto X ws h1 -> websocket on h1
49 listen li
50 bind "fd@${li}"
51 server hap_srv ${hapsrv_fe_addr}:${hapsrv_fe_port} proto h2 ws h1
52
53 # proto X ws h2 -> websocket on h2
54 listen lih2
55 bind "fd@${lih2}"
56 server hap_srv ${hapsrv_fe_addr}:${hapsrv_fe_port} proto h2 ws h2
57
58 # alpn h2,http/1.1 ws h2 -> websocket on h2
59 listen lisslh2
60 bind "fd@${lisslh2}"
61 server hap_srv ${hapsrv_fessl_addr}:${hapsrv_fessl_port} ssl verify none alpn h2,http/1.1 ws h2
62 http-response set-header x-alpn "%[ssl_bc_alpn]"
63
64 # ws auto -> websocket on h1
65 listen liauto
66 bind "fd@${liauto}"
67 server hap_srv ${hapsrv_fe_addr}:${hapsrv_fe_port}
68
69 # alpn h2,http/1.1 ws auto -> websocket on h1
70 listen lissl
71 bind "fd@${lissl}"
72 server hap_srv ${hapsrv_fessl_addr}:${hapsrv_fessl_port} ssl verify none alpn h2,http/1.1 ws auto
73 http-response set-header x-alpn "%[ssl_bc_alpn]"
74 # alpn h2,http/1.1 ws auto -> websocket on h1
75 listen lisslauto
76 bind "fd@${lisslauto}"
77 server hap_srv ${hapsrv_fessl_addr}:${hapsrv_fessl_port} ssl verify none alpn h2,http/1.1
78 http-response set-header x-alpn "%[ssl_bc_alpn]"
79
80 # proto h2 ws auto -> websocket on h2
81 listen liauto2
82 bind "fd@${liauto2}"
83 server hap_srv ${hapsrv_fe_addr}:${hapsrv_fe_port} proto h2
84
85 # alpn h2 ws auto -> websocket on h2
86 listen lisslauto2
87 bind "fd@${lisslauto2}"
88 server hap_srv ${hapsrv_fessl_addr}:${hapsrv_fessl_port} ssl verify none alpn h2 ws auto
89 http-response set-header x-alpn "%[ssl_bc_alpn]"
90} -start
91
92client c1 -connect ${hap_li_sock} {
93 txreq \
94 -req "GET" \
95 -url "/" \
96 -hdr "host: 127.0.0.1" \
97 -hdr "connection: upgrade" \
98 -hdr "upgrade: websocket" \
99 -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
100 rxresp
101 expect resp.status == 101
102 expect resp.http.x-backend-protocol == "1.1"
103} -run
104
105client c1.2 -connect ${hap_lih2_sock} {
106 txreq \
107 -req "GET" \
108 -url "/" \
109 -hdr "host: 127.0.0.1" \
110 -hdr "connection: upgrade" \
111 -hdr "upgrade: websocket" \
112 -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
113 rxresp
114 expect resp.status == 101
115 expect resp.http.x-backend-protocol == "2.0"
116} -run
117
118client c1.3 -connect ${hap_liauto_sock} {
119 txreq \
120 -req "GET" \
121 -url "/" \
122 -hdr "host: 127.0.0.1" \
123 -hdr "connection: upgrade" \
124 -hdr "upgrade: websocket" \
125 -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
126 rxresp
127 expect resp.status == 101
128 expect resp.http.x-backend-protocol == "1.1"
129} -run
130
131client c1.4 -connect ${hap_liauto2_sock} {
132 txreq \
133 -req "GET" \
134 -url "/" \
135 -hdr "host: 127.0.0.1" \
136 -hdr "connection: upgrade" \
137 -hdr "upgrade: websocket" \
138 -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
139 rxresp
140 expect resp.status == 101
141 expect resp.http.x-backend-protocol == "2.0"
142} -run
143
144client c2 -connect ${hap_lisslauto_sock} {
145 txreq \
146 -req "GET" \
147 -url "/" \
148 -hdr "host: 127.0.0.1" \
149 -hdr "connection: upgrade" \
150 -hdr "upgrade: websocket" \
151 -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
152 rxresp
153 expect resp.status == 101
154 expect resp.http.x-alpn == "http/1.1"
155} -run
156
157client c2.2 -connect ${hap_lisslauto2_sock} {
158 txreq \
159 -req "GET" \
160 -url "/" \
161 -hdr "host: 127.0.0.1" \
162 -hdr "connection: upgrade" \
163 -hdr "upgrade: websocket" \
164 -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
165 rxresp
166 expect resp.status == 101
167 expect resp.http.x-alpn == "h2"
168} -run
169
170client c2.3 -connect ${hap_lisslh2_sock} {
171 txreq \
172 -req "GET" \
173 -url "/" \
174 -hdr "host: 127.0.0.1" \
175 -hdr "connection: upgrade" \
176 -hdr "upgrade: websocket" \
177 -hdr "sec-websocket-key: dGhlIHNhbXBsZSBub25jZQ=="
178 rxresp
179 expect resp.status == 101
180 expect resp.http.x-alpn == "h2"
181} -run