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.
37 lines
915 B
Go
37 lines
915 B
Go
package server
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/config"
|
|
)
|
|
|
|
func testBearerToken(t *testing.T, baseURL string, cfg *config.Config) string {
|
|
t.Helper()
|
|
if cfg == nil {
|
|
cfg = &config.Config{AdminUsername: "admin", AdminPassword: "admin-secret-password-123"}
|
|
}
|
|
body, _ := json.Marshal(map[string]string{
|
|
"username": cfg.AdminUsername,
|
|
"password": cfg.AdminPassword,
|
|
})
|
|
resp, err := http.Post(baseURL+"/api/v1/auth/login", "application/json", bytes.NewReader(body))
|
|
if err != nil {
|
|
t.Fatalf("login request failed: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode != http.StatusOK {
|
|
t.Fatalf("login failed status=%d", resp.StatusCode)
|
|
}
|
|
var out struct {
|
|
Token string `json:"token"`
|
|
}
|
|
if err := json.NewDecoder(resp.Body).Decode(&out); err != nil || out.Token == "" {
|
|
t.Fatalf("login decode failed: %v", err)
|
|
}
|
|
return out.Token
|
|
}
|