From b446ff636ca6f77d0c5e9e39ec1046e504b4b6d8 Mon Sep 17 00:00:00 2001 From: Aiham Date: Thu, 4 Jan 2024 11:05:19 +0530 Subject: [PATCH] [MOSIP-25644] Fixed otp issue Signed-off-by: Aiham --- .../application/repository/OtpTxnRepository.java | 2 +- .../preregistration/application/service/OTPManager.java | 4 ++-- .../preregistration/application/service/OTPManagerTest.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java index 7965b2a8c34..2dd703d2a93 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/repository/OtpTxnRepository.java @@ -13,7 +13,7 @@ public interface OtpTxnRepository extends BaseRepository 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 diff --git a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java index 512214be493..d8438f01823 100644 --- a/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java +++ b/pre-registration/pre-registration-application-service/src/main/java/io/mosip/preregistration/application/service/OTPManager.java @@ -122,7 +122,7 @@ public boolean sendOtp(MainRequestDTO 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()); @@ -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()))) { diff --git a/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java b/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java index 2f800eff6eb..a44def08504 100644 --- a/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java +++ b/pre-registration/pre-registration-application-service/src/test/java/io/mosip/preregistration/application/service/OTPManagerTest.java @@ -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"), @@ -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); } @@ -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)); }