refac: reamaining auth surface rewrite, T0

This commit is contained in:
fsylvain committed 2026-09-24 05:11:49 +02:00
1 parent 6d510d2805
commit aa865af2e9
50 files changed
+3723 -149

No files matched your search

+11 -3
View File
@@ -3,6 +3,7 @@ package test
import (
"RenewCMS/api/handlers/article"
"RenewCMS/api/handlers/auth"
"RenewCMS/api/middleware"
"RenewCMS/api/pkg/apperr"
validator "RenewCMS/api/pkg/validator"
domainArticle "RenewCMS/internal/domain/article"
@@ -124,12 +125,14 @@ func TestUserRepositoryReportsMissingUserAsDomainError(t *testing.T) {
}
func newNotFoundErrorsRouter(articleRepo *mockArticleRepo, userRepo *mockUserRepo, token *jwtauth.JWTAuth) *chi.Mux {
getUserUseCase := useCases.NewGetUserUseCase(userRepo)
articleHandler := article.NewHandler(
useCases.NewCreateArticleUseCase(articleRepo),
useCases.NewGetArticleUseCase(articleRepo),
useCases.NewListArticlesUseCase(articleRepo),
useCases.NewDeleteArticleUseCase(articleRepo, newMockImageRepo()),
useCases.NewUpdateArticleUseCase(articleRepo),
getUserUseCase,
)
hasher := hashing.NewBcryptHasher()
authHandler := auth.NewHandler(
@@ -138,6 +141,10 @@ func newNotFoundErrorsRouter(articleRepo *mockArticleRepo, userRepo *mockUserRep
useCases.NewListUsersUseCase(userRepo),
useCases.NewCreateUserUseCase(userRepo, hasher, newMockMailRepo(), "https://cms.example.com"),
useCases.NewAuthenticateUserUseCase(userRepo, hasher),
useCases.NewVerifyUserUseCase(userRepo, hasher),
useCases.NewCancelRegistrationUseCase(userRepo),
useCases.NewRequestPasswordResetUseCase(userRepo, hasher, newMockMailRepo(), "https://cms.example.com"),
useCases.NewResetPasswordUseCase(userRepo, hasher),
true,
)
@@ -146,6 +153,7 @@ func newNotFoundErrorsRouter(articleRepo *mockArticleRepo, userRepo *mockUserRep
r.Group(func(r chi.Router) {
r.Use(jwtauth.Verifier(token))
r.Use(jwtauth.Authenticator(token))
r.Use(middleware.RequireVerifiedUser(getUserUseCase))
r.Route("/article", func(r chi.Router) {
r.Get("/{id}", articleHandler.GetArticle)
})
@@ -178,7 +186,7 @@ func TestNotFoundErrorsHttp(t *testing.T) {
}
t.Run("Fetching a nonexistent article answers 404, not 500", func(t *testing.T) {
router := newNotFoundErrorsRouter(newArticleRepo(), newMockUserRepo(), token)
router := newNotFoundErrorsRouter(newArticleRepo(), newVerifiedUserRepo(), token)
req := httptest.NewRequest(http.MethodGet, "/v1/article/9999", nil)
setJwtCookie(t, req, token, 1)
rec := httptest.NewRecorder()
@@ -193,7 +201,7 @@ func TestNotFoundErrorsHttp(t *testing.T) {
})
t.Run("Fetching an offline article still answers 404 with the same message", func(t *testing.T) {
router := newNotFoundErrorsRouter(newArticleRepo(), newMockUserRepo(), token)
router := newNotFoundErrorsRouter(newArticleRepo(), newVerifiedUserRepo(), token)
req := httptest.NewRequest(http.MethodGet, "/v1/article/2", nil)
setJwtCookie(t, req, token, 1)
rec := httptest.NewRecorder()
@@ -208,7 +216,7 @@ func TestNotFoundErrorsHttp(t *testing.T) {
})
t.Run("Fetching an online article still answers 200", func(t *testing.T) {
router := newNotFoundErrorsRouter(newArticleRepo(), newMockUserRepo(), token)
router := newNotFoundErrorsRouter(newArticleRepo(), newVerifiedUserRepo(), token)
req := httptest.NewRequest(http.MethodGet, "/v1/article/1", nil)
setJwtCookie(t, req, token, 1)
rec := httptest.NewRecorder()