You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2022/02/07 15:59:58 UTC

[GitHub] [activemq] mattrpav commented on a change in pull request #759: [AMQ-8413] NetworkConnector remote user and pass unit test

mattrpav commented on a change in pull request #759:
URL: https://github.com/apache/activemq/pull/759#discussion_r800805997



##########
File path: activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkRemoteUserPasswordTest.java
##########
@@ -0,0 +1,131 @@
+/**
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.activemq.network;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.Test;
+
+public class NetworkRemoteUserPasswordTest extends BaseNetworkTest {
+
+    @Override
+    protected void doSetUp(boolean deleteAllMessages) throws Exception {
+        remoteBroker = createRemoteBroker();
+        remoteBroker.setDeleteAllMessagesOnStartup(deleteAllMessages);
+        remoteBroker.start();
+        remoteBroker.waitUntilStarted();
+        localBroker = createLocalBroker();
+        localBroker.setDeleteAllMessagesOnStartup(deleteAllMessages);
+        localBroker.start();
+        localBroker.waitUntilStarted();
+        URI localURI = localBroker.getVmConnectorURI();
+        ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(localURI);
+        fac.setAlwaysSyncSend(true);
+        fac.setDispatchAsync(false);
+        localConnection = fac.createConnection("userA", "passwordA");
+        localConnection.setClientID("clientId");
+        localConnection.start();
+        URI remoteURI = remoteBroker.getVmConnectorURI();
+        fac = new ActiveMQConnectionFactory(remoteURI);
+        remoteConnection = fac.createConnection("userB", "passwordB");
+        remoteConnection.setClientID("clientId");
+        remoteConnection.start();
+        localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+    }
+
+    @Override
+    protected String getRemoteBrokerURI() {
+        return "org/apache/activemq/network/remoteBroker-authn.xml";
+    }
+
+    @Override
+    protected String getLocalBrokerURI() {
+        return "org/apache/activemq/network/localBroker-remote-userName.xml";
+    }
+
+    @Test
+    public void testNetworkRemoteUserPassword() throws JMSException {
+
+        // Across the network
+        sendTextMessage(localConnection, "include.test.foo", "This network message uses remoteUserName");
+        verifyTextMessage(remoteConnection, "include.test.foo", "This network message uses remoteUserName", null, null, false);
+    }
+
+    protected void sendTextMessage(Connection connection, String queueName, String textBody) throws JMSException {
+        Session tmpSession = null;
+        MessageProducer tmpProducer = null;
+        try { 
+            tmpSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer tmpLocalProducer = tmpSession.createProducer(tmpSession.createQueue(queueName));
+            tmpLocalProducer.send(tmpSession.createTextMessage(textBody));
+        } finally {
+            if(tmpProducer != null) { tmpProducer.close(); }
+            if(tmpSession != null) { tmpSession.close(); }
+        }
+    }
+
+    protected void verifyTextMessage(Connection connection, String queueName, String body, String property, String value, boolean propertyExists) throws JMSException {

Review comment:
       I created a new JIRA [AMQ-8477](https://issues.apache.org/jira/browse/AMQ-8477) to put this in 5.17.0 to focus time on other 5.16.4 release critical actions.

##########
File path: activemq-unit-tests/src/test/java/org/apache/activemq/network/NetworkRemoteUserPasswordTest.java
##########
@@ -0,0 +1,131 @@
+/**
+ * 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.activemq.network;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.junit.Test;
+
+public class NetworkRemoteUserPasswordTest extends BaseNetworkTest {
+
+    @Override
+    protected void doSetUp(boolean deleteAllMessages) throws Exception {
+        remoteBroker = createRemoteBroker();
+        remoteBroker.setDeleteAllMessagesOnStartup(deleteAllMessages);
+        remoteBroker.start();
+        remoteBroker.waitUntilStarted();
+        localBroker = createLocalBroker();
+        localBroker.setDeleteAllMessagesOnStartup(deleteAllMessages);
+        localBroker.start();
+        localBroker.waitUntilStarted();
+        URI localURI = localBroker.getVmConnectorURI();
+        ActiveMQConnectionFactory fac = new ActiveMQConnectionFactory(localURI);
+        fac.setAlwaysSyncSend(true);
+        fac.setDispatchAsync(false);
+        localConnection = fac.createConnection("userA", "passwordA");
+        localConnection.setClientID("clientId");
+        localConnection.start();
+        URI remoteURI = remoteBroker.getVmConnectorURI();
+        fac = new ActiveMQConnectionFactory(remoteURI);
+        remoteConnection = fac.createConnection("userB", "passwordB");
+        remoteConnection.setClientID("clientId");
+        remoteConnection.start();
+        localSession = localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        remoteSession = remoteConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+    }
+
+    @Override
+    protected String getRemoteBrokerURI() {
+        return "org/apache/activemq/network/remoteBroker-authn.xml";
+    }
+
+    @Override
+    protected String getLocalBrokerURI() {
+        return "org/apache/activemq/network/localBroker-remote-userName.xml";
+    }
+
+    @Test
+    public void testNetworkRemoteUserPassword() throws JMSException {
+
+        // Across the network
+        sendTextMessage(localConnection, "include.test.foo", "This network message uses remoteUserName");
+        verifyTextMessage(remoteConnection, "include.test.foo", "This network message uses remoteUserName", null, null, false);
+    }
+
+    protected void sendTextMessage(Connection connection, String queueName, String textBody) throws JMSException {
+        Session tmpSession = null;
+        MessageProducer tmpProducer = null;
+        try { 
+            tmpSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            MessageProducer tmpLocalProducer = tmpSession.createProducer(tmpSession.createQueue(queueName));
+            tmpLocalProducer.send(tmpSession.createTextMessage(textBody));
+        } finally {
+            if(tmpProducer != null) { tmpProducer.close(); }
+            if(tmpSession != null) { tmpSession.close(); }
+        }
+    }
+
+    protected void verifyTextMessage(Connection connection, String queueName, String body, String property, String value, boolean propertyExists) throws JMSException {

Review comment:
       I created a new JIRA [AMQ-8477](https://issues.apache.org/jira/browse/AMQ-8477) to put this request inline for 5.17.0 to focus time on other 5.16.4 release critical actions.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org