From 67232f5b1d4561416484402b41737731459dd3fa Mon Sep 17 00:00:00 2001 From: Markus Gylling Date: Wed, 13 Jul 2022 21:27:09 +0200 Subject: [PATCH] add unit test for JsonSchemaProbe --- .../vc/probe/ExpirationVerifierProbe.java | 1 - .../org/oneedtech/inspect/vc/OB30Tests.java | 12 ++++++++ .../org/oneedtech/inspect/vc/Samples.java | 1 + .../test/resources/ob30/simple-issuer.json | 29 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 inspector-vc/src/test/resources/ob30/simple-issuer.json diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationVerifierProbe.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationVerifierProbe.java index 8fab94e..3660651 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationVerifierProbe.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/ExpirationVerifierProbe.java @@ -25,7 +25,6 @@ public class ExpirationVerifierProbe extends Probe { * If the AchievementCredential or EndorsementCredential has an “expirationDate” property * and the expiration date is prior to the current date, the credential has expired. */ - System.err.println("ExpirationVerifierProbe"); JsonNode node = crd.getJson().get("expirationDate"); if(node != null) { try { diff --git a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB30Tests.java b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB30Tests.java index 079a28c..6b843e6 100644 --- a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB30Tests.java +++ b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB30Tests.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.oneedtech.inspect.core.Inspector.Behavior; +import org.oneedtech.inspect.core.probe.json.JsonSchemaProbe; import org.oneedtech.inspect.core.report.Report; import org.oneedtech.inspect.test.PrintHelper; import org.oneedtech.inspect.vc.probe.ExpirationVerifierProbe; @@ -108,6 +109,17 @@ public class OB30Tests { }); } + @Test + void testSimpleJsonSchemaError() throws Exception { + //issuer removed + assertDoesNotThrow(()->{ + Report report = validator.run(Samples.OB30.JSON.SIMPLE_JSON_ISSUER.asFileResource()); + if(verbose) PrintHelper.print(report, true); + assertInvalid(report); + assertHasProbeID(report, JsonSchemaProbe.ID, true); + }); + } + @Disabled //TODO IssuanceVerifierProbe is not run because FATAL: InvalidSignature terminates @Test void testSimpleJsonNotIssued() { diff --git a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/Samples.java b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/Samples.java index 1e08b0d..b0904bc 100644 --- a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/Samples.java +++ b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/Samples.java @@ -16,6 +16,7 @@ public class Samples { public final static Sample SIMPLE_JSON_PROOF_ERROR = new Sample("ob30/simple-proof-error.json", false); public final static Sample SIMPLE_JSON_EXPIRED = new Sample("ob30/simple-expired.json", false); public final static Sample SIMPLE_JSON_ISSUED = new Sample("ob30/simple-issued.json", false); + public final static Sample SIMPLE_JSON_ISSUER = new Sample("ob30/simple-issuer.json", false); } public static final class PNG { public final static Sample SIMPLE_JWT_PNG = new Sample("ob30/simple-jwt.png", true); diff --git a/inspector-vc/src/test/resources/ob30/simple-issuer.json b/inspector-vc/src/test/resources/ob30/simple-issuer.json new file mode 100644 index 0000000..2e988ea --- /dev/null +++ b/inspector-vc/src/test/resources/ob30/simple-issuer.json @@ -0,0 +1,29 @@ +{ + "@context": [ + "https://www.w3.org/2018/credentials/v1", + "https://imsglobal.github.io/openbadges-specification/context.json", + "https://w3id.org/security/suites/ed25519-2020/v1" + ], + "id": "http://example.edu/credentials/3732", + "type": [ + "VerifiableCredential", + "OpenBadgeCredential" + ], + "issuanceDate": "2010-01-01T00:00:00Z", + "name": "Example University Degree", + "credentialSubject": { + "id": "did:example:ebfeb1f712ebc6f1c276e12ec21", + "type": [ + "AchievementSubject" + ] + }, + "proof": [ + { + "type": "Ed25519Signature2020", + "created": "2022-06-28T16:28:36Z", + "verificationMethod": "did:key:z6MkkUD3J14nkYzn46QeuaVSnp7dF85QJKwKvJvfsjx79aXj", + "proofPurpose": "assertionMethod", + "proofValue": "z3MUt2ZuU8Byqivxh6GphEM65AFYyNaGYibm97xLTafM7uGufZQLKvJR8itZwxKskvtFM3CUty46v26DZidMNoQnM" + } + ] +} \ No newline at end of file