Skip to content

Commit 998c62c

Browse files
committed
Revert "Trivially allow test utility classes if annotated with @WithoutEntitlements"
This reverts commit 3a086de.
1 parent c400748 commit 998c62c

File tree

2 files changed

+2
-20
lines changed

2 files changed

+2
-20
lines changed

test/framework/src/main/java/org/elasticsearch/entitlement/runtime/policy/TestPolicyManager.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.concurrent.ConcurrentHashMap;
2626
import java.util.function.Function;
2727

28-
import static java.lang.StackWalker.Option.RETAIN_CLASS_REFERENCE;
2928
import static java.util.Objects.requireNonNull;
3029

3130
public class TestPolicyManager extends PolicyManager {
@@ -117,30 +116,15 @@ boolean isTriviallyAllowed(Class<?> requestingClass) {
117116
if (isTriviallyAllowingTestCode && isTestCode(requestingClass)) {
118117
return true;
119118
}
120-
if(super.isTriviallyAllowed(requestingClass)){
121-
return true;
122-
};
123-
return isStackWithoutEntitlements();
119+
return super.isTriviallyAllowed(requestingClass);
124120
}
125121

126122
@Override
127123
protected Collection<Path> getComponentPathsFromClass(Class<?> requestingClass) {
128124
return classpath; // required to grant read access to the production source and test resources
129125
}
130126

131-
private static boolean hasWithoutEntitlements(Class<?> clazz) {
132-
return clazz.getAnnotation(ESTestCase.WithoutEntitlements.class) != null;
133-
}
134-
135-
private static boolean isStackWithoutEntitlements() {
136-
return StackWalker.getInstance(RETAIN_CLASS_REFERENCE)
137-
.walk(frames -> frames
138-
.map(StackWalker.StackFrame::getDeclaringClass)
139-
.filter(c -> isEntitlementClass(c) == false)
140-
.anyMatch(TestPolicyManager::hasWithoutEntitlements));
141-
}
142-
143-
private static boolean isEntitlementClass(Class<?> requestingClass) {
127+
private boolean isEntitlementClass(Class<?> requestingClass) {
144128
return requestingClass.getPackageName().startsWith("org.elasticsearch.entitlement")
145129
&& (requestingClass.getName().contains("Test") == false);
146130
}

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/test/SecurityTestUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.elasticsearch.index.Index;
2222
import org.elasticsearch.index.shard.ShardId;
2323
import org.elasticsearch.test.ESTestCase;
24-
import org.elasticsearch.test.ESTestCase.WithoutEntitlements;
2524

2625
import java.io.IOException;
2726
import java.io.OutputStream;
@@ -40,7 +39,6 @@
4039
import static org.elasticsearch.cluster.routing.ShardRouting.UNAVAILABLE_EXPECTED_SHARD_SIZE;
4140
import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SECURITY_MAIN_ALIAS;
4241

43-
@WithoutEntitlements
4442
public class SecurityTestUtils {
4543

4644
public static String writeFile(Path folder, String name, byte[] content) {

0 commit comments

Comments
 (0)