Repository navigation
test(api): cover authorization, validation and error paths in api handlers - #3039
Merged
Merged
Conversation
…dlers Adds *_coverage_test.go files across internal/api, raising package statement coverage from 79.5% to 85.2%. The tests assert status codes, bodies and the stored state after each call: tenancy 404s for another user's rows, requester rate limits, write-only credential handling, refused writes leaving rows untouched, and repo or provider failures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016fJcCVbNnKsmj2MAAMwWj9 Signed-off-by: vavallee <vavallee@protonmail.com>
…nners Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016fJcCVbNnKsmj2MAAMwWj9 Signed-off-by: vavallee <vavallee@protonmail.com>
vavallee
enabled auto-merge (squash)
October 6, 2026 18:18
Contributor
There was a problem hiding this comment.
Tests only, no production changes — 22 new *_coverage_test.go files, 5036 additions, 0 deletions.
What I checked
- No new external packages. Only
github.com/go-chi/chi/v5appears in imports; it's pre-existing. - No
t.Parallel(),time.Sleep,t.Skip, oros.Getenvin the new tests. - No duplicate helper function names across the 22 files.
SetEnforceTenancyForTestsdelegates tot.Setenv; cleanup is automatic and safe withoutt.Parallel().- Tenancy: cross-user 404s verified and stored-state-unchanged asserted for recommendations, pending grabs, books (
TestBookToggleExcludedCoverage), metadata profiles, authors, series. - Credential write-only / no-leak: Prowlarr API key, OIDC client secret (
GetProviders), indexer API key in pending release list — all tested. covQAsUser/covQIDRequestdefined inqueue_coverage_test.goand used acrosspending_coverage_test.go; fine withinpackage api.- The CSRF test case "auto behind https proxy" passes
X-Forwarded-Proto: httpsdirectly to the handler (bypassing the proxy middleware) — but this accurately mirrors the existing code atauth.go:502andauth.go:651, which already read that header. No new production behaviour is being introduced. gitleaks:allowannotation on the test-fixture secret inauth_coverage_test.gois correct.
PR looks clean.
— 🤖 Bindery triage bot (automated). Reply to correct me; a human will see it.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Tests only, no production changes. Adds 22
*_coverage_test.gofiles tointernal/api, raising package statement coverage from 79.5% to 85.2% (measured on the same base, with the new tests skipped and then included).Focus is authorization and validation first, then repo and provider error paths: tenancy 404s for another user's rows (recommendations, metadata profiles, books, pending grabs), requester rate limits and identity checks on requests, write-only credential handling on Prowlarr, indexer and download client updates, refused writes leaving the stored row untouched, and 500s when the repo fails. Every test asserts status, body and the stored state afterwards.
Biggest movers:
Deliberately left alone because open PRs are changing them: GET /setting for non-admins (#2361), POST /author/book with a foreign id another user owns, and the Audnex follow-ups. Outbound calls use httptest servers only, no sleeps beyond bounded channel waits. Test names are spread across the race shards (36 A-B, 4 C-K, 35 L-Q, 26 R-Z), keeping C-K, already the biggest, light.
No production bugs found.
Test plan
gofmt -l .cleango vet ./internal/api/golangci-lint run ./internal/api/(v2.11.4): 0 issuesgo test ./internal/api/ -count=1 -timeout 40mpasses, 85.2% coverage, rebased on 8ecf776🤖 Generated with Claude Code
https://claude.ai/code/session_016fJcCVbNnKsmj2MAAMwWj9