Files
weichen 3145550a59 feat(security): complete P0 release blocking remediation
Unify auth middleware and remove X-User-ID trust, add project_members
authorization, sandbox workspaces via resolver, and admin-only reconcile
by run_id. Introduce goose migrations with startup schema gate, fail closed
when DB unavailable outside explicit ALLOW_IN_MEMORY, bundle web/dist in
app Dockerfile, and remove frontend pseudo-login fallback.
2026-09-13 02:50:22 +00:00

47 lines
1.3 KiB
Go

package server
import (
"net/http"
"net/http/httptest"
"testing"
"chat-agent-system/internal/bizdev"
"chat-agent-system/internal/config"
)
func TestServer_WebAssetsHostingAndFallback(t *testing.T) {
cfg := &config.Config{
Env: "test",
AgentBackend: "stub",
DataDir: t.TempDir(),
AllowInMemory: false,
}
svc, err := bizdev.NewService(cfg)
if err != nil {
t.Fatalf("NewService: %v", err)
}
srv := NewServer(cfg, svc)
handler := srv.Routes()
reqRoot := httptest.NewRequest(http.MethodGet, "/", nil)
wRoot := httptest.NewRecorder()
handler.ServeHTTP(wRoot, reqRoot)
if wRoot.Code != http.StatusOK && wRoot.Code != http.StatusNotFound {
t.Errorf("expected status 200 or 404 for root SPA, got %d", wRoot.Code)
}
reqClientRoute := httptest.NewRequest(http.MethodGet, "/sessions/sess-001", nil)
wClient := httptest.NewRecorder()
handler.ServeHTTP(wClient, reqClientRoute)
if wClient.Code != http.StatusOK && wClient.Code != http.StatusNotFound {
t.Errorf("expected status 200 or 404 for client route fallback, got %d", wClient.Code)
}
reqAPI := httptest.NewRequest(http.MethodGet, "/api/v1/chat/sessions", nil)
wAPI := httptest.NewRecorder()
handler.ServeHTTP(wAPI, reqAPI)
if wAPI.Code != http.StatusUnauthorized {
t.Errorf("expected status 401 for unauthenticated /api/v1/chat/sessions, got %d", wAPI.Code)
}
}