Skip to content

Add TestEntitlementsRule and node grants for testing #132077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Aug 5, 2025
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public Path nodeConfigPath(int nodeOrdinal) {
0,
"other",
Arrays.asList(getTestTransportPlugin(), MockHttpTransport.TestPlugin.class),
Function.identity()
Function.identity(),
TEST_ENTITLEMENTS::addEntitledNodePaths
);
try {
other.beforeTest(random());
Expand Down Expand Up @@ -137,7 +138,8 @@ public Path nodeConfigPath(int nodeOrdinal) {
0,
"other",
Arrays.asList(getTestTransportPlugin(), MockHttpTransport.TestPlugin.class),
Function.identity()
Function.identity(),
TEST_ENTITLEMENTS::addEntitledNodePaths
);
try (var mockLog = MockLog.capture(JoinHelper.class)) {
mockLog.addExpectation(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public Path nodeConfigPath(int nodeOrdinal) {
InternalSettingsPlugin.class,
getTestTransportPlugin()
),
Function.identity()
Function.identity(),
TEST_ENTITLEMENTS::addEntitledNodePaths
);
secondCluster.beforeTest(random());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
package org.elasticsearch.bootstrap;

import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.entitlement.bootstrap.TestEntitlementBootstrap;
import org.elasticsearch.entitlement.bootstrap.TestEntitlementsRule;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.ESTestCase.WithEntitlementsOnTestCode;

import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -42,7 +41,7 @@
*/
public class EntitlementMetaTests extends ESTestCase {
public void testSelfTestPasses() {
assumeTrue("Not yet working in serverless", TestEntitlementBootstrap.isEnabledForTest());
assumeTrue("Not yet working in serverless", TestEntitlementsRule.isEnabledForTests());
Elasticsearch.entitlementSelfTest();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package org.elasticsearch.bootstrap;

import org.elasticsearch.core.SuppressForbidden;
import org.elasticsearch.entitlement.bootstrap.TestEntitlementBootstrap;
import org.elasticsearch.entitlement.bootstrap.TestEntitlementsRule;
import org.elasticsearch.entitlement.runtime.api.NotEntitledException;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.ESTestCase.WithEntitlementsOnTestCode;
Expand All @@ -30,13 +30,13 @@ public class WithEntitlementsOnTestCodeMetaTests extends ESTestCase {
* is called from server code. The self-test should pass as usual.
*/
public void testSelfTestPasses() {
assumeTrue("Not yet working in serverless", TestEntitlementBootstrap.isEnabledForTest());
assumeTrue("Not yet working in serverless", TestEntitlementsRule.isEnabledForTests());
Elasticsearch.entitlementSelfTest();
}

@SuppressForbidden(reason = "Testing that a forbidden API is disallowed")
public void testForbiddenActionDenied() {
assumeTrue("Not yet working in serverless", TestEntitlementBootstrap.isEnabledForTest());
assumeTrue("Not yet working in serverless", TestEntitlementsRule.isEnabledForTests());
assertThrows(NotEntitledException.class, () -> Path.of(".").toRealPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ private Node startNode() throws NodeValidationException {
Node node = new MockNode(
settings,
Arrays.asList(getTestTransportPlugin(), MockHttpTransport.TestPlugin.class, InternalSettingsPlugin.class),
true
true,
() -> {}
);
node.start();
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.Booleans;
import org.elasticsearch.core.PathUtils;
import org.elasticsearch.entitlement.bootstrap.TestEntitlementBootstrap;
import org.elasticsearch.entitlement.bootstrap.TestEntitlementsRule;
import org.elasticsearch.jdk.JarHell;

import java.io.IOException;
Expand Down Expand Up @@ -75,7 +75,7 @@ public class BootstrapForTesting {

// Fire up entitlements
try {
TestEntitlementBootstrap.bootstrap(javaTmpDir);
TestEntitlementsRule.initialize(javaTmpDir);
} catch (IOException e) {
throw new IllegalStateException(e.getClass().getSimpleName() + " while initializing entitlements for tests", e);
}
Expand Down
Loading