Skip to content

Commit 7c11547

Browse files
committed
Entitlement IT cases for reflection
1 parent 0cf0009 commit 7c11547

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/DummyImplementations.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@
5252
* <p>
5353
* A bit like Mockito but way more painful.
5454
*/
55-
class DummyImplementations {
56-
57-
static class DummyLocaleServiceProvider extends LocaleServiceProvider {
55+
public class DummyImplementations {
5856

57+
public static class DummyLocaleServiceProvider extends LocaleServiceProvider {
5958
@Override
6059
public Locale[] getAvailableLocales() {
6160
throw unexpected();

libs/entitlement/qa/entitlement-test-plugin/src/main/java/org/elasticsearch/entitlement/qa/test/RestEntitlementsCheckAction.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {
9696

9797
private static final Map<String, CheckAction> checkActions = Stream.concat(
9898
Stream.<Entry<String, CheckAction>>of(
99+
entry("static_reflection", deniedToPlugins(RestEntitlementsCheckAction::staticMethodNeverEntitledViaReflection)),
100+
entry("nonstatic_reflection", deniedToPlugins(RestEntitlementsCheckAction::nonstaticMethodNeverEntitledViaReflection)),
101+
entry("constructor_reflection", deniedToPlugins(RestEntitlementsCheckAction::constructorNeverEntitledViaReflection)),
99102
entry("runtime_exit", deniedToPlugins(RestEntitlementsCheckAction::runtimeExit)),
100103
entry("runtime_halt", deniedToPlugins(RestEntitlementsCheckAction::runtimeHalt)),
101104
entry("system_exit", deniedToPlugins(RestEntitlementsCheckAction::systemExit)),
@@ -338,6 +341,11 @@ private static void systemExit() {
338341
System.exit(123);
339342
}
340343

344+
private static void staticMethodNeverEntitledViaReflection() throws Exception {
345+
Method systemExit = System.class.getMethod("exit", int.class);
346+
systemExit.invoke(null, 123);
347+
}
348+
341349
private static void createClassLoader() throws IOException {
342350
try (var classLoader = new URLClassLoader("test", new URL[0], RestEntitlementsCheckAction.class.getClassLoader())) {
343351
logger.info("Created URLClassLoader [{}]", classLoader.getName());
@@ -348,6 +356,11 @@ private static void processBuilder_start() throws IOException {
348356
new ProcessBuilder("").start();
349357
}
350358

359+
private static void nonstaticMethodNeverEntitledViaReflection() throws Exception {
360+
Method processBuilderStart = ProcessBuilder.class.getMethod("start");
361+
processBuilderStart.invoke(new ProcessBuilder(""));
362+
}
363+
351364
private static void processBuilder_startPipeline() throws IOException {
352365
ProcessBuilder.startPipeline(List.of());
353366
}
@@ -386,6 +399,10 @@ private static void setHttpsConnectionProperties() {
386399
new DummyLocaleServiceProvider();
387400
}
388401

402+
private static void constructorNeverEntitledViaReflection() throws Exception {
403+
DummyLocaleServiceProvider.class.getConstructor().newInstance();
404+
}
405+
389406
private static void breakIteratorProvider$() {
390407
new DummyBreakIteratorProvider();
391408
}

libs/entitlement/qa/src/javaRestTest/java/org/elasticsearch/entitlement/qa/EntitlementsTestRule.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ protected void before() throws Throwable {
5656
.systemProperty("es.entitlements.enabled", "true")
5757
.systemProperty("es.entitlements.testdir", () -> testDir.getRoot().getAbsolutePath())
5858
.setting("xpack.security.enabled", "false")
59+
.setting("logger.org.elasticsearch.entitlement", "TRACE")
5960
.build();
6061
ruleChain = RuleChain.outerRule(testDir).around(tempDirSetup).around(cluster);
6162
}

0 commit comments

Comments
 (0)