forked from opensearch-project/common-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update keystore password to utilize secure variants
security plugin PR opensearch-project/security#2296 added secure variants of the keystore and pemfile passwords resolves opensearch-project#334 Signed-off-by: Chris White <[email protected]>
- Loading branch information
1 parent
84b4ee3
commit 28712cb
Showing
4 changed files
with
94 additions
and
8 deletions.
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
50 changes: 50 additions & 0 deletions
50
src/test/java/org/opensearch/commons/ConfigConstantsTest.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,50 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.commons; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.opensearch.common.settings.MockSecureSettings; | ||
import org.opensearch.common.settings.Settings; | ||
|
||
public class ConfigConstantsTest { | ||
private void assertPasswords(Settings settings, String expectedPassword, String expectedKeyPassword) { | ||
final var password = ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_PASSWORD_SETTING.get(settings); | ||
Assertions.assertEquals(expectedPassword, password.toString()); | ||
|
||
final var keyPassword = ConfigConstants.OPENSEARCH_SECURITY_SSL_HTTP_KEYSTORE_KEYPASSWORD_SETTING.get(settings); | ||
Assertions.assertEquals(expectedKeyPassword, keyPassword.toString()); | ||
} | ||
|
||
@Test | ||
public void testLegacyHttpKeystorePassword() { | ||
final var settings = Settings | ||
.builder() | ||
.put("plugins.security.ssl.http.keystore_password", "legacy-password") | ||
.put("plugins.security.ssl.http.keystore_keypassword", "legacy-keypassword") | ||
.build(); | ||
|
||
assertPasswords(settings, "legacy-password", "legacy-keypassword"); | ||
} | ||
|
||
@Test | ||
public void testSecureHttpKeystorePassword() { | ||
final var mockSecureSettings = new MockSecureSettings(); | ||
// deliberately not using constants here to verify correct concatenation of legacy + _secure suffix | ||
mockSecureSettings.setString("plugins.security.ssl.http.keystore_password_secure", "password"); | ||
mockSecureSettings.setString("plugins.security.ssl.http.keystore_keypassword_secure", "keypassword"); | ||
|
||
final var settings = Settings | ||
.builder() | ||
// check priority that secure variants are taken over the legacy ones | ||
.put("plugins.security.ssl.http.keystore_password", "legacy-password") | ||
.put("plugins.security.ssl.http.keystore_keypassword", "legacy-keypassword") | ||
.setSecureSettings(mockSecureSettings) | ||
.build(); | ||
|
||
assertPasswords(settings, "password", "keypassword"); | ||
} | ||
} |
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