git.iko.soy/typeable/oauth2-proxy
on master help sign in
Add description on ipv6 address (#1635)

* add docs on ipv6 * add tests for ipv6 address * add tests for ipv6 address * remove Print function for debugging * Updated changelog

commitc6a98369a0e544da8a36241426e02052cc6a6598 authort-katsumura <83070078+t-katsumura@users.noreply.github.com> dateMon 23 May 2022, 18:17 (4 years ago) parent743c344
6 files changed+486−67
CHANGELOG.md+1 docs/docs/configuration/overview.md+2−2 pkg/http/http_suite_test.go+29−10 pkg/http/server_test.go+451−52 pkg/sessions/redis/redis_store_test.go+1−1 pkg/util/util.go+2−2
CHANGELOG.md+1
@@ -41,6 +41,7 @@ If you are using an architecture specific tag (ex: v7.2.1-arm64) you should move
4141- [#1594](https://github.com/oauth2-proxy/oauth2-proxy/pull/1594) Release ARMv8 docker images (@braunsonm)
4242- [#1649](https://github.com/oauth2-proxy/oauth2-proxy/pull/1649) Return a 400 instead of a 500 when a request contains an invalid redirect target (@niksko)
4343- [#1638](https://github.com/oauth2-proxy/oauth2-proxy/pull/1638) Implement configurable upstream timeout (@jacksgt)
44+- [#1635](https://github.com/oauth2-proxy/oauth2-proxy/pull/1635) Added description and unit tests for ipv6 address (@t-katsumura)
4445
4546# V7.2.1
4647
docs/docs/configuration/overview.md+2−2
@@ -119,8 +119,8 @@ An example [oauth2-proxy.cfg](https://github.com/oauth2-proxy/oauth2-proxy/blob/
119119| `--google-service-account-json` | string | the path to the service account json credentials | |
120120| `--htpasswd-file` | string | additionally authenticate against a htpasswd file. Entries must be created with `htpasswd -B` for bcrypt encryption | |
121121| `--htpasswd-user-group` | string \| list | the groups to be set on sessions for htpasswd users | |
122−| `--http-address` | string | `[http://]<addr>:<port>` or `unix://<path>` to listen on for HTTP clients | `"127.0.0.1:4180"` |
123−| `--https-address` | string | `<addr>:<port>` to listen on for HTTPS clients | `":443"` |
122+| `--http-address` | string | `[http://]<addr>:<port>` or `unix://<path>` to listen on for HTTP clients. Square brackets are required for ipv6 address, e.g. `http://[::1]:4180` | `"127.0.0.1:4180"` |
123+| `--https-address` | string | `[https://]<addr>:<port>` to listen on for HTTPS clients. Square brackets are required for ipv6 address, e.g. `https://[::1]:443` | `":443"` |
124124| `--logging-compress` | bool | Should rotated log files be compressed using gzip | false |
125125| `--logging-filename` | string | File to log requests to, empty for `stdout` | `""` (stdout) |
126126| `--logging-local-time` | bool | Use local time in log files and backup filenames instead of UTC | true (local time) |
pkg/http/http_suite_test.go+29−10
@@ -15,8 +15,9 @@ import (
1515 . "github.com/onsi/gomega"
1616)
1717
18−var certData []byte
19−var certDataSource, keyDataSource options.SecretSource
18+var ipv4CertData, ipv6CertData []byte
19+var ipv4CertDataSource, ipv4KeyDataSource options.SecretSource
20+var ipv6CertDataSource, ipv6KeyDataSource options.SecretSource
2021var client *http.Client
2122
2223func TestHTTPSuite(t *testing.T) {
@@ -28,28 +29,46 @@ func TestHTTPSuite(t *testing.T) {
2829}
2930
3031var _ = BeforeSuite(func() {
31− By("Generating a self-signed cert for TLS tests", func() {
32− certBytes, keyBytes, err := util.GenerateCert()
32+ By("Generating a ipv4 self-signed cert for TLS tests", func() {
33+ certBytes, keyBytes, err := util.GenerateCert("127.0.0.1")
3334 Expect(err).ToNot(HaveOccurred())
34− certData = certBytes
35+ ipv4CertData = certBytes
3536
3637 certOut := new(bytes.Buffer)
3738 Expect(pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes})).To(Succeed())
38− certDataSource.Value = certOut.Bytes()
39+ ipv4CertDataSource.Value = certOut.Bytes()
3940 keyOut := new(bytes.Buffer)
4041 Expect(pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})).To(Succeed())
41− keyDataSource.Value = keyOut.Bytes()
42+ ipv4KeyDataSource.Value = keyOut.Bytes()
43+ })
44+
45+ By("Generating a ipv6 self-signed cert for TLS tests", func() {
46+ certBytes, keyBytes, err := util.GenerateCert("::1")
47+ Expect(err).ToNot(HaveOccurred())
48+ ipv6CertData = certBytes
49+
50+ certOut := new(bytes.Buffer)
51+ Expect(pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes})).To(Succeed())
52+ ipv6CertDataSource.Value = certOut.Bytes()
53+ keyOut := new(bytes.Buffer)
54+ Expect(pem.Encode(keyOut, &pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})).To(Succeed())
55+ ipv6KeyDataSource.Value = keyOut.Bytes()
4256 })
4357
4458 By("Setting up a http client", func() {
45− cert, err := tls.X509KeyPair(certDataSource.Value, keyDataSource.Value)
59+ ipv4cert, err := tls.X509KeyPair(ipv4CertDataSource.Value, ipv4KeyDataSource.Value)
60+ Expect(err).ToNot(HaveOccurred())
61+ ipv6cert, err := tls.X509KeyPair(ipv6CertDataSource.Value, ipv6KeyDataSource.Value)
4662 Expect(err).ToNot(HaveOccurred())
4763
48− certificate, err := x509.ParseCertificate(cert.Certificate[0])
64+ ipv4certificate, err := x509.ParseCertificate(ipv4cert.Certificate[0])
65+ Expect(err).ToNot(HaveOccurred())
66+ ipv6certificate, err := x509.ParseCertificate(ipv6cert.Certificate[0])
4967 Expect(err).ToNot(HaveOccurred())
5068
5169 certpool := x509.NewCertPool()
52− certpool.AddCert(certificate)
70+ certpool.AddCert(ipv4certificate)
71+ certpool.AddCert(ipv6certificate)
5372
5473 transport := http.DefaultTransport.(*http.Transport).Clone()
5574 transport.TLSClientConfig.RootCAs = certpool
pkg/http/server_test.go+451−52
@@ -50,7 +50,7 @@ var _ = Describe("Server", func() {
5050 Expect(s.tlsListener.Close()).To(Succeed())
5151 }
5252 },
53− Entry("with a valid http bind address", &newServerTableInput{
53+ Entry("with an ipv4 valid http bind address", &newServerTableInput{
5454 opts: Opts{
5555 Handler: handler,
5656 BindAddress: "127.0.0.1:0",
@@ -59,7 +59,7 @@ var _ = Describe("Server", func() {
5959 expectHTTPListener: true,
6060 expectTLSListener: false,
6161 }),
62− Entry("with a valid https bind address, with no TLS config", &newServerTableInput{
62+ Entry("with an ipv4 valid https bind address, with no TLS config", &newServerTableInput{
6363 opts: Opts{
6464 Handler: handler,
6565 SecureBindAddress: "127.0.0.1:0",
@@ -68,27 +68,27 @@ var _ = Describe("Server", func() {
6868 expectHTTPListener: false,
6969 expectTLSListener: false,
7070 }),
71− Entry("with a valid https bind address, and valid TLS config", &newServerTableInput{
71+ Entry("with an ipv4 valid https bind address, and valid TLS config", &newServerTableInput{
7272 opts: Opts{
7373 Handler: handler,
7474 SecureBindAddress: "127.0.0.1:0",
7575 TLS: &options.TLS{
76− Key: &keyDataSource,
77− Cert: &certDataSource,
76+ Key: &ipv4KeyDataSource,
77+ Cert: &ipv4CertDataSource,
7878 },
7979 },
8080 expectedErr: nil,
8181 expectHTTPListener: false,
8282 expectTLSListener: true,
8383 }),
84− Entry("with a both a valid http and valid https bind address, and valid TLS config", &newServerTableInput{
84+ Entry("with a both a ipv4 valid http and ipv4 valid https bind address, and valid TLS config", &newServerTableInput{
8585 opts: Opts{
8686 Handler: handler,
8787 BindAddress: "127.0.0.1:0",
8888 SecureBindAddress: "127.0.0.1:0",
8989 TLS: &options.TLS{
90− Key: &keyDataSource,
91− Cert: &certDataSource,
90+ Key: &ipv4KeyDataSource,
91+ Cert: &ipv4CertDataSource,
9292 },
9393 },
9494 expectedErr: nil,
@@ -113,7 +113,7 @@ var _ = Describe("Server", func() {
113113 expectHTTPListener: false,
114114 expectTLSListener: false,
115115 }),
116− Entry("with an invalid bind address scheme", &newServerTableInput{
116+ Entry("with an ipv4 invalid bind address scheme", &newServerTableInput{
117117 opts: Opts{
118118 Handler: handler,
119119 BindAddress: "invalid://127.0.0.1:0",
@@ -122,20 +122,20 @@ var _ = Describe("Server", func() {
122122 expectHTTPListener: false,
123123 expectTLSListener: false,
124124 }),
125− Entry("with an invalid secure bind address scheme", &newServerTableInput{
125+ Entry("with an ipv4 invalid secure bind address scheme", &newServerTableInput{
126126 opts: Opts{
127127 Handler: handler,
128128 SecureBindAddress: "invalid://127.0.0.1:0",
129129 TLS: &options.TLS{
130− Key: &keyDataSource,
131− Cert: &certDataSource,
130+ Key: &ipv4KeyDataSource,
131+ Cert: &ipv4CertDataSource,
132132 },
133133 },
134134 expectedErr: nil,
135135 expectHTTPListener: false,
136136 expectTLSListener: true,
137137 }),
138− Entry("with an invalid bind address port", &newServerTableInput{
138+ Entry("with an ipv4 invalid bind address port", &newServerTableInput{
139139 opts: Opts{
140140 Handler: handler,
141141 BindAddress: "127.0.0.1:a",
@@ -144,20 +144,20 @@ var _ = Describe("Server", func() {
144144 expectHTTPListener: false,
145145 expectTLSListener: false,
146146 }),
147− Entry("with an invalid secure bind address port", &newServerTableInput{
147+ Entry("with an ipv4 invalid secure bind address port", &newServerTableInput{
148148 opts: Opts{
149149 Handler: handler,
150150 SecureBindAddress: "127.0.0.1:a",
151151 TLS: &options.TLS{
152− Key: &keyDataSource,
153− Cert: &certDataSource,
152+ Key: &ipv4KeyDataSource,
153+ Cert: &ipv4CertDataSource,
154154 },
155155 },
156156 expectedErr: errors.New("error setting up TLS listener: listen (127.0.0.1:a) failed: listen tcp: "),
157157 expectHTTPListener: false,
158158 expectTLSListener: false,
159159 }),
160− Entry("with an invalid TLS key", &newServerTableInput{
160+ Entry("with an ipv4 invalid TLS key", &newServerTableInput{
161161 opts: Opts{
162162 Handler: handler,
163163 SecureBindAddress: "127.0.0.1:0",
@@ -165,19 +165,19 @@ var _ = Describe("Server", func() {
165165 Key: &options.SecretSource{
166166 Value: []byte("invalid"),
167167 },
168− Cert: &certDataSource,
168+ Cert: &ipv4CertDataSource,
169169 },
170170 },
171171 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not parse certificate data: tls: failed to find any PEM data in key input"),
172172 expectHTTPListener: false,
173173 expectTLSListener: false,
174174 }),
175− Entry("with an invalid TLS cert", &newServerTableInput{
175+ Entry("with an ipv4 invalid TLS cert", &newServerTableInput{
176176 opts: Opts{
177177 Handler: handler,
178178 SecureBindAddress: "127.0.0.1:0",
179179 TLS: &options.TLS{
180− Key: &keyDataSource,
180+ Key: &ipv4KeyDataSource,
181181 Cert: &options.SecretSource{
182182 Value: []byte("invalid"),
183183 },
@@ -187,31 +187,31 @@ var _ = Describe("Server", func() {
187187 expectHTTPListener: false,
188188 expectTLSListener: false,
189189 }),
190− Entry("with no TLS key", &newServerTableInput{
190+ Entry("with an ipv4 address, with no TLS key", &newServerTableInput{
191191 opts: Opts{
192192 Handler: handler,
193193 SecureBindAddress: "127.0.0.1:0",
194194 TLS: &options.TLS{
195− Cert: &certDataSource,
195+ Cert: &ipv4CertDataSource,
196196 },
197197 },
198198 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
199199 expectHTTPListener: false,
200200 expectTLSListener: false,
201201 }),
202− Entry("with no TLS cert", &newServerTableInput{
202+ Entry("with an ipv4 address, with no TLS cert", &newServerTableInput{
203203 opts: Opts{
204204 Handler: handler,
205205 SecureBindAddress: "127.0.0.1:0",
206206 TLS: &options.TLS{
207− Key: &keyDataSource,
207+ Key: &ipv4KeyDataSource,
208208 },
209209 },
210210 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
211211 expectHTTPListener: false,
212212 expectTLSListener: false,
213213 }),
214− Entry("when the bind address is prefixed with the http scheme", &newServerTableInput{
214+ Entry("when the ipv4 bind address is prefixed with the http scheme", &newServerTableInput{
215215 opts: Opts{
216216 Handler: handler,
217217 BindAddress: "http://127.0.0.1:0",
@@ -220,26 +220,26 @@ var _ = Describe("Server", func() {
220220 expectHTTPListener: true,
221221 expectTLSListener: false,
222222 }),
223− Entry("when the secure bind address is prefixed with the https scheme", &newServerTableInput{
223+ Entry("when the ipv4 secure bind address is prefixed with the https scheme", &newServerTableInput{
224224 opts: Opts{
225225 Handler: handler,
226226 SecureBindAddress: "https://127.0.0.1:0",
227227 TLS: &options.TLS{
228− Key: &keyDataSource,
229− Cert: &certDataSource,
228+ Key: &ipv4KeyDataSource,
229+ Cert: &ipv4CertDataSource,
230230 },
231231 },
232232 expectedErr: nil,
233233 expectHTTPListener: false,
234234 expectTLSListener: true,
235235 }),
236− Entry("with a valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
236+ Entry("with an ipv4 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
237237 opts: Opts{
238238 Handler: handler,
239239 SecureBindAddress: "127.0.0.1:0",
240240 TLS: &options.TLS{
241− Key: &keyDataSource,
242− Cert: &certDataSource,
241+ Key: &ipv4KeyDataSource,
242+ Cert: &ipv4CertDataSource,
243243 MinVersion: "TLS1.3",
244244 },
245245 },
@@ -247,13 +247,206 @@ var _ = Describe("Server", func() {
247247 expectHTTPListener: false,
248248 expectTLSListener: true,
249249 }),
250− Entry("with a valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
250+ Entry("with an ipv4 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
251251 opts: Opts{
252252 Handler: handler,
253253 SecureBindAddress: "127.0.0.1:0",
254254 TLS: &options.TLS{
255− Key: &keyDataSource,
256− Cert: &certDataSource,
255+ Key: &ipv4KeyDataSource,
256+ Cert: &ipv4CertDataSource,
257+ MinVersion: "TLS1.42",
258+ },
259+ },
260+ expectedErr: errors.New("error setting up TLS listener: unknown TLS MinVersion config provided"),
261+ expectHTTPListener: false,
262+ expectTLSListener: true,
263+ }),
264+ Entry("with an ipv6 valid http bind address", &newServerTableInput{
265+ opts: Opts{
266+ Handler: handler,
267+ BindAddress: "[::1]:0",
268+ },
269+ expectedErr: nil,
270+ expectHTTPListener: true,
271+ expectTLSListener: false,
272+ }),
273+ Entry("with an ipv6 valid https bind address, with no TLS config", &newServerTableInput{
274+ opts: Opts{
275+ Handler: handler,
276+ SecureBindAddress: "[::1]:0",
277+ },
278+ expectedErr: errors.New("error setting up TLS listener: no TLS config provided"),
279+ expectHTTPListener: false,
280+ expectTLSListener: false,
281+ }),
282+ Entry("with an ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
283+ opts: Opts{
284+ Handler: handler,
285+ SecureBindAddress: "[::1]:0",
286+ TLS: &options.TLS{
287+ Key: &ipv6KeyDataSource,
288+ Cert: &ipv6CertDataSource,
289+ },
290+ },
291+ expectedErr: nil,
292+ expectHTTPListener: false,
293+ expectTLSListener: true,
294+ }),
295+ Entry("with a both a ipv6 valid http and ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
296+ opts: Opts{
297+ Handler: handler,
298+ BindAddress: "[::1]:0",
299+ SecureBindAddress: "[::1]:0",
300+ TLS: &options.TLS{
301+ Key: &ipv6KeyDataSource,
302+ Cert: &ipv6CertDataSource,
303+ },
304+ },
305+ expectedErr: nil,
306+ expectHTTPListener: true,
307+ expectTLSListener: true,
308+ }),
309+ Entry("with an ipv6 invalid bind address scheme", &newServerTableInput{
310+ opts: Opts{
311+ Handler: handler,
312+ BindAddress: "invalid://[::1]:0",
313+ },
314+ expectedErr: errors.New("error setting up listener: listen (invalid, [::1]:0) failed: listen invalid: unknown network invalid"),
315+ expectHTTPListener: false,
316+ expectTLSListener: false,
317+ }),
318+ Entry("with an ipv6 invalid secure bind address scheme", &newServerTableInput{
319+ opts: Opts{
320+ Handler: handler,
321+ SecureBindAddress: "invalid://[::1]:0",
322+ TLS: &options.TLS{
323+ Key: &ipv6KeyDataSource,
324+ Cert: &ipv6CertDataSource,
325+ },
326+ },
327+ expectedErr: nil,
328+ expectHTTPListener: false,
329+ expectTLSListener: true,
330+ }),
331+ Entry("with an ipv6 invalid bind address port", &newServerTableInput{
332+ opts: Opts{
333+ Handler: handler,
334+ BindAddress: "[::1]:a",
335+ },
336+ expectedErr: errors.New("error setting up listener: listen (tcp, [::1]:a) failed: listen tcp: "),
337+ expectHTTPListener: false,
338+ expectTLSListener: false,
339+ }),
340+ Entry("with an ipv6 invalid secure bind address port", &newServerTableInput{
341+ opts: Opts{
342+ Handler: handler,
343+ SecureBindAddress: "[::1]:a",
344+ TLS: &options.TLS{
345+ Key: &ipv6KeyDataSource,
346+ Cert: &ipv6CertDataSource,
347+ },
348+ },
349+ expectedErr: errors.New("error setting up TLS listener: listen ([::1]:a) failed: listen tcp: "),
350+ expectHTTPListener: false,
351+ expectTLSListener: false,
352+ }),
353+ Entry("with an ipv6 invalid TLS key", &newServerTableInput{
354+ opts: Opts{
355+ Handler: handler,
356+ SecureBindAddress: "[::1]:0",
357+ TLS: &options.TLS{
358+ Key: &options.SecretSource{
359+ Value: []byte("invalid"),
360+ },
361+ Cert: &ipv6CertDataSource,
362+ },
363+ },
364+ expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not parse certificate data: tls: failed to find any PEM data in key input"),
365+ expectHTTPListener: false,
366+ expectTLSListener: false,
367+ }),
368+ Entry("with an ipv6 invalid TLS cert", &newServerTableInput{
369+ opts: Opts{
370+ Handler: handler,
371+ SecureBindAddress: "[::1]:0",
372+ TLS: &options.TLS{
373+ Key: &ipv6KeyDataSource,
374+ Cert: &options.SecretSource{
375+ Value: []byte("invalid"),
376+ },
377+ },
378+ },
379+ expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not parse certificate data: tls: failed to find any PEM data in certificate input"),
380+ expectHTTPListener: false,
381+ expectTLSListener: false,
382+ }),
383+ Entry("with an ipv6 address, with no TLS key", &newServerTableInput{
384+ opts: Opts{
385+ Handler: handler,
386+ SecureBindAddress: "[::1]:0",
387+ TLS: &options.TLS{
388+ Cert: &ipv6CertDataSource,
389+ },
390+ },
391+ expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
392+ expectHTTPListener: false,
393+ expectTLSListener: false,
394+ }),
395+ Entry("with an ipv6 address, with no TLS cert", &newServerTableInput{
396+ opts: Opts{
397+ Handler: handler,
398+ SecureBindAddress: "[::1]:0",
399+ TLS: &options.TLS{
400+ Key: &ipv6KeyDataSource,
401+ },
402+ },
403+ expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
404+ expectHTTPListener: false,
405+ expectTLSListener: false,
406+ }),
407+ Entry("when the ipv6 bind address is prefixed with the http scheme", &newServerTableInput{
408+ opts: Opts{
409+ Handler: handler,
410+ BindAddress: "http://[::1]:0",
411+ },
412+ expectedErr: nil,
413+ expectHTTPListener: true,
414+ expectTLSListener: false,
415+ }),
416+ Entry("when the ipv6 secure bind address is prefixed with the https scheme", &newServerTableInput{
417+ opts: Opts{
418+ Handler: handler,
419+ SecureBindAddress: "https://[::1]:0",
420+ TLS: &options.TLS{
421+ Key: &ipv6KeyDataSource,
422+ Cert: &ipv6CertDataSource,
423+ },
424+ },
425+ expectedErr: nil,
426+ expectHTTPListener: false,
427+ expectTLSListener: true,
428+ }),
429+ Entry("with an ipv6 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
430+ opts: Opts{
431+ Handler: handler,
432+ SecureBindAddress: "[::1]:0",
433+ TLS: &options.TLS{
434+ Key: &ipv6KeyDataSource,
435+ Cert: &ipv6CertDataSource,
436+ MinVersion: "TLS1.3",
437+ },
438+ },
439+ expectedErr: nil,
440+ expectHTTPListener: false,
441+ expectTLSListener: true,
442+ }),
443+ Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
444+ opts: Opts{
445+ Handler: handler,
446+ SecureBindAddress: "[::1]:0",
447+ TLS: &options.TLS{
448+ Key: &ipv6KeyDataSource,
449+ Cert: &ipv6CertDataSource,
257450 MinVersion: "TLS1.42",
258451 },
259452 },
@@ -277,7 +470,7 @@ var _ = Describe("Server", func() {
277470 cancel()
278471 })
279472
280− Context("with an http server", func() {
473+ Context("with an ipv4 http server", func() {
281474 var listenAddr string
282475
283476 BeforeEach(func() {
@@ -327,7 +520,7 @@ var _ = Describe("Server", func() {
327520 })
328521 })
329522
330− Context("with an https server", func() {
523+ Context("with an ipv4 https server", func() {
331524 var secureListenAddr string
332525
333526 BeforeEach(func() {
@@ -336,8 +529,8 @@ var _ = Describe("Server", func() {
336529 Handler: handler,
337530 SecureBindAddress: "127.0.0.1:0",
338531 TLS: &options.TLS{
339− Key: &keyDataSource,
340− Cert: &certDataSource,
532+ Key: &ipv4KeyDataSource,
533+ Cert: &ipv4CertDataSource,
341534 },
342535 })
343536 Expect(err).ToNot(HaveOccurred())
@@ -392,11 +585,11 @@ var _ = Describe("Server", func() {
392585
393586 Expect(resp.TLS.VerifiedChains).Should(HaveLen(1))
394587 Expect(resp.TLS.VerifiedChains[0]).Should(HaveLen(1))
395− Expect(resp.TLS.VerifiedChains[0][0].Raw).Should(Equal(certData))
588+ Expect(resp.TLS.VerifiedChains[0][0].Raw).Should(Equal(ipv4CertData))
396589 })
397590 })
398591
399− Context("with both an http and an https server", func() {
592+ Context("with both an ipv4 http and an ipv4 https server", func() {
400593 var listenAddr, secureListenAddr string
401594
402595 BeforeEach(func() {
@@ -406,8 +599,204 @@ var _ = Describe("Server", func() {
406599 BindAddress: "127.0.0.1:0",
407600 SecureBindAddress: "127.0.0.1:0",
408601 TLS: &options.TLS{
409− Key: &keyDataSource,
410− Cert: &certDataSource,
602+ Key: &ipv4KeyDataSource,
603+ Cert: &ipv4CertDataSource,
604+ },
605+ })
606+ Expect(err).ToNot(HaveOccurred())
607+
608+ s, ok := srv.(*server)
609+ Expect(ok).To(BeTrue())
610+
611+ listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
612+ secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
613+ })
614+
615+ It("Starts the server and serves the handler on http", func() {
616+ go func() {
617+ defer GinkgoRecover()
618+ Expect(srv.Start(ctx)).To(Succeed())
619+ }()
620+
621+ resp, err := client.Get(listenAddr)
622+ Expect(err).ToNot(HaveOccurred())
623+ Expect(resp.StatusCode).To(Equal(http.StatusOK))
624+
625+ body, err := ioutil.ReadAll(resp.Body)
626+ Expect(err).ToNot(HaveOccurred())
627+ Expect(string(body)).To(Equal(hello))
628+ })
629+
630+ It("Starts the server and serves the handler on https", func() {
631+ go func() {
632+ defer GinkgoRecover()
633+ Expect(srv.Start(ctx)).To(Succeed())
634+ }()
635+
636+ resp, err := client.Get(secureListenAddr)
637+ Expect(err).ToNot(HaveOccurred())
638+ Expect(resp.StatusCode).To(Equal(http.StatusOK))
639+
640+ body, err := ioutil.ReadAll(resp.Body)
641+ Expect(err).ToNot(HaveOccurred())
642+ Expect(string(body)).To(Equal(hello))
643+ })
644+
645+ It("Stops both servers when the context is cancelled", func() {
646+ go func() {
647+ defer GinkgoRecover()
648+ Expect(srv.Start(ctx)).To(Succeed())
649+ }()
650+
651+ _, err := client.Get(listenAddr)
652+ Expect(err).ToNot(HaveOccurred())
653+ _, err = client.Get(secureListenAddr)
654+ Expect(err).ToNot(HaveOccurred())
655+
656+ cancel()
657+
658+ Eventually(func() error {
659+ _, err := client.Get(listenAddr)
660+ return err
661+ }).Should(HaveOccurred())
662+ Eventually(func() error {
663+ _, err := client.Get(secureListenAddr)
664+ return err
665+ }).Should(HaveOccurred())
666+ })
667+ })
668+
669+ Context("with an ipv6 http server", func() {
670+ var listenAddr string
671+
672+ BeforeEach(func() {
673+ var err error
674+ srv, err = NewServer(Opts{
675+ Handler: handler,
676+ BindAddress: "[::1]:0",
677+ })
678+ Expect(err).ToNot(HaveOccurred())
679+
680+ s, ok := srv.(*server)
681+ Expect(ok).To(BeTrue())
682+
683+ listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
684+ })
685+
686+ It("Starts the server and serves the handler", func() {
687+ go func() {
688+ defer GinkgoRecover()
689+ Expect(srv.Start(ctx)).To(Succeed())
690+ }()
691+
692+ resp, err := client.Get(listenAddr)
693+ Expect(err).ToNot(HaveOccurred())
694+ Expect(resp.StatusCode).To(Equal(http.StatusOK))
695+
696+ body, err := ioutil.ReadAll(resp.Body)
697+ Expect(err).ToNot(HaveOccurred())
698+ Expect(string(body)).To(Equal(hello))
699+ })
700+
701+ It("Stops the server when the context is cancelled", func() {
702+ go func() {
703+ defer GinkgoRecover()
704+ Expect(srv.Start(ctx)).To(Succeed())
705+ }()
706+
707+ _, err := client.Get(listenAddr)
708+ Expect(err).ToNot(HaveOccurred())
709+
710+ cancel()
711+
712+ Eventually(func() error {
713+ _, err := client.Get(listenAddr)
714+ return err
715+ }).Should(HaveOccurred())
716+ })
717+ })
718+
719+ Context("with an ipv6 https server", func() {
720+ var secureListenAddr string
721+
722+ BeforeEach(func() {
723+ var err error
724+ srv, err = NewServer(Opts{
725+ Handler: handler,
726+ SecureBindAddress: "[::1]:0",
727+ TLS: &options.TLS{
728+ Key: &ipv6KeyDataSource,
729+ Cert: &ipv6CertDataSource,
730+ },
731+ })
732+ Expect(err).ToNot(HaveOccurred())
733+
734+ s, ok := srv.(*server)
735+ Expect(ok).To(BeTrue())
736+
737+ secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
738+ })
739+
740+ It("Starts the server and serves the handler", func() {
741+ go func() {
742+ defer GinkgoRecover()
743+ Expect(srv.Start(ctx)).To(Succeed())
744+ }()
745+
746+ resp, err := client.Get(secureListenAddr)
747+ Expect(err).ToNot(HaveOccurred())
748+ Expect(resp.StatusCode).To(Equal(http.StatusOK))
749+
750+ body, err := ioutil.ReadAll(resp.Body)
751+ Expect(err).ToNot(HaveOccurred())
752+ Expect(string(body)).To(Equal(hello))
753+ })
754+
755+ It("Stops the server when the context is cancelled", func() {
756+ go func() {
757+ defer GinkgoRecover()
758+ Expect(srv.Start(ctx)).To(Succeed())
759+ }()
760+
761+ _, err := client.Get(secureListenAddr)
762+ Expect(err).ToNot(HaveOccurred())
763+
764+ cancel()
765+
766+ Eventually(func() error {
767+ _, err := client.Get(secureListenAddr)
768+ return err
769+ }).Should(HaveOccurred())
770+ })
771+
772+ It("Serves the certificate provided", func() {
773+ go func() {
774+ defer GinkgoRecover()
775+ Expect(srv.Start(ctx)).To(Succeed())
776+ }()
777+
778+ resp, err := client.Get(secureListenAddr)
779+ Expect(err).ToNot(HaveOccurred())
780+ Expect(resp.StatusCode).To(Equal(http.StatusOK))
781+
782+ Expect(resp.TLS.VerifiedChains).Should(HaveLen(1))
783+ Expect(resp.TLS.VerifiedChains[0]).Should(HaveLen(1))
784+ Expect(resp.TLS.VerifiedChains[0][0].Raw).Should(Equal(ipv6CertData))
785+ })
786+ })
787+
788+ Context("with both an ipv6 http and an ipv6 https server", func() {
789+ var listenAddr, secureListenAddr string
790+
791+ BeforeEach(func() {
792+ var err error
793+ srv, err = NewServer(Opts{
794+ Handler: handler,
795+ BindAddress: "[::1]:0",
796+ SecureBindAddress: "[::1]:0",
797+ TLS: &options.TLS{
798+ Key: &ipv6KeyDataSource,
799+ Cert: &ipv6CertDataSource,
411800 },
412801 })
413802 Expect(err).ToNot(HaveOccurred())
@@ -478,11 +867,16 @@ var _ = Describe("Server", func() {
478867 DescribeTable("should return the scheme", func(in, expected string) {
479868 Expect(getNetworkScheme(in)).To(Equal(expected))
480869 },
481− Entry("with no scheme", "127.0.0.1:0", "tcp"),
482− Entry("with a tcp scheme", "tcp://127.0.0.1:0", "tcp"),
483− Entry("with a http scheme", "http://192.168.0.1:1", "tcp"),
484− Entry("with a unix scheme", "unix://172.168.16.2:2", "unix"),
485− Entry("with a random scheme", "random://10.10.10.10:10", "random"),
870+ Entry("ipv4 address with no scheme", "127.0.0.1:0", "tcp"),
871+ Entry("ipv4 address with a tcp scheme", "tcp://127.0.0.1:0", "tcp"),
872+ Entry("ipv4 address with a http scheme", "http://192.168.0.1:1", "tcp"),
873+ Entry("ipv4 address with a unix scheme", "unix://172.168.16.2:2", "unix"),
874+ Entry("ipv4 address with a random scheme", "random://10.10.10.10:10", "random"),
875+ Entry("ipv6 address with no scheme", "[::1]:0", "tcp"),
876+ Entry("ipv6 address with a tcp scheme", "tcp://[::1]:0", "tcp"),
877+ Entry("ipv6 address with a http scheme", "http://[::ffff:c0a8:1]:1", "tcp"),
878+ Entry("ipv6 address with a unix scheme", "unix://[::ffff:aca8:1002]:2", "unix"),
879+ Entry("ipv6 address with a random scheme", "random://[::ffff:a0a:a0a]:10", "random"),
486880 )
487881 })
488882
@@ -490,11 +884,16 @@ var _ = Describe("Server", func() {
490884 DescribeTable("should remove the scheme", func(in, expected string) {
491885 Expect(getListenAddress(in)).To(Equal(expected))
492886 },
493− Entry("with no scheme", "127.0.0.1:0", "127.0.0.1:0"),
494− Entry("with a tcp scheme", "tcp://127.0.0.1:0", "127.0.0.1:0"),
495− Entry("with a http scheme", "http://192.168.0.1:1", "192.168.0.1:1"),
496− Entry("with a unix scheme", "unix://172.168.16.2:2", "172.168.16.2:2"),
497− Entry("with a random scheme", "random://10.10.10.10:10", "10.10.10.10:10"),
887+ Entry("ipv4 address with no scheme", "127.0.0.1:0", "127.0.0.1:0"),
888+ Entry("ipv4 address with a tcp scheme", "tcp://127.0.0.1:0", "127.0.0.1:0"),
889+ Entry("ipv4 address with a http scheme", "http://192.168.0.1:1", "192.168.0.1:1"),
890+ Entry("ipv4 address with a unix scheme", "unix://172.168.16.2:2", "172.168.16.2:2"),
891+ Entry("ipv4 address with a random scheme", "random://10.10.10.10:10", "10.10.10.10:10"),
892+ Entry("ipv6 address with no scheme", "[::1]:0", "[::1]:0"),
893+ Entry("ipv6 address with a tcp scheme", "tcp://[::1]:0", "[::1]:0"),
894+ Entry("ipv6 address with a http scheme", "http://[::ffff:c0a8:1]:1", "[::ffff:c0a8:1]:1"),
895+ Entry("ipv6 address with a unix scheme", "unix://[::ffff:aca8:1002]:2", "[::ffff:aca8:1002]:2"),
896+ Entry("ipv6 address with a random scheme", "random://[::ffff:a0a:a0a]:10", "[::ffff:a0a:a0a]:10"),
498897 )
499898 })
500899})
pkg/sessions/redis/redis_store_test.go+1−1
@@ -54,7 +54,7 @@ var (
5454
5555var _ = BeforeSuite(func() {
5656 var err error
57− certBytes, keyBytes, err := util.GenerateCert()
57+ certBytes, keyBytes, err := util.GenerateCert("127.0.0.1")
5858 Expect(err).ToNot(HaveOccurred())
5959 certOut := new(bytes.Buffer)
6060 Expect(pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: certBytes})).To(Succeed())
pkg/util/util.go+2−2
@@ -33,7 +33,7 @@ func GetCertPool(paths []string) (*x509.CertPool, error) {
3333}
3434
3535// https://golang.org/src/crypto/tls/generate_cert.go as a function
36−func GenerateCert() ([]byte, []byte, error) {
36+func GenerateCert(ipaddr string) ([]byte, []byte, error) {
3737 var err error
3838
3939 priv, err := rsa.GenerateKey(rand.Reader, 2048)
@@ -63,7 +63,7 @@ func GenerateCert() ([]byte, []byte, error) {
6363
6464 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
6565
66− IPAddresses: []net.IP{net.ParseIP("127.0.0.1")},
66+ IPAddresses: []net.IP{net.ParseIP(ipaddr)},
6767 }
6868 certBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
6969 return certBytes, keyBytes, err