-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
will be reverted Signed-off-by: Harsh Vardhan <[email protected]>
- Loading branch information
Showing
15 changed files
with
263 additions
and
40 deletions.
There are no files selected for viewing
11 changes: 9 additions & 2 deletions
11
certify-core/src/main/java/io/mosip/certify/core/constants/SignatureAlg.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 7 additions & 5 deletions
12
certify-core/src/main/java/io/mosip/certify/core/entity/TemplateId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 49 additions & 3 deletions
52
...core/src/test/java/io/mosip/certify/core/templating/VelocityTemplatingEngineImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,88 @@ | ||
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<String, Template> templateCache = new ConcurrentHashMap<>(); | ||
@MockBean | ||
private TemplateRepository templateRepository; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
engine = new VelocityEngine(); | ||
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<String, Object> templateInput = new HashMap<>(); | ||
VelocityContext c = new VelocityContext(); | ||
StringWriter writer = new StringWriter(); | ||
engine.evaluate(c, writer, "SchoolTemplateTest", t.toString()); | ||
String out = writer.toString(); | ||
|
||
Map<String, Object> res = new RestTemplate().getForObject( | ||
"https://api.dev1.mosip.net/v1/mock-identity-system/identity/34455445765", | ||
HashMap.class); | ||
res = (Map<String, Object>) res.get("response"); | ||
Map<String, Object> 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<String, Object> finalTemplate = new HashMap<>(); | ||
for (String key : ret.keySet()) { | ||
Object value = ret.get(key); | ||
if (value instanceof List) { | ||
finalTemplate.put(key, new JSONArray((List<String>) 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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.