11 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
12 . "github.com/onsi/ginkgo"
13 . "github.com/onsi/ginkgo/extensions/table"
14 . "github.com/onsi/gomega"
15 . "github.com/onsi/gomega/gleak"
18const hello = "Hello World!"
20var _ = Describe("Server", func() {
21 handler := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
22 rw.Write([]byte(hello))
25 Context("NewServer", func() {
26 type newServerTableInput struct {
29 expectHTTPListener bool
30 expectTLSListener bool
34 DescribeTable("When creating the new server from the options", func(in *newServerTableInput) {
38 srv, err := NewServer(in.opts)
39 if in.expectedErr != nil {
40 Expect(err).To(MatchError(ContainSubstring(in.expectedErr.Error())))
41 Expect(srv).To(BeNil())
45 Expect(err).ToNot(HaveOccurred())
47 s, ok := srv.(*server)
48 Expect(ok).To(BeTrue())
50 Expect(s.listener != nil).To(Equal(in.expectHTTPListener))
51 if in.expectHTTPListener {
52 Expect(s.listener.Close()).To(Succeed())
54 Expect(s.tlsListener != nil).To(Equal(in.expectTLSListener))
55 if in.expectTLSListener {
56 Expect(s.tlsListener.Close()).To(Succeed())
59 Entry("with an ipv4 valid http bind address", &newServerTableInput{
62 BindAddress: "127.0.0.1:0",
65 expectHTTPListener: true,
66 expectTLSListener: false,
68 Entry("with an ipv4 valid https bind address, with no TLS config", &newServerTableInput{
71 SecureBindAddress: "127.0.0.1:0",
73 expectedErr: errors.New("error setting up TLS listener: no TLS config provided"),
74 expectHTTPListener: false,
75 expectTLSListener: false,
77 Entry("with an ipv4 valid https bind address, and valid TLS config", &newServerTableInput{
80 SecureBindAddress: "127.0.0.1:0",
82 Key: &ipv4KeyDataSource,
83 Cert: &ipv4CertDataSource,
87 expectHTTPListener: false,
88 expectTLSListener: true,
90 Entry("with a both a ipv4 valid http and ipv4 valid https bind address, and valid TLS config", &newServerTableInput{
93 BindAddress: "127.0.0.1:0",
94 SecureBindAddress: "127.0.0.1:0",
96 Key: &ipv4KeyDataSource,
97 Cert: &ipv4CertDataSource,
101 expectHTTPListener: true,
102 expectTLSListener: true,
104 Entry("with a \"-\" for the bind address", &newServerTableInput{
110 expectHTTPListener: false,
111 expectTLSListener: false,
113 Entry("with a \"-\" for the secure bind address", &newServerTableInput{
116 SecureBindAddress: "-",
119 expectHTTPListener: false,
120 expectTLSListener: false,
122 Entry("with an ipv4 invalid bind address scheme", &newServerTableInput{
125 BindAddress: "invalid://127.0.0.1:0",
127 expectedErr: errors.New("error setting up listener: listen (invalid, 127.0.0.1:0) failed: listen invalid: unknown network invalid"),
128 expectHTTPListener: false,
129 expectTLSListener: false,
131 Entry("with an ipv4 invalid secure bind address scheme", &newServerTableInput{
134 SecureBindAddress: "invalid://127.0.0.1:0",
136 Key: &ipv4KeyDataSource,
137 Cert: &ipv4CertDataSource,
141 expectHTTPListener: false,
142 expectTLSListener: true,
144 Entry("with an ipv4 invalid bind address port", &newServerTableInput{
147 BindAddress: "127.0.0.1:a",
149 expectedErr: errors.New("error setting up listener: listen (tcp, 127.0.0.1:a) failed: listen tcp: "),
150 expectHTTPListener: false,
151 expectTLSListener: false,
153 Entry("with an ipv4 invalid secure bind address port", &newServerTableInput{
156 SecureBindAddress: "127.0.0.1:a",
158 Key: &ipv4KeyDataSource,
159 Cert: &ipv4CertDataSource,
162 expectedErr: errors.New("error setting up TLS listener: listen (127.0.0.1:a) failed: listen tcp: "),
163 expectHTTPListener: false,
164 expectTLSListener: false,
166 Entry("with an ipv4 invalid TLS key", &newServerTableInput{
169 SecureBindAddress: "127.0.0.1:0",
171 Key: &options.SecretSource{
172 Value: []byte("invalid"),
174 Cert: &ipv4CertDataSource,
177 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"),
178 expectHTTPListener: false,
179 expectTLSListener: false,
181 Entry("with an ipv4 invalid TLS cert", &newServerTableInput{
184 SecureBindAddress: "127.0.0.1:0",
186 Key: &ipv4KeyDataSource,
187 Cert: &options.SecretSource{
188 Value: []byte("invalid"),
192 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"),
193 expectHTTPListener: false,
194 expectTLSListener: false,
196 Entry("with an ipv4 address, with no TLS key", &newServerTableInput{
199 SecureBindAddress: "127.0.0.1:0",
201 Cert: &ipv4CertDataSource,
204 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
205 expectHTTPListener: false,
206 expectTLSListener: false,
208 Entry("with an ipv4 address, with no TLS cert", &newServerTableInput{
211 SecureBindAddress: "127.0.0.1:0",
213 Key: &ipv4KeyDataSource,
216 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
217 expectHTTPListener: false,
218 expectTLSListener: false,
220 Entry("when the ipv4 bind address is prefixed with the http scheme", &newServerTableInput{
223 BindAddress: "http://127.0.0.1:0",
226 expectHTTPListener: true,
227 expectTLSListener: false,
229 Entry("when the ipv4 secure bind address is prefixed with the https scheme", &newServerTableInput{
232 SecureBindAddress: "https://127.0.0.1:0",
234 Key: &ipv4KeyDataSource,
235 Cert: &ipv4CertDataSource,
239 expectHTTPListener: false,
240 expectTLSListener: true,
242 Entry("with an ipv4 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
245 SecureBindAddress: "127.0.0.1:0",
247 Key: &ipv4KeyDataSource,
248 Cert: &ipv4CertDataSource,
249 MinVersion: "TLS1.3",
253 expectHTTPListener: false,
254 expectTLSListener: true,
256 Entry("with an ipv4 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
259 SecureBindAddress: "127.0.0.1:0",
261 Key: &ipv4KeyDataSource,
262 Cert: &ipv4CertDataSource,
263 MinVersion: "TLS1.42",
266 expectedErr: errors.New("error setting up TLS listener: unknown TLS MinVersion config provided"),
267 expectHTTPListener: false,
268 expectTLSListener: true,
270 Entry("with an ipv4 valid https bind address, and valid TLS config with CipherSuites", &newServerTableInput{
273 SecureBindAddress: "127.0.0.1:0",
275 Key: &ipv4KeyDataSource,
276 Cert: &ipv4CertDataSource,
277 CipherSuites: []string{
278 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
279 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
284 expectHTTPListener: false,
285 expectTLSListener: true,
287 Entry("with an ipv4 valid https bind address, and invalid TLS config with unknown CipherSuites", &newServerTableInput{
290 SecureBindAddress: "127.0.0.1:0",
292 Key: &ipv4KeyDataSource,
293 Cert: &ipv4CertDataSource,
294 CipherSuites: []string{
295 "TLS_RSA_WITH_RC4_64_SHA",
296 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
300 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\""),
301 expectHTTPListener: false,
302 expectTLSListener: true,
304 Entry("with an ipv6 valid http bind address", &newServerTableInput{
307 BindAddress: "[::1]:0",
310 expectHTTPListener: true,
311 expectTLSListener: false,
314 Entry("with an ipv6 valid https bind address, with no TLS config", &newServerTableInput{
317 SecureBindAddress: "[::1]:0",
319 expectedErr: errors.New("error setting up TLS listener: no TLS config provided"),
320 expectHTTPListener: false,
321 expectTLSListener: false,
324 Entry("with an ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
327 SecureBindAddress: "[::1]:0",
329 Key: &ipv6KeyDataSource,
330 Cert: &ipv6CertDataSource,
334 expectHTTPListener: false,
335 expectTLSListener: true,
338 Entry("with a both a ipv6 valid http and ipv6 valid https bind address, and valid TLS config", &newServerTableInput{
341 BindAddress: "[::1]:0",
342 SecureBindAddress: "[::1]:0",
344 Key: &ipv6KeyDataSource,
345 Cert: &ipv6CertDataSource,
349 expectHTTPListener: true,
350 expectTLSListener: true,
353 Entry("with an ipv6 invalid bind address scheme", &newServerTableInput{
356 BindAddress: "invalid://[::1]:0",
358 expectedErr: errors.New("error setting up listener: listen (invalid, [::1]:0) failed: listen invalid: unknown network invalid"),
359 expectHTTPListener: false,
360 expectTLSListener: false,
363 Entry("with an ipv6 invalid secure bind address scheme", &newServerTableInput{
366 SecureBindAddress: "invalid://[::1]:0",
368 Key: &ipv6KeyDataSource,
369 Cert: &ipv6CertDataSource,
373 expectHTTPListener: false,
374 expectTLSListener: true,
377 Entry("with an ipv6 invalid bind address port", &newServerTableInput{
380 BindAddress: "[::1]:a",
382 expectedErr: errors.New("error setting up listener: listen (tcp, [::1]:a) failed: listen tcp: "),
383 expectHTTPListener: false,
384 expectTLSListener: false,
387 Entry("with an ipv6 invalid secure bind address port", &newServerTableInput{
390 SecureBindAddress: "[::1]:a",
392 Key: &ipv6KeyDataSource,
393 Cert: &ipv6CertDataSource,
396 expectedErr: errors.New("error setting up TLS listener: listen ([::1]:a) failed: listen tcp: "),
397 expectHTTPListener: false,
398 expectTLSListener: false,
401 Entry("with an ipv6 invalid TLS key", &newServerTableInput{
404 SecureBindAddress: "[::1]:0",
406 Key: &options.SecretSource{
407 Value: []byte("invalid"),
409 Cert: &ipv6CertDataSource,
412 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"),
413 expectHTTPListener: false,
414 expectTLSListener: false,
417 Entry("with an ipv6 invalid TLS cert", &newServerTableInput{
420 SecureBindAddress: "[::1]:0",
422 Key: &ipv6KeyDataSource,
423 Cert: &options.SecretSource{
424 Value: []byte("invalid"),
428 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"),
429 expectHTTPListener: false,
430 expectTLSListener: false,
433 Entry("with an ipv6 address, with no TLS key", &newServerTableInput{
436 SecureBindAddress: "[::1]:0",
438 Cert: &ipv6CertDataSource,
441 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load key data: no configuration provided"),
442 expectHTTPListener: false,
443 expectTLSListener: false,
446 Entry("with an ipv6 address, with no TLS cert", &newServerTableInput{
449 SecureBindAddress: "[::1]:0",
451 Key: &ipv6KeyDataSource,
454 expectedErr: errors.New("error setting up TLS listener: could not load certificate: could not load cert data: no configuration provided"),
455 expectHTTPListener: false,
456 expectTLSListener: false,
459 Entry("when the ipv6 bind address is prefixed with the http scheme", &newServerTableInput{
462 BindAddress: "http://[::1]:0",
465 expectHTTPListener: true,
466 expectTLSListener: false,
469 Entry("when the ipv6 secure bind address is prefixed with the https scheme", &newServerTableInput{
472 SecureBindAddress: "https://[::1]:0",
474 Key: &ipv6KeyDataSource,
475 Cert: &ipv6CertDataSource,
479 expectHTTPListener: false,
480 expectTLSListener: true,
483 Entry("with an ipv6 valid https bind address, and valid TLS config with MinVersion", &newServerTableInput{
486 SecureBindAddress: "[::1]:0",
488 Key: &ipv6KeyDataSource,
489 Cert: &ipv6CertDataSource,
490 MinVersion: "TLS1.3",
494 expectHTTPListener: false,
495 expectTLSListener: true,
498 Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown MinVersion", &newServerTableInput{
501 SecureBindAddress: "[::1]:0",
503 Key: &ipv6KeyDataSource,
504 Cert: &ipv6CertDataSource,
505 MinVersion: "TLS1.42",
508 expectedErr: errors.New("error setting up TLS listener: unknown TLS MinVersion config provided"),
509 expectHTTPListener: false,
510 expectTLSListener: true,
513 Entry("with an ipv6 valid https bind address, and valid TLS config with CipherSuites", &newServerTableInput{
516 SecureBindAddress: "[::1]:0",
518 Key: &ipv4KeyDataSource,
519 Cert: &ipv4CertDataSource,
520 CipherSuites: []string{
521 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
522 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
527 expectHTTPListener: false,
528 expectTLSListener: true,
531 Entry("with an ipv6 valid https bind address, and invalid TLS config with unknown CipherSuites", &newServerTableInput{
534 SecureBindAddress: "[::1]:0",
536 Key: &ipv4KeyDataSource,
537 Cert: &ipv4CertDataSource,
538 CipherSuites: []string{
539 "TLS_RSA_WITH_RC4_64_SHA",
540 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
544 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\""),
545 expectHTTPListener: false,
546 expectTLSListener: true,
552 Context("Start", func() {
554 var ctx context.Context
555 var cancel context.CancelFunc
558 ctx, cancel = context.WithCancel(context.Background())
563 Eventually(Goroutines).ShouldNot(HaveLeaked())
567 Context("with an ipv4 http server", func() {
568 var listenAddr string
572 srv, err = NewServer(Opts{
574 BindAddress: "127.0.0.1:0",
576 Expect(err).ToNot(HaveOccurred())
578 s, ok := srv.(*server)
579 Expect(ok).To(BeTrue())
581 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
584 It("Starts the server and serves the handler", func() {
586 defer GinkgoRecover()
587 Expect(srv.Start(ctx)).To(Succeed())
590 resp, err := httpGet(ctx, listenAddr)
591 Expect(err).ToNot(HaveOccurred())
592 Expect(resp.StatusCode).To(Equal(http.StatusOK))
594 body, err := io.ReadAll(resp.Body)
595 Expect(err).ToNot(HaveOccurred())
596 Expect(string(body)).To(Equal(hello))
599 It("Stops the server when the context is cancelled", func() {
601 defer GinkgoRecover()
602 Expect(srv.Start(ctx)).To(Succeed())
605 _, err := httpGet(ctx, listenAddr)
606 Expect(err).ToNot(HaveOccurred())
610 Eventually(func() error {
611 _, err := httpGet(ctx, listenAddr)
613 }).Should(HaveOccurred())
617 Context("with an ipv4 https server", func() {
618 var secureListenAddr string
622 srv, err = NewServer(Opts{
624 SecureBindAddress: "127.0.0.1:0",
626 Key: &ipv4KeyDataSource,
627 Cert: &ipv4CertDataSource,
630 Expect(err).ToNot(HaveOccurred())
632 s, ok := srv.(*server)
633 Expect(ok).To(BeTrue())
635 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
638 It("Starts the server and serves the handler", func() {
640 defer GinkgoRecover()
641 Expect(srv.Start(ctx)).To(Succeed())
644 resp, err := httpGet(ctx, secureListenAddr)
645 Expect(err).ToNot(HaveOccurred())
646 Expect(resp.StatusCode).To(Equal(http.StatusOK))
648 body, err := io.ReadAll(resp.Body)
649 Expect(err).ToNot(HaveOccurred())
650 Expect(string(body)).To(Equal(hello))
653 It("Stops the server when the context is cancelled", func() {
655 defer GinkgoRecover()
656 Expect(srv.Start(ctx)).To(Succeed())
659 _, err := httpGet(ctx, secureListenAddr)
660 Expect(err).ToNot(HaveOccurred())
664 Eventually(func() error {
665 _, err := httpGet(ctx, secureListenAddr)
667 }).Should(HaveOccurred())
670 It("Serves the certificate provided", func() {
672 defer GinkgoRecover()
673 Expect(srv.Start(ctx)).To(Succeed())
676 resp, err := httpGet(ctx, secureListenAddr)
677 Expect(err).ToNot(HaveOccurred())
678 Expect(resp.StatusCode).To(Equal(http.StatusOK))
680 Expect(resp.TLS.VerifiedChains).Should(HaveLen(1))
681 Expect(resp.TLS.VerifiedChains[0]).Should(HaveLen(1))
682 Expect(resp.TLS.VerifiedChains[0][0].Raw).Should(Equal(ipv4CertData))
686 Context("with both an ipv4 http and an ipv4 https server", func() {
687 var listenAddr, secureListenAddr string
691 srv, err = NewServer(Opts{
693 BindAddress: "127.0.0.1:0",
694 SecureBindAddress: "127.0.0.1:0",
696 Key: &ipv4KeyDataSource,
697 Cert: &ipv4CertDataSource,
700 Expect(err).ToNot(HaveOccurred())
702 s, ok := srv.(*server)
703 Expect(ok).To(BeTrue())
705 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
706 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
709 It("Starts the server and serves the handler on http", func() {
711 defer GinkgoRecover()
712 Expect(srv.Start(ctx)).To(Succeed())
715 resp, err := httpGet(ctx, listenAddr)
716 Expect(err).ToNot(HaveOccurred())
717 Expect(resp.StatusCode).To(Equal(http.StatusOK))
719 body, err := io.ReadAll(resp.Body)
720 Expect(err).ToNot(HaveOccurred())
721 Expect(string(body)).To(Equal(hello))
724 It("Starts the server and serves the handler on https", func() {
726 defer GinkgoRecover()
727 Expect(srv.Start(ctx)).To(Succeed())
730 resp, err := httpGet(ctx, secureListenAddr)
731 Expect(err).ToNot(HaveOccurred())
732 Expect(resp.StatusCode).To(Equal(http.StatusOK))
734 body, err := io.ReadAll(resp.Body)
735 Expect(err).ToNot(HaveOccurred())
736 Expect(string(body)).To(Equal(hello))
739 It("Stops both servers when the context is cancelled", func() {
741 defer GinkgoRecover()
742 Expect(srv.Start(ctx)).To(Succeed())
745 _, err := httpGet(ctx, listenAddr)
746 Expect(err).ToNot(HaveOccurred())
747 _, err = httpGet(ctx, secureListenAddr)
748 Expect(err).ToNot(HaveOccurred())
752 Eventually(func() error {
753 _, err := httpGet(ctx, listenAddr)
755 }).Should(HaveOccurred())
756 Eventually(func() error {
757 _, err := httpGet(ctx, secureListenAddr)
759 }).Should(HaveOccurred())
763 Context("with an ipv6 http server", func() {
764 var listenAddr string
769 srv, err = NewServer(Opts{
771 BindAddress: "[::1]:0",
773 Expect(err).ToNot(HaveOccurred())
775 s, ok := srv.(*server)
776 Expect(ok).To(BeTrue())
778 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
781 It("Starts the server and serves the handler", func() {
783 defer GinkgoRecover()
784 Expect(srv.Start(ctx)).To(Succeed())
787 resp, err := httpGet(ctx, listenAddr)
788 Expect(err).ToNot(HaveOccurred())
789 Expect(resp.StatusCode).To(Equal(http.StatusOK))
791 body, err := io.ReadAll(resp.Body)
792 Expect(err).ToNot(HaveOccurred())
793 Expect(string(body)).To(Equal(hello))
796 It("Stops the server when the context is cancelled", func() {
798 defer GinkgoRecover()
799 Expect(srv.Start(ctx)).To(Succeed())
802 _, err := httpGet(ctx, listenAddr)
803 Expect(err).ToNot(HaveOccurred())
807 Eventually(func() error {
808 _, err := httpGet(ctx, listenAddr)
810 }).Should(HaveOccurred())
814 Context("with an ipv6 https server", func() {
815 var secureListenAddr string
820 srv, err = NewServer(Opts{
822 SecureBindAddress: "[::1]:0",
824 Key: &ipv6KeyDataSource,
825 Cert: &ipv6CertDataSource,
828 Expect(err).ToNot(HaveOccurred())
830 s, ok := srv.(*server)
831 Expect(ok).To(BeTrue())
833 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
836 It("Starts the server and serves the handler", func() {
838 defer GinkgoRecover()
839 Expect(srv.Start(ctx)).To(Succeed())
842 resp, err := httpGet(ctx, secureListenAddr)
843 Expect(err).ToNot(HaveOccurred())
844 Expect(resp.StatusCode).To(Equal(http.StatusOK))
846 body, err := io.ReadAll(resp.Body)
847 Expect(err).ToNot(HaveOccurred())
848 Expect(string(body)).To(Equal(hello))
851 It("Stops the server when the context is cancelled", func() {
853 defer GinkgoRecover()
854 Expect(srv.Start(ctx)).To(Succeed())
857 _, err := httpGet(ctx, secureListenAddr)
858 Expect(err).ToNot(HaveOccurred())
862 Eventually(func() error {
863 _, err := httpGet(ctx, secureListenAddr)
865 }).Should(HaveOccurred())
868 It("Serves the certificate provided", func() {
870 defer GinkgoRecover()
871 Expect(srv.Start(ctx)).To(Succeed())
874 resp, err := httpGet(ctx, secureListenAddr)
875 Expect(err).ToNot(HaveOccurred())
876 Expect(resp.StatusCode).To(Equal(http.StatusOK))
878 Expect(resp.TLS.VerifiedChains).Should(HaveLen(1))
879 Expect(resp.TLS.VerifiedChains[0]).Should(HaveLen(1))
880 Expect(resp.TLS.VerifiedChains[0][0].Raw).Should(Equal(ipv6CertData))
884 Context("with both an ipv6 http and an ipv6 https server", func() {
885 var listenAddr, secureListenAddr string
890 srv, err = NewServer(Opts{
892 BindAddress: "[::1]:0",
893 SecureBindAddress: "[::1]:0",
895 Key: &ipv6KeyDataSource,
896 Cert: &ipv6CertDataSource,
899 Expect(err).ToNot(HaveOccurred())
901 s, ok := srv.(*server)
902 Expect(ok).To(BeTrue())
904 listenAddr = fmt.Sprintf("http://%s/", s.listener.Addr().String())
905 secureListenAddr = fmt.Sprintf("https://%s/", s.tlsListener.Addr().String())
908 It("Starts the server and serves the handler on http", func() {
910 defer GinkgoRecover()
911 Expect(srv.Start(ctx)).To(Succeed())
914 resp, err := httpGet(ctx, listenAddr)
915 Expect(err).ToNot(HaveOccurred())
916 Expect(resp.StatusCode).To(Equal(http.StatusOK))
918 body, err := io.ReadAll(resp.Body)
919 Expect(err).ToNot(HaveOccurred())
920 Expect(string(body)).To(Equal(hello))
923 It("Starts the server and serves the handler on https", func() {
925 defer GinkgoRecover()
926 Expect(srv.Start(ctx)).To(Succeed())
929 resp, err := httpGet(ctx, secureListenAddr)
930 Expect(err).ToNot(HaveOccurred())
931 Expect(resp.StatusCode).To(Equal(http.StatusOK))
933 body, err := io.ReadAll(resp.Body)
934 Expect(err).ToNot(HaveOccurred())
935 Expect(string(body)).To(Equal(hello))
938 It("Stops both servers when the context is cancelled", func() {
940 defer GinkgoRecover()
941 Expect(srv.Start(ctx)).To(Succeed())
944 _, err := httpGet(ctx, listenAddr)
945 Expect(err).ToNot(HaveOccurred())
946 _, err = httpGet(ctx, secureListenAddr)
947 Expect(err).ToNot(HaveOccurred())
951 Eventually(func() error {
952 _, err := httpGet(ctx, listenAddr)
954 }).Should(HaveOccurred())
955 Eventually(func() error {
956 _, err := httpGet(ctx, secureListenAddr)
958 }).Should(HaveOccurred())
963 Context("getNetworkScheme", func() {
964 DescribeTable("should return the scheme", func(in, expected string) {
965 Expect(getNetworkScheme(in)).To(Equal(expected))
967 Entry("ipv4 address with no scheme", "127.0.0.1:0", "tcp"),
968 Entry("ipv4 address with a tcp scheme", "tcp://127.0.0.1:0", "tcp"),
969 Entry("ipv4 address with a http scheme", "http://192.168.0.1:1", "tcp"),
970 Entry("ipv4 address with a unix scheme", "unix://172.168.16.2:2", "unix"),
971 Entry("ipv4 address with a random scheme", "random://10.10.10.10:10", "random"),
972 Entry("ipv6 address with no scheme", "[::1]:0", "tcp"),
973 Entry("ipv6 address with a tcp scheme", "tcp://[::1]:0", "tcp"),
974 Entry("ipv6 address with a http scheme", "http://[::ffff:c0a8:1]:1", "tcp"),
975 Entry("ipv6 address with a unix scheme", "unix://[::ffff:aca8:1002]:2", "unix"),
976 Entry("ipv6 address with a random scheme", "random://[::ffff:a0a:a0a]:10", "random"),
980 Context("getListenAddress", func() {
981 DescribeTable("should remove the scheme", func(in, expected string) {
982 Expect(getListenAddress(in)).To(Equal(expected))
984 Entry("ipv4 address with no scheme", "127.0.0.1:0", "127.0.0.1:0"),
985 Entry("ipv4 address with a tcp scheme", "tcp://127.0.0.1:0", "127.0.0.1:0"),
986 Entry("ipv4 address with a http scheme", "http://192.168.0.1:1", "192.168.0.1:1"),
987 Entry("ipv4 address with a unix scheme", "unix://172.168.16.2:2", "172.168.16.2:2"),
988 Entry("ipv4 address with a random scheme", "random://10.10.10.10:10", "10.10.10.10:10"),
989 Entry("ipv6 address with no scheme", "[::1]:0", "[::1]:0"),
990 Entry("ipv6 address with a tcp scheme", "tcp://[::1]:0", "[::1]:0"),
991 Entry("ipv6 address with a http scheme", "http://[::ffff:c0a8:1]:1", "[::ffff:c0a8:1]:1"),
992 Entry("ipv6 address with a unix scheme", "unix://[::ffff:aca8:1002]:2", "[::ffff:aca8:1002]:2"),
993 Entry("ipv6 address with a random scheme", "random://[::ffff:a0a:a0a]:10", "[::ffff:a0a:a0a]:10"),
998func skipDevContainer() {
999 if os.Getenv("DEVCONTAINER") != "" {
1000 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