From b3690415717704b7f7364da75516fdd4887bdc26 Mon Sep 17 00:00:00 2001 From: Anusha Sunkada Date: Wed, 6 Dec 2023 18:22:08 +0530 Subject: [PATCH] ES-427 (#34) * ES-427 Signed-off-by: ase-101 * ES-427 Signed-off-by: ase-101 * Added logback.xml Signed-off-by: ase-101 --------- Signed-off-by: ase-101 Signed-off-by: Sreang Rathanak --- signup-service/pom.xml | 21 +++- .../signup/dto/GenerateChallengeRequest.java | 3 + ...iChallengeRequest.java => OtpRequest.java} | 2 +- .../java/io/mosip/signup/dto/OtpResponse.java | 9 ++ .../signup/dto/RegistrationTransaction.java | 14 ++- .../services/ChallengeManagerService.java | 59 +++++++----- .../GoogleRecaptchaValidatorService.java | 4 + .../signup/services/RegistrationService.java | 96 ++++++++++--------- .../io/mosip/signup/util/ErrorConstants.java | 4 +- .../io/mosip/signup/validator/Language.java | 2 + .../signup/validator/LanguageValidator.java | 12 ++- .../resources/application-default.properties | 7 +- signup-service/src/main/resources/logback.xml | 11 +++ .../RegistrationControllerTest.java | 16 ++-- .../signup/services/CacheUtilServiceTest.java | 4 +- .../services/ChallengeManagerServiceTest.java | 86 +++++++++++------ .../services/RegistrationServiceTest.java | 72 ++++++++++---- .../resources/application-test.properties | 1 + 18 files changed, 277 insertions(+), 146 deletions(-) rename signup-service/src/main/java/io/mosip/signup/dto/{ApiChallengeRequest.java => OtpRequest.java} (65%) create mode 100644 signup-service/src/main/java/io/mosip/signup/dto/OtpResponse.java create mode 100644 signup-service/src/main/resources/logback.xml diff --git a/signup-service/pom.xml b/signup-service/pom.xml index 96452fbf..1dfd5854 100644 --- a/signup-service/pom.xml +++ b/signup-service/pom.xml @@ -84,6 +84,12 @@ org.springframework.boot spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-logging + + org.springframework.boot @@ -147,15 +153,22 @@ kernel-core 1.2.0.1-B1 + + io.mosip.kernel + kernel-logger-logback + 1.2.0.1-B1 + + + io.mosip.kernel + kernel-core + + + org.springframework.boot spring-boot-starter-test test - - org.apache.httpcomponents - httpcore - io.mosip.esignet esignet-integration-api diff --git a/signup-service/src/main/java/io/mosip/signup/dto/GenerateChallengeRequest.java b/signup-service/src/main/java/io/mosip/signup/dto/GenerateChallengeRequest.java index bb7c25c3..33539f0e 100644 --- a/signup-service/src/main/java/io/mosip/signup/dto/GenerateChallengeRequest.java +++ b/signup-service/src/main/java/io/mosip/signup/dto/GenerateChallengeRequest.java @@ -1,6 +1,7 @@ package io.mosip.signup.dto; import io.mosip.signup.validator.Identifier; +import io.mosip.signup.validator.Language; import lombok.Data; @Data @@ -9,5 +10,7 @@ public class GenerateChallengeRequest { @Identifier private String identifier; private String captchaToken; + @Language(required = false) private String locale; + private boolean regenerate; } diff --git a/signup-service/src/main/java/io/mosip/signup/dto/ApiChallengeRequest.java b/signup-service/src/main/java/io/mosip/signup/dto/OtpRequest.java similarity index 65% rename from signup-service/src/main/java/io/mosip/signup/dto/ApiChallengeRequest.java rename to signup-service/src/main/java/io/mosip/signup/dto/OtpRequest.java index 36843e2c..f4b8b9b4 100644 --- a/signup-service/src/main/java/io/mosip/signup/dto/ApiChallengeRequest.java +++ b/signup-service/src/main/java/io/mosip/signup/dto/OtpRequest.java @@ -5,6 +5,6 @@ import java.io.Serializable; @Data -public class ApiChallengeRequest implements Serializable { +public class OtpRequest implements Serializable { private String key; } diff --git a/signup-service/src/main/java/io/mosip/signup/dto/OtpResponse.java b/signup-service/src/main/java/io/mosip/signup/dto/OtpResponse.java new file mode 100644 index 00000000..99b93c1f --- /dev/null +++ b/signup-service/src/main/java/io/mosip/signup/dto/OtpResponse.java @@ -0,0 +1,9 @@ +package io.mosip.signup.dto; + +import lombok.Data; + +@Data +public class OtpResponse { + + private String otp; +} diff --git a/signup-service/src/main/java/io/mosip/signup/dto/RegistrationTransaction.java b/signup-service/src/main/java/io/mosip/signup/dto/RegistrationTransaction.java index 6d897086..a3d3bf50 100644 --- a/signup-service/src/main/java/io/mosip/signup/dto/RegistrationTransaction.java +++ b/signup-service/src/main/java/io/mosip/signup/dto/RegistrationTransaction.java @@ -5,11 +5,13 @@ import java.io.Serializable; import java.time.LocalDateTime; +import java.time.ZoneOffset; import java.time.temporal.ChronoUnit; import java.util.UUID; @Data public class RegistrationTransaction implements Serializable { + private String challengeHash; private String identifier; private LocalDateTime startedAt; @@ -18,10 +20,12 @@ public class RegistrationTransaction implements Serializable { private String challengeTransactionId; private String applicationId; private RegistrationStatus registrationStatus; - public RegistrationTransaction(String identifier, String transactionId) { + private String locale; + + public RegistrationTransaction(String identifier) { this.identifier = identifier; - this.startedAt = LocalDateTime.now(); - this.challengeTransactionId = transactionId; + this.startedAt = LocalDateTime.now(ZoneOffset.UTC); + this.challengeTransactionId = UUID.randomUUID().toString(); this.applicationId = UUID.randomUUID().toString(); this.registrationStatus = null; this.challengeHash = null; @@ -32,11 +36,11 @@ public RegistrationTransaction(String identifier, String transactionId) { public long getLastRetryToNow() { if (this.lastRetryAt == null) return 0; - return this.lastRetryAt.until(LocalDateTime.now(), ChronoUnit.SECONDS); + return this.lastRetryAt.until(LocalDateTime.now(ZoneOffset.UTC), ChronoUnit.SECONDS); } public void increaseAttempt() { this.challengeRetryAttempts += 1; - this.lastRetryAt = LocalDateTime.now(); + this.lastRetryAt = LocalDateTime.now(ZoneOffset.UTC); } } diff --git a/signup-service/src/main/java/io/mosip/signup/services/ChallengeManagerService.java b/signup-service/src/main/java/io/mosip/signup/services/ChallengeManagerService.java index 5cac6bbc..a386d266 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/ChallengeManagerService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/ChallengeManagerService.java @@ -1,24 +1,25 @@ package io.mosip.signup.services; import io.mosip.esignet.core.util.IdentityProviderUtil; -import io.mosip.signup.dto.ApiChallengeRequest; -import io.mosip.signup.dto.RegistrationTransaction; -import io.mosip.signup.dto.RestRequestWrapper; -import io.mosip.signup.dto.RestResponseWrapper; +import io.mosip.signup.dto.*; import io.mosip.signup.exception.SignUpException; import io.mosip.signup.util.ErrorConstants; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; -import java.util.LinkedHashMap; - @Service @Slf4j public class ChallengeManagerService { + @Autowired @Qualifier("selfTokenRestTemplate") private RestTemplate selfTokenRestTemplate; @@ -26,30 +27,38 @@ public class ChallengeManagerService { @Value("${mosip.signup.generate-challenge.endpoint}") private String generateChallengeUrl; + @Value("${mosip.signup.supported.challenge-type:OTP}") + private String challengeType; + + public String generateChallenge(RegistrationTransaction transaction) throws SignUpException { - ApiChallengeRequest apiChallengeRequest = new ApiChallengeRequest(); - apiChallengeRequest.setKey(transaction.getChallengeTransactionId()); - RestRequestWrapper restRequest = new RestRequestWrapper<>(); - restRequest.setRequesttime(IdentityProviderUtil.getUTCDateTime()); - restRequest.setRequest(apiChallengeRequest); - RestResponseWrapper> restResponseWrapper = (RestResponseWrapper>) selfTokenRestTemplate - .postForObject(generateChallengeUrl, restRequest, RestResponseWrapper.class); - if (restResponseWrapper == null) { - log.error("generate-challenge Failed wrapper returned null"); - throw new SignUpException(ErrorConstants.SEND_CHALLENGE_FAILED); + switch (challengeType) { + case "OTP" : + return generateOTPChallenge(transaction.getChallengeTransactionId()); } + throw new SignUpException(ErrorConstants.UNSUPPORTED_CHALLENGE_TYPE); + } - if(restResponseWrapper.getErrors() != null) { - log.error("generate-challenge Failed wrapper returned errors {}!", restResponseWrapper.getErrors()); - throw new SignUpException(ErrorConstants.SEND_CHALLENGE_FAILED); - } + private String generateOTPChallenge(String challengeTransactionId) { + OtpRequest otpRequest = new OtpRequest(); + otpRequest.setKey(challengeTransactionId); + RestRequestWrapper restRequestWrapper = new RestRequestWrapper<>(); + restRequestWrapper.setRequesttime(IdentityProviderUtil.getUTCDateTime()); + restRequestWrapper.setRequest(otpRequest); + + RestResponseWrapper restResponseWrapper = selfTokenRestTemplate + .exchange(generateChallengeUrl, HttpMethod.POST, + new HttpEntity<>(restRequestWrapper), + new ParameterizedTypeReference>() {}).getBody(); - String challenge = restResponseWrapper.getResponse().get("otp"); - if (challenge == null || challenge.isEmpty()) { - log.error("generate-challenge Failed challenge returned null"); - throw new SignUpException(ErrorConstants.SEND_CHALLENGE_FAILED); + if (restResponseWrapper != null && restResponseWrapper.getResponse() != null && + !StringUtils.isEmpty(restResponseWrapper.getResponse().getOtp()) && + !restResponseWrapper.getResponse().getOtp().equals("null")) { + return restResponseWrapper.getResponse().getOtp(); } - return challenge; + log.error("Generate OTP failed with response {}", restResponseWrapper); + throw new SignUpException(restResponseWrapper != null && !CollectionUtils.isEmpty(restResponseWrapper.getErrors()) ? + restResponseWrapper.getErrors().get(0).getErrorCode() : ErrorConstants.GENERATE_CHALLENGE_FAILED); } } diff --git a/signup-service/src/main/java/io/mosip/signup/services/GoogleRecaptchaValidatorService.java b/signup-service/src/main/java/io/mosip/signup/services/GoogleRecaptchaValidatorService.java index 3b55bdce..a981dac1 100644 --- a/signup-service/src/main/java/io/mosip/signup/services/GoogleRecaptchaValidatorService.java +++ b/signup-service/src/main/java/io/mosip/signup/services/GoogleRecaptchaValidatorService.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; @ConditionalOnProperty(value = "mosip.signup.integration.captcha-validator", havingValue = "GoogleRecaptchaValidatorService") @@ -39,6 +40,9 @@ public boolean validateCaptcha(String captchaToken) { if (!requiredCaptcha) return true; + if(StringUtils.isEmpty(captchaToken)) + return false; + MultiValueMap param = new LinkedMultiValueMap<>(); param.add("secret", verifierSecret); param.add("response", captchaToken.trim()); 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 713b8324..49f00bbc 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 @@ -75,6 +75,44 @@ public class RegistrationService { @Value("${mosip.signup.challenge.resend-delay}") private long resendDelay; + /** + * Generate and regenerate challenge based on the "regenerate" flag in the request. + * if regenerate is false - always creates a new transaction and set-cookie header is sent in the response. + * if regenerate is true - expects a valid transaction Id in the cookie + * @param generateChallengeRequest + * @param transactionId + * @return + * @throws SignUpException + */ + public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest generateChallengeRequest, String transactionId) throws SignUpException { + if (!googleRecaptchaValidatorService.validateCaptcha(generateChallengeRequest.getCaptchaToken())) { + log.error("generate-challenge failed: invalid captcha"); + throw new CaptchaException(ErrorConstants.INVALID_CAPTCHA); + } + + String identifier = generateChallengeRequest.getIdentifier(); + RegistrationTransaction transaction = null; + + if(generateChallengeRequest.isRegenerate() == false) { + transactionId = IdentityProviderUtil.createTransactionId(null); + transaction = new RegistrationTransaction(identifier); + } + else { + transaction = cacheUtilService.getChallengeGeneratedTransaction(transactionId); + validateTransaction(transaction, identifier); + } + + // generate Challenge + String challenge = challengeManagerService.generateChallenge(transaction); + String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challenge); + addCookieResponse(transactionId); + transaction.setChallengeHash(challengeHash); + transaction.increaseAttempt(); + transaction.setLocale(generateChallengeRequest.getLocale()); + cacheUtilService.setChallengeGeneratedTransaction(transactionId, transaction); + return new GenerateChallengeResponse(ActionStatus.SUCCESS); + } + public VerifyChallengeResponse verifyChallenge(VerifyChallengeRequest verifyChallengeRequest, String transactionId) throws SignUpException { @@ -128,6 +166,21 @@ public RegisterResponse register(RegisterRequest registerRequest, String transac return registration; } + public RegistrationStatusResponse getRegistrationStatus(String transactionId) + throws SignUpException { + if (transactionId == null || transactionId.isEmpty()) + throw new InvalidTransactionException(); + + RegistrationTransaction registrationTransaction = cacheUtilService.getRegisteredTransaction( + transactionId); + if (registrationTransaction == null) + throw new InvalidTransactionException(); + + RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); + registrationStatusResponse.setStatus(registrationTransaction.getRegistrationStatus()); + return registrationStatusResponse; + } + private void saveIdentityData(RegisterRequest registerRequest, String transactionId, String applicationId) throws SignUpException{ UserInfoMap userInfoMap = registerRequest.getUserInfo(); @@ -212,49 +265,6 @@ private String getUniqueIdentifier(String transactionId) throws SignUpException restResponseWrapper.getErrors().get(0).getErrorCode() : ErrorConstants.GET_UIN_FAILED); } - public GenerateChallengeResponse generateChallenge(GenerateChallengeRequest generateChallengeRequest, String transactionId) throws SignUpException { - if (!googleRecaptchaValidatorService.validateCaptcha(generateChallengeRequest.getCaptchaToken())) { - log.error("generate-challenge failed: invalid captcha"); - throw new CaptchaException(ErrorConstants.INVALID_CAPTCHA); - } - - String identifier = generateChallengeRequest.getIdentifier(); - RegistrationTransaction transaction = null; - if (!transactionId.isEmpty()) { - transaction = cacheUtilService.getChallengeGeneratedTransaction(transactionId); - validateTransaction(transaction, identifier); - } - - if(transaction == null) { - transactionId = IdentityProviderUtil.createTransactionId(null); - transaction = new RegistrationTransaction(identifier, transactionId); - } - - // generate Challenge - String challenge = challengeManagerService.generateChallenge(transaction); - String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challenge); - addCookieResponse(transactionId); - transaction.setChallengeHash(challengeHash); - transaction.increaseAttempt(); - cacheUtilService.setChallengeGeneratedTransaction(transactionId, transaction); - return new GenerateChallengeResponse(ActionStatus.SUCCESS); - } - - public RegistrationStatusResponse getRegistrationStatus(String transactionId) - throws SignUpException { - if (transactionId == null || transactionId.isEmpty()) - throw new InvalidTransactionException(); - - RegistrationTransaction registrationTransaction = cacheUtilService.getRegisteredTransaction( - transactionId); - if (registrationTransaction == null) - throw new InvalidTransactionException(); - - RegistrationStatusResponse registrationStatusResponse = new RegistrationStatusResponse(); - registrationStatusResponse.setStatus(registrationTransaction.getRegistrationStatus()); - return registrationStatusResponse; - } - private void validateTransaction(RegistrationTransaction transaction, String identifier) { if(transaction == null) { log.error("generate-challenge failed: validate transaction null"); diff --git a/signup-service/src/main/java/io/mosip/signup/util/ErrorConstants.java b/signup-service/src/main/java/io/mosip/signup/util/ErrorConstants.java index 788da063..6e764b54 100644 --- a/signup-service/src/main/java/io/mosip/signup/util/ErrorConstants.java +++ b/signup-service/src/main/java/io/mosip/signup/util/ErrorConstants.java @@ -11,9 +11,9 @@ public class ErrorConstants { public static final String UNSUPPORTED_USERNAME = "unsupported_username"; public static final String CONSENT_REQUIRED = "consent_required"; public static final String INVALID_TRANSACTION="invalid_transaction"; - public static final String INVALID_CHALLENGE_CHANNEL ="invalid_challenge_channel"; + public static final String UNSUPPORTED_CHALLENGE_TYPE ="unsupported_challenge_type"; public static final String INVALID_CAPTCHA="invalid_captcha"; - public static final String SEND_CHALLENGE_FAILED ="send_challenge_failed"; + public static final String GENERATE_CHALLENGE_FAILED ="generate_challenge_failed"; public static final String ACTIVE_CHALLENGE_FOUND="active_challenge_found"; public static final String UNKNOWN_ERROR="unknown_error"; public static final String TOO_MANY_ATTEMPTS="too_many_attempts"; diff --git a/signup-service/src/main/java/io/mosip/signup/validator/Language.java b/signup-service/src/main/java/io/mosip/signup/validator/Language.java index 1df8b9ff..d9e35c27 100644 --- a/signup-service/src/main/java/io/mosip/signup/validator/Language.java +++ b/signup-service/src/main/java/io/mosip/signup/validator/Language.java @@ -20,4 +20,6 @@ String message() default ErrorConstants.UNSUPPORTED_LANGUAGE; Class[] groups() default { }; Class[] payload() default { }; + + boolean required() default true; } diff --git a/signup-service/src/main/java/io/mosip/signup/validator/LanguageValidator.java b/signup-service/src/main/java/io/mosip/signup/validator/LanguageValidator.java index f76e976e..721c0f24 100644 --- a/signup-service/src/main/java/io/mosip/signup/validator/LanguageValidator.java +++ b/signup-service/src/main/java/io/mosip/signup/validator/LanguageValidator.java @@ -12,10 +12,18 @@ public class LanguageValidator implements ConstraintValidator @Value("#{${mosip.signup.supported-languages}}") private List supportedLanguages; + private boolean required; + + @Override + public void initialize(Language constraintAnnotation) { + this.required = constraintAnnotation.required(); + } + @Override public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) { - if(value == null || value.isBlank()) - return false; + if(value == null) + return this.required ? false : true; + return supportedLanguages.contains(value); } } diff --git a/signup-service/src/main/resources/application-default.properties b/signup-service/src/main/resources/application-default.properties index a9b616c2..3b4a91b5 100644 --- a/signup-service/src/main/resources/application-default.properties +++ b/signup-service/src/main/resources/application-default.properties @@ -1,4 +1,5 @@ ## --------------------------------------------------------------------------------------------------------------------- +mosip.signup.supported.challenge-type=OTP mosip.signup.supported.challenge-format-types={'alpha-numeric'} mosip.signup.id-schema.version=0.2 mosip.signup.cookie.max-age=60 @@ -11,7 +12,7 @@ mosip.signup.password.pattern=^.{8,}$ mosip.signup.password.length.max=30 mosip.signup.password.length.min=8 mosip.signup.status.request.delay=20 -mosip.signup.status.request.limit=5 +mosip.signup.status.request.limit=10 mosip.signup.fullname.pattern=^[\p{Khmer}\s]{1,30}$ mosip.signup.challenge.timeout=60 @@ -27,7 +28,9 @@ management.health.redis.enabled=false mosip.esignet.cache.names=challenge-generated,challenge-verified,status-check mosip.esignet.cache.size={'challenge-generated': 200,'challenge-verified': 200,'status-check': 200 } -mosip.esignet.cache.expire-in-seconds={'challenge-generated': 86400,'challenge-verified': 86400,'status-check': 86400 } +mosip.esignet.cache.expire-in-seconds={'challenge-generated': 86400,\ + 'challenge-verified': 200,\ + 'status-check': 86400 } ## ------------------------------------- Auth adapter ------------------------------------------------------------------ mosip.kernel.authmanager.url=https://api-internal.camdgc-dev.mosip.net diff --git a/signup-service/src/main/resources/logback.xml b/signup-service/src/main/resources/logback.xml new file mode 100644 index 00000000..b9dfc23e --- /dev/null +++ b/signup-service/src/main/resources/logback.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/signup-service/src/test/java/io/mosip/signup/controllers/RegistrationControllerTest.java b/signup-service/src/test/java/io/mosip/signup/controllers/RegistrationControllerTest.java index b99fc76c..8a089d92 100644 --- a/signup-service/src/test/java/io/mosip/signup/controllers/RegistrationControllerTest.java +++ b/signup-service/src/test/java/io/mosip/signup/controllers/RegistrationControllerTest.java @@ -234,7 +234,7 @@ public void doVerifyChallenge_withoutIdentifier_returnErrorResponse() throws Exc verifyRequestWrapper.setRequest(verifyChallengeRequest); String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction(""); registrationTransaction.setChallengeHash("mock"); registrationTransaction.setIdentifier("mock"); @@ -253,7 +253,7 @@ public void doVerifyChallenge_withoutIdentifier_returnErrorResponse() throws Exc @Test public void doVerifyChallenge_withInvalidTransaction_returnErrorResponse() throws Exception { String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction(""); registrationTransaction.setChallengeHash("mock"); registrationTransaction.setIdentifier("mock"); @@ -272,7 +272,7 @@ public void doVerifyChallenge_withInvalidTransaction_returnErrorResponse() throw @Test public void doVerifyChallenge_withVerifyChallengeRaiseChallengeFailedException_returnErrorResponse() throws Exception { String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123128", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123128"); registrationTransaction.setChallengeHash("mock"); registrationTransaction.setIdentifier("mock"); @@ -291,7 +291,7 @@ public void doVerifyChallenge_withVerifyChallengeRaiseChallengeFailedException_r @Test public void doVerifyChallenge_withVerifyChallengeRaiseInvalidIdentifierException_returnErrorResponse() throws Exception { String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123128", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123128"); registrationTransaction.setChallengeHash("mock"); registrationTransaction.setIdentifier("mock"); @@ -316,7 +316,7 @@ public void doVerifyChallenge_withMultipleInvalidRequest_returnErrorResponse() t verifyRequestWrapper.setRequestTime(null); String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123128", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123128"); registrationTransaction.setChallengeHash("mock"); registrationTransaction.setIdentifier("mock"); @@ -390,7 +390,7 @@ public void doGenerateChallenge_withInvalidCaptchaToken_returnErrorResponse() th @Test public void doGetRegistrationStatus_returnCompletedResponse() throws Exception { String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", "TRAN_ID"); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541"); registrationTransaction.setRegistrationStatus(RegistrationStatus.COMPLETED); RegistrationStatusResponse response = new RegistrationStatusResponse(); response.setStatus(registrationTransaction.getRegistrationStatus()); @@ -406,7 +406,7 @@ public void doGetRegistrationStatus_returnCompletedResponse() throws Exception { @Test public void doGetRegistrationStatus_returnPendingResponse() throws Exception { String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", "TRAN_ID"); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541"); registrationTransaction.setRegistrationStatus(RegistrationStatus.PENDING); RegistrationStatusResponse response = new RegistrationStatusResponse(); response.setStatus(registrationTransaction.getRegistrationStatus()); @@ -422,7 +422,7 @@ public void doGetRegistrationStatus_returnPendingResponse() throws Exception { @Test public void doGetRegistrationStatus_returnFailedResponse() throws Exception { String mockTransactionID = "123456789"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", "TRAN_ID"); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541"); registrationTransaction.setRegistrationStatus(RegistrationStatus.FAILED); RegistrationStatusResponse response = new RegistrationStatusResponse(); response.setStatus(registrationTransaction.getRegistrationStatus()); diff --git a/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java index a2874bc3..cc991fd8 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/CacheUtilServiceTest.java @@ -24,7 +24,7 @@ public class CacheUtilServiceTest { @Test public void test_RegistrationTransaction_cache() { - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123"); registrationTransaction.setChallengeHash("123456-HASH"); Mockito.when(cache.get("mock", RegistrationTransaction.class)).thenReturn(registrationTransaction); @@ -44,7 +44,7 @@ public void test_RegistrationTransaction_cache() { @Test public void setChallengeTransaction_thenPass() { - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123"); Assert.assertEquals(cacheUtilService.setChallengeGeneratedTransaction("mock-transaction", registrationTransaction), registrationTransaction); Assert.assertNotNull(cacheUtilService.setChallengeGeneratedTransaction("mock-transaction", registrationTransaction)); } diff --git a/signup-service/src/test/java/io/mosip/signup/services/ChallengeManagerServiceTest.java b/signup-service/src/test/java/io/mosip/signup/services/ChallengeManagerServiceTest.java index 91e177b1..aae3093e 100644 --- a/signup-service/src/test/java/io/mosip/signup/services/ChallengeManagerServiceTest.java +++ b/signup-service/src/test/java/io/mosip/signup/services/ChallengeManagerServiceTest.java @@ -1,7 +1,8 @@ package io.mosip.signup.services; -import com.fasterxml.jackson.databind.ObjectMapper; +import io.mosip.signup.dto.OtpResponse; import io.mosip.signup.dto.RegistrationTransaction; +import io.mosip.signup.dto.RestError; import io.mosip.signup.dto.RestResponseWrapper; import io.mosip.signup.exception.SignUpException; import org.junit.Assert; @@ -11,6 +12,11 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.web.client.RestTemplate; @@ -23,80 +29,98 @@ @RunWith(MockitoJUnitRunner.class) public class ChallengeManagerServiceTest { + @InjectMocks ChallengeManagerService challengeManagerService; @Mock RestTemplate selfTokenRestTemplate; - private RestResponseWrapper challengeResponse; - - ObjectMapper objectMapper = new ObjectMapper(); private String generateChallengeUrl = "https://api.net/v1/otpmanager/otp/generate"; @Before - public void setUp() throws IOException { - ReflectionTestUtils.setField( - challengeManagerService, "generateChallengeUrl", generateChallengeUrl); - challengeResponse = objectMapper.readValue("{\"id\":\"string\",\"version\":\"string\",\"responsetime\":\"2023-11-14T10:59:16.574Z\",\"metadata\":null,\"response\":{\"status\":\"GENERATION_SUCCESSFUL\",\"otp\":\"1111\"},\"errors\":null}".getBytes(), RestResponseWrapper.class); + public void setUp() { + ReflectionTestUtils.setField(challengeManagerService, "generateChallengeUrl", generateChallengeUrl); + ReflectionTestUtils.setField(challengeManagerService, "challengeType", "OTP"); } @Test - public void doGenerateChallenge_allValid_thenPass() throws SignUpException, IOException { - RegistrationTransaction transaction = new RegistrationTransaction("+85577410541", "TRAN-ID"); - when(selfTokenRestTemplate.postForObject(eq(generateChallengeUrl), any(), eq(RestResponseWrapper.class))) - .thenReturn(challengeResponse); + public void doGenerateChallenge_allValid_thenPass() throws SignUpException { + RegistrationTransaction transaction = new RegistrationTransaction("+85577410541"); + RestResponseWrapper challengeResponse = new RestResponseWrapper<>(); + OtpResponse otpResponse = new OtpResponse(); + otpResponse.setOtp("1111"); + challengeResponse.setResponse(otpResponse); + + when(selfTokenRestTemplate.exchange( + eq(generateChallengeUrl), + eq(HttpMethod.POST), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))).thenReturn(new ResponseEntity<>(challengeResponse, HttpStatus.OK)); String challenge = challengeManagerService.generateChallenge(transaction); Assert.assertEquals(challenge, "1111"); } @Test - public void doGenerateChallenge_withApiResponseEmptyChallenge_thenFail() throws SignUpException, IOException { - RegistrationTransaction transaction = new RegistrationTransaction("+85577410541", "TRAN-ID"); - challengeResponse = objectMapper.readValue("{\"id\":\"string\",\"version\":\"string\",\"responsetime\":\"2023-11-14T10:59:16.574Z\",\"metadata\":null,\"response\":{\"status\":\"GENERATION_SUCCESSFUL\",\"otp\":\"\"},\"errors\":null}".getBytes(), RestResponseWrapper.class); - when(selfTokenRestTemplate.postForObject(eq(generateChallengeUrl), any(), eq(RestResponseWrapper.class))) - .thenReturn(challengeResponse); + public void doGenerateChallenge_withApiResponseEmptyChallenge_thenFail() throws SignUpException { + RegistrationTransaction transaction = new RegistrationTransaction("+85577410541"); + RestResponseWrapper challengeResponse = new RestResponseWrapper<>(); + OtpResponse otpResponse = new OtpResponse(); + otpResponse.setOtp(""); + challengeResponse.setResponse(otpResponse); + + when(selfTokenRestTemplate.exchange( + eq(generateChallengeUrl), + eq(HttpMethod.POST), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))).thenReturn(new ResponseEntity<>(challengeResponse, HttpStatus.OK)); try { challengeManagerService.generateChallenge(transaction); Assert.fail(); } catch (SignUpException ex) { - Assert.assertEquals("send_challenge_failed", ex.getErrorCode()); + Assert.assertEquals("generate_challenge_failed", ex.getErrorCode()); } } @Test - public void doGenerateChallenge_withApiNullResponse_thenFail() throws SignUpException, IOException { - RegistrationTransaction transaction = new RegistrationTransaction("+85577410541", "TRAN-ID"); - when(selfTokenRestTemplate.postForObject(eq(generateChallengeUrl), any(), eq(RestResponseWrapper.class))) - .thenReturn(null); + public void doGenerateChallenge_withApiNullResponse_thenFail() throws SignUpException { + RegistrationTransaction transaction = new RegistrationTransaction("+85577410541"); + when(selfTokenRestTemplate.exchange( + eq(generateChallengeUrl), + eq(HttpMethod.POST), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))).thenReturn(new ResponseEntity(null, HttpStatus.OK)); try { challengeManagerService.generateChallenge(transaction); Assert.fail(); } catch (SignUpException ex) { - Assert.assertEquals("send_challenge_failed", ex.getErrorCode()); + Assert.assertEquals("generate_challenge_failed", ex.getErrorCode()); } } @Test - public void doGenerateChallenge_withApiResponseErrors_thenFail() throws SignUpException, IOException { - RegistrationTransaction transaction = new RegistrationTransaction("+85577410541", "TRAN-ID"); - ArrayList errors= new ArrayList(); - errors.add(new Error("401")); - challengeResponse.setResponse(null); + public void doGenerateChallenge_withApiResponseErrors_thenFail() throws SignUpException { + RegistrationTransaction transaction = new RegistrationTransaction("+85577410541"); + ArrayList errors= new ArrayList(); + errors.add(new RestError("401", "401")); + RestResponseWrapper challengeResponse = new RestResponseWrapper<>(); challengeResponse.setErrors(errors); - when(selfTokenRestTemplate.postForObject(eq(generateChallengeUrl), any(), eq(RestResponseWrapper.class))) - .thenReturn(challengeResponse); + when(selfTokenRestTemplate.exchange( + eq(generateChallengeUrl), + eq(HttpMethod.POST), + any(HttpEntity.class), + any(ParameterizedTypeReference.class))).thenReturn(new ResponseEntity<>(challengeResponse, HttpStatus.OK)); try { challengeManagerService.generateChallenge(transaction); Assert.fail(); } catch (SignUpException ex) { - Assert.assertEquals("send_challenge_failed", ex.getErrorCode()); + Assert.assertEquals("401", ex.getErrorCode()); } } } 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 01f8719e..300f7da9 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 @@ -26,6 +26,7 @@ import org.springframework.web.client.RestTemplate; import java.io.IOException; +import java.time.ZoneOffset; import java.util.ArrayList; import java.util.List; @@ -87,7 +88,7 @@ public void doVerifyChallenge_thenPass() throws Exception{ verifyChallengeRequest.setChallengeInfo(challengeInfo); String mockTransactionId = "mock-transactionId"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123"); String challengeHash = IdentityProviderUtil.generateB64EncodedHash(IdentityProviderUtil.ALGO_SHA3_256, challengeInfo.getChallenge()); registrationTransaction.setChallengeHash(challengeHash); registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier()); @@ -131,7 +132,7 @@ public void doVerifyChallenge_withChallengeNotMatch_thenFail() throws Exception{ verifyChallengeRequest.setChallengeInfo(challengeInfo); String mockTransactionId = "mock-transactionId"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123"); registrationTransaction.setChallengeHash("failed"); registrationTransaction.setIdentifier(verifyChallengeRequest.getIdentifier()); when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction); @@ -155,7 +156,7 @@ public void doVerifyChallenge_withIdentifierNotMatch_throwsException() throws Ex verifyChallengeRequest.setChallengeInfo(challengeInfo); String mockTransactionId = "mock-transactionId"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123", ""); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85512123123"); registrationTransaction.setChallengeHash(challengeInfo.getChallenge()); registrationTransaction.setIdentifier("failed"); when(cacheUtilService.getChallengeGeneratedTransaction(mockTransactionId)).thenReturn(registrationTransaction); @@ -184,7 +185,7 @@ public void register_thenPass() throws Exception{ String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(userInfo.getPhone(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(userInfo.getPhone()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -242,7 +243,7 @@ public void register_thenUinEndpointResponseNullBody_throwException() throws Exc String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -278,7 +279,7 @@ public void register_thenUinEndpointResponseErrors_throwException() throws Excep String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -319,7 +320,7 @@ public void register_thenGenerateHashEndpointResponseNullBody_throwException() t String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -371,7 +372,7 @@ public void register_thenGenerateHashEndpointResponseErrors_throwException() thr String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -427,7 +428,7 @@ public void register_thenAddIdentityEndpointResponseNullBody_throwException() th String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -486,7 +487,7 @@ public void register_thenAddIdentityEndpointResponseErrors_throwException() thro String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -572,7 +573,7 @@ public void register_withInvalidUsername_throwException() throws Exception{ String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -602,7 +603,7 @@ public void register_withInvalidConsent_throwException() throws Exception{ String mockTransactionID = "123456789"; - RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername(), mockTransactionID); + RegistrationTransaction mockRegistrationTransaction = new RegistrationTransaction(registerRequest.getUsername()); mockRegistrationTransaction.setChallengeHash("123456"); mockRegistrationTransaction.setIdentifier(userInfo.getPhone()); @@ -624,6 +625,7 @@ public void doGenerateChallenge_withoutTransactionId_thenPass() throws SignUpExc GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); generateChallengeRequest.setIdentifier(identifier); generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(false); when(challengeManagerService.generateChallenge(any())).thenReturn("1111"); when(googleRecaptchaValidatorService.validateCaptcha( generateChallengeRequest.getCaptchaToken())).thenReturn(true); @@ -641,9 +643,10 @@ public void doGenerateChallenge_withTransactionId_thenPass() throws SignUpExcept GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); generateChallengeRequest.setIdentifier(identifier); generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(true); String transactionId = "TRAN-1234"; - RegistrationTransaction transaction = new RegistrationTransaction(identifier, transactionId); - transaction.setLastRetryAt(LocalDateTime.now().minusSeconds(40)); + RegistrationTransaction transaction = new RegistrationTransaction(identifier); + transaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC).minusSeconds(40)); when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(transaction); when(challengeManagerService.generateChallenge(transaction)).thenReturn("1111"); @@ -657,6 +660,29 @@ public void doGenerateChallenge_withTransactionId_thenPass() throws SignUpExcept Assert.assertEquals("SUCCESS", generateChallengeResponse.getStatus()); } + @Test + public void doGenerateChallenge_regenerateWithInvalidTransactionId_thenFail() throws SignUpException { + String identifier = "+85577410541"; + GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); + generateChallengeRequest.setIdentifier(identifier); + generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(true); + String transactionId = "TRAN-12341"; + RegistrationTransaction transaction = new RegistrationTransaction(identifier); + transaction.setLastRetryAt(LocalDateTime.now(ZoneOffset.UTC).minusSeconds(40)); + + when(challengeManagerService.generateChallenge(transaction)).thenReturn("1111"); + when(googleRecaptchaValidatorService.validateCaptcha( + generateChallengeRequest.getCaptchaToken())).thenReturn(true); + + try { + registrationService.generateChallenge(generateChallengeRequest, transactionId); + Assert.fail(); + } catch (SignUpException ex) { + Assert.assertEquals("invalid_transaction", ex.getErrorCode()); + } + } + @Test public void doGenerateChallenge_withInvalidCaptcha_thenFail() throws EsignetException { String identifier = "12345678"; @@ -679,8 +705,9 @@ public void doGenerateChallenge_withInvalidTransactionId_thenFail() throws SignU GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); generateChallengeRequest.setIdentifier(identifier); generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(true); String transactionId = "TRAN-1234"; - RegistrationTransaction transaction = new RegistrationTransaction(identifier, transactionId); + RegistrationTransaction transaction = new RegistrationTransaction(identifier); when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(null); when(googleRecaptchaValidatorService.validateCaptcha( @@ -701,8 +728,9 @@ public void doGenerateChallenge_withIdentifierNotMatchTransactionId_thenFail() t GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); generateChallengeRequest.setIdentifier(identifier); generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(true); String transactionId = "TRAN-1234"; - RegistrationTransaction transaction = new RegistrationTransaction(other_identifier, transactionId); + RegistrationTransaction transaction = new RegistrationTransaction(other_identifier); when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(transaction); when(googleRecaptchaValidatorService.validateCaptcha( @@ -722,8 +750,9 @@ public void doGenerateChallenge_withTooManyAttemptTransactionId_thenFail() throw GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); generateChallengeRequest.setIdentifier(identifier); generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(true); String transactionId = "TRAN-1234"; - RegistrationTransaction transaction = new RegistrationTransaction(identifier, transactionId); + RegistrationTransaction transaction = new RegistrationTransaction(identifier); transaction.setChallengeRetryAttempts(4); when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(transaction); @@ -744,8 +773,9 @@ public void doGenerateChallenge_withToEarlyAttemptTransactionId_thenFail() throw GenerateChallengeRequest generateChallengeRequest = new GenerateChallengeRequest(); generateChallengeRequest.setIdentifier(identifier); generateChallengeRequest.setCaptchaToken("mock-captcha"); + generateChallengeRequest.setRegenerate(true); String transactionId = "TRAN-1234"; - RegistrationTransaction transaction = new RegistrationTransaction(identifier, transactionId); + RegistrationTransaction transaction = new RegistrationTransaction(identifier); transaction.increaseAttempt(); when(cacheUtilService.getChallengeGeneratedTransaction(transactionId)).thenReturn(transaction); @@ -763,7 +793,7 @@ public void doGenerateChallenge_withToEarlyAttemptTransactionId_thenFail() throw @Test public void doGetRegistrationStatus_withCompletedTransaction_thenPass() { String transactionId = "TRAN-1234"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", "TRAN_ID"); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541"); registrationTransaction.setRegistrationStatus(RegistrationStatus.COMPLETED); when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction); RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId); @@ -775,7 +805,7 @@ public void doGetRegistrationStatus_withCompletedTransaction_thenPass() { @Test public void doGetRegistrationStatus_withPendingTransaction_thenPass() { String transactionId = "TRAN-1234"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", "TRAN_ID"); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541"); registrationTransaction.setRegistrationStatus(RegistrationStatus.PENDING); when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction); RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId); @@ -787,7 +817,7 @@ public void doGetRegistrationStatus_withPendingTransaction_thenPass() { @Test public void doGetRegistrationStatus_withFailedTransaction_thenPass() { String transactionId = "TRAN-1234"; - RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541", "TRAN_ID"); + RegistrationTransaction registrationTransaction = new RegistrationTransaction("+85577410541"); registrationTransaction.setRegistrationStatus(RegistrationStatus.FAILED); when(cacheUtilService.getRegisteredTransaction(transactionId)).thenReturn(registrationTransaction); RegistrationStatusResponse registrationStatusResponse = registrationService.getRegistrationStatus(transactionId); diff --git a/signup-service/src/test/resources/application-test.properties b/signup-service/src/test/resources/application-test.properties index 4d445168..f22b7490 100644 --- a/signup-service/src/test/resources/application-test.properties +++ b/signup-service/src/test/resources/application-test.properties @@ -76,6 +76,7 @@ mosip.signup.challenge.resend-delay=30 mosip.signup.identifier.regex=\\+855\\d{8,9} mosip.signup.supported-languages={'khm', 'eng'} mosip.signup.password.max-length=20 +mosip.signup.supported.challenge-type=OTP ## --------------------------------- mosip.signup.ui.config.key-values={\ \'identifier.pattern': '\\d{8,9}', \