Added test with non-http issuer

This commit is contained in:
Xavi Aracil 2022-11-30 18:50:01 +01:00
parent d6e0d85d2f
commit d604f213be
8 changed files with 262 additions and 8 deletions

View File

@ -9,6 +9,7 @@ import static org.oneedtech.inspect.test.Assertions.assertWarning;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.List;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
@ -26,10 +27,11 @@ public class OB20Tests {
@BeforeAll @BeforeAll
static void setup() throws URISyntaxException { static void setup() throws URISyntaxException {
validator = new TestBuilder() TestBuilder builder = new TestBuilder();
.add(new URI("https://www.example.org/"), "ob20/assets") for (String localDomain : localDomains) {
.add(new URI("https://example.org/"), "ob20/assets") builder.add(new URI(localDomain), "ob20/assets");
.add(new URI("http://example.org/"), "ob20/assets") }
validator = builder
.set(Behavior.TEST_INCLUDE_SUCCESS, true) .set(Behavior.TEST_INCLUDE_SUCCESS, true)
.set(Behavior.TEST_INCLUDE_WARNINGS, false) .set(Behavior.TEST_INCLUDE_WARNINGS, false)
.set(Behavior.VALIDATOR_FAIL_FAST, true) .set(Behavior.VALIDATOR_FAIL_FAST, true)
@ -93,8 +95,11 @@ public class OB20Tests {
static class WarningTests { static class WarningTests {
@BeforeAll @BeforeAll
static void setup() throws URISyntaxException { static void setup() throws URISyntaxException {
validator = new TestBuilder() TestBuilder builder = new TestBuilder();
.add(new URI("https://www.example.org/"), "ob20/assets") for (String localDomain : localDomains) {
builder.add(new URI(localDomain), "ob20/assets");
}
validator = builder
.set(Behavior.TEST_INCLUDE_SUCCESS, true) .set(Behavior.TEST_INCLUDE_SUCCESS, true)
.set(Behavior.TEST_INCLUDE_WARNINGS, true) .set(Behavior.TEST_INCLUDE_WARNINGS, true)
.set(Behavior.VALIDATOR_FAIL_FAST, true) .set(Behavior.VALIDATOR_FAIL_FAST, true)
@ -110,5 +115,16 @@ public class OB20Tests {
assertWarning(report); assertWarning(report);
}); });
} }
@Test
void testWarningIssuerNonHttps() {
assertDoesNotThrow(()->{
Report report = validator.run(Samples.OB20.JSON.WARNING_ISSUER_NON_HTTPS_JSON.asFileResource());
if(verbose) PrintHelper.print(report, true);
assertWarning(report);
});
}
} }
private static final List<String> localDomains = List.of("https://www.example.org/", "https://example.org/", "http://example.org/");
} }

View File

@ -49,6 +49,8 @@ public class Samples {
public final static Sample SIMPLE_ASSERTION_INVALID_TYPE_JSON = new Sample("ob20/basic-assertion-invalid-type.json", true); public final static Sample SIMPLE_ASSERTION_INVALID_TYPE_JSON = new Sample("ob20/basic-assertion-invalid-type.json", true);
// original: test_graph: test_verify_with_redirection // original: test_graph: test_verify_with_redirection
public final static Sample WARNING_REDIRECTION_ASSERTION_JSON = new Sample("ob20/warning-with-redirection.json", true); public final static Sample WARNING_REDIRECTION_ASSERTION_JSON = new Sample("ob20/warning-with-redirection.json", true);
// original: test_validation: test_issuer_warn_on_non_https_id
public final static Sample WARNING_ISSUER_NON_HTTPS_JSON = new Sample("ob20/warning-issuer-non-http.json", true);
// original: test_validation: test_can_input_badgeclass // original: test_validation: test_can_input_badgeclass
public final static Sample SIMPLE_BADGECLASS = new Sample("ob20/assets/badgeclass1.json", true); public final static Sample SIMPLE_BADGECLASS = new Sample("ob20/assets/badgeclass1.json", true);
} }

View File

@ -5,6 +5,6 @@
"name": "Awesome Robotics Badge", "name": "Awesome Robotics Badge",
"description": "For doing awesome things with robots that people think is pretty great.", "description": "For doing awesome things with robots that people think is pretty great.",
"image": "https://example.org/robotics-badge.png", "image": "https://example.org/robotics-badge.png",
"criteria": "https://example.org/robotics-badge.html", "criteria": "http://example.com/badgecriteria.json",
"issuer": "https://example.org/organization.json" "issuer": "https://example.org/organization.json"
} }

View File

