This is an automated email from the ASF dual-hosted git repository. xyz pushed a commit to branch branch-2.8 in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit e31713a0720e18162872d0439585ac44f7595c89 Author: Zixuan Liu <[email protected]> AuthorDate: Fri Jul 29 15:09:26 2022 +0800 [fix][proxy] Fix client service url (#16834) (cherry picked from commit eedee403da4ee531546b6440d82ed4bf14fa333a) --- .../pulsar/proxy/server/ProxyConnection.java | 4 +++- .../pulsar/proxy/server/ProxyConnectionTest.java | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java index 0f41208fde2..42b4d0f08f7 100644 --- a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java +++ b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConnection.java @@ -525,8 +525,10 @@ public class ProxyConnection extends PulsarHandler { ClientConfigurationData createClientConfiguration() { ClientConfigurationData initialConf = new ClientConfigurationData(); - initialConf.setServiceUrl(service.getServiceUrl()); ProxyConfiguration proxyConfig = service.getConfiguration(); + initialConf.setServiceUrl( + proxyConfig.isTlsEnabledWithBroker() ? service.getServiceUrlTls() : service.getServiceUrl()); + // Apply all arbitrary configuration. This must be called before setting any fields annotated as // @Secret on the ClientConfigurationData object because of the way they are serialized. // See https://github.com/apache/pulsar/issues/8509 for more information. diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java index 5f533e37d35..8c07e4b42d7 100644 --- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java +++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyConnectionTest.java @@ -18,8 +18,12 @@ */ package org.apache.pulsar.proxy.server; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; +import org.apache.pulsar.client.impl.conf.ClientConfigurationData; import org.testng.annotations.Test; public class ProxyConnectionTest { @@ -35,4 +39,24 @@ public class ProxyConnectionTest { assertFalse(ProxyConnection .matchesHostAndPort("pulsar://", "pulsar://1.2.3.4:12345", "1.2.3.4:1234")); } + @Test + public void testCreateClientConfiguration() { + ProxyConfiguration proxyConfiguration = new ProxyConfiguration(); + proxyConfiguration.setTlsEnabledWithBroker(true); + String proxyUrlTls = "pulsar+ssl://proxy:6651"; + String proxyUrl = "pulsar://proxy:6650"; + + ProxyService proxyService = mock(ProxyService.class); + doReturn(proxyConfiguration).when(proxyService).getConfiguration(); + doReturn(proxyUrlTls).when(proxyService).getServiceUrlTls(); + doReturn(proxyUrl).when(proxyService).getServiceUrl(); + + ProxyConnection proxyConnection = new ProxyConnection(proxyService, null); + ClientConfigurationData clientConfiguration = proxyConnection.createClientConfiguration(); + assertEquals(clientConfiguration.getServiceUrl(), proxyUrlTls); + + proxyConfiguration.setTlsEnabledWithBroker(false); + clientConfiguration = proxyConnection.createClientConfiguration(); + assertEquals(clientConfiguration.getServiceUrl(), proxyUrl); + } }
