diff --git a/service/conf/environmentConfig.go b/service/conf/environmentConfig.go index 559ab126..07fe2917 100644 --- a/service/conf/environmentConfig.go +++ b/service/conf/environmentConfig.go @@ -55,7 +55,10 @@ func initFunc() { EnvPrefix: "V2RAYA_", }) if err != nil { - if err.Error() != "unexpected word while parsing flags: '-test.v'" { + // go test hands its own -test.* flags to the binary; only "-test.v" + // used to be tolerated, so every package whose tests reach this init + // died on the first other test flag. + if !strings.Contains(err.Error(), "parsing flags: '-test.") { log2.Fatal(err) } } diff --git a/service/server/service/import.go b/service/server/service/import.go index d6d2fbb3..a3069202 100644 --- a/service/server/service/import.go +++ b/service/server/service/import.go @@ -58,9 +58,32 @@ func Import(url string, which *configure.Which) (err error) { if PluginManagerValidateLink(url) || common.HasAnyPrefix(urlLower, supportedPrefix) { return ImportServer(url, which) } + if isBareHttpProxyLink(url) { + return ImportServer(url, which) + } return ImportSubscription(url) } +// isBareHttpProxyLink recognises the one http(s) URL shape that cannot be a +// subscription address: credentials, a port, and nothing else. A subscription +// address always carries a path or a query, and never credentials. Clients +// that send "kind" never reach this guess. +func isBareHttpProxyLink(rawURL string) bool { + u, err := url2.Parse(rawURL) + if err != nil || u.User == nil || u.User.String() == "" { + return false + } + switch strings.ToLower(u.Scheme) { + case "http", "https": + default: + return false + } + if u.RawQuery != "" { + return false + } + return u.Path == "" || u.Path == "/" +} + // ImportServer imports one server link, or several separated by newlines, // or a JSON config. A non-nil which with ID > 0 replaces that server instead // of appending. diff --git a/service/server/service/import_test.go b/service/server/service/import_test.go new file mode 100644 index 00000000..d45d71b6 --- /dev/null +++ b/service/server/service/import_test.go @@ -0,0 +1,29 @@ +package service + +import "testing" + +func TestIsBareHttpProxyLink(t *testing.T) { + yes := []string{ + "http://user:pass@proxy.example:8080", + "https://user:pass@proxy.example:8443", + "http://user@proxy.example:8080#work", + "http://user:pass@proxy.example:8080/", + } + no := []string{ + "http://sub.example.com/link/abc?mu=1", + "https://sub.example.com/api/v1/client/subscribe?token=x", + "http://proxy.example:8080", + "https://example.com", + "ss://YWVzLTEyOC1nY206dGVzdA@127.0.0.1:8388", + } + for _, u := range yes { + if !isBareHttpProxyLink(u) { + t.Errorf("%s should be taken for an http proxy link", u) + } + } + for _, u := range no { + if isBareHttpProxyLink(u) { + t.Errorf("%s should not be taken for an http proxy link", u) + } + } +}