Added Rdf Type validation test
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.oneedtech.inspect.vc;
|
||||
|
||||
import static org.oneedtech.inspect.vc.util.PrimitiveValueValidator.validateIri;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -84,14 +86,21 @@ public class Assertion extends Credential {
|
||||
VerificationObject(List.of("VerificationObject")),
|
||||
VerificationObjectAssertion(List.of("VerificationObjectAssertion")),
|
||||
VerificationObjectIssuer(List.of("VerificationObjectIssuer")),
|
||||
External(Collections.emptyList(), false),
|
||||
Unknown(Collections.emptyList());
|
||||
|
||||
public static List<Type> primaryObjects = List.of(Assertion, BadgeClass, Issuer, Profile, Endorsement);
|
||||
|
||||
private final List<String> allowedTypeValues;
|
||||
private final boolean allowedTypeValuesRequired;
|
||||
|
||||
Type(List<String> typeValues) {
|
||||
this(typeValues, true);
|
||||
}
|
||||
|
||||
Type(List<String> typeValues, boolean allowedTypeValuesRequired) {
|
||||
this.allowedTypeValues = typeValues;
|
||||
this.allowedTypeValuesRequired = allowedTypeValuesRequired;
|
||||
}
|
||||
|
||||
public static Assertion.Type valueOf (JsonNode typeNode) {
|
||||
@@ -107,6 +116,12 @@ public class Assertion extends Credential {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check external type
|
||||
if (validateIri(typeNode)) {
|
||||
return External;
|
||||
}
|
||||
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
@@ -125,6 +140,11 @@ public class Assertion extends Credential {
|
||||
return List.of("https://w3id.org/openbadges/v2") ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedTypeValuesRequired() {
|
||||
return allowedTypeValuesRequired;
|
||||
}
|
||||
|
||||
public List<Validation> getValidations() {
|
||||
return validationMap.get(this);
|
||||
}
|
||||
@@ -318,6 +338,8 @@ public class Assertion extends Credential {
|
||||
new Validation.Builder().name("startsWith").type(ValueType.URL).build(),
|
||||
new Validation.Builder().name("allowedOrigins").type(ValueType.URL_AUTHORITY).many(true).build()
|
||||
))
|
||||
.put(Type.External, Collections.emptyList())
|
||||
.put(Type.Unknown, Collections.emptyList())
|
||||
.build();
|
||||
|
||||
public static final String ID = Assertion.class.getCanonicalName();
|
||||
|
||||
@@ -90,6 +90,7 @@ public abstract class Credential extends GeneratedObject {
|
||||
public interface CredentialEnum {
|
||||
List<String> getRequiredTypeValues();
|
||||
List<String> getAllowedTypeValues();
|
||||
boolean isAllowedTypeValuesRequired();
|
||||
List<String> getContextUris();
|
||||
}
|
||||
|
||||
|
||||
@@ -107,6 +107,10 @@ public class VerifiableCredential extends Credential {
|
||||
return allowedTypeValues;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedTypeValuesRequired() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public List<String> getContextUris() {
|
||||
return contextMap.get(contextMap.keySet()
|
||||
|
||||
@@ -31,12 +31,14 @@ public class TypePropertyProbe extends StringValuePropertyProbe {
|
||||
}
|
||||
}
|
||||
|
||||
List<String> allowedValues = expected.getAllowedTypeValues();
|
||||
if (allowedValues.isEmpty()) {
|
||||
return fatal("The type property is invalid", ctx);
|
||||
}
|
||||
if (!values.stream().anyMatch(v -> allowedValues.contains(v))) {
|
||||
return fatal(formatMessage(values), ctx);
|
||||
if (expected.isAllowedTypeValuesRequired()) {
|
||||
List<String> allowedValues = expected.getAllowedTypeValues();
|
||||
if (allowedValues.isEmpty()) {
|
||||
return fatal("The type property is invalid", ctx);
|
||||
}
|
||||
if (!values.stream().anyMatch(v -> allowedValues.contains(v))) {
|
||||
return fatal(formatMessage(values), ctx);
|
||||
}
|
||||
}
|
||||
|
||||
return success(ctx);
|
||||
|
||||
Reference in New Issue
Block a user