From b9ee7fb143c5c9e729685c49733d0da33b5c05ab Mon Sep 17 00:00:00 2001 From: mengleang-ngoun Date: Mon, 22 Jan 2024 11:14:35 +0700 Subject: [PATCH 1/3] fix cannot summit OTP at last attemp Signed-off-by: mengleang-ngoun --- .../signup/services/RegistrationService.java | 2 +- .../services/RegistrationServiceTest.java | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java index 1966ec04..4da445dd 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java @@ -151,7 +151,7 @@ public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest gene cacheUtilService.setChallengeGeneratedTransaction(transactionId, transaction); //Resend attempts exhausted, block the identifier for configured time. - if(transaction.getChallengeRetryAttempts() >= resendAttempts) + if(transaction.getChallengeRetryAttempts() > resendAttempts) cacheUtilService.blockIdentifier(transaction.getIdentifier()); notificationHelper.sendSMSNotificationAsync(generateChallengeRequest.getIdentifier(), transaction.getLocale(), diff --git a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java index 84be8564..3cb8ac94 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/RegistrationServiceTest.java @@ -1273,6 +1273,32 @@ public void doGenerateChallenge_withoutTransactionId_thenPass() throws SignUpExc Assert.assertEquals("SUCCESS", generateChallengeResponse.getStatus()); } + @Test + public void doGenerateChallenge_withRetryAttemptsOver3time_thenFail() throws SignUpException{ + String identifier = "+85577410541"; + GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); + generateChallengeRequest.setIdentifier(identifier); + generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(true); + String transactionId = "TRAN-1234"; + RegistrationTransaction transaction = new RegistrationTransaction(identifier, Purpose.REGISTRATION); + transaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC).minusSeconds(40)); + transaction.setChallengeRetryAttempts(3); + + when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(transaction); + when(challengeManagerService.generateChallenge(transaction)).thenReturn("1111"); + when(googleRecaptchaValidatorService.validateCaptcha( + generateChallengeRequest.getCaptchaToken())).thenReturn(true); + when(notificationHelper.sendSMSNotificationAsync(any(), any(), any(), any())) + .thenReturn(new CompletableFuture<>()); + + GenerateChallengeResponse generateChallengeResponse = + registrationService.generateChallenge( + generateChallengeRequest, transactionId); + Assert.assertNotNull(generateChallengeResponse); + Assert.assertEquals("SUCCESS", generateChallengeResponse.getStatus()); + } + @Test public void doGenerateChallenge_withTransactionId_thenPass() throws SignUpException { String identifier = "+85577410541"; From 9712df7675b636e2a210383361fa8f6813da6bc1 Mon Sep 17 00:00:00 2001 From: mengleang-ngoun Date: Mon, 22 Jan 2024 14:49:03 +0700 Subject: [PATCH 2/3] update logic at block attempt Signed-off-by: mengleang-ngoun --- .../main/java/io/mosip/signup/services/RegistrationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java index 4da445dd..248f4896 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java @@ -151,7 +151,7 @@ public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest gene cacheUtilService.setChallengeGeneratedTransaction(transactionId, transaction); //Resend attempts exhausted, block the identifier for configured time. - if(transaction.getChallengeRetryAttempts() > resendAttempts) + if(transaction.getChallengeRetryAttempts() >= resendAttempts + 1) cacheUtilService.blockIdentifier(transaction.getIdentifier()); notificationHelper.sendSMSNotificationAsync(generateChallengeRequest.getIdentifier(), transaction.getLocale(), From b1a53ce5fb0a850f5c652ec40bb42cb142b986aa Mon Sep 17 00:00:00 2001 From: mengleang-ngoun Date: Mon, 22 Jan 2024 15:46:16 +0700 Subject: [PATCH 3/3] update logic at block attempt Signed-off-by: mengleang-ngoun --- .../main/java/io/mosip/signup/services/RegistrationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java index 248f4896..9dd98fab 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/RegistrationService.java @@ -151,7 +151,7 @@ public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest gene cacheUtilService.setChallengeGeneratedTransaction(transactionId, transaction); //Resend attempts exhausted, block the identifier for configured time. - if(transaction.getChallengeRetryAttempts() >= resendAttempts + 1) + if(transaction.getChallengeRetryAttempts() > resendAttempts + 1) cacheUtilService.blockIdentifier(transaction.getIdentifier()); notificationHelper.sendSMSNotificationAsync(generateChallengeRequest.getIdentifier(), transaction.getLocale(),