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
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package controller
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestWithServerBasePath(t *testing.T) {
|
|
spec := []byte(`{"openapi":"3.0.3","info":{"title":"x"},"servers":[{"url":"/","description":"old"}],"paths":{"/p":{"get":{"summary":"s"}}}}`)
|
|
|
|
out, err := withServerBasePath(spec, "/test/")
|
|
if err != nil {
|
|
t.Fatalf("withServerBasePath: %v", err)
|
|
}
|
|
|
|
var doc map[string]any
|
|
if err := json.Unmarshal(out, &doc); err != nil {
|
|
t.Fatalf("unmarshal result: %v", err)
|
|
}
|
|
|
|
servers, ok := doc["servers"].([]any)
|
|
if !ok || len(servers) != 1 {
|
|
t.Fatalf("servers = %v, want one entry", doc["servers"])
|
|
}
|
|
srv, _ := servers[0].(map[string]any)
|
|
if srv["url"] != "/test" {
|
|
t.Errorf("server url = %v, want /test (trailing slash trimmed)", srv["url"])
|
|
}
|
|
|
|
if doc["openapi"] != "3.0.3" {
|
|
t.Errorf("openapi field not preserved: %v", doc["openapi"])
|
|
}
|
|
if _, ok := doc["paths"].(map[string]any)["/p"]; !ok {
|
|
t.Errorf("paths content not preserved verbatim")
|
|
}
|
|
}
|
|
|
|
func TestWithServerBasePathInvalidJSON(t *testing.T) {
|
|
if _, err := withServerBasePath([]byte("not json"), "/test/"); err == nil {
|
|
t.Errorf("expected error on invalid spec, got nil")
|
|
}
|
|
}
|
|
|
|
func TestPWAHeadInjectionUsesRuntimeBasePath(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
basePath string
|
|
wantPath string
|
|
}{
|
|
{name: "root", basePath: "/", wantPath: "/manifest.webmanifest"},
|
|
{name: "secret path", basePath: "panel-secret", wantPath: "/panel-secret/manifest.webmanifest"},
|
|
{name: "trailing slash", basePath: "/panel-secret/", wantPath: "/panel-secret/manifest.webmanifest"},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
t.Run(test.name, func(t *testing.T) {
|
|
head := string(pwaHeadInjection(test.basePath, "login.html"))
|
|
if !strings.Contains(head, `href="`+test.wantPath+`"`) {
|
|
t.Fatalf("manifest URL = %q, want %q", head, test.wantPath)
|
|
}
|
|
if !strings.Contains(head, `src="`+strings.Replace(test.wantPath, "manifest.webmanifest", "pwa-register.js", 1)+`"`) {
|
|
t.Fatalf("registration URL = %q", head)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPWAHeadInjectionSkipsSubscriptionPage(t *testing.T) {
|
|
if got := pwaHeadInjection("/panel-secret/", "subpage.html"); got != nil {
|
|
t.Fatalf("subpage injection = %q, want nil", got)
|
|
}
|
|
}
|