misc small edits

This commit is contained in:
Markus Gylling 2022-06-30 15:13:46 +02:00
parent 5d5f3f7588
commit c655b3ca1c
8 changed files with 16 additions and 19 deletions

View File

@ -45,7 +45,7 @@ public class Credential extends GeneratedObject {
return resource;
}
public JsonNode asJson() {
public JsonNode getJson() {
return jsonData;
}

View File

@ -8,7 +8,6 @@ import java.util.Map;
import org.oneedtech.inspect.core.SubInspector;
import org.oneedtech.inspect.core.probe.GeneratedObject;
import org.oneedtech.inspect.core.probe.RunContext;
import org.oneedtech.inspect.core.probe.RunContext.Key;
import org.oneedtech.inspect.core.probe.json.JsonPathEvaluator;
import org.oneedtech.inspect.core.report.Report;
import org.oneedtech.inspect.core.report.ReportItems;
@ -18,7 +17,7 @@ import org.oneedtech.inspect.util.resource.Resource;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* An inspector for EndersementCredential objects.
* An inspector for EndorsementCredential objects.
* @author mgylling
*/
public class EndorsementInspector extends VCInspector implements SubInspector {
@ -30,7 +29,7 @@ public class EndorsementInspector extends VCInspector implements SubInspector {
@Override
public Report run(Resource resource, Map<String, GeneratedObject> parentObjects) {
/*
* resource is the top-level credential that embeds the endorsement, we
* The resource param is the top-level credential that embeds the endorsement, we
* expect parentObjects to provide a pointer to the JsonNode we should check
*/
Credential endorsement = (Credential) parentObjects.get(ENDORSEMENT_KEY);

View File

@ -1,17 +1,15 @@
package org.oneedtech.inspect.vc;
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.lang.Boolean.TRUE;
import static org.oneedtech.inspect.core.Inspector.Behavior.RESET_CACHES_ON_RUN;
import static org.oneedtech.inspect.core.report.ReportUtil.onProbeException;
import static org.oneedtech.inspect.util.json.ObjectMapperCache.Config.DEFAULT;
import static org.oneedtech.inspect.vc.EndorsementInspector.ENDORSEMENT_KEY;
import static org.oneedtech.inspect.vc.util.JsonNodeUtil.getEndorsements;
import static com.google.common.base.Strings.isNullOrEmpty;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.oneedtech.inspect.core.probe.Outcome;
@ -92,15 +90,15 @@ public class OB30Inspector extends VCInspector {
//validate the value of the type property
probeCount++;
accumulator.add(new JsonArrayProbe(vcType).run(crd.asJson(), ctx));
accumulator.add(new JsonArrayProbe(vcType).run(crd.getJson(), ctx));
probeCount++;
accumulator.add(new JsonArrayProbe(obType).run(crd.asJson(), ctx));
accumulator.add(new JsonArrayProbe(obType).run(crd.getJson(), ctx));
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
//validate against the canonical schema
SchemaKey canonical = crd.getSchemaKey().orElseThrow();
probeCount++;
accumulator.add(new JsonSchemaProbe(canonical).run(crd.asJson(), ctx));
accumulator.add(new JsonSchemaProbe(canonical).run(crd.getJson(), ctx));
//validate against any inline schemas
probeCount++;
@ -148,7 +146,7 @@ public class OB30Inspector extends VCInspector {
if(broken(accumulator)) return abort(ctx, accumulator, probeCount);
//embedded endorsements
List<JsonNode> endorsements = getEndorsements(crd.asJson(), jsonPath);
List<JsonNode> endorsements = getEndorsements(crd.getJson(), jsonPath);
if(endorsements.size() > 0) {
EndorsementInspector subInspector = new EndorsementInspector.Builder().build();
for(JsonNode endorsementNode : endorsements) {

View File

@ -28,7 +28,7 @@ public class ExpirationVerifierProbe extends Probe<Credential> {
*/
ZonedDateTime now = ZonedDateTime.now();
JsonNode node = crd.asJson().get("expirationDate");
JsonNode node = crd.getJson().get("expirationDate");
if(node != null) {
ZonedDateTime expirationDate = null;
try {

View File

@ -37,7 +37,7 @@ public class InlineJsonSchemaProbe extends Probe<Credential> {
// ArrayNode nodes = jsonPath.eval("$..*[?(@.credentialSchema)]", crd.getJson());
// note - we dont get deep nested ones in e.g. EndorsementCredential
JsonNode credentialSchemaNode = crd.asJson().get("credentialSchema");
JsonNode credentialSchemaNode = crd.getJson().get("credentialSchema");
if(credentialSchemaNode == null) return success(ctx);
ArrayNode schemas = (ArrayNode) credentialSchemaNode; //TODO guard this cast
@ -51,7 +51,7 @@ public class InlineJsonSchemaProbe extends Probe<Credential> {
if(ioErrors.contains(id)) continue;
if(skipCanonical && equals(crd.getSchemaKey(), id)) continue;
try {
accumulator.add(new JsonSchemaProbe(id).run(crd.asJson(), ctx));
accumulator.add(new JsonSchemaProbe(id).run(crd.getJson(), ctx));
} catch (Exception e) {
if(!ioErrors.contains(id)) {
ioErrors.add(id);

View File

@ -28,7 +28,7 @@ public class IssuanceVerifierProbe extends Probe<Credential> {
*/
ZonedDateTime now = ZonedDateTime.now();
JsonNode node = crd.asJson().get("issuanceDate");
JsonNode node = crd.getJson().get("issuanceDate");
if(node != null) {
ZonedDateTime issuanceDate = null;
try {

View File

@ -61,7 +61,7 @@ public class ProofVerifierProbe extends Probe<Credential> {
//clone the incoming credential object so we can modify it freely
ObjectMapper mapper = (ObjectMapper)ctx.get(JACKSON_OBJECTMAPPER);
JsonNode copy = mapper.readTree(crd.asJson().toString());
JsonNode copy = mapper.readTree(crd.getJson().toString());
//remove proof
((ObjectNode)copy).remove("proof");
@ -69,7 +69,7 @@ public class ProofVerifierProbe extends Probe<Credential> {
//create JSON-P Json-LD instance
JsonDocument jsonLdDoc = JsonDocument.of(new StringReader(copy.toString()));
//create rdf and normalize
//create rdf and normalize //TODO add DocumentLoader to cache contexts
RdfDataset dataSet = JsonLd.toRdf(jsonLdDoc).ordered(true).get();
RdfDataset normalized = RdfNormalize.normalize(dataSet);

View File

@ -36,7 +36,7 @@ public class RevocationListProbe extends Probe<Credential> {
* report a warning, not an error.
*/
JsonNode credentialStatus = crd.asJson().get("credentialStatus");
JsonNode credentialStatus = crd.getJson().get("credentialStatus");
if(credentialStatus != null) {
JsonNode type = credentialStatus.get("type");
if(type != null && type.asText().strip().equals("1EdTechRevocationList")) {
@ -52,7 +52,7 @@ public class RevocationListProbe extends Probe<Credential> {
* credential's id is in the list of revokedCredentials and the value of
* revoked is true or ommitted, the issuer has revoked the credential. */
JsonNode crdID = crd.asJson().get("id");
JsonNode crdID = crd.getJson().get("id"); //TODO these != checks sb removed (trigger warning)
if(crdID != null) {
List<JsonNode> list = JsonNodeUtil.asNodeList(revocList.get("revokedCredentials"));
if(list != null) {