This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 2c5ef2d  Make it possible to get namespaces owned by broker when TLS 
is enabled (#1346)
2c5ef2d is described below

commit 2c5ef2dfbef31fba391c9eeb94c80b6e002bd9c2
Author: massakam <massa...@yahoo-corp.jp>
AuthorDate: Wed Mar 7 04:05:43 2018 +0900

    Make it possible to get namespaces owned by broker when TLS is enabled 
(#1346)
---
 .../apache/pulsar/broker/admin/AdminResource.java  |  4 +++-
 .../apache/pulsar/broker/admin/AdminApiTest.java   | 22 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
index 527f455..1e77640 100644
--- 
a/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
+++ 
b/pulsar-broker/src/main/java/org/apache/pulsar/broker/admin/AdminResource.java
@@ -276,7 +276,9 @@ public abstract class AdminResource extends 
PulsarWebResource {
      */
     protected void validateBrokerName(String broker) throws 
MalformedURLException {
         String brokerUrl = String.format("http://%s";, broker);
-        if (!pulsar().getWebServiceAddress().equals(brokerUrl)) {
+        String brokerUrlTls = String.format("https://%s";, broker);
+        if (!pulsar().getWebServiceAddress().equals(brokerUrl)
+                && !pulsar().getWebServiceAddressTls().equals(brokerUrlTls)) {
             String[] parts = broker.split(":");
             checkArgument(parts.length == 2, "Invalid broker url %s", broker);
             String host = parts[0];
diff --git 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
index 0f5cfa5..90d6691 100644
--- 
a/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
+++ 
b/pulsar-broker/src/test/java/org/apache/pulsar/broker/admin/AdminApiTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.pulsar.broker.admin;
 
+import static org.mockito.Mockito.spy;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotEquals;
@@ -55,6 +56,7 @@ import 
org.apache.pulsar.client.admin.PulsarAdminException.PreconditionFailedExc
 import org.apache.pulsar.client.admin.internal.LookupImpl;
 import org.apache.pulsar.client.admin.internal.PersistentTopicsImpl;
 import org.apache.pulsar.client.admin.internal.PropertiesImpl;
+import org.apache.pulsar.client.api.ClientConfiguration;
 import org.apache.pulsar.client.api.Consumer;
 import org.apache.pulsar.client.api.ConsumerBuilder;
 import org.apache.pulsar.client.api.Message;
@@ -108,10 +110,14 @@ public class AdminApiTest extends 
MockedPulsarServiceBaseTest {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(AdminApiTest.class);
 
+    private final String TLS_SERVER_CERT_FILE_PATH = 
"./src/test/resources/certificate/server.crt";
+    private final String TLS_SERVER_KEY_FILE_PATH = 
"./src/test/resources/certificate/server.key";
+
     private MockedPulsarService mockPulsarSetup;
 
     private PulsarService otherPulsar;
 
+    private PulsarAdmin adminTls;
     private PulsarAdmin otheradmin;
 
     private NamespaceBundleFactory bundleFactory;
@@ -120,10 +126,19 @@ public class AdminApiTest extends 
MockedPulsarServiceBaseTest {
     @Override
     public void setup() throws Exception {
         conf.setLoadBalancerEnabled(true);
+        conf.setTlsEnabled(true);
+        conf.setTlsCertificateFilePath(TLS_SERVER_CERT_FILE_PATH);
+        conf.setTlsKeyFilePath(TLS_SERVER_KEY_FILE_PATH);
+
         super.internalSetup();
 
         bundleFactory = new NamespaceBundleFactory(pulsar, Hashing.crc32());
 
+        ClientConfiguration clientConf = new ClientConfiguration();
+        clientConf.setUseTls(true);
+        clientConf.setTlsTrustCertsFilePath(TLS_SERVER_CERT_FILE_PATH);
+        adminTls = spy(new PulsarAdmin(brokerUrlTls, clientConf));
+
         // create otherbroker to test redirect on calls that need
         // namespace ownership
         mockPulsarSetup = new MockedPulsarService(this.conf);
@@ -141,6 +156,7 @@ public class AdminApiTest extends 
MockedPulsarServiceBaseTest {
     @AfterMethod
     @Override
     public void cleanup() throws Exception {
+        adminTls.close();
         super.internalCleanup();
         mockPulsarSetup.cleanup();
     }
@@ -379,6 +395,12 @@ public class AdminApiTest extends 
MockedPulsarServiceBaseTest {
             }
         }
 
+        String[] parts = list.get(0).split(":");
+        Assert.assertEquals(parts.length, 2);
+        Map<String, NamespaceOwnershipStatus> nsMap2 = 
adminTls.brokers().getOwnedNamespaces("use",
+                String.format("%s:%d", parts[0], BROKER_WEBSERVICE_PORT_TLS));
+        Assert.assertEquals(nsMap2.size(), 1);
+
         admin.namespaces().deleteNamespace("prop-xyz/use/ns1");
         admin.clusters().deleteCluster("use");
         // "test" cluster is part of config-default cluster and it's znode 
gets created when PulsarService creates

-- 
To stop receiving notification emails like this one, please contact
mme...@apache.org.

Reply via email to