feat(safemode): support /management.html route in ExampleAPIKeyWarningHandler

- Added handling for `/management.html` in `ExampleAPIKeyWarningHandler`.
- Updated tests to validate correct behavior for the new route.
This commit is contained in:
Luis Pater
2026-06-08 12:41:28 +08:00
parent 6f38e8488a
commit 856dc81748
2 changed files with 11 additions and 1 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ func WarningServerURL(cfg *config.Config) string {
func NewExampleAPIKeyWarningHandler(configPath string, keys []string) http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
if r.URL == nil || r.URL.Path != "/" {
if r.URL == nil || (r.URL.Path != "/" && r.URL.Path != "/management.html") {
http.NotFound(w, r)
return
}
@@ -59,6 +59,16 @@ func TestExampleAPIKeyWarningHandler(t *testing.T) {
}
}
req = httptest.NewRequest(http.MethodGet, "/management.html", nil)
w = httptest.NewRecorder()
handler.ServeHTTP(w, req)
if w.Code != http.StatusOK {
t.Fatalf("GET /management.html status = %d, want %d", w.Code, http.StatusOK)
}
if body := w.Body.String(); !strings.Contains(body, "Example API key detected") {
t.Fatalf("GET /management.html body missing warning: %s", body)
}
req = httptest.NewRequest(http.MethodHead, "/", nil)
w = httptest.NewRecorder()
handler.ServeHTTP(w, req)