CI / go-test (push) Canceled after 0s
CI / postgres-durable-first (push) Canceled after 0s
CI / codegen (push) Canceled after 0s
CI / govulncheck (push) Canceled after 0s
CI / race (push) Canceled after 0s
CI / fuzz-smoke (push) Canceled after 0s
CI / golangci (push) Canceled after 0s
CI / frontend (push) Canceled after 0s
CodeQL Advanced / Analyze (go) (push) Canceled after 0s
CodeQL Advanced / Analyze (actions) (push) Canceled after 0s
CodeQL Advanced / Analyze (javascript-typescript) (push) Canceled after 0s
Docs CI / build (push) Canceled after 0s
Docs Deploy (GitHub Pages) / build (push) Canceled after 0s
Release 3X-UI / build (386) (push) Canceled after 0s
Release 3X-UI / build (amd64) (push) Canceled after 0s
Release 3X-UI / build (arm64) (push) Canceled after 0s
Release 3X-UI / build (armv5) (push) Canceled after 0s
Release 3X-UI / build (armv6) (push) Canceled after 0s
Release 3X-UI / build (armv7) (push) Canceled after 0s
Release 3X-UI / build (s390x) (push) Canceled after 0s
Release 3X-UI / Build for Windows (amd64) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / noninteractive-install (ubuntu-latest) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-24.04-arm) (push) Canceled after 0s
Deploy Smoke Tests / release-tag-install (ubuntu-latest) (push) Canceled after 0s
Docs Deploy (GitHub Pages) / deploy (push) Canceled after 0s
Release 3X-UI / Publish rolling dev release (push) Canceled after 0s
79 lines
2.6 KiB
Go
79 lines
2.6 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database"
|
|
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
|
)
|
|
|
|
// TestBuildRuntimeInboundForAPI_InjectsFallbacks is the #5963 regression: the
|
|
// runtime inbound sent to nodes never carried the inbound_fallbacks rows, so
|
|
// fallbacks configured on the master silently vanished from every node.
|
|
func TestBuildRuntimeInboundForAPI_InjectsFallbacks(t *testing.T) {
|
|
setupBulkDB(t)
|
|
svc := &InboundService{}
|
|
db := database.GetDB()
|
|
|
|
clients := []model.Client{
|
|
{Email: "fb@x", ID: "11111111-1111-1111-1111-111111111111", Enable: true},
|
|
}
|
|
master := mkInbound(t, 30201, model.VLESS, clientsSettings(t, clients))
|
|
master.StreamSettings = `{"network":"tcp","security":"tls","tlsSettings":{"serverName":"s"}}`
|
|
if err := db.Save(master).Error; err != nil {
|
|
t.Fatalf("save master stream: %v", err)
|
|
}
|
|
|
|
fb := model.InboundFallback{MasterId: master.Id, ChildId: 0, Dest: "8081", Alpn: "h2", Path: "/fb", Xver: 1}
|
|
if err := db.Create(&fb).Error; err != nil {
|
|
t.Fatalf("seed fallback: %v", err)
|
|
}
|
|
|
|
runtimeIb, err := svc.buildInboundForLocalRuntime(db, master)
|
|
if err != nil {
|
|
t.Fatalf("buildInboundForLocalRuntime: %v", err)
|
|
}
|
|
|
|
var settings map[string]any
|
|
if err := json.Unmarshal([]byte(runtimeIb.Settings), &settings); err != nil {
|
|
t.Fatalf("runtime settings not valid json: %v", err)
|
|
}
|
|
fallbacks, ok := settings["fallbacks"].([]any)
|
|
if !ok || len(fallbacks) != 1 {
|
|
t.Fatalf("runtime settings must carry the fallback, got: %s", runtimeIb.Settings)
|
|
}
|
|
if !strings.Contains(runtimeIb.Settings, `"dest"`) || !strings.Contains(runtimeIb.Settings, "8081") {
|
|
t.Fatalf("fallback dest missing from runtime settings: %s", runtimeIb.Settings)
|
|
}
|
|
}
|
|
|
|
// A non-fallback-capable inbound (ws transport) must stay untouched.
|
|
func TestBuildRuntimeInboundForAPI_NoFallbacksOnWsInbound(t *testing.T) {
|
|
setupBulkDB(t)
|
|
svc := &InboundService{}
|
|
db := database.GetDB()
|
|
|
|
clients := []model.Client{
|
|
{Email: "ws@x", ID: "22222222-2222-2222-2222-222222222222", Enable: true},
|
|
}
|
|
ib := mkInbound(t, 30202, model.VLESS, clientsSettings(t, clients))
|
|
ib.StreamSettings = `{"network":"ws","security":"none"}`
|
|
if err := db.Save(ib).Error; err != nil {
|
|
t.Fatalf("save stream: %v", err)
|
|
}
|
|
fb := model.InboundFallback{MasterId: ib.Id, Dest: "8082"}
|
|
if err := db.Create(&fb).Error; err != nil {
|
|
t.Fatalf("seed fallback: %v", err)
|
|
}
|
|
|
|
runtimeIb, err := svc.buildInboundForLocalRuntime(db, ib)
|
|
if err != nil {
|
|
t.Fatalf("buildInboundForLocalRuntime: %v", err)
|
|
}
|
|
if strings.Contains(runtimeIb.Settings, "fallbacks") {
|
|
t.Fatalf("ws inbound must not receive fallbacks: %s", runtimeIb.Settings)
|
|
}
|
|
}
|