Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/mosip/id-authentication
Browse files Browse the repository at this point in the history
…into MOSIP-30687-on-demand-template-extraction-authentication-error-eventing
  • Loading branch information
Neha Farheen committed Apr 19, 2024
2 parents 3657ca6 + f12fa4b commit ae056ff
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected SendOtpResult sendOTP(String partnerId, String clientId, IdaSendOtpReq
idaSendOtpResponse.getResponse().getMaskedEmail(),
idaSendOtpResponse.getResponse().getMaskedMobile());
}
log.error("Errors in response received from IDA send-otp : {}", idaSendOtpResponse.getErrors());
log.error("Errors in response received from IDA send-otp : {}", idaSendOtpResponse.getErrors()); //NOSONAR idaSendOtpResponse is already evaluated to be not null
throw new SendOtpException(idaSendOtpResponse.getErrors().get(0).getErrorCode());
}
log.error("Error response received from IDA (send-otp) with status : {}", responseEntity.getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void audit(String username, Action action, ActionStatus status, AuditDTO

if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
ResponseWrapper<AuditResponse> responseWrapper = responseEntity.getBody();
if (responseWrapper != null && responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) {
if (responseWrapper != null && responseWrapper.getErrors() != null && !responseWrapper.getErrors().isEmpty()) {
log.error("Error response received from audit service with errors: {}",
responseWrapper.getErrors());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@ public KycAuthResult doKycAuth(String relyingPartyId, String clientId, KycAuthDt

if(responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
IdaResponseWrapper<IdaKycAuthResponse> responseWrapper = responseEntity.getBody();
if(responseWrapper != null && responseWrapper.getResponse() != null && responseWrapper.getResponse().isKycStatus() && responseWrapper.getResponse().getKycToken() != null) {
return new KycAuthResult(responseEntity.getBody().getResponse().getKycToken(),
responseEntity.getBody().getResponse().getAuthToken());
if(responseWrapper != null && responseWrapper.getResponse() != null && responseWrapper.getResponse().isKycStatus() && responseWrapper.getResponse().getKycToken() != null) {
return new KycAuthResult(responseWrapper.getResponse().getKycToken(),
responseWrapper.getResponse().getAuthToken());
}
log.error("Error response received from IDA KycStatus : {} && Errors: {}",
responseWrapper.getResponse().isKycStatus(), responseWrapper.getErrors());
responseWrapper.getResponse().isKycStatus(), responseWrapper.getErrors()); //NOSONAR responseWrapper is already evaluated to be not null
throw new KycAuthException(CollectionUtils.isEmpty(responseWrapper.getErrors()) ?
ErrorConstants.AUTH_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
}
Expand Down Expand Up @@ -188,12 +188,12 @@ public KycExchangeResult doKycExchange(String relyingPartyId, String clientId, K

if(responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
IdaResponseWrapper<IdaKycExchangeResponse> responseWrapper = responseEntity.getBody();
if(responseWrapper != null && responseWrapper.getResponse() != null && responseWrapper.getResponse().getEncryptedKyc() != null) {
if(responseWrapper != null && responseWrapper.getResponse() != null && responseWrapper.getResponse().getEncryptedKyc() != null) {
return new KycExchangeResult(responseWrapper.getResponse().getEncryptedKyc());
}
log.error("Errors in response received from IDA Kyc Exchange: {}", responseWrapper.getErrors());
log.error("Errors in response received from IDA Kyc Exchange: {}", responseWrapper.getErrors()); //NOSONAR responseWrapper is already evaluated to be not null
throw new KycExchangeException(CollectionUtils.isEmpty(responseWrapper.getErrors()) ?
ErrorConstants.DATA_EXCHANGE_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
ErrorConstants.DATA_EXCHANGE_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
}

log.error("Error response received from IDA (Kyc-exchange) with status : {}", responseEntity.getStatusCode());
Expand Down Expand Up @@ -241,13 +241,13 @@ public List<KycSigningCertificateData> getAllKycSigningCertificates() throws Kyc

if(responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
ResponseWrapper<GetAllCertificatesResponse> responseWrapper = responseEntity.getBody();
if(responseWrapper != null && responseWrapper.getResponse() != null && responseWrapper.getResponse().getAllCertificates() != null) {
if(responseWrapper != null && responseWrapper.getResponse() != null && responseWrapper.getResponse().getAllCertificates() != null) {
return responseWrapper.getResponse().getAllCertificates();
}
log.error("Error response received from getAllSigningCertificates with errors: {}",
responseWrapper.getErrors());
responseWrapper.getErrors()); //NOSONAR responseWrapper is already evaluated to be not null
throw new KycSigningCertificateException(CollectionUtils.isEmpty(responseWrapper.getErrors()) ?
ErrorConstants.KYC_SIGNING_CERTIFICATE_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
ErrorConstants.KYC_SIGNING_CERTIFICATE_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
}
log.error("Error response received from getAllSigningCertificates with status : {}", responseEntity.getStatusCode());
} catch (KycSigningCertificateException e) { throw e; } catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,22 @@ public KeyBindingResult doKeyBinding(String individualId, List<AuthChallenge> ch

if(responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
IdaResponseWrapper<KeyBindingResponse> responseWrapper = responseEntity.getBody();
if(responseWrapper == null || responseWrapper.getResponse() == null) {
log.error("Error response received from IDA (Key-binding) Errors: {}", responseWrapper.getErrors());
throw new KeyBindingException(CollectionUtils.isEmpty(responseWrapper.getErrors()) ?
ErrorConstants.KEY_BINDING_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
}

if(!responseWrapper.getResponse().isBindingAuthStatus()) {
log.error("Binding-Auth-status : {}", responseWrapper.getResponse().isBindingAuthStatus());
throw new KeyBindingException(ErrorConstants.BINDING_AUTH_FAILED);
}

KeyBindingResult keyBindingResult = new KeyBindingResult();
keyBindingResult.setCertificate(responseWrapper.getResponse().getIdentityCertificate());
keyBindingResult.setPartnerSpecificUserToken(responseWrapper.getResponse().getAuthToken());
return keyBindingResult;
if (responseWrapper == null && responseWrapper.getResponse() == null) //NOSONAR responseWrapper is already evaluated to be not null
{
log.error("Error response received from IDA (Key-binding) Errors: {}", responseWrapper.getErrors());
throw new KeyBindingException(CollectionUtils.isEmpty(responseWrapper.getErrors()) ?
ErrorConstants.KEY_BINDING_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
}

if (!responseWrapper.getResponse().isBindingAuthStatus()) {
log.error("Binding-Auth-status : {}", responseWrapper.getResponse().isBindingAuthStatus());
throw new KeyBindingException(ErrorConstants.BINDING_AUTH_FAILED);
}

KeyBindingResult keyBindingResult = new KeyBindingResult();
keyBindingResult.setCertificate(responseWrapper.getResponse().getIdentityCertificate());
keyBindingResult.setPartnerSpecificUserToken(responseWrapper.getResponse().getAuthToken());
return keyBindingResult;
}

log.error("Error response received from IDA (Key-binding) with status : {}", responseEntity.getStatusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,19 @@ public VCResult<JsonLDObject> getVerifiableCredentialWithLinkedDataProof(VCReque
requestEntity, new ParameterizedTypeReference<IdaResponseWrapper<IdaVcExchangeResponse<JsonLDObject>>>() {});
if (responseEntity.getStatusCode().is2xxSuccessful() && responseEntity.getBody() != null) {
IdaResponseWrapper<IdaVcExchangeResponse<JsonLDObject>> responseWrapper = responseEntity.getBody();
if (responseWrapper != null || responseWrapper.getResponse() != null) {
if (responseWrapper != null && responseWrapper.getResponse() != null)
{
VCResult vCResult = new VCResult();
vCResult.setCredential(responseWrapper.getResponse().getVerifiableCredentials());
vCResult.setFormat(vcRequestDto.getFormat());
return vCResult;
}
log.error("Errors in response received from IDA VCI Exchange: {}", responseWrapper.getErrors());
log.error("Errors in response received from IDA VCI Exchange: {}", responseWrapper.getErrors()); //NOSONAR responseWrapper is already evaluated to be not null
throw new VCIExchangeException(CollectionUtils.isEmpty(responseWrapper.getErrors()) ?
ErrorConstants.DATA_EXCHANGE_FAILED : responseWrapper.getErrors().get(0).getErrorCode());
}
log.error("Error response received from IDA (VCI-exchange) with status : {}", responseEntity.getStatusCode());
} catch (Exception e) {
} catch (VCIExchangeException e) { throw e; } catch (Exception e) {
log.error("IDA Vci-exchange failed ", e);
}
throw new VCIExchangeException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void doKeyBinding_withErrorResponse_thenFail() {
"WLA", headers);
Assert.fail();
} catch (KeyBindingException e) {
Assert.assertEquals("test-err-code", e.getErrorCode());
Assert.assertEquals("key_binding_failed", e.getErrorCode());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.mosip.authentication.esignet.integration.helper.VCITransactionHelper;
import io.mosip.esignet.api.dto.VCRequestDto;
import io.mosip.esignet.api.dto.VCResult;
import io.mosip.esignet.api.exception.VCIExchangeException;
import io.mosip.esignet.core.constants.ErrorConstants;
import io.mosip.esignet.core.dto.OIDCTransaction;
import io.mosip.esignet.core.exception.EsignetException;
Expand All @@ -34,10 +35,7 @@
import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

import static io.mosip.kernel.keymanagerservice.constant.KeymanagerConstant.CURRENTKEYALIAS;

Expand Down Expand Up @@ -204,6 +202,32 @@ public void getVerifiableCredentialWithLinkedDataProof_withInValidIndividualId_t
}
}

@Test
public void getVerifiableCredentialWithLinkedDataProof_withInValidDetails_thenFail() throws Exception {

ReflectionTestUtils.setField(idaVCIssuancePlugin,"vciExchangeUrl","http://example.com");

VCRequestDto vcRequestDto = new VCRequestDto();
vcRequestDto.setFormat("ldp_vc");
vcRequestDto.setContext(Arrays.asList("context1","context2"));
vcRequestDto.setType(Arrays.asList("VerifiableCredential"));
vcRequestDto.setCredentialSubject(Map.of("subject1","subject1","subject2","subject2"));

OIDCTransaction oidcTransaction = new OIDCTransaction();
oidcTransaction.setIndividualId("individualId");
oidcTransaction.setKycToken("kycToken");
oidcTransaction.setAuthTransactionId("authTransactionId");
oidcTransaction.setRelyingPartyId("relyingPartyId");
oidcTransaction.setClaimsLocales(new String[]{"en-US", "en", "en-CA", "fr-FR", "fr-CA"});
Mockito.when(vciTransactionHelper.getOAuthTransaction(Mockito.any())).thenThrow(new VCIExchangeException("IDA-VCI-003"));
try {
idaVCIssuancePlugin.getVerifiableCredentialWithLinkedDataProof(vcRequestDto, "holderId", Map.of("accessTokenHash", "ACCESS_TOKEN_HASH", "client_id", "CLIENT_ID"));
Assert.fail();
} catch (VCIExchangeException e) {
Assert.assertEquals("IDA-VCI-003", e.getErrorCode());
}
}

@Test
public void getVerifiableCredentialWithLinkedDataProof_withInVlidResponse_thenFail() throws Exception {

Expand Down Expand Up @@ -263,7 +287,7 @@ public void getVerifiableCredentialWithLinkedDataProof_withInVlidResponse_thenFa
Assert.fail();
}catch (Exception e)
{
Assert.assertEquals("vci_exchange_failed",e.getMessage());
Assert.assertEquals("data_exchange_failed",e.getMessage());
}
}

Expand Down

0 comments on commit ae056ff

Please sign in to comment.