Skip to content

Commit 5d67fd2

Browse files
cwperksopensearch-trigger-bot[bot]github-actions[bot]
authored
[Backport 2.x] Forward port integ test fixes to main branch (#4867) (#4868)
Signed-off-by: Craig Perkins <cwperx@amazon.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: opensearch-trigger-bot[bot] <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 55ff20e commit 5d67fd2

14 files changed

+200
-25
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ Run tests against local cluster:
7676
```bash
7777
./gradlew integTestRemote -Dtests.rest.cluster=localhost:9200 -Dtests.cluster=localhost:9200 -Dtests.clustername=docker-cluster -Dsecurity=true -Dhttps=true -Duser=admin -Dpassword=admin -Dcommon_utils.version="2.2.0.0"
7878
```
79+
OR
80+
```bash
81+
./scripts/integtest.sh
82+
```
7983
Note: To run against a remote cluster replace cluster-name and `localhost:9200` with the IPAddress:Port of that cluster.
8084

8185
Build artifacts (zip, deb, rpm):

build.gradle

+5-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,11 @@ task integrationTest(type: Test) {
569569
}
570570
}
571571

572-
tasks.integTest.dependsOn(integrationTest)
572+
tasks.named("integrationTest") {
573+
minHeapSize = "512m"
574+
maxHeapSize = "2g"
575+
}
576+
573577
tasks.integrationTest.finalizedBy(jacocoTestReport) // report is always generated after integration tests run
574578

575579
//run the integrationTest task before the check task

scripts/integtest.sh

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
function usage() {
6+
echo ""
7+
echo "This script is used to run integration tests for plugin installed on a remote OpenSearch/Dashboards cluster."
8+
echo "--------------------------------------------------------------------------"
9+
echo "Usage: $0 [args]"
10+
echo ""
11+
echo "Required arguments:"
12+
echo "None"
13+
echo ""
14+
echo "Optional arguments:"
15+
echo -e "-b BIND_ADDRESS\t, defaults to localhost | 127.0.0.1, can be changed to any IP or domain name for the cluster location."
16+
echo -e "-p BIND_PORT\t, defaults to 9200, can be changed to any port for the cluster location."
17+
echo -e "-s SECURITY_ENABLED\t(true | false), defaults to true. Specify the OpenSearch/Dashboards have security enabled or not."
18+
echo -e "-c CREDENTIAL\t(usename:password), no defaults, effective when SECURITY_ENABLED=true."
19+
echo -e "-h\tPrint this message."
20+
echo -e "-v OPENSEARCH_VERSION\t, no defaults"
21+
echo -e "-n SNAPSHOT\t, defaults to false"
22+
echo -e "-m CLUSTER_NAME\t, defaults to docker-cluster"
23+
echo "--------------------------------------------------------------------------"
24+
}
25+
26+
while getopts ":h:b:p:s:c:v:n:t:m:u:" arg; do
27+
case $arg in
28+
h)
29+
usage
30+
exit 1
31+
;;
32+
b)
33+
BIND_ADDRESS=$OPTARG
34+
;;
35+
p)
36+
BIND_PORT=$OPTARG
37+
;;
38+
t)
39+
TRANSPORT_PORT=$OPTARG
40+
;;
41+
s)
42+
SECURITY_ENABLED=$OPTARG
43+
;;
44+
c)
45+
CREDENTIAL=$OPTARG
46+
;;
47+
m)
48+
CLUSTER_NAME=$OPTARG
49+
;;
50+
v)
51+
OPENSEARCH_VERSION=$OPTARG
52+
;;
53+
n)
54+
# Do nothing as we're not consuming this param.
55+
;;
56+
u)
57+
COMMON_UTILS_VERSION=$OPTARG
58+
;;
59+
:)
60+
echo "-${OPTARG} requires an argument"
61+
usage
62+
exit 1
63+
;;
64+
?)
65+
echo "Invalid option: -${OPTARG}"
66+
exit 1
67+
;;
68+
esac
69+
done
70+
71+
72+
if [ -z "$BIND_ADDRESS" ]
73+
then
74+
BIND_ADDRESS="localhost"
75+
fi
76+
77+
if [ -z "$BIND_PORT" ]
78+
then
79+
BIND_PORT="9200"
80+
fi
81+
82+
if [ -z "$SECURITY_ENABLED" ]
83+
then
84+
SECURITY_ENABLED="true"
85+
fi
86+
87+
OPENSEARCH_REQUIRED_VERSION="2.12.0"
88+
if [ -z "$CREDENTIAL" ]
89+
then
90+
# Starting in 2.12.0, security demo configuration script requires an initial admin password
91+
COMPARE_VERSION=`echo $OPENSEARCH_REQUIRED_VERSION $OPENSEARCH_VERSION | tr ' ' '\n' | sort -V | uniq | head -n 1`
92+
if [ "$COMPARE_VERSION" != "$OPENSEARCH_REQUIRED_VERSION" ]; then
93+
CREDENTIAL="admin:admin"
94+
else
95+
CREDENTIAL="admin:myStrongPassword123!"
96+
fi
97+
fi
98+
99+
if [ -z "$CLUSTER_NAME" ]
100+
then
101+
CLUSTER_NAME="docker-cluster"
102+
fi
103+
104+
USERNAME=`echo $CREDENTIAL | awk -F ':' '{print $1}'`
105+
PASSWORD=`echo $CREDENTIAL | awk -F ':' '{print $2}'`
106+
107+
./gradlew integTestRemote -Dtests.rest.cluster="$BIND_ADDRESS:$BIND_PORT" -Dtests.cluster="$BIND_ADDRESS:$BIND_PORT" -Dsecurity_enabled=$SECURITY_ENABLED -Dtests.clustername=$CLUSTER_NAME -Dhttps=true -Duser=$USERNAME -Dpassword=$PASSWORD

