diff --git a/certify-core/src/main/java/io/mosip/certify/core/constants/SignatureAlg.java b/certify-core/src/main/java/io/mosip/certify/core/constants/SignatureAlg.java index af68794f..b5903d77 100644 --- a/certify-core/src/main/java/io/mosip/certify/core/constants/SignatureAlg.java +++ b/certify-core/src/main/java/io/mosip/certify/core/constants/SignatureAlg.java @@ -1,8 +1,15 @@ package io.mosip.certify.core.constants; +/** + * SignatureAlg is the constants file of supported VC sign algorithms. + * TODO(later): convert this into a structure such that it enables + * consumers to choose VC sign algos with + */ public class SignatureAlg { // LinkedDataSignature Algorithms - public static final String RSA_SIGNATURE_2018 = "RsaSignature2018"; + public static final String RSA_SIGNATURE_SUITE = "RsaSignature2018"; - // RS256, PS256, ES256 + public static final String ED25519_SIGNATURE_SUITE = "Ed25519Signature2018"; + + // RS256, PS256, ES256 --> JWSAlgorithm.RS256.getName(); } diff --git a/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateData.java b/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateData.java index e12ee4fa..21ce3891 100644 --- a/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateData.java +++ b/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateData.java @@ -3,25 +3,27 @@ import jakarta.persistence.Entity; import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Data; +import lombok.*; import jakarta.validation.constraints.NotBlank; -import lombok.NoArgsConstructor; import java.io.Serializable; import java.util.Objects; -@Data @Entity @NoArgsConstructor -@AllArgsConstructor @IdClass(TemplateId.class) public class TemplateData { @NotBlank(message = "Template is mandatory") + @Getter + @Setter private String template; @Id + @Getter + @Setter private String context; @Id + @Getter + @Setter private String credentialType; } diff --git a/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateId.java b/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateId.java index b726c955..ef472d04 100644 --- a/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateId.java +++ b/certify-core/src/main/java/io/mosip/certify/core/entity/TemplateId.java @@ -1,16 +1,18 @@ package io.mosip.certify.core.entity; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; + import java.io.Serializable; import java.util.Objects; -@Data -@AllArgsConstructor @NoArgsConstructor +@AllArgsConstructor public class TemplateId implements Serializable { + @Getter + @Setter private String context; + @Getter + @Setter private String credentialType; @Override diff --git a/certify-core/src/test/java/io/mosip/certify/core/templating/VelocityTemplatingEngineImplTest.java b/certify-core/src/test/java/io/mosip/certify/core/templating/VelocityTemplatingEngineImplTest.java index 6c056c21..902c178d 100644 --- a/certify-core/src/test/java/io/mosip/certify/core/templating/VelocityTemplatingEngineImplTest.java +++ b/certify-core/src/test/java/io/mosip/certify/core/templating/VelocityTemplatingEngineImplTest.java @@ -1,22 +1,35 @@ package io.mosip.certify.core.templating; +import io.mosip.certify.core.repository.TemplateRepository; import junit.framework.TestCase; +import lombok.SneakyThrows; import org.apache.velocity.Template; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; +import org.json.JSONArray; import org.junit.Before; import org.junit.Test; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import java.io.ByteArrayInputStream; +import java.io.InputStream; import java.io.StringWriter; +import java.nio.charset.StandardCharsets; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +@Component public class VelocityTemplatingEngineImplTest extends TestCase { private VelocityEngine engine; private final Map templateCache = new ConcurrentHashMap<>(); + @MockBean + private TemplateRepository templateRepository; @Before public void setUp() throws Exception { @@ -24,19 +37,52 @@ public void setUp() throws Exception { engine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath"); engine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName()); engine.setProperty(RuntimeConstants.RUNTIME_LOG_LOGSYSTEM_CLASS, "org.apache.velocity.runtime.log.NullLogChute"); + engine.setProperty(RuntimeConstants.INPUT_ENCODING, "UTF-8"); + engine.setProperty(RuntimeConstants.OUTPUT_ENCODING, "UTF-8"); engine.init(); } + @SneakyThrows @Test public void testTemplating() { // 1. setup template - Template t = engine.getTemplate("SchoolTemplate.vm"); + Template t = engine.getTemplate("MockCredential.vm"); assert t != null; - Map templateInput = new HashMap<>(); VelocityContext c = new VelocityContext(); StringWriter writer = new StringWriter(); engine.evaluate(c, writer, "SchoolTemplateTest", t.toString()); String out = writer.toString(); - + Map res = new RestTemplate().getForObject( + "https://api.dev1.mosip.net/v1/mock-identity-system/identity/34455445765", + HashMap.class); + res = (Map) res.get("response"); + Map ret = new HashMap<>(); + ret.put("vcVer", "VC-V1"); + ret.put("name", res.get("name")); + ret.put("fullName", res.get("fullName")); + ret.put("gender", res.get("gender")); + ret.put("dateOfBirth", res.get("dateOfBirth")); + ret.put("email", res.get("email")); + ret.put("UIN", "34455445765"); + ret.put("phone", res.get("phone")); + ret.put("addressLine1", res.get("streetAddress")); + ret.put("province", res.get("locality")); + ret.put("region", res.get("region")); + ret.put("postalCode", res.get("postalCode")); + ret.put("face", res.get("encodedPhoto")); + Map finalTemplate = new HashMap<>(); + for (String key : ret.keySet()) { + Object value = ret.get(key); + if (value instanceof List) { + finalTemplate.put(key, new JSONArray((List) value)); + } else if (value instanceof JSONArray) { + finalTemplate.put(key, new JSONArray(value)); + } else { + finalTemplate.put(key, value); + } + } + VelocityContext context = new VelocityContext(finalTemplate); + InputStream is = new ByteArrayInputStream(t.toString().getBytes(StandardCharsets.UTF_8)); + t.merge(context, writer); } } \ No newline at end of file diff --git a/certify-core/src/test/resources/MockCredential.vm b/certify-core/src/test/resources/MockCredential.vm new file mode 100644 index 00000000..61e55277 --- /dev/null +++ b/certify-core/src/test/resources/MockCredential.vm @@ -0,0 +1,25 @@ +{ + "@context": [ + "https://www.w3.org/ns/credentials/v2", + "https://schema.org" + ], + "issuer": "${issuer}", + "type": ["VerifiableCredential", "MockVerifiableCredential"], + "validFrom": "${validFrom}", + "validUntil": "${validUntil}", + "credentialSubject": { + "gender": ${gender}, + "postalCode": ${postalCode}, + "fullName": ${fullName}, + "dateOfBirth": "${dateOfBirth}", + "province": ${province}, + "phone": "${phone}", + "addressLine1": ${addressLine1}, + "region": ${region}, + "vcVer": "${vcVer}", + "UIN": ${UIN}, + "email": "${email}", + "id": "${id}", + "face": "${face}" + } +} diff --git a/certify-service/src/main/java/io/mosip/certify/CertifyServiceApplication.java b/certify-service/src/main/java/io/mosip/certify/CertifyServiceApplication.java index 2683923d..c6d89a31 100644 --- a/certify-service/src/main/java/io/mosip/certify/CertifyServiceApplication.java +++ b/certify-service/src/main/java/io/mosip/certify/CertifyServiceApplication.java @@ -14,7 +14,6 @@ @EnableAsync @EnableCaching -@EnableJpaRepositories @SpringBootApplication(scanBasePackages = "io.mosip.certify,"+ "io.mosip.certify.core.*," + "io.mosip.kernel.crypto," + diff --git a/certify-service/src/main/java/io/mosip/certify/config/AppConfig.java b/certify-service/src/main/java/io/mosip/certify/config/AppConfig.java index 80ce6027..279ea110 100644 --- a/certify-service/src/main/java/io/mosip/certify/config/AppConfig.java +++ b/certify-service/src/main/java/io/mosip/certify/config/AppConfig.java @@ -30,7 +30,7 @@ import org.springframework.web.client.RestTemplate; @Configuration -@EnableJpaRepositories(basePackages = {"io.mosip.kernel.keymanagerservice.repository"}) +@EnableJpaRepositories(basePackages = {"io.mosip.kernel.keymanagerservice.repository", "io.mosip.certify.core.repository"}) @EntityScan(basePackages = {"io.mosip.kernel.keymanagerservice.entity, io.mosip.certify.core.entity"}) @Slf4j public class AppConfig implements ApplicationRunner { diff --git a/certify-service/src/main/java/io/mosip/certify/services/KeymanagerLibSigner.java b/certify-service/src/main/java/io/mosip/certify/services/KeymanagerLibSigner.java index b14cc878..c9390392 100644 --- a/certify-service/src/main/java/io/mosip/certify/services/KeymanagerLibSigner.java +++ b/certify-service/src/main/java/io/mosip/certify/services/KeymanagerLibSigner.java @@ -36,12 +36,13 @@ public VCResult perform(String templatedVC, Map ke VCResult VC = null; JsonLDObject j = JsonLDObject.fromJson(templatedVC); j.setDocumentLoader(null); + // NOTE: other aspects can be configured via keyMgrInput map Date validFrom = Date .from(LocalDateTime .parse((String) j.getJsonObject().get(VCDM2Constants.VALID_FROM), DateTimeFormatter.ofPattern(Constants.UTC_DATETIME_PATTERN)) .atZone(ZoneId.systemDefault()).toInstant()); - LdProof vcLdProof = LdProof.builder().defaultContexts(false).defaultTypes(false).type(SignatureAlg.RSA_SIGNATURE_2018) + LdProof vcLdProof = LdProof.builder().defaultContexts(false).defaultTypes(false).type(SignatureAlg.RSA_SIGNATURE_SUITE) .created(validFrom).proofPurpose(VCDM2Constants.ASSERTION_METHOD) .verificationMethod(URI.create("https://vharsh.github.io/DID/mock-public-key.json")) // ^^ Why is this pointing to JWKS URL of eSignet?? diff --git a/certify-service/src/main/java/io/mosip/certify/services/templating/VelocityTemplatingEngineImpl.java b/certify-service/src/main/java/io/mosip/certify/services/templating/VelocityTemplatingEngineImpl.java index 3ff025a5..f0116240 100644 --- a/certify-service/src/main/java/io/mosip/certify/services/templating/VelocityTemplatingEngineImpl.java +++ b/certify-service/src/main/java/io/mosip/certify/services/templating/VelocityTemplatingEngineImpl.java @@ -1,16 +1,19 @@ package io.mosip.certify.services.templating; import java.io.*; -import java.nio.charset.StandardCharsets; import java.util.*; - import io.mosip.certify.api.spi.VCFormatter; +import io.mosip.certify.core.constants.VCDM2Constants; import io.mosip.certify.core.repository.TemplateRepository; import jakarta.annotation.PostConstruct; +import lombok.SneakyThrows; import org.apache.velocity.VelocityContext; import org.apache.velocity.app.VelocityEngine; import org.apache.velocity.runtime.RuntimeConstants; +import org.apache.velocity.tools.generic.DateTool; +import org.json.JSONArray; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @Service @@ -20,12 +23,8 @@ public class VelocityTemplatingEngineImpl implements VCFormatter { Map templateCache; @Autowired TemplateRepository templateRepository; - // DATA to be fetched from DB - - @Autowired - public void setTemplateRepository(TemplateRepository templateRepository) { - this.templateRepository = templateRepository; - } + @Value("${mosip.certify.vcformat.vc.expiry:true}") + boolean shouldHaveDates; @PostConstruct public void initialize() { @@ -54,15 +53,33 @@ public void initialize() { * internal work such as locating the appropriate template * @return templated VC as a String */ + @SneakyThrows @Override public String format(Map templateInput, Map defaultSettings) { // TODO: Isn't template name becoming too complex with VC_CONTEXTS & CREDENTIAL_TYPES both? String templateName = defaultSettings.get("templateName").toString(); String t = templateCache.get(templateName); StringWriter writer = new StringWriter(); + // 1. Prepare map + Map finalTemplate = new HashMap<>(); + for (String key : templateInput.keySet()) { + Object value = templateInput.get(key); + if (value instanceof List) { + // TODO(problem area): handle field values with unescaped JSON + // reserved literals such as " or , + // (Q) Should Object always be a JSONObject? + finalTemplate.put(key, new JSONArray((List) value)); + } else { + finalTemplate.put(key, value); + } + } + if (shouldHaveDates && !(templateInput.containsKey(VCDM2Constants.VALID_FROM) + && templateInput.containsKey(VCDM2Constants.VALID_UNITL))) { + templateInput.put("_dateTool", new DateTool()); + templateInput.put(VCDM2Constants.VALID_FROM, "$now"); + templateInput.put(VCDM2Constants.VALID_UNITL, "$now+3"); + } VelocityContext context = new VelocityContext(templateInput); - // TODO: Check config for templateName.* fields and apply those configs as well, e.g. auto-fill validFrom & validUntil - InputStream is = new ByteArrayInputStream(t.toString().getBytes(StandardCharsets.UTF_8)); engine.evaluate(context, writer, /*logTag */ templateName,t.toString()); return writer.toString(); } diff --git a/certify-service/src/main/java/io/mosip/certify/utils/CredentialUtils.java b/certify-service/src/main/java/io/mosip/certify/utils/CredentialUtils.java index 0a3894a1..b543fa43 100644 --- a/certify-service/src/main/java/io/mosip/certify/utils/CredentialUtils.java +++ b/certify-service/src/main/java/io/mosip/certify/utils/CredentialUtils.java @@ -2,6 +2,10 @@ import io.mosip.certify.api.dto.VCRequestDto; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + public class CredentialUtils { // returns true for VC 2.0 VCI requests public static boolean isVC2_0Request(VCRequestDto r) { @@ -15,4 +19,19 @@ public static boolean isNextGenPluginRequest(VCRequestDto r) { // TODO: use the Host header + credential.type return true; } + + /** + * get the template name for a VCRequest for VCFormatter lib + * @param vcRequestDto + * @return + */ + public static String getTemplateName(VCRequestDto vcRequestDto) { + List c = new ArrayList<>(vcRequestDto.getContext()); + List t = new ArrayList<>(vcRequestDto.getType()); + Collections.sort(c); + Collections.sort(t); + String contextKey = String.join(",", c); + String typeKey = String.join(",", t); + return String.join(":", typeKey, contextKey); + } } diff --git a/certify-service/src/main/resources/application-local.properties b/certify-service/src/main/resources/application-local.properties index 801f8f6b..db7a066f 100644 --- a/certify-service/src/main/resources/application-local.properties +++ b/certify-service/src/main/resources/application-local.properties @@ -14,7 +14,7 @@ mosip.certify.security.ignore-auth-urls=/actuator/**,**/error,**/swagger-ui/**,\ ## ------------------------------------------ Discovery openid-configuration ------------------------------------------- -mosipbox.public.url=http://localhost:8090 +mosipbox.public.url=https://injicertify.qa-inji.mosip.net mosip.certify.discovery.issuer-id=${mosipbox.public.url}${server.servlet.path} ##--------------change this later--------------------------------- @@ -22,11 +22,11 @@ mosip.certify.supported.jwt-proof-alg={'RS256','PS256'} ## ---------------------------------------------- VCI ------------------------------------------------------------------ ##----- These are properties for any oauth resource server providing jwk------------### -mosip.certify.identifier=http://localhost:8090 +mosip.certify.identifier=https://injicertify.qa-inji.mosip.net mosip.certify.authn.filter-urls={ '${server.servlet.path}/issuance/credential', '${server.servlet.path}/issuance/vd12/credential', '${server.servlet.path}/issuance/vd11/credential'} mosip.certify.authn.issuer-uri=http://localhost:8088/v1/esignet mosip.certify.authn.jwk-set-uri=http://localhost:8088/v1/esignet/oauth/.well-known/jwks.json -mosip.certify.authn.allowed-audiences={ '${mosipbox.public.url}${server.servlet.path}/issuance/credential', 'http://localhost:8088/v1/esignet/vci/credential' } +mosip.certify.authn.allowed-audiences={ '${mosipbox.public.url}${server.servlet.path}/issuance/credential', 'http://localhost:8088/v1/esignet/vci/credential', 'https://injicertify.qa-inji.mosip.net' } mosip.certify.key-values={\ 'v11' : {\ @@ -159,12 +159,12 @@ mosip.certify.key-values={\ 'credential_configurations_supported' : { \ "InsuranceCredential" : {\ 'format': 'ldp_vc',\ - 'scope' : 'sunbird_rc_insurance_vc_ldp',\ + 'scope' : 'sample_vc_ldp',\ 'cryptographic_binding_methods_supported': {'did:jwk'},\ 'credential_signing_alg_values_supported': {'Ed25519Signature2020'},\ 'proof_types_supported': {'jwt': {'proof_signing_alg_values_supported': {'RS256', 'PS256'}}},\ 'credential_definition': {\ - 'type': {'VerifiableCredential','InsuranceCredential'},\ + 'type': {'VerifiableCredential','MockVerifiableCredential'},\ 'credentialSubject': {\ 'fullName': {'display': {{'name': 'Name','locale': 'en'}}}, \ 'mobile': {'display': {{'name': 'Phone Number','locale': 'en'}}},\ @@ -187,7 +187,7 @@ mosip.certify.key-values={\ },\ "LifeInsuranceCredential":{\ 'format': 'ldp_vc',\ - 'scope' : 'life_insurance_vc_ldp',\ + 'scope' : 'sample_vc_ldp',\ 'cryptographic_binding_methods_supported': {'did:jwk'},\ 'credential_signing_alg_values_supported': {'Ed25519Signature2020'},\ 'proof_types_supported': {'jwt': {'proof_signing_alg_values_supported': {'RS256', 'ES256'}}},\ @@ -235,6 +235,7 @@ mosip.certify.key-values={\ #mosip.certify.authenticator.ida.secret-key=client-secret-key #mosip.certify.authenticator.ida.app-id=ida +mosip.certify.vcformat.vc.expiry=true ## ------------------------------------------- Mock ID Integration properties ------------------------------------------------------------ mosip.certify.integration.scan-base-package=io.mosip.certify.mock.integration @@ -252,11 +253,11 @@ mosip.certify.cache.security.secretkey.reference-id=TRANSACTION_CACHE mosip.certify.cache.security.algorithm-name=AES/ECB/PKCS5Padding #spring.cache.type=redis -#spring.data.redis.host=localhost -#spring.data.redis.port=6379 +spring.data.redis.host=localhost +spring.data.redis.port=6379 #spring.data.redis.password=eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81 -spring.cache.type=simple +spring.cache.type=redis spring.cache.cache-names=${mosip.certify.cache.names} management.health.redis.enabled=false @@ -353,7 +354,7 @@ crypto.PrependThumbprint.enable=true ##----------------------------------------- Database properties -------------------------------------------------------- mosip.certify.database.hostname=localhost -mosip.certify.database.port=5456 +mosip.certify.database.port=5432 spring.datasource.url=jdbc:postgresql://${mosip.certify.database.hostname}:${mosip.certify.database.port}/inji_certify?currentSchema=certify spring.datasource.username=postgres spring.datasource.password=postgres diff --git a/certify-service/src/test/java/io/mosip/certify/controller/VCIssuanceControllerTest.java b/certify-service/src/test/java/io/mosip/certify/controller/VCIssuanceControllerTest.java index 12bafee5..d88898d7 100644 --- a/certify-service/src/test/java/io/mosip/certify/controller/VCIssuanceControllerTest.java +++ b/certify-service/src/test/java/io/mosip/certify/controller/VCIssuanceControllerTest.java @@ -3,6 +3,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import foundation.identity.jsonld.JsonLDObject; import io.mosip.certify.api.spi.AuditPlugin; +import io.mosip.certify.api.spi.DataProviderPlugin; +import io.mosip.certify.api.spi.VCFormatter; +import io.mosip.certify.api.spi.VCSigner; import io.mosip.certify.core.constants.ErrorConstants; import io.mosip.certify.core.dto.*; import io.mosip.certify.core.exception.InvalidRequestException; @@ -37,10 +40,18 @@ public class VCIssuanceControllerTest { @MockBean AuditPlugin auditWrapper; - @MockBean ParsedAccessToken parsedAccessToken; + @MockBean + DataProviderPlugin dataProviderPlugin; + + @MockBean + VCFormatter vcFormatter; + + @MockBean + VCSigner vcSigner; + @MockBean VCIssuanceService vcIssuanceService; diff --git a/certify-service/src/test/java/io/mosip/certify/services/KeymanagerLibSignerTest.java b/certify-service/src/test/java/io/mosip/certify/services/KeymanagerLibSignerTest.java new file mode 100644 index 00000000..c2df75fa --- /dev/null +++ b/certify-service/src/test/java/io/mosip/certify/services/KeymanagerLibSignerTest.java @@ -0,0 +1,63 @@ +package io.mosip.certify.services; + +import com.nimbusds.jose.JWSAlgorithm; +import foundation.identity.jsonld.JsonLDObject; +import io.mosip.certify.api.dto.VCResult; +import io.mosip.certify.core.constants.Constants; +import io.mosip.certify.core.constants.SignatureAlg; +import io.mosip.kernel.signature.dto.JWTSignatureResponseDto; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import io.mosip.kernel.signature.service.SignatureService; +import com.fasterxml.jackson.databind.JsonNode; // Assuming JsonLDObject extends JsonNode + +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; + +public class KeymanagerLibSignerTest { + + @Mock + private SignatureService signatureService; + private KeymanagerLibSigner signer; + + @Before + public void setup() { + + } + + @Test + public void testPerformSuccess() throws Exception { + // Mock Templated VC and Key Manager Input + String templatedVC = """ + {"@context":["https://www.w3.org/ns/credentials/v2","https://www.w3.org/ns/credentials/examples/v2"],"type":["VerifiableCredential","MyPrototypeCredential"],"credentialSubject":{"mySubjectProperty":"mySubjectValue"}} + """; + Map keyMgrInput = new HashMap<>(); + keyMgrInput.put("pubKey", "https://example.com/pub-key.json"); + keyMgrInput.put("vcSigner", SignatureAlg.RSA_SIGNATURE_SUITE); + keyMgrInput.put("keyType", JWSAlgorithm.RS256.getName()); + keyMgrInput.put("keyManagerAppId", Constants.CERTIFY_MOCK_RSA); + keyMgrInput.put("keyManagerRefID", ""); + + // Mock Signature Service Response + JWTSignatureResponseDto jwsSignedData = new JWTSignatureResponseDto(); + jwsSignedData.setJwtSignedData("mocked-jws"); + when(signatureService.jwsSign(any())).thenReturn(jwsSignedData); + // Perform the test + VCResult vcResult = signer.perform(templatedVC, keyMgrInput); + + // Assertions + Assert.assertNotNull(vcResult); + JsonLDObject credential = vcResult.getCredential(); + Assert.assertNotNull(credential); + Assert.assertTrue(credential.getJsonObject.("proof")); + JsonNode proof = credential.get("proof"); + Assert.assertTrue(proof.has("jws")); + Assert.assertEquals("mocked-jws", proof.get("jws").asText()); + } +} \ No newline at end of file diff --git a/certify-service/src/test/java/io/mosip/certify/utils/CredentialUtilsTest.java b/certify-service/src/test/java/io/mosip/certify/utils/CredentialUtilsTest.java new file mode 100644 index 00000000..4057295a --- /dev/null +++ b/certify-service/src/test/java/io/mosip/certify/utils/CredentialUtilsTest.java @@ -0,0 +1,30 @@ +package io.mosip.certify.utils; + +import io.mosip.certify.api.dto.VCRequestDto; +import junit.framework.TestCase; +import org.junit.jupiter.params.provider.ArgumentsSource; + +import java.util.List; + +public class CredentialUtilsTest extends TestCase { + + public void testIsVC2_0Request_VCIssuancePluginRequest() { + VCRequestDto request = new VCRequestDto(); + request.setContext(List.of("https://www.w3.org/2018/credentials/v1", "https://schema.org")); + assertFalse(CredentialUtils.isVC2_0Request(request)); + } + + public void testIsVC2_0Request_DataProviderPluginRequest() { + VCRequestDto request = new VCRequestDto(); + request.setContext(List.of("https://www.w3.org/ns/credentials/v2", "https://schema.org")); + assertTrue(CredentialUtils.isVC2_0Request(request)); + } + + public void testGetTemplateName() { + VCRequestDto request = new VCRequestDto(); + request.setContext(List.of("https://www.w3.org/ns/credentials/v2", "https://schema.org/Person")); + request.setType(List.of("VerifiableCredential", "UniversityCredential")); + String expected = "UniversityCredential,VerifiableCredential:https://schema.org/Person,https://www.w3.org/ns/credentials/v2"; + assertEquals(expected, CredentialUtils.getTemplateName(request)); + } +} \ No newline at end of file diff --git a/db_scripts/mosip_certify/dml/certify-key_policy_def.csv b/db_scripts/mosip_certify/dml/certify-key_policy_def.csv index f498cddc..79638499 100644 --- a/db_scripts/mosip_certify/dml/certify-key_policy_def.csv +++ b/db_scripts/mosip_certify/dml/certify-key_policy_def.csv @@ -2,4 +2,4 @@ app_id,key_validity_duration,pre_expire_days,access_allowed,is_active,cr_by,cr_d ROOT,2920,1125,NA,TRUE,mosipadmin,now() CERTIFY_SERVICE,1095,60,NA,TRUE,mosipadmin,now() CERTIFY_PARTNER,1095,60,NA,TRUE,mosipadmin,now() -CERTIFY_MOCK_RSA|1095|60|NA|TRUE|mosipadmin|now() +CERTIFY_MOCK_RSA,1095,60,NA,TRUE,mosipadmin,now()