[mule-dev] Re: [mule-scm] [mule][25194] branches/mule-3.x/transports/tcp/src: MULE-6584: HTTP/ TCP bound to 127.0.0.1 listens on all interfaces

3 views
Skip to first unread message

Pablo Kraan

unread,
Jan 14, 2013, 10:14:08 AM1/14/13
to d...@mule.codehaus.org, s...@mule.codehaus.org
Missing header in TcpSocketToAddressBindingTestCase.
Can you split testRequestNotUsingLoopbackAddress in separate test methods? That test looks complex to follow
I don't think that we have to include test scenarios for services.

Pablo

On Mon, Jan 14, 2013 at 10:32 AM, <damian....@codehaus.org> wrote:
Revision
25194
Author
damian.bakarcic
Date
2013-01-14 07:32:42 -0600 (Mon, 14 Jan 2013)

Log Message

MULE-6584: HTTP/TCP bound to 127.0.0.1 listens on all interfaces
- Modified the way tcp sockets are bound to addresses. Now, inbound endpoints with host attribute set as:
	- 127.0.0.1, listen only at localhost
	- localhost, listen only at localhost
	- 0.0.0.0, listen at all local addresses

Modified Paths

Added Paths

Diff

Modified: branches/mule-3.x/transports/tcp/src/main/java/org/mule/transport/tcp/TcpServerSocketFactory.java (25193 => 25194)


--- branches/mule-3.x/transports/tcp/src/main/java/org/mule/transport/tcp/TcpServerSocketFactory.java	2013-01-12 01:48:50 UTC (rev 25193)
+++ branches/mule-3.x/transports/tcp/src/main/java/org/mule/transport/tcp/TcpServerSocketFactory.java	2013-01-14 13:32:42 UTC (rev 25194)
@@ -26,16 +26,7 @@
         String host = StringUtils.defaultIfEmpty(uri.getHost(), "localhost");
         InetAddress inetAddress = InetAddress.getByName(host);
 
-        if (inetAddress.equals(InetAddress.getLocalHost())
-                || inetAddress.isLoopbackAddress()
-                || host.trim().equals("localhost"))
-        {
-            return createServerSocket(uri.getPort(), backlog, reuse);
-        }
-        else
-        {
-            return createServerSocket(inetAddress, uri.getPort(), backlog, reuse);
-        }
+        return createServerSocket(inetAddress, uri.getPort(), backlog, reuse);
     }
 
     public ServerSocket createServerSocket(InetAddress address, int port, int backlog, Boolean reuse) throws IOException

Added: branches/mule-3.x/transports/tcp/src/test/java/org/mule/transport/tcp/issues/TcpSocketToAddressBindingTestCase.java (0 => 25194)


--- branches/mule-3.x/transports/tcp/src/test/java/org/mule/transport/tcp/issues/TcpSocketToAddressBindingTestCase.java	                        (rev 0)
+++ branches/mule-3.x/transports/tcp/src/test/java/org/mule/transport/tcp/issues/TcpSocketToAddressBindingTestCase.java	2013-01-14 13:32:42 UTC (rev 25194)
@@ -0,0 +1,137 @@
+package org.mule.transport.tcp.issues;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.mule.api.MuleMessage;
+import org.mule.api.transport.DispatchException;
+import org.mule.module.client.MuleClient;
+import org.mule.tck.AbstractServiceAndFlowTestCase;
+import org.mule.tck.junit4.rule.DynamicPort;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Tests how sockets are bound to addresses by the TCP transport. This test is related to MULE-6584.
+ */
+public class TcpSocketToAddressBindingTestCase extends AbstractServiceAndFlowTestCase
+{
+    protected static String TEST_MESSAGE = "Test TCP Request";
+
+    @Rule
+    public DynamicPort dynamicPort1 = new DynamicPort("port1");
+
+    @Rule
+    public DynamicPort dynamicPort2 = new DynamicPort("port2");
+
+    @Rule
+    public DynamicPort dynamicPort3 = new DynamicPort("port3");
+
+    public TcpSocketToAddressBindingTestCase(ConfigVariant variant, String configResources)
+    {
+        super(variant, configResources);
+    }
+
+    @Parameters
+    public static Collection<Object[]> parameters()
+    {
+        return Arrays.asList(new Object[][]{
+                {ConfigVariant.SERVICE, "tcp-socket-to-address-binding-test-service.xml"},
+                {ConfigVariant.FLOW, "tcp-socket-to-address-binding-test-flow.xml"}
+        });
+    }
+
+    @Test
+    public void testRequestUsingLoopbackAddress() throws Exception
+    {
+        MuleClient client = new MuleClient(muleContext);
+        MuleMessage result;
+
+        // Request using loopback address to all endpoints should get an appropriate response.
+        result = client.send("tcp://127.0.0.1:"+dynamicPort1.getNumber(), TEST_MESSAGE, null);
+        assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
+
+        result = client.send("tcp://127.0.0.1:"+dynamicPort2.getNumber(), TEST_MESSAGE, null);
+        assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
+
+        result = client.send("tcp://127.0.0.1:"+dynamicPort3.getNumber(), TEST_MESSAGE, null);
+        assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
+    }
+
+    @Test
+    public void testRequestNotUsingLoopbackAddress() throws Exception
+    {
+        MuleClient client = new MuleClient(muleContext);
+        MuleMessage result;
+
+        // Iterate over local addresses.
+        for (InetAddress inetAddress : getAllLocalInetAddresses())
+        {
+            if (!inetAddress.isLoopbackAddress())
+            {
+                // Request not using loopback address to endpoint listening at 127.0.0.1 should timeout.
+                try
+                {
+                    result = client.send("tcp://"+inetAddress.getHostAddress()+":"+dynamicPort1.getNumber(), TEST_MESSAGE, null);
+                    assertNull(result);
+                }
+                catch (DispatchException ex)
+                {
+                    ex.printStackTrace();
+                }
+
+                // Request not using loopback address to endpoint listening at localhost should timeout.
+                try
+                {
+                    result = client.send("tcp://"+inetAddress.getHostAddress()+":"+dynamicPort2.getNumber(), TEST_MESSAGE, null);
+                    assertNull(result);
+                }
+                catch (DispatchException ex)
+                {
+                    ex.printStackTrace();
+                }
+
+                /* Request not using loopback address to endpoint listening at all local addresses should get an
+                 * appropriate response. */
+                result = client.send("tcp://"+inetAddress.getHostAddress()+":"+dynamicPort3.getNumber(), TEST_MESSAGE, null);
+                assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
+            }
+        }
+    }
+
+    /**
+     * Returns all local {@link InetAddress}.
+     * @return A {@link java.util.List <InetAddress>} with the IPv4 local addresses.
+     * @throws SocketException If there is a problem getting the addresses.
+     */
+    private List<InetAddress> getAllLocalInetAddresses() throws SocketException
+    {
+        List<InetAddress> result = new ArrayList<InetAddress>();
+        Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
+        for (NetworkInterface netInt : Collections.list(nets))
+        {
+            Enumeration<InetAddress> inetAddresses = netInt.getInetAddresses();
+            for (InetAddress inetAddress : Collections.list(inetAddresses))
+            {
+                if (inetAddress instanceof Inet4Address)
+                {
+                    result.add(inetAddress);
+                }
+            }
+        }
+        return result;
+    }
+}
Property changes on: branches/mule-3.x/transports/tcp/src/test/java/org/mule/transport/tcp/issues/TcpSocketToAddressBindingTestCase.java
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Added: branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-flow.xml (0 => 25194)


--- branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-flow.xml	                        (rev 0)
+++ branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-flow.xml	2013-01-14 13:32:42 UTC (rev 25194)
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp" xmlns:test="http://www.mulesoft.org/schema/mule/test"
+    xsi:schemaLocation="
+               http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd
+               http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
+               http://www.mulesoft.org/schema/mule/tcp http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd">
+
+    <tcp:connector name="tcpConnector" keepSendSocketOpen="true">
+        <tcp:direct-protocol payloadOnly="true" />
+    </tcp:connector>
+
+    <tcp:endpoint name="clientEndpointLoopbackAddress" host="127.0.0.1" port="${port1}" exchange-pattern="request-response"/>
+
+    <tcp:endpoint name="clientEndpointLocalhostAddress" host="localhost" port="${port2}" exchange-pattern="request-response"/>
+
+    <tcp:endpoint name="clientEndpointAllLocalAddresses" host="0.0.0.0" port="${port3}" exchange-pattern="request-response"/>
+
+    <flow name="testComponentLoopbackAddress">
+        <inbound-endpoint ref="clientEndpointLoopbackAddress" />
+        <test:component appendString=" Received" />
+    </flow>
+
+    <flow name="testComponentLocalhostAddress">
+        <inbound-endpoint ref="clientEndpointLocalhostAddress" />
+        <test:component appendString=" Received" />
+    </flow>
+
+    <flow name="testComponentAllLocalAddresses">
+        <inbound-endpoint ref="clientEndpointAllLocalAddresses" />
+        <test:component appendString=" Received" />
+    </flow>
+</mule>
Property changes on: branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-flow.xml
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style

Added: branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-service.xml (0 => 25194)


--- branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-service.xml	                        (rev 0)
+++ branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-service.xml	2013-01-14 13:32:42 UTC (rev 25194)
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mule xmlns="http://www.mulesoft.org/schema/mule/core"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp"
+       xmlns:test="http://www.mulesoft.org/schema/mule/test"
+       xsi:schemaLocation="
+               http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd
+               http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
+               http://www.mulesoft.org/schema/mule/tcp http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd">
+
+    <tcp:connector name="tcpConnector" keepSendSocketOpen="true">
+        <tcp:direct-protocol payloadOnly="true"/>
+    </tcp:connector>
+
+    <tcp:endpoint name="clientEndpointLoopbackAddress" host="127.0.0.1" port="${port1}" exchange-pattern="request-response"/>
+
+    <tcp:endpoint name="clientEndpointLocalhostAddress" host="localhost" port="${port2}" exchange-pattern="request-response"/>
+
+    <tcp:endpoint name="clientEndpointAllLocalAddresses" host="0.0.0.0" port="${port3}" exchange-pattern="request-response"/>
+
+    <model name="main">
+        <service name="testComponentLoopbackAddress">
+            <inbound>
+                <inbound-endpoint ref="clientEndpointLoopbackAddress"/>
+            </inbound>
+            <test:component appendString=" Received"/>
+        </service>
+
+        <service name="testComponentLocalhostAddress">
+            <inbound>
+                <inbound-endpoint ref="clientEndpointLocalhostAddress"/>
+            </inbound>
+            <test:component appendString=" Received"/>
+        </service>
+
+        <service name="testComponentAllLocalAddresses">
+            <inbound>
+                <inbound-endpoint ref="clientEndpointAllLocalAddresses"/>
+            </inbound>
+            <test:component appendString=" Received"/>
+        </service>
+    </model>
+</mule>
Property changes on: branches/mule-3.x/transports/tcp/src/test/resources/tcp-socket-to-address-binding-test-service.xml
___________________________________________________________________

Added: svn:keywords

Added: svn:eol-style


To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email


Reply all
Reply to author
Forward
0 new messages