Skip to content

Commit 6c1b7fd

Browse files
committed
More comments for meta-tests
1 parent c53e10a commit 6c1b7fd

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

server/src/test/java/org/elasticsearch/bootstrap/EntitlementMetaTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import org.elasticsearch.core.SuppressForbidden;
1313
import org.elasticsearch.test.ESTestCase;
14+
import org.elasticsearch.test.ESTestCase.WithEntitlementsOnTestCode;
1415

1516
import java.io.IOException;
1617
import java.nio.file.Path;
@@ -31,11 +32,9 @@
3132
* Naturally, there are very few candidates, because most code doesn't fail entitlement checks:
3233
* really just the entitlement self-test we do at startup. Hence, that's what we use here.
3334
* <p>
34-
* Even then, we cannot call this from someplace outside the server, because in other places,
35-
* we deliberately don't check entitlements on dependencies that aren't used in production,
36-
* and other places like {@code libs} don't depend on server at runtime. Hence, this test
37-
* must be in {@code server}, rather than {@code libs/entitlement}, even if the latter
38-
* seems like a more natural choice.
35+
* Since we want to call the self-test, which is in the server, we can't call it
36+
* from a place like the entitlement library tests, because those deliberately do not
37+
* have a dependency on the server code. Hence, this test lives here in the server tests.
3938
*
4039
* @see WithoutEntitlementsMetaTests
4140
* @see WithEntitlementsOnTestCodeMetaTests
@@ -45,8 +44,13 @@ public void testSelfTestPasses() {
4544
Elasticsearch.entitlementSelfTest();
4645
}
4746

47+
/**
48+
* Unless {@link WithEntitlementsOnTestCode} is specified, sensitive methods <em>can</em>
49+
* be called from test code.
50+
*/
4851
@SuppressForbidden(reason = "Testing that a forbidden API is allowed under these circumstances")
4952
public void testForbiddenActionAllowedInTestCode() throws IOException {
53+
// If entitlements were enforced, this would throw.
5054
Path.of(".").toRealPath();
5155
}
5256
}

server/src/test/java/org/elasticsearch/bootstrap/WithEntitlementsOnTestCodeMetaTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717
import java.nio.file.Path;
1818

1919
/**
20-
* Tests {@link WithEntitlementsOnTestCode}.
20+
* A version of {@link EntitlementMetaTests} that tests {@link WithEntitlementsOnTestCode}.
2121
*
2222
* @see EntitlementMetaTests
2323
* @see WithoutEntitlementsMetaTests
2424
*/
2525
@WithEntitlementsOnTestCode
2626
public class WithEntitlementsOnTestCodeMetaTests extends ESTestCase {
27+
/**
28+
* {@link WithEntitlementsOnTestCode} should not affect this, since the sensitive method
29+
* is called from server code. The self-test should pass as usual.
30+
*/
2731
public void testSelfTestPasses() {
2832
Elasticsearch.entitlementSelfTest();
2933
}

server/src/test/java/org/elasticsearch/bootstrap/WithoutEntitlementsMetaTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,27 @@
1717
import java.nio.file.Path;
1818

1919
/**
20-
* Tests {@link WithoutEntitlements}.
20+
* A version of {@link EntitlementMetaTests} that tests {@link WithoutEntitlements}.
2121
*
2222
* @see EntitlementMetaTests
2323
* @see WithEntitlementsOnTestCodeMetaTests
2424
*/
2525
@WithoutEntitlements
2626
public class WithoutEntitlementsMetaTests extends ESTestCase {
27+
/**
28+
* Without enforcement of entitlements, {@link Elasticsearch#entitlementSelfTest} will fail and throw.
29+
*/
2730
public void testSelfTestFails() {
2831
assertThrows(IllegalStateException.class, Elasticsearch::entitlementSelfTest);
2932
}
3033

34+
/**
35+
* A forbidden action called from test code should be allowed,
36+
* with or without {@link WithoutEntitlements}.
37+
*/
3138
@SuppressForbidden(reason = "Testing that a forbidden API is allowed under these circumstances")
3239
public void testForbiddenActionAllowed() throws IOException {
40+
// If entitlements were enforced, this would throw
3341
Path.of(".").toRealPath();
3442
}
3543
}

0 commit comments

Comments
 (0)