@@ -501,7 +501,21 @@ func (s *HTTPSSuite) TestWithClientCertificateAuthentication(c *check.C) {
501
501
// TestWithClientCertificateAuthentication
502
502
// Use two CA:s and test that clients with client signed by either of them can connect
503
503
func (s * HTTPSSuite ) TestWithClientCertificateAuthenticationMultipleCAs (c * check.C ) {
504
- file := s .adaptFile (c , "fixtures/https/clientca/https_2ca1config.toml" , struct {}{})
504
+ server1 := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , _ * http.Request ) { rw .Write ([]byte ("server1" )) }))
505
+ server2 := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , _ * http.Request ) { rw .Write ([]byte ("server2" )) }))
506
+ defer func () {
507
+ server1 .Close ()
508
+ server2 .Close ()
509
+ }()
510
+
511
+ file := s .adaptFile (c , "fixtures/https/clientca/https_2ca1config.toml" , struct {
512
+ Server1 string
513
+ Server2 string
514
+ }{
515
+ Server1 : server1 .URL ,
516
+ Server2 : server2 .URL ,
517
+ })
518
+
505
519
defer os .Remove (file )
506
520
cmd , display := s .traefikCmd (withConfigFile (file ))
507
521
defer display (c )
@@ -513,58 +527,91 @@ func (s *HTTPSSuite) TestWithClientCertificateAuthenticationMultipleCAs(c *check
513
527
err = try .GetRequest ("http://127.0.0.1:8080/api/rawdata" , 1 * time .Second , try .BodyContains ("Host(`snitest.org`)" ))
514
528
c .Assert (err , checker .IsNil )
515
529
530
+ req , err := http .NewRequest (http .MethodGet , "https://127.0.0.1:4443" , nil )
531
+ c .Assert (err , checker .IsNil )
532
+ req .Host = "snitest.com"
533
+
516
534
tlsConfig := & tls.Config {
517
535
InsecureSkipVerify : true ,
518
536
ServerName : "snitest.com" ,
519
537
Certificates : []tls.Certificate {},
520
538
}
539
+
540
+ client := http.Client {
541
+ Transport : & http.Transport {TLSClientConfig : tlsConfig },
542
+ Timeout : 1 * time .Second ,
543
+ }
544
+
521
545
// Connection without client certificate should fail
522
- _ , err = tls . Dial ( "tcp" , "127.0.0.1:4443" , tlsConfig )
523
- c .Assert (err , checker .NotNil , check . Commentf ( "should not be allowed to connect to server" ) )
546
+ _ , err = client . Do ( req )
547
+ c .Assert (err , checker .NotNil )
524
548
525
- // Connect with client signed by ca1
526
549
cert , err := tls .LoadX509KeyPair ("fixtures/https/clientca/client1.crt" , "fixtures/https/clientca/client1.key" )
527
550
c .Assert (err , checker .IsNil , check .Commentf ("unable to load client certificate and key" ))
528
551
tlsConfig .Certificates = append (tlsConfig .Certificates , cert )
529
552
530
- conn , err := tls .Dial ("tcp" , "127.0.0.1:4443" , tlsConfig )
531
- c .Assert (err , checker .IsNil , check .Commentf ("failed to connect to server" ))
532
-
533
- conn .Close ()
553
+ // Connect with client signed by ca1
554
+ _ , err = client .Do (req )
555
+ c .Assert (err , checker .IsNil )
534
556
535
557
// Connect with client signed by ca2
536
558
tlsConfig = & tls.Config {
537
559
InsecureSkipVerify : true ,
538
560
ServerName : "snitest.com" ,
539
561
Certificates : []tls.Certificate {},
540
562
}
563
+
541
564
cert , err = tls .LoadX509KeyPair ("fixtures/https/clientca/client2.crt" , "fixtures/https/clientca/client2.key" )
542
565
c .Assert (err , checker .IsNil , check .Commentf ("unable to load client certificate and key" ))
543
566
tlsConfig .Certificates = append (tlsConfig .Certificates , cert )
544
567
545
- conn , err = tls .Dial ("tcp" , "127.0.0.1:4443" , tlsConfig )
546
- c .Assert (err , checker .IsNil , check .Commentf ("failed to connect to server" ))
568
+ client = http.Client {
569
+ Transport : & http.Transport {TLSClientConfig : tlsConfig },
570
+ Timeout : 1 * time .Second ,
571
+ }
547
572
548
- conn .Close ()
573
+ // Connect with client signed by ca1
574
+ _ , err = client .Do (req )
575
+ c .Assert (err , checker .IsNil )
549
576
550
577
// Connect with client signed by ca3 should fail
551
578
tlsConfig = & tls.Config {
552
579
InsecureSkipVerify : true ,
553
580
ServerName : "snitest.com" ,
554
581
Certificates : []tls.Certificate {},
555
582
}
583
+
556
584
cert , err = tls .LoadX509KeyPair ("fixtures/https/clientca/client3.crt" , "fixtures/https/clientca/client3.key" )
557
585
c .Assert (err , checker .IsNil , check .Commentf ("unable to load client certificate and key" ))
558
586
tlsConfig .Certificates = append (tlsConfig .Certificates , cert )
559
587
560
- _ , err = tls .Dial ("tcp" , "127.0.0.1:4443" , tlsConfig )
561
- c .Assert (err , checker .NotNil , check .Commentf ("should not be allowed to connect to server" ))
588
+ client = http.Client {
589
+ Transport : & http.Transport {TLSClientConfig : tlsConfig },
590
+ Timeout : 1 * time .Second ,
591
+ }
592
+
593
+ // Connect with client signed by ca1
594
+ _ , err = client .Do (req )
595
+ c .Assert (err , checker .NotNil )
562
596
}
563
597
564
598
// TestWithClientCertificateAuthentication
565
599
// Use two CA:s in two different files and test that clients with client signed by either of them can connect
566
600
func (s * HTTPSSuite ) TestWithClientCertificateAuthenticationMultipleCAsMultipleFiles (c * check.C ) {
567
- file := s .adaptFile (c , "fixtures/https/clientca/https_2ca2config.toml" , struct {}{})
601
+ server1 := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , _ * http.Request ) { rw .Write ([]byte ("server1" )) }))
602
+ server2 := httptest .NewServer (http .HandlerFunc (func (rw http.ResponseWriter , _ * http.Request ) { rw .Write ([]byte ("server2" )) }))
603
+ defer func () {
604
+ server1 .Close ()
605
+ server2 .Close ()
606
+ }()
607
+
608
+ file := s .adaptFile (c , "fixtures/https/clientca/https_2ca2config.toml" , struct {
609
+ Server1 string
610
+ Server2 string
611
+ }{
612
+ Server1 : server1 .URL ,
613
+ Server2 : server2 .URL ,
614
+ })
568
615
defer os .Remove (file )
569
616
cmd , display := s .traefikCmd (withConfigFile (file ))
570
617
defer display (c )
@@ -576,51 +623,70 @@ func (s *HTTPSSuite) TestWithClientCertificateAuthenticationMultipleCAsMultipleF
576
623
err = try .GetRequest ("http://127.0.0.1:8080/api/rawdata" , 1 * time .Second , try .BodyContains ("Host(`snitest.org`)" ))
577
624
c .Assert (err , checker .IsNil )
578
625
626
+ req , err := http .NewRequest (http .MethodGet , "https://127.0.0.1:4443" , nil )
627
+ c .Assert (err , checker .IsNil )
628
+ req .Host = "snitest.com"
629
+
579
630
tlsConfig := & tls.Config {
580
631
InsecureSkipVerify : true ,
581
632
ServerName : "snitest.com" ,
582
633
Certificates : []tls.Certificate {},
583
634
}
635
+
636
+ client := http.Client {
637
+ Transport : & http.Transport {TLSClientConfig : tlsConfig },
638
+ Timeout : 1 * time .Second ,
639
+ }
640
+
584
641
// Connection without client certificate should fail
585
- _ , err = tls . Dial ( "tcp" , "127.0.0.1:4443" , tlsConfig )
586
- c .Assert (err , checker .NotNil , check . Commentf ( "should not be allowed to connect to server" ) )
642
+ _ , err = client . Do ( req )
643
+ c .Assert (err , checker .NotNil )
587
644
588
645
// Connect with client signed by ca1
589
646
cert , err := tls .LoadX509KeyPair ("fixtures/https/clientca/client1.crt" , "fixtures/https/clientca/client1.key" )
590
647
c .Assert (err , checker .IsNil , check .Commentf ("unable to load client certificate and key" ))
591
648
tlsConfig .Certificates = append (tlsConfig .Certificates , cert )
592
649
593
- conn , err := tls .Dial ("tcp" , "127.0.0.1:4443" , tlsConfig )
594
- c .Assert (err , checker .IsNil , check .Commentf ("failed to connect to server" ))
595
-
596
- conn .Close ()
650
+ _ , err = client .Do (req )
651
+ c .Assert (err , checker .IsNil )
597
652
598
653
// Connect with client signed by ca2
599
654
tlsConfig = & tls.Config {
600
655
InsecureSkipVerify : true ,
601
656
ServerName : "snitest.com" ,
602
657
Certificates : []tls.Certificate {},
603
658
}
659
+
604
660
cert , err = tls .LoadX509KeyPair ("fixtures/https/clientca/client2.crt" , "fixtures/https/clientca/client2.key" )
605
661
c .Assert (err , checker .IsNil , check .Commentf ("unable to load client certificate and key" ))
606
662
tlsConfig .Certificates = append (tlsConfig .Certificates , cert )
607
663
608
- conn , err = tls .Dial ("tcp" , "127.0.0.1:4443" , tlsConfig )
609
- c .Assert (err , checker .IsNil , check .Commentf ("failed to connect to server" ))
610
- conn .Close ()
664
+ client = http.Client {
665
+ Transport : & http.Transport {TLSClientConfig : tlsConfig },
666
+ Timeout : 1 * time .Second ,
667
+ }
668
+
669
+ _ , err = client .Do (req )
670
+ c .Assert (err , checker .IsNil )
611
671
612
672
// Connect with client signed by ca3 should fail
613
673
tlsConfig = & tls.Config {
614
674
InsecureSkipVerify : true ,
615
675
ServerName : "snitest.com" ,
616
676
Certificates : []tls.Certificate {},
617
677
}
678
+
618
679
cert , err = tls .LoadX509KeyPair ("fixtures/https/clientca/client3.crt" , "fixtures/https/clientca/client3.key" )
619
680
c .Assert (err , checker .IsNil , check .Commentf ("unable to load client certificate and key" ))
620
681
tlsConfig .Certificates = append (tlsConfig .Certificates , cert )
621
682
622
- _ , err = tls .Dial ("tcp" , "127.0.0.1:4443" , tlsConfig )
623
- c .Assert (err , checker .NotNil , check .Commentf ("should not be allowed to connect to server" ))
683
+ client = http.Client {
684
+ Transport : & http.Transport {TLSClientConfig : tlsConfig },
685
+ Timeout : 1 * time .Second ,
686
+ }
687
+
688
+ _ , err = client .Do (req )
689
+ c .Assert (err , checker .NotNil )
624
690
}
625
691
626
692
func (s * HTTPSSuite ) TestWithRootCAsContentForHTTPSOnBackend (c * check.C ) {
0 commit comments