From e47061de8dbb8a94bc3c04948a4abc12b7ae17e2 Mon Sep 17 00:00:00 2001 From: Xavi Aracil Date: Mon, 12 Dec 2022 18:26:16 +0100 Subject: [PATCH] Added more image validation tests --- .../org/oneedtech/inspect/vc/OB20Tests.java | 20 ++++++++++++++++++- .../org/oneedtech/inspect/vc/Samples.java | 4 ++++ .../ob20/assertion-with-data-image.json | 18 +++++++++++++++++ .../assets/badgeclass-with-complex-image.json | 14 +++++++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 inspector-vc/src/test/resources/ob20/assertion-with-data-image.json create mode 100644 inspector-vc/src/test/resources/ob20/assets/badgeclass-with-complex-image.json 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 73706be..1949d92 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 @@ -116,7 +116,7 @@ public class OB20Tests { } @Test - void testDataImage() { + void testDataImageInBadge() { assertDoesNotThrow(()->{ Report report = validator.run(Samples.OB20.JSON.BADGE_WITH_DATA_IMAGE_JSON.asFileResource()); if(verbose) PrintHelper.print(report, true); @@ -124,6 +124,24 @@ public class OB20Tests { }); } + @Test + void testDataImageInAssertion() { + assertDoesNotThrow(()->{ + Report report = validator.run(Samples.OB20.JSON.ASSERTION_WITH_DATA_IMAGE_JSON.asFileResource()); + if(verbose) PrintHelper.print(report, true); + assertInvalid(report); + }); + } + + @Test + void testComplexImageInAssertion() { + assertDoesNotThrow(()->{ + Report report = validator.run(Samples.OB20.JSON.BADGE_WITH_COMPLEX_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 a3c31d1..1b644af 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 @@ -85,6 +85,10 @@ public class Samples { 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); + // original: test_image_validation: test_base64_data_uri_in_assertion + public final static Sample ASSERTION_WITH_DATA_IMAGE_JSON = new Sample("ob20/assertion-with-data-image.json", true); + // original: test_image_validation: test_validate_badgeclass_image_formats + public final static Sample BADGE_WITH_COMPLEX_IMAGE_JSON = new Sample("ob20/assets/badgeclass-with-complex-image.json", true); } public static final class PNG { diff --git a/inspector-vc/src/test/resources/ob20/assertion-with-data-image.json b/inspector-vc/src/test/resources/ob20/assertion-with-data-image.json new file mode 100644 index 0000000..338ba57 --- /dev/null +++ b/inspector-vc/src/test/resources/ob20/assertion-with-data-image.json @@ -0,0 +1,18 @@ +{ + "@context": "https://w3id.org/openbadges/v2", + "type": "Assertion", + "id": "https://example.org/beths-robotics-badge.json", + "recipient": { + "type": "email", + "hashed": true, + "salt": "deadsea", + "identity": "sha256$ecf5409f3f4b91ab60cc5ef4c02aef7032354375e70cf4d8e43f6a1d29891942" + }, + "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOUMyqsBwACeQFChxlltgAAAABJRU5ErkJggg==", + "evidence": "https://example.org/beths-robot-work.html", + "issuedOn": "2016-12-31T23:59:59Z", + "badge": "https://example.org/robotics-badge.json", + "verification": { + "type": "hosted" + } +} \ No newline at end of file diff --git a/inspector-vc/src/test/resources/ob20/assets/badgeclass-with-complex-image.json b/inspector-vc/src/test/resources/ob20/assets/badgeclass-with-complex-image.json new file mode 100644 index 0000000..e06df7e --- /dev/null +++ b/inspector-vc/src/test/resources/ob20/assets/badgeclass-with-complex-image.json @@ -0,0 +1,14 @@ +{ + "@context": "https://w3id.org/openbadges/v2", + "id": "http://example.org/badgeclass-with-complex-image.json", + "type": "BadgeClass", + "name": "Example Badge", + "description": "An example", + "criteria": "http://example.com/badgecriteria.json", + "issuer": "http://example.org/issuer1.json", + "image": { + "id": "http://example.org/beths-robot-badge.png", + "author": "http://someoneelse.org/1", + "caption": "A hexagon with attitude" + } +} \ No newline at end of file