From de2cede1f89d65f463b00a86df3994fdde3742bb Mon Sep 17 00:00:00 2001 From: Victor Nicolet Date: Fri, 11 Sep 2026 16:15:42 -0400 Subject: [PATCH] update tests to reflect cedar#2545 Signed-off-by: Victor Nicolet --- .../java/com/cedarpolicy/ValidationTests.java | 30 ++++++++++++++----- CedarJavaFFI/src/interface.rs | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CedarJava/src/test/java/com/cedarpolicy/ValidationTests.java b/CedarJava/src/test/java/com/cedarpolicy/ValidationTests.java index d3943c70..fc60bcca 100644 --- a/CedarJava/src/test/java/com/cedarpolicy/ValidationTests.java +++ b/CedarJava/src/test/java/com/cedarpolicy/ValidationTests.java @@ -80,7 +80,7 @@ public void givenExampleSchemaAndCorrectPolicyReturnsValid() { /** Test. */ @Test - public void givenExampleSchemaAndIncorrectPolicyReturnsValid() { + public void givenExampleSchemaAndImpossiblePolicyReturnsWarning() { givenSchema(PHOTOFLASH_SCHEMA); givenPolicy( "policy0", @@ -90,9 +90,9 @@ public void givenExampleSchemaAndIncorrectPolicyReturnsValid() { + " resource == User::\"bob\"" + ");"); ValidationResponse response = whenValidated(); - thenIsNotValid(response); + thenHasWarnings(response); ValidationResponse levelResponse = whenLevelValidated(1); - thenIsNotValid(levelResponse); + thenHasWarnings(levelResponse); } /** Test. */ @@ -169,16 +169,16 @@ public void validateTemplateLinkedPolicyFailsWhenExpected() { thenValidationFailed(levelResponse3); - // validation returns an error if we provide a link with the wrong type + // validation warns if we provide a link with the wrong type LinkValue badLink1 = new LinkValue("?resource", EntityUID.parse("Library::User::\"Victor\"").get()); this.policies = new PolicySet(new HashSet<>(), templates, List.of(new TemplateLink("template1", "policy", List.of(badLink1)))); ValidationResponse response4 = whenValidated(); - thenIsNotValid(response4); + thenHasWarnings(response4); ValidationResponse levelResponse4 = whenLevelValidated(1); - thenIsNotValid(levelResponse4); + thenHasWarnings(levelResponse4); - // validation returns an error if we provide a link with an invalid type + // validation returns an error if we provide a link with an unrecognized type LinkValue badLink2 = new LinkValue("?resource", EntityUID.parse("Library::BOOK::\"The black Swan\"").get()); this.policies = new PolicySet(new HashSet<>(), templates, List.of(new TemplateLink("template1", "policy", List.of(badLink2)))); @@ -284,6 +284,22 @@ private void thenIsNotValid(ValidationResponse response) { }); } + private void thenHasWarnings(ValidationResponse response) { + assertEquals(response.type, SuccessOrFailure.Success); + final ValidationSuccessResponse success = assertDoesNotThrow(() -> response.success.get()); + assertTrue( + success.validationErrors.isEmpty(), + () -> { + String errors = response.success.get().validationErrors.stream() + .map(note -> String.format("in policy %s: %s", note.getPolicyId(), note.getError())) + .collect(Collectors.joining("\n")); + return "Expected no validation errors but got:\n" + errors; + }); + assertFalse( + success.validationWarnings.isEmpty(), + () -> "Expected validation warnings but did not find any"); + } + private void thenValidationFailed(ValidationResponse response) { assertEquals(response.type, SuccessOrFailure.Failure); final List errors = assertDoesNotThrow(() -> response.errors.get()); diff --git a/CedarJavaFFI/src/interface.rs b/CedarJavaFFI/src/interface.rs index b03841e6..2ace7222 100644 --- a/CedarJavaFFI/src/interface.rs +++ b/CedarJavaFFI/src/interface.rs @@ -1201,7 +1201,7 @@ pub fn get_cedar_schema_internal<'a>( let cedar_format = schema_to_text(schema); match cedar_format { - SchemaToTextAnswer::Success { text, warnings } => { + SchemaToTextAnswer::Success { text, .. } => { let jstr = env.new_string(&text)?; Ok(JValueGen::Object(JObject::from(jstr)).into()) }