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
52 lines
2.0 KiB
Go
52 lines
2.0 KiB
Go
package service
|
|
|
|
import "testing"
|
|
|
|
// BuildSubURIBase is the single source of truth for the scheme://host[:port]
|
|
// prefix shown both on the panel's Client Information page and on the
|
|
// subscription page. The cases pin scheme selection (sub TLS cert/key),
|
|
// Sub Domain preference, standard-port omission, and IPv6 bracketing.
|
|
func TestBuildSubURIBase(t *testing.T) {
|
|
setupConflictDB(t)
|
|
s := &SettingService{}
|
|
|
|
set := func(subDomain, port, cert, key string) {
|
|
if err := s.saveSetting("subDomain", subDomain); err != nil {
|
|
t.Fatalf("set subDomain: %v", err)
|
|
}
|
|
if err := s.saveSetting("subPort", port); err != nil {
|
|
t.Fatalf("set subPort: %v", err)
|
|
}
|
|
if err := s.saveSetting("subCertFile", cert); err != nil {
|
|
t.Fatalf("set subCertFile: %v", err)
|
|
}
|
|
if err := s.saveSetting("subKeyFile", key); err != nil {
|
|
t.Fatalf("set subKeyFile: %v", err)
|
|
}
|
|
}
|
|
|
|
cases := []struct {
|
|
name string
|
|
subDomain, port string
|
|
cert, key string
|
|
host string
|
|
want string
|
|
}{
|
|
{"no domain, plain, non-standard port", "", "2096", "", "", "panel.example.com", "http://panel.example.com:2096"},
|
|
{"host carries a port — stripped, sub port applied", "", "2096", "", "", "panel.example.com:9999", "http://panel.example.com:2096"},
|
|
{"sub domain preferred over host", "sub.cdn.com", "2096", "", "", "panel.example.com", "http://sub.cdn.com:2096"},
|
|
{"tls + 443 omits the port", "sub.cdn.com", "443", "/c.crt", "/k.key", "panel.example.com", "https://sub.cdn.com"},
|
|
{"plain + 80 omits the port", "", "80", "", "", "x.com", "http://x.com"},
|
|
{"tls on a non-standard port keeps it", "", "2096", "/c.crt", "/k.key", "x.com", "https://x.com:2096"},
|
|
{"ipv6 host is bracketed", "", "2096", "", "", "::1", "http://[::1]:2096"},
|
|
}
|
|
for _, c := range cases {
|
|
t.Run(c.name, func(t *testing.T) {
|
|
set(c.subDomain, c.port, c.cert, c.key)
|
|
if got := s.BuildSubURIBase(c.host); got != c.want {
|
|
t.Fatalf("BuildSubURIBase(%q) = %q, want %q", c.host, got, c.want)
|
|
}
|
|
})
|
|
}
|
|
}
|