release / web (push) Successful in 1m34s
release / go (push) Successful in 2m0s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m24s
release / android (push) Successful in 4m46s
release / Build signed APK (push) Successful in 5m12s
release / Attach APK to the Release (tag releases only) (push) Skipped
release / Publish the release image to GHCR (dispatch only) (push) Skipped
release / Build + push container image (push) Successful in 29s
release / Verify release artifacts (tag releases only) (push) Skipped
- The like/unlike story runs as one sequence that checks the rows after each step. - The invite-only sign-up cases are one test, which now also checks that a refused sign-up creates no account. - Demoting an admin, and stopping at the last one, is one test. - A wrong password and an unknown user are one test, which now also checks that the two refusals are identical. - The cover-path resolver tests repeated the cover handler's tests branch for branch; the handler tests stay. - The Range-from-start stream test only re-checked http.ServeContent. - The APK's nil-user 401 is covered by the mounted-route walk. - 68 copies of the MINSTREL_TEST_DATABASE_URL skip go: every one of those tests reaches dbtest.Pool, which already skips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
93 lines
2.6 KiB
Go
93 lines
2.6 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/Fabled-Sword/minstrel/internal/auth"
|
|
)
|
|
|
|
func newAdminScanRouter(h *handlers) chi.Router {
|
|
r := chi.NewRouter()
|
|
r.Route("/api/admin", func(admin chi.Router) {
|
|
admin.Use(auth.RequireAdmin())
|
|
admin.Get("/scan/status", h.handleGetScanStatus)
|
|
admin.Post("/scan/run", h.handleTriggerScan)
|
|
})
|
|
return r
|
|
}
|
|
|
|
func TestAdminScanStatus_NoRowReturnsEmpty(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
admin := seedUser(t, pool, "rootscan", "pw", true)
|
|
req := httptest.NewRequest(http.MethodGet, "/api/admin/scan/status", nil)
|
|
req = withUser(req, admin)
|
|
rec := httptest.NewRecorder()
|
|
newAdminScanRouter(h).ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d, want 200; body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
var resp scanStatusResp
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if resp.ID != "" || resp.InFlight {
|
|
t.Errorf("expected empty payload; got %+v", resp)
|
|
}
|
|
}
|
|
|
|
func TestAdminScanStatus_RowReturnsValues(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
admin := seedUser(t, pool, "rootscan2", "pw", true)
|
|
if _, err := pool.Exec(context.Background(), `
|
|
INSERT INTO scan_runs (started_at, finished_at, library)
|
|
VALUES (now() - interval '1 minute', now(), '{"scanned":10,"added":2}'::jsonb)
|
|
`); err != nil {
|
|
t.Fatalf("seed scan_runs: %v", err)
|
|
}
|
|
|
|
req := httptest.NewRequest(http.MethodGet, "/api/admin/scan/status", nil)
|
|
req = withUser(req, admin)
|
|
rec := httptest.NewRecorder()
|
|
newAdminScanRouter(h).ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("status = %d", rec.Code)
|
|
}
|
|
var resp scanStatusResp
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &resp); err != nil {
|
|
t.Fatalf("decode: %v", err)
|
|
}
|
|
if resp.InFlight {
|
|
t.Error("expected InFlight=false (finished_at set)")
|
|
}
|
|
if resp.FinishedAt == nil {
|
|
t.Error("expected FinishedAt to be non-nil")
|
|
}
|
|
if len(resp.Library) == 0 {
|
|
t.Error("expected Library jsonb to be non-empty")
|
|
}
|
|
}
|
|
|
|
func TestAdminTriggerScan_InFlightReturns409(t *testing.T) {
|
|
h, pool := testHandlers(t)
|
|
admin := seedUser(t, pool, "rootscan3", "pw", true)
|
|
if _, err := pool.Exec(context.Background(), `
|
|
INSERT INTO scan_runs (started_at) VALUES (now())
|
|
`); err != nil {
|
|
t.Fatalf("seed in-flight scan: %v", err)
|
|
}
|
|
|
|
req := httptest.NewRequest(http.MethodPost, "/api/admin/scan/run", nil)
|
|
req = withUser(req, admin)
|
|
rec := httptest.NewRecorder()
|
|
newAdminScanRouter(h).ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusConflict {
|
|
t.Fatalf("status = %d, want 409; body=%s", rec.Code, rec.Body.String())
|
|
}
|
|
}
|