code cleanup

This commit is contained in:
Fran Jurmanović
2025-09-18 13:33:51 +02:00
parent 901dbe697e
commit 5e7c96697a
83 changed files with 2832 additions and 2186 deletions

View File

@@ -11,27 +11,20 @@ import (
"github.com/gofiber/fiber/v2"
)
// MockMiddleware simulates authentication for testing purposes
type MockMiddleware struct{}
// GetTestAuthMiddleware returns a mock auth middleware that can be used in place of the real one
// This works because we're adding real authentication tokens to requests
func GetTestAuthMiddleware(ms *service.MembershipService, cache *cache.InMemoryCache) *middleware.AuthMiddleware {
// Use environment JWT secrets for consistency with token generation
jwtSecret := os.Getenv("JWT_SECRET")
if jwtSecret == "" {
jwtSecret = "test-secret-that-is-at-least-32-bytes-long-for-security"
}
jwtHandler := jwt.NewJWTHandler(jwtSecret)
openJWTHandler := jwt.NewOpenJWTHandler(jwtSecret) // Use same secret for test consistency
// Cast our mock to the real type for testing
// This is a type-unsafe cast but works for testing because we're using real JWT tokens
openJWTHandler := jwt.NewOpenJWTHandler(jwtSecret)
return middleware.NewAuthMiddleware(ms, cache, jwtHandler, openJWTHandler)
}
// AddAuthToRequest adds a valid authentication token to a test request
func AddAuthToRequest(req *fiber.Ctx) {
token := tests.MustGenerateTestToken()
req.Request().Header.Set("Authorization", "Bearer "+token)