Skip to content

Commit f8c2544

Browse files
committed
Thorough integration tests for index API authorization
Signed-off-by: Nils Bandener <[email protected]>
1 parent 9c69f34 commit f8c2544

20 files changed

+5889
-235
lines changed

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,11 @@ allprojects {
573573
integrationTestImplementation 'org.slf4j:slf4j-api:2.0.12'
574574
integrationTestImplementation 'com.selectivem.collections:special-collections-complete:1.4.0'
575575
integrationTestImplementation "org.opensearch.plugin:lang-painless:${opensearch_version}"
576+
577+
integrationTestImplementation ('com.jayway.jsonpath:json-path:2.9.0') {
578+
exclude(group: 'net.minidev', module: 'json-smart')
579+
}
580+
integrationTestImplementation 'net.minidev:json-smart:2.6.0'
576581
}
577582
}
578583

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)