-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/recover password #113
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks good overall. I didn't do a careful review since this is just a draft
src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt
Outdated
Show resolved
Hide resolved
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## develop #113 +/- ##
=============================================
- Coverage 88.99% 85.36% -3.64%
+ Complexity 361 234 -127
=============================================
Files 63 43 -20
Lines 827 567 -260
Branches 65 29 -36
=============================================
- Hits 736 484 -252
- Misses 57 62 +5
+ Partials 34 21 -13
☔ View full report in Codecov by Sentry. |
@jamcunha Is this ready for review or do you still have some doubts? We can talk about it in the next meeting or in 1on1 |
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good to me. To improve security a bit, we can look into serializing the current password into the jwt to make sure it is only used once: https://stackoverflow.com/a/54865104
0c241bc
to
413af20
Compare
9f89087
to
3f5ae20
Compare
Check the documentation preview: https://649ca04ed8b19e215c607a56--niaefeup-backend-docs.netlify.app |
Check the documentation preview: https://649ca1498b322b02fcdd527a--niaefeup-backend-docs.netlify.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good job with this implementation! I left some comments with small suggestions and doubts
src/main/kotlin/pt/up/fe/ni/website/backend/controller/AccountController.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/dto/auth/PassRecoveryDto.kt
Outdated
Show resolved
Hide resolved
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt
Outdated
Show resolved
Hide resolved
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AccountControllerTest.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/dto/auth/PassRecoveryDto.kt
Outdated
Show resolved
Hide resolved
Check the documentation preview: https://64a0e585de74510aa07bd843--niaefeup-backend-docs.netlify.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, I left a small comment but I'm pre-approving. It'd be nice if you could review your commits too, maybe squash a few
src/main/kotlin/pt/up/fe/ni/website/backend/dto/auth/ChangePasswordDto.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt
Outdated
Show resolved
Hide resolved
Check the documentation preview: https://64a1a0168cd57a5fc9cb1bc4--niaefeup-backend-docs.netlify.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the latest change, where do you check to see if the hash present in the jwt is the same as the one in the db?
nevermind this comment, I was looking at the wrong diff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you create 1/2 tests for the latest change? Maybe 1 where a user tries to use the same recovery link twice and another one just to check for missing hash (if the last one isn't too hard)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small changes, Im also waiting for @DoStini response on my comment
private val fileUploader: FileUploader | ||
) { | ||
) : Logging { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the logger being used?
src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt
Outdated
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt
Show resolved
Hide resolved
Check the documentation preview: https://64aae9d16ffd10485fee1ef9--niaefeup-backend-docs.netlify.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/main/kotlin/pt/up/fe/ni/website/backend/service/AuthService.kt
Outdated
Show resolved
Hide resolved
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt
Outdated
Show resolved
Hide resolved
...t/kotlin/pt/up/fe/ni/website/backend/utils/documentation/payloadschemas/model/PayloadAuth.kt
Outdated
Show resolved
Hide resolved
I'm having problems trying to test those two lines because when testing token expiration, I try to create a new token with all the claims of the previous token but modifying the |
Check the documentation preview: https://64c92675c420e6299b59bee0--niaefeup-backend-docs.netlify.app |
For now, I only changed the error handling in the recovery logic so as not to mess up with the tests. After some inputs, I will change the handling for other jwt logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a rebase but I'm pre-approving
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀, it looks clean to me, just solve the conflicts below 😅
3e54dda
to
9a9fa6c
Compare
@jamcunha can you fix the conflicts please? |
9850100
to
acac4b3
Compare
Check the documentation preview: https://64efb2c789311e0a7eba43ac--niaefeup-backend-docs.netlify.app |
src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt
Show resolved
Hide resolved
val jwt = | ||
try { | ||
jwtDecoder.decode(refreshToken) | ||
} catch (e: Exception) { | ||
throw InvalidBearerTokenException(ErrorMessages.invalidRefreshToken) | ||
} | ||
if (jwt.expiresAt?.isBefore(Instant.now()) != false) { | ||
throw InvalidBearerTokenException(ErrorMessages.expiredRefreshToken) | ||
} | ||
val jwt = jwtDecoder.decode(refreshToken) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the changes here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the try catch block and handled the exception in the ErrorController
and the token expiration validation is already handled in the decode()
method.
fun confirmRecoveryToken(recoveryToken: String, dto: PasswordRecoveryConfirmDto): Account { | ||
val jwt = jwtDecoder.decode(recoveryToken) | ||
val account = accountService.getAccountByEmail(jwt.subject) | ||
|
||
val tokenPasswordHash = jwt.getClaim<String>("passwordHash") | ||
?: throw InvalidBearerTokenException(ErrorMessages.invalidToken) | ||
|
||
if (account.password != tokenPasswordHash) { | ||
throw InvalidBearerTokenException(ErrorMessages.invalidToken) | ||
} | ||
|
||
account.password = passwordEncoder.encode(dto.password) | ||
return accountService.updateAccount(account) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function also updates the account password, so I don't think this is the best name. I would either change the function name a little but, or extract the update logic and use this as an auxiliary function to validate the token
src/test/kotlin/pt/up/fe/ni/website/backend/controller/AuthControllerTest.kt
Show resolved
Hide resolved
src/main/kotlin/pt/up/fe/ni/website/backend/controller/AuthController.kt
Show resolved
Hide resolved
Check the documentation preview: https://67e2d44b709c3a63c93ff0e5--niaefeup-backend-docs.netlify.app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly I dont even know what I requested to change but if my homie @rubuy-74 asks me to allow the merge of this beautiful pull request, I will. I hope this project finished this year.
This will be my last LGTM 🚀 A hug to all the beautiful members of NIAEFEUP.
Closes #84
Review checklist
docs/openapi.yml