Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
Signed-off-by: Mohd Kaif Siddique <mohdkaif.siddique@ad.infosys.com>
  • Loading branch information
Mohd Kaif Siddique committed Jul 17, 2024
1 parent 093395d commit 2345758
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
@Data
public class VerificationDetail {

String trust_framework;
String trustFramework;
String dateTime;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ public interface IdentityService {

public void addVerifiedClaim(VerifiedClaimRequestDto request) throws MockIdentityException;

public JsonNode getIdentityInJsonNode(String individualId) throws MockIdentityException;
public JsonNode getIdentityV2(String individualId) throws MockIdentityException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class AuthenticationServiceImpl implements AuthenticationService {
public KycAuthResponseDto kycAuth(String relyingPartyId, String clientId, KycAuthRequestDto kycAuthRequestDto) throws MockIdentityException {
//TODO validate relying party Id and client Id

JsonNode identityData = identityService.getIdentityInJsonNode(kycAuthRequestDto.getIndividualId());
JsonNode identityData = identityService.getIdentityV2(kycAuthRequestDto.getIndividualId());
if (identityData == null) {
throw new MockIdentityException("invalid_individual_id");
}
Expand All @@ -117,7 +117,7 @@ public KycAuthResponseDto kycAuth(String relyingPartyId, String clientId, KycAut
@Override
public KycAuthResponseDtoV2 kycAuthV2(String relyingPartyId, String clientId, KycAuthRequestDto kycAuthRequestDto) {

JsonNode identityData = identityService.getIdentityInJsonNode(kycAuthRequestDto.getIndividualId());
JsonNode identityData = identityService.getIdentityV2(kycAuthRequestDto.getIndividualId());
Boolean authStatus=doKycAuthentication(kycAuthRequestDto,identityData);

Optional<List<VerifiedClaim>> verifiedClaimsOptional = verifiedClaimRepository.findByIndividualIdAndActive(kycAuthRequestDto.getIndividualId(), true);
Expand All @@ -143,7 +143,7 @@ public KycAuthResponseDtoV2 kycAuthV2(String relyingPartyId, String clientId, Ky
for (VerifiedClaim verifiedClaim : verifiedClaimsList) {
VerificationDetail verificationDetail = new VerificationDetail();
verificationDetail.setDateTime(verifiedClaim.getVerifiedDateTime().format(DateTimeFormatter.ofPattern(UTC_DATETIME_PATTERN)));
verificationDetail.setTrust_framework(verifiedClaim.getTrustFramework());
verificationDetail.setTrustFramework(verifiedClaim.getTrustFramework());
verificationDetailList.add(verificationDetail);
}
}
Expand Down Expand Up @@ -301,7 +301,7 @@ private Boolean doKycAuthentication(KycAuthRequestDto kycAuthRequestDto,JsonNode
}

if (kycAuthRequestDto.getPin() != null) {
authStatus = kycAuthRequestDto.getPin().equals(HelperUtil.getIdentityDataValue(identityData,"pin","eng"));
authStatus = kycAuthRequestDto.getPin().equals(HelperUtil.getIdentityDataValue(identityData,"pin",defaultLanguage));
if (!authStatus)
throw new MockIdentityException("auth_failed");
}
Expand Down Expand Up @@ -404,7 +404,7 @@ private KycAuth saveKycAuthTransaction(String transactionId, String relyingParty

private Map<String, Object> buildKycDataBasedOnPolicyV2(String individualId, Map<String, Object> acceptedClaims, List<String> locales) {
Map<String, Object> kyc = new HashMap<>();
JsonNode identityData = identityService.getIdentityInJsonNode(individualId);
JsonNode identityData = identityService.getIdentityV2(individualId);
if (identityData == null) {
throw new MockIdentityException("mock-ida-001");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public IdentityData getIdentity(String individualId) throws MockIdentityExceptio
}

@Override
public JsonNode getIdentityInJsonNode(String individualId) throws MockIdentityException {
public JsonNode getIdentityV2(String individualId) throws MockIdentityException {
Optional<MockIdentity> mockIdentity = identityRepository.findById(individualId);
if (!mockIdentity.isPresent()) {
throw new MockIdentityException(ErrorConstants.INVALID_INDIVIDUAL_ID);
Expand All @@ -92,7 +92,7 @@ public JsonNode getIdentityInJsonNode(String individualId) throws MockIdentityEx
@Override
public void addVerifiedClaim(VerifiedClaimRequestDto verifiedClaimRequestDto) throws MockIdentityException {
VerifiedClaim verifiedClaim =null;
JsonNode identity = getIdentityInJsonNode(verifiedClaimRequestDto.getIndividualId());
JsonNode identity = getIdentityV2(verifiedClaimRequestDto.getIndividualId());
Object fieldValue= HelperUtil.getIdentityDataValue(identity, verifiedClaimRequestDto.getClaim(),fieldLang);
if(fieldValue==null){
throw new MockIdentityException(ErrorConstants.INVALID_CLAIM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ public static String getIdentityDataValue(JsonNode jsonNode, String field, Strin
if(jsonNode.has(field)){
Object fieldValue = jsonNode.get(field);
if(fieldValue instanceof ArrayNode){
List<LanguageValue> languageValues = getLanguageValuesList((ArrayNode) fieldValue);
for(LanguageValue languageValue:languageValues){
if(languageValue.getLanguage().equals(fieldLang)){
return languageValue.getValue();
for (JsonNode node : (ArrayNode)fieldValue) {
String language = node.get("language").asText();
String value = node.get("value").asText();
if(language.equals(fieldLang)){
return value;
}
}
}else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void kycAuth_withValidKbiChallenge_thenPass() {
languageValue.setLanguage("eng");
languageValue.setValue("Siddharth K Mansour");
identityData.setFullName(List.of(languageValue));
Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(jsonNode);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(jsonNode);

Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth());

Expand Down Expand Up @@ -102,7 +102,7 @@ public void kycAuth_withInCorrectKbiChallenge_thenFail() {
languageValue.setLanguage("eng");
languageValue.setValue("Siddharth K Mansour");
identityData.setFullName(List.of(languageValue));
Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(jsonNode);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(jsonNode);

Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth());

Expand Down Expand Up @@ -131,7 +131,7 @@ public void kycAuth_withInValidKbiChallenge_thenFail() {
languageValue.setLanguage("eng");
languageValue.setValue("Siddharth K Mansour");
identityData.setFullName(List.of(languageValue));
Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(jsonNode);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(jsonNode);
try{
authenticationService.kycAuth("relyingPartyId", "clientId", kycAuthRequestDto);
}catch (MockIdentityException e){
Expand Down Expand Up @@ -237,7 +237,7 @@ public void kycExchangeV2_withDetail_thenPass() {
Mockito.any(),Mockito.any(),Mockito.any())).thenReturn(kycAuthOptional);
Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth());

Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(jsonNode);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(jsonNode);

VerifiedClaim verifiedClaim = new VerifiedClaim();
verifiedClaim.setTrustFramework("pwd");
Expand Down Expand Up @@ -298,7 +298,7 @@ public void kycExchangeV2_withInValidIndividualId_thenFail() throws InvocationTa
Mockito.when(authRepository.findByKycTokenAndValidityAndTransactionIdAndIndividualId(Mockito.any(),
Mockito.any(),Mockito.any(),Mockito.any())).thenReturn(kycAuthOptional);

Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(null);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(null);

try{
authenticationService.kycExchangeV2("relyingPartyId", "clientId", kycExchangeRequestDtoV2);
Expand Down Expand Up @@ -402,7 +402,7 @@ public void kycExchangeV2_withOutVerifiedClaims_thenPass() throws InvocationTarg
Mockito.any(),Mockito.any(),Mockito.any())).thenReturn(kycAuthOptional);
Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth());

Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(jsonNode);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(jsonNode);

Mockito.when(verifiedClaimRepository.findByIndividualIdAndActive(Mockito.anyString(),Mockito.anyBoolean())).thenReturn(Optional.empty());
JWTSignatureResponseDto jwtSignatureResponseDto = new JWTSignatureResponseDto();
Expand Down Expand Up @@ -454,7 +454,7 @@ public void kycAuth2_withValidKbiChallenge_thenPass() throws Exception {
identityData.setDateOfBirth("1987/11/25");
identityData.setEmail("email@gmail.com");

Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(jsonNode);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(jsonNode);

Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth());

Expand Down Expand Up @@ -534,7 +534,7 @@ public void kycAuth2_withValidKbiChallenge_and_withOutVerifiedClaim_thenPass() t
identityData.setDateOfBirth("1987/11/25");
identityData.setEmail("email@gmail.com");

Mockito.when(identityService.getIdentityInJsonNode(Mockito.anyString())).thenReturn(jsonNode);
Mockito.when(identityService.getIdentityV2(Mockito.anyString())).thenReturn(jsonNode);

Mockito.when(authRepository.save(Mockito.any())).thenReturn(new KycAuth());

Expand Down

0 comments on commit 2345758

Please sign in to comment.