Fix tests (#201)

Co-authored-by: RPRX <63339210+rprx@users.noreply.github.com>
This commit is contained in:
Jim Han 2021-01-30 21:01:20 +08:00 committed by GitHub
parent d032a8deb7
commit 4cd343f2d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 18 deletions

View File

@ -18,10 +18,10 @@ func init() {
common.Must(err) common.Must(err)
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(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) { 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")))
} }
} }

View File

@ -55,7 +55,7 @@ func TestAddressReading(t *testing.T) {
}, },
{ {
Options: []AddressOption{AddressFamilyByte(0x03, net.AddressFamilyDomain)}, 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"), Address: net.DomainAddress("example.com"),
Port: net.Port(80), Port: net.Port(80),
}, },
@ -84,8 +84,9 @@ func TestAddressReading(t *testing.T) {
} }
for _, tc := range data { for _, tc := range data {
b := buf.New()
parser := NewAddressParser(tc.Options...) parser := NewAddressParser(tc.Options...)
b := buf.New()
addr, port, err := parser.ReadAddressPort(b, bytes.NewReader(tc.Input)) addr, port, err := parser.ReadAddressPort(b, bytes.NewReader(tc.Input))
b.Release() b.Release()
if tc.Error { if tc.Error {

View File

@ -195,6 +195,7 @@ func initInstanceWithConfig(config *Config, server *Instance) (bool, error) {
} }
if l >= 17 && s[11:17] == "trojan" || l >= 22 && s[11:22] == "shadowsocks" { if l >= 17 && s[11:17] == "trojan" || l >= 22 && s[11:22] == "shadowsocks" {
t = true t = true
if outbound.SenderSettings != nil {
var m proxyman.SenderConfig var m proxyman.SenderConfig
proto.Unmarshal(outbound.SenderSettings.Value, &m) proto.Unmarshal(outbound.SenderSettings.Value, &m)
if m.MultiplexSettings != nil && m.MultiplexSettings.Enabled { if m.MultiplexSettings != nil && m.MultiplexSettings.Enabled {
@ -203,6 +204,7 @@ func initInstanceWithConfig(config *Config, server *Instance) (bool, error) {
} }
} }
} }
}
if v && !t { if v && !t {
cone = false cone = false
} }

View File

@ -21,7 +21,7 @@ func init() {
common.Must(err) common.Must(err)
if _, err := os.Stat(platform.GetAssetLocation("geoip.dat")); err != nil && os.IsNotExist(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") geositeFilePath := filepath.Join(wd, "geosite.dat")
@ -112,6 +112,11 @@ func TestDNSConfigParsing(t *testing.T) {
Domain: "example.com", Domain: "example.com",
ProxiedDomain: "google.com", ProxiedDomain: "google.com",
}, },
{
Type: dns.DomainMatchingType_Full,
Domain: "example.com",
Ip: [][]byte{{127, 0, 0, 1}},
},
{ {
Type: dns.DomainMatchingType_Full, Type: dns.DomainMatchingType_Full,
Domain: "example.com", Domain: "example.com",
@ -127,11 +132,6 @@ func TestDNSConfigParsing(t *testing.T) {
Domain: ".*\\.com", Domain: ".*\\.com",
Ip: [][]byte{{8, 8, 4, 4}}, 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}, ClientIp: []byte{10, 0, 0, 1},
}, },

View File

@ -45,7 +45,7 @@ func TestUDPEncoding(t *testing.T) {
t.Error("data: ", r) 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) t.Error("request: ", r)
} }
} }
@ -119,7 +119,7 @@ func TestTCPRequest(t *testing.T) {
decodedRequest, reader, err := ReadTCPSession([]*protocol.MemoryUser{request.User}, cache) decodedRequest, reader, err := ReadTCPSession([]*protocol.MemoryUser{request.User}, cache)
common.Must(err) 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) t.Error("request: ", r)
} }

View File

@ -118,7 +118,7 @@ func genTestBinaryPath() {
} }
func GetSourcePath() string { func GetSourcePath() string {
return filepath.Join("example.com", "core", "main") return filepath.Join("github.com", "xtls", "xray-core", "main")
} }
func CloseAllServers(servers []*exec.Cmd) { func CloseAllServers(servers []*exec.Cmd) {

View File

@ -17,6 +17,8 @@ func BuildXray() error {
fmt.Printf("Building Xray into path (%s)\n", testBinaryPath) fmt.Printf("Building Xray into path (%s)\n", testBinaryPath)
cmd := exec.Command("go", "build", "-o="+testBinaryPath, GetSourcePath()) cmd := exec.Command("go", "build", "-o="+testBinaryPath, GetSourcePath())
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run() return cmd.Run()
} }