Skip to content

Commit 788eb1c

Browse files
authored
fix: add schema validation for cel expression testing (#5761)
1 parent f403c90 commit 788eb1c

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

extensions/common/api/management-api-schema-validator/src/main/java/org/eclipse/edc/connector/api/management/schema/ManagementApiSchemaValidatorExtension.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import static org.eclipse.edc.api.management.schema.ManagementApiJsonSchema.V4.CATALOG_ASSET;
3232
import static org.eclipse.edc.api.management.schema.ManagementApiJsonSchema.V4.CATALOG_REQUEST;
3333
import static org.eclipse.edc.api.management.schema.ManagementApiJsonSchema.V4.CEL_EXPRESSION;
34+
import static org.eclipse.edc.api.management.schema.ManagementApiJsonSchema.V4.CEL_EXPRESSION_TEST_REQUEST;
3435
import static org.eclipse.edc.api.management.schema.ManagementApiJsonSchema.V4.CONTRACT_AGREEMENT;
3536
import static org.eclipse.edc.api.management.schema.ManagementApiJsonSchema.V4.CONTRACT_DEFINITION;
3637
import static org.eclipse.edc.api.management.schema.ManagementApiJsonSchema.V4.CONTRACT_NEGOTIATION;
@@ -73,6 +74,7 @@
7374
import static org.eclipse.edc.participantcontext.spi.config.model.ParticipantContextConfiguration.PARTICIPANT_CONTEXT_CONFIG_TYPE_TERM;
7475
import static org.eclipse.edc.participantcontext.spi.types.ParticipantContext.PARTICIPANT_CONTEXT_TYPE_TERM;
7576
import static org.eclipse.edc.policy.cel.model.CelExpression.CEL_EXPRESSION_TYPE_TERM;
77+
import static org.eclipse.edc.policy.cel.model.CelExpressionTestRequest.CEL_EXPRESSION_TEST_REQUEST_TYPE_TERM;
7678
import static org.eclipse.edc.policy.engine.spi.plan.PolicyEvaluationPlan.EDC_POLICY_EVALUATION_PLAN_TYPE_TERM;
7779
import static org.eclipse.edc.spi.constants.CoreConstants.JSON_LD;
7880
import static org.eclipse.edc.spi.query.QuerySpec.EDC_QUERY_SPEC_TYPE_TERM;
@@ -116,6 +118,7 @@ public class ManagementApiSchemaValidatorExtension implements ServiceExtension {
116118
put(PARTICIPANT_CONTEXT_TYPE_TERM, PARTICIPANT_CONTEXT);
117119
put(PARTICIPANT_CONTEXT_CONFIG_TYPE_TERM, PARTICIPANT_CONTEXT_CONFIG);
118120
put(CEL_EXPRESSION_TYPE_TERM, CEL_EXPRESSION);
121+
put(CEL_EXPRESSION_TEST_REQUEST_TYPE_TERM, CEL_EXPRESSION_TEST_REQUEST);
119122
put("AssociateDataspaceProfile", ASSOCIATE_DATASPACE_PROFILE_CONTEXT);
120123
}
121124
};

extensions/common/api/management-api-schema-validator/src/main/resources/schema/management/v4/cel-expression-test-request-schema.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@
2929
"type": "string"
3030
},
3131
"rightOperand": {
32-
"type": "object"
32+
"oneOf": [
33+
{
34+
"type": "string"
35+
},
36+
{
37+
"type": "object"
38+
}
39+
]
3340
},
3441
"params": {
3542
"type": "object"

system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/v5/CelExpressionApiV5EndToEndTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,26 @@ void test_evaluationError(ManagementEndToEndV5TestContext context) {
443443
.body("error", containsString("key 'agent' is not present in map"))
444444
.body("evaluationResult", nullValue());
445445
}
446+
447+
@Test
448+
void test_validationError(ManagementEndToEndV5TestContext context) {
449+
var requestBody = createObjectBuilder()
450+
.add(CONTEXT, jsonLdContext())
451+
.add(TYPE, "CelExpressionTestRequest")
452+
.build();
453+
454+
context.baseRequest(adminToken)
455+
.body(requestBody.toString())
456+
.contentType(JSON)
457+
.post("/v5beta/celexpressions/test")
458+
.then()
459+
.statusCode(400)
460+
.log().ifError()
461+
.body("[0].message", containsString("required property 'leftOperand' not found"))
462+
.body("[1].message", containsString("required property 'expression' not found"))
463+
.body("[2].message", containsString("required property 'rightOperand' not found"))
464+
.body("[3].message", containsString("required property 'operator' not found"));
465+
}
446466
}
447467

448468
@Nested

0 commit comments

Comments
 (0)