Skip to content

Commit

Permalink
[fix][proxy] Fix client service url (#16834)
Browse files Browse the repository at this point in the history
(cherry picked from commit eedee40)
  • Loading branch information
nodece authored and Jason918 committed Jul 29, 2022
1 parent d166c93 commit 10b4e99
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,10 @@ protected void handleLookup(CommandLookupTopic lookup) {
ClientConfigurationData createClientConfiguration()
throws PulsarClientException.UnsupportedAuthenticationException {
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -35,4 +39,24 @@ public void testMatchesHostAndPort() {
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);
}
}

0 comments on commit 10b4e99

Please sign in to comment.