From 7d94c7fda37370e4c304c74e8887451464e90e5f Mon Sep 17 00:00:00 2001 From: Harsh Vardhan Date: Wed, 31 Jul 2024 19:49:50 +0530 Subject: [PATCH] [INJICERT-317] rename credential.type to MockVerifiableCredential Signed-off-by: Harsh Vardhan --- .../service/MockVCIssuancePlugin.java | 4 ++-- .../service/MockVCIssuancePluginTest.java | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/mock-certify-plugin/src/main/java/io.mosip.certify.mock.integration/service/MockVCIssuancePlugin.java b/mock-certify-plugin/src/main/java/io.mosip.certify.mock.integration/service/MockVCIssuancePlugin.java index 2f42503..22b7aef 100644 --- a/mock-certify-plugin/src/main/java/io.mosip.certify.mock.integration/service/MockVCIssuancePlugin.java +++ b/mock-certify-plugin/src/main/java/io.mosip.certify.mock.integration/service/MockVCIssuancePlugin.java @@ -127,7 +127,7 @@ private JsonLDObject buildJsonLDWithLDProof(String accessTokenHash) Map verCredJsonObject = new HashMap<>(); verCredJsonObject.put("@context", vcCredentialContexts); - verCredJsonObject.put("type", Arrays.asList("VerifiableCredential", "MOSIPVerifiableCredential")); + verCredJsonObject.put("type", Arrays.asList("VerifiableCredential", "MockVerifiableCredential")); verCredJsonObject.put("id", "urn:uuid:3978344f-8596-4c3a-a978-8fcaba3903c5"); verCredJsonObject.put("issuer", "did:example:123456789"); verCredJsonObject.put("issuanceDate", getUTCDateTime()); @@ -241,4 +241,4 @@ public VCResult getVerifiableCredential(VCRequestDto vcRequestDto, Strin public OIDCTransaction getUserInfoTransaction(String accessTokenHash) { return cacheManager.getCache(USERINFO_CACHE).get(accessTokenHash, OIDCTransaction.class); } -} \ No newline at end of file +} diff --git a/mock-certify-plugin/src/test/java/io/mosip/certify/mock/integration/service/MockVCIssuancePluginTest.java b/mock-certify-plugin/src/test/java/io/mosip/certify/mock/integration/service/MockVCIssuancePluginTest.java index 1164642..b4c91fe 100644 --- a/mock-certify-plugin/src/test/java/io/mosip/certify/mock/integration/service/MockVCIssuancePluginTest.java +++ b/mock-certify-plugin/src/test/java/io/mosip/certify/mock/integration/service/MockVCIssuancePluginTest.java @@ -1,9 +1,9 @@ package io.mosip.certify.mock.integration.service; +import foundation.identity.jsonld.JsonLDObject; import io.mosip.certify.api.dto.VCRequestDto; import io.mosip.certify.api.dto.VCResult; import io.mosip.certify.api.exception.VCIExchangeException; -import io.mosip.certify.core.dto.ParsedAccessToken; import io.mosip.esignet.core.dto.OIDCTransaction; import io.mosip.kernel.signature.dto.JWTSignatureResponseDto; import io.mosip.kernel.signature.service.SignatureService; @@ -21,6 +21,7 @@ import org.springframework.test.util.ReflectionTestUtils; import java.util.Arrays; +import java.util.List; import java.util.Map; import static org.mockito.ArgumentMatchers.any; @@ -63,7 +64,7 @@ public void setUp() { vcRequestDto.setFormat("ldp_vc"); vcRequestDto.setContext(Arrays.asList("context1","context2")); - vcRequestDto.setType(Arrays.asList("VerifiableCredential")); + vcRequestDto.setType(Arrays.asList("VerifiableCredential", "MockVerifiableCredential")); vcRequestDto.setCredentialSubject(Map.of("subject1","subject1","subject2","subject2")); Mockito.when(cacheManager.getCache(Mockito.anyString())).thenReturn(cache); @@ -88,4 +89,17 @@ public void getVerifiableCredentialWithLinkedDataProof_withoutSignatureService_t Assert.assertEquals("vci_exchange_failed",e.getMessage()); } } + + @Test + public void getVerifiableCredentialWithLinkedDataProof_withValidCredentialType() throws VCIExchangeException { + JWTSignatureResponseDto jwtSignatureResponseDto = new JWTSignatureResponseDto(); + jwtSignatureResponseDto.setJwtSignedData("test-jwt"); + Mockito.when(signatureService.jwtSign(any())).thenReturn(jwtSignatureResponseDto); + VCResult vcResult = mockVCIssuancePlugin.getVerifiableCredentialWithLinkedDataProof(vcRequestDto,"holderId",Map.of("accessTokenHash","ACCESS_TOKEN_HASH","client_id","CLIENT_ID")); + Assert.assertNotNull(vcResult.getCredential()); + JsonLDObject credential = (JsonLDObject) vcResult.getCredential(); + Assert.assertNotNull(credential.getTypes()); + List expectedType = Arrays.asList("VerifiableCredential", "MockVerifiableCredential"); + Assert.assertEquals(expectedType, credential.getTypes()); + } }