diff --git a/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtils.java b/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtils.java index f7bcf63035bc8..df51d0f4049e6 100644 --- a/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtils.java +++ b/libs/entitlement/src/main/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtils.java @@ -81,6 +81,10 @@ public static Map createPluginPolicies( return pluginPolicies; } + /** + * @throws PolicyParserException if the supplied policy is formatted incorrectly + * @throws IllegalStateException for any other error parsing the patch, such as nonexistent module names + */ public static Policy parseEncodedPolicyIfExists( String encodedPolicy, String version, @@ -106,11 +110,8 @@ public static Policy parseEncodedPolicyIfExists( version ); } - } catch (Exception ex) { - logger.warn( - Strings.format("Found a policy patch with invalid content. The patch will not be applied. Layer [%s]", layerName), - ex - ); + } catch (Exception e) { + throw new IllegalStateException("Unable to parse policy patch for layer [" + layerName + "]", e); } } return null; diff --git a/libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtilsTests.java b/libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtilsTests.java index bb77f9c6a83ba..ed61087f7163c 100644 --- a/libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtilsTests.java +++ b/libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyUtilsTests.java @@ -134,6 +134,7 @@ public void testNoPatchWithVersionMismatch() { public void testNoPatchWithValidationError() { + // Nonexistent module names var policyPatch = """ versions: - 9.0.0 @@ -149,13 +150,15 @@ public void testNoPatchWithValidationError() { StandardCharsets.UTF_8 ); - var policy = PolicyUtils.parseEncodedPolicyIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of()); - - assertThat(policy, nullValue()); + assertThrows( + IllegalStateException.class, + () -> PolicyUtils.parseEncodedPolicyIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of()) + ); } public void testNoPatchWithParsingError() { + // no or field var policyPatch = """ entitlement-module-name: - load_native_libraries @@ -167,9 +170,10 @@ public void testNoPatchWithParsingError() { StandardCharsets.UTF_8 ); - var policy = PolicyUtils.parseEncodedPolicyIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of()); - - assertThat(policy, nullValue()); + assertThrows( + IllegalStateException.class, + () -> PolicyUtils.parseEncodedPolicyIfExists(base64EncodedPolicy, "9.0.0", true, "test-plugin", Set.of()) + ); } public void testMergeScopes() {