diff --git a/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java b/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java index 04ae0df..4ec161c 100644 --- a/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java +++ b/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockAuthenticationServiceTest.java @@ -50,156 +50,6 @@ public class MockAuthenticationServiceTest { @Mock ObjectMapper objectMapper; - /*@Test - public void doVerifiedKycExchange_withValidDetails_thenPass() throws KycExchangeException { - ReflectionTestUtils.setField(mockAuthenticationService, "kycExchangeUrl", "http://localhost:8080/kyc/exchange"); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - ReflectionTestUtils.setField(mockAuthenticationService, "objectMapper", objectMapper); - - - VerifiedKycExchangeDto verifiedKycExchangeDto = new VerifiedKycExchangeDto(); - verifiedKycExchangeDto.setKycToken("kycToken"); - verifiedKycExchangeDto.setAcceptedClaims(Arrays.asList("name", "gender")); - verifiedKycExchangeDto.setClaimsLocales(new String[]{"eng", "hin"}); - - - - Map acceptedVerifiedClaims=new HashMap<>(); - - VerificationFilter verificationFilterForName= new VerificationFilter(); - FilterCriteria trustFrameWorkCriteria = new FilterCriteria(); - trustFrameWorkCriteria.setValues(List.of("PWD", "Income-tax")); - FilterDateTime filterDateTime = new FilterDateTime(); - filterDateTime.setMax_age(1000); - verificationFilterForName.setTime(filterDateTime); - verificationFilterForName.setTrust_framework(trustFrameWorkCriteria); - - VerificationFilter verificationFilterForEmail= new VerificationFilter(); - FilterCriteria trustFrameworkForEmail = new FilterCriteria(); - trustFrameworkForEmail.setValues(List.of("PWD")); - filterDateTime.setMax_age(500); - verificationFilterForEmail.setTime(filterDateTime); - verificationFilterForEmail.setTrust_framework(trustFrameworkForEmail); - - - acceptedVerifiedClaims.put("name", verificationFilterForName); - acceptedVerifiedClaims.put("email", verificationFilterForEmail); - - verifiedKycExchangeDto.setAcceptedVerifiedClaims(acceptedVerifiedClaims); - KycExchangeResponseDto kycExchangeResponseDto = new KycExchangeResponseDto(); - kycExchangeResponseDto.setKyc("responseKyc"); - ResponseWrapper responseWrapper = new ResponseWrapper(); - responseWrapper.setResponse(kycExchangeResponseDto); - ResponseEntity> responseEntity = new ResponseEntity(responseWrapper, HttpStatus.OK); - Mockito.when(restTemplate.exchange( - Mockito.any(RequestEntity.class), - Mockito.eq(new ParameterizedTypeReference>() { - }) - )).thenReturn(responseEntity); - - KycExchangeResult kycExchangeResult = mockAuthenticationService.doVerifiedKycExchange("RP", "CL", verifiedKycExchangeDto); - Assert.assertEquals(kycExchangeResponseDto.getKyc(), kycExchangeResult.getEncryptedKyc()); - - } - - @Test - public void doVerifiedKycExchange_withEmptyResponse_thenFail() { - ReflectionTestUtils.setField(mockAuthenticationService, "kycExchangeUrl", "http://localhost:8080/kyc/exchange"); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - ReflectionTestUtils.setField(mockAuthenticationService, "objectMapper", objectMapper); - - VerifiedKycExchangeDto verifiedKycExchangeDto = new VerifiedKycExchangeDto(); - verifiedKycExchangeDto.setKycToken("kycToken"); - verifiedKycExchangeDto.setAcceptedClaims(Arrays.asList("name", "gender")); - verifiedKycExchangeDto.setClaimsLocales(new String[]{"eng", "hin"}); - - - - Map acceptedVerifiedClaims=new HashMap<>(); - - VerificationFilter verificationFilterForName= new VerificationFilter(); - FilterCriteria trustFrameWorkCriteria = new FilterCriteria(); - trustFrameWorkCriteria.setValues(List.of("PWD", "Income-tax")); - FilterDateTime filterDateTime = new FilterDateTime(); - filterDateTime.setMax_age(1000); - verificationFilterForName.setTime(filterDateTime); - verificationFilterForName.setTrust_framework(trustFrameWorkCriteria); - - VerificationFilter verificationFilterForEmail= new VerificationFilter(); - FilterCriteria trustFrameworkForEmail = new FilterCriteria(); - trustFrameworkForEmail.setValues(List.of("PWD")); - filterDateTime.setMax_age(500); - verificationFilterForEmail.setTime(filterDateTime); - verificationFilterForEmail.setTrust_framework(trustFrameworkForEmail); - - - acceptedVerifiedClaims.put("name", verificationFilterForName); - acceptedVerifiedClaims.put("email", verificationFilterForEmail); - - verifiedKycExchangeDto.setAcceptedVerifiedClaims(acceptedVerifiedClaims); - ResponseWrapper responseWrapper = new ResponseWrapper(); - responseWrapper.setResponse(null); - ResponseEntity> responseEntity = new ResponseEntity(responseWrapper, HttpStatus.OK); - Mockito.when(restTemplate.exchange( - Mockito.any(RequestEntity.class), - Mockito.eq(new ParameterizedTypeReference>() { - }) - )).thenReturn(responseEntity); - try { - mockAuthenticationService.doVerifiedKycExchange("RP", "CL", verifiedKycExchangeDto); - Assert.fail(); - } catch (KycExchangeException e) { - Assert.assertEquals(e.getErrorCode(), ErrorConstants.DATA_EXCHANGE_FAILED); - } - } - - @Test - public void doVerifiedKycExchange_withInvalidDetails_thenFail() { - ReflectionTestUtils.setField(mockAuthenticationService, "kycExchangeUrl", "http://localhost:8080/kyc/exchange"); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.registerModule(new JavaTimeModule()); - ReflectionTestUtils.setField(mockAuthenticationService, "objectMapper", objectMapper); - - VerifiedKycExchangeDto verifiedKycExchangeDto = new VerifiedKycExchangeDto(); - verifiedKycExchangeDto.setKycToken("kycToken"); - verifiedKycExchangeDto.setAcceptedClaims(Arrays.asList("name", "gender")); - verifiedKycExchangeDto.setClaimsLocales(new String[]{"eng", "hin"}); - - - - Map acceptedVerifiedClaims=new HashMap<>(); - - VerificationFilter verificationFilterForName= new VerificationFilter(); - FilterCriteria trustFrameWorkCriteria = new FilterCriteria(); - trustFrameWorkCriteria.setValues(List.of("PWD", "Income-tax")); - FilterDateTime filterDateTime = new FilterDateTime(); - filterDateTime.setMax_age(1000); - verificationFilterForName.setTime(filterDateTime); - verificationFilterForName.setTrust_framework(trustFrameWorkCriteria); - - VerificationFilter verificationFilterForEmail= new VerificationFilter(); - FilterCriteria trustFrameworkForEmail = new FilterCriteria(); - trustFrameworkForEmail.setValues(List.of("PWD")); - filterDateTime.setMax_age(500); - verificationFilterForEmail.setTime(filterDateTime); - verificationFilterForEmail.setTrust_framework(trustFrameworkForEmail); - - - acceptedVerifiedClaims.put("name", verificationFilterForName); - acceptedVerifiedClaims.put("email", verificationFilterForEmail); - - verifiedKycExchangeDto.setAcceptedVerifiedClaims(acceptedVerifiedClaims); - - try { - mockAuthenticationService.doVerifiedKycExchange("RP", "CL", verifiedKycExchangeDto); - Assert.fail(); - } catch (KycExchangeException e) { - Assert.assertEquals(e.getErrorCode(),"mock-ida-005"); - } - }*/ - @Test public void doKycExchange_withValidDetails_thenPass() throws KycExchangeException { ReflectionTestUtils.setField(mockAuthenticationService, "kycExchangeUrl", "http://localhost:8080/kyc/exchange"); diff --git a/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockHelperServiceTest.java b/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockHelperServiceTest.java index 0af4748..a41e6a1 100644 --- a/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockHelperServiceTest.java +++ b/mock-plugin/src/test/java/io/mosip/esignet/plugin/mock/service/MockHelperServiceTest.java @@ -49,7 +49,7 @@ public class MockHelperServiceTest { @Mock SignatureService signatureService; - private final ObjectMapper objectMapper = new ObjectMapper(); + private ObjectMapper objectMapper = new ObjectMapper(); @Before @@ -81,7 +81,7 @@ public void setUp() throws Exception { } @Test - public void doKycAuthMock_withValidAuthFactorAsOTP_thenPass() throws KycAuthException { + public void doKycAuthMock_withAuthFactorAsOTP_thenPass() throws KycAuthException { ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); @@ -238,175 +238,6 @@ public void doKycAuthMock_withAuthFactorAsPWD_thenPass() throws KycAuthException Assert.assertEquals("partner_token", result.getPartnerSpecificUserToken()); } - @Test - public void doKycAuthMock_withInvalidChallenge_thenFail() { - ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); - ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2(); - Map> claimMetaData=new HashMap<>(); - ObjectNode verificationDetail = objectMapper.createObjectNode(); - verificationDetail.put("trust_framework", "test_trust_framework"); - claimMetaData.put("name",List.of(verificationDetail)); - response.setClaimMetadata(claimMetaData); - response.setAuthStatus(true); - response.setKycToken("test_token"); - response.setPartnerSpecificUserToken("partner_token"); - responseWrapper.setResponse(response); - KycAuthDto kycAuthDto = new KycAuthDto(); - AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setAuthFactorType("abc"); - authChallenge.setChallenge("123456"); - authChallenge.setFormat("alpha-numeric"); - kycAuthDto.setChallengeList(List.of(authChallenge)); - try { - mockHelperService.doKycAuthMock("relyingPartyId", "clientId", kycAuthDto, true); - Assert.fail(); - }catch (KycAuthException e) - { - Assert.assertEquals("invalid_auth_challenge",e.getMessage()); - } - } - - @Test - public void doKycAuthMock_withInvalidChallengeFormat_thenFail() { - ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); - ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2(); - Map> claimMetaData=new HashMap<>(); - ObjectNode verificationDetail = objectMapper.createObjectNode(); - verificationDetail.put("trust_framework", "test_trust_framework"); - claimMetaData.put("name",List.of(verificationDetail)); - response.setClaimMetadata(claimMetaData); - - response.setAuthStatus(true); - response.setKycToken("test_token"); - response.setPartnerSpecificUserToken("partner_token"); - responseWrapper.setResponse(response); - ResponseEntity> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK); - - KycAuthDto kycAuthDto = new KycAuthDto(); - AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setAuthFactorType("OTP"); - authChallenge.setChallenge("123456"); - authChallenge.setFormat("invalidFormat"); - kycAuthDto.setChallengeList(List.of(authChallenge)); - try { - mockHelperService.doKycAuthMock("relyingPartyId", "clientId", kycAuthDto, true); - Assert.fail(); - }catch (KycAuthException e) - { - Assert.assertEquals("invalid_challenge_format",e.getMessage()); - } - } - - @Test - public void getUTCDateTime_withValidDetails_thenPass() { - LocalDateTime utcDateTime = mockHelperService.getUTCDateTime(); - Assert.assertNotNull(utcDateTime); - } - - @Test - public void getEpochSeconds_withValidDetails_thenPass() { - long epochSeconds = mockHelperService.getEpochSeconds(); - Assert.assertTrue(epochSeconds > 0); - } - - @Test - public void isSupportedOtpChannel_withValidChannel_thenPass() { - ReflectionTestUtils.setField(mockHelperService,"otpChannels",List.of("sms")); - Assert.assertTrue(mockHelperService.isSupportedOtpChannel("sms")); - } - - @Test - public void doKycAuthMock_withEmptyResponse_thenFail() throws KycAuthException { - ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); - ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2(); - - Map> claimMetaData=new HashMap<>(); - - ObjectNode verificationDetail = objectMapper.createObjectNode(); - verificationDetail.put("trust_framework", "test_trust_framework"); - claimMetaData.put("name",List.of(verificationDetail)); - - response.setClaimMetadata(claimMetaData); - - response.setAuthStatus(true); - response.setKycToken("test_token"); - response.setPartnerSpecificUserToken("partner_token"); - responseWrapper.setResponse(response); - ResponseEntity> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK); - - Mockito.when(restTemplate.exchange( - Mockito.any(RequestEntity.class), - Mockito.eq(new ParameterizedTypeReference>() { - }) - )).thenReturn(responseEntity); - - - KycAuthDto kycAuthDto = new KycAuthDto(); // Assume this is properly initialized - AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setAuthFactorType("PIN"); - authChallenge.setChallenge("123456"); - authChallenge.setFormat("number"); - kycAuthDto.setChallengeList(List.of(authChallenge)); - // Execute the method - KycAuthResult result = mockHelperService.doKycAuthMock("relyingPartyId", "clientId", kycAuthDto, true); - - Assert.assertNotNull(result); - Assert.assertEquals("test_token", result.getKycToken()); - Assert.assertEquals("partner_token", result.getPartnerSpecificUserToken()); - } - - - @Test - public void doKycAuthMock_withValidAuthFactorAsPWD_thenPass() throws KycAuthException { - - ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); - ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2(); - - Map> claimMetaData=new HashMap<>(); - - ObjectNode verificationDetail = objectMapper.createObjectNode(); - verificationDetail.put("trust_framework", "test_trust_framework"); - claimMetaData.put("name",List.of(verificationDetail)); - - response.setClaimMetadata(claimMetaData); - - response.setAuthStatus(true); - response.setKycToken("test_token"); - response.setPartnerSpecificUserToken("partner_token"); - responseWrapper.setResponse(response); - ResponseEntity> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK); - - Mockito.when(restTemplate.exchange( - Mockito.any(RequestEntity.class), - Mockito.eq(new ParameterizedTypeReference>() { - }) - )).thenReturn(responseEntity); - - - KycAuthDto kycAuthDto = new KycAuthDto(); // Assume this is properly initialized - AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setAuthFactorType("PWD"); - authChallenge.setChallenge("123av456"); - authChallenge.setFormat("alpha-numeric"); - kycAuthDto.setChallengeList(List.of(authChallenge)); - // Execute the method - KycAuthResult result = mockHelperService.doKycAuthMock("relyingPartyId", "clientId", kycAuthDto, true); - - Assert.assertNotNull(result); - Assert.assertEquals("test_token", result.getKycToken()); - Assert.assertEquals("partner_token", result.getPartnerSpecificUserToken()); - } - @Test public void doKycAuthMock_withValidAuthFactorAsBIO_thenPass() throws KycAuthException { ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); @@ -450,94 +281,6 @@ public void doKycAuthMock_withValidAuthFactorAsBIO_thenPass() throws KycAuthExce Assert.assertEquals("partner_token", result.getPartnerSpecificUserToken()); } - @Test - public void doKycAuthMock_withValidAuthFactorAsKBI_thenPass() throws KycAuthException { - - ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); - ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2(); - - Map> claimMetaData=new HashMap<>(); - - ObjectNode verificationDetail = objectMapper.createObjectNode(); - verificationDetail.put("trust_framework", "test_trust_framework"); - claimMetaData.put("name",List.of(verificationDetail)); - - response.setClaimMetadata(claimMetaData); - - response.setAuthStatus(true); - response.setKycToken("test_token"); - response.setPartnerSpecificUserToken("partner_token"); - responseWrapper.setResponse(response); - ResponseEntity> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK); - - Mockito.when(restTemplate.exchange( - Mockito.any(RequestEntity.class), - Mockito.eq(new ParameterizedTypeReference>() { - }) - )).thenReturn(responseEntity); - - - KycAuthDto kycAuthDto = new KycAuthDto(); // Assume this is properly initialized - AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setAuthFactorType("KBI"); - authChallenge.setChallenge("3db2a3"); - authChallenge.setFormat("base64url-encoded-json"); - kycAuthDto.setChallengeList(List.of(authChallenge)); - // Execute the method - KycAuthResult result = mockHelperService.doKycAuthMock("relyingPartyId", "clientId", kycAuthDto, true); - - Assert.assertNotNull(result); - Assert.assertEquals("test_token", result.getKycToken()); - Assert.assertEquals("partner_token", result.getPartnerSpecificUserToken()); - } - - @Test - public void doKycAuthMock_withValidAuthFactorAsWLA_thenPass() throws KycAuthException { - ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); - ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); - - ResponseWrapper responseWrapper = new ResponseWrapper<>(); - KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2(); - - Map> claimMetaData=new HashMap<>(); - - ObjectNode verificationDetail = objectMapper.createObjectNode(); - verificationDetail.put("trust_framework", "test_trust_framework"); - claimMetaData.put("name",List.of(verificationDetail)); - - response.setClaimMetadata(claimMetaData); - - response.setAuthStatus(true); - response.setKycToken("test_token"); - response.setPartnerSpecificUserToken("partner_token"); - responseWrapper.setResponse(response); - ResponseEntity> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK); - - Mockito.when(restTemplate.exchange( - Mockito.any(RequestEntity.class), - Mockito.eq(new ParameterizedTypeReference>() { - }) - )).thenReturn(responseEntity); - - - KycAuthDto kycAuthDto = new KycAuthDto(); // Assume this is properly initialized - AuthChallenge authChallenge = new AuthChallenge(); - authChallenge.setAuthFactorType("WLA"); - authChallenge.setChallenge("e3dq.2ef.3ww23"); - authChallenge.setFormat("jwt"); - kycAuthDto.setChallengeList(List.of(authChallenge)); - // Execute the method - KycAuthResult result = mockHelperService.doKycAuthMock("relyingPartyId", "clientId", kycAuthDto, true); - - Assert.assertNotNull(result); - Assert.assertEquals("test_token", result.getKycToken()); - Assert.assertEquals("partner_token", result.getPartnerSpecificUserToken()); - } - - @Test public void doKycAuthMock_withInValidAuthFactor_thenFail() { @@ -559,7 +302,7 @@ public void doKycAuthMock_withInValidAuthFactor_thenFail() { } @Test - public void doKycAuthMock_withInValidAuthFactorType_thenFail() { + public void doKycAuthMock_withInValidAuthChallenge_thenFail() { ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); @@ -579,7 +322,19 @@ public void doKycAuthMock_withInValidAuthFactorType_thenFail() { } @Test - public void doKycAuthMock_withEmptyResponse_thenFail() { + public void getUTCDateTime_withValidDetails_thenPass() { + LocalDateTime utcDateTime = mockHelperService.getUTCDateTime(); + Assert.assertNotNull(utcDateTime); + } + + @Test + public void getEpochSeconds_withValidDetails_thenPass() { + long epochSeconds = mockHelperService.getEpochSeconds(); + Assert.assertTrue(epochSeconds > 0); + } + + @Test + public void doKycAuthMock_withEmptyResponse_thenFail() throws KycAuthException { ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth"); ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper()); @@ -638,7 +393,7 @@ public void sendOtpMock_withValidDetails_thenPass() throws SendOtpException { } @Test - public void sendOtpMock_withEmptyResponse_thenFail() { + public void sendOtpMock_withEmptyResponse_thenFail() throws SendOtpException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); @@ -664,7 +419,7 @@ public void sendOtpMock_withEmptyResponse_thenFail() { } @Test - public void sendOtpMock_withErrorInResponse_thenFail() { + public void sendOtpMock_withErrorInResponse_thenFail() throws SendOtpException { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerModule(new JavaTimeModule()); @@ -681,6 +436,7 @@ public void sendOtpMock_withErrorInResponse_thenFail() { Mockito.eq(new ParameterizedTypeReference>() { }) )).thenReturn(responseEntity); + try{ mockHelperService.sendOtpMock("test_transaction_id", "individualId", List.of("mobile"),"relyingPartyId", "clientId"); Assert.fail(); @@ -691,7 +447,7 @@ public void sendOtpMock_withErrorInResponse_thenFail() { @Test - public void sendOtpMock_withResponseCodeAsUnAuthorized_thenFail() { + public void sendOtpMock_withResponseCodeAsUnAuthorized_thenFail() throws SendOtpException { ObjectMapper objectMapper = new ObjectMapper();