Skip to content

Commit 308e562

Browse files
Expands sample plugin integration tests to cover multiple scenarios
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
1 parent 0a54de6 commit 308e562

9 files changed

+706
-832
lines changed

sample-resource-plugin/src/integrationTest/java/org/opensearch/sample/AbstractSampleResourcePluginFeatureEnabledTests.java

+466
Large diffs are not rendered by default.

sample-resource-plugin/src/integrationTest/java/org/opensearch/sample/AbstractSampleResourcePluginTests.java

+22-17
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,34 @@
1919
import static org.opensearch.security.dlic.rest.support.Utils.PLUGIN_RESOURCE_ROUTE_PREFIX;
2020

2121
/**
22-
* These tests run with security enabled
22+
* Abstract class for sample resource plugin tests. Provides common constants and utility methods for testing. This class is not intended to be
23+
* instantiated directly. It is extended by {@link AbstractSampleResourcePluginFeatureEnabledTests}, {@link SampleResourcePluginFeatureDisabledTests}, {@link org.opensearch.sample.nonsystemindex.AbstractResourcePluginNonSystemIndexTests}
2324
*/
2425
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
2526
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
26-
public class AbstractSampleResourcePluginTests {
27+
public abstract class AbstractSampleResourcePluginTests {
2728

28-
final static TestSecurityConfig.User SHARED_WITH_USER = new TestSecurityConfig.User("resource_sharing_test_user").roles(
29+
protected final static TestSecurityConfig.User SHARED_WITH_USER = new TestSecurityConfig.User("resource_sharing_test_user").roles(
2930
new TestSecurityConfig.Role("shared_role").indexPermissions("*").on("*").clusterPermissions("*")
3031
);
3132

32-
static final String SAMPLE_RESOURCE_CREATE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/create";
33-
static final String SAMPLE_RESOURCE_GET_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/get";
34-
static final String SAMPLE_RESOURCE_UPDATE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/update";
35-
static final String SAMPLE_RESOURCE_DELETE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/delete";
36-
static final String SAMPLE_RESOURCE_SHARE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/share";
37-
static final String SAMPLE_RESOURCE_REVOKE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/revoke";
33+
protected final static TestSecurityConfig.User SHARED_WITH_USER_LIMITED_PERMISSIONS = new TestSecurityConfig.User(
34+
"resource_sharing_test_user"
35+
).roles(new TestSecurityConfig.Role("shared_role").indexPermissions("*").on(RESOURCE_INDEX_NAME));
36+
37+
protected static final String SAMPLE_RESOURCE_CREATE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/create";
38+
protected static final String SAMPLE_RESOURCE_GET_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/get";
39+
protected static final String SAMPLE_RESOURCE_UPDATE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/update";
40+
protected static final String SAMPLE_RESOURCE_DELETE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/delete";
41+
protected static final String SAMPLE_RESOURCE_SHARE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/share";
42+
protected static final String SAMPLE_RESOURCE_REVOKE_ENDPOINT = SAMPLE_RESOURCE_PLUGIN_PREFIX + "/revoke";
3843
private static final String PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH = PLUGIN_RESOURCE_ROUTE_PREFIX.replaceFirst("/", "");
39-
static final String SECURITY_RESOURCE_LIST_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/list";
40-
static final String SECURITY_RESOURCE_SHARE_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/share";
41-
static final String SECURITY_RESOURCE_VERIFY_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/verify_access";
42-
static final String SECURITY_RESOURCE_REVOKE_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/revoke";
44+
protected static final String SECURITY_RESOURCE_LIST_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/list";
45+
protected static final String SECURITY_RESOURCE_SHARE_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/share";
46+
protected static final String SECURITY_RESOURCE_VERIFY_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/verify_access";
47+
protected static final String SECURITY_RESOURCE_REVOKE_ENDPOINT = PLUGIN_RESOURCE_ROUTE_PREFIX_NO_LEADING_SLASH + "/revoke";
4348

44-
static String shareWithPayloadSecurityApi(String resourceId) {
49+
protected static String shareWithPayloadSecurityApi(String resourceId) {
4550
return "{"
4651
+ "\"resource_id\":\""
4752
+ resourceId
@@ -61,7 +66,7 @@ static String shareWithPayloadSecurityApi(String resourceId) {
6166
+ "}";
6267
}
6368

64-
static String shareWithPayload() {
69+
protected static String shareWithPayload() {
6570
return "{"
6671
+ "\"share_with\":{"
6772
+ "\""
@@ -75,7 +80,7 @@ static String shareWithPayload() {
7580
+ "}";
7681
}
7782

78-
static String revokeAccessPayloadSecurityApi(String resourceId) {
83+
protected static String revokeAccessPayloadSecurityApi(String resourceId) {
7984
return "{"
8085
+ "\"resource_id\": \""
8186
+ resourceId
@@ -94,7 +99,7 @@ static String revokeAccessPayloadSecurityApi(String resourceId) {
9499
+ "}";
95100
}
96101

97-
static String revokeAccessPayload() {
102+
protected static String revokeAccessPayload() {
98103
return "{"
99104
+ "\"entities_to_revoke\": {"
100105
+ "\"users\": [\""

sample-resource-plugin/src/integrationTest/java/org/opensearch/sample/SampleResourcePluginFeatureDisabledTests.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010

1111
import java.util.Map;
1212

13-
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
1413
import org.apache.http.HttpStatus;
1514
import org.junit.After;
1615
import org.junit.ClassRule;
1716
import org.junit.Test;
18-
import org.junit.runner.RunWith;
1917

2018
import org.opensearch.painless.PainlessModulePlugin;
2119
import org.opensearch.test.framework.cluster.ClusterManager;
@@ -32,11 +30,8 @@
3230
import static org.opensearch.test.framework.TestSecurityConfig.User.USER_ADMIN;
3331

3432
/**
35-
* These tests run with security disabled
36-
*
33+
* These tests run with resource sharing feature disabled.
3734
*/
38-
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
39-
@ThreadLeakScope(ThreadLeakScope.Scope.NONE)
4035
public class SampleResourcePluginFeatureDisabledTests extends AbstractSampleResourcePluginTests {
4136

4237
@ClassRule

0 commit comments

Comments
 (0)