-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
- Loading branch information
1 parent
f48fcdc
commit 83ba6e0
Showing
11 changed files
with
415 additions
and
1 deletion.
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
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,110 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
function usage() { | ||
echo "" | ||
echo "This script is used to run integration tests for plugin installed on a remote OpenSearch/Dashboards cluster." | ||
echo "--------------------------------------------------------------------------" | ||
echo "Usage: $0 [args]" | ||
echo "" | ||
echo "Required arguments:" | ||
echo "None" | ||
echo "" | ||
echo "Optional arguments:" | ||
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." | ||
echo -e "-p BIND_PORT\t, defaults to 9200, can be changed to any port for the cluster location." | ||
echo -e "-s SECURITY_ENABLED\t(true | false), defaults to true. Specify the OpenSearch/Dashboards have security enabled or not." | ||
echo -e "-c CREDENTIAL\t(usename:password), no defaults, effective when SECURITY_ENABLED=true." | ||
echo -e "-h\tPrint this message." | ||
echo -e "-v OPENSEARCH_VERSION\t, no defaults" | ||
echo -e "-n SNAPSHOT\t, defaults to false" | ||
echo -e "-m CLUSTER_NAME\t, defaults to docker-cluster" | ||
echo -e "-u COMMON_UTILS_VERSION\t, defaults to 2.2.0.0" | ||
echo "--------------------------------------------------------------------------" | ||
} | ||
|
||
while getopts ":h:b:p:s:c:v:n:t:m:u:" arg; do | ||
case $arg in | ||
h) | ||
usage | ||
exit 1 | ||
;; | ||
b) | ||
BIND_ADDRESS=$OPTARG | ||
;; | ||
p) | ||
BIND_PORT=$OPTARG | ||
;; | ||
t) | ||
TRANSPORT_PORT=$OPTARG | ||
;; | ||
s) | ||
SECURITY_ENABLED=$OPTARG | ||
;; | ||
c) | ||
CREDENTIAL=$OPTARG | ||
;; | ||
m) | ||
CLUSTER_NAME=$OPTARG | ||
;; | ||
v) | ||
# Do nothing as we're not consuming this param. | ||
;; | ||
n) | ||
# Do nothing as we're not consuming this param. | ||
;; | ||
u) | ||
COMMON_UTILS_VERSION=$OPTARG | ||
;; | ||
:) | ||
echo "-${OPTARG} requires an argument" | ||
usage | ||
exit 1 | ||
;; | ||
?) | ||
echo "Invalid option: -${OPTARG}" | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
|
||
if [ -z "$BIND_ADDRESS" ] | ||
then | ||
BIND_ADDRESS="localhost" | ||
fi | ||
|
||
if [ -z "$BIND_PORT" ] | ||
then | ||
BIND_PORT="9200" | ||
fi | ||
|
||
if [ -z "$SECURITY_ENABLED" ] | ||
then | ||
SECURITY_ENABLED="true" | ||
fi | ||
|
||
if [ -z "$CREDENTIAL" ] | ||
then | ||
CREDENTIAL="admin:admin" | ||
fi | ||
|
||
if [ -z "$CREDENTIAL" ] | ||
then | ||
CREDENTIAL="admin:admin" | ||
fi | ||
|
||
if [ -z "$CLUSTER_NAME" ] | ||
then | ||
CLUSTER_NAME="docker-cluster" | ||
fi | ||
if [ -z "$COMMON_UTILS_VERSION" ] | ||
then | ||
COMMON_UTILS_VERSION="2.2.0.0" | ||
fi | ||
|
||
USERNAME=`echo $CREDENTIAL | awk -F ':' '{print $1}'` | ||
PASSWORD=`echo $CREDENTIAL | awk -F ':' '{print $2}'` | ||
|
||
./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 -Dcommon_utils.version=$COMMON_UTILS_VERSION |
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,32 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.bootstrap; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.net.URL; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Disable JarHell to unblock test development | ||
* https://github.com/opensearch-project/security/issues/1938 | ||
*/ | ||
public class JarHell { | ||
private JarHell() {} | ||
public static void checkJarHell(Consumer<String> output) throws IOException, Exception {} | ||
public static void checkJarHell(Set<URL> urls, Consumer<String> output) throws URISyntaxException, IOException {} | ||
public static void checkVersionFormat(String targetVersion) {} | ||
public static void checkJavaVersion(String resource, String targetVersion) {} | ||
public static Set<URL> parseClassPath() {return new HashSet<URL>();} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/test/java/org/opensearch/security/sanity/tests/SecurityRestTestCase.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,99 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.sanity.tests; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Map; | ||
|
||
import org.apache.http.HttpHost; | ||
|
||
import org.opensearch.client.Request; | ||
import org.opensearch.client.Response; | ||
import org.opensearch.client.RestClient; | ||
import org.opensearch.client.RestClientBuilder; | ||
import org.opensearch.common.io.PathUtils; | ||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.commons.rest.SecureRestClientBuilder; | ||
import org.opensearch.test.rest.OpenSearchRestTestCase; | ||
|
||
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_ENABLED; | ||
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH; | ||
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD; | ||
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD; | ||
import static org.opensearch.commons.ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_PEMCERT_FILEPATH; | ||
|
||
/** | ||
* Overrides OpenSearchRestTestCase to fit the use-case for testing | ||
* against remote cluster for Security Plugin. | ||
* | ||
* Modify this test class as needed | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public class SecurityRestTestCase extends OpenSearchRestTestCase { | ||
|
||
private static final String CERT_FILE_DIRECTORY = "sanity-tests/"; | ||
private boolean isHttps() { | ||
return System.getProperty("https").equals("true"); | ||
} | ||
private boolean securityEnabled() { | ||
return System.getProperty("security.enabled").equals("true"); | ||
} | ||
|
||
@Override | ||
protected Settings restAdminSettings(){ | ||
|
||
return Settings | ||
.builder() | ||
.put("http.port", 9200) | ||
.put(OPENSEARCH_SECURITY_SSL_HTTP_ENABLED, isHttps()) | ||
.put(OPENSEARCH_SECURITY_SSL_HTTP_PEMCERT_FILEPATH, CERT_FILE_DIRECTORY + "opensearch-node.pem") | ||
.put("plugins.security.ssl.http.pemkey_filepath", CERT_FILE_DIRECTORY + "opensearch-node-key.pem") | ||
.put("plugins.security.ssl.transport.pemtrustedcas_filepath", CERT_FILE_DIRECTORY + "root-ca.pem") | ||
.put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH, CERT_FILE_DIRECTORY + "test-kirk.jks") | ||
.put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD, "changeit") | ||
.put(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD, "changeit") | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected RestClient buildClient(Settings settings, HttpHost[] hosts) throws IOException { | ||
|
||
if(securityEnabled()){ | ||
String keystore = settings.get(OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_FILEPATH); | ||
|
||
if(keystore != null){ | ||
// create adminDN (super-admin) client | ||
File file = new File(getClass().getClassLoader().getResource(CERT_FILE_DIRECTORY).getFile()); | ||
Path configPath = PathUtils.get(file.toURI()).getParent().toAbsolutePath(); | ||
return new SecureRestClientBuilder(settings, configPath).setSocketTimeout(60000).build(); | ||
} | ||
|
||
// create client with passed user | ||
String userName = System.getProperty("user"); | ||
String password = System.getProperty("password"); | ||
return new SecureRestClientBuilder(hosts, isHttps(), userName, password).setSocketTimeout(60000).build(); | ||
} | ||
else { | ||
RestClientBuilder builder = RestClient.builder(hosts); | ||
configureClient(builder, settings); | ||
builder.setStrictDeprecationMode(true); | ||
return builder.build(); | ||
} | ||
} | ||
|
||
protected static Map<String, Object> getAsMapByAdmin(final String endpoint) throws IOException { | ||
Response response = adminClient().performRequest(new Request("GET", endpoint)); | ||
return responseAsMap(response); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/test/java/org/opensearch/security/sanity/tests/SingleClusterSanityIT.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,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.sanity.tests; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.junit.Test; | ||
|
||
import static org.hamcrest.Matchers.anEmptyMap; | ||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
|
||
@SuppressWarnings("unchecked") | ||
public class SingleClusterSanityIT extends SecurityRestTestCase { | ||
|
||
private static final String SECURITY_PLUGIN_NAME = "opensearch-security"; | ||
|
||
@Test | ||
public void testSecurityPluginInstallation() throws Exception { | ||
verifyPluginInstallationOnAllNodes(); | ||
} | ||
|
||
private void verifyPluginInstallationOnAllNodes() throws Exception { | ||
|
||
Map<String, Map<String, Object>> nodesInCluster = (Map<String, Map<String, Object>>) getAsMapByAdmin("_nodes").get("nodes"); | ||
|
||
for (Map<String, Object> node : nodesInCluster.values()) { | ||
|
||
List<Map<String, Object>> plugins = (List<Map<String, Object>>) node.get("plugins"); | ||
Set<Object> pluginNames = plugins.stream().map(map -> map.get("name")).collect(Collectors.toSet()); | ||
|
||
MatcherAssert.assertThat(pluginNames, contains(SECURITY_PLUGIN_NAME)); | ||
} | ||
MatcherAssert.assertThat(nodesInCluster, is(not(anEmptyMap()))); | ||
} | ||
} |
Oops, something went wrong.