627dbca6af
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
33 lines
1.2 KiB
Go
33 lines
1.2 KiB
Go
package lkgateway
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
// Служебные разделы разработчиков вне режима разработки отвечают 404 — даже при открытом входе.
|
|
func TestDevOnlyPaths(t *testing.T) {
|
|
for _, p := range []string{"/admin/m2m-testing", "/admin/m2m-testing/preview", "/admin/setup/test-run", "/admin/api/callback-url", "/admin/help/robot"} {
|
|
if !devOnlyPath(p) || requiredPerm(p, http.MethodGet) != "dev" {
|
|
t.Errorf("%s должен быть служебным", p)
|
|
}
|
|
}
|
|
for _, p := range []string{"/admin/m2m-testingx", "/admin/incoming", "/admin/setup", "/admin/help"} {
|
|
if devOnlyPath(p) {
|
|
t.Errorf("%s не служебный", p)
|
|
}
|
|
}
|
|
rc, err := NewRuntimeConfig(t.TempDir() + "/setup.json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
next := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusTeapot) })
|
|
h := authMiddleware(rc, next)
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/admin/m2m-testing", nil))
|
|
if rec.Code != http.StatusNotFound {
|
|
t.Fatalf("вне режима разработки: %d", rec.Code)
|
|
}
|
|
}
|