Skip to content

Commit 0da0145

Browse files
TristonianJonescopybara-github
authored andcommitted
Additional test case and error message refinement
PiperOrigin-RevId: 682818292
1 parent 2f6f308 commit 0da0145

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

policy/src/main/java/dev/cel/policy/CelPolicyYamlConfigParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ private CelPolicyConfig parseYaml(String source, String description)
343343
.orElseThrow(
344344
() ->
345345
new CelPolicyValidationException(
346-
String.format("YAML document is malformed: %s", source)));
346+
String.format("YAML document empty or malformed: %s", source)));
347347
node = yamlNode;
348348
} catch (RuntimeException e) {
349349
throw new CelPolicyValidationException("YAML document is malformed: " + e.getMessage(), e);

policy/src/main/java/dev/cel/policy/CelPolicyYamlParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ private CelPolicy parseYaml() throws CelPolicyValidationException {
7373
.orElseThrow(
7474
() ->
7575
new CelPolicyValidationException(
76-
String.format("YAML document is malformed: %s", policySourceString)));
76+
String.format(
77+
"YAML document empty or malformed: %s", policySourceString)));
7778
node = yamlNode;
7879
} catch (RuntimeException e) {
7980
throw new CelPolicyValidationException("YAML document is malformed: " + e.getMessage(), e);

policy/src/test/java/dev/cel/policy/CelPolicyYamlConfigParserTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public final class CelPolicyYamlConfigParserTest {
4343
private static final CelPolicyConfigParser POLICY_CONFIG_PARSER =
4444
CelPolicyParserFactory.newYamlConfigParser();
4545

46+
@Test
47+
public void config_setEmpty() throws Exception {
48+
assertThrows(CelPolicyValidationException.class, () -> POLICY_CONFIG_PARSER.parse(""));
49+
}
50+
4651
@Test
4752
public void config_setBasicProperties() throws Exception {
4853
String yamlConfig = "name: hello\n" + "description: empty\n" + "container: pb.pkg\n";

policy/src/test/java/dev/cel/policy/CelPolicyYamlParserTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public void parseYamlPolicy_success(@TestParameter TestYamlPolicy yamlPolicy) th
4343
assertThat(policy.policySource().getDescription()).isEqualTo(description);
4444
}
4545

46+
@Test
47+
public void parser_setEmpty() throws Exception {
48+
assertThrows(CelPolicyValidationException.class, () -> POLICY_PARSER.parse("", ""));
49+
}
50+
4651
@Test
4752
public void parseYamlPolicy_withExplanation() throws Exception {
4853
String policySource =

0 commit comments

Comments
 (0)