From 6c0edad2eecb41caff5c42a7f0ef2b9d6b2bd178 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Wed, 14 Feb 2024 16:43:25 -0500 Subject: [PATCH 1/2] Fixes base64 encoded hardcoded admin credentials Signed-off-by: Darshit Chanpura --- .../org/opensearch/replication/MultiClusterRestTestCase.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt b/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt index 090bdf00..84b73b85 100644 --- a/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt @@ -57,12 +57,14 @@ import org.junit.After import org.junit.AfterClass import org.junit.Before import org.junit.BeforeClass +import java.nio.charset.StandardCharsets import java.nio.file.Files import java.security.KeyManagementException import java.security.KeyStore import java.security.KeyStoreException import java.security.NoSuchAlgorithmException import java.security.cert.CertificateException +import java.util.Base64 import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicReference import java.util.Collections @@ -233,8 +235,10 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() { for ((key, value) in headers) { defaultHeaders[i++] = BasicHeader(key, value) } + + val creds = System.getProperty("user", "admin") + System.getProperty("password", "myStrongPassword123!"); if(securityEnabled) { - defaultHeaders[i++] = BasicHeader("Authorization", "Basic YWRtaW46YWRtaW4=") + defaultHeaders[i++] = BasicHeader("Authorization", "Basic " + Base64.getUrlEncoder().encodeToString(creds.toByteArray(StandardCharsets.UTF_8))) } builder.setDefaultHeaders(defaultHeaders) From 5a983998bb5fdcf6d4289f2ca05f986575ab70ac Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Wed, 14 Feb 2024 20:10:17 -0500 Subject: [PATCH 2/2] Fixes broken integTest task Signed-off-by: Darshit Chanpura --- build.gradle | 1 + .../org/opensearch/replication/MultiClusterRestTestCase.kt | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 40819857..33e81ff2 100644 --- a/build.gradle +++ b/build.gradle @@ -450,6 +450,7 @@ int endJmxPort = startJmxPort integTest { useCluster testClusters.leaderCluster useCluster testClusters.followCluster + systemProperty "password", "admin" // setting it to `admin` explicitly since its a custom security setup if(knnEnabled){ nonInputProperties.systemProperty('tests.knn_plugin_enabled', "true") diff --git a/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt b/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt index 84b73b85..185cadc4 100644 --- a/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt +++ b/src/test/kotlin/org/opensearch/replication/MultiClusterRestTestCase.kt @@ -236,9 +236,9 @@ abstract class MultiClusterRestTestCase : OpenSearchTestCase() { defaultHeaders[i++] = BasicHeader(key, value) } - val creds = System.getProperty("user", "admin") + System.getProperty("password", "myStrongPassword123!"); + val creds = System.getProperty("user", "admin") + ":" + System.getProperty("password", "myStrongPassword123!") if(securityEnabled) { - defaultHeaders[i++] = BasicHeader("Authorization", "Basic " + Base64.getUrlEncoder().encodeToString(creds.toByteArray(StandardCharsets.UTF_8))) + defaultHeaders[i++] = BasicHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString(creds.toByteArray(StandardCharsets.UTF_8))) } builder.setDefaultHeaders(defaultHeaders)