-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Entitlements] Moving and refactoring IT tests (#118254)
- Loading branch information
Showing
21 changed files
with
537 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.build' | ||
|
||
dependencies { | ||
implementation project(':server') | ||
implementation project(':libs:logging') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
module org.elasticsearch.entitlement.qa.common { | ||
requires org.elasticsearch.server; | ||
requires org.elasticsearch.base; | ||
requires org.elasticsearch.logging; | ||
|
||
exports org.elasticsearch.entitlement.qa.common; | ||
} |
112 changes: 112 additions & 0 deletions
112
...on/src/main/java/org/elasticsearch/entitlement/qa/common/RestEntitlementsCheckAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.entitlement.qa.common; | ||
|
||
import org.elasticsearch.client.internal.node.NodeClient; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.core.SuppressForbidden; | ||
import org.elasticsearch.logging.LogManager; | ||
import org.elasticsearch.logging.Logger; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.RestResponse; | ||
import org.elasticsearch.rest.RestStatus; | ||
|
||
import java.io.IOException; | ||
import java.io.UncheckedIOException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static java.util.Map.entry; | ||
import static org.elasticsearch.rest.RestRequest.Method.GET; | ||
|
||
public class RestEntitlementsCheckAction extends BaseRestHandler { | ||
private static final Logger logger = LogManager.getLogger(RestEntitlementsCheckAction.class); | ||
private final String prefix; | ||
|
||
private record CheckAction(Runnable action, boolean isServerOnly) { | ||
|
||
static CheckAction serverOnly(Runnable action) { | ||
return new CheckAction(action, true); | ||
} | ||
|
||
static CheckAction serverAndPlugin(Runnable action) { | ||
return new CheckAction(action, false); | ||
} | ||
} | ||
|
||
private static final Map<String, CheckAction> checkActions = Map.ofEntries( | ||
entry("system_exit", CheckAction.serverOnly(RestEntitlementsCheckAction::systemExit)), | ||
entry("create_classloader", CheckAction.serverAndPlugin(RestEntitlementsCheckAction::createClassLoader)) | ||
); | ||
|
||
@SuppressForbidden(reason = "Specifically testing System.exit") | ||
private static void systemExit() { | ||
logger.info("Calling System.exit(123);"); | ||
System.exit(123); | ||
} | ||
|
||
private static void createClassLoader() { | ||
logger.info("Calling new URLClassLoader"); | ||
try (var classLoader = new URLClassLoader("test", new URL[0], RestEntitlementsCheckAction.class.getClassLoader())) { | ||
logger.info("Created URLClassLoader [{}]", classLoader.getName()); | ||
} catch (IOException e) { | ||
throw new UncheckedIOException(e); | ||
} | ||
} | ||
|
||
public RestEntitlementsCheckAction(String prefix) { | ||
this.prefix = prefix; | ||
} | ||
|
||
public static Set<String> getServerAndPluginsCheckActions() { | ||
return checkActions.entrySet() | ||
.stream() | ||
.filter(kv -> kv.getValue().isServerOnly() == false) | ||
.map(Map.Entry::getKey) | ||
.collect(Collectors.toSet()); | ||
} | ||
|
||
public static Set<String> getAllCheckActions() { | ||
return checkActions.keySet(); | ||
} | ||
|
||
@Override | ||
public List<Route> routes() { | ||
return List.of(new Route(GET, "/_entitlement/" + prefix + "/_check")); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "check_" + prefix + "_action"; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
logger.info("RestEntitlementsCheckAction rest handler [{}]", request.path()); | ||
var actionName = request.param("action"); | ||
if (Strings.isNullOrEmpty(actionName)) { | ||
throw new IllegalArgumentException("Missing action parameter"); | ||
} | ||
var checkAction = checkActions.get(actionName); | ||
if (checkAction == null) { | ||
throw new IllegalArgumentException(Strings.format("Unknown action [%s]", actionName)); | ||
} | ||
|
||
return channel -> { | ||
checkAction.action().run(); | ||
channel.sendResponse(new RestResponse(RestStatus.OK, Strings.format("Succesfully executed action [%s]", actionName))); | ||
}; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
libs/entitlement/qa/entitlement-allowed-nonmodular/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.base-internal-es-plugin' | ||
|
||
esplugin { | ||
name 'entitlement-allowed-nonmodular' | ||
description 'A non-modular test module that invokes entitlement checks that are supposed to be granted' | ||
classname 'org.elasticsearch.entitlement.qa.nonmodular.EntitlementAllowedNonModularPlugin' | ||
} | ||
|
||
dependencies { | ||
implementation project(':libs:entitlement:qa:common') | ||
} | ||
|
||
tasks.named("javadoc").configure { | ||
enabled = false | ||
} |
45 changes: 45 additions & 0 deletions
45
.../java/org/elasticsearch/entitlement/qa/nonmodular/EntitlementAllowedNonModularPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
package org.elasticsearch.entitlement.qa.nonmodular; | ||
|
||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.common.settings.IndexScopedSettings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.settings.SettingsFilter; | ||
import org.elasticsearch.entitlement.qa.common.RestEntitlementsCheckAction; | ||
import org.elasticsearch.features.NodeFeature; | ||
import org.elasticsearch.plugins.ActionPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.rest.RestHandler; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
public class EntitlementAllowedNonModularPlugin extends Plugin implements ActionPlugin { | ||
|
||
@Override | ||
public List<RestHandler> getRestHandlers( | ||
final Settings settings, | ||
NamedWriteableRegistry namedWriteableRegistry, | ||
final RestController restController, | ||
final ClusterSettings clusterSettings, | ||
final IndexScopedSettings indexScopedSettings, | ||
final SettingsFilter settingsFilter, | ||
final IndexNameExpressionResolver indexNameExpressionResolver, | ||
final Supplier<DiscoveryNodes> nodesInCluster, | ||
Predicate<NodeFeature> clusterSupportsFeature | ||
) { | ||
return List.of(new RestEntitlementsCheckAction("allowed_nonmodular")); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
...lement/qa/entitlement-allowed-nonmodular/src/main/plugin-metadata/entitlement-policy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALL-UNNAMED: | ||
- create_class_loader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.base-internal-es-plugin' | ||
|
||
esplugin { | ||
name 'entitlement-allowed' | ||
description 'A test module that invokes entitlement checks that are supposed to be granted' | ||
classname 'org.elasticsearch.entitlement.qa.EntitlementAllowedPlugin' | ||
} | ||
|
||
dependencies { | ||
implementation project(':libs:entitlement:qa:common') | ||
} | ||
|
||
tasks.named("javadoc").configure { | ||
enabled = false | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
libs/entitlement/qa/entitlement-allowed/src/main/java/module-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
module org.elasticsearch.entitlement.qa.allowed { | ||
requires org.elasticsearch.server; | ||
requires org.elasticsearch.base; | ||
requires org.elasticsearch.logging; | ||
requires org.elasticsearch.entitlement.qa.common; | ||
} |
45 changes: 45 additions & 0 deletions
45
...ment-allowed/src/main/java/org/elasticsearch/entitlement/qa/EntitlementAllowedPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
package org.elasticsearch.entitlement.qa; | ||
|
||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.node.DiscoveryNodes; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.settings.ClusterSettings; | ||
import org.elasticsearch.common.settings.IndexScopedSettings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.settings.SettingsFilter; | ||
import org.elasticsearch.entitlement.qa.common.RestEntitlementsCheckAction; | ||
import org.elasticsearch.features.NodeFeature; | ||
import org.elasticsearch.plugins.ActionPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.rest.RestHandler; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
public class EntitlementAllowedPlugin extends Plugin implements ActionPlugin { | ||
|
||
@Override | ||
public List<RestHandler> getRestHandlers( | ||
final Settings settings, | ||
NamedWriteableRegistry namedWriteableRegistry, | ||
final RestController restController, | ||
final ClusterSettings clusterSettings, | ||
final IndexScopedSettings indexScopedSettings, | ||
final SettingsFilter settingsFilter, | ||
final IndexNameExpressionResolver indexNameExpressionResolver, | ||
final Supplier<DiscoveryNodes> nodesInCluster, | ||
Predicate<NodeFeature> clusterSupportsFeature | ||
) { | ||
return List.of(new RestEntitlementsCheckAction("allowed")); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
libs/entitlement/qa/entitlement-allowed/src/main/plugin-metadata/entitlement-policy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
org.elasticsearch.entitlement.qa.common: | ||
- create_class_loader |
24 changes: 24 additions & 0 deletions
24
libs/entitlement/qa/entitlement-denied-nonmodular/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
apply plugin: 'elasticsearch.base-internal-es-plugin' | ||
|
||
esplugin { | ||
name 'entitlement-denied-nonmodular' | ||
description 'A non-modular test module that invokes non-granted entitlement and triggers exceptions' | ||
classname 'org.elasticsearch.entitlement.qa.nonmodular.EntitlementDeniedNonModularPlugin' | ||
} | ||
|
||
dependencies { | ||
implementation project(':libs:entitlement:qa:common') | ||
} | ||
|
||
tasks.named("javadoc").configure { | ||
enabled = false | ||
} |
Oops, something went wrong.