mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-09-19 16:37:19 +00:00
fix(xray): read the last two inboundTag protocol ids like the core (#6530)
The core lowercases an outbound's protocol id before it resolves the handler, so an outbound spelled "Loopback" still is the loopback outbound. Both readers that keep a loopback outbound's inboundTag in step with the inbound it names compared the id exactly, so such an outbound was skipped: renaming or deleting that inbound left settings.inboundTag pointing at a tag that no longer exists, and traffic returning through the loopback outbound arrives under a tag no routing rule can match (infra/conf/loopback.go:15 carries the tag, proxy/loopback/loopback.go:43 uses it as the inbound identity). The probe lane's "nothing to test here" gate had the same exact comparison, so a "Freedom"/"Blackhole" outbound reported the vaguer "No testable endpoint" where the canonical spelling reports "Outbound has no testable endpoint" — the two spellings took different paths to the same rejection. Both readers now compare case-insensitively; the outbound package reuses its existing equalsAnyFold helper rather than adding a second one. The service reads the config template an operator edits, so a case variant is reachable there; server.go's GetDefaultLogOutboundTags scans the embedded config.json instead, whose protocols are canonical by construction, so it is left as is and no test can tell a case-insensitive read there from an exact one.
This commit is contained in:
@@ -221,6 +221,73 @@ func TestRemoveInboundTagReferences_RemovesOneTagFromMultiInboundRule(t *testing
|
||||
}
|
||||
}
|
||||
|
||||
// The core lowercases a protocol id before resolving the handler, so "Loopback"
|
||||
// is the loopback outbound whose inboundTag has to follow the inbound it names.
|
||||
func TestReplaceInboundTagInOutbounds_ReadsTheProtocolIDLikeTheCore(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
protocol any
|
||||
want bool
|
||||
wantTag any
|
||||
}{
|
||||
{"canonical loopback is rewritten", "loopback", true, "new-tag"},
|
||||
{"capitalised loopback is rewritten", "Loopback", true, "new-tag"},
|
||||
{"uppercase loopback is rewritten", "LOOPBACK", true, "new-tag"},
|
||||
{"another protocol keeps its tag", "vmess", false, "old-tag"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
outbounds := []any{map[string]any{
|
||||
"protocol": tt.protocol,
|
||||
"settings": map[string]any{"inboundTag": "old-tag"},
|
||||
}}
|
||||
if got := replaceInboundTagInOutbounds(outbounds, "old-tag", "new-tag"); got != tt.want {
|
||||
t.Errorf("changed = %v, want %v", got, tt.want)
|
||||
}
|
||||
settings := outbounds[0].(map[string]any)["settings"].(map[string]any)
|
||||
if got := settings["inboundTag"]; got != tt.wantTag {
|
||||
t.Errorf("inboundTag = %v, want %v", got, tt.wantTag)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRemoveInboundTagFromOutbounds_ReadsTheProtocolIDLikeTheCore(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
protocol any
|
||||
want bool
|
||||
wantTag any
|
||||
}{
|
||||
{"canonical loopback is cleared", "loopback", true, nil},
|
||||
{"capitalised loopback is cleared", "Loopback", true, nil},
|
||||
{"uppercase loopback is cleared", "LOOPBACK", true, nil},
|
||||
{"another protocol keeps its tag", "vmess", false, "gone-tag"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
outbounds := []any{map[string]any{
|
||||
"protocol": tt.protocol,
|
||||
"settings": map[string]any{"inboundTag": "gone-tag"},
|
||||
}}
|
||||
if got := removeInboundTagFromOutbounds(outbounds, "gone-tag"); got != tt.want {
|
||||
t.Errorf("changed = %v, want %v", got, tt.want)
|
||||
}
|
||||
settings := outbounds[0].(map[string]any)["settings"].(map[string]any)
|
||||
got, ok := settings["inboundTag"]
|
||||
if tt.wantTag == nil {
|
||||
if ok {
|
||||
t.Errorf("inboundTag = %v, want the key gone", got)
|
||||
}
|
||||
return
|
||||
}
|
||||
if !ok || got != tt.wantTag {
|
||||
t.Errorf("inboundTag = %v (present=%v), want %v", got, ok, tt.wantTag)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func findRuleByOutbound(t *testing.T, template, outbound string) map[string]any {
|
||||
t.Helper()
|
||||
for _, rule := range routingRulesFromTemplate(t, template) {
|
||||
|
||||
Reference in New Issue
Block a user