mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
fix(import): keep bare http proxy links importable without a kind field
A client that predates the kind field sends only the URL, so an http(s) link
had to be guessed. Guessing "subscription" is right for every address a
provider hands out, but it took away the bare proxy link 3fd0e882 had added:
credentials, host, port and nothing else cannot be a subscription address, so
that one shape goes back to the server importer.
Also let the config loader ignore every -test.* flag instead of only -test.v,
so the packages that reach it can run their tests at all.
This commit is contained in:
3 files changed
+56
-1
No files matched your search
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user