summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2012-02-18 23:49:24 +0000
committerKeith Wall <kwall@apache.org>2012-02-18 23:49:24 +0000
commitad6fa56cef0ecbbf602b4596ebb0c301392de396 (patch)
tree677d4edc473e285a8fa6b4d8c6dcd51f52dfd6ec
parent74e8f052ab0b0297de2c668b3d6374e8354d467b (diff)
downloadqpid-python-ad6fa56cef0ecbbf602b4596ebb0c301392de396.tar.gz
QPID-3827: FirewallConfigTests fail on FreeBSD Jenkins CI due to peer IP reported as non-loopback
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1290908 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java40
1 files changed, 26 insertions, 14 deletions
diff --git a/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java b/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
index 41b101bbbe..f5adf815aa 100644
--- a/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
+++ b/java/systests/src/main/java/org/apache/qpid/server/security/firewall/FirewallConfigTest.java
@@ -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 QpidBrokerTestCase
_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 QpidBrokerTestCase
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 QpidBrokerTestCase
_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 QpidBrokerTestCase
_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 QpidBrokerTestCase
//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 QpidBrokerTestCase
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);
+ }
+
+ }
}