test(api): one walk over the mounted router checks access and id errors (#8295)
release / go (push) Successful in 2m3s
release / web (push) Successful in 1m29s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m29s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 3m28s
release / Build signed APK (push) Canceled after 3m3s
release / go (push) Successful in 2m3s
release / web (push) Successful in 1m29s
release / govulncheck (push) Successful in 19s
release / integration (push) Successful in 3m29s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Publish the release image to GHCR (dispatch only) (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / android (push) Canceled after 3m28s
release / Build signed APK (push) Canceled after 3m3s
The access tests checked hand-built routers that applied RequireAdmin themselves, so none could catch a production route mounted outside its group. One test now walks every route Mount registers: each non-public route answers 401 without a session, and each admin route 403 to a listener. The per-endpoint malformed-id (400) and unknown-id (404) tests become one table over the real routes. Profile updates, playlist kind filters and empty searches each fold into one table; writeErr's envelope tests move to apierror.Write, which they were testing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -56,22 +56,6 @@ func testHandlersWithCovers(t *testing.T) (*handlers, *coverart.Enricher) {
|
||||
return h, enricher
|
||||
}
|
||||
|
||||
func TestAdminAlbumRefetchCover_NonAdminReturns403(t *testing.T) {
|
||||
if os.Getenv("MINSTREL_TEST_DATABASE_URL") == "" {
|
||||
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
|
||||
}
|
||||
h, _ := testHandlersWithCovers(t)
|
||||
user := seedUser(t, h.pool, "alice", "pw", false)
|
||||
artist := seedArtist(t, h.pool, "TestArtist")
|
||||
album := seedAlbum(t, h.pool, artist.ID, "TestAlbum", 0)
|
||||
|
||||
w := doAdminCoversReq(t, h, http.MethodPost,
|
||||
"/api/admin/albums/"+uuidToString(album.ID)+"/cover/refetch", user)
|
||||
if w.Code != http.StatusForbidden {
|
||||
t.Errorf("status = %d, want 403; body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminAlbumRefetchCover_AdminOK(t *testing.T) {
|
||||
if os.Getenv("MINSTREL_TEST_DATABASE_URL") == "" {
|
||||
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
|
||||
@@ -118,16 +102,3 @@ func TestAdminBulkRefetchCovers_AdminStartsRefetch(t *testing.T) {
|
||||
t.Errorf("started = false, want true (bulk refetch should acknowledge)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminBulkRefetchCovers_NonAdminReturns403(t *testing.T) {
|
||||
if os.Getenv("MINSTREL_TEST_DATABASE_URL") == "" {
|
||||
t.Skip("MINSTREL_TEST_DATABASE_URL not set")
|
||||
}
|
||||
h, _ := testHandlersWithCovers(t)
|
||||
user := seedUser(t, h.pool, "alicebulk", "pw", false)
|
||||
|
||||
w := doAdminCoversReq(t, h, http.MethodPost, "/api/admin/covers/refetch-missing", user)
|
||||
if w.Code != http.StatusForbidden {
|
||||
t.Errorf("status = %d, want 403; body=%s", w.Code, w.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user