@@ -442,6 +442,7 @@ type testDialOpts struct {
442
442
isIdUnsupported bool
443
443
isPapSha256Auth bool
444
444
isErrAuth bool
445
+ isEmptyAuth bool
445
446
}
446
447
447
448
type dialServerActual struct {
@@ -484,6 +485,8 @@ func testDialAccept(opts testDialOpts, l net.Listener) chan dialServerActual {
484
485
authRequestExpected := authRequestExpectedChapSha1
485
486
if opts .isPapSha256Auth {
486
487
authRequestExpected = authRequestExpectedPapSha256
488
+ } else if opts .isEmptyAuth {
489
+ authRequestExpected = []byte {}
487
490
}
488
491
authRequestActual := make ([]byte , len (authRequestExpected ))
489
492
client .Read (authRequestActual )
@@ -526,6 +529,8 @@ func testDialer(t *testing.T, l net.Listener, dialer tarantool.Dialer,
526
529
authRequestExpected := authRequestExpectedChapSha1
527
530
if opts .isPapSha256Auth {
528
531
authRequestExpected = authRequestExpectedPapSha256
532
+ } else if opts .isEmptyAuth {
533
+ authRequestExpected = []byte {}
529
534
}
530
535
require .Equal (t , authRequestExpected , actual .AuthRequest )
531
536
conn .Close ()
@@ -779,3 +784,77 @@ func TestOpenSslDialer_Dial_ctx_cancel(t *testing.T) {
779
784
}
780
785
require .Error (t , err )
781
786
}
787
+
788
+ func TestFdDialer_Dial (t * testing.T ) {
789
+ l , err := net .Listen ("tcp" , "127.0.0.1:0" )
790
+ require .NoError (t , err )
791
+ defer l .Close ()
792
+ addr := l .Addr ().String ()
793
+
794
+ cases := []testDialOpts {
795
+ {
796
+ name : "all is ok" ,
797
+ expectedProtocolInfo : idResponseTyped .Clone (),
798
+ isEmptyAuth : true ,
799
+ },
800
+ {
801
+ name : "id request unsupported" ,
802
+ expectedProtocolInfo : tarantool.ProtocolInfo {},
803
+ isIdUnsupported : true ,
804
+ isEmptyAuth : true ,
805
+ },
806
+ {
807
+ name : "greeting response error" ,
808
+ wantErr : true ,
809
+ expectedErr : "failed to read greeting" ,
810
+ isErrGreeting : true ,
811
+ },
812
+ {
813
+ name : "id response error" ,
814
+ wantErr : true ,
815
+ expectedErr : "failed to identify" ,
816
+ isErrId : true ,
817
+ },
818
+ }
819
+
820
+ for _ , tc := range cases {
821
+ t .Run (tc .name , func (t * testing.T ) {
822
+ sock , err := net .Dial ("tcp" , addr )
823
+ require .NoError (t , err )
824
+ f , err := sock .(* net.TCPConn ).File ()
825
+ require .NoError (t , err )
826
+ dialer := tarantool.FdDialer {
827
+ Fd : f .Fd (),
828
+ }
829
+ testDialer (t , l , dialer , tc )
830
+ })
831
+ }
832
+ }
833
+
834
+ func TestFdDialer_Dial_requirements (t * testing.T ) {
835
+ l , err := net .Listen ("tcp" , "127.0.0.1:0" )
836
+ require .NoError (t , err )
837
+ defer l .Close ()
838
+ addr := l .Addr ().String ()
839
+
840
+ sock , err := net .Dial ("tcp" , addr )
841
+ require .NoError (t , err )
842
+ f , err := sock .(* net.TCPConn ).File ()
843
+ require .NoError (t , err )
844
+ dialer := tarantool.FdDialer {
845
+ Fd : f .Fd (),
846
+ RequiredProtocolInfo : tarantool.ProtocolInfo {
847
+ Features : []iproto.Feature {42 },
848
+ },
849
+ }
850
+
851
+ testDialAccept (t , testDialOpts {}, l )
852
+ ctx , cancel := test_helpers .GetConnectContext ()
853
+ defer cancel ()
854
+ conn , err := dialer .Dial (ctx , tarantool.DialOpts {})
855
+ if err == nil {
856
+ conn .Close ()
857
+ }
858
+ require .Error (t , err )
859
+ require .Contains (t , err .Error (), "invalid server protocol" )
860
+ }
0 commit comments