- embedded React admin UI at /admin/ui (go:embed), login with ADMIN_SECRET via signed HttpOnly session cookie, X-ADMIN-KEY still works for scripts - admin API: overview stats, indexing queue, addon management (priority, reindex, delete/restore/purge, bulk), whitelist CRUD, duplicate hashes, traffic, metrics explorer, services, events/audit log, system info - built-in metrics: request latency per route, visitors, top addons and searches, indexer/scraper counters; minute buckets in the DB with hourly rollups and retention; optional Prometheus /metrics (METRICS_TOKEN) - POST /back/telemetry for indexers/scrapers (metrics, events, heartbeat) and a stdlib-only Go client in telemetry/ - auth hardening: empty secrets no longer allow access, constant-time compare, CORS not applied to /admin and /back, TRUSTED_PROXIES setting - Dockerfile builds the UI and no longer bakes config.yaml into the image; CI builds the UI, runs tests and builds arm64 with CGO
This commit is contained in:
1 parent
0ef27b0072
commit
56d9e10621
79 files changed
+13146
-118
No files matched your search
@@ -0,0 +1,51 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func TestSPA(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
r := gin.New()
|
||||
Register(r)
|
||||
|
||||
get := func(path string) *httptest.ResponseRecorder {
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, httptest.NewRequest(http.MethodGet, path, nil))
|
||||
return w
|
||||
}
|
||||
|
||||
for _, p := range []string{"/admin/ui/", "/admin/ui/addons/123", "/admin/ui/index.html"} {
|
||||
w := get(p)
|
||||
if w.Code != http.StatusOK || !strings.Contains(w.Header().Get("Content-Type"), "text/html") {
|
||||
t.Errorf("%s: got %d %s", p, w.Code, w.Header().Get("Content-Type"))
|
||||
}
|
||||
if w.Header().Get("Content-Security-Policy") == "" {
|
||||
t.Errorf("%s: missing CSP", p)
|
||||
}
|
||||
}
|
||||
|
||||
if w := get("/admin/ui/assets/missing.js"); w.Code != http.StatusNotFound {
|
||||
t.Errorf("missing asset: got %d, want 404", w.Code)
|
||||
}
|
||||
if w := get("/admin"); w.Code != http.StatusFound || w.Header().Get("Location") != "/admin/ui/" {
|
||||
t.Errorf("/admin: got %d -> %s", w.Code, w.Header().Get("Location"))
|
||||
}
|
||||
|
||||
// when the UI is built, hashed assets are served with long caching
|
||||
sub, _ := fs.Sub(dist, "dist")
|
||||
entries, _ := fs.ReadDir(sub, "assets")
|
||||
for _, e := range entries {
|
||||
w := get("/admin/ui/assets/" + e.Name())
|
||||
if w.Code != http.StatusOK || !strings.Contains(w.Header().Get("Cache-Control"), "immutable") {
|
||||
t.Errorf("asset %s: got %d cache %q", e.Name(), w.Code, w.Header().Get("Cache-Control"))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user