src/integrationTest/java/org/opensearch/security/SecurityConfigurationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ public void testParallelTenantPutRequests() throws Exception {
266266
assertThat(
267267
response.getBody(),
268268
response.getStatusCode(),
269-
anyOf(equalTo(HttpStatus.SC_CREATED), equalTo(HttpStatus.SC_CONFLICT))
269+
anyOf(equalTo(HttpStatus.SC_CREATED), equalTo(HttpStatus.SC_OK), equalTo(HttpStatus.SC_CONFLICT))
270270
);
271271
if (response.getStatusCode() == HttpStatus.SC_CREATED) numCreatedResponses.getAndIncrement();
272272
});

src/integrationTest/java/org/opensearch/security/api/AbstractApiIntegrationTest.java

+20-10
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313

1414
import java.io.IOException;
1515
import java.nio.file.Path;
16+
import java.util.HashMap;
1617
import java.util.List;
18+
import java.util.Map;
1719
import java.util.StringJoiner;
1820

1921
import com.carrotsearch.randomizedtesting.RandomizedTest;
2022
import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope;
21-
import com.google.common.collect.ImmutableMap;
2223
import org.apache.commons.io.FileUtils;
2324
import org.apache.http.HttpStatus;
2425
import org.apache.logging.log4j.LogManager;
2526
import org.apache.logging.log4j.Logger;
2627
import org.awaitility.Awaitility;
2728
import org.junit.AfterClass;
28-
import org.junit.BeforeClass;
29+
import org.junit.Before;
2930
import org.junit.runner.RunWith;
3031

