You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2018/02/13 17:54:33 UTC
[GitHub] merlimat closed pull request #1230: ProxyForwardAuthDataTest shouldn't reuse pulsar client
merlimat closed pull request #1230: ProxyForwardAuthDataTest shouldn't reuse pulsar client
URL: https://github.com/apache/incubator-pulsar/pull/1230
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyForwardAuthDataTest.java b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyForwardAuthDataTest.java
index 2309ebbf3..d4b8e4d86 100644
--- a/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyForwardAuthDataTest.java
+++ b/pulsar-proxy/src/test/java/org/apache/pulsar/proxy/server/ProxyForwardAuthDataTest.java
@@ -25,7 +25,6 @@
import org.apache.bookkeeper.test.PortManager;
import org.apache.pulsar.client.admin.PulsarAdmin;
-import org.apache.pulsar.client.api.Consumer;
import org.apache.pulsar.client.api.ConsumerConfiguration;
import org.apache.pulsar.client.api.ProducerConsumerBase;
import org.apache.pulsar.client.api.PulsarClient;
@@ -48,7 +47,7 @@
private static final Logger log = LoggerFactory.getLogger(ProxyForwardAuthDataTest.class);
private int webServicePort;
private int servicePort;
-
+
@BeforeMethod
@Override
protected void setup() throws Exception {
@@ -60,11 +59,11 @@ protected void setup() throws Exception {
conf.setBrokerClientAuthenticationPlugin(BasicAuthentication.class.getName());
conf.setBrokerClientAuthenticationParameters("authParam:broker");
conf.setAuthenticateOriginalAuthData(true);
-
+
Set<String> superUserRoles = new HashSet<String>();
superUserRoles.add("admin");
conf.setSuperUserRoles(superUserRoles);
-
+
Set<String> providers = new HashSet<String>();
providers.add(BasicAuthenticationProvider.class.getName());
conf.setAuthenticationProviders(providers);
@@ -79,9 +78,9 @@ protected void setup() throws Exception {
@Override
protected void cleanup() throws Exception {
- super.internalCleanup();
+ super.internalCleanup();
}
-
+
@Test
void testForwardAuthData() throws Exception {
log.info("-- Starting {} test --", methodName);
@@ -95,15 +94,13 @@ void testForwardAuthData() throws Exception {
String subscriptionName = "my-subscriber-name";
String clientAuthParams = "authParam:client";
String proxyAuthParams = "authParam:proxy";
-
+
admin.properties().createProperty("my-property",
new PropertyAdmin(Lists.newArrayList("appid1", "appid2"), Sets.newHashSet("use")));
admin.namespaces().createNamespace(namespaceName);
-
admin.namespaces().grantPermissionOnNamespace(namespaceName, "proxy", Sets.newHashSet(AuthAction.consume, AuthAction.produce));
admin.namespaces().grantPermissionOnNamespace(namespaceName, "client", Sets.newHashSet(AuthAction.consume, AuthAction.produce));
-
// Step 2: Run Pulsar Proxy without forwarding authData - expect Exception
ProxyConfiguration proxyConfig = new ProxyConfiguration();
proxyConfig.setAuthenticationEnabled(true);
@@ -111,35 +108,29 @@ void testForwardAuthData() throws Exception {
proxyConfig.setServicePort(servicePort);
proxyConfig.setWebServicePort(webServicePort);
proxyConfig.setBrokerServiceURL("pulsar://localhost:" + BROKER_PORT);
-
proxyConfig.setBrokerClientAuthenticationPlugin(BasicAuthentication.class.getName());
proxyConfig.setBrokerClientAuthenticationParameters(proxyAuthParams);
Set<String> providers = new HashSet<>();
providers.add(BasicAuthenticationProvider.class.getName());
proxyConfig.setAuthenticationProviders(providers);
- ProxyService proxyService = new ProxyService(proxyConfig);
-
- proxyService.start();
- PulsarClient proxyClient = createPulsarClient(proxyServiceUrl, clientAuthParams);
- Consumer consumer;
- boolean exceptionOccured = false;
- try {
- consumer = proxyClient.subscribe(topicName, subscriptionName);
- } catch(Exception ex) {
- exceptionOccured = true;
- }
- Assert.assertTrue(exceptionOccured);
- proxyService.close();
-
+
+ try (ProxyService proxyService = new ProxyService(proxyConfig);
+ PulsarClient proxyClient = createPulsarClient(proxyServiceUrl, clientAuthParams)) {
+ proxyService.start();
+ proxyClient.subscribe(topicName, subscriptionName);
+ Assert.fail("Shouldn't be able to subscribe, auth required");
+ } catch (PulsarClientException.AuthorizationException e) {
+ // expected behaviour
+ }
+
// Step 3: Create proxy with forwardAuthData enabled
proxyConfig.setForwardAuthorizationCredentials(true);
- proxyService = new ProxyService(proxyConfig);
-
- proxyService.start();
- consumer = proxyClient.subscribe(topicName, subscriptionName);
- Assert.assertTrue(exceptionOccured);
- proxyService.close();
+ try (ProxyService proxyService = new ProxyService(proxyConfig);
+ PulsarClient proxyClient = createPulsarClient(proxyServiceUrl, clientAuthParams)) {
+ proxyService.start();
+ proxyClient.subscribe(topicName, subscriptionName).close();
+ }
}
private void createAdminClient() throws PulsarClientException {
@@ -147,9 +138,9 @@ private void createAdminClient() throws PulsarClientException {
org.apache.pulsar.client.api.ClientConfiguration clientConf = new org.apache.pulsar.client.api.ClientConfiguration();
clientConf.setAuthentication(BasicAuthentication.class.getName(), adminAuthParams);
- admin = spy(new PulsarAdmin(brokerUrl, clientConf));
+ admin = spy(new PulsarAdmin(brokerUrl, clientConf));
}
-
+
private PulsarClient createPulsarClient(String proxyServiceUrl, String authParams) throws PulsarClientException {
org.apache.pulsar.client.api.ClientConfiguration clientConf = new org.apache.pulsar.client.api.ClientConfiguration();
clientConf.setAuthentication(BasicAuthentication.class.getName(), authParams);
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services