|
|
|
@ -6,7 +6,7 @@ import (
|
|
|
|
|
"testing" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
v2net "v2ray.com/core/common/net" |
|
|
|
|
"v2ray.com/core/common/net" |
|
|
|
|
"v2ray.com/core/testing/assert" |
|
|
|
|
tlsgen "v2ray.com/core/testing/tls" |
|
|
|
|
"v2ray.com/core/transport/internet" |
|
|
|
@ -18,7 +18,7 @@ func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
|
assert := assert.On(t) |
|
|
|
|
listen, err := ListenWS(internet.ContextWithTransportSettings(context.Background(), &Config{ |
|
|
|
|
Path: "ws", |
|
|
|
|
}), v2net.DomainAddress("localhost"), 13146, func(ctx context.Context, conn internet.Connection) bool { |
|
|
|
|
}), net.DomainAddress("localhost"), 13146, func(ctx context.Context, conn internet.Connection) bool { |
|
|
|
|
go func(c internet.Connection) { |
|
|
|
|
defer c.Close() |
|
|
|
|
|
|
|
|
@ -38,7 +38,7 @@ func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
|
|
|
|
|
|
ctx := internet.ContextWithTransportSettings(context.Background(), &Config{Path: "ws"}) |
|
|
|
|
conn, err := Dial(ctx, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13146)) |
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146)) |
|
|
|
|
|
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
|
_, err = conn.Write([]byte("Test connection 1")) |
|
|
|
@ -51,7 +51,7 @@ func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
assert.Error(conn.Close()).IsNil() |
|
|
|
|
<-time.After(time.Second * 5) |
|
|
|
|
conn, err = Dial(ctx, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13146)) |
|
|
|
|
conn, err = Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146)) |
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
|
_, err = conn.Write([]byte("Test connection 2")) |
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
@ -60,7 +60,7 @@ func Test_listenWSAndDial(t *testing.T) {
|
|
|
|
|
assert.String(string(b[:n])).Equals("Response") |
|
|
|
|
assert.Error(conn.Close()).IsNil() |
|
|
|
|
<-time.After(time.Second * 15) |
|
|
|
|
conn, err = Dial(ctx, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13146)) |
|
|
|
|
conn, err = Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13146)) |
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
|
_, err = conn.Write([]byte("Test connection 3")) |
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
@ -86,7 +86,7 @@ func Test_listenWSAndDial_TLS(t *testing.T) {
|
|
|
|
|
AllowInsecure: true, |
|
|
|
|
Certificate: []*v2tls.Certificate{tlsgen.GenerateCertificateForTest()}, |
|
|
|
|
}) |
|
|
|
|
listen, err := ListenWS(ctx, v2net.DomainAddress("localhost"), 13143, func(ctx context.Context, conn internet.Connection) bool { |
|
|
|
|
listen, err := ListenWS(ctx, net.DomainAddress("localhost"), 13143, func(ctx context.Context, conn internet.Connection) bool { |
|
|
|
|
go func() { |
|
|
|
|
conn.Close() |
|
|
|
|
}() |
|
|
|
@ -95,7 +95,7 @@ func Test_listenWSAndDial_TLS(t *testing.T) {
|
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
|
defer listen.Close() |
|
|
|
|
|
|
|
|
|
conn, err := Dial(ctx, v2net.TCPDestination(v2net.DomainAddress("localhost"), 13143)) |
|
|
|
|
conn, err := Dial(ctx, net.TCPDestination(net.DomainAddress("localhost"), 13143)) |
|
|
|
|
assert.Error(err).IsNil() |
|
|
|
|
conn.Close() |
|
|
|
|
} |
|
|
|
|