Added invalid context test
This commit is contained in:
parent
c72d1de7f4
commit
5cb232ea5b
@ -99,6 +99,14 @@ public class OB20Inspector extends Inspector {
|
|||||||
// we expect the above to place a generated object in the context
|
// we expect the above to place a generated object in the context
|
||||||
Assertion assertion = ctx.getGeneratedObject(Assertion.ID);
|
Assertion assertion = ctx.getGeneratedObject(Assertion.ID);
|
||||||
|
|
||||||
|
//context and type properties
|
||||||
|
CredentialEnum type = assertion.getCredentialType();
|
||||||
|
for(Probe<JsonNode> probe : List.of(new ContextPropertyProbe(type), new TypePropertyProbe(type))) {
|
||||||
|
probeCount++;
|
||||||
|
accumulator.add(probe.run(assertion.getJson(), ctx));
|
||||||
|
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
|
||||||
|
}
|
||||||
|
|
||||||
// let's compact
|
// let's compact
|
||||||
accumulator.add(getCompactionProbe(assertion).run(assertion, ctx));
|
accumulator.add(getCompactionProbe(assertion).run(assertion, ctx));
|
||||||
if(broken(accumulator, true)) return abort(ctx, accumulator, probeCount);
|
if(broken(accumulator, true)) return abort(ctx, accumulator, probeCount);
|
||||||
@ -108,14 +116,6 @@ public class OB20Inspector extends Inspector {
|
|||||||
accumulator.add(new JsonLDValidationProbe(jsonLdGeneratedObject).run(assertion, ctx));
|
accumulator.add(new JsonLDValidationProbe(jsonLdGeneratedObject).run(assertion, ctx));
|
||||||
if(broken(accumulator, true)) return abort(ctx, accumulator, probeCount);
|
if(broken(accumulator, true)) return abort(ctx, accumulator, probeCount);
|
||||||
|
|
||||||
//context and type properties
|
|
||||||
CredentialEnum type = assertion.getCredentialType();
|
|
||||||
for(Probe<JsonNode> probe : List.of(new ContextPropertyProbe(type), new TypePropertyProbe(type))) {
|
|
||||||
probeCount++;
|
|
||||||
accumulator.add(probe.run(assertion.getJson(), ctx));
|
|
||||||
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
|
|
||||||
}
|
|
||||||
|
|
||||||
//canonical schema and inline schemata
|
//canonical schema and inline schemata
|
||||||
// SchemaKey schema = assertion.getSchemaKey().orElseThrow();
|
// SchemaKey schema = assertion.getSchemaKey().orElseThrow();
|
||||||
// for(Probe<JsonNode> probe : List.of(new JsonSchemaProbe(schema), new InlineJsonSchemaProbe(schema))) {
|
// for(Probe<JsonNode> probe : List.of(new JsonSchemaProbe(schema), new InlineJsonSchemaProbe(schema))) {
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package org.oneedtech.inspect.vc;
|
package org.oneedtech.inspect.vc;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||||
|
import static org.oneedtech.inspect.test.Assertions.assertFatalCount;
|
||||||
|
import static org.oneedtech.inspect.test.Assertions.assertHasProbeID;
|
||||||
|
import static org.oneedtech.inspect.test.Assertions.assertInvalid;
|
||||||
import static org.oneedtech.inspect.test.Assertions.assertValid;
|
import static org.oneedtech.inspect.test.Assertions.assertValid;
|
||||||
import static org.oneedtech.inspect.test.Assertions.assertWarning;
|
import static org.oneedtech.inspect.test.Assertions.assertWarning;
|
||||||
|
|
||||||
@ -13,6 +16,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.oneedtech.inspect.core.Inspector.Behavior;
|
import org.oneedtech.inspect.core.Inspector.Behavior;
|
||||||
import org.oneedtech.inspect.core.report.Report;
|
import org.oneedtech.inspect.core.report.Report;
|
||||||
import org.oneedtech.inspect.test.PrintHelper;
|
import org.oneedtech.inspect.test.PrintHelper;
|
||||||
|
import org.oneedtech.inspect.vc.probe.ContextPropertyProbe;
|
||||||
import org.oneedtech.inspect.vc.util.TestOB20Inspector.TestBuilder;
|
import org.oneedtech.inspect.vc.util.TestOB20Inspector.TestBuilder;
|
||||||
|
|
||||||
public class OB20Tests {
|
public class OB20Tests {
|
||||||
@ -39,6 +43,17 @@ public class OB20Tests {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSimpleJsonInvalidContext() {
|
||||||
|
assertDoesNotThrow(()->{
|
||||||
|
Report report = validator.run(Samples.OB20.JSON.SIMPLE_ASSERTION_INVALID_CONTEXT_JSON.asFileResource());
|
||||||
|
if(verbose) PrintHelper.print(report, true);
|
||||||
|
assertInvalid(report);
|
||||||
|
assertFatalCount(report, 1);
|
||||||
|
assertHasProbeID(report, ContextPropertyProbe.ID, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSimplePNGPlainValid() {
|
void testSimplePNGPlainValid() {
|
||||||
assertDoesNotThrow(()->{
|
assertDoesNotThrow(()->{
|
||||||
|
@ -45,6 +45,7 @@ public class Samples {
|
|||||||
public static final class JSON {
|
public static final class JSON {
|
||||||
// original: test_verify: test_verify_function
|
// original: test_verify: test_verify_function
|
||||||
public final static Sample SIMPLE_ASSERTION_JSON = new Sample("ob20/basic-assertion.json", true);
|
public final static Sample SIMPLE_ASSERTION_JSON = new Sample("ob20/basic-assertion.json", true);
|
||||||
|
public final static Sample SIMPLE_ASSERTION_INVALID_CONTEXT_JSON = new Sample("ob20/basic-assertion-invalid-context.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_can_input_badgeclass
|
// original: test_validation: test_can_input_badgeclass
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"@context": "https://w3id.org/openbadges/invalid",
|
||||||
|
"type": "Assertion",
|
||||||
|
"id": "https://example.org/beths-robotics-badge.json",
|
||||||
|
"recipient": {
|
||||||
|
"type": "email",
|
||||||
|
"hashed": true,
|
||||||
|
"salt": "deadsea",
|
||||||
|
"identity": "sha256$ecf5409f3f4b91ab60cc5ef4c02aef7032354375e70cf4d8e43f6a1d29891942"
|
||||||
|
},
|
||||||
|
"image": "https://example.org/beths-robot-badge.png",
|
||||||
|
"evidence": "https://example.org/beths-robot-work.html",
|
||||||
|
"issuedOn": "2016-12-31T23:59:59Z",
|
||||||
|
"badge": "https://example.org/robotics-badge.json",
|
||||||
|
"verification": {
|
||||||
|
"type": "hosted"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user