Skip to content

Commit f0ed569

Browse files
committed
more tests
1 parent dcc6265 commit f0ed569

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

libs/entitlement/src/test/java/org/elasticsearch/entitlement/runtime/policy/PolicyParserTests.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ public static ConstructorAndMethodEntitlement create(String s) {
6262
public ConstructorAndMethodEntitlement(String s) {}
6363
}
6464

65+
public static class NonStaticMethodEntitlement implements Entitlement {
66+
@ExternalEntitlement
67+
public NonStaticMethodEntitlement create() {
68+
return new NonStaticMethodEntitlement();
69+
}
70+
}
71+
6572
public void testGetEntitlementTypeName() {
6673
assertEquals("create_class_loader", PolicyParser.getEntitlementTypeName(CreateClassLoaderEntitlement.class));
6774

@@ -235,4 +242,21 @@ public void testConstructorAndMethodAnnotated() throws IOException {
235242
)
236243
);
237244
}
245+
246+
public void testNonStaticMethodAnnotated() throws IOException {
247+
var parser = new PolicyParser(new ByteArrayInputStream("""
248+
entitlement-module-name:
249+
- non_static
250+
""".getBytes(StandardCharsets.UTF_8)), "test-policy.yaml", true, Map.of("non_static", NonStaticMethodEntitlement.class));
251+
252+
var e = expectThrows(IllegalStateException.class, parser::parsePolicy);
253+
assertThat(
254+
e.getMessage(),
255+
equalTo(
256+
"entitlement class "
257+
+ "[org.elasticsearch.entitlement.runtime.policy.PolicyParserTests$NonStaticMethodEntitlement]"
258+
+ " has non-static method annotated with ExternalEntitlement"
259+
)
260+
);
261+
}
238262
}

0 commit comments

Comments
 (0)