50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenderXraySidecarConfigAddsMissingVLESSEncryption(t *testing.T) {
|
|
profile := &NodeProfile{
|
|
Protocol: "vless",
|
|
Address: "example.com",
|
|
Port: 443,
|
|
UUID: "00000000-0000-0000-0000-000000000000",
|
|
Transport: "xhttp",
|
|
RawOutbound: json.RawMessage(`{
|
|
"protocol":"vless",
|
|
"settings":{
|
|
"vnext":[{
|
|
"address":"example.com",
|
|
"port":443,
|
|
"users":[{
|
|
"id":"00000000-0000-0000-0000-000000000000"
|
|
}]
|
|
}]
|
|
},
|
|
"streamSettings":{
|
|
"network":"xhttp",
|
|
"security":"reality",
|
|
"realitySettings":{"publicKey":"public-key"},
|
|
"xhttpSettings":{"path":"/api","mode":"auto"}
|
|
}
|
|
}`),
|
|
}
|
|
|
|
data, err := RenderXraySidecarConfig(profile, XraySidecarSocksPort)
|
|
if err != nil {
|
|
t.Fatalf("render xray sidecar: %v", err)
|
|
}
|
|
var rendered map[string]any
|
|
if err := json.Unmarshal(data, &rendered); err != nil {
|
|
t.Fatalf("unmarshal rendered config: %v", err)
|
|
}
|
|
outbound := rendered["outbounds"].([]any)[0].(map[string]any)
|
|
settings := outbound["settings"].(map[string]any)
|
|
vnext := settings["vnext"].([]any)[0].(map[string]any)
|
|
user := vnext["users"].([]any)[0].(map[string]any)
|
|
if user["encryption"] != "none" {
|
|
t.Fatalf("xray sidecar must add vless encryption=none for stored xhttp nodes: %#v", user)
|
|
}
|
|
}
|