Skip to content

Commit 3afef7c

Browse files
authored
Thorough integration tests for index API authorization (#5632)
Signed-off-by: Nils Bandener <[email protected]>
1 parent e4da221 commit 3afef7c

27 files changed

+6979
-345
lines changed

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,10 @@ allprojects {
573573
}
574574
integrationTestImplementation 'org.slf4j:slf4j-api:2.0.12'
575575
integrationTestImplementation 'com.selectivem.collections:special-collections-complete:1.4.0'
576+
577+
integrationTestImplementation ('com.jayway.jsonpath:json-path:2.9.0') {
578+
exclude(group: 'net.minidev', module: 'json-smart')
579+
}
576580
}
577581
}
578582

src/integrationTest/java/org/opensearch/security/http/ServiceAccountAuthenticationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import org.junit.Test;
2121
import org.junit.runner.RunWith;
2222

23-
import org.opensearch.test.framework.TestIndex;
2423
import org.opensearch.test.framework.TestSecurityConfig;
2524
import org.opensearch.test.framework.cluster.ClusterManager;
2625
import org.opensearch.test.framework.cluster.LocalCluster;
2726
import org.opensearch.test.framework.cluster.TestRestClient;
27+
import org.opensearch.test.framework.data.TestIndex;
2828

2929
import static org.opensearch.security.support.ConfigConstants.SECURITY_RESTAPI_ROLES_ENABLED;
3030
import static org.opensearch.security.support.ConfigConstants.SECURITY_SYSTEM_INDICES_ENABLED_KEY;

src/integrationTest/java/org/opensearch/security/privileges/PrivilegesEvaluatorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
import org.opensearch.script.mustache.MustacheModulePlugin;
2121
import org.opensearch.script.mustache.RenderSearchTemplateAction;
22-
import org.opensearch.test.framework.TestIndex;
2322
import org.opensearch.test.framework.TestSecurityConfig;
2423
import org.opensearch.test.framework.TestSecurityConfig.Role;
2524
import org.opensearch.test.framework.cluster.ClusterManager;
2625
import org.opensearch.test.framework.cluster.LocalCluster;
2726
import org.opensearch.test.framework.cluster.TestRestClient;
27+
import org.opensearch.test.framework.data.TestIndex;
2828

2929
import static org.hamcrest.MatcherAssert.assertThat;
3030
import static org.hamcrest.Matchers.equalTo;

src/integrationTest/java/org/opensearch/security/privileges/dlsfls/FlsFmIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
import org.bouncycastle.util.encoders.Hex;
2929

3030
import org.opensearch.plugin.mapper.MapperSizePlugin;
31-
import org.opensearch.test.framework.TestData;
32-
import org.opensearch.test.framework.TestIndex;
3331
import org.opensearch.test.framework.TestSecurityConfig;
3432
import org.opensearch.test.framework.cluster.ClusterManager;
3533
import org.opensearch.test.framework.cluster.LocalCluster;
3634
import org.opensearch.test.framework.cluster.TestRestClient;
35+
import org.opensearch.test.framework.data.TestData;
36+
import org.opensearch.test.framework.data.TestIndex;
3737

3838
import com.rfksystems.blake2b.Blake2b;
3939

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
package org.opensearch.security.privileges.int_tests;
13+
14+
import java.util.Map;
15+
import java.util.function.Function;
16+
import java.util.function.Supplier;
17+
18+
import org.opensearch.test.framework.cluster.LocalCluster;
19+
20+
/**
21+
* This is one of the test parameter dimensions used by the *Authorization*IntTests test suites.
22+
* The test suites run on different cluster configurations; the possible cluster configurations are defined here.
23+
*/
24+
public enum ClusterConfig {
25+
LEGACY_PRIVILEGES_EVALUATION(
26+
"legacy",
27+
c -> c.doNotFailOnForbidden(true).nodeSettings(Map.of("plugins.security.system_indices.enabled", true)),
28+
true,
29+
false,
30+
false
31+
),
32+
LEGACY_PRIVILEGES_EVALUATION_SYSTEM_INDEX_PERMISSION(
33+
"legacy_system_index_perm",
34+
c -> c.doNotFailOnForbidden(true)
35+
.nodeSettings(
36+
Map.of("plugins.security.system_indices.enabled", true, "plugins.security.system_indices.permission.enabled", true)
37+
),
38+
true,
39+
true,
40+
false
41+
);
42+
43+
final String name;
44+
final Function<LocalCluster.Builder, LocalCluster.Builder> clusterConfiguration;
45+
final boolean legacyPrivilegeEvaluation;
46+
final boolean systemIndexPrivilegeEnabled;
47+
final boolean allowsEmptyResultSets;
48+
49+
private LocalCluster cluster;
50+
51+
ClusterConfig(
52+
String name,
53+
Function<LocalCluster.Builder, LocalCluster.Builder> clusterConfiguration,
54+
boolean legacyPrivilegeEvaluation,
55+
boolean systemIndexPrivilegeEnabled,
56+
boolean allowsEmptyResultSets
57+
) {
58+
this.name = name;
59+
this.clusterConfiguration = clusterConfiguration;
60+
this.legacyPrivilegeEvaluation = legacyPrivilegeEvaluation;
61+
this.systemIndexPrivilegeEnabled = systemIndexPrivilegeEnabled;
62+
this.allowsEmptyResultSets = allowsEmptyResultSets;
63+
}
64+
65+
LocalCluster cluster(Supplier<LocalCluster.Builder> clusterBuilder) {
66+
if (cluster == null) {
67+
cluster = this.clusterConfiguration.apply(clusterBuilder.get()).build();
68+
cluster.before();
69+
}
70+
return cluster;
71+
}
72+
73+
void shutdown() {
74+
if (cluster != null) {
75+
try {
76+
cluster.close();
77+
} catch (Exception e) {}
78+
cluster = null;
79+
}
80+
}
81+
82+
@Override
83+
public String toString() {
84+
return name;
85+
}
86+
}

0 commit comments

Comments
 (0)