diff --git a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidator.java b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidator.java index 28af76118c3..2739fdf5092 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidator.java +++ b/extensions/control-plane/api/management-api/policy-definition-api/src/main/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidator.java @@ -146,7 +146,15 @@ private record ConstraintValidator(JsonLdPath path) implements Validator 1) { + return ValidationResult.failure( + violation("Cannot define multiple operands in a Logical Constraint: %s".formatted(logicalOperands), + path.toString())); + } + + if (logicalOperands.size() == 1) { return ValidationResult.success(); } diff --git a/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidatorTest.java b/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidatorTest.java index fe3f6881a1a..cc762f6186f 100644 --- a/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidatorTest.java +++ b/extensions/control-plane/api/management-api/policy-definition-api/src/test/java/org/eclipse/edc/connector/controlplane/api/management/policy/validation/PolicyDefinitionValidatorTest.java @@ -34,6 +34,7 @@ import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_CONSTRAINT_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_LEFT_OPERAND_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_OPERATOR_ATTRIBUTE; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_OR_CONSTRAINT_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PERMISSION_ATTRIBUTE; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_TYPE_SET; import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_PROFILE_ATTRIBUTE; @@ -202,6 +203,31 @@ void shouldSucceed_whenLogicalConstraintIsPresent() { assertThat(result).isSucceeded(); } + @Test + void shouldFail_whenLogicalConstraintWithMultipleOperandsIsPresent() { + var permission = createArrayBuilder().add(createObjectBuilder() + .add(ODRL_ACTION_ATTRIBUTE, createValidAction()) + .add(ODRL_CONSTRAINT_ATTRIBUTE, createArrayBuilder().add(createObjectBuilder() + .add(ODRL_AND_CONSTRAINT_ATTRIBUTE, createArrayBuilder()) + .add(ODRL_OR_CONSTRAINT_ATTRIBUTE, createArrayBuilder()) + ))); + var policy = createObjectBuilder() + .add(TYPE, policySet()) + .add(ODRL_PERMISSION_ATTRIBUTE, permission); + var policyDefinition = createObjectBuilder() + .add(EDC_POLICY_DEFINITION_POLICY, createArrayBuilder().add(policy)) + .build(); + + var result = validator.validate(policyDefinition); + + assertThat(result).isFailed().extracting(ValidationFailure::getViolations).asInstanceOf(list(Violation.class)) + .hasSize(1) + .anySatisfy(violation -> { + assertThat(violation.message()).contains("multiple operands"); + assertThat(violation.path()).endsWith(ODRL_CONSTRAINT_ATTRIBUTE); + }); + } + @Test void shouldSucceed_whenProfileIsPresent() { var policy = createObjectBuilder()