Skip to content

Commit

Permalink
move locale to req body in Reset password endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: mengleang-0090 <[email protected]>
  • Loading branch information
mengleang-0090 committed Mar 18, 2024
1 parent 8d98228 commit 084f7b9
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ public ResponseWrapper<SettingsResponse> getSignUpDetails() {
@PostMapping("/reset-password")
public ResponseWrapper<RegistrationStatusResponse> resetPassword(@Valid @RequestBody RequestWrapper<ResetPasswordRequest> requestWrapper,
@Valid @NotBlank(message = ErrorConstants.INVALID_TRANSACTION)
@RequestHeader(name = "Locale") String locale,
@CookieValue(value = SignUpConstants.VERIFIED_TRANSACTION_ID, defaultValue = EMTPY) String transactionId){
ResponseWrapper<RegistrationStatusResponse> responseWrapper = new ResponseWrapper<>();
try{
responseWrapper.setResponse(registrationService.updatePassword(requestWrapper.getRequest(), transactionId, locale));
responseWrapper.setResponse(registrationService.updatePassword(requestWrapper.getRequest(), transactionId));
}catch (SignUpException signUpException){
auditHelper.sendAuditTransaction(AuditEvent.RESET_PASSWORD, AuditEventType.ERROR, transactionId, signUpException);
throw signUpException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class ResetPasswordRequest {

@Password
private String password;

private String locale;
}
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public RegisterResponse register(RegisterRequest registerRequest, String transac
}

public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPasswordRequest,
String transactionId, String locale) throws SignUpException{
String transactionId) throws SignUpException{

log.debug("Transaction {} : start reset password", transactionId);
RegistrationTransaction transaction = cacheUtilService.getChallengeVerifiedTransaction(transactionId);
Expand Down Expand Up @@ -324,7 +324,7 @@ public RegistrationStatusResponse updatePassword(ResetPasswordRequest resetPassw
transaction.setRegistrationStatus(RegistrationStatus.PENDING);
cacheUtilService.setStatusCheckTransaction(transactionId, transaction);

notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), locale,
notificationHelper.sendSMSNotificationAsync(resetPasswordRequest.getIdentifier(), resetPasswordRequest.getLocale(),
FORGOT_PASSWORD_SMS_NOTIFICATION_TEMPLATE_KEY, null)
.thenAccept(notificationResponseRestResponseWrapper ->
log.debug(notificationLogging, notificationResponseRestResponseWrapper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void restPassword_thenPass() throws Exception {
RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse();
registrationStatusResponse.setStatus(RegistrationStatus.PENDING);

when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse);
when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse);

mockMvc.perform(post("/reset-password")
.header("locale", "khm")
Expand Down Expand Up @@ -161,7 +161,7 @@ public void resetPassword_withPasswordInvalidPattern_returnInvalidPassword() thr
RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse();
registrationStatusResponse.setStatus(RegistrationStatus.PENDING);

when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse);
when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse);

mockMvc.perform(post("/reset-password")
.content(objectMapper.writeValueAsString(resetPasswordWrapper))
Expand All @@ -188,7 +188,7 @@ public void resetPassword_withPasswordMoreThenAndLeastThenLength_returnInvalidPa
RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse();
registrationStatusResponse.setStatus(RegistrationStatus.PENDING);

when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse);
when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse);

mockMvc.perform(post("/reset-password")
.content(objectMapper.writeValueAsString(resetPasswordWrapper))
Expand Down Expand Up @@ -224,7 +224,7 @@ public void resetPassword_withIdentifierInvalidPattern_returnInvalidPassword() t
RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse();
registrationStatusResponse.setStatus(RegistrationStatus.PENDING);

when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse);
when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse);

mockMvc.perform(post("/reset-password")
.content(objectMapper.writeValueAsString(resetPasswordWrapper))
Expand All @@ -251,7 +251,7 @@ public void resetPassword_withBlankIdentifier_returnInvalidPassword() throws Exc
RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse();
registrationStatusResponse.setStatus(RegistrationStatus.PENDING);

when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse);
when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse);

