11 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
12 . "github.com/onsi/ginkgo/v2"
13 . "github.com/onsi/gomega"
14 . "github.com/onsi/gomega/gleak"
17const hello = "Hello World!"
19var _ = Describe("Server", func() {
20 handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
21 rw.Write([]byte(hello))
24 Context("NewServer", func() {
25 type newServerTableInput struct {
28 expectHTTPListener bool
29 expectTLSListener bool
33 DescribeTable("When creating the new server from the options", func(in *newServerTableInput) {
37 srv, err := NewServer(in.opts)
38 if in.expectedErr != nil {
39 Expect(err).To(MatchError(ContainSubstring(in.expectedErr.Error())))
40 Expect(srv).To(BeNil())
44 Expect(err).ToNot(HaveOccurred())
46 s, ok := srv.(*server)
47 Expect(ok).To(BeTrue())
49 Expect(s.listener != nil).To(Equal(in.expectHTTPListener))
50 if in.expectHTTPListener {
51 Expect(s.listener.Close()).To(Succeed())
53 Expect(s.tlsListener != nil).To(Equal(in.expectTLSListener))
54 if in.expectTLSListener {
55 Expect(s.tlsListener.Close()).To(Succeed())
58 Entry("with an ipv4 valid http bind address", &newServerTableInput{
61 BindAddress: "127.0.0.1:0",
64 expectHTTPListener: true,
65 expectTLSListener: false,
67 Entry("with an ipv4 valid https bind address, with no TLS config", &newServerTableInput{
70 SecureBindAddress: "127.0.0.1:0",
72 expectedErr: errors.New("error setting up TLS listener: no TLS config provided"),
73 expectHTTPListener: false,
74 expectTLSListener: false,
76 Entry("with an ipv4 valid https bind address, and valid TLS config", &newServerTableInput{
79 SecureBindAddress: "127.0.0.1:0",
81 Key: &ipv4KeyDataSource,
82 Cert: &ipv4CertDataSource,
86 expectHTTPListener: false,
87 expectTLSListener: true,
89 Entry("with a both a ipv4 valid http and ipv4 valid https bind address, and valid TLS config", &newServerTableInput{
92 BindAddress: "127.0.0.1:0",
93 SecureBindAddress: "127.0.0.1:0",
95 Key: &ipv4KeyDataSource,
96 Cert: &ipv4CertDataSource,
100 expectHTTPListener: true,
101 expectTLSListener: true,
103 Entry("with a \"-\" for the bind address", &newServerTableInput{
109 expectHTTPListener: false,
110 expectTLSListener: false,
112 Entry("with a \"-\" for the secure bind address", &newServerTableInput{
115 SecureBindAddress: "-",
118 expectHTTPListener: false,
119 expectTLSListener: false,
121 Entry("with an ipv4 invalid bind address scheme", &newServerTableInput{
124 BindAddress: "invalid://127.0.0.1:0",
126 expectedErr: errors.New("error setting up listener: listen (invalid, 127.0.0.1:0) failed: listen invalid: unknown network invalid"),
127 expectHTTPListener: false,
128 expectTLSListener: false,
130 Entry("with an ipv4 invalid secure bind address scheme", &newServerTableInput{
133 SecureBindAddress: "invalid://127.0.0.1:0",
135 Key: &ipv4KeyDataSource,
136 Cert: &ipv4CertDataSource,
140 expectHTTPListener: false,
141 expectTLSListener: true,
143 Entry("with an ipv4 invalid bind address port", &newServerTableInput{
146 BindAddress: "127.0.0.1:a",
148 expectedErr: errors.New("error setting up listener: listen (tcp, 127.0.0.1:a) failed: listen tcp: "),
149 expectHTTPListener: false,
150 expectTLSListener: false,
152 Entry("with an ipv4 invalid secure bind address port", &newServerTableInput{
155 SecureBindAddress: "127.0.0.1:a",
157 Key: &ipv4KeyDataSource,
158 Cert: &ipv4CertDataSource,
161 expectedErr: errors.New("error setting up TLS listener: listen (127.0.0.1:a) failed: listen tcp: "),
162 expectHTTPListener: false,
163 expectTLSListener: false,
165 Entry("with an ipv4 invalid TLS key", &newServerTableInput{
168 SecureBindAddress: "127.0.0.1:0",
170 Key: &options.SecretSource{
171 Value: []byte("invalid"),
173 Cert: &ipv4CertDataSource,
176 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"),
177 expectHTTPListener: false,
178 expectTLSListener: false,
180 Entry("with an ipv4 invalid TLS cert", &newServerTableInput{
183 SecureBindAddress: "127.0.0.1:0",
185 Key: &ipv4KeyDataSource,
186 Cert: &options.SecretSource{
187 Value: []byte("invalid"),
191 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"),
192 expectHTTPListener: false,
193 expectTLSListener: false,
195 Entry("with an ipv4 address, with no TLS key", &newServerTableInput{
198 SecureBindAddress: "127.0.0.1:0",
200 Cert: &ipv4CertDataSource,
203 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
204 expectHTTPListener: false,
205 expectTLSListener: false,
207 Entry("with an ipv4 address, with no TLS cert", &newServerTableInput{
210 SecureBindAddress: "127.0.0.1:0",
212 Key: &ipv4KeyDataSource,
215 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
216 expectHTTPListener: false,
217 expectTLSListener: false,
219 Entry("when the ipv4 bind address is prefixed with the http scheme", &newServerTableInput{
222 BindAddress: "http://127.0.0.1:0",
225 expectHTTPListener: true,
226 expectTLSListener: false,
228 Entry("when the ipv4 secure bind address is prefixed with the https scheme", &newServerTableInput{
231 SecureBindAddress: "https://127.0.0.1:0",
233 Key: &ipv4KeyDataSource,
234 Cert: &ipv4CertDataSource,
238 expectHTTPListener: false,
239 expectTLSListener: true,
241 Entry("with an ipv4 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
244 SecureBindAddress: "127.0.0.1:0",
246 Key: &ipv4KeyDataSource,
247 Cert: &ipv4CertDataSource,
248 MinVersion: "TLS1.3",
252 expectHTTPListener: false,
253 expectTLSListener: true,
255 Entry("with an ipv4 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
258 SecureBindAddress: "127.0.0.1:0",
260 Key: &ipv4KeyDataSource,
261 Cert: &ipv4CertDataSource,
262 MinVersion: "TLS1.42",
265 expectedErr: errors.New("error setting up TLS listener: unknown TLS MinVersion config provided"),
266 expectHTTPListener: false,
267 expectTLSListener: true,
269 Entry("with an ipv4 valid https bind address, and valid TLS config with CipherSuites", &newServerTableInput{
272 SecureBindAddress: "127.0.0.1:0",
274 Key: &ipv4KeyDataSource,
275 Cert: &ipv4CertDataSource,
276 CipherSuites: []string{
277 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
278 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
283 expectHTTPListener: false,
284 expectTLSListener: true,
286 Entry("with an ipv4 valid https bind address, and invalid TLS config with unknown CipherSuites", &newServerTableInput{
289 SecureBindAddress: "127.0.0.1:0",
291 Key: &ipv4KeyDataSource,
292 Cert: &ipv4CertDataSource,
293 CipherSuites: []string{
294 "TLS_RSA_WITH_RC4_64_SHA",
295 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
299 expectedErr: errors.New("error setting up TLS listener: could not parse cipher suites: unknown TLS cipher suite name specified \"TLS_RSA_WITH_RC4_64_SHA\""),
300 expectHTTPListener: false,
301 expectTLSListener: true,
303 Entry("with an ipv6 valid http bind address", &newServerTableInput{
306 BindAddress: "[::1]:0",
309 expectHTTPListener: true,
310 expectTLSListener: false,
313 Entry("with an ipv6 valid https bind address, with no TLS config", &newServerTableInput{
316 SecureBindAddress: "[::1]:0",
318 expectedErr: errors.New("error setting up TLS listener: no TLS config provided"),
319 expectHTTPListener: false,
320 expectTLSListener: false,
323 Entry("with an ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
326 SecureBindAddress: "[::1]:0",
328 Key: &ipv6KeyDataSource,
329 Cert: &ipv6CertDataSource,
333 expectHTTPListener: false,
334 expectTLSListener: true,
337 Entry("with a both a ipv6 valid http and ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
340 BindAddress: "[::1]:0",
341 SecureBindAddress: "[::1]:0",
343 Key: &ipv6KeyDataSource,
344 Cert: &ipv6CertDataSource,
348 expectHTTPListener: true,
349 expectTLSListener: true,
352 Entry("with an ipv6 invalid bind address scheme", &newServerTableInput{
355 BindAddress: "invalid://[::1]:0",
357 expectedErr: errors.New("error setting up listener: listen (invalid, [::1]:0) failed: listen invalid: unknown network invalid"),
358 expectHTTPListener: false,
359 expectTLSListener: false,
362 Entry("with an ipv6 invalid secure bind address scheme", &newServerTableInput{
365 SecureBindAddress: "invalid://[::1]:0",
367 Key: &ipv6KeyDataSource,
368 Cert: &ipv6CertDataSource,
372 expectHTTPListener: false,
373 expectTLSListener: true,
376 Entry("with an ipv6 invalid bind address port", &newServerTableInput{
379 BindAddress: "[::1]:a",
381 expectedErr: errors.New("error setting up listener: listen (tcp, [::1]:a) failed: listen tcp: "),
382 expectHTTPListener: false,
383 expectTLSListener: false,
386 Entry("with an ipv6 invalid secure bind address port", &newServerTableInput{
389 SecureBindAddress: "[::1]:a",
391 Key: &ipv6KeyDataSource,
392 Cert: &ipv6CertDataSource,
395 expectedErr: errors.New("error setting up TLS listener: listen ([::1]:a) failed: listen tcp: "),
396 expectHTTPListener: false,
397 expectTLSListener: false,
400 Entry("with an ipv6 invalid TLS key", &newServerTableInput{
403 SecureBindAddress: "[::1]:0",
405 Key: &options.SecretSource{
406 Value: []byte("invalid"),
408 Cert: &ipv6CertDataSource,
411 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"),
412 expectHTTPListener: false,
413 expectTLSListener: false,
416 Entry("with an ipv6 invalid TLS cert", &newServerTableInput{
419 SecureBindAddress: "[::1]:0",
421 Key: &ipv6KeyDataSource,
422 Cert: &options.SecretSource{
423 Value: []byte("invalid"),
427 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"),
428 expectHTTPListener: false,
429 expectTLSListener: false,
432 Entry("with an ipv6 address, with no TLS key", &newServerTableInput{
435 SecureBindAddress: "[::1]:0",
437 Cert: &ipv6CertDataSource,
440 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
441 expectHTTPListener: false,
442 expectTLSListener: false,
445 Entry("with an ipv6 address, with no TLS cert", &newServerTableInput{
448 SecureBindAddress: "[::1]:0",
450 Key: &ipv6KeyDataSource,
453 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
454 expectHTTPListener: false,
455 expectTLSListener: false,
458 Entry("when the ipv6 bind address is prefixed with the http scheme", &newServerTableInput{
461 BindAddress: "http://[::1]:0",
464 expectHTTPListener: true,
465 expectTLSListener: false,
468 Entry("when the ipv6 secure bind address is prefixed with the https scheme", &newServerTableInput{
471 SecureBindAddress: "https://[::1]:0",
473 Key: &ipv6KeyDataSource,
474 Cert: &ipv6CertDataSource,
478 expectHTTPListener: false,
479 expectTLSListener: true,
482 Entry("with an ipv6 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
485 SecureBindAddress: "[::1]:0",
487 Key: &ipv6KeyDataSource,
488 Cert: &ipv6CertDataSource,
489 MinVersion: "TLS1.3",
493 expectHTTPListener: false,
494 expectTLSListener: true,
497 Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
500 SecureBindAddress: "[::1]:0",
502 Key: &ipv6KeyDataSource,
503 Cert: &ipv6CertDataSource,
504 MinVersion: "TLS1.42",
507 expectedErr: errors.New("error setting up TLS listener: unknown TLS MinVersion config provided"),
508 expectHTTPListener: false,
509 expectTLSListener: true,
512 Entry("with an ipv6 valid https bind address, and valid TLS config with CipherSuites", &newServerTableInput{
515 SecureBindAddress: "[::1]:0",
517 Key: &ipv4KeyDataSource,
518 Cert: &ipv4CertDataSource,
519 CipherSuites: []string{
520 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
521 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
526 expectHTTPListener: false,
527 expectTLSListener: true,
530 Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown CipherSuites", &newServerTableInput{
533 SecureBindAddress: "[::1]:0",
535 Key: &ipv4KeyDataSource,
536 Cert: &ipv4CertDataSource,
537 CipherSuites: []string{
538 "TLS_RSA_WITH_RC4_64_SHA",
539 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
543 expectedErr: errors.New("error setting up TLS listener: could not parse cipher suites: unknown TLS cipher suite name specified \"TLS_RSA_WITH_RC4_64_SHA\""),
544 expectHTTPListener: false,
545 expectTLSListener: true,
551 Context("Start", func() {
553 var ctx context.Context
554 var cancel context.CancelFunc
557 ctx, cancel = context.WithCancel(context.Background())
562 Eventually(Goroutines).ShouldNot(HaveLeaked())
566 Context("with an ipv4 http server", func() {
567 var listenAddr string
571 srv, err = NewServer(Opts{
573 BindAddress: "127.0.0.1:0",
575 Expect(err).ToNot(HaveOccurred())
577 s, ok := srv.(*server)
578 Expect(ok).To(BeTrue())
580 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
583 It("Starts the server and serves the handler", func() {
585 defer GinkgoRecover()
586 Expect(srv.Start(ctx)).To(Succeed())
589 resp, err := httpGet(ctx, listenAddr)
590 Expect(err).ToNot(HaveOccurred())
591 Expect(resp.StatusCode).To(Equal(http.StatusOK))
593 body, err := io.ReadAll(resp.Body)
594 Expect(err).ToNot(HaveOccurred())
595 Expect(string(body)).To(Equal(hello))
598 It("Stops the server when the context is cancelled", func() {
600 defer GinkgoRecover()
601 Expect(srv.Start(ctx)).To(Succeed())
604 _, err := httpGet(ctx, listenAddr)
605 Expect(err).ToNot(HaveOccurred())
609 Eventually(func() error {
610 _, err := httpGet(ctx, listenAddr)
612 }).Should(HaveOccurred())
616 Context("with an ipv4 https server", func() {
617 var secureListenAddr string
621 srv, err = NewServer(Opts{
623 SecureBindAddress: "127.0.0.1:0",
625 Key: &ipv4KeyDataSource,
626 Cert: &ipv4CertDataSource,
629 Expect(err).ToNot(HaveOccurred())
631 s, ok := srv.(*server)
632 Expect(ok).To(BeTrue())
634 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
637 It("Starts the server and serves the handler", func() {
639 defer GinkgoRecover()
640 Expect(srv.Start(ctx)).To(Succeed())
643 resp, err := httpGet(ctx, secureListenAddr)
644 Expect(err).ToNot(HaveOccurred())
645 Expect(resp.StatusCode).To(Equal(http.StatusOK))
647 body, err := io.ReadAll(resp.Body)
648 Expect(err).ToNot(HaveOccurred())
649 Expect(string(body)).To(Equal(hello))
652 It("Stops the server when the context is cancelled", func() {
654 defer GinkgoRecover()
655 Expect(srv.Start(ctx)).To(Succeed())
658 _, err := httpGet(ctx, secureListenAddr)
659 Expect(err).ToNot(HaveOccurred())
663 Eventually(func() error {
664 _, err := httpGet(ctx, secureListenAddr)
666 }).Should(HaveOccurred())
669 It("Serves the certificate provided", func() {
671 defer GinkgoRecover()
672 Expect(srv.Start(ctx)).To(Succeed())
675 resp, err := httpGet(ctx, secureListenAddr)
676 Expect(err).ToNot(HaveOccurred())
677 Expect(resp.StatusCode).To(Equal(http.StatusOK))
679 Expect(resp.TLS.VerifiedChains).Should(HaveLen(1))
680 Expect(resp.TLS.VerifiedChains[0]).Should(HaveLen(1))
681 Expect(resp.TLS.VerifiedChains[0][0].Raw).Should(Equal(ipv4CertData))
685 Context("with both an ipv4 http and an ipv4 https server", func() {
686 var listenAddr, secureListenAddr string
690 srv, err = NewServer(Opts{
692 BindAddress: "127.0.0.1:0",
693 SecureBindAddress: "127.0.0.1:0",
695 Key: &ipv4KeyDataSource,
696 Cert: &ipv4CertDataSource,
699 Expect(err).ToNot(HaveOccurred())
701 s, ok := srv.(*server)
702 Expect(ok).To(BeTrue())
704 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
705 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
708 It("Starts the server and serves the handler on http", func() {
710 defer GinkgoRecover()
711 Expect(srv.Start(ctx)).To(Succeed())
714 resp, err := httpGet(ctx, listenAddr)
715 Expect(err).ToNot(HaveOccurred())
716 Expect(resp.StatusCode).To(Equal(http.StatusOK))
718 body, err := io.ReadAll(resp.Body)
719 Expect(err).ToNot(HaveOccurred())
720 Expect(string(body)).To(Equal(hello))
723 It("Starts the server and serves the handler on https", func() {
725 defer GinkgoRecover()
726 Expect(srv.Start(ctx)).To(Succeed())
729 resp, err := httpGet(ctx, secureListenAddr)
730 Expect(err).ToNot(HaveOccurred())
731 Expect(resp.StatusCode).To(Equal(http.StatusOK))
733 body, err := io.ReadAll(resp.Body)
734 Expect(err).ToNot(HaveOccurred())
735 Expect(string(body)).To(Equal(hello))
738 It("Stops both servers when the context is cancelled", func() {
740 defer GinkgoRecover()
741 Expect(srv.Start(ctx)).To(Succeed())
744 _, err := httpGet(ctx, listenAddr)
745 Expect(err).ToNot(HaveOccurred())
746 _, err = httpGet(ctx, secureListenAddr)
747 Expect(err).ToNot(HaveOccurred())
751 Eventually(func() error {
752 _, err := httpGet(ctx, listenAddr)
754 }).Should(HaveOccurred())
755 Eventually(func() error {
756 _, err := httpGet(ctx, secureListenAddr)
758 }).Should(HaveOccurred())
762 Context("with an ipv6 http server", func() {
763 var listenAddr string
768 srv, err = NewServer(Opts{
770 BindAddress: "[::1]:0",
772 Expect(err).ToNot(HaveOccurred())
774 s, ok := srv.(*server)
775 Expect(ok).To(BeTrue())
777 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
780 It("Starts the server and serves the handler", func() {
782 defer GinkgoRecover()
783 Expect(srv.Start(ctx)).To(Succeed())
786 resp, err := httpGet(ctx, listenAddr)
787 Expect(err).ToNot(HaveOccurred())
788 Expect(resp.StatusCode).To(Equal(http.StatusOK))
790 body, err := io.ReadAll(resp.Body)
791 Expect(err).ToNot(HaveOccurred())
792 Expect(string(body)).To(Equal(hello))
795 It("Stops the server when the context is cancelled", func() {
797 defer GinkgoRecover()
798 Expect(srv.Start(ctx)).To(Succeed())
801 _, err := httpGet(ctx, listenAddr)
802 Expect(err).ToNot(HaveOccurred())
806 Eventually(func() error {
807 _, err := httpGet(ctx, listenAddr)
809 }).Should(HaveOccurred())
813 Context("with an ipv6 https server", func() {
814 var secureListenAddr string
819 srv, err = NewServer(Opts{
821 SecureBindAddress: "[::1]:0",
823 Key: &ipv6KeyDataSource,
824 Cert: &ipv6CertDataSource,
827 Expect(err).ToNot(HaveOccurred())
829 s, ok := srv.(*server)
830 Expect(ok).To(BeTrue())
832 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
835 It("Starts the server and serves the handler", func() {
837 defer GinkgoRecover()
838 Expect(srv.Start(ctx)).To(Succeed())
841 resp, err := httpGet(ctx, secureListenAddr)
842 Expect(err).ToNot(HaveOccurred())
843 Expect(resp.StatusCode).To(Equal(http.StatusOK))
845 body, err := io.ReadAll(resp.Body)
846 Expect(err).ToNot(HaveOccurred())
847 Expect(string(body)).To(Equal(hello))
850 It("Stops the server when the context is cancelled", func() {
852 defer GinkgoRecover()
853 Expect(srv.Start(ctx)).To(Succeed())
856 _, err := httpGet(ctx, secureListenAddr)
857 Expect(err).ToNot(HaveOccurred())
861 Eventually(func() error {
862 _, err := httpGet(ctx, secureListenAddr)
864 }).Should(HaveOccurred())
867 It("Serves the certificate provided", func() {
869 defer GinkgoRecover()
870 Expect(srv.Start(ctx)).To(Succeed())
873 resp, err := httpGet(ctx, secureListenAddr)
874 Expect(err).ToNot(HaveOccurred())
875 Expect(resp.StatusCode).To(Equal(http.StatusOK))
877 Expect(resp.TLS.VerifiedChains).Should(HaveLen(1))
878 Expect(resp.TLS.VerifiedChains[0]).Should(HaveLen(1))
879 Expect(resp.TLS.VerifiedChains[0][0].Raw).Should(Equal(ipv6CertData))
883 Context("with both an ipv6 http and an ipv6 https server", func() {
884 var listenAddr, secureListenAddr string
889 srv, err = NewServer(Opts{
891 BindAddress: "[::1]:0",
892 SecureBindAddress: "[::1]:0",
894 Key: &ipv6KeyDataSource,
895 Cert: &ipv6CertDataSource,
898 Expect(err).ToNot(HaveOccurred())
900 s, ok := srv.(*server)
901 Expect(ok).To(BeTrue())
903 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
904 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
907 It("Starts the server and serves the handler on http", func() {
909 defer GinkgoRecover()
910 Expect(srv.Start(ctx)).To(Succeed())
913 resp, err := httpGet(ctx, listenAddr)
914 Expect(err).ToNot(HaveOccurred())
915 Expect(resp.StatusCode).To(Equal(http.StatusOK))
917 body, err := io.ReadAll(resp.Body)
918 Expect(err).ToNot(HaveOccurred())
919 Expect(string(body)).To(Equal(hello))
922 It("Starts the server and serves the handler on https", func() {
924 defer GinkgoRecover()
925 Expect(srv.Start(ctx)).To(Succeed())
928 resp, err := httpGet(ctx, secureListenAddr)
929 Expect(err).ToNot(HaveOccurred())
930 Expect(resp.StatusCode).To(Equal(http.StatusOK))
932 body, err := io.ReadAll(resp.Body)
933 Expect(err).ToNot(HaveOccurred())
934 Expect(string(body)).To(Equal(hello))
937 It("Stops both servers when the context is cancelled", func() {
939 defer GinkgoRecover()
940 Expect(srv.Start(ctx)).To(Succeed())
943 _, err := httpGet(ctx, listenAddr)
944 Expect(err).ToNot(HaveOccurred())
945 _, err = httpGet(ctx, secureListenAddr)
946 Expect(err).ToNot(HaveOccurred())
950 Eventually(func() error {
951 _, err := httpGet(ctx, listenAddr)
953 }).Should(HaveOccurred())
954 Eventually(func() error {
955 _, err := httpGet(ctx, secureListenAddr)
957 }).Should(HaveOccurred())
962 Context("getNetworkScheme", func() {
963 DescribeTable("should return the scheme", func(in, expected string) {
964 Expect(getNetworkScheme(in)).To(Equal(expected))
966 Entry("ipv4 address with no scheme", "127.0.0.1:0", "tcp"),
967 Entry("ipv4 address with a tcp scheme", "tcp://127.0.0.1:0", "tcp"),
968 Entry("ipv4 address with a http scheme", "http://192.168.0.1:1", "tcp"),
969 Entry("ipv4 address with a unix scheme", "unix://172.168.16.2:2", "unix"),
970 Entry("ipv4 address with a random scheme", "random://10.10.10.10:10", "random"),
971 Entry("ipv6 address with no scheme", "[::1]:0", "tcp"),
972 Entry("ipv6 address with a tcp scheme", "tcp://[::1]:0", "tcp"),
973 Entry("ipv6 address with a http scheme", "http://[::ffff:c0a8:1]:1", "tcp"),
974 Entry("ipv6 address with a unix scheme", "unix://[::ffff:aca8:1002]:2", "unix"),
975 Entry("ipv6 address with a random scheme", "random://[::ffff:a0a:a0a]:10", "random"),
979 Context("getListenAddress", func() {
980 DescribeTable("should remove the scheme", func(in, expected string) {
981 Expect(getListenAddress(in)).To(Equal(expected))
983 Entry("ipv4 address with no scheme", "127.0.0.1:0", "127.0.0.1:0"),
984 Entry("ipv4 address with a tcp scheme", "tcp://127.0.0.1:0", "127.0.0.1:0"),
985 Entry("ipv4 address with a http scheme", "http://192.168.0.1:1", "192.168.0.1:1"),
986 Entry("ipv4 address with a unix scheme", "unix://172.168.16.2:2", "172.168.16.2:2"),
987 Entry("ipv4 address with a random scheme", "random://10.10.10.10:10", "10.10.10.10:10"),
988 Entry("ipv6 address with no scheme", "[::1]:0", "[::1]:0"),
989 Entry("ipv6 address with a tcp scheme", "tcp://[::1]:0", "[::1]:0"),
990 Entry("ipv6 address with a http scheme", "http://[::ffff:c0a8:1]:1", "[::ffff:c0a8:1]:1"),
991 Entry("ipv6 address with a unix scheme", "unix://[::ffff:aca8:1002]:2", "[::ffff:aca8:1002]:2"),
992 Entry("ipv6 address with a random scheme", "random://[::ffff:a0a:a0a]:10", "[::ffff:a0a:a0a]:10"),
997func skipDevContainer() {
998 if os.Getenv("DEVCONTAINER") != "" {
999 Skip("Skipping testing in DevContainer environment")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list