diff --git a/deploy/delete-mock.sh b/deploy/delete-mock.sh index bcb49ecf..6efa9455 100755 --- a/deploy/delete-mock.sh +++ b/deploy/delete-mock.sh @@ -1,29 +1,26 @@ #!/bin/bash -# Uninstalls all esignet mock service helm charts -## Usage: ./delete-mock.sh [kubeconfig] +# Uninstalls esignet mock services. +## Usage: ./delete.sh [kubeconfig] if [ $# -ge 1 ] ; then export KUBECONFIG=$1 fi -ROOT_DIR=`pwd` - -function deleting_mock() { - - declare -a module=("mock-identity-system" - "mock-relying-party-service" - "mock-relying-party-ui" - ) - - echo Installing esignet mock services - - for i in "${module[@]}" - do - cd $ROOT_DIR/"$i" - ./delete.sh +Deleting_All() { + MOCK_NS=mockid + NS=esignet + while true; do + read -p "Are you sure you want to delete esignet mock service helm charts?(Y/n) " yn + if [[ $yn = "Y" ]] || [[ $yn = "y" ]]; + then + helm -n $NS delete mock-relying-party-service || true + helm -n $NS delete mock-relying-party-ui || true + helm -n $MOCK_NS delete mock-identity-system || true + break + else + break + fi done - - echo All esignet mock services deleted sucessfully. return 0 } @@ -33,4 +30,4 @@ set -o errexit ## set -e : exit the script if any statement returns a non-true set -o nounset ## set -u : exit the script if you try to use an uninitialised variable set -o errtrace # trace ERR through 'time command' and other functions set -o pipefail # trace ERR through pipes -deleting_mock # calling function +Deleting_All # calling function diff --git a/deploy/mock-identity-system/install.sh b/deploy/mock-identity-system/install.sh index 8fa29595..3bcbb7a1 100755 --- a/deploy/mock-identity-system/install.sh +++ b/deploy/mock-identity-system/install.sh @@ -6,13 +6,13 @@ if [ $# -ge 1 ] ; then export KUBECONFIG=$1 fi -NS=mockid -CHART_VERSION=0.10.0-develop +function installing_mock-identity-system() { + NS=mockid + CHART_VERSION=0.10.0-develop -echo Create $NS namespace -kubectl create ns $NS + echo Create $NS namespace + kubectl create ns $NS || true -function installing_mock-identity-system() { echo Istio label helm repo add mosip https://mosip.github.io/mosip-helm helm repo update diff --git a/deploy/mock-relying-party-service/install.sh b/deploy/mock-relying-party-service/install.sh index 9cd73a9b..d92ae4ef 100755 --- a/deploy/mock-relying-party-service/install.sh +++ b/deploy/mock-relying-party-service/install.sh @@ -6,28 +6,13 @@ if [ $# -ge 1 ] ; then export KUBECONFIG=$1 fi -function installing_mock-relying-party-service() { - - while true; do - read -p "Do you want to install mock relying party service? (y/n): " response - if [[ "$response" == "y" || "$response" == "Y" ]]; then - break - elif [[ "$response" == "n" || "$response" == "N" ]]; then - exit - else - echo "Not a correct response. Please respond with y (yes) or n (no)." - fi - done - - helm repo add mosip https://mosip.github.io/mosip-helm - helm repo update +NS=esignet +CHART_VERSION=0.0.1-develop - NS=esignet - CHART_VERSION=0.10.0-develop - - echo Create $NS namespace - kubectl create ns $NS || true +echo Create $NS namespace +kubectl create ns $NS +function installing_mock-relying-party-service() { echo Istio label kubectl label ns $NS istio-injection=enabled --overwrite @@ -51,11 +36,12 @@ function installing_mock-relying-party-service() { ESIGNET_SERVICE_URL=${USER_PROVIDED_ESIGNET_SERVICE_URL:-$DEFAULT_ESIGNET_SERVICE_URL} echo Installing Mock Relying Party Service - helm -n $NS install mock-relying-party-service mosip/mock-relying-party-service \ - --set mock_relying_party_service.ESIGNET_SERVICE_URL="$ESIGNET_SERVICE_URL" \ - --set mock_relying_party_service.ESIGNET_AUD_URL="https://$ESIGNET_HOST/v1/esignet/oauth/v2/token" \ - --version $CHART_VERSION $ENABLE_INSECURE \ - -f values.yaml --wait +# helm -n $NS install mock-relying-party-service mosip/mock-relying-party-service \ + helm -n $NS install mock-relying-party-service ../../helm/mock-relying-party-service/ \ + --set mock_relying_party_service.ESIGNET_SERVICE_URL="$ESIGNET_SERVICE_URL" \ + --set mock_relying_party_service.ESIGNET_AUD_URL="https://$ESIGNET_HOST/v1/esignet/oauth/v2/token" \ + --version $CHART_VERSION $ENABLE_INSECURE \ + -f values.yaml --wait kubectl -n $NS get deploy mock-relying-party-service -o name | xargs -n1 -t kubectl -n $NS rollout status diff --git a/helm/mock-identity-system/values.yaml b/helm/mock-identity-system/values.yaml index 60bf67a8..dcfa02e8 100644 --- a/helm/mock-identity-system/values.yaml +++ b/helm/mock-identity-system/values.yaml @@ -53,7 +53,7 @@ service: image: registry: docker.io repository: mosipdev/mock-identity-system - tag: release-0.10.x + tag: develop ## Specify a imagePullPolicy ## Defaults to 'Always' if image tag is 'latest', else set to 'IfNotPresent' ## ref: http://kubernetes.io/docs/user-guide/images/#pre-pulling-images diff --git a/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/AuthenticationServiceImplTest.java b/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/AuthenticationServiceImplTest.java index 571968dc..0dfc90e1 100644 --- a/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/AuthenticationServiceImplTest.java +++ b/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/AuthenticationServiceImplTest.java @@ -107,6 +107,200 @@ public void kycAuth_withValidKbiChallenge_thenPass() { Assert.assertTrue(kycAuthResponseDto.isAuthStatus()); } + @Test + public void kycAuth_withInvalidIdentity_thenFail() { + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setKbi("eyJmdWxsTmFtZSI6IlNpZGRoYXJ0aCBLIE1hbnNvdXIiLCJkYXRlT2ZCaXJ0aCI6IjE5ODctMTEtMjUifQ=="); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId("transactionId"); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(null); + + try{ + authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + }catch (MockIdentityException e){ + Assert.assertEquals("invalid_individual_id",e.getMessage()); + } + } + + @Test + public void kycAuth_withoutSendOTPInvocation_thenFail() { + List> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string") + ,Map.of("id","fullName","type","text","format","") + ,Map.of("id","dateOfBirth","type","date","format","yyyy-MM-dd")); + ReflectionTestUtils.setField(authenticationService, "fieldDetailList", fieldDetailList); + ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng"); + ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper()); + + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setOtp("111111"); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId("transactionId"); + + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + LanguageValue languageValue = new LanguageValue(); + languageValue.setLanguage("eng"); + languageValue.setValue("Siddharth K Mansour"); + identityData.setFullName(List.of(languageValue)); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(this.identityData); + try{ + authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + }catch (MockIdentityException e){ + Assert.assertEquals("invalid_transaction",e.getMessage()); + } + } + + @Test + public void kycAuth_withSendOTPInvocation_thenPass() { + List> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string") + ,Map.of("id","fullName","type","text","format","") + ,Map.of("id","dateOfBirth","type","date","format","yyyy-MM-dd")); + ReflectionTestUtils.setField(authenticationService,"otpChannels",Arrays.asList("email","phone")); + ReflectionTestUtils.setField(authenticationService, "fieldDetailList", fieldDetailList); + ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng"); + ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper()); + ReflectionTestUtils.setField(authenticationService,"trnHash",new ArrayList<>()); + + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setOtp("111111"); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId("transactionId"); + + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + identityData.setIndividualId("individualId"); + identityData.setEmail("test@email.com"); + identityData.setPhone("1234567890"); + LanguageValue languageValue = new LanguageValue(); + languageValue.setLanguage("eng"); + languageValue.setValue("Siddharth K Mansour"); + identityData.setFullName(List.of(languageValue)); + SendOtpDto sendOtpDto=new SendOtpDto(); + sendOtpDto.setIndividualId("individualId"); + sendOtpDto.setOtpChannels(Arrays.asList("email","phone")); + sendOtpDto.setTransactionId("transactionId"); + + Mockito.when(identityService.getIdentity("individualId")).thenReturn(identityData); + authenticationService.sendOtp("relyingPartyId", "clientId", sendOtpDto); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(this.identityData); + Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth()); + KycAuthResponseDto kycAuthResponseDto = authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + Assert.assertTrue(kycAuthResponseDto.isAuthStatus()); + } + + @Test + public void kycAuth_withInValidTransactionId_thenFail() { + List> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string") + ,Map.of("id","fullName","type","text","format","") + ,Map.of("id","dateOfBirth","type","date","format","yyyy-MM-dd")); + ReflectionTestUtils.setField(authenticationService, "fieldDetailList", fieldDetailList); + ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng"); + ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper()); + + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setOtp("111111"); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId(""); + + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + LanguageValue languageValue = new LanguageValue(); + languageValue.setLanguage("eng"); + languageValue.setValue("Siddharth K Mansour"); + identityData.setFullName(List.of(languageValue)); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(this.identityData); + try{ + authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + }catch (MockIdentityException e){ + Assert.assertEquals("invalid_transaction_id",e.getMessage()); + } + } + + @Test + public void kycAuth_withValidPinChallenge_thenPass() { + + List> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string") + ,Map.of("id","fullName","type","text","format","") + ,Map.of("id","dateOfBirth","type","date","format","yyyy-MM-dd")); + ReflectionTestUtils.setField(authenticationService, "fieldDetailList", fieldDetailList); + ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng"); + ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper()); + + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setPin("111111"); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId("transactionId"); + + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + LanguageValue languageValue = new LanguageValue(); + languageValue.setLanguage("eng"); + languageValue.setValue("Siddharth K Mansour"); + identityData.setFullName(List.of(languageValue)); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(this.identityData); + Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth()); + + KycAuthResponseDto kycAuthResponseDto = authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + Assert.assertTrue(kycAuthResponseDto.isAuthStatus()); + } + + @Test + public void kycAuth_withValidBiometricsChallenge_thenPass() { + + List> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string") + ,Map.of("id","fullName","type","text","format","") + ,Map.of("id","dateOfBirth","type","date","format","yyyy-MM-dd")); + ReflectionTestUtils.setField(authenticationService, "fieldDetailList", fieldDetailList); + ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng"); + ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper()); + + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setBiometrics("111111"); + kycAuthDto.setTokens(new ArrayList<>()); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId("transactionId"); + + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + LanguageValue languageValue = new LanguageValue(); + languageValue.setLanguage("eng"); + languageValue.setValue("Siddharth K Mansour"); + identityData.setFullName(List.of(languageValue)); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(this.identityData); + Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth()); + + KycAuthResponseDto kycAuthResponseDto = authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + Assert.assertTrue(kycAuthResponseDto.isAuthStatus()); + } + + @Test + public void kycAuth_withValidPwdChallenge_thenPass() { + + List> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string") + ,Map.of("id","fullName","type","text","format","") + ,Map.of("id","dateOfBirth","type","date","format","yyyy-MM-dd")); + ReflectionTestUtils.setField(authenticationService, "fieldDetailList", fieldDetailList); + ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng"); + ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper()); + + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setPassword("Mosip@123"); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId("transactionId"); + + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + identityData.setPassword("Mosip@123"); + LanguageValue languageValue = new LanguageValue(); + languageValue.setLanguage("eng"); + languageValue.setValue("Siddharth K Mansour"); + identityData.setFullName(List.of(languageValue)); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(this.identityData); + + KycAuthResponseDto kycAuthResponseDto = authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + Assert.assertNotNull(kycAuthResponseDto); + } + @Test public void kycAuth_withValidKbiChallengeCustomPSUTfield_thenPass() { List> fieldDetailList = List.of(Map.of("id","individualId","type","text","format","string") @@ -195,6 +389,31 @@ public void kycAuth_withInValidKbiChallenge_thenFail() { } } + @Test + public void kycAuth_withEmptyKbiChallenge_thenFail() { + + ReflectionTestUtils.setField(authenticationService, "fieldLang", "eng"); + ReflectionTestUtils.setField(authenticationService,"objectMapper",new ObjectMapper()); + + KycAuthDto kycAuthDto = new KycAuthDto(); + kycAuthDto.setKbi("xsTmFtZSI6IlNpZG0aCBLIiwiZG9iIjoiMTk4Ny0xMS0yNSJ9"); + kycAuthDto.setIndividualId("individualId"); + kycAuthDto.setTransactionId("transactionId"); + + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + LanguageValue languageValue = new LanguageValue(); + languageValue.setLanguage("eng"); + languageValue.setValue("Siddharth K Mansour"); + identityData.setFullName(List.of(languageValue)); + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(this.identityData); + try{ + authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthDto); + }catch (MockIdentityException e){ + Assert.assertEquals("auth-failed",e.getMessage()); + } + } + @Test public void sendOtp_validIndividualIdAndOtpChannels_thenPass() throws MockIdentityException { ReflectionTestUtils.setField(authenticationService,"otpChannels",Arrays.asList("email","phone")); @@ -622,6 +841,116 @@ public void kycExchangeV2_withInValidIndividualId_thenFail() throws InvocationTa } } + @Test + public void kycExchangeV2_withDetailAndMatchedClaims_thenPass() { + Map oidcClaimsMap = new HashMap<>(); + oidcClaimsMap.put("name", "name"); + oidcClaimsMap.put("email", "email"); + oidcClaimsMap.put("phone", "phone"); + oidcClaimsMap.put("gender", "gender"); + oidcClaimsMap.put("dateOfBirth", "birthdate"); + oidcClaimsMap.put("encodedPhoto", "picture"); + ReflectionTestUtils.setField(authenticationService, "oidcClaimsMapping", oidcClaimsMap); + ReflectionTestUtils.setField(authenticationService, "objectMapper", new ObjectMapper()); + + // Create an IdentityData object + IdentityData identityData = new IdentityData(); + identityData.setDateOfBirth("1987/11/25"); + LanguageValue languageValueName = new LanguageValue(); + languageValueName.setLanguage("eng"); + languageValueName.setValue("Siddharth K Mansour"); + identityData.setName(List.of(languageValueName)); + + // Convert IdentityData to JsonNode + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode identityDataJsonNode = objectMapper.valueToTree(identityData); + + KycExchangeDto kycExchangeRequestDtoV2 = new KycExchangeDto(); + kycExchangeRequestDtoV2.setIndividualId("individualId"); + kycExchangeRequestDtoV2.setTransactionId("transactionId"); + + Map acceptedClaims = new HashMap<>(); + + ObjectNode birthdate = objectMapper.createObjectNode(); + birthdate.put("essential", true); + acceptedClaims.put("birthdate", birthdate); + + ObjectNode gender = objectMapper.createObjectNode(); + gender.put("essential", false); + acceptedClaims.put("gender", gender); + + // Create a list for verified claims + ArrayNode verifiedClaimsList = objectMapper.createArrayNode(); + + // First verified claim with matching trust framework + ObjectNode verifiedClaim1 = objectMapper.createObjectNode(); + ObjectNode verification1 = objectMapper.createObjectNode(); + verification1.put("trust_framework", "pwd"); + verifiedClaim1.put("verification", verification1); + + ObjectNode claims1 = objectMapper.createObjectNode(); + claims1.put("email", NullNode.getInstance()); + claims1.put("birthdate", NullNode.getInstance()); + verifiedClaim1.put("claims", claims1); + verifiedClaimsList.add(verifiedClaim1); + + // Set up the second verified claim that should not match + ObjectNode verifiedClaim2 = objectMapper.createObjectNode(); + ObjectNode verification2 = objectMapper.createObjectNode(); + verification2.put("trust_framework", "non_matching"); + verifiedClaim2.put("verification", verification2); + + ObjectNode claims2 = objectMapper.createObjectNode(); + claims2.put("name", NullNode.getInstance()); + claims2.put("email", NullNode.getInstance()); + claims2.put("gender", NullNode.getInstance()); + verifiedClaim2.put("claims", claims2); + verifiedClaimsList.add(verifiedClaim2); + + // Add the list of verified claims to the outer map + acceptedClaims.put("verified_claims", verifiedClaimsList); + kycExchangeRequestDtoV2.setAcceptedClaimDetail(acceptedClaims); + kycExchangeRequestDtoV2.setClaimLocales(List.of("eng")); + kycExchangeRequestDtoV2.setRequestDateTime(LocalDateTime.now()); + + KycAuth kycAuth = new KycAuth(); + kycAuth.setKycToken("kycToken"); + kycAuth.setTransactionId("transactionId"); + kycAuth.setIndividualId("individualId"); + kycAuth.setPartnerSpecificUserToken("partnerSpecificUserToken"); + kycAuth.setResponseTime(LocalDateTime.now()); + Optional kycAuthOptional = Optional.of(kycAuth); + Mockito.when(authRepository.findByKycTokenAndValidityAndTransactionIdAndIndividualId(Mockito.any(), + Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(kycAuthOptional); + Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth()); + + // Mock the identityService to return JsonNode + Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(identityDataJsonNode); + + VerifiedClaim verifiedClaim = new VerifiedClaim(); + verifiedClaim.setTrustFramework("pwd"); + verifiedClaim.setClaim("email"); + + VerifiedClaim verifiedClaim4 = new VerifiedClaim(); + verifiedClaim4.setTrustFramework("pwd"); + verifiedClaim4.setClaim("birthdate"); + + List verifiedClaimList = new ArrayList<>(); + verifiedClaimList.add(verifiedClaim); + verifiedClaimList.add(verifiedClaim4); + Optional> verifiedClaimsOptional = Optional.of(verifiedClaimList); + + Mockito.when(verifiedClaimRepository.findByIndividualIdAndClaimAndIsActive(Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean())) + .thenReturn(verifiedClaimsOptional); + + JWTSignatureResponseDto jwtSignatureResponseDto = new JWTSignatureResponseDto(); + jwtSignatureResponseDto.setJwtSignedData("jwtSignedData"); + Mockito.when(signatureService.jwtSign(Mockito.any())).thenReturn(jwtSignatureResponseDto); + + KycExchangeResponseDto kycExchangeResponseDto = authenticationService.kycExchange("relyingPartyId", "clientId", kycExchangeRequestDtoV2); + Assert.assertEquals("jwtSignedData", kycExchangeResponseDto.getKyc()); + } + @Test public void kycExchangeV2_withOutVerifiedClaims_thenPass() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { Map oidcClaimsMap=new HashMap<>(); diff --git a/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/IdentityServiceTest.java b/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/IdentityServiceTest.java index 48200ecd..61d045c9 100644 --- a/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/IdentityServiceTest.java +++ b/mock-identity-system/src/test/java/io/mosip/esignet/mock/identitysystem/service/impl/IdentityServiceTest.java @@ -87,6 +87,63 @@ public void addVerifiedClaim_withValidDetails_thenPass() { identityService.addVerifiedClaim(verifiedClaimRequestDto); } + @Test + public void addVerifiedClaim_withInvalidClaim_thenFail() { + + VerifiedClaimRequestDto verifiedClaimRequestDto = new VerifiedClaimRequestDto(); + verifiedClaimRequestDto.setActive(true); + verifiedClaimRequestDto.setIndividualId("123456"); + Map verificationDetail = new HashMap<>(); + + ObjectNode emailVerification = objectMapper.createObjectNode(); + emailVerification.put("trust_framework", "trust_framework"); + verificationDetail.put("null", emailVerification); + verifiedClaimRequestDto.setVerificationDetail(verificationDetail); + + IdentityData identityData = new IdentityData(); + identityData.setEmail("email@gmail.com"); + identityData.setEncodedPhoto("encodedPhoto"); + + MockIdentity mockIdentity = new MockIdentity(); + mockIdentity.setIndividualId("123456"); + mockIdentity.setIdentityJson("{\"individualId\":\"8267411571\",\"pin\":\"111111\",\"fullName\":[{\"language\":\"fra\",\"value\":\"Siddharth K Mansour\"},{\"language\":\"ara\",\"value\":\"تتگلدكنسَزقهِقِفل دسييسيكدكنوڤو\"},{\"language\":\"eng\",\"value\":\"Siddharth K Mansour\"}],\"email\":\"siddhartha.km@gmail.com\",\"phone\":\"+919427357934\"}"); + Mockito.when(identityRepository.findById(Mockito.anyString())).thenReturn(Optional.of(mockIdentity)); + try{ + identityService.addVerifiedClaim(verifiedClaimRequestDto); + }catch (MockIdentityException e){ + Assert.assertEquals(ErrorConstants.INVALID_CLAIM,e.getErrorCode()); + } + } + + @Test + public void addVerifiedClaim_withInvalidTrustFramework_thenFail() { + + VerifiedClaimRequestDto verifiedClaimRequestDto = new VerifiedClaimRequestDto(); + verifiedClaimRequestDto.setActive(true); + verifiedClaimRequestDto.setIndividualId("123456"); + Map verificationDetail = new HashMap<>(); + + ObjectNode emailVerification = objectMapper.createObjectNode(); + emailVerification.put("trust_framework", " "); + verificationDetail.put("email", emailVerification); + verifiedClaimRequestDto.setVerificationDetail(verificationDetail); + + IdentityData identityData = new IdentityData(); + identityData.setEmail("email@gmail.com"); + identityData.setEncodedPhoto("encodedPhoto"); + + MockIdentity mockIdentity = new MockIdentity(); + mockIdentity.setIndividualId("123456"); + mockIdentity.setIdentityJson("{\"individualId\":\"8267411571\",\"pin\":\"111111\",\"fullName\":[{\"language\":\"fra\",\"value\":\"Siddharth K Mansour\"},{\"language\":\"ara\",\"value\":\"تتگلدكنسَزقهِقِفل دسييسيكدكنوڤو\"},{\"language\":\"eng\",\"value\":\"Siddharth K Mansour\"}],\"email\":\"siddhartha.km@gmail.com\",\"phone\":\"+919427357934\"}"); + Mockito.when(verifiedClaimRepository.findById(Mockito.anyString())).thenReturn(Optional.empty()); + Mockito.when(identityRepository.findById(Mockito.anyString())).thenReturn(Optional.of(mockIdentity)); + try{ + identityService.addVerifiedClaim(verifiedClaimRequestDto); + }catch (MockIdentityException e){ + Assert.assertEquals(ErrorConstants.INVALID_REQUEST,e.getErrorCode()); + } + } + @Test public void addVerifiedClaim_withInValidIndividualId_thenFail() { VerifiedClaimRequestDto verifiedClaimRequestDto = new VerifiedClaimRequestDto(); @@ -148,6 +205,23 @@ public void getIdentity_withValidDetails_thenPass() throws MockIdentityException assertEquals(identityData.getIndividualId(), result.getIndividualId()); } + @Test + public void getIdentity_withInValidIdentityJson_thenFail() throws MockIdentityException, JsonProcessingException { + IdentityData identityData = new IdentityData(); + identityData.setEmail("email@gmail.com"); + identityData.setEncodedPhoto("encodedPhoto"); + MockIdentity mockIdentity = new MockIdentity(); + mockIdentity.setIndividualId("123456"); + mockIdentity.setIdentityJson("{ \\\"name\\\": \\\"John Doe, \\\"age\\\": 30 }"); + when(identityRepository.findById(identityData.getIndividualId())).thenReturn(Optional.of(mockIdentity)); + try { + identityService.getIdentity(identityData.getIndividualId()); + Assert.fail(); + }catch (MockIdentityException e){ + Assert.assertEquals(ErrorConstants.JSON_PROCESSING_ERROR,e.getErrorCode()); + } + } + @Test public void getIdentity_withInvalidId_thenFail() { IdentityData identityData = new IdentityData(); @@ -173,6 +247,23 @@ public void updateIdentity_withExistingIndividualId_thenPass() { Assert.assertNotNull(mockIdentity.getIdentityJson()); } + @Test + public void updateIdentity_withInvalidIdentityJson_thenFail() { + IdentityData identityData = new IdentityData(); + identityData.setIndividualId("existing-id"); + identityData.setPassword("new-password"); + MockIdentity mockIdentity = new MockIdentity(); + mockIdentity.setIndividualId("existing-id"); + mockIdentity.setIdentityJson("{ \\\"name\\\": \\\"John Doe, \\\"age\\\": 30 }"); + when(identityRepository.findById("existing-id")).thenReturn(Optional.of(mockIdentity)); + try { + identityService.updateIdentity(identityData); + Assert.fail(); + }catch (MockIdentityException e){ + Assert.assertEquals(ErrorConstants.JSON_PROCESSING_ERROR,e.getErrorCode()); + } + } + @Test public void updateIdentity_withNonExistingIndividualId_thenFail() { IdentityData identityData = new IdentityData(); @@ -184,4 +275,4 @@ public void updateIdentity_withNonExistingIndividualId_thenFail() { assertEquals(ErrorConstants.INVALID_INDIVIDUAL_ID, exception.getErrorCode()); } -} \ No newline at end of file +}