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

cshannon pushed a commit to branch activemq-5.18.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-5.18.x by this push:
     new 347bdd3edc AMQ-9478 Add unit tests for tcp & ssl socket properties 
(#1360)
347bdd3edc is described below

commit 347bdd3edc23516768250b843fc07f9a47d6b154
Author: pa-deasy <[email protected]>
AuthorDate: Wed Dec 11 15:47:21 2024 -0800

    AMQ-9478 Add unit tests for tcp & ssl socket properties (#1360)
    
    AMQ-9478 Add unit tests for tcp & ssl socket properties.
    
    (cherry picked from commit de0d68b15a83e4ddc437467d581096bc2b3335de)
---
 .../activemq/ActiveMQSslConnectionFactoryTest.java | 67 ++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
index 34c9147afe..9394d869c8 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/ActiveMQSslConnectionFactoryTest.java
@@ -20,20 +20,29 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.Socket;
 import java.security.KeyStore;
 import java.security.SecureRandom;
 import java.security.UnrecoverableKeyException;
 
 import javax.net.ssl.KeyManager;
 import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLSocket;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
 
 import org.apache.activemq.broker.BrokerService;
 import org.apache.activemq.broker.SslBrokerService;
+import org.apache.activemq.transport.Transport;
+import org.apache.activemq.transport.TransportFilter;
+import org.apache.activemq.transport.tcp.SslTransport;
+import org.apache.activemq.transport.tcp.TcpTransport;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import static org.junit.Assert.assertArrayEquals;
+
 public class ActiveMQSslConnectionFactoryTest extends CombinationTestSupport {
     private static final Log LOG = 
LogFactory.getLog(ActiveMQSslConnectionFactoryTest.class);
 
@@ -72,6 +81,26 @@ public class ActiveMQSslConnectionFactoryTest extends 
CombinationTestSupport {
         brokerStop();
     }
 
+    public void testCreateTcpConnectionWithSocketParameters() throws Exception 
{
+        // Control case: check that the factory can create an ordinary 
(non-ssl) connection.
+        String tcpUri = 
"tcp://localhost:61610?socket.OOBInline=true&socket.keepAlive=true&tcpNoDelay=true";
+        broker = createBroker(tcpUri);
+
+        // This should create the connection.
+        ActiveMQSslConnectionFactory cf = getFactory(tcpUri);
+        connection = (ActiveMQConnection)cf.createConnection();
+        assertNotNull(connection);
+
+        Socket socket = getSocketFromConnection(connection);
+        assertTrue(socket.getOOBInline());
+        assertTrue(socket.getKeepAlive());
+        assertTrue(socket.getTcpNoDelay());
+
+        connection.start();
+        connection.stop();
+        brokerStop();
+    }
+
     public void testCreateFailoverTcpConnectionUsingKnownPort() throws 
Exception {
         // Control case: check that the factory can create an ordinary 
(non-ssl) connection.
         broker = 
createBroker("tcp://localhost:61610?wireFormat.tcpNoDelayEnabled=true");
@@ -103,6 +132,30 @@ public class ActiveMQSslConnectionFactoryTest extends 
CombinationTestSupport {
         brokerStop();
     }
 
+    public void testCreateSslConnectionWithSocketParameters() throws Exception 
{
+        // Create SSL/TLS connection with trusted cert from truststore.
+        String sslUri = 
"ssl://localhost:61611?socket.enabledProtocols=TLSv1.3&socket.enableSessionCreation=true&socket.needClientAuth=true";
+        broker = createSslBroker(sslUri);
+        assertNotNull(broker);
+
+        // This should create the connection.
+        ActiveMQSslConnectionFactory cf = getFactory(sslUri);
+        cf.setTrustStore("server.keystore");
+        cf.setTrustStorePassword("password");
+        connection = (ActiveMQConnection)cf.createConnection();
+        assertNotNull(connection);
+
+        SSLSocket socket = (SSLSocket) getSocketFromConnection(connection);
+        String[] expectedProtocols = {"TLSv1.3"};
+        assertArrayEquals(expectedProtocols, socket.getEnabledProtocols());
+        assertTrue(socket.getEnableSessionCreation());
+        assertTrue(socket.getNeedClientAuth());
+
+        connection.start();
+        connection.stop();
+        brokerStop();
+    }
+
     public void testCreateSslConnectionKeyStore() throws Exception {
         // Create SSL/TLS connection with trusted cert from truststore.
         String sslUri = "ssl://localhost:61611";
@@ -371,4 +424,18 @@ public class ActiveMQSslConnectionFactoryTest extends 
CombinationTestSupport {
         return rootCause;
     }
 
+    private Socket getSocketFromConnection(ActiveMQConnection connection) 
throws Exception {
+        Transport transport = connection.getTransport();
+        while(!(transport instanceof TcpTransport)) {
+            transport = ((TransportFilter) transport).getNext();
+        }
+        Class<?> transportClass = transport.getClass();
+        if (transport instanceof SslTransport) {
+            transportClass = transportClass.getSuperclass();
+        }
+        Field socket = transportClass.getDeclaredField("socket");
+        socket.setAccessible(true);
+        return (Socket) socket.get(transport);
+    }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to