mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-08-21 04:06:27 +00:00
* Increase some tls test timeout * Fix TestUserValidator * Change all tests to VMessAEAD Old VMess MD5 tests will be rejected and fail in 2022 * Chore: auto format code
95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
//go:build !windows && !android
|
|
// +build !windows,!android
|
|
|
|
package domainsocket_test
|
|
|
|
import (
|
|
"context"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/xtls/xray-core/common"
|
|
"github.com/xtls/xray-core/common/buf"
|
|
"github.com/xtls/xray-core/common/net"
|
|
"github.com/xtls/xray-core/transport/internet"
|
|
. "github.com/xtls/xray-core/transport/internet/domainsocket"
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
|
)
|
|
|
|
func TestListen(t *testing.T) {
|
|
ctx := context.Background()
|
|
streamSettings := &internet.MemoryStreamConfig{
|
|
ProtocolName: "domainsocket",
|
|
ProtocolSettings: &Config{
|
|
Path: "/tmp/ts3",
|
|
},
|
|
}
|
|
listener, err := Listen(ctx, nil, net.Port(0), streamSettings, func(conn stat.Connection) {
|
|
defer conn.Close()
|
|
|
|
b := buf.New()
|
|
defer b.Release()
|
|
common.Must2(b.ReadFrom(conn))
|
|
b.WriteString("Response")
|
|
|
|
common.Must2(conn.Write(b.Bytes()))
|
|
})
|
|
common.Must(err)
|
|
defer listener.Close()
|
|
|
|
conn, err := Dial(ctx, net.Destination{}, streamSettings)
|
|
common.Must(err)
|
|
defer conn.Close()
|
|
|
|
common.Must2(conn.Write([]byte("Request")))
|
|
|
|
b := buf.New()
|
|
defer b.Release()
|
|
common.Must2(b.ReadFrom(conn))
|
|
|
|
if b.String() != "RequestResponse" {
|
|
t.Error("expected response as 'RequestResponse' but got ", b.String())
|
|
}
|
|
}
|
|
|
|
func TestListenAbstract(t *testing.T) {
|
|
if runtime.GOOS != "linux" {
|
|
return
|
|
}
|
|
|
|
ctx := context.Background()
|
|
streamSettings := &internet.MemoryStreamConfig{
|
|
ProtocolName: "domainsocket",
|
|
ProtocolSettings: &Config{
|
|
Path: "/tmp/ts3",
|
|
Abstract: true,
|
|
},
|
|
}
|
|
listener, err := Listen(ctx, nil, net.Port(0), streamSettings, func(conn stat.Connection) {
|
|
defer conn.Close()
|
|
|
|
b := buf.New()
|
|
defer b.Release()
|
|
common.Must2(b.ReadFrom(conn))
|
|
b.WriteString("Response")
|
|
|
|
common.Must2(conn.Write(b.Bytes()))
|
|
})
|
|
common.Must(err)
|
|
defer listener.Close()
|
|
|
|
conn, err := Dial(ctx, net.Destination{}, streamSettings)
|
|
common.Must(err)
|
|
defer conn.Close()
|
|
|
|
common.Must2(conn.Write([]byte("Request")))
|
|
|
|
b := buf.New()
|
|
defer b.Release()
|
|
common.Must2(b.ReadFrom(conn))
|
|
|
|
if b.String() != "RequestResponse" {
|
|
t.Error("expected response as 'RequestResponse' but got ", b.String())
|
|
}
|
|
}
|