@@ -74,7 +74,7 @@ public class TestEntitlementsRule implements TestRule {
7474 static {
7575 PathLookup pathLookup = new TestPathLookup (BASE_DIR_PATHS );
7676 try {
77- if (isEnabledForTest ()) {
77+ if (isEnabledForTests ()) {
7878 POLICY_MANAGER = createPolicyManager (pathLookup );
7979 loadAgent (POLICY_MANAGER , pathLookup );
8080 } else {
@@ -107,6 +107,7 @@ public Statement apply(Statement base, Description description) {
107107 public void evaluate () throws Throwable {
108108 if (active .compareAndSet (false , true )) {
109109 try {
110+ BASE_DIR_PATHS .keySet ().retainAll (List .of (TEMP ));
110111 POLICY_MANAGER .setActive (false == withoutEntitlements );
111112 POLICY_MANAGER .setTriviallyAllowingTestCode (false == withEntitlementsOnTestCode );
112113 if (entitledPackages != null ) {
@@ -115,16 +116,12 @@ public void evaluate() throws Throwable {
115116 } else {
116117 POLICY_MANAGER .setEntitledTestPackages ();
117118 }
118- BASE_DIR_PATHS .keySet ().retainAll (List .of (TEMP ));
119119 POLICY_MANAGER .clearModuleEntitlementsCache ();
120120 // evaluate the suite
121121 base .evaluate ();
122122 } finally {
123- POLICY_MANAGER .setActive (false );
124- POLICY_MANAGER .setTriviallyAllowingTestCode (true );
125- POLICY_MANAGER .setEntitledTestPackages ();
126123 BASE_DIR_PATHS .keySet ().retainAll (List .of (TEMP ));
127- POLICY_MANAGER .clearModuleEntitlementsCache ();
124+ POLICY_MANAGER .resetAfterTest ();
128125 active .set (false );
129126 }
130127 } else {
@@ -144,6 +141,7 @@ public void evaluate() throws Throwable {
144141 /**
145142 * Temporarily adds node paths based entitlements based on a node's {@code settings} and {@code configPath}
146143 * until the returned handle is closed.
144+ * @see PathLookup
147145 */
148146 public Closeable addEntitledNodePaths (Settings settings , Path configPath ) {
149147 if (POLICY_MANAGER == null ) {
@@ -250,7 +248,7 @@ private static BiFunction<BaseDir, Collection<Path>, Collection<Path>> baseDirMo
250248 };
251249 }
252250
253- public static boolean isEnabledForTest () {
251+ public static boolean isEnabledForTests () {
254252 return Booleans .parseBoolean (System .getProperty ("es.entitlement.enableForTests" , "false" ));
255253 }
256254
@@ -272,7 +270,7 @@ private static TestPolicyManager createPolicyManager(PathLookup pathLookup) thro
272270
273271 String separator = System .getProperty ("path.separator" );
274272
275- // In productions , plugins would have access to their respective bundle directories,
273+ // In production , plugins would have access to their respective bundle directories,
276274 // and so they'd be able to read from their jars. In testing, we approximate this
277275 // by considering the entire classpath to be "source paths" of all plugins. This
278276 // also has the effect of granting read access to everything on the test-only classpath,
0 commit comments