Skip to content

Commit

Permalink
Remove entitlement reflection ITs. (elastic#121550) (elastic#121562)
Browse files Browse the repository at this point in the history
This is best tested in unit tests, not REST actions.
  • Loading branch information
prdoyle authored Feb 3, 2025
1 parent bbfa4dc commit 86de107
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@
* <p>
* A bit like Mockito but way more painful.
*/
public class DummyImplementations {
class DummyImplementations {

static class DummyLocaleServiceProvider extends LocaleServiceProvider {

public static class DummyLocaleServiceProvider extends LocaleServiceProvider {
@Override
public Locale[] getAvailableLocales() {
throw unexpected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ static CheckAction alwaysDenied(CheckedRunnable<Exception> action) {

private static final Map<String, CheckAction> checkActions = Stream.concat(
Stream.<Entry<String, CheckAction>>of(
entry("static_reflection", deniedToPlugins(RestEntitlementsCheckAction::staticMethodNeverEntitledViaReflection)),
entry("nonstatic_reflection", deniedToPlugins(RestEntitlementsCheckAction::nonstaticMethodNeverEntitledViaReflection)),
entry("constructor_reflection", deniedToPlugins(RestEntitlementsCheckAction::constructorNeverEntitledViaReflection)),
entry("runtime_exit", deniedToPlugins(RestEntitlementsCheckAction::runtimeExit)),
entry("runtime_halt", deniedToPlugins(RestEntitlementsCheckAction::runtimeHalt)),
entry("system_exit", deniedToPlugins(RestEntitlementsCheckAction::systemExit)),
Expand Down Expand Up @@ -341,11 +338,6 @@ private static void systemExit() {
System.exit(123);
}

private static void staticMethodNeverEntitledViaReflection() throws Exception {
Method systemExit = System.class.getMethod("exit", int.class);
systemExit.invoke(null, 123);
}

private static void createClassLoader() throws IOException {
try (var classLoader = new URLClassLoader("test", new URL[0], RestEntitlementsCheckAction.class.getClassLoader())) {
logger.info("Created URLClassLoader [{}]", classLoader.getName());
Expand All @@ -356,11 +348,6 @@ private static void processBuilder_start() throws IOException {
new ProcessBuilder("").start();
}

private static void nonstaticMethodNeverEntitledViaReflection() throws Exception {
Method processBuilderStart = ProcessBuilder.class.getMethod("start");
processBuilderStart.invoke(new ProcessBuilder(""));
}

private static void processBuilder_startPipeline() throws IOException {
ProcessBuilder.startPipeline(List.of());
}
Expand Down Expand Up @@ -399,10 +386,6 @@ private static void setHttpsConnectionProperties() {
new DummyLocaleServiceProvider();
}

private static void constructorNeverEntitledViaReflection() throws Exception {
DummyLocaleServiceProvider.class.getConstructor().newInstance();
}

private static void breakIteratorProvider$() {
new DummyBreakIteratorProvider();
}
Expand Down

0 comments on commit 86de107

Please sign in to comment.