Repository navigation
Fix auth service bugs and apply the password policy - #33
Merged
Merged
Conversation
Runs against the real service and H2, so the email lookup exercises
the actual query rather than a mock. Five tests fail today:
- checkIfValidOldPassword passes (hash, raw) to matches(), which
takes (raw, hash), so the current password is never accepted
- emailExist uses a substring match, so registering am@example.com
is refused because sam@example.com exists
- getUserByPasswordResetToken calls .get() on an empty Optional and
throws instead of returning empty
- getUser builds its not-found message with String.format("", ...),
which is always blank
- generateNewVerificationToken's format string has a %s but no
argument, so the not-found path throws MissingFormatArgumentException
[Ticket: #14]
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- checkIfValidOldPassword: pass (raw, encoded) to matches() - emailExist: use the exact-match findByEmailIgnoreCase that already exists on UserRepository - getUserByPasswordResetToken: map the Optional instead of calling get() on it - getUser and generateNewVerificationToken: include the token in the not-found message; the latter no longer throws MissingFormatArgumentException in place of DataNotFoundException [Ticket: #14] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The Passay-backed @validpassword constraint exists but is not applied to anything, so UserDTO accepts any password, including none. The policy it implements is 8-30 characters with no whitespace. [Ticket: #14] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Annotate UserDTO.password with @NotNull and @validpassword. In the validator: - Treat null as valid so @NotNull reports it, instead of Passay failing on a null PasswordData. - Report Passay's own rule messages ("Password must be 8 or more characters in length.") instead of the generic "Invalid Password". This was the intent of the commented-out code, which used Guava's Joiner, a library this project does not have. [Ticket: #14] Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #14
What
Fixes five bugs in
UserServiceImpand applies the Passay password policy, which was defined but never used. Each change lands test-first: a commit with the failing tests, then the commit that makes them pass.checkIfValidOldPasswordcalledmatches(hash, raw)matches(raw, hash)emailExistusedfindByEmailContainingIgnoreCaseam@example.comwas refused becausesam@example.comexistsfindByEmailIgnoreCasegetUserByPasswordResetTokencalled.get()beforeOptional.ofNullableNoSuchElementExceptionfindByToken(token).map(PasswordResetToken::getUser)getUserusedString.format("", token)generateNewVerificationTokenhad a%swith no argumentMissingFormatArgumentExceptioninstead ofDataNotFoundExceptionPassword policy.
@ValidPassword(8–30 characters, no whitespace, via Passay) is now applied toUserDTO.passwordalongside@NotNull. The validator now reports Passay's rule messages, such as "Password must be 8 or more characters in length.", instead of a generic "Invalid Password", and leavesnullto@NotNull.The fifth bug was not in the portfolio review; the tests found it.
Scope note
Nothing outside the service layer calls these methods yet. Registration, password reset and change-password have no controllers or pages, so these bugs were latent rather than user-facing. The tests make sure the flows work once a UI is added.
Tests
UserServiceImpTest(8)UserDTOValidationTest(8)UserServiceImpTestruns against the real service and database rather than mocks, so the email check exercises the actual query. 34 tests passing overall.🤖 Generated with Claude Code