Skip to content

Commit

Permalink
[ES-1613] Added test cases
Browse files Browse the repository at this point in the history
Signed-off-by: Venkata Saidurga Polamraju <[email protected]>
  • Loading branch information
pvsaidurga committed Oct 13, 2024
1 parent 0ed2990 commit 7bb38c6
Showing 1 changed file with 210 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public void setUp() throws Exception {
supportedKycAuthFormats.put("BIO", List.of("encoded-json"));
supportedKycAuthFormats.put("WLA", List.of("jwt"));
supportedKycAuthFormats.put("KBA", List.of("base64url-encoded-json"));
supportedKycAuthFormats.put("PWD", List.of("alpha-numeric"));

// Get the field
Field field = MockHelperService.class.getDeclaredField("supportedKycAuthFormats");
Expand Down Expand Up @@ -130,6 +131,215 @@ public void doKycAuthMock_withValidDetails_thenPass() throws KycAuthException {
Assert.assertEquals("partner_token", result.getPartnerSpecificUserToken());
}

@Test
public void doKycAuthMock_withAuthFactorAsWLA_thenPass() throws KycAuthException {
ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth");
ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper());
ResponseWrapper<KycAuthResponseDtoV2> responseWrapper = new ResponseWrapper<>();
KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2();
Map<String,List<JsonNode>> 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<ResponseWrapper<KycAuthResponseDtoV2>> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK);

Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(new ParameterizedTypeReference<ResponseWrapper<KycAuthResponseDtoV2>>() {
})
)).thenReturn(responseEntity);

KycAuthDto kycAuthDto = new KycAuthDto();
AuthChallenge authChallenge = new AuthChallenge();
authChallenge.setAuthFactorType("WLA");
authChallenge.setChallenge("validjwt");
authChallenge.setFormat("jwt");
kycAuthDto.setChallengeList(List.of(authChallenge));
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_withAuthFactorAsPIN_thenPass() throws KycAuthException {
ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth");
ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper());
ResponseWrapper<KycAuthResponseDtoV2> responseWrapper = new ResponseWrapper<>();
KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2();
Map<String,List<JsonNode>> 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<ResponseWrapper<KycAuthResponseDtoV2>> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK);

Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(new ParameterizedTypeReference<ResponseWrapper<KycAuthResponseDtoV2>>() {
})
)).thenReturn(responseEntity);

KycAuthDto kycAuthDto = new KycAuthDto();
AuthChallenge authChallenge = new AuthChallenge();
authChallenge.setAuthFactorType("PIN");
authChallenge.setChallenge("111111");
authChallenge.setFormat("number");
kycAuthDto.setChallengeList(List.of(authChallenge));
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_withAuthFactorAsPWD_thenPass() throws KycAuthException {
ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth");
ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper());
ResponseWrapper<KycAuthResponseDtoV2> responseWrapper = new ResponseWrapper<>();
KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2();
Map<String,List<JsonNode>> 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<ResponseWrapper<KycAuthResponseDtoV2>> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK);

Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(new ParameterizedTypeReference<ResponseWrapper<KycAuthResponseDtoV2>>() {
})
)).thenReturn(responseEntity);

KycAuthDto kycAuthDto = new KycAuthDto();
AuthChallenge authChallenge = new AuthChallenge();
authChallenge.setAuthFactorType("PWD");
authChallenge.setChallenge("Mosip@12");
authChallenge.setFormat("alpha-numeric");
kycAuthDto.setChallengeList(List.of(authChallenge));
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_withInvalidChallenge_thenFail() {
ReflectionTestUtils.setField(mockHelperService, "kycAuthUrl", "http://localhost:8080/kyc/auth");
ReflectionTestUtils.setField(mockHelperService, "objectMapper", new ObjectMapper());
ResponseWrapper<KycAuthResponseDtoV2> responseWrapper = new ResponseWrapper<>();
KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2();
Map<String,List<JsonNode>> 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<ResponseWrapper<KycAuthResponseDtoV2>> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK);

Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(new ParameterizedTypeReference<ResponseWrapper<KycAuthResponseDtoV2>>() {
})
)).thenReturn(responseEntity);

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<KycAuthResponseDtoV2> responseWrapper = new ResponseWrapper<>();
KycAuthResponseDtoV2 response = new KycAuthResponseDtoV2();
Map<String,List<JsonNode>> 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<ResponseWrapper<KycAuthResponseDtoV2>> responseEntity= new ResponseEntity<>(responseWrapper, HttpStatus.OK);

Mockito.when(restTemplate.exchange(
Mockito.any(RequestEntity.class),
Mockito.eq(new ParameterizedTypeReference<ResponseWrapper<KycAuthResponseDtoV2>>() {
})
)).thenReturn(responseEntity);

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 {

Expand Down

0 comments on commit 7bb38c6

Please sign in to comment.