qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kw...@apache.org
Subject svn commit: r1290908 - /qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
Date Sat, 18 Feb 2012 23:49:24 GMT
Author: kwall
Date: Sat Feb 18 23:49:24 2012
New Revision: 1290908

URL: http://svn.apache.org/viewvc?rev=1290908&view=rev
Log:
QPID-3827: FirewallConfigTests fail on FreeBSD Jenkins CI due to peer IP reported as non-loopback

Modified:
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java?rev=1290908&r1=1290907&r2=1290908&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
(original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
Sat Feb 18 23:49:24 2012
@@ -26,11 +26,14 @@ import javax.jms.JMSException;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
 
 public class FirewallConfigTest extends QpidBrokerTestCase 
 {
     private File _tmpConfig, _tmpVirtualhosts;
-    
+    private String _ipAddressOfBrokerHost;
+
     @Override
     protected void setUp() throws Exception
     {
@@ -46,12 +49,13 @@ public class FirewallConfigTest extends 
         _tmpVirtualhosts = File.createTempFile("virtualhosts-systests-firewall", ".xml");
         setSystemProperty("QPID_FIREWALL_VIRTUALHOSTS_SETTINGS", _tmpVirtualhosts.getAbsolutePath());
         _tmpVirtualhosts.deleteOnExit();
+
+        _ipAddressOfBrokerHost = getIpAddressOfBrokerHost();
     }
 
     private void writeFirewallFile(boolean allow, boolean inVhost) throws IOException
     {
         FileWriter out = new FileWriter(inVhost ? _tmpVirtualhosts : _tmpConfig);
-        String ipAddr = "127.0.0.1"; // FIXME: get this from InetAddress.getLocalHost().getAddress()
?
         if (inVhost) 
         {
             out.write("<virtualhosts><virtualhost><test>");
@@ -61,7 +65,7 @@ public class FirewallConfigTest extends 
             out.write("<broker>");
         }
         out.write("<security><firewall>");
-        out.write("<rule access=\""+((allow) ? "allow" : "deny")+"\" network=\""+ipAddr
+"\"/>");
+        out.write("<rule access=\""+((allow) ? "allow" : "deny")+"\" network=\"" + _ipAddressOfBrokerHost
+ "\"/>");
         out.write("</firewall></security>");
         if (inVhost)
         {
@@ -80,26 +84,23 @@ public class FirewallConfigTest extends 
         _configFile = new File("build/etc/config-systests-firewall-2.xml");
         
         super.setUp();
-        
-        Connection conn = null;
         try 
         {
             //Try to get a connection to the 'test2' vhost
             //This is expected to succeed as it is allowed at the vhost level
-            conn = getConnection(new AMQConnectionURL("amqp://guest:guest@clientid/test2?brokerlist='"
+ getBroker() + "'"));
+            getConnection(new AMQConnectionURL("amqp://guest:guest@clientid/test2?brokerlist='"
+ getBroker() + "'"));
         } 
         catch (JMSException e)
         {
             e.getLinkedException().printStackTrace();
             fail("The connection was expected to succeed: " + e.getMessage());
         }
-        
-        conn = null;
+
         try 
         {
             //Try to get a connection to the 'test' vhost
             //This is expected to fail as it is denied at the broker level
-            conn = getConnection();
+            getConnection();
             fail("We expected the connection to fail");
         } 
         catch (JMSException e)
@@ -113,13 +114,11 @@ public class FirewallConfigTest extends 
         _configFile = new File("build/etc/config-systests-firewall-3.xml");
         
         super.setUp();
-        
-        Connection conn = null;
         try 
         {
             //Try to get a connection to the 'test2' vhost
             //This is expected to fail as it is denied at the vhost level
-            conn = getConnection(new AMQConnectionURL("amqp://guest:guest@clientid/test2?brokerlist='"
+ getBroker() + "'"));
+            getConnection(new AMQConnectionURL("amqp://guest:guest@clientid/test2?brokerlist='"
+ getBroker() + "'"));
             fail("The connection was expected to fail");
         } 
         catch (JMSException e)
@@ -127,12 +126,11 @@ public class FirewallConfigTest extends 
             //ignore
         }
 
-        conn = null;
         try 
         {
             //Try to get a connection to the 'test' vhost
             //This is expected to succeed as it is allowed at the broker level
-            conn = getConnection();
+            getConnection();
         } 
         catch (JMSException e)
         {
@@ -268,4 +266,18 @@ public class FirewallConfigTest extends 
         
         assertEquals("Second connection check failed", !initial, checkConnection());
     }
+
+    private String getIpAddressOfBrokerHost()
+    {
+        String brokerHost = getBroker().getHost();
+        try
+        {
+            return InetAddress.getByName(brokerHost).getHostAddress();
+        }
+        catch (UnknownHostException e)
+        {
+            throw new RuntimeException("Could not determine IP address of host : " + brokerHost,
e);
+        }
+
+    }
 }



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message