3132
import org.opensearch.common.CheckedConsumer;
@@ -86,22 +87,22 @@ public abstract class AbstractApiIntegrationTest extends RandomizedTest {
8687

8788
public static Path configurationFolder;
8889

89-
public static ImmutableMap.Builder<String, Object> clusterSettings = ImmutableMap.builder();
90-
9190
protected static TestSecurityConfig testSecurityConfig = new TestSecurityConfig();
9291

9392
public static LocalCluster localCluster;
9493

95-
@BeforeClass
96-
public static void startCluster() throws IOException {
94+
private Class<? extends AbstractApiIntegrationTest> testClass;
95+
96+
@Before
97+
public void startCluster() throws IOException {
98+
if (this.getClass().equals(testClass)) {
99+
return;
100+
}
97101
configurationFolder = ConfigurationFiles.createConfigurationDirectory();
98102
extendConfiguration();
99-
clusterSettings.put(SECURITY_ALLOW_DEFAULT_INIT_SECURITYINDEX, true)
100-
.put(PLUGINS_SECURITY_RESTAPI_ROLES_ENABLED, List.of("user_admin__all_access", REST_ADMIN_REST_API_ACCESS))
101-
.put(SECURITY_ALLOW_DEFAULT_INIT_USE_CLUSTER_STATE, randomBoolean());
102103
final var clusterManager = randomFrom(List.of(ClusterManager.THREE_CLUSTER_MANAGERS, ClusterManager.SINGLENODE));
103104
final var localClusterBuilder = new LocalCluster.Builder().clusterManager(clusterManager)
104-
.nodeSettings(clusterSettings.buildKeepingLast())
105+
.nodeSettings(getClusterSettings())
105106
.defaultConfigurationInitDirectory(configurationFolder.toString())
106107
.loadConfigurationIntoIndex(false);
107108
localCluster = localClusterBuilder.build();
@@ -111,6 +112,15 @@ public static void startCluster() throws IOException {
111112
.alias("Load default configuration")
112113
.until(() -> client.securityHealth().getTextFromJsonBody("/status"), equalTo("UP"));
113114
}
115+
testClass = this.getClass();
116+
}
117+
118+
protected Map<String, Object> getClusterSettings() {
119+
Map<String, Object> clusterSettings = new HashMap<>();
120+
clusterSettings.put(SECURITY_ALLOW_DEFAULT_INIT_SECURITYINDEX, true);
121+
clusterSettings.put(PLUGINS_SECURITY_RESTAPI_ROLES_ENABLED, List.of("user_admin__all_access", REST_ADMIN_REST_API_ACCESS));
122+
clusterSettings.put(SECURITY_ALLOW_DEFAULT_INIT_USE_CLUSTER_STATE, randomBoolean());
123+
return clusterSettings;
114124
}
115125

116126
private static void extendConfiguration() throws IOException {

src/integrationTest/java/org/opensearch/security/api/AbstractConfigEntityApiIntegrationTest.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@
3939
public abstract class AbstractConfigEntityApiIntegrationTest extends AbstractApiIntegrationTest {
4040

4141
static {
42-
clusterSettings.put(SECURITY_RESTAPI_ADMIN_ENABLED, true);
4342
testSecurityConfig.withRestAdminUser(REST_ADMIN_USER, allRestAdminPermissions());
4443
}
4544

45+
@Override
46+
protected Map<String, Object> getClusterSettings() {
47+
Map<String, Object> clusterSettings = super.getClusterSettings();
48+
clusterSettings.put(SECURITY_RESTAPI_ADMIN_ENABLED, true);
49+
return clusterSettings;
50+
}
51+
4652
interface TestDescriptor {
4753

4854
String entityJsonProperty();

src/integrationTest/java/org/opensearch/security/api/CertificatesRestApiIntegrationTest.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Collection;
1515
import java.util.Collections;
1616
import java.util.List;
17+
import java.util.Map;
1718
import java.util.Set;
1819
import java.util.StringJoiner;
1920
import java.util.stream.Collectors;
@@ -43,7 +44,6 @@ public class CertificatesRestApiIntegrationTest extends AbstractApiIntegrationTe
4344
final static String REGULAR_USER = "regular_user";
4445

4546
static {
46-
clusterSettings.put(SECURITY_RESTAPI_ADMIN_ENABLED, true);
4747
testSecurityConfig.roles(
4848
new TestSecurityConfig.Role("simple_user_role").clusterPermissions("cluster:admin/security/certificates/info")
4949
)
@@ -53,6 +53,13 @@ public class CertificatesRestApiIntegrationTest extends AbstractApiIntegrationTe
5353
.withRestAdminUser(REST_API_ADMIN_SSL_INFO, restAdminPermission(Endpoint.SSL, CERTS_INFO_ACTION));
5454
}
5555

56+
@Override
57+
protected Map<String, Object> getClusterSettings() {
58+
Map<String, Object> clusterSettings = super.getClusterSettings();
59+
clusterSettings.put(SECURITY_RESTAPI_ADMIN_ENABLED, true);
60+
return clusterSettings;
61+
}
62+
5663
@Override
5764
protected String apiPathPrefix() {
5865
return PLUGINS_PREFIX;

src/integrationTest/java/org/opensearch/security/api/ConfigRestApiIntegrationTest.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
*/
1111
package org.opensearch.security.api;
1212

13+
import java.util.Map;
1314
import java.util.StringJoiner;
1415

1516
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -30,11 +31,18 @@ public class ConfigRestApiIntegrationTest extends AbstractApiIntegrationTest {
3031
final static String REST_API_ADMIN_CONFIG_UPDATE = "rest-api-admin-config-update";
3132

3233
static {
33-
clusterSettings.put(SECURITY_UNSUPPORTED_RESTAPI_ALLOW_SECURITYCONFIG_MODIFICATION, true).put(SECURITY_RESTAPI_ADMIN_ENABLED, true);
3434
testSecurityConfig.withRestAdminUser(REST_ADMIN_USER, allRestAdminPermissions())
3535
.withRestAdminUser(REST_API_ADMIN_CONFIG_UPDATE, restAdminPermission(Endpoint.CONFIG, SECURITY_CONFIG_UPDATE));
3636
}
3737

38+
@Override
39+
protected Map<String, Object> getClusterSettings() {
40+
Map<String, Object> clusterSettings = super.getClusterSettings();
41+
clusterSettings.put(SECURITY_UNSUPPORTED_RESTAPI_ALLOW_SECURITYCONFIG_MODIFICATION, true);
42+
clusterSettings.put(SECURITY_RESTAPI_ADMIN_ENABLED, true);
43+
return clusterSettings;
44+
}
45+
3846
private String securityConfigPath(final String... path) {
3947
final var fullPath = new StringJoiner("/").add(super.apiPath("securityconfig"));
4048
if (path != null) for (final var p : path)
@@ -80,6 +88,7 @@ void verifyUpdate(final TestRestClient client) throws Exception {
8088
badRequest(() -> client.putJson(securityConfigPath("xxx"), EMPTY_BODY));
8189
verifyNotAllowedMethods(client);
8290

91+
TestRestClient.HttpResponse resp = client.get(securityConfigPath());
8392
final var configJson = ok(() -> client.get(securityConfigPath())).bodyAsJsonNode();
8493
final var authFailureListeners = DefaultObjectMapper.objectMapper.createObjectNode();
8594
authFailureListeners.set(

src/integrationTest/java/org/opensearch/security/api/DashboardsInfoWithSettingsTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package org.opensearch.security.api;
1313

1414
import java.util.List;
15+
import java.util.Map;
1516

1617
import org.junit.Test;
1718

@@ -32,15 +33,21 @@ public class DashboardsInfoWithSettingsTest extends AbstractApiIntegrationTest {
3233
"Password must be minimum 5 characters long and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character.";
3334

3435
static {
35-
clusterSettings.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX, CUSTOM_PASSWORD_REGEX)
36-
.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE, CUSTOM_PASSWORD_MESSAGE);
3736
testSecurityConfig.user(
3837
new TestSecurityConfig.User("dashboards_user").roles(
3938
new Role("dashboards_role").indexPermissions("read").on("*").clusterPermissions("cluster_composite_ops")
4039
)
4140
);
4241
}
4342

43+
@Override
44+
protected Map<String, Object> getClusterSettings() {
45+
Map<String, Object> clusterSettings = super.getClusterSettings();
46+
clusterSettings.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX, CUSTOM_PASSWORD_REGEX);
47+
clusterSettings.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE, CUSTOM_PASSWORD_MESSAGE);
48+
return clusterSettings;
49+
}
50+
4451
private String apiPath() {
4552
return randomFrom(List.of(PLUGINS_PREFIX + "/dashboardsinfo", LEGACY_OPENDISTRO_PREFIX + "/kibanainfo"));
4653
}

src/integrationTest/java/org/opensearch/security/api/InternalUsersRegExpPasswordRulesRestApiIntegrationTest.java

+14-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package org.opensearch.security.api;
1313

14+
import java.util.Map;
1415
import java.util.StringJoiner;
1516

1617
import org.junit.Test;
@@ -27,10 +28,19 @@ public class InternalUsersRegExpPasswordRulesRestApiIntegrationTest extends Abst
2728

2829
final static String PASSWORD_VALIDATION_ERROR_MESSAGE = "xxxxxxxx";
2930

30-
static {
31-
clusterSettings.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE, PASSWORD_VALIDATION_ERROR_MESSAGE)
32-
.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX, "(?=.*[A-Z])(?=.*[^a-zA-Z\\\\d])(?=.*[0-9])(?=.*[a-z]).{8,}")
33-
.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_SCORE_BASED_VALIDATION_STRENGTH, PasswordValidator.ScoreStrength.FAIR.name());
31+
@Override
32+
protected Map<String, Object> getClusterSettings() {
33+
Map<String, Object> clusterSettings = super.getClusterSettings();
34+
clusterSettings.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_ERROR_MESSAGE, PASSWORD_VALIDATION_ERROR_MESSAGE);
35+
clusterSettings.put(
36+
ConfigConstants.SECURITY_RESTAPI_PASSWORD_VALIDATION_REGEX,
37+
"(?=.*[A-Z])(?=.*[^a-zA-Z\\\\d])(?=.*[0-9])(?=.*[a-z]).{8,}"
38+
);
39+
clusterSettings.put(
40+
ConfigConstants.SECURITY_RESTAPI_PASSWORD_SCORE_BASED_VALIDATION_STRENGTH,
41+
PasswordValidator.ScoreStrength.FAIR.name()
42+
);
43+
return clusterSettings;
3444
}
3545

3646
String internalUsers(String... path) {

src/integrationTest/java/org/opensearch/security/api/InternalUsersScoreBasedPasswordRulesRestApiIntegrationTest.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
package org.opensearch.security.api;
1313

14+
import java.util.Map;
1415
import java.util.StringJoiner;
1516

1617
import org.junit.Test;
@@ -24,8 +25,11 @@
2425

2526
public class InternalUsersScoreBasedPasswordRulesRestApiIntegrationTest extends AbstractApiIntegrationTest {
2627

27-
static {
28+
@Override
29+
protected Map<String, Object> getClusterSettings() {
30+
Map<String, Object> clusterSettings = super.getClusterSettings();
2831
clusterSettings.put(ConfigConstants.SECURITY_RESTAPI_PASSWORD_MIN_LENGTH, 9);
32+
return clusterSettings;
2933
}
3034

3135
String internalUsers(String... path) {

0 commit comments

Comments
 (0)