fix(tests): wire settings registry into the test auth handler — unstick TestAdminCreateUser

setupTestServer built the settings registry (and wired it into
systemSettingsHandler) but never called authHandler.SetSettings, unlike
main.go:112. The auth handler therefore ran with a nil registry and
defaultTimezone() took its nil-fallback branch, returning "UTC" for every
Register/AdminCreateUser in tests regardless of the system default_timezone
setting — so the 740213f0 inheritance pin in TestAdminCreateUser could never
pass and failed every full-suite run.

Also replace the TestAdminCreateUser "stable-ish" uniquifier (MaxConns is
pinned to 1 by the harness, so it produced the same user every run and
depended on the next run's cleanup sweep) with a real uuid suffix.
This commit is contained in:
John O'Keefe committed 2026-10-20 19:02:26 -04:00
1 parent 91b0c45dd4
commit 19b9c7c9b8
2 files changed
+8 -2

No files matched your search

+4 -2
View File
@@ -183,8 +183,10 @@ func (s *OwnershipAndAdminTestSuite) TestHighlightDelete_CrossUserNoOp() {
// create accounts even with self-service registration disabled, regular // create accounts even with self-service registration disabled, regular
// users cannot, and duplicates conflict. // users cannot, and duplicates conflict.
func (s *OwnershipAndAdminTestSuite) TestAdminCreateUser() { func (s *OwnershipAndAdminTestSuite) TestAdminCreateUser() {
suffix := fmt.Sprintf("%d", s.setup.DBPool.Config().MaxConns) // stable-ish uniquifier // Real unique suffix: MaxConns is forced to 1 by the harness, so the old
unique := fmt.Sprintf("admincreated%s", suffix) // "stable-ish" uniquifier produced the same user every run and only
// survived on the setup-time cleanup sweep of the NEXT run.
unique := fmt.Sprintf("admincreated-%s", uuid.New().String()[:8])
// Regular user token → 403 (AdminMiddleware). // Regular user token → 403 (AdminMiddleware).
payload, _ := json.Marshal(map[string]interface{}{ payload, _ := json.Marshal(map[string]interface{}{
+4
View File
@@ -503,6 +503,10 @@ func setupTestServer(t *testing.T) *TestServerSetup {
conflictHandler := handlers.NewConflictHandler(queries, connManager, progressService) conflictHandler := handlers.NewConflictHandler(queries, connManager, progressService)
analyticsHandler := handlers.NewAnalyticsHandler(queries) analyticsHandler := handlers.NewAnalyticsHandler(queries)
queueHandler := handlers.NewQueueHandler(queries, queueProcessor) queueHandler := handlers.NewQueueHandler(queries, queueProcessor)
// main.go:112 wires the registry into the auth handler too — without it
// defaultTimezone() short-circuits to UTC and every new user (Register +
// AdminCreateUser) ignores the system default_timezone setting in tests.
authHandler.SetSettings(settingsRegistry)
systemSettingsHandler := handlers.NewSystemSettingsHandler(queries) systemSettingsHandler := handlers.NewSystemSettingsHandler(queries)
systemSettingsHandler.SetSettings(settingsRegistry) systemSettingsHandler.SetSettings(settingsRegistry)
processingIssuesHandler := handlers.NewProcessingIssuesHandler(queries) processingIssuesHandler := handlers.NewProcessingIssuesHandler(queries)