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