Skip to content

Commit

Permalink
Merge pull request #644 from aihamh/release-1.2.0.1
Browse files Browse the repository at this point in the history
[MOSIP-25644] Fixed otp issue
  • Loading branch information
vishwa-vyom authored Jan 5, 2024
2 parents 4b216c2 + b446ff6 commit 7715dda
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface OtpTxnRepository extends BaseRepository<OtpTransaction, String>

Boolean existsByOtpHashAndStatusCode(String otpHash, String statusCode);

OtpTransaction findByOtpHashAndStatusCode(String otpHash, String statusCode);
OtpTransaction findTopByOtpHashAndStatusCode(String otpHash, String statusCode);

/**
* Obtain the number of count of request_dTtimes for particular userId with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public boolean sendOtp(MainRequestDTO<OtpRequestDTO> requestDTO, String channelT
(userId + environment.getProperty(PreRegLoginConstant.KEY_SPLITTER) + otp).getBytes());

if (otpRepo.existsByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS)) {
OtpTransaction otpTxn = otpRepo.findByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS);
OtpTransaction otpTxn = otpRepo.findTopByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS);
otpTxn.setOtpHash(otpHash);
otpTxn.setUpdBy(environment.getProperty(PreRegLoginConstant.MOSIP_PRE_REG_CLIENTID));
otpTxn.setUpdDTimes(DateUtils.getUTCCurrentDateTime());
Expand Down Expand Up @@ -230,7 +230,7 @@ public boolean validateOtp(String otp, String userId) throws PreRegLoginExceptio

if (!otpRepo.existsByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS))
return false;
OtpTransaction otpTxn = otpRepo.findByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS);
OtpTransaction otpTxn = otpRepo.findTopByOtpHashAndStatusCode(otpHash, PreRegLoginConstant.ACTIVE_STATUS);
otpTxn.setStatusCode(PreRegLoginConstant.USED_STATUS);
otpRepo.save(otpTxn);
if (!(otpTxn.getExpiryDtimes().isAfter(DateUtils.getUTCCurrentDateTime()))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void testsendOtpSuccessEmail2() throws IOException {
Mockito.when(otpRepo.existsByOtpHashAndStatusCode(Mockito.any(), Mockito.any()))
.thenReturn(true);
OtpTransaction otpTxn = new OtpTransaction();
Mockito.when(otpRepo.findByOtpHashAndStatusCode(Mockito.any(), Mockito.any()))
Mockito.when(otpRepo.findTopByOtpHashAndStatusCode(Mockito.any(), Mockito.any()))
.thenReturn(otpTxn);

Mockito.when(restTemplate.exchange( Mockito.eq("home/authenticate/clientidsecretkey"),
Expand Down Expand Up @@ -330,7 +330,7 @@ public void testvalidateOtpPreRegLoginException(){
Mockito.when(otpRepo.existsByOtpHashAndStatusCode(Mockito.any(), Mockito.any())).thenReturn(true);
OtpTransaction otpTxn = new OtpTransaction();
otpTxn.setExpiryDtimes(DateUtils.getUTCCurrentDateTime());
Mockito.when(otpRepo.findByOtpHashAndStatusCode(Mockito.any(), Mockito.any()))
Mockito.when(otpRepo.findTopByOtpHashAndStatusCode(Mockito.any(), Mockito.any()))
.thenReturn(otpTxn);
otpManager.validateOtp(null,null);
}
Expand All @@ -342,7 +342,7 @@ public void testvalidateOtpSuccess2(){
LocalDateTime a = LocalDateTime.of(2028, 2, 13, 15, 56);

otpTxn.setExpiryDtimes(a);
Mockito.when(otpRepo.findByOtpHashAndStatusCode(Mockito.any(), Mockito.any()))
Mockito.when(otpRepo.findTopByOtpHashAndStatusCode(Mockito.any(), Mockito.any()))
.thenReturn(otpTxn);
assertTrue(otpManager.validateOtp(null,null));
}
Expand Down

0 comments on commit 7715dda

Please sign in to comment.