From 2c870cb9d959b240856315594701959f38c7f614 Mon Sep 17 00:00:00 2001 From: kaifk468 <74772315+kaifk468@users.noreply.github.com> Date: Fri, 3 Nov 2023 13:06:21 +0530 Subject: [PATCH] Added test case for coverage (#1123) * added test cases for idaVCIssuancePluginImpl * test cases added for idaVCIssuancePluginImpl * added test cases for idaVCIssuancePluginImpl * added langCode converter in idaVCIssuancePluginImpl * fix the build failed * fix issue with lan code like en-US * added test case * added test cases for coverage * added test case * test case for coverage --- .../helper/TokenValidationHelperTest.java | 139 +++++++ .../KeyBindedTokenAuthServiceImplTest.java | 69 ++++ .../util/KeyBindedTokenMatcherUtilTest.java | 157 ++++++++ .../service/util/TokenEncoderUtilTest.java | 27 ++ .../service/kyc/facade/VciFacadeImplTest.java | 179 +++++++++ .../service/kyc/impl/VciServiceImplTest.java | 347 ++++++++++++++++++ .../service/IdaVCIssuancePluginImplTest.java | 2 +- 7 files changed, 919 insertions(+), 1 deletion(-) create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/TokenValidationHelperTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/KeyBindedTokenAuthServiceImplTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/KeyBindedTokenMatcherUtilTest.java create mode 100644 authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/TokenEncoderUtilTest.java create mode 100644 authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/facade/VciFacadeImplTest.java create mode 100644 authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/impl/VciServiceImplTest.java diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/TokenValidationHelperTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/TokenValidationHelperTest.java new file mode 100644 index 00000000000..0e7b328781a --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/helper/TokenValidationHelperTest.java @@ -0,0 +1,139 @@ +package io.mosip.authentication.common.service.helper; + +import io.mosip.authentication.common.service.entity.KycTokenData; +import io.mosip.authentication.common.service.repository.KycTokenDataRepository; +import io.mosip.authentication.common.service.repository.OIDCClientDataRepository; +import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.authentication.core.spi.indauth.service.KycService; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.test.context.junit4.SpringRunner; + +import java.time.LocalDateTime; +import java.util.*; + +@RunWith(SpringRunner.class) +public class TokenValidationHelperTest { + + /** The Kyc Service */ + @Mock + private KycService kycService; + + @Mock + private KycTokenDataRepository kycTokenDataRepo; + + @Mock + private IdInfoHelper idInfoHelper; + + @Mock + private OIDCClientDataRepository oidcClientDataRepo; + + @InjectMocks + TokenValidationHelper tokenValidationHelper; + + + @Test + public void findAndValidateIssuedTokenTestWithValidDetails_thenPass() throws IdAuthenticationBusinessException { + + KycTokenData kycTokenData = new KycTokenData(); + kycTokenData.setPsuToken("1234567890"); + kycTokenData.setKycToken("1234567890"); + kycTokenData.setKycTokenStatus("ACTIVE"); + kycTokenData.setOidcClientId("12345"); + kycTokenData.setTokenIssuedDateTime(LocalDateTime.now()); + kycTokenData.setIdVidHash("1234567"); + kycTokenData.setRequestTransactionId("123456"); + Mockito.when(kycTokenDataRepo.findByKycToken(Mockito.anyString())).thenReturn(Optional.of(kycTokenData)); + Mockito.when( kycService.isKycTokenExpire(Mockito.any(),Mockito.anyString())).thenReturn(false); + + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12345", "123456", "1234567"); + + } + + @Test + public void findAndValidateIssuedTokenTestWithInValidTokenDetails_thenFail() throws IdAuthenticationBusinessException { + + Mockito.when(kycTokenDataRepo.findByKycToken(Mockito.anyString())).thenReturn(Optional.empty()); + Mockito.when( kycService.isKycTokenExpire(Mockito.any(),Mockito.anyString())).thenReturn(false); + + try{ + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12346", "123456", "1234567"); + }catch (IdAuthenticationBusinessException e){ + assert(e.getErrorCode().equalsIgnoreCase("IDA-KYE-001")); + } + + } + + @Test + public void findAndValidateIssuedTokenTestWithExpiredTokenDetails_thenFail() throws IdAuthenticationBusinessException { + + KycTokenData kycTokenData = new KycTokenData(); + kycTokenData.setPsuToken("1234567890"); + kycTokenData.setKycToken("1234567890"); + kycTokenData.setKycTokenStatus("ACTIVE"); + kycTokenData.setOidcClientId("12345"); + kycTokenData.setTokenIssuedDateTime(LocalDateTime.now()); + kycTokenData.setIdVidHash("1234567"); + kycTokenData.setRequestTransactionId("123456"); + Mockito.when(kycTokenDataRepo.findByKycToken(Mockito.anyString())).thenReturn(Optional.of(kycTokenData)); + Mockito.when( kycService.isKycTokenExpire(Mockito.any(),Mockito.anyString())).thenReturn(true); + + try{ + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12345", "123456", "1234567"); + }catch (IdAuthenticationBusinessException e){ + assert(e.getErrorCode().equalsIgnoreCase("IDA-KYE-002")); + } + + } + + @Test + public void findAndValidateIssuedTokenTestWithInValidDetails_thenPass() throws IdAuthenticationBusinessException { + + KycTokenData kycTokenData = new KycTokenData(); + kycTokenData.setPsuToken("1234567890"); + kycTokenData.setKycToken("1234567890"); + kycTokenData.setKycTokenStatus("ACTIVE"); + kycTokenData.setOidcClientId("12345"); + kycTokenData.setTokenIssuedDateTime(LocalDateTime.now()); + kycTokenData.setIdVidHash("1234567"); + kycTokenData.setRequestTransactionId("123456"); + Mockito.when(kycTokenDataRepo.findByKycToken(Mockito.anyString())).thenReturn(Optional.of(kycTokenData)); + Mockito.when( kycService.isKycTokenExpire(Mockito.any(),Mockito.anyString())).thenReturn(false); + + + try{ + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12346", "123456", "1234567"); + }catch (IdAuthenticationBusinessException e){ + assert(e.getErrorCode().equalsIgnoreCase("IDA-KYE-004")); + } + + try{ + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12345", "123457", "1234567"); + }catch (IdAuthenticationBusinessException e){ + assert(e.getErrorCode().equalsIgnoreCase("IDA-KYE-005")); + } + + try{ + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12345", "123456", "1234568"); + }catch (IdAuthenticationBusinessException e){ + assert(e.getErrorCode().equalsIgnoreCase("IDA-KYE-007")); + } + + kycTokenData.setKycTokenStatus("EXPIRED"); + try{ + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12345", "123456", "1234567"); + }catch (IdAuthenticationBusinessException e){ + assert(e.getErrorCode().equalsIgnoreCase("IDA-KYE-002")); + } + + kycTokenData.setKycTokenStatus("PROCESSED"); + try{ + tokenValidationHelper.findAndValidateIssuedToken("1234567890", "12345", "123456", "1234567"); + }catch (IdAuthenticationBusinessException e){ + assert(e.getErrorCode().equalsIgnoreCase("IDA-KYE-003")); + } + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/KeyBindedTokenAuthServiceImplTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/KeyBindedTokenAuthServiceImplTest.java new file mode 100644 index 00000000000..3ca7339c265 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/impl/KeyBindedTokenAuthServiceImplTest.java @@ -0,0 +1,69 @@ +package io.mosip.authentication.common.service.impl; + + +import io.mosip.authentication.common.service.builder.MatchInputBuilder; +import io.mosip.authentication.common.service.config.IDAMappingConfig; +import io.mosip.authentication.common.service.helper.IdInfoHelper; +import io.mosip.authentication.common.service.repository.IdentityBindingCertificateRepository; +import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; +import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.authentication.core.indauth.dto.AuthRequestDTO; +import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; +import io.mosip.authentication.core.spi.indauth.match.MatchOutput; +import org.apache.commons.collections.map.HashedMap; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +public class KeyBindedTokenAuthServiceImplTest { + + @InjectMocks + IdInfoHelper idInfoHelper; + + /** The id info helper. */ + @Mock + MatchInputBuilder matchInputBuilder; + + /** The ida mapping config. */ + @Mock + IDAMappingConfig idaMappingConfig; + + @Mock + IdAuthSecurityManager securityManager; + + @Mock + IdentityBindingCertificateRepository identityBindingCertificateRepository; + + @InjectMocks + KeyBindedTokenAuthServiceImpl keyBindedTokenAuthService; + + @Test + public void authenticateTestWithValidDetails_thenPass() throws IdAuthenticationBusinessException { + AuthRequestDTO authRequestDTO = new AuthRequestDTO(); + + ReflectionTestUtils.setField(keyBindedTokenAuthService,"idInfoHelper",idInfoHelper); + IdentityInfoDTO identityInfoDTO=new IdentityInfoDTO(); + identityInfoDTO.setValue("value"); + identityInfoDTO.setLanguage("end"); + List list=new ArrayList<>(); + list.add(identityInfoDTO); + Map> idInfo= new HashedMap(); + idInfo.put("key",list); + + MatchOutput matchOutput=new MatchOutput(5,true,"fingerpring",null,"end","idName"); + + matchOutput.setLanguage("end"); + List matchOutputList=new ArrayList<>(); + matchOutputList.add(matchOutput); + keyBindedTokenAuthService.authenticate(authRequestDTO,"individualId",idInfo,"partnerId"); + + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/KeyBindedTokenMatcherUtilTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/KeyBindedTokenMatcherUtilTest.java new file mode 100644 index 00000000000..6bfd363de7d --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/KeyBindedTokenMatcherUtilTest.java @@ -0,0 +1,157 @@ +package io.mosip.authentication.common.service.util; + +import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.kernel.keymanagerservice.util.KeymanagerUtil; +import org.bouncycastle.util.io.pem.PemObject; +import org.bouncycastle.util.io.pem.PemReader; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.StringReader; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@RunWith(SpringRunner.class) +public class KeyBindedTokenMatcherUtilTest { + + @Mock + KeymanagerUtil keymanagerUtil; + @InjectMocks + KeyBindedTokenMatcherUtil keyBindedTokenMatcherUtil; + + + @Test + public void matchTestWithInValidToken_thenFail() { + + Map properties =new HashMap<>(); + Map bindingCertificates =new HashMap<>(); + Map input =new HashMap<>(); + input.put("individualId","individualId"); + input.put("type","type"); + input.put("format","jwt"); + input.put("token",".eyJ"); + + try{ + keyBindedTokenMatcherUtil.match(input, bindingCertificates, properties); + }catch (IdAuthenticationBusinessException e){ + } + } + @Test + public void matchTestWithExpiredToken_thenFail() { + + Map properties =new HashMap<>(); + Map bindingCertificates =new HashMap<>(); + Map input =new HashMap<>(); + input.put("individualId","individualId"); + input.put("type","type"); + input.put("format","jwt"); + input.put("token","eyJ0eXAiOiJKV1QiLCJ4NXQjUzI1NiI6IjBFSmtKMDYyWnZNZ0dKSk9BRVNYWFo1Tl9hamRDOG04Y0hPTXVKVVRGWUEiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2OTg5ODgyMTcsIm5iZiI6MTY5ODk4ODIxNywiZXhwIjoxNjk4OTg4ODIyLCJqdGkiOiJYZkpRaGVfU3RuNTNmaWc3YVV3V3MiLCJhdWQiOiJpZGEtYmluZGluZyIsInN1YiI6IjQxNTg2MTI2MDkiLCJpc3MiOiJwb3N0bWFuLWluamkifQ.bSqcJZlq5PyAExwPoww41OF-vBIyaADZ8OsXzA_7gtowNl0kChVAB11eIPEcjuFvYeQiSpQgNZsS2-w84ZBdiqh72kkJQLjN7ItMKNf-cekNRmG6XFf1os1vom7CwrguataoYvboiiXYw0WUfsZTmnhcOKC8XN3qAsB2YAyYEnBJBeKy5aCNAfJiOULTMrqAqcu-A1MA_wtAkaCJggiNxf1-5bJWjZYyQOkis0nHmbgWjzzThdd6TzMkLnUyNxzO2n1E9A19OJ2ZH0ZN1d46c8QBMsYmGX-Kz8B8GBDnDlwC4M5g4hmxuXCN6sBcVjAONl92LxI1htSZ6muv3xL1YQ"); + + try{ + keyBindedTokenMatcherUtil.match(input, bindingCertificates, properties); + }catch (IdAuthenticationBusinessException e){ + Assert.assertEquals("IDA-KBT-002",e.getErrorCode()); + } + } + + @Test + public void matchTestWithInValidThumbprint_thenFail() { + + Map properties =new HashMap<>(); + Map bindingCertificates =new HashMap<>(); + Map input =new HashMap<>(); + input.put("individualId","individualId"); + input.put("type","type"); + input.put("format","jwt"); + input.put("token","eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJrdHkiOiJSU0EiLCJlIjoiQVFBQiIsInVzZSI6InNpZyIsImtpZCI6IkFBNzBWbUQ2OGltaUU2NDhSdDBzRWNhc1N3VkJDNGxtbno4ZUFPZmRYQzgiLCJhbGciOiJSUzI1NiIsIm4iOiJzZFNtY0o1bzJZX1JMOURORXFEQl9fV0xqV1RUY3JvRHpMaXRFRUxSb3h3MF9talV1azAyd1NlcTY3YlR4YzR0b2JMTS04Y19DNkVsNUgtQzlsTFF3VURZYnZ1VmxpX2lBLWtvZ0Rxa1dOTEEwbWZaLW9FRUtEYTlJV280VmY4MHl2Z09EN2hfSlpCWG53dHZjaTRqUlNaekc1R05sU2VJY25ZU0tiNVpvTTBOVDEtb0VrLU1tQnIxcmZGYWpGZ0hvMXhQSTQwUkN6UFhNWnkwOXY5Y2R5SVdTbWFzd2VRMmcxbEtsVHhqcVhibEtiTjZMQzNhUXc2azlFVVEzNjJ5QW5FMmZWOWpkcmNFb29RT0ZYZk1ZTHQ2UlFRMmJQSjIxb01aT0RGUjU0cHlVT0RxdlowMnczcnZMS0ozU2dvTHEtLVlDUTEzNi04cWJqNXpTVnNwMlEiLCJpYXQiOjE2OTg5OTQzMzR9.J4DNzGDNWE6AIIg7PAF8CZufFOOKA97ngBn1xMU05T9X_eqV9mfSk3G-fDXRRGS3ucS25gB2k6kOh7vt0eoVYEgw1lOQ2ERM2UoT7sWzUYvt0zedkP2zgkcubkeOwC-dY65_NiFRZ4iXudu38iLd2iQcAdwnp9e5HBfCFxiVkxIByMfGac6SwrCByNnPQnaiYn_988UKW7YVoqK4NK2kIJ405bz9kRWb8MMIRSTRskg0gYoQs9tCQGfD0QJWjJGk_Qqj2eDuH2pHresKELchjhe9hbbkajG021azpvPdq3t4PrYlqhiFajE-MRKwAR7Ey3_CfSHSoJ4mg2OBrhOVsA"); + + try{ + keyBindedTokenMatcherUtil.match(input, bindingCertificates, properties); + }catch (IdAuthenticationBusinessException e){ + Assert.assertEquals("IDA-MLC-009",e.getErrorCode()); + } + } + @Test + public void matchTestWithInValidCerts_thenFail() throws IdAuthenticationBusinessException { + ReflectionTestUtils.setField(keyBindedTokenMatcherUtil, "iatAdjSeconds", 30000000); + Map properties =new HashMap<>(); + Map bindingCertificates =new HashMap<>(); + Map input =new HashMap<>(); + input.put("individualId","individualId"); + input.put("type","type"); + input.put("format","jwt"); + input.put("token","eyJ0eXAiOiJKV1QiLCJ4NXQjUzI1NiI6IjBFSmtKMDYyWnZNZ0dKSk9BRVNYWFo1Tl9hamRDOG04Y0hPTXVKVVRGWUEiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2OTg5ODgyMTcsIm5iZiI6MTY5ODk4ODIxNywiZXhwIjoxNjk4OTg4ODIyLCJqdGkiOiJYZkpRaGVfU3RuNTNmaWc3YVV3V3MiLCJhdWQiOiJpZGEtYmluZGluZyIsInN1YiI6IjQxNTg2MTI2MDkiLCJpc3MiOiJwb3N0bWFuLWluamkifQ.bSqcJZlq5PyAExwPoww41OF-vBIyaADZ8OsXzA_7gtowNl0kChVAB11eIPEcjuFvYeQiSpQgNZsS2-w84ZBdiqh72kkJQLjN7ItMKNf-cekNRmG6XFf1os1vom7CwrguataoYvboiiXYw0WUfsZTmnhcOKC8XN3qAsB2YAyYEnBJBeKy5aCNAfJiOULTMrqAqcu-A1MA_wtAkaCJggiNxf1-5bJWjZYyQOkis0nHmbgWjzzThdd6TzMkLnUyNxzO2n1E9A19OJ2ZH0ZN1d46c8QBMsYmGX-Kz8B8GBDnDlwC4M5g4hmxuXCN6sBcVjAONl92LxI1htSZ6muv3xL1YQ"); + + try { + keyBindedTokenMatcherUtil.match(input, bindingCertificates, properties); + }catch (IdAuthenticationBusinessException e){ + Assert.assertEquals("IDA-KBT-001",e.getErrorCode()); + } + } + + @Test + public void matchTestWithValidCerts_thenFail() throws IdAuthenticationBusinessException { + ReflectionTestUtils.setField(keyBindedTokenMatcherUtil, "iatAdjSeconds", 300000000); + Map properties =new HashMap<>(); + Map bindingCertificates =new HashMap<>(); + bindingCertificates.put("D04264274EB666F32018924E0044975D9E4DFDA8DD0BC9BC70738CB895131580-TYPE","X509"); + Map input =new HashMap<>(); + input.put("individualId","individualId"); + input.put("type","type"); + input.put("format","jwt"); + input.put("token","eyJ0eXAiOiJKV1QiLCJ4NXQjUzI1NiI6IjBFSmtKMDYyWnZNZ0dKSk9BRVNYWFo1Tl9hamRDOG04Y0hPTXVKVVRGWUEiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2OTg5ODgyMTcsIm5iZiI6MTY5ODk4ODIxNywiZXhwIjoxNjk4OTg4ODIyLCJqdGkiOiJYZkpRaGVfU3RuNTNmaWc3YVV3V3MiLCJhdWQiOiJpZGEtYmluZGluZyIsInN1YiI6IjQxNTg2MTI2MDkiLCJpc3MiOiJwb3N0bWFuLWluamkifQ.bSqcJZlq5PyAExwPoww41OF-vBIyaADZ8OsXzA_7gtowNl0kChVAB11eIPEcjuFvYeQiSpQgNZsS2-w84ZBdiqh72kkJQLjN7ItMKNf-cekNRmG6XFf1os1vom7CwrguataoYvboiiXYw0WUfsZTmnhcOKC8XN3qAsB2YAyYEnBJBeKy5aCNAfJiOULTMrqAqcu-A1MA_wtAkaCJggiNxf1-5bJWjZYyQOkis0nHmbgWjzzThdd6TzMkLnUyNxzO2n1E9A19OJ2ZH0ZN1d46c8QBMsYmGX-Kz8B8GBDnDlwC4M5g4hmxuXCN6sBcVjAONl92LxI1htSZ6muv3xL1YQ"); + String certificateString="-----BEGIN CERTIFICATE-----\n" + + "MIIC6jCCAdKgAwIBAgIGAYuT8Am8MA0GCSqGSIb3DQEBCwUAMDYxNDAyBgNVBAMM\n" + + "K0FBNzBWbUQ2OGltaUU2NDhSdDBzRWNhc1N3VkJDNGxtbno4ZUFPZmRYQzgwHhcN\n" + + "MjMxMTAzMDY0NzQzWhcNMjQwODI5MDY0NzQzWjA2MTQwMgYDVQQDDCtBQTcwVm1E\n" + + "NjhpbWlFNjQ4UnQwc0VjYXNTd1ZCQzRsbW56OGVBT2ZkWEM4MIIBIjANBgkqhkiG\n" + + "9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsdSmcJ5o2Y/RL9DNEqDB//WLjWTTcroDzLit\n" + + "EELRoxw0/mjUuk02wSeq67bTxc4tobLM+8c/C6El5H+C9lLQwUDYbvuVli/iA+ko\n" + + "gDqkWNLA0mfZ+oEEKDa9IWo4Vf80yvgOD7h/JZBXnwtvci4jRSZzG5GNlSeIcnYS\n" + + "Kb5ZoM0NT1+oEk+MmBr1rfFajFgHo1xPI40RCzPXMZy09v9cdyIWSmasweQ2g1lK\n" + + "lTxjqXblKbN6LC3aQw6k9EUQ362yAnE2fV9jdrcEooQOFXfMYLt6RQQ2bPJ21oMZ\n" + + "ODFR54pyUODqvZ02w3rvLKJ3SgoLq++YCQ136+8qbj5zSVsp2QIDAQABMA0GCSqG\n" + + "SIb3DQEBCwUAA4IBAQAR4qLsRAmLc3iNcX2I+YXdHHh1Vmoje2xMELZwpGbXq9LE\n" + + "ozKEQxjSoidwmXwH/m7biH0/X7w1fFgT3ZxgaCVk3BWF+oS691+nQZceORbWYGDg\n" + + "fyyliMT/f25bIfqfqLnk1p6A6RyAGkU5ICPEchDKziX6X4AkbIYXGkcNwi7naSpo\n" + + "VULtcruR7Q3yCnXLJC4hyT7q8dp2GsmUiB/xP5jw2WtxwJZy60Syea0h2e8GEAmn\n" + + "K25CO5bPD/lEVhvwEzY2ZWg7ZMp1FE02fhFbSXpbF9BACy8UsEZ0Pcr0daWUtXTC\n" + + "5xbRhnAbNF0ixcSvZFcZvPhHDSnmnjABuHmuCUAQ\n" + + "-----END CERTIFICATE-----"; + Certificate certificate=convertToCertificate(certificateString); + Mockito.when(keymanagerUtil.convertToCertificate(Mockito.anyString())).thenReturn(certificate); + try{ + keyBindedTokenMatcherUtil.match(input, bindingCertificates, properties); + }catch (IdAuthenticationBusinessException e){ + Assert.assertEquals("IDA-KBT-003",e.getErrorCode()); + } + } + + public static Certificate convertToCertificate(String certData) { + try { + StringReader strReader = new StringReader(certData); + PemReader pemReader = new PemReader(strReader); + PemObject pemObject = pemReader.readPemObject(); + if (Objects.isNull(pemObject)) { + throw new RuntimeException("Invalid certificate"); + } + byte[] certBytes = pemObject.getContent(); + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + return certFactory.generateCertificate(new ByteArrayInputStream(certBytes)); + } catch (IOException | CertificateException e) { + throw new RuntimeException("Invalid certificate"); + } + } +} diff --git a/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/TokenEncoderUtilTest.java b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/TokenEncoderUtilTest.java new file mode 100644 index 00000000000..b4b89aa1404 --- /dev/null +++ b/authentication/authentication-common/src/test/java/io/mosip/authentication/common/service/util/TokenEncoderUtilTest.java @@ -0,0 +1,27 @@ +package io.mosip.authentication.common.service.util; + + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +public class TokenEncoderUtilTest { + + + + @Test + public void encodeBase58TestWithVaidDetails_thenPass(){ + String st="string"; + String result=TokenEncoderUtil.encodeBase58(st.getBytes()); + Assert.assertEquals("zVbyBrMk",result); + } + + @Test + public void encodeBase58TestWithNull_thenFail(){ + String st="string"; + String result=TokenEncoderUtil.encodeBase58(null); + } + +} diff --git a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/facade/VciFacadeImplTest.java b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/facade/VciFacadeImplTest.java new file mode 100644 index 00000000000..835294d8bec --- /dev/null +++ b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/facade/VciFacadeImplTest.java @@ -0,0 +1,179 @@ +package io.mosip.authentication.service.kyc.facade; + + + +import io.mosip.authentication.common.manager.IdAuthFraudAnalysisEventManager; +import io.mosip.authentication.common.service.entity.AutnTxn; +import io.mosip.authentication.common.service.entity.KycTokenData; +import io.mosip.authentication.common.service.helper.AuditHelper; +import io.mosip.authentication.common.service.helper.TokenValidationHelper; +import io.mosip.authentication.common.service.integration.TokenIdManager; +import io.mosip.authentication.common.service.repository.IdaUinHashSaltRepo; +import io.mosip.authentication.common.service.repository.KycTokenDataRepository; +import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; +import io.mosip.authentication.common.service.util.EnvUtil; +import io.mosip.authentication.common.service.util.TestObjectWithMetadata; +import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.authentication.core.indauth.dto.VciCredentialsDefinitionRequestDTO; +import io.mosip.authentication.core.indauth.dto.VciExchangeRequestDTO; +import io.mosip.authentication.core.partner.dto.*; +import io.mosip.authentication.core.spi.id.service.IdService; +import io.mosip.authentication.core.spi.partner.service.PartnerService; +import io.mosip.authentication.service.kyc.impl.VciServiceImpl; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.util.*; + +@RunWith(SpringRunner.class) +@Import(EnvUtil.class) +public class VciFacadeImplTest { + + @Autowired + EnvUtil env; + + @Mock + EnvUtil envMock; + + @Mock + IdService idService; + + /** The AuditHelper */ + @Mock + AuditHelper auditHelper; + + @Mock + IdaUinHashSaltRepo uinHashSaltRepo; + + @Mock + TokenIdManager tokenIdManager; + + @Mock + IdAuthSecurityManager securityManager; + + @Mock + PartnerService partnerService; + + @Mock + IdAuthFraudAnalysisEventManager fraudEventManager; + + @Mock + VciServiceImpl vciServiceImpl; + + @Mock + TokenValidationHelper tokenValidationHelper; + + @Mock + KycTokenDataRepository kycTokenDataRepo; + + @InjectMocks + VciFacadeImpl vciFacadeImpl; + + @Test + public void processVciExchangeTestWithInvalidDetails_ThenFail() throws IdAuthenticationBusinessException { + + VciExchangeRequestDTO vciExchangeRequestDTO = new VciExchangeRequestDTO(); + vciExchangeRequestDTO.setId("12345678901234567890123456789012"); + vciExchangeRequestDTO.setMetadata(new HashMap<>()) ; + vciExchangeRequestDTO.setRequestTime("2019-07-15T12:00:00.000Z"); + vciExchangeRequestDTO.setVcAuthToken("12345678901234567890123456789012"); + vciExchangeRequestDTO.setCredSubjectId("12345678901234567890123456789012"); + vciExchangeRequestDTO.setVcFormat("WLA"); + vciExchangeRequestDTO.setIndividualId("1234567890"); + vciExchangeRequestDTO.setIndividualIdType("UIN"); + + VciCredentialsDefinitionRequestDTO vciCredentialsDefinitionRequestDTO = new VciCredentialsDefinitionRequestDTO(); + vciCredentialsDefinitionRequestDTO.setContext(List.of("https://www.w3.org/2018/credentials/v1")); + vciCredentialsDefinitionRequestDTO.setType(List.of("VerifiableCredential")); + vciCredentialsDefinitionRequestDTO.setCredentialSubject(new HashMap<>()); + + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + + Map metaData=new HashMap<>(); + + try{ + vciFacadeImpl.processVciExchange(vciExchangeRequestDTO,"1234567890","12345",metaData,new TestObjectWithMetadata()); + }catch(IdAuthenticationBusinessException e){ + Assert.assertEquals("IDA-KYE-006",e.getErrorCode()); + } + } + + @Test + public void processVciExchangeTestWithInValidTxnDetails_ThenFail() throws IdAuthenticationBusinessException { + ReflectionTestUtils.setField(vciFacadeImpl, "tokenValidationHelper", tokenValidationHelper); + + VciExchangeRequestDTO vciExchangeRequestDTO = new VciExchangeRequestDTO(); + vciExchangeRequestDTO.setId("12345678901234567890123456789012"); + vciExchangeRequestDTO.setMetadata(new HashMap<>()) ; + vciExchangeRequestDTO.setRequestTime("2019-07-15T12:00:00.000Z"); + vciExchangeRequestDTO.setVcAuthToken("12345678901234567890123456789012"); + vciExchangeRequestDTO.setCredSubjectId("12345678901234567890123456789012"); + vciExchangeRequestDTO.setVcFormat("WLA"); + vciExchangeRequestDTO.setIndividualId("1234567890"); + vciExchangeRequestDTO.setIndividualIdType("UIN"); + vciExchangeRequestDTO.setTransactionID("12345"); + + VciCredentialsDefinitionRequestDTO vciCredentialsDefinitionRequestDTO = new VciCredentialsDefinitionRequestDTO(); + vciCredentialsDefinitionRequestDTO.setContext(List.of("https://www.w3.org/2018/credentials/v1")); + vciCredentialsDefinitionRequestDTO.setType(List.of("VerifiableCredential")); + vciCredentialsDefinitionRequestDTO.setCredentialSubject(new HashMap<>()); + + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + + Map metaData=new HashMap<>(); + + PartnerPolicyResponseDTO partnerPolicyResponseDTO = new PartnerPolicyResponseDTO(); + partnerPolicyResponseDTO.setMispPolicyId("1234567890"); + + MispPolicyDTO mispPolicyDTO = new MispPolicyDTO(); + mispPolicyDTO.setAllowKeyBindingDelegation(true); + mispPolicyDTO.setAllowKycRequestDelegation(true); + mispPolicyDTO.setAllowOTPRequestDelegation(true); + + PolicyDTO policyDTO = new PolicyDTO(); + + List listOfPolicy=new ArrayList<>(); + + AuthPolicy authPolicy=new AuthPolicy(); + authPolicy.setAuthType("OTP"); + authPolicy.setAuthSubType("OTP"); + authPolicy.setMandatory(false); + + listOfPolicy.add(authPolicy); + + policyDTO.setAllowedAuthTypes(listOfPolicy); + policyDTO.setAuthTokenType("OTP"); + + partnerPolicyResponseDTO.setPolicy(policyDTO); + partnerPolicyResponseDTO.setMispPolicy(mispPolicyDTO); + partnerPolicyResponseDTO.setPartnerId("1234567890"); + + KycTokenData kycTokenData = new KycTokenData(); + kycTokenData.setPsuToken("1234567890"); + + Mockito.when(securityManager.hash(Mockito.anyString())).thenReturn("1234567890"); + Mockito.when(tokenValidationHelper.findAndValidateIssuedToken("12345678901234567890123456789012","12345","12345","1234567890")).thenReturn(kycTokenData); + Mockito.when(partnerService.getPolicyForPartner(Mockito.anyString(),Mockito.anyString(),Mockito.anyMap())).thenReturn(Optional.of(partnerPolicyResponseDTO)); + Mockito.when(idService.getToken(Mockito.any())).thenReturn("token"); + Mockito.when(tokenIdManager.generateTokenId(Mockito.anyString(),Mockito.anyString())).thenReturn("1234567890"); + + EnvUtil.setAuthTokenRequired(true); + PartnerDTO partnerDTO= new PartnerDTO(); + partnerDTO.setPartnerId("12345"); + partnerDTO.setPartnerName("relyingPartyId"); + Mockito.when(partnerService.getPartner(Mockito.anyString(),Mockito.anyMap())).thenReturn(Optional.of(partnerDTO)); + try{ + vciFacadeImpl.processVciExchange(vciExchangeRequestDTO,"1234567890","12345",metaData,new TestObjectWithMetadata()); + }catch (Exception e){ + } + + } +} diff --git a/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/impl/VciServiceImplTest.java b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/impl/VciServiceImplTest.java new file mode 100644 index 00000000000..8ae4b80c7eb --- /dev/null +++ b/authentication/authentication-service/src/test/java/io/mosip/authentication/service/kyc/impl/VciServiceImplTest.java @@ -0,0 +1,347 @@ +package io.mosip.authentication.service.kyc.impl; + +import com.fasterxml.jackson.databind.ObjectMapper; +import foundation.identity.jsonld.ConfigurableDocumentLoader; +import foundation.identity.jsonld.JsonLDException; +import info.weboftrust.ldsignatures.LdProof; +import info.weboftrust.ldsignatures.canonicalizer.URDNA2015Canonicalizer; +import io.mosip.authentication.common.service.entity.CredSubjectIdStore; +import io.mosip.authentication.common.service.helper.IdInfoHelper; +import io.mosip.authentication.common.service.repository.CredSubjectIdStoreRepository; +import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager; +import io.mosip.authentication.common.service.util.EnvUtil; +import io.mosip.authentication.core.exception.IdAuthenticationBusinessException; +import io.mosip.authentication.core.indauth.dto.IdentityInfoDTO; +import io.mosip.authentication.core.indauth.dto.VciCredentialsDefinitionRequestDTO; +import io.mosip.authentication.core.indauth.dto.VciExchangeRequestDTO; +import io.mosip.authentication.service.kyc.util.VCSchemaProviderUtil; +import io.mosip.kernel.biometrics.entities.BIR; +import io.mosip.kernel.biometrics.spi.CbeffUtil; +import org.json.simple.JSONObject; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.util.ReflectionTestUtils; + +import java.io.IOException; +import java.security.GeneralSecurityException; +import java.util.*; + +@RunWith(SpringRunner.class) +@Import(EnvUtil.class) +public class VciServiceImplTest { + + @Mock + JSONObject vcContextJsonld; + + @Autowired + EnvUtil envUtil; + + @Mock + IdAuthSecurityManager securityManager; + + @Mock + CredSubjectIdStoreRepository csidStoreRepo; + + @Mock + LdProof.Builder builder; + + @Mock + URDNA2015Canonicalizer urdna2015Canonicalizer; + + @Mock + VCSchemaProviderUtil vcSchemaProviderUtil; + + /** The demo helper. */ + @Mock + IdInfoHelper idInfoHelper; + + @Mock + CbeffUtil cbeffUtil; + + @Mock + ObjectMapper objectMapper=new ObjectMapper(); + + @InjectMocks + VciServiceImpl vciServiceImpl; + + VciCredentialsDefinitionRequestDTO vciCredentialsDefinitionRequestDTO; + + VciExchangeRequestDTO vciExchangeRequestDTO; + + IdentityInfoDTO identityInfoDTO; + + List locale; + + Map> idInfo; + + String credSubjectId; + + + @Before + public void beforeTest(){ + + identityInfoDTO=new IdentityInfoDTO(); + identityInfoDTO.setLanguage("eng"); + identityInfoDTO.setValue("value"); + List list=new ArrayList<>(); + list.add(identityInfoDTO); + idInfo =new HashMap<>(); + idInfo.put("name",list); + + locale=new ArrayList<>(); + locale.add("eng"); + + vciExchangeRequestDTO = new VciExchangeRequestDTO(); + vciExchangeRequestDTO.setId("12345678901234567890123456789012"); + vciExchangeRequestDTO.setMetadata(new HashMap<>()) ; + vciExchangeRequestDTO.setRequestTime("2019-07-15T12:00:00.000Z"); + vciExchangeRequestDTO.setVcAuthToken("12345678901234567890123456789012"); + vciExchangeRequestDTO.setCredSubjectId("12345678901234567890123456789012"); + vciExchangeRequestDTO.setVcFormat("WLA"); + vciExchangeRequestDTO.setIndividualId("1234567890"); + vciExchangeRequestDTO.setIndividualIdType("UIN"); + + vciCredentialsDefinitionRequestDTO = new VciCredentialsDefinitionRequestDTO(); + vciCredentialsDefinitionRequestDTO.setContext(List.of("https://www.w3.org/2018/credentials/v1")); + vciCredentialsDefinitionRequestDTO.setType(List.of("VerifiableCredential")); + vciCredentialsDefinitionRequestDTO.setCredentialSubject(new HashMap<>()); + credSubjectId="12345:54321:ewogICAgImt0eSI6ICJSU0EiLAogICAgImUiOiAiQVFBQiIsCiAgICAidXNlIjogInNpZyIsCiAgICAia2lkIjogInBicy1GY1B6N1Jwbm42UUI1WG8xLWxrdVBEWHlxRlBZUzB5V296S0VpUjgiLAogICAgImFsZyI6ICJSUzI1NiIsCiAgICAibiI6ICJzSzhLTE55d0JoVVloYWhIREpTN0lPNkN2SkYxeTNmX0xsTEJvTV81eGFvcXVPckxDb084R0llaWJ1ai1YOWV0S3d1SkoycTdjdzRnTEJocXFOd2x3T2ZTOXZ2X1BnRTZkTTYtSDkxVVgtbGljQzh6YUFDSkdCV1N2TlVjSmtSNFJpOW5laGQ3NmRMSTJ5SDdlYVh3N0lRVERyMDVtSFFyR1ZaNVBVZTRMR3haZlVqcmxQUGttcTZfUTBIbk5RN1ZGTjVFLUxDejNvUWtKbHl4OTQyenhJdk5TV2V1enNMQU5xZWdSQzVWd3YtWlJtNmgxb1BNSWY1MThoZHdwaEhqeU5fRGs5djExYV8yT2VaNzd0T3Ria0RUaUxtamVLS1dTNXZldW1rOWMzTkw4OU00LS1yMFJMZ0Jrb3k1X0RMNHNmRXpSRnZYWVF0eHI4c3R1aURaRFEiCn0="; + + } + + @Test + public void addCredSubjectIdTestWithInvalidCredSubjectId_thenFail() throws IdAuthenticationBusinessException { + + try{ + vciServiceImpl.addCredSubjectId("12345:54321:MTIzNDU2Nzg5MA==","hash","123456789","12"); + }catch (IdAuthenticationBusinessException e){ + Assert.assertEquals("IDA-MLC-007",e.getErrorCode()); + } + } + + @Test + public void addCredSubjectIdTestWithValidDetailsAndWithoutSubIdList_thenPass() throws IdAuthenticationBusinessException { + vciServiceImpl.addCredSubjectId(credSubjectId,"hash","123456789","12"); + + } + + @Test + public void addCredSubjectIdTestWithValidDetailsWithSameVid_thenPass() throws IdAuthenticationBusinessException { + + List credSubjectIdList = new ArrayList<>(); + CredSubjectIdStore credSubjectIdStore=new CredSubjectIdStore(); + credSubjectIdStore.setCredSubjectId("12345"); + credSubjectIdStore.setId("12345"); + credSubjectIdStore.setIdVidHash("hash"); + credSubjectIdList.add(credSubjectIdStore); + credSubjectIdStore.setTokenId("token"); + Mockito.when(csidStoreRepo.findAllByCsidKeyHash(Mockito.anyString())).thenReturn(credSubjectIdList); + vciServiceImpl.addCredSubjectId(credSubjectId,"hash","token","12"); + + } + + @Test + public void addCredSubjectIdTestWithValidDetailsWithDiffSameVid_thenPass() throws IdAuthenticationBusinessException { + + List credSubjectIdList = new ArrayList<>(); + CredSubjectIdStore credSubjectIdStore=new CredSubjectIdStore(); + credSubjectIdStore.setCredSubjectId("12345"); + credSubjectIdStore.setId("12345"); + credSubjectIdStore.setIdVidHash("hash"); + credSubjectIdList.add(credSubjectIdStore); + credSubjectIdStore.setTokenId("token"); + Mockito.when(csidStoreRepo.findAllByCsidKeyHash(Mockito.anyString())).thenReturn(credSubjectIdList); + vciServiceImpl.addCredSubjectId(credSubjectId,"hashe","token","12"); + + } + + //TODO builder need to be fixed + @Test + public void buildVerifiableCredentialsTest() throws IdAuthenticationBusinessException, JsonLDException, GeneralSecurityException, IOException { + ReflectionTestUtils.setField(vciServiceImpl, "consentedIndividualAttributeName", "name"); + ReflectionTestUtils.setField(vciServiceImpl, "proofPurpose", "purpose"); + ReflectionTestUtils.setField(vciServiceImpl, "proofType", "proofType"); + ReflectionTestUtils.setField(vciServiceImpl,"verificationMethod","verificationMethod"); + ReflectionTestUtils.setField(vciServiceImpl,"confDocumentLoader",new ConfigurableDocumentLoader()); + Set allowedAttribute =new HashSet<>(); + allowedAttribute.add("name"); + + VciCredentialsDefinitionRequestDTO vciCredentialsDefinitionRequestDTO = new VciCredentialsDefinitionRequestDTO(); + vciCredentialsDefinitionRequestDTO.setContext(List.of("https://www.w3.org/2018/credentials/v1")); + vciCredentialsDefinitionRequestDTO.setType(List.of("VerifiableCredential")); + vciCredentialsDefinitionRequestDTO.setCredentialSubject(new HashMap<>()); + + + EnvUtil.setDateTimePattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + + // Create a mock of the LdProof.Builder class + LdProof.Builder builderMock = Mockito.mock(LdProof.Builder.class,"RETURNS_SELF"); + + Mockito.when(builderMock.defaultContexts(Mockito.anyBoolean())).thenReturn(builderMock); + Mockito.when(builderMock.defaultTypes(Mockito.anyBoolean())).thenReturn(builderMock); + Mockito.when(builderMock.type(Mockito.anyString())).thenReturn(builderMock); + Mockito.when(builderMock.created(Mockito.any())).thenReturn(builderMock); + Mockito.when(builderMock.proofPurpose("purpose")).thenReturn(builderMock); + Mockito.when(builderMock.verificationMethod(Mockito.any())).thenReturn(builderMock); + + + LdProof ldProofMock = Mockito.mock(LdProof.class); + Mockito.when(builderMock.build()).thenReturn(ldProofMock); + + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + Mockito.when( vcContextJsonld.get("context")).thenReturn(new Object()); + Mockito.when(urdna2015Canonicalizer.canonicalize(Mockito.any(),Mockito.any())).thenReturn(new byte[4]); + + try{ + vciServiceImpl.buildVerifiableCredentials(credSubjectId,"ldp_vc" ,idInfo, locale, allowedAttribute, vciExchangeRequestDTO,"pusutokdn"); + }catch (Exception e){} + + } + + @Test + public void buildVerifiableCredentialswithjwt_vc_jsonTest() throws IdAuthenticationBusinessException { + + Set allowedAttribute =new HashSet<>(); + allowedAttribute.add("name"); + + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + Mockito.when( vcContextJsonld.get("context")).thenReturn(new Object()); + + try{ + vciServiceImpl.buildVerifiableCredentials(credSubjectId,"jwt_vc_json" ,idInfo, locale, allowedAttribute, vciExchangeRequestDTO,"pusutokdn"); + }catch (Exception e){} + + } + + @Test + public void buildVerifiableCredentialswithjwt_vc_jsonldTest() throws IdAuthenticationBusinessException { + + Set allowedAttribute =new HashSet<>(); + allowedAttribute.add("name"); + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + Mockito.when( vcContextJsonld.get("context")).thenReturn(new Object()); + + try{ + vciServiceImpl.buildVerifiableCredentials(credSubjectId,"jwt_vc_json-ld" ,idInfo, locale, allowedAttribute, vciExchangeRequestDTO,"pusutokdn"); + }catch (Exception e){} + + } + + @Test + public void buildVerifiableCredentialsWithFaceTest() throws Exception { + ReflectionTestUtils.setField(vciServiceImpl, "consentedIndividualAttributeName", "name"); + ReflectionTestUtils.setField(vciServiceImpl, "proofPurpose", "purpose"); + ReflectionTestUtils.setField(vciServiceImpl, "proofType", "proofType"); + ReflectionTestUtils.setField(vciServiceImpl,"verificationMethod","verificationMethod"); + ReflectionTestUtils.setField(vciServiceImpl,"confDocumentLoader",new ConfigurableDocumentLoader()); + + Set allowedAttribute =new HashSet<>(); + allowedAttribute.add("face"); + + EnvUtil.setDateTimePattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + Mockito.when( vcContextJsonld.get("context")).thenReturn(new Object()); + Mockito.when(urdna2015Canonicalizer.canonicalize(Mockito.any(),Mockito.any())).thenReturn(new byte[4]); + + List birDataFromXMLType =new ArrayList<>(); + BIR bir=new BIR(); + bir.setBdb(new byte[4]); + birDataFromXMLType.add(bir); + Mockito.when(cbeffUtil.getBIRDataFromXMLType(Mockito.any(),Mockito.anyString())).thenReturn(birDataFromXMLType); + Map faceEntityInfoMap = new HashMap<>(); + faceEntityInfoMap.put("Face","face"); + Mockito.when(idInfoHelper.getIdEntityInfoMap(Mockito.any(),Mockito.anyMap(),Mockito.any())).thenReturn(faceEntityInfoMap); + try{ + vciServiceImpl.buildVerifiableCredentials(credSubjectId,"ldp_vc" ,idInfo, locale, allowedAttribute, vciExchangeRequestDTO,"pusutokdn"); + }catch (Exception e){} + + } + + @Test + public void buildVerifiableCredentialsWithIdScemaTest() throws Exception { + ReflectionTestUtils.setField(vciServiceImpl, "consentedIndividualAttributeName", "name"); + ReflectionTestUtils.setField(vciServiceImpl, "proofPurpose", "purpose"); + ReflectionTestUtils.setField(vciServiceImpl, "proofType", "proofType"); + ReflectionTestUtils.setField(vciServiceImpl,"verificationMethod","verificationMethod"); + ReflectionTestUtils.setField(vciServiceImpl,"confDocumentLoader",new ConfigurableDocumentLoader()); + IdentityInfoDTO identityInfoDTO=new IdentityInfoDTO(); + identityInfoDTO.setLanguage("eng"); + identityInfoDTO.setValue("value"); + List list=new ArrayList<>(); + list.add(identityInfoDTO); + Map> idInfo =new HashMap<>(); + idInfo.put("info",list); + + List locale=new ArrayList<>(); + locale.add("eng"); + + Set allowedAttribute =new HashSet<>(); + allowedAttribute.add("id"); + + EnvUtil.setDateTimePattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + Mockito.when( vcContextJsonld.get("context")).thenReturn(new Object()); + Mockito.when(urdna2015Canonicalizer.canonicalize(Mockito.any(),Mockito.any())).thenReturn(new byte[4]); + + + List idInfoHelperList = new ArrayList<>(); + idInfoHelperList.add("info"); + Mockito.when(idInfoHelper.getIdentityAttributesForIdName(Mockito.anyString())).thenReturn(idInfoHelperList); + try{ + vciServiceImpl.buildVerifiableCredentials(credSubjectId,"ldp_vc" ,idInfo, locale, allowedAttribute, vciExchangeRequestDTO,"pusutokdn"); + }catch (Exception e){} + + } + + + @Test + public void buildVerifiableCredentialsWithInfoListTest() throws Exception { + ReflectionTestUtils.setField(vciServiceImpl, "consentedIndividualAttributeName", "name"); + ReflectionTestUtils.setField(vciServiceImpl, "proofPurpose", "purpose"); + ReflectionTestUtils.setField(vciServiceImpl, "proofType", "proofType"); + ReflectionTestUtils.setField(vciServiceImpl,"verificationMethod","verificationMethod"); + ReflectionTestUtils.setField(vciServiceImpl,"confDocumentLoader",new ConfigurableDocumentLoader()); + IdentityInfoDTO identityInfoDTO=new IdentityInfoDTO(); + identityInfoDTO.setLanguage("eng"); + identityInfoDTO.setValue("value"); + List list=new ArrayList<>(); + list.add(identityInfoDTO); + identityInfoDTO=new IdentityInfoDTO(); + identityInfoDTO.setLanguage("hin"); + identityInfoDTO.setValue("value"); + list.add(identityInfoDTO); + Map> idInfo =new HashMap<>(); + idInfo.put("info",list); + + List locale=new ArrayList<>(); + locale.add("eng"); + + Set allowedAttribute =new HashSet<>(); + allowedAttribute.add("id"); + + EnvUtil.setDateTimePattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX"); + + vciExchangeRequestDTO.setCredentialsDefinition(vciCredentialsDefinitionRequestDTO); + Mockito.when( vcContextJsonld.get("context")).thenReturn(new Object()); + Mockito.when(urdna2015Canonicalizer.canonicalize(Mockito.any(),Mockito.any())).thenReturn(new byte[4]); + + + List idInfoHelperList = new ArrayList<>(); + idInfoHelperList.add("info"); + Mockito.when(idInfoHelper.getIdentityAttributesForIdName(Mockito.anyString())).thenReturn(idInfoHelperList); + try{ + vciServiceImpl.buildVerifiableCredentials(credSubjectId,"ldp_vc" ,idInfo, locale, allowedAttribute, vciExchangeRequestDTO,"pusutokdn"); + }catch (Exception e){} + + } +} diff --git a/authentication/esignet-integration-impl/src/test/java/io/mosip/authentication/esignet/integration/service/IdaVCIssuancePluginImplTest.java b/authentication/esignet-integration-impl/src/test/java/io/mosip/authentication/esignet/integration/service/IdaVCIssuancePluginImplTest.java index b37730feed7..fe3bb52f8c6 100644 --- a/authentication/esignet-integration-impl/src/test/java/io/mosip/authentication/esignet/integration/service/IdaVCIssuancePluginImplTest.java +++ b/authentication/esignet-integration-impl/src/test/java/io/mosip/authentication/esignet/integration/service/IdaVCIssuancePluginImplTest.java @@ -81,7 +81,7 @@ public void getVerifiableCredentialWithLinkedDataProof_withValidDetails_thenPass oidcTransaction.setKycToken("kycToken"); oidcTransaction.setAuthTransactionId("authTransactionId"); oidcTransaction.setRelyingPartyId("relyingPartyId"); - oidcTransaction.setClaimsLocales(new String[]{"eng"}); + oidcTransaction.setClaimsLocales(new String[]{"en-US", "en", "en-CA", "fr-FR", "fr-CA"}); IdaResponseWrapper> mockResponseWrapper = new IdaResponseWrapper<>(); IdaVcExchangeResponse mockResponse = new IdaVcExchangeResponse<>();