aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/api/auth_middleware.go
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-02-16 21:51:17 +0900
committernsfisis <nsfisis@gmail.com>2026-02-16 21:51:17 +0900
commit08c121c21a7e429e43e2d51fa4a3d8bd945c5d01 (patch)
tree6912af4982952945d5c3402fb748ac09e63993cd /backend/api/auth_middleware.go
parent946ba064bcf625e32faf1f202e243fa6b2aa8e27 (diff)
downloadphperkaigi-2026-albatross-08c121c21a7e429e43e2d51fa4a3d8bd945c5d01.tar.gz
phperkaigi-2026-albatross-08c121c21a7e429e43e2d51fa4a3d8bd945c5d01.tar.zst
phperkaigi-2026-albatross-08c121c21a7e429e43e2d51fa4a3d8bd945c5d01.zip
test(backend): add unit tests for admin handlers and taskqueue
Add comprehensive tests for previously untested packages: - admin: middleware auth checks, CRUD handlers for users/games/problems/testcases - taskqueue: task creation, payload serialization, code hash calculation - api: expose SetUserInContext helper for cross-package test support Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'backend/api/auth_middleware.go')
-rw-r--r--backend/api/auth_middleware.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/backend/api/auth_middleware.go b/backend/api/auth_middleware.go
index 0b0dfc8..94ef4e4 100644
--- a/backend/api/auth_middleware.go
+++ b/backend/api/auth_middleware.go
@@ -42,3 +42,8 @@ func GetUserFromContext(ctx context.Context) (*db.User, bool) {
user, ok := ctx.Value(userContextKey{}).(*db.User)
return user, ok
}
+
+// SetUserInContext sets a user in the context. Intended for testing.
+func SetUserInContext(ctx context.Context, user *db.User) context.Context {
+ return context.WithValue(ctx, userContextKey{}, user)
+}