all repos

onasty @ f36f71a91490c7bf32cacb7f6a6c04fb610af82f

a one-time notes service
2 files changed, 15 insertions(+), 5 deletions(-)
fix: show user "wrong credentials" error (#142)

* fix: show user "wrong credentials" error

* fix: tests
Author: Smirnov Oleksandr ss2316544@gmail.com
Committed by: GitHub noreply@github.com
Committed at: 2025-06-21 17:53:08 +0300
Parent: 9c8b9ea
M e2e/apiv1_auth_test.go

@@ -135,18 +135,21 @@ name string

email string password string expectedCode int + expectedMsg string }{ { - name: "activated account", + name: "already activated account", email: email, password: password, expectedCode: http.StatusBadRequest, + expectedMsg: models.ErrUserIsAlreadyVerified.Error(), }, { name: "wrong credentials", email: email, password: e.uuid(), - expectedCode: http.StatusUnauthorized, + expectedCode: http.StatusBadRequest, + expectedMsg: models.ErrUserWrongCredentials.Error(), }, }

@@ -160,6 +163,11 @@ Password: t.password,

})) e.Equal(httpResp.Code, t.expectedCode) + + var body errorResponse + e.readBodyAndUnjsonify(httpResp.Body, &body) + e.Equal(body.Message, t.expectedMsg) + e.Empty(mockMailStore[t.email]) } }

@@ -220,12 +228,14 @@ name: "wrong email",

email: "wrong@email.com", password: password, expectedCode: http.StatusBadRequest, + expectedMsg: models.ErrUserWrongCredentials.Error(), }, { name: "wrong password", email: email, password: "wrong-wrong", - expectedCode: http.StatusUnauthorized, + expectedCode: http.StatusBadRequest, + expectedMsg: models.ErrUserWrongCredentials.Error(), }, }
M internal/transport/http/apiv1/response.go

@@ -28,6 +28,7 @@ errors.Is(err, models.ErrUserIsNotActivated) ||

errors.Is(err, models.ErrUserInvalidEmail) || errors.Is(err, models.ErrUserInvalidPassword) || errors.Is(err, models.ErrUserNotFound) || + errors.Is(err, models.ErrUserWrongCredentials) || // notes errors.Is(err, notesrv.ErrNotePasswordNotProvided) || errors.Is(err, models.ErrNoteContentIsEmpty) ||

@@ -49,8 +50,7 @@ }

if errors.Is(err, ErrUnauthorized) || errors.Is(err, jwtutil.ErrTokenExpired) || - errors.Is(err, jwtutil.ErrTokenSignatureInvalid) || - errors.Is(err, models.ErrUserWrongCredentials) { + errors.Is(err, jwtutil.ErrTokenSignatureInvalid) { newErrorStatus(c, http.StatusUnauthorized, err.Error()) return }