Skip to content

Commit

Permalink
test no validators
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Jul 31, 2024
1 parent fb09a70 commit 211bd43
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ public UiPolicy buildUiPolicy(Policy policy) {

var expression = expressionExtractor.getPermissionExpression(policy, errors);

System.out.println("Expression: " + expression);
System.out.println("Errors: " + errors.getErrors());

return UiPolicy.builder()
.policyJsonLd(toJson(buildPolicyJsonLd(policy)))
.expression(expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ private List<UiPolicyExpression> getPermissionExpressions(Policy policy, Mapping
return List.of();
}

if (permissions.size() > 1) {
errors.add("Multiple permissions were present. Prefer using a conjunction using AND.");
}

List<UiPolicyExpression> expressions = new ArrayList<>();
for (int iPermission = 0; iPermission < permissions.size(); iPermission++) {
var permissionErrors = errors.forChildObject("permissions").forChildArrayElement(iPermission);
Expand All @@ -80,6 +84,10 @@ private List<UiPolicyExpression> getPermissionExpressions(Permission permission,
}

var constraints = permission.getConstraints();
if (constraints != null && constraints.size() > 1) {
errors.forChildObject("constraints")
.add("Multiple constraints were present. Prefer using a conjunction using AND.");
}

return expressionMapper.buildUiPolicyExpressions(
constraints,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.edc.policy.model.Policy;
import org.eclipse.edc.policy.model.PolicyType;

import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

Expand All @@ -36,6 +37,10 @@ public void validateOtherPolicyFieldsUnset(Policy policy, MappingErrors errors)
return;
}

if (isEmpty(policy.getPermissions())) {
errors.add("Policy has no permissions.");
}

if (isNotEmpty(policy.getProhibitions())) {
errors.add("Policy has prohibitions, which are currently unsupported.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ void test_getPermissionConstraints_merge_constraints() {
assertThat(actual)
.usingRecursiveComparison()
.isEqualTo(expected);

assertThat(errors.getErrors()).containsExactly(
"$: Multiple permissions were present. Prefer using a conjunction using AND."
);
}

@Test
Expand Down Expand Up @@ -171,6 +173,9 @@ void test_getPermissionConstraints_merge_constraints2() {
assertThat(actual)
.usingRecursiveComparison()
.isEqualTo(expected);
assertThat(errors.getErrors()).containsExactly(
"$.permissions[0].constraints: Multiple constraints were present. Prefer using a conjunction using AND."
);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ void testPolicy_full() {

// assert
assertThat(errors.getErrors()).containsExactlyInAnyOrder(
"$: Policy has no permissions.",
"$: Policy has prohibitions, which are currently unsupported.",
"$: Policy has obligations, which are currently unsupported.",
"$: Policy has inheritsFrom, which is currently unsupported.",
Expand Down

0 comments on commit 211bd43

Please sign in to comment.