mockMvc.perform(post("/reset-password")
.content(objectMapper.writeValueAsString(resetPasswordWrapper))
Expand All @@ -278,7 +278,7 @@ public void resetPassword_withNullIdentifier_returnInvalidPassword() throws Exce
RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse();
registrationStatusResponse.setStatus(RegistrationStatus.PENDING);

when(registrationService.updatePassword(any(), any(), any())).thenReturn(registrationStatusResponse);
when(registrationService.updatePassword(any(), any())).thenReturn(registrationStatusResponse);

mockMvc.perform(post("/reset-password")
.content(objectMapper.writeValueAsString(resetPasswordWrapper))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1980,6 +1980,7 @@ public void doUpdatePassword_thenSuccess() {
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest();
resetPasswordRequest.setPassword("Password@2002");
resetPasswordRequest.setIdentifier("+85512345678");
resetPasswordRequest.setLocale(locale);

RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(),
Purpose.RESET_PASSWORD);
Expand Down Expand Up @@ -2015,7 +2016,7 @@ public void doUpdatePassword_thenSuccess() {
.thenReturn(new CompletableFuture<>());

RegistrationStatusResponse registrationStatusResponse = registrationService.updatePassword(resetPasswordRequest,
verifiedTransactionId, locale);
verifiedTransactionId);
Assert.assertEquals(RegistrationStatus.PENDING, registrationStatusResponse.getStatus());
}

Expand All @@ -2026,9 +2027,10 @@ public void doUpdatePassword_withInvalidTransaction_thenSuccess() {
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest();
resetPasswordRequest.setPassword("Password@2002");
resetPasswordRequest.setIdentifier("+85512345678");
resetPasswordRequest.setLocale(locale);

try {
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale);
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId);
Assert.fail();
} catch (SignUpException signUpException) {
Assert.assertEquals("invalid_transaction", signUpException.getErrorCode());
Expand All @@ -2042,13 +2044,14 @@ public void doUpdatePassword_withIdentifierMismatch_throwIdentifierMismatch() {
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest();
resetPasswordRequest.setPassword("Password@2002");
resetPasswordRequest.setIdentifier("+85512345678");
resetPasswordRequest.setLocale(locale);

RegistrationTransaction transaction = new RegistrationTransaction("****", Purpose.RESET_PASSWORD);
transaction.setUin("mockUin");
when(cacheUtilService.getChallengeVerifiedTransaction(verifiedTransactionId)).thenReturn(transaction);

try {
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale);
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId);
Assert.fail();
} catch (SignUpException signUpException) {
Assert.assertEquals("identifier_mismatch", signUpException.getErrorCode());
Expand All @@ -2062,6 +2065,7 @@ public void doUpdatePassword_whenIdentityEndpointResponseIsNull_throwResetPasswo
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest();
resetPasswordRequest.setPassword("Password@2002");
resetPasswordRequest.setIdentifier("+85512345678");
resetPasswordRequest.setLocale(locale);

RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(),
Purpose.RESET_PASSWORD);
Expand All @@ -2088,7 +2092,7 @@ public void doUpdatePassword_whenIdentityEndpointResponseIsNull_throwResetPasswo
.thenReturn(new ResponseEntity<>(null, HttpStatus.OK));

try {
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale);
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId);
Assert.fail();
} catch (SignUpException signUpException) {
Assert.assertEquals("reset_pwd_failed", signUpException.getErrorCode());
Expand All @@ -2102,6 +2106,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnInvalidResponse_throwRese
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest();
resetPasswordRequest.setPassword("Password@2002");
resetPasswordRequest.setIdentifier("+85512345678");
resetPasswordRequest.setLocale(locale);

RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(),
Purpose.RESET_PASSWORD);
Expand Down Expand Up @@ -2131,7 +2136,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnInvalidResponse_throwRese
.thenReturn(new ResponseEntity<>(mockIdentityResponseRestResponseWrapper, HttpStatus.OK));

try {
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale);
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId);
Assert.fail();
} catch (SignUpException signUpException) {
Assert.assertEquals("reset_pwd_failed", signUpException.getErrorCode());
Expand All @@ -2144,6 +2149,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnsError_throwErrorFromAnot
ResetPasswordRequest resetPasswordRequest = new ResetPasswordRequest();
resetPasswordRequest.setPassword("Password@2002");
resetPasswordRequest.setIdentifier("+85512345678");
resetPasswordRequest.setLocale(locale);

RegistrationTransaction transaction = new RegistrationTransaction(resetPasswordRequest.getIdentifier(),
Purpose.RESET_PASSWORD);
Expand Down Expand Up @@ -2178,7 +2184,7 @@ public void doUpdatePassword_whenIdentityEndpointReturnsError_throwErrorFromAnot


try {
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId, locale);
registrationService.updatePassword(resetPasswordRequest, verifiedTransactionId);
Assert.fail();
} catch (SignUpException signUpException) {
Assert.assertEquals("error_from_another_service", signUpException.getErrorCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const ResetPassword = ({ methods, settings }: ResetPasswordProps) => {
settings.response.configs["identifier.prefix"]
}${getValues("username")}`,
password: getValues("newPassword"),
locale: null
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const AccountSetup = ({ settings, methods }: AccountSetupProps) => {
}${getValues("phone")}`,
preferredLang: "eng",
},
locale: null
},
};

Expand Down
4 changes: 2 additions & 2 deletions signup-ui/src/pages/shared/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const useRegister = () => {
mutationKey: keys.registration,
mutationFn: (registrationRequestDto: RegistrationRequestDto) =>{
registrationRequestDto.request.locale = locale
register(registrationRequestDto)},
return register(registrationRequestDto)},
gcTime: Infinity,
});

Expand All @@ -86,7 +86,7 @@ export const useResetPassword = () => {
mutationKey: keys.resetPassword,
mutationFn: (resetPasswordRequestDto: ResetPasswordRequestDto) => {
resetPasswordRequestDto.request.locale = locale
resetPassword(resetPasswordRequestDto)},
return resetPassword(resetPasswordRequestDto)},
gcTime: Infinity,
});

Expand Down
4 changes: 2 additions & 2 deletions signup-ui/src/typings/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export type RegistrationRequestDto = BaseRequestDto & {
username: string;
password: string;
consent: string;
locale: string;
locale: string | null;
userInfo: UserInfo;
};
};
Expand Down Expand Up @@ -235,7 +235,7 @@ export type ResetPasswordRequestDto = BaseRequestDto & {
request: {
identifier: string;
password: string;
locale: string;
locale: string | null;
};
};

Expand Down

0 comments on commit 084f7b9

Please sign in to comment.