github.com/metacubex/sing-shadowsocks@v0.2.6/shadowaead_2022/service_test.go (about) 1 package shadowaead_2022_test 2 3 import ( 4 "context" 5 "crypto/rand" 6 "net" 7 "sync" 8 "testing" 9 10 "github.com/metacubex/sing-shadowsocks/shadowaead_2022" 11 "github.com/sagernet/sing/common" 12 E "github.com/sagernet/sing/common/exceptions" 13 M "github.com/sagernet/sing/common/metadata" 14 ) 15 16 func TestService(t *testing.T) { 17 t.Parallel() 18 method := "2022-blake3-aes-128-gcm" 19 var psk [16]byte 20 rand.Reader.Read(psk[:]) 21 22 var wg sync.WaitGroup 23 24 service, err := shadowaead_2022.NewService(method, psk[:], 500, &multiHandler{t, &wg}, nil) 25 if err != nil { 26 t.Fatal(err) 27 } 28 29 client, err := shadowaead_2022.New(method, [][]byte{psk[:]}, nil) 30 if err != nil { 31 t.Fatal(err) 32 } 33 wg.Add(1) 34 35 serverConn, clientConn := net.Pipe() 36 defer common.Close(serverConn, clientConn) 37 go func() { 38 err := service.NewConnection(context.Background(), serverConn, M.Metadata{}) 39 if err != nil { 40 serverConn.Close() 41 t.Error(E.Cause(err, "server")) 42 return 43 } 44 }() 45 _, err = client.DialConn(clientConn, M.ParseSocksaddr("test.com:443")) 46 if err != nil { 47 t.Fatal(err) 48 } 49 wg.Wait() 50 }