Skip to content

Commit

Permalink
Merge pull request #21 from mengleang-0090/ES-670
Browse files Browse the repository at this point in the history
ES-670
  • Loading branch information
ase-101 authored Jan 22, 2024
2 parents 871e695 + b1a53ce commit f580f13
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,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";
Expand Down

0 comments on commit f580f13

Please sign in to comment.