From 4cd343f2d5bf36fb09f19888c2fed556c3fff0c4 Mon Sep 17 00:00:00 2001 From: Jim Han <50871214+JimhHan@users.noreply.github.com> Date: Sat, 30 Jan 2021 21:01:20 +0800 Subject: [PATCH] Fix tests (#201) Co-authored-by: RPRX <63339210+rprx@users.noreply.github.com> --- app/router/condition_geoip_test.go | 4 ++-- common/protocol/address_test.go | 5 +++-- core/xray.go | 12 +++++++----- infra/conf/dns_test.go | 12 ++++++------ proxy/shadowsocks/protocol_test.go | 4 ++-- testing/scenarios/common.go | 2 +- testing/scenarios/common_regular.go | 2 ++ 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/app/router/condition_geoip_test.go b/app/router/condition_geoip_test.go index 614cafa5..596478c6 100644 --- a/app/router/condition_geoip_test.go +++ b/app/router/condition_geoip_test.go @@ -18,10 +18,10 @@ func init() { common.Must(err) if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) { - common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat"))) + common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "resources", "geoip.dat"))) } if _, err := os.Stat(platform.GetAssetLocation("geosite.dat")); err != nil && os.IsNotExist(err) { - common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "release", "config", "geosite.dat"))) + common.Must(filesystem.CopyFile(platform.GetAssetLocation("geosite.dat"), filepath.Join(wd, "..", "..", "resources", "geosite.dat"))) } } diff --git a/common/protocol/address_test.go b/common/protocol/address_test.go index 4733ea3d..b18adf82 100644 --- a/common/protocol/address_test.go +++ b/common/protocol/address_test.go @@ -55,7 +55,7 @@ func TestAddressReading(t *testing.T) { }, { Options: []AddressOption{AddressFamilyByte(0x03, net.AddressFamilyDomain)}, - Input: []byte{3, 9, 118, 50, 114, 97, 121, 46, 99, 111, 109, 0, 80}, + Input: []byte{3, 11, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109, 0, 80}, Address: net.DomainAddress("example.com"), Port: net.Port(80), }, @@ -84,8 +84,9 @@ func TestAddressReading(t *testing.T) { } for _, tc := range data { - b := buf.New() parser := NewAddressParser(tc.Options...) + + b := buf.New() addr, port, err := parser.ReadAddressPort(b, bytes.NewReader(tc.Input)) b.Release() if tc.Error { diff --git a/core/xray.go b/core/xray.go index 3a86d323..e5ef00b6 100644 --- a/core/xray.go +++ b/core/xray.go @@ -195,11 +195,13 @@ func initInstanceWithConfig(config *Config, server *Instance) (bool, error) { } if l >= 17 && s[11:17] == "trojan" || l >= 22 && s[11:22] == "shadowsocks" { t = true - var m proxyman.SenderConfig - proto.Unmarshal(outbound.SenderSettings.Value, &m) - if m.MultiplexSettings != nil && m.MultiplexSettings.Enabled { - cone = false - break + if outbound.SenderSettings != nil { + var m proxyman.SenderConfig + proto.Unmarshal(outbound.SenderSettings.Value, &m) + if m.MultiplexSettings != nil && m.MultiplexSettings.Enabled { + cone = false + break + } } } } diff --git a/infra/conf/dns_test.go b/infra/conf/dns_test.go index 680a1f4a..421fb877 100644 --- a/infra/conf/dns_test.go +++ b/infra/conf/dns_test.go @@ -21,7 +21,7 @@ func init() { common.Must(err) if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(err) { - common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "release", "config", "geoip.dat"))) + common.Must(filesystem.CopyFile(platform.GetAssetLocation("geoip.dat"), filepath.Join(wd, "..", "..", "resources", "geoip.dat"))) } geositeFilePath := filepath.Join(wd, "geosite.dat") @@ -112,6 +112,11 @@ func TestDNSConfigParsing(t *testing.T) { Domain: "example.com", ProxiedDomain: "google.com", }, + { + Type: dns.DomainMatchingType_Full, + Domain: "example.com", + Ip: [][]byte{{127, 0, 0, 1}}, + }, { Type: dns.DomainMatchingType_Full, Domain: "example.com", @@ -127,11 +132,6 @@ func TestDNSConfigParsing(t *testing.T) { Domain: ".*\\.com", Ip: [][]byte{{8, 8, 4, 4}}, }, - { - Type: dns.DomainMatchingType_Full, - Domain: "example.com", - Ip: [][]byte{{127, 0, 0, 1}}, - }, }, ClientIp: []byte{10, 0, 0, 1}, }, diff --git a/proxy/shadowsocks/protocol_test.go b/proxy/shadowsocks/protocol_test.go index 59d863f3..3183a39f 100644 --- a/proxy/shadowsocks/protocol_test.go +++ b/proxy/shadowsocks/protocol_test.go @@ -45,7 +45,7 @@ func TestUDPEncoding(t *testing.T) { t.Error("data: ", r) } - if r := cmp.Diff(decodedRequest, request); r != "" { + if r := cmp.Diff(decodedRequest, request, cmp.Comparer(func(a1, a2 protocol.Account) bool { return a1.Equals(a2) })); r != "" { t.Error("request: ", r) } } @@ -119,7 +119,7 @@ func TestTCPRequest(t *testing.T) { decodedRequest, reader, err := ReadTCPSession([]*protocol.MemoryUser{request.User}, cache) common.Must(err) - if r := cmp.Diff(decodedRequest, request); r != "" { + if r := cmp.Diff(decodedRequest, request, cmp.Comparer(func(a1, a2 protocol.Account) bool { return a1.Equals(a2) })); r != "" { t.Error("request: ", r) } diff --git a/testing/scenarios/common.go b/testing/scenarios/common.go index 2a7cbfd0..d562e9ba 100644 --- a/testing/scenarios/common.go +++ b/testing/scenarios/common.go @@ -118,7 +118,7 @@ func genTestBinaryPath() { } func GetSourcePath() string { - return filepath.Join("example.com", "core", "main") + return filepath.Join("github.com", "xtls", "xray-core", "main") } func CloseAllServers(servers []*exec.Cmd) { diff --git a/testing/scenarios/common_regular.go b/testing/scenarios/common_regular.go index ac42bb06..514daafb 100644 --- a/testing/scenarios/common_regular.go +++ b/testing/scenarios/common_regular.go @@ -17,6 +17,8 @@ func BuildXray() error { fmt.Printf("Building Xray into path (%s)\n", testBinaryPath) cmd := exec.Command("go", "build", "-o="+testBinaryPath, GetSourcePath()) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr return cmd.Run() }