@@ -16,6 +16,7 @@ var _ = Describe("HTTPS Frontend", func() {
16
16
var closeLocalServer func ()
17
17
enableHTTP2 := false
18
18
var http1Client * http.Client
19
+ var http2Client * http.Client
19
20
20
21
haproxyBackendPort := 12000
21
22
opsfileHTTPS := `---
@@ -32,6 +33,36 @@ var _ = Describe("HTTPS Frontend", func() {
32
33
ssl_pem:
33
34
cert_chain: ((https_frontend.certificate))((https_frontend_ca.certificate))
34
35
private_key: ((https_frontend.private_key))
36
+ # Configure CA and cert chain
37
+ - type: replace
38
+ path: /instance_groups/name=haproxy/jobs/name=haproxy/properties/ha_proxy/crt_list?/-
39
+ value:
40
+ snifilter:
41
+ - haproxy.h2.internal
42
+ ssl_pem:
43
+ cert_chain: ((https_frontend.certificate))((https_frontend_ca.certificate))
44
+ private_key: ((https_frontend.private_key))
45
+ alpn: ['h2']
46
+ # Configure CA and cert chain
47
+ - type: replace
48
+ path: /instance_groups/name=haproxy/jobs/name=haproxy/properties/ha_proxy/crt_list?/-
49
+ value:
50
+ snifilter:
51
+ - haproxy.http11.internal
52
+ ssl_pem:
53
+ cert_chain: ((https_frontend.certificate))((https_frontend_ca.certificate))
54
+ private_key: ((https_frontend.private_key))
55
+ alpn: ['http/1.1']
56
+ # Configure CA and cert chain
57
+ - type: replace
58
+ path: /instance_groups/name=haproxy/jobs/name=haproxy/properties/ha_proxy/crt_list?/-
59
+ value:
60
+ snifilter:
61
+ - haproxy.h2-http11.internal
62
+ ssl_pem:
63
+ cert_chain: ((https_frontend.certificate))((https_frontend_ca.certificate))
64
+ private_key: ((https_frontend.private_key))
65
+ alpn: ['h2', 'http/1.1']
35
66
# Declare certs
36
67
- type: replace
37
68
path: /variables?/-
@@ -49,7 +80,7 @@ var _ = Describe("HTTPS Frontend", func() {
49
80
options:
50
81
ca: https_frontend_ca
51
82
common_name: haproxy.internal
52
- alternative_names: [haproxy.internal]
83
+ alternative_names: [haproxy.internal, haproxy.h2.internal, haproxy.http11.internal, haproxy.h2-http11.internal ]
53
84
`
54
85
55
86
var creds struct {
@@ -77,11 +108,14 @@ var _ = Describe("HTTPS Frontend", func() {
77
108
closeLocalServer , localPort = startDefaultTestServer ()
78
109
closeTunnel = setupTunnelFromHaproxyToTestServer (haproxyInfo , haproxyBackendPort , localPort )
79
110
80
- http1Client = buildHTTPClient (
81
- []string {creds .HTTPSFrontend .CA },
82
- map [string ]string {"haproxy.internal:443" : fmt .Sprintf ("%s:443" , haproxyInfo .PublicIP )},
83
- []tls.Certificate {}, "" ,
84
- )
111
+ addresses := map [string ]string {
112
+ "haproxy.internal:443" : fmt .Sprintf ("%s:443" , haproxyInfo .PublicIP ),
113
+ "haproxy.h2.internal:443" : fmt .Sprintf ("%s:443" , haproxyInfo .PublicIP ),
114
+ "haproxy.http11.internal:443" : fmt .Sprintf ("%s:443" , haproxyInfo .PublicIP ),
115
+ }
116
+
117
+ http1Client = buildHTTPClient ([]string {creds .HTTPSFrontend .CA }, addresses , []tls.Certificate {}, "" )
118
+ http2Client = buildHTTP2Client ([]string {creds .HTTPSFrontend .CA }, addresses , []tls.Certificate {})
85
119
})
86
120
87
121
AfterEach (func () {
@@ -134,12 +168,6 @@ var _ = Describe("HTTPS Frontend", func() {
134
168
Expect (resp .StatusCode ).To (Equal (http .StatusOK ))
135
169
Eventually (gbytes .BufferReader (resp .Body )).Should (gbytes .Say ("Hello cloud foundry" ))
136
170
137
- http2Client := buildHTTP2Client (
138
- []string {creds .HTTPSFrontend .CA },
139
- map [string ]string {"haproxy.internal:443" : fmt .Sprintf ("%s:443" , haproxyInfo .PublicIP )},
140
- []tls.Certificate {},
141
- )
142
-
143
171
By ("Sending a request to HAProxy using HTTP 2" )
144
172
resp , err = http2Client .Get ("https://haproxy.internal:443" )
145
173
Expect (err ).NotTo (HaveOccurred ())
@@ -150,4 +178,43 @@ var _ = Describe("HTTPS Frontend", func() {
150
178
Eventually (gbytes .BufferReader (resp .Body )).Should (gbytes .Say ("Hello cloud foundry" ))
151
179
})
152
180
})
181
+
182
+ Context ("ALPN Configuration via CRT list" , func () {
183
+ BeforeEach (func () {
184
+ // Do not enable HTTP globally, since we are adding it via crt-list entries
185
+ enableHTTP2 = false
186
+ })
187
+
188
+ It ("Negotiates the correct ALPN protocol" , func () {
189
+ // H2 endpoint should negotiate H2 if the client supports it
190
+ alpnProto , err := connectTLSALPNNegotiatedProtocol ([]string {"http/1.1" , "h2" }, haproxyInfo .PublicIP , creds .HTTPSFrontend .CA , "haproxy.h2.internal" )
191
+ Expect (err ).NotTo (HaveOccurred ())
192
+ Expect (alpnProto ).To (Equal ("h2" ))
193
+
194
+ // HTTP/1.1 endpoint should negotiate HTTP/1.1 if the client supports it
195
+ alpnProto , err = connectTLSALPNNegotiatedProtocol ([]string {"h2" , "http/1.1" }, haproxyInfo .PublicIP , creds .HTTPSFrontend .CA , "haproxy.http11.internal" )
196
+ Expect (err ).NotTo (HaveOccurred ())
197
+ Expect (alpnProto ).To (Equal ("http/1.1" ))
198
+
199
+ // H2+HTTP/1.1 endpoint should negotiate H2 if the client supports it
200
+ alpnProto , err = connectTLSALPNNegotiatedProtocol ([]string {"h2" }, haproxyInfo .PublicIP , creds .HTTPSFrontend .CA , "haproxy.h2-http11.internal" )
201
+ Expect (err ).NotTo (HaveOccurred ())
202
+ Expect (alpnProto ).To (Equal ("h2" ))
203
+
204
+ // H2+HTTP/1.1 endpoint should negotiate HTTP/1.1 if the client supports it
205
+ alpnProto , err = connectTLSALPNNegotiatedProtocol ([]string {"http/1.1" }, haproxyInfo .PublicIP , creds .HTTPSFrontend .CA , "haproxy.h2-http11.internal" )
206
+ Expect (err ).NotTo (HaveOccurred ())
207
+ Expect (alpnProto ).To (Equal ("http/1.1" ))
208
+
209
+ // H2 endpoint should not use ALPN if client does not support H2
210
+ alpnProto , err = connectTLSALPNNegotiatedProtocol ([]string {"http/1.1" }, haproxyInfo .PublicIP , creds .HTTPSFrontend .CA , "haproxy.h2.internal" )
211
+ Expect (err ).NotTo (HaveOccurred ())
212
+ Expect (alpnProto ).To (Equal ("" ))
213
+
214
+ // HTTP/1.1 endpoint should not use ALPN if client does not support HTTP/1.1
215
+ alpnProto , err = connectTLSALPNNegotiatedProtocol ([]string {"h2" }, haproxyInfo .PublicIP , creds .HTTPSFrontend .CA , "haproxy.http11.internal" )
216
+ Expect (err ).NotTo (HaveOccurred ())
217
+ Expect (alpnProto ).To (Equal ("" ))
218
+ })
219
+ })
153
220
})
0 commit comments