@ -0,0 +1,206 @@
{
"@context": {
"id": "@id",
"type": "@type",
"extensions": "https://w3id.org/openbadges/extensions#",
"obi": "https://w3id.org/openbadges#",
"validation": "obi:validation",
"cred": "https://w3id.org/credentials#",
"dc": "http://purl.org/dc/terms/",
"schema": "http://schema.org/",
"sec": "https://w3id.org/security#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"AlignmentObject": "schema:AlignmentObject",
"CryptographicKey": "sec:Key",
"Endorsement": "cred:Credential",
"Assertion": "obi:Assertion",
"BadgeClass": "obi:BadgeClass",
"Criteria": "obi:Criteria",
"Evidence": "obi:Evidence",
"Extension": "obi:Extension",
"FrameValidation": "obi:FrameValidation",
"IdentityObject": "obi:IdentityObject",
"Image": "obi:Image",
"HostedBadge": "obi:HostedBadge",
"hosted": "obi:HostedBadge",
"Issuer": "obi:Issuer",
"Profile": "obi:Profile",
"RevocationList": "obi:RevocationList",
"SignedBadge": "obi:SignedBadge",
"signed": "obi:SignedBadge",
"TypeValidation": "obi:TypeValidation",
"VerificationObject": "obi:VerificationObject",
"author": {
"@id": "schema:author",
"@type": "@id"
},
"caption": {
"@id": "schema:caption"
},
"claim": {
"@id": "cred:claim",
"@type": "@id"
},
"created": {
"@id": "dc:created",
"@type": "xsd:dateTime"
},
"creator": {
"@id": "dc:creator",
"@type": "@id"
},
"description": {
"@id": "schema:description"
},
"email": {
"@id": "schema:email"
},
"endorsement": {
"@id": "cred:credential",
"@type": "@id"
},
"expires": {
"@id": "sec:expiration",
"@type": "xsd:dateTime"
},
"genre": {
"@id": "schema:genre"
},
"image": {
"@id": "schema:image",
"@type": "@id"
},
"name": {
"@id": "schema:name"
},
"owner": {
"@id": "sec:owner",
"@type": "@id"
},
"publicKey": {
"@id": "sec:publicKey",
"@type": "@id"
},
"publicKeyPem": {
"@id": "sec:publicKeyPem"
},
"related": {
"@id": "dc:relation",
"@type": "@id"
},
"startsWith": {
"@id": "http://purl.org/dqm-vocabulary/v1/dqm#startsWith"
},
"tags": {
"@id": "schema:keywords"
},
"targetDescription": {
"@id": "schema:targetDescription"
},
"targetFramework": {
"@id": "schema:targetFramework"
},
"targetName": {
"@id": "schema:targetName"
},
"targetUrl": {
"@id": "schema:targetUrl"
},
"telephone": {
"@id": "schema:telephone"
},
"url": {
"@id": "schema:url",
"@type": "@id"
},
"version": {
"@id": "schema:version"
},
"alignment": {
"@id": "obi:alignment",
"@type": "@id"
},
"allowedOrigins": {
"@id": "obi:allowedOrigins"
},
"audience": {
"@id": "obi:audience"
},
"badge": {
"@id": "obi:badge",
"@type": "@id"
},
"criteria": {
"@id": "obi:criteria",
"@type": "@id"
},
"endorsementComment": {
"@id": "obi:endorsementComment"
},
"evidence": {
"@id": "obi:evidence",
"@type": "@id"
},
"hashed": {
"@id": "obi:hashed",
"@type": "xsd:boolean"
},
"identity": {
"@id": "obi:identityHash"
},
"issuedOn": {
"@id": "obi:issueDate",
"@type": "xsd:dateTime"
},
"issuer": {
"@id": "obi:issuer",
"@type": "@id"
},
"narrative": {
"@id": "obi:narrative"
},
"recipient": {
"@id": "obi:recipient",
"@type": "@id"
},
"revocationList": {
"@id": "obi:revocationList",
"@type": "@id"
},
"revocationReason": {
"@id": "obi:revocationReason"
},
"revoked": {
"@id": "obi:revoked",
"@type": "xsd:boolean"
},
"revokedAssertions": {
"@id": "obi:revoked"
},
"salt": {
"@id": "obi:salt"
},
"targetCode": {
"@id": "obi:targetCode"
},
"uid": {
"@id": "obi:uid"
},
"validatesType": "obi:validatesType",
"validationFrame": "obi:validationFrame",
"validationSchema": "obi:validationSchema",
"verification": {
"@id": "obi:verify",
"@type": "@id"
},
"verificationProperty": {
"@id": "obi:verificationProperty"
},
"verify": "verification"
},
"id": "urn:uuid:2d391246-6e0d-4dab-906c-b29770bd7aa6",
"type": "Issuer",
"url": "http://example.com",
"email": "email@example.org",
"name": "some Issuer"
}

View File

@ -0,0 +1,10 @@
{
"@context": "https://w3id.org/openbadges/v2",
"type": "BadgeClass",
"id": "http://example.org/badge-with-bad-issuer.json",
"name": "Awesome Robotics Badge",
"description": "For doing awesome things with robots that people think is pretty great.",
"image": "https://example.org/robotics-badge.png",
"criteria": "http://example.com/badgecriteria.json",
"issuer": "https://example.org/bad-issuer.json"
}

View File

@ -202,7 +202,7 @@
"type": "BadgeClass", "type": "BadgeClass",
"name": "Example Badge", "name": "Example Badge",
"description": "An example", "description": "An example",
"criteria": "http://example.org/criteria", "criteria": "http://example.com/badgecriteria.json",
"issuer": "http://example.org/issuer1", "issuer": "http://example.org/issuer1",
"image": "http://example.org/robotics-badge.png" "image": "http://example.org/robotics-badge.png"
} }

View File

@ -0,0 +1,3 @@
{
"narrative": "Do the important things."
}

View File

@ -0,0 +1,17 @@
{
"@context": "https://w3id.org/openbadges/v2",
"type": "Assertion",
"id": "https://example.org/warning-issuer-non-http.json",
"recipient": {
"type": "email",
"hashed": true,
"salt": "deadsea",
"identity": "sha256$ecf5409f3f4b91ab60cc5ef4c02aef7032354375e70cf4d8e43f6a1d29891942"
},
"image": "https://example.org/beths-robot-badge.png",
"issuedOn": "2016-12-31T23:59:59Z",
"badge": "http://example.org/badge-with-bad-issuer.json",
"verification": {
"type": "hosted"
}
}