This is an automated email from the ASF dual-hosted git repository.
krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new 41590e1 KNOX-2474 - RemoteConfigurationRegistryJAASConfigTest fails
due to invalid auth (#387)
41590e1 is described below
commit 41590e185efa2c8d8c4aaf22fbc562c498ba808d
Author: Kevin Risden <[email protected]>
AuthorDate: Thu Nov 26 11:58:11 2020 -0500
KNOX-2474 - RemoteConfigurationRegistryJAASConfigTest fails due to invalid
auth (#387)
Signed-off-by: Kevin Risden <[email protected]>
---
...nfigurationRegistryClientServiceSecureTest.java | 115 +++++++++++
...onfigurationRegistryClientServiceTestBase.java} | 210 +++------------------
...igurationRegistryClientServiceUnsecureTest.java | 115 +++++++++++
3 files changed, 251 insertions(+), 189 deletions(-)
diff --git
a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceSecureTest.java
b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceSecureTest.java
new file mode 100644
index 0000000..64c1877
--- /dev/null
+++
b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceSecureTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package org.apache.knox.gateway.service.config.remote.zk;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.test.TestingCluster;
+import org.apache.knox.gateway.config.GatewayConfig;
+import
org.apache.knox.gateway.service.config.remote.util.RemoteRegistryConfigTestUtils;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class RemoteConfigurationRegistryClientServiceSecureTest extends
RemoteConfigurationRegistryClientServiceTestBase {
+ /*
+ * Test a configuration for a secure remote registry, included in the
gateway configuration.
+ */
+ @Test
+ public void testZooKeeperWithSimpleRegistryConfig() throws Exception {
+ final String AUTH_TYPE = "digest";
+ final String REGISTRY_CLIENT_NAME = "zk-registry-name";
+ final String PRINCIPAL = "knox";
+ final String PWD = "knoxtest";
+ final String CRED_ALIAS = "zkCredential";
+
+ // Configure and start a secure ZK cluster
+ try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
+ // Create the setup client for the test cluster, and initialize
the test znodes
+ CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
+
+ // Mock configuration
+ GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
+ final String registryConfigValue =
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString() + ";" +
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE + "=" +
AUTH_TYPE + ";" +
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL + "=" +
PRINCIPAL + ";" +
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS +
"=" + CRED_ALIAS;
+
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME))
+ .andReturn(registryConfigValue)
+ .anyTimes();
+ EasyMock.expect(config.getRemoteRegistryConfigurationNames())
+
.andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
+ EasyMock.replay(config);
+
+ doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config,
CRED_ALIAS, PWD);
+ }
+ }
+
+ /*
+ * Test the remote registry configuration external to, and referenced
from, the gateway configuration, for a secure
+ * client.
+ */
+ @Test
+ public void testZooKeeperWithSingleExternalRegistryConfig() throws
Exception {
+ final String AUTH_TYPE = "digest";
+ final String REGISTRY_CLIENT_NAME = "my-zookeeper_registryNAME";
+ final String PRINCIPAL = "knox";
+ final String PWD = "knoxtest";
+ final String CRED_ALIAS = "zkCredential";
+
+ // Configure and start a secure ZK cluster
+ File tmpRegConfigFile = null;
+ try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
+ // Create the setup client for the test cluster, and initialize
the test znodes
+ CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
+
+ // Mock configuration
+ Map<String, String> registryConfigProps = new HashMap<>();
+ registryConfigProps.put("type", ZooKeeperClientService.TYPE);
+ registryConfigProps.put("name", REGISTRY_CLIENT_NAME);
+ registryConfigProps.put("address", zkCluster.getConnectString());
+ registryConfigProps.put("secure", "true");
+ registryConfigProps.put("authType", AUTH_TYPE);
+ registryConfigProps.put("principal", PRINCIPAL);
+ registryConfigProps.put("credentialAlias", CRED_ALIAS);
+ String registryConfigXML =
+
RemoteRegistryConfigTestUtils.createRemoteConfigRegistriesXML(Collections.singleton(registryConfigProps));
+ tmpRegConfigFile = File.createTempFile("myRemoteRegistryConfig",
"xml");
+ FileUtils.writeStringToFile(tmpRegConfigFile, registryConfigXML,
StandardCharsets.UTF_8);
+
+
System.setProperty("org.apache.knox.gateway.remote.registry.config.file",
tmpRegConfigFile.getAbsolutePath());
+
+ GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
+ EasyMock.replay(config);
+
+ doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config,
CRED_ALIAS, PWD);
+ } finally {
+ if (tmpRegConfigFile != null && tmpRegConfigFile.exists()) {
+ tmpRegConfigFile.delete();
+ }
+
System.clearProperty("org.apache.knox.gateway.remote.registry.config.file");
+ }
+ }
+}
diff --git
a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java
b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTestBase.java
similarity index 52%
rename from
gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java
rename to
gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTestBase.java
index adaa26b..3efda8d 100644
---
a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTest.java
+++
b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceTestBase.java
@@ -16,7 +16,22 @@
*/
package org.apache.knox.gateway.service.config.remote.zk;
-import org.apache.commons.io.FileUtils;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import javax.security.auth.login.AppConfigurationEntry;
+import javax.security.auth.login.Configuration;
+
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
@@ -24,7 +39,6 @@ import org.apache.curator.test.InstanceSpec;
import org.apache.curator.test.TestingCluster;
import org.apache.knox.gateway.config.GatewayConfig;
import
org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceFactory;
-import
org.apache.knox.gateway.service.config.remote.util.RemoteRegistryConfigTestUtils;
import
org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient;
import
org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService;
import org.apache.knox.gateway.services.security.AliasService;
@@ -32,194 +46,12 @@ import org.apache.zookeeper.ZooDefs;
import org.apache.zookeeper.data.ACL;
import org.apache.zookeeper.data.Id;
import org.easymock.EasyMock;
-import org.junit.Test;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.login.Configuration;
-import java.io.File;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-public class RemoteConfigurationRegistryClientServiceTest {
-
- /*
- * Test a configuration for an unsecured remote registry, included in the
gateway configuration.
- */
- @Test
- public void testUnsecuredZooKeeperWithSimpleRegistryConfig() throws
Exception {
- final String REGISTRY_CLIENT_NAME = "unsecured-zk-registry-name";
- final String PRINCIPAL = null;
- final String PWD = null;
- final String CRED_ALIAS = null;
-
- // Configure and start a secure ZK cluster
- try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
- // Create the setup client for the test cluster, and initialize
the test znodes
- CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
- final String registryConfigValue =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString();
-
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME))
- .andReturn(registryConfigValue)
- .anyTimes();
- EasyMock.expect(config.getRemoteRegistryConfigurationNames())
-
.andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
- EasyMock.replay(config);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config,
CRED_ALIAS, PWD);
- }
- }
-
- /*
- * Test multiple configurations for an unsecured remote registry.
- */
- @Test
- public void testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig()
throws Exception {
- final String REGISTRY_CLIENT_NAME_1 = "zkclient1";
- final String REGISTRY_CLIENT_NAME_2 = "zkclient2";
- final String PRINCIPAL = null;
- final String PWD = null;
-
- // Configure and start a secure ZK cluster
- try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
- // Create the setup client for the test cluster, and initialize
the test znodes
- CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
- final String registryConfigValue1 =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString();
-
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_1))
- .andReturn(registryConfigValue1).anyTimes();
- final String registryConfigValue2 =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString();
-
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_2))
- .andReturn(registryConfigValue2).anyTimes();
- EasyMock.expect(config.getRemoteRegistryConfigurationNames())
- .andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1,
REGISTRY_CLIENT_NAME_2)).anyTimes();
- EasyMock.replay(config);
-
- // Create the client service instance
- RemoteConfigurationRegistryClientService clientService =
-
RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
- assertEquals("Wrong registry client service type.",
clientService.getClass(), CuratorClientService.class);
- clientService.setAliasService(null);
- clientService.init(config, null);
- clientService.start();
-
- RemoteConfigurationRegistryClient client1 =
clientService.get(REGISTRY_CLIENT_NAME_1);
- assertNotNull(client1);
-
- RemoteConfigurationRegistryClient client2 =
clientService.get(REGISTRY_CLIENT_NAME_2);
- assertNotNull(client2);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_1,
clientService, false);
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_2,
clientService, false);
- }
- }
-
- /*
- * Test a configuration for a secure remote registry, included in the
gateway configuration.
- */
- @Test
- public void testZooKeeperWithSimpleRegistryConfig() throws Exception {
- final String AUTH_TYPE = "digest";
- final String REGISTRY_CLIENT_NAME = "zk-registry-name";
- final String PRINCIPAL = "knox";
- final String PWD = "knoxtest";
- final String CRED_ALIAS = "zkCredential";
-
- // Configure and start a secure ZK cluster
- try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
- // Create the setup client for the test cluster, and initialize
the test znodes
- CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
- final String registryConfigValue =
- GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString() + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_AUTH_TYPE + "=" +
AUTH_TYPE + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_PRINCIPAL + "=" +
PRINCIPAL + ";" +
- GatewayConfig.REMOTE_CONFIG_REGISTRY_CREDENTIAL_ALIAS +
"=" + CRED_ALIAS;
-
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME))
- .andReturn(registryConfigValue)
- .anyTimes();
- EasyMock.expect(config.getRemoteRegistryConfigurationNames())
-
.andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
- EasyMock.replay(config);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config,
CRED_ALIAS, PWD);
- }
- }
-
- /*
- * Test the remote registry configuration external to, and referenced
from, the gateway configuration, for a secure
- * client.
- */
- @Test
- public void testZooKeeperWithSingleExternalRegistryConfig() throws
Exception {
- final String AUTH_TYPE = "digest";
- final String REGISTRY_CLIENT_NAME = "my-zookeeper_registryNAME";
- final String PRINCIPAL = "knox";
- final String PWD = "knoxtest";
- final String CRED_ALIAS = "zkCredential";
-
- // Configure and start a secure ZK cluster
- File tmpRegConfigFile = null;
- try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
- // Create the setup client for the test cluster, and initialize
the test znodes
- CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
-
- // Mock configuration
- Map<String, String> registryConfigProps = new HashMap<>();
- registryConfigProps.put("type", ZooKeeperClientService.TYPE);
- registryConfigProps.put("name", REGISTRY_CLIENT_NAME);
- registryConfigProps.put("address", zkCluster.getConnectString());
- registryConfigProps.put("secure", "true");
- registryConfigProps.put("authType", AUTH_TYPE);
- registryConfigProps.put("principal", PRINCIPAL);
- registryConfigProps.put("credentialAlias", CRED_ALIAS);
- String registryConfigXML =
-
RemoteRegistryConfigTestUtils.createRemoteConfigRegistriesXML(Collections.singleton(registryConfigProps));
- tmpRegConfigFile = File.createTempFile("myRemoteRegistryConfig",
"xml");
- FileUtils.writeStringToFile(tmpRegConfigFile, registryConfigXML,
StandardCharsets.UTF_8);
-
-
System.setProperty("org.apache.knox.gateway.remote.registry.config.file",
tmpRegConfigFile.getAbsolutePath());
-
- GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
- EasyMock.replay(config);
-
- doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config,
CRED_ALIAS, PWD);
- } finally {
- if (tmpRegConfigFile != null && tmpRegConfigFile.exists()) {
- tmpRegConfigFile.delete();
- }
-
System.clearProperty("org.apache.knox.gateway.remote.registry.config.file");
- }
- }
+public class RemoteConfigurationRegistryClientServiceTestBase {
/*
* Setup and start a secure test ZooKeeper cluster.
*/
- private TestingCluster setupAndStartSecureTestZooKeeper(String principal,
String digestPassword) throws Exception {
+ protected TestingCluster setupAndStartSecureTestZooKeeper(String
principal, String digestPassword) throws Exception {
final boolean applyAuthentication = (principal != null);
// Configure security for the ZK cluster instances
@@ -267,7 +99,7 @@ public class RemoteConfigurationRegistryClientServiceTest {
* @param principal principal for SASL digrest auth
* @throws Exception exception on failure
*/
- private CuratorFramework initializeTestClientAndZNodes(TestingCluster
zkCluster, String principal) throws Exception {
+ protected CuratorFramework initializeTestClientAndZNodes(TestingCluster
zkCluster, String principal) throws Exception {
// Create the client for the test cluster
CuratorFramework setupClient = CuratorFrameworkFactory.builder()
.connectString(zkCluster.getConnectString())
@@ -298,7 +130,7 @@ public class RemoteConfigurationRegistryClientServiceTest {
return setupClient;
}
- private void doTestZooKeeperClient(final CuratorFramework setupClient,
+ protected void doTestZooKeeperClient(final CuratorFramework setupClient,
final String testClientName,
final GatewayConfig config,
final String credentialAlias,
@@ -332,7 +164,7 @@ public class RemoteConfigurationRegistryClientServiceTest {
* @param isSecureTest Flag to indicate whether this is a secure
interaction test
* @throws Exception exception on failure
*/
- private void doTestZooKeeperClient(final CuratorFramework
setupClient,
+ protected void doTestZooKeeperClient(final CuratorFramework
setupClient,
final String
testClientName,
final
RemoteConfigurationRegistryClientService clientService,
boolean
isSecureTest) throws Exception {
diff --git
a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceUnsecureTest.java
b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceUnsecureTest.java
new file mode 100644
index 0000000..a971fdb
--- /dev/null
+++
b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryClientServiceUnsecureTest.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package org.apache.knox.gateway.service.config.remote.zk;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+import java.util.Collections;
+
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.test.TestingCluster;
+import org.apache.knox.gateway.config.GatewayConfig;
+import
org.apache.knox.gateway.service.config.remote.RemoteConfigurationRegistryClientServiceFactory;
+import
org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClient;
+import
org.apache.knox.gateway.services.config.client.RemoteConfigurationRegistryClientService;
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+public class RemoteConfigurationRegistryClientServiceUnsecureTest extends
RemoteConfigurationRegistryClientServiceTestBase {
+ /*
+ * Test a configuration for an unsecured remote registry, included in the
gateway configuration.
+ */
+ @Test
+ public void testUnsecuredZooKeeperWithSimpleRegistryConfig() throws
Exception {
+ final String REGISTRY_CLIENT_NAME = "unsecured-zk-registry-name";
+ final String PRINCIPAL = null;
+ final String PWD = null;
+ final String CRED_ALIAS = null;
+
+ // Configure and start a secure ZK cluster
+ try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
+ // Create the setup client for the test cluster, and initialize
the test znodes
+ CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
+
+ // Mock configuration
+ GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
+ final String registryConfigValue =
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString();
+
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME))
+ .andReturn(registryConfigValue)
+ .anyTimes();
+ EasyMock.expect(config.getRemoteRegistryConfigurationNames())
+
.andReturn(Collections.singletonList(REGISTRY_CLIENT_NAME)).anyTimes();
+ EasyMock.replay(config);
+
+ doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME, config,
CRED_ALIAS, PWD);
+ }
+ }
+
+ /*
+ * Test multiple configurations for an unsecured remote registry.
+ */
+ @Test
+ public void testMultipleUnsecuredZooKeeperWithSimpleRegistryConfig()
throws Exception {
+ final String REGISTRY_CLIENT_NAME_1 = "zkclient1";
+ final String REGISTRY_CLIENT_NAME_2 = "zkclient2";
+ final String PRINCIPAL = null;
+ final String PWD = null;
+
+ // Configure and start a secure ZK cluster
+ try (TestingCluster zkCluster =
setupAndStartSecureTestZooKeeper(PRINCIPAL, PWD)) {
+ // Create the setup client for the test cluster, and initialize
the test znodes
+ CuratorFramework setupClient =
initializeTestClientAndZNodes(zkCluster, PRINCIPAL);
+
+ // Mock configuration
+ GatewayConfig config =
EasyMock.createNiceMock(GatewayConfig.class);
+ final String registryConfigValue1 =
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString();
+
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_1))
+ .andReturn(registryConfigValue1).anyTimes();
+ final String registryConfigValue2 =
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_TYPE + "=" +
ZooKeeperClientService.TYPE + ";" +
+ GatewayConfig.REMOTE_CONFIG_REGISTRY_ADDRESS + "=" +
zkCluster.getConnectString();
+
EasyMock.expect(config.getRemoteRegistryConfiguration(REGISTRY_CLIENT_NAME_2))
+ .andReturn(registryConfigValue2).anyTimes();
+ EasyMock.expect(config.getRemoteRegistryConfigurationNames())
+ .andReturn(Arrays.asList(REGISTRY_CLIENT_NAME_1,
REGISTRY_CLIENT_NAME_2)).anyTimes();
+ EasyMock.replay(config);
+
+ // Create the client service instance
+ RemoteConfigurationRegistryClientService clientService =
+
RemoteConfigurationRegistryClientServiceFactory.newInstance(config);
+ assertEquals("Wrong registry client service type.",
clientService.getClass(), CuratorClientService.class);
+ clientService.setAliasService(null);
+ clientService.init(config, null);
+ clientService.start();
+
+ RemoteConfigurationRegistryClient client1 =
clientService.get(REGISTRY_CLIENT_NAME_1);
+ assertNotNull(client1);
+
+ RemoteConfigurationRegistryClient client2 =
clientService.get(REGISTRY_CLIENT_NAME_2);
+ assertNotNull(client2);
+
+ doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_1,
clientService, false);
+ doTestZooKeeperClient(setupClient, REGISTRY_CLIENT_NAME_2,
clientService, false);
+ }
+ }
+}