|
@@ -128,21 +128,32 @@ func TestSubJsonServiceVmessFlattened(t *testing.T) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func TestSubJsonServiceServerFlattened(t *testing.T) {
|
|
|
|
|
|
|
+// Shadowsocks/Trojan outbounds must use the standard "servers" array so older
|
|
|
|
|
+// bundled xray-cores (e.g. v2rayN) parse them; the flat top-level form only
|
|
|
|
|
+// works on very recent xray-core.
|
|
|
|
|
+func TestSubJsonServiceServerUsesServersArray(t *testing.T) {
|
|
|
trojan := &model.Inbound{Listen: "1.2.3.4", Port: 443, Protocol: model.Trojan, Settings: `{}`}
|
|
trojan := &model.Inbound{Listen: "1.2.3.4", Port: 443, Protocol: model.Trojan, Settings: `{}`}
|
|
|
client := model.Client{Password: "p4ss"}
|
|
client := model.Client{Password: "p4ss"}
|
|
|
|
|
|
|
|
settings := outboundSettings(t, NewSubJsonService("", "", "", nil).genServer(trojan, nil, client, ""))
|
|
settings := outboundSettings(t, NewSubJsonService("", "", "", nil).genServer(trojan, nil, client, ""))
|
|
|
- if _, ok := settings["servers"]; ok {
|
|
|
|
|
- t.Fatal("trojan outbound must not use servers array")
|
|
|
|
|
|
|
+ server := firstServer(settings)
|
|
|
|
|
+ if server == nil {
|
|
|
|
|
+ t.Fatalf("trojan outbound must use a servers array, got: %#v", settings)
|
|
|
}
|
|
}
|
|
|
- if settings["password"] != "p4ss" || settings["address"] != "1.2.3.4" {
|
|
|
|
|
- t.Fatalf("flat trojan settings wrong: %#v", settings)
|
|
|
|
|
|
|
+ if server["password"] != "p4ss" || server["address"] != "1.2.3.4" {
|
|
|
|
|
+ t.Fatalf("trojan server entry wrong: %#v", server)
|
|
|
|
|
+ }
|
|
|
|
|
+ if _, ok := server["method"]; ok {
|
|
|
|
|
+ t.Fatalf("trojan must not carry method: %#v", server)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ss := &model.Inbound{Listen: "1.2.3.4", Port: 443, Protocol: model.Shadowsocks, Settings: `{"method":"aes-256-gcm"}`}
|
|
ss := &model.Inbound{Listen: "1.2.3.4", Port: 443, Protocol: model.Shadowsocks, Settings: `{"method":"aes-256-gcm"}`}
|
|
|
ssSettings := outboundSettings(t, NewSubJsonService("", "", "", nil).genServer(ss, nil, client, ""))
|
|
ssSettings := outboundSettings(t, NewSubJsonService("", "", "", nil).genServer(ss, nil, client, ""))
|
|
|
- if ssSettings["method"] != "aes-256-gcm" {
|
|
|
|
|
- t.Fatalf("flat shadowsocks must carry method: %#v", ssSettings)
|
|
|
|
|
|
|
+ ssServer := firstServer(ssSettings)
|
|
|
|
|
+ if ssServer == nil {
|
|
|
|
|
+ t.Fatalf("shadowsocks outbound must use a servers array, got: %#v", ssSettings)
|
|
|
|
|
+ }
|
|
|
|
|
+ if ssServer["method"] != "aes-256-gcm" {
|
|
|
|
|
+ t.Fatalf("shadowsocks server entry must carry method: %#v", ssServer)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|