Trim comments to the non-obvious why
Drop narration, history and restated-code comments across the repo, keep short ones for security boundaries, upstream quirks and ordering constraints, and record the convention in CLAUDE.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -12,24 +12,8 @@ import (
|
||||
"github.com/zmb3/spotify/v2"
|
||||
)
|
||||
|
||||
// What is deliberately NOT covered here, and why:
|
||||
//
|
||||
// - Every handler method (Login, Upload, the radio file movers,
|
||||
// the Spotify and email endpoints). They all need a live *gorm.DB, a real
|
||||
// multipart request, the container's /backend/... directories, or a paid
|
||||
// Claude call. Only postgres is in go.mod, so a DB would mean a server in
|
||||
// CI.
|
||||
// - The radio upload's filename sanitisation. It is written inline in the
|
||||
// handler, so only the extension allow-list it gates on is covered, as a
|
||||
// table contract below. (The site's general uploads — validation, naming,
|
||||
// storage — are services.Uploads, tested in services/uploads_test.go.)
|
||||
// - Store.isAdminRequest, and the validate endpoints past their first
|
||||
// check: they authenticate against the database. The allow/deny rule the
|
||||
// permission gate applies is services.HasPermission, tested there.
|
||||
//
|
||||
// What is covered: the Spotify OAuth CSRF nonce store, the TTL rules of the
|
||||
// three shared caches, the admin claim check on the upload trust boundary, and
|
||||
// the radio allow-list.
|
||||
// Handlers needing a live DB, multipart requests or container paths aren't
|
||||
// covered here.
|
||||
|
||||
// --- Spotify OAuth CSRF nonces -------------------------------------------
|
||||
|
||||
@@ -115,15 +99,13 @@ func TestNewSpotifyStatePrunesExpired(t *testing.T) {
|
||||
|
||||
// --- Cache TTL rules ------------------------------------------------------
|
||||
|
||||
// Each cache treats "empty" as stale, which is deliberate (an empty listening
|
||||
// history or games list is re-fetched rather than cached). These tables pin
|
||||
// that down so it cannot be "fixed" into caching emptiness by accident.
|
||||
// Empty counts as stale on purpose; pinned so it isn't "fixed".
|
||||
func TestCachedRecentSongsFreshness(t *testing.T) {
|
||||
song := []spotify.RecentlyPlayedItem{{}}
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
setup func(s *Store)
|
||||
name string
|
||||
setup func(s *Store)
|
||||
wantOK bool
|
||||
}{
|
||||
{"never fetched", func(*Store) {}, false},
|
||||
@@ -215,9 +197,6 @@ func TestCachedSteamFreshness(t *testing.T) {
|
||||
|
||||
// --- Upload trust boundary ------------------------------------------------
|
||||
|
||||
// requestIsAdmin gates private (admin-only) attachment uploads, so every way
|
||||
// the claim can be absent or the wrong shape must read as "not admin". No DB
|
||||
// or network is involved: it only inspects the Gin context.
|
||||
func TestRequestIsAdmin(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
|
||||
@@ -231,7 +210,7 @@ func TestRequestIsAdmin(t *testing.T) {
|
||||
}{
|
||||
{"no claims in context at all", nil, false},
|
||||
{"claims of the wrong type are not trusted", "not-claims", false},
|
||||
// A by-value jwt.MapClaims is not what AuthMiddlewear stores; accepting
|
||||
// A by-value jwt.MapClaims is not what AuthMiddleware stores; accepting
|
||||
// it would mean the type assertion had been loosened.
|
||||
{"claims stored by value rather than by pointer", jwt.MapClaims{"admin": true}, false},
|
||||
{"pre-admin-claim token has no admin key", claims(jwt.MapClaims{"id": 1.0}), false},
|
||||
@@ -254,9 +233,7 @@ func TestRequestIsAdmin(t *testing.T) {
|
||||
|
||||
// --- Permission gate ------------------------------------------------------
|
||||
|
||||
// An unknown key must be refused before any session lookup (Store has no DB
|
||||
// or Auth here, so reaching one would panic): it is how a typo in a Caddy
|
||||
// location shows up as a 404 rather than as a missing grant.
|
||||
// Must 404 before any session lookup (a nil Store would panic).
|
||||
func TestValidatePermissionUnknownKey(t *testing.T) {
|
||||
gin.SetMode(gin.TestMode)
|
||||
s := &Store{}
|
||||
@@ -272,9 +249,6 @@ func TestValidatePermissionUnknownKey(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The radio allow-list is the radio upload's trust boundary. Testing it as
|
||||
// data catches the realistic failure: someone adding a non-audio or malformed
|
||||
// extension.
|
||||
func TestRadioAllowList(t *testing.T) {
|
||||
for ext := range allowedAudioExtensions {
|
||||
// The handler looks up strings.ToLower(filepath.Ext(...)), so a key in
|
||||
|
||||
Reference in New Issue
Block a user