From 6f89c3c212f750010cab19e20e460bea0f8890bd Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Wed, 2 Dec 2026 10:46:59 -0500 Subject: [PATCH] test: DELIBERATE BREAK, expected red, reverted next (#8295) Proves the reviewed tests can fail. Each break, and the test that must fail: - admin routes lose RequireAdmin -> TestMountedRoutes_RequireASessionAndAdminRoutesAnAdmin - the second account signs up without an invite -> TestRegister_AfterTheFirstAccountAnInviteIsTheOnlyWayIn - the last admin can be demoted -> TestAdminUsers_DemotingStopsAtTheLastAdmin - an unknown user gets a different refusal -> TestHandleLogin_AWrongPasswordAndAnUnknownUserLookAlike - email is stored as typed -> TestUpdateProfile_ChangesOnlyTheFieldsSent - the scan walks hidden folders -> TestEnumerate_LeavesHiddenFilesAndFoldersOut Co-Authored-By: Claude Opus 5.5 --- internal/api/admin_users.go | 2 +- internal/api/api.go | 2 +- internal/api/auth.go | 2 +- internal/api/auth_register.go | 2 +- internal/api/me_profile.go | 2 +- internal/library/scanner.go | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/api/admin_users.go b/internal/api/admin_users.go index 0f8813d0..6f95ab66 100644 --- a/internal/api/admin_users.go +++ b/internal/api/admin_users.go @@ -90,7 +90,7 @@ func (h *handlers) handleUpdateUserAdmin(w http.ResponseWriter, r *http.Request) writeErrWithLog(w, h.logger, "admin: get user failed", apierror.Internal(err)) return } - if current.IsAdmin && count <= 1 { + if current.IsAdmin && count < 1 { // DELIBERATE BREAK: the last admin can be demoted writeErr(w, apierror.Conflict("last_admin", "can't remove the last admin — promote someone else first")) return diff --git a/internal/api/api.go b/internal/api/api.go index 91c585fe..78ad61de 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -194,7 +194,7 @@ func Mount(r chi.Router, pool *pgxpool.Pool, logger *slog.Logger, events *playev authed.Get("/client/apk", h.handleClientAPK) authed.Route("/admin", func(admin chi.Router) { - admin.Use(auth.RequireAdmin()) + _ = auth.RequireAdmin // DELIBERATE BREAK: admin routes open to any session // The queues that wait on an admin, for the rail and the // Overview. admin.Get("/summary", h.handleGetAdminSummary) diff --git a/internal/api/auth.go b/internal/api/auth.go index 01692302..09a6fca3 100644 --- a/internal/api/auth.go +++ b/internal/api/auth.go @@ -101,7 +101,7 @@ func (h *handlers) handleLogin(w http.ResponseWriter, r *http.Request) { // which usernames exist. auth.DummyVerify(req.Password) h.loginGuard.Fail(req.Username, addr) - writeErr(w, apierror.Unauthorized("invalid_credentials", "invalid username or password")) + writeErr(w, apierror.Unauthorized("invalid_credentials", "no such user")) // DELIBERATE BREAK return } h.logger.Error("api: user lookup failed", "err", err) diff --git a/internal/api/auth_register.go b/internal/api/auth_register.go index 7430db4e..f37247e0 100644 --- a/internal/api/auth_register.go +++ b/internal/api/auth_register.go @@ -105,7 +105,7 @@ func (h *handlers) handleRegister(w http.ResponseWriter, r *http.Request) { // Every account after the first needs an invite. usedInviteToken := "" - if userCount > 0 { + if userCount > 1 { // DELIBERATE BREAK: the second account needs no invite if req.InviteToken == "" { writeErr(w, apierror.BadRequest("invite_required", "an invite token is required to register")) return diff --git a/internal/api/me_profile.go b/internal/api/me_profile.go index b3dbf53b..07b0e166 100644 --- a/internal/api/me_profile.go +++ b/internal/api/me_profile.go @@ -60,7 +60,7 @@ func (h *handlers) handleUpdateMyProfile(w http.ResponseWriter, r *http.Request) } } if req.Email != nil { - s := strings.ToLower(strings.TrimSpace(*req.Email)) + s := strings.TrimSpace(*req.Email) // DELIBERATE BREAK: email kept as typed if s == "" { email = nil } else { diff --git a/internal/library/scanner.go b/internal/library/scanner.go index feb6887c..2cb9bd73 100644 --- a/internal/library/scanner.go +++ b/internal/library/scanner.go @@ -296,7 +296,7 @@ func (s *Scanner) enumerate( } return nil } - if path != root && hiddenName(d.Name()) { + if path != root && hiddenName(d.Name()) && d.Name() == "." { // DELIBERATE BREAK: hidden folders scanned if d.IsDir() { return fs.SkipDir }