mirror of
https://gh-proxy.org/https://github.com/klinsmaya/CLIProxyAPI.git
synced 2026-11-08 01:16:47 +08:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user