From 59c96d68d1bb20359651e5e5df2f15586b9ec37f Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Mon, 12 Dec 2022 18:04:53 +0100 Subject: [PATCH] Added image validation tests --- .../main/java/org/oneedtech/inspect/vc/Assertion.java | 9 +++++---- .../vc/probe/validation/ValidationPropertyProbe.java | 2 +- .../test/java/org/oneedtech/inspect/vc/OB20Tests.java | 9 +++++++++ .../test/java/org/oneedtech/inspect/vc/Samples.java | 2 ++ .../resources/ob20/assets/badge-with-data-image.json | 10 ++++++++++ 5 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 inspector-vc/src/test/resources/ob20/assets/badge-with-data-image.json diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java index 0cd395f..e904a5a 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/Assertion.java @@ -217,7 +217,8 @@ public class Assertion extends Credential { new Validation.Builder().name("@language").type(ValueType.LANGUAGE).build(), new Validation.Builder().name("version").type(ValueType.TEXT_OR_NUMBER).build(), new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.BadgeClass).many(true).fullValidate(false).build(), - new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build() + new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build(), + new Validation.Builder().name("image").type(ValueType.IMAGE).allowDataUri(true).build() )) .put(Type.AlignmentObject, List.of( new Validation.Builder().name("type").type(ValueType.RDF_TYPE).many(true).defaultType(Type.AlignmentObject).build(), @@ -286,7 +287,8 @@ public class Assertion extends Credential { new Validation.Builder().name("type").type(ValueType.RDF_TYPE).many(true).defaultType("schema:ImageObject").build(), new Validation.Builder().name("id").type(ValueType.DATA_URI_OR_URL).required(true).build(), new Validation.Builder().name("caption").type(ValueType.TEXT).build(), - new Validation.Builder().name("author").type(ValueType.IRI).build() + new Validation.Builder().name("author").type(ValueType.IRI).build(), + new Validation.Builder().name("id").type(ValueType.IMAGE).allowDataUri(true).build() )) .put(Type.Issuer, List.of( new Validation.Builder().name("id").type(ValueType.IRI).required(true).build(), @@ -321,8 +323,7 @@ public class Assertion extends Credential { new Validation.Builder().name("@language").type(ValueType.LANGUAGE).build(), new Validation.Builder().name("version").type(ValueType.TEXT_OR_NUMBER).build(), new Validation.Builder().name("related").type(ValueType.ID).allowRemoteUrl(true).expectedType(Type.Profile).many(true).fullValidate(false).build(), - new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build() - )) + new Validation.Builder().name("endorsement").type(ValueType.ID).allowRemoteUrl(true).fetch(true).expectedType(Type.Endorsement).many(true).build() )) .put(Type.RevocationList, List.of( new Validation.Builder().name("type").type(ValueType.RDF_TYPE).required(true).many(true).mustContainOneType(List.of(Type.RevocationList)).build(), new Validation.Builder().name("id").type(ValueType.IRI).build() diff --git a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/validation/ValidationPropertyProbe.java b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/validation/ValidationPropertyProbe.java index c371d90..8cb907d 100644 --- a/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/validation/ValidationPropertyProbe.java +++ b/inspector-vc/src/main/java/org/oneedtech/inspect/vc/probe/validation/ValidationPropertyProbe.java @@ -44,7 +44,7 @@ public class ValidationPropertyProbe extends PropertyProbe { } public ValidationPropertyProbe(String id, Validation validation) { - this(ID, validation, true); + this(id, validation, true); } public ValidationPropertyProbe(Validation validation, boolean fullValidate) { diff --git a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB20Tests.java b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB20Tests.java index 0f5f98e..73706be 100644 --- a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB20Tests.java +++ b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/OB20Tests.java @@ -115,6 +115,15 @@ public class OB20Tests { }); } + @Test + void testDataImage() { + assertDoesNotThrow(()->{ + Report report = validator.run(Samples.OB20.JSON.BADGE_WITH_DATA_IMAGE_JSON.asFileResource()); + if(verbose) PrintHelper.print(report, true); + assertValid(report); + }); + } + @Test void testLanguageInBadgeClass() { assertDoesNotThrow(()->{ 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 e27af23..a3c31d1 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 @@ -83,6 +83,8 @@ public class Samples { public final static Sample SIMPLE_FUTURE_ASSERTION_JSON = new Sample("ob20/basic-assertion-in-future.json", true); // original: test_validate_related: test_validate_related_language public final static Sample BASIC_WITH_LANGUAGE_JSON = new Sample("ob20/basic-assertion-with-language.json", true); + // original: test_image_validation: test_base64_data_uri_in_badgeclass + public final static Sample BADGE_WITH_DATA_IMAGE_JSON = new Sample("ob20/assets/badge-with-data-image.json", true); } public static final class PNG { diff --git a/inspector-vc/src/test/resources/ob20/assets/badge-with-data-image.json b/inspector-vc/src/test/resources/ob20/assets/badge-with-data-image.json new file mode 100644 index 0000000..da4abf9 --- /dev/null +++ b/inspector-vc/src/test/resources/ob20/assets/badge-with-data-image.json @@ -0,0 +1,10 @@ +{ + "@context": "https://w3id.org/openbadges/v2", + "type": "BadgeClass", + "id": "https://example.org/badge-from-organization-with-revocation-list.json", + "name": "Awesome Robotics Badge", + "description": "For doing awesome things with robots that people think is pretty great.", + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOUMyqsBwACeQFChxlltgAAAABJRU5ErkJggg==", + "criteria": "http://example.com/badgecriteria.json", + "issuer": "https://example.org/organization-with-revocation-list.json" +} \ No newline at end of file