@@ -14,7 +14,6 @@ import (
14
14
"github.com/stretchr/testify/assert"
15
15
"github.com/stretchr/testify/require"
16
16
"github.com/tarantool/go-iproto"
17
- "github.com/tarantool/go-openssl"
18
17
19
18
"github.com/tarantool/go-tarantool/v2"
20
19
"github.com/tarantool/go-tarantool/v2/test_helpers"
@@ -605,186 +604,6 @@ func TestNetDialer_Dial_requirements(t *testing.T) {
605
604
require .Contains (t , err .Error (), "invalid server protocol" )
606
605
}
607
606
608
- func createSslListener (t * testing.T , opts tarantool.SslTestOpts ) net.Listener {
609
- ctx , err := tarantool .SslCreateContext (opts )
610
- require .NoError (t , err )
611
- l , err := openssl .Listen ("tcp" , "127.0.0.1:0" , ctx .(* openssl.Ctx ))
612
- require .NoError (t , err )
613
- return l
614
- }
615
-
616
- func TestOpenSslDialer_Dial_basic (t * testing.T ) {
617
- l := createSslListener (t , tarantool.SslTestOpts {
618
- KeyFile : "testdata/localhost.key" ,
619
- CertFile : "testdata/localhost.crt" ,
620
- })
621
-
622
- defer l .Close ()
623
- addr := l .Addr ().String ()
624
-
625
- dialer := tarantool.OpenSslDialer {
626
- Address : addr ,
627
- User : testDialUser ,
628
- Password : testDialPass ,
629
- }
630
-
631
- cases := []testDialOpts {
632
- {
633
- name : "all is ok" ,
634
- expectedProtocolInfo : idResponseTyped .Clone (),
635
- },
636
- {
637
- name : "id request unsupported" ,
638
- // Dialer sets auth.
639
- expectedProtocolInfo : tarantool.ProtocolInfo {Auth : tarantool .ChapSha1Auth },
640
- isIdUnsupported : true ,
641
- },
642
- {
643
- name : "greeting response error" ,
644
- wantErr : true ,
645
- expectedErr : "failed to read greeting" ,
646
- isErrGreeting : true ,
647
- },
648
- {
649
- name : "id response error" ,
650
- wantErr : true ,
651
- expectedErr : "failed to identify" ,
652
- isErrId : true ,
653
- },
654
- {
655
- name : "auth response error" ,
656
- wantErr : true ,
657
- expectedErr : "failed to authenticate" ,
658
- isErrAuth : true ,
659
- },
660
- }
661
- for _ , tc := range cases {
662
- t .Run (tc .name , func (t * testing.T ) {
663
- testDialer (t , l , dialer , tc )
664
- })
665
- }
666
- }
667
-
668
- func TestOpenSslDialer_Dial_requirements (t * testing.T ) {
669
- l := createSslListener (t , tarantool.SslTestOpts {
670
- KeyFile : "testdata/localhost.key" ,
671
- CertFile : "testdata/localhost.crt" ,
672
- })
673
-
674
- defer l .Close ()
675
- addr := l .Addr ().String ()
676
-
677
- dialer := tarantool.OpenSslDialer {
678
- Address : addr ,
679
- User : testDialUser ,
680
- Password : testDialPass ,
681
- RequiredProtocolInfo : tarantool.ProtocolInfo {
682
- Features : []iproto.Feature {42 },
683
- },
684
- }
685
-
686
- testDialAccept (testDialOpts {}, l )
687
- ctx , cancel := test_helpers .GetConnectContext ()
688
- defer cancel ()
689
- conn , err := dialer .Dial (ctx , tarantool.DialOpts {})
690
- if err == nil {
691
- conn .Close ()
692
- }
693
- require .Error (t , err )
694
- require .Contains (t , err .Error (), "invalid server protocol" )
695
- }
696
-
697
- func TestOpenSslDialer_Dial_papSha256Auth (t * testing.T ) {
698
- l := createSslListener (t , tarantool.SslTestOpts {
699
- KeyFile : "testdata/localhost.key" ,
700
- CertFile : "testdata/localhost.crt" ,
701
- })
702
-
703
- defer l .Close ()
704
- addr := l .Addr ().String ()
705
-
706
- dialer := tarantool.OpenSslDialer {
707
- Address : addr ,
708
- User : testDialUser ,
709
- Password : testDialPass ,
710
- Auth : tarantool .PapSha256Auth ,
711
- }
712
-
713
- protocol := idResponseTyped .Clone ()
714
- protocol .Auth = tarantool .PapSha256Auth
715
-
716
- testDialer (t , l , dialer , testDialOpts {
717
- expectedProtocolInfo : protocol ,
718
- isPapSha256Auth : true ,
719
- })
720
- }
721
-
722
- func TestOpenSslDialer_Dial_opts (t * testing.T ) {
723
- for _ , test := range sslTests {
724
- t .Run (test .name , func (t * testing.T ) {
725
- l := createSslListener (t , test .serverOpts )
726
- defer l .Close ()
727
- addr := l .Addr ().String ()
728
-
729
- dialer := tarantool.OpenSslDialer {
730
- Address : addr ,
731
- User : testDialUser ,
732
- Password : testDialPass ,
733
- SslKeyFile : test .clientOpts .KeyFile ,
734
- SslCertFile : test .clientOpts .CertFile ,
735
- SslCaFile : test .clientOpts .CaFile ,
736
- SslCiphers : test .clientOpts .Ciphers ,
737
- SslPassword : test .clientOpts .Password ,
738
- SslPasswordFile : test .clientOpts .PasswordFile ,
739
- }
740
- testDialer (t , l , dialer , testDialOpts {
741
- wantErr : ! test .ok ,
742
- expectedProtocolInfo : idResponseTyped .Clone (),
743
- })
744
- })
745
- }
746
- }
747
-
748
- func TestOpenSslDialer_Dial_ctx_cancel (t * testing.T ) {
749
- serverOpts := tarantool.SslTestOpts {
750
- KeyFile : "testdata/localhost.key" ,
751
- CertFile : "testdata/localhost.crt" ,
752
- CaFile : "testdata/ca.crt" ,
753
- Ciphers : "ECDHE-RSA-AES256-GCM-SHA384" ,
754
- }
755
- clientOpts := tarantool.SslTestOpts {
756
- KeyFile : "testdata/localhost.key" ,
757
- CertFile : "testdata/localhost.crt" ,
758
- CaFile : "testdata/ca.crt" ,
759
- Ciphers : "ECDHE-RSA-AES256-GCM-SHA384" ,
760
- }
761
-
762
- l := createSslListener (t , serverOpts )
763
- defer l .Close ()
764
- addr := l .Addr ().String ()
765
- testDialAccept (testDialOpts {}, l )
766
-
767
- dialer := tarantool.OpenSslDialer {
768
- Address : addr ,
769
- User : testDialUser ,
770
- Password : testDialPass ,
771
- SslKeyFile : clientOpts .KeyFile ,
772
- SslCertFile : clientOpts .CertFile ,
773
- SslCaFile : clientOpts .CaFile ,
774
- SslCiphers : clientOpts .Ciphers ,
775
- SslPassword : clientOpts .Password ,
776
- SslPasswordFile : clientOpts .PasswordFile ,
777
- }
778
-
779
- ctx , cancel := context .WithCancel (context .Background ())
780
- cancel ()
781
- conn , err := dialer .Dial (ctx , tarantool.DialOpts {})
782
- if err == nil {
783
- conn .Close ()
784
- }
785
- require .Error (t , err )
786
- }
787
-
788
607
func TestFdDialer_Dial (t * testing.T ) {
789
608
l , err := net .Listen ("tcp" , "127.0.0.1:0" )
790
609
require .NoError (t , err )
0 commit comments