Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static DiscoveryApiClient getApiClient(final GatewayConfig gatewayConfig,
final AliasService aliasService, final KeyStore truststore) {
try {
final char[] trustStorePassword = aliasService.getPasswordFromAliasForGateway(TRUSTSTORE_PASSWORD_ALIAS);
if (trustStorePassword != null) {
if (trustStorePassword != null && trustStorePassword.length > 0) {
System.setProperty(TRUSTSTORE_PASSWORD_SYSTEM_PROPERTY, new String(trustStorePassword));
}
return new DiscoveryApiClient(gatewayConfig, discoveryConfig, aliasService, truststore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.knox.gateway.topology.discovery.cm;

import org.apache.commons.lang3.StringUtils;
import org.apache.knox.gateway.config.GatewayConfig;
import org.apache.knox.gateway.services.security.AliasService;
import org.apache.knox.gateway.services.security.AliasServiceException;
Expand Down Expand Up @@ -46,16 +47,20 @@ public void tearDown() {

@Test
public void testSystemPropertySetWhenAliasExists() throws AliasServiceException {
testGetApiClient(true);
testGetApiClient(true, "changeit");
}

@Test
public void testSystemPropertyNotSetWhenAliasNotExists() throws AliasServiceException {
testGetApiClient(false);
testGetApiClient(false, null);
}

private void testGetApiClient(final boolean shouldSetSystemProperty) throws AliasServiceException {
final String trustStorePassword = "changeit";
@Test
public void testSystemPropertySetWhenAliasEmpty() throws AliasServiceException {
testGetApiClient(true, "");
}

private void testGetApiClient(final boolean shouldSetSystemProperty, String trustStorePassword) throws AliasServiceException {
final RecordingProperties testProps = new RecordingProperties(originalProps);
System.setProperties(testProps);

Expand All @@ -82,7 +87,7 @@ private void testGetApiClient(final boolean shouldSetSystemProperty) throws Alia
EasyMock.replay(aliasService, gatewayConfig, serviceDiscoveryConfig, trustStore);
ApiClientFactory.getApiClient(gatewayConfig, serviceDiscoveryConfig, aliasService, trustStore);

if (shouldSetSystemProperty) {
if (shouldSetSystemProperty && StringUtils.isNotBlank(trustStorePassword)) {
Assert.assertEquals(ApiClientFactory.TRUSTSTORE_PASSWORD_SYSTEM_PROPERTY, testProps.lastSetKey);
Assert.assertEquals(trustStorePassword, testProps.lastSetValue);
Assert.assertEquals(ApiClientFactory.TRUSTSTORE_PASSWORD_SYSTEM_PROPERTY, testProps.lastRemovedKey);
Expand Down
Loading