You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ch...@apache.org on 2014/07/16 17:47:13 UTC

svn commit: r1611059 - in /qpid/trunk/qpid/cpp/src: qpid/sys/posix/SocketAddress.cpp qpid/sys/windows/SocketAddress.cpp tests/AclHost.cpp

Author: chug
Date: Wed Jul 16 15:47:12 2014
New Revision: 1611059

URL: http://svn.apache.org/r1611059
Log:
QPID-5898: AclHost unit test fails on systems with no IPv6
* In SocketAddress::isComparable catch exceptions thrown by
  getAddrInfo when address family is not supported.
* Delete self test that expects hosts to have 127.0.0.1 and
  ::1 as valid addresses for localhost.
* In self tests sense whether IPv4 and IPv6 are supported
  and skip running tests that use those families accordingly.


Modified:
    qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp
    qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp
    qpid/trunk/qpid/cpp/src/tests/AclHost.cpp

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp?rev=1611059&r1=1611058&r2=1611059&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/posix/SocketAddress.cpp Wed Jul 16 15:47:12 2014
@@ -172,33 +172,43 @@ std::string SocketAddress::comparisonDet
  * This check is run at acl file load time and not at run tme.
  */
 bool SocketAddress::isComparable(const SocketAddress& hiPeer) const {
-    // May only compare if this socket is IPv4 or IPv6
-    SocketAddress lo(*this);
-    const ::addrinfo& peerLoInfo = getAddrInfo(lo);
-    if (!(peerLoInfo.ai_family == AF_INET || peerLoInfo.ai_family == AF_INET6)) {
-        return false;
-    }
-    // May only compare if peer socket is same family
-    SocketAddress hi(hiPeer);
-    const ::addrinfo& peerHiInfo = getAddrInfo(hi);
-    if (peerLoInfo.ai_family != peerHiInfo.ai_family) {
-        return false;
-    }
-    // Host names that resolve to lists are allowed if they are equal.
-    // For example: localhost, or fjord.lab.example.com
-    if ((*this).asString() == hiPeer.asString()) {
-        return true;
-    }
-    // May only compare if this and peer resolve to single address.
-    if (lo.nextAddress() || hi.nextAddress()) {
-        return false;
-    }
-    // Make sure that the lo/hi relationship is ok
-    int res;
-    if (!compareAddresses(peerLoInfo, peerHiInfo, res) || res < 0) {
+    try {
+        // May only compare if this socket is IPv4 or IPv6
+        SocketAddress lo(*this);
+        const ::addrinfo& peerLoInfo = getAddrInfo(lo);
+        if (!(peerLoInfo.ai_family == AF_INET || peerLoInfo.ai_family == AF_INET6)) {
+            return false;
+        }
+        try {
+            // May only compare if peer socket is same family
+            SocketAddress hi(hiPeer);
+            const ::addrinfo& peerHiInfo = getAddrInfo(hi);
+            if (peerLoInfo.ai_family != peerHiInfo.ai_family) {
+                return false;
+            }
+            // Host names that resolve to lists are allowed if they are equal.
+            // For example: localhost, or fjord.lab.example.com
+            if ((*this).asString() == hiPeer.asString()) {
+                return true;
+            }
+            // May only compare if this and peer resolve to single address.
+            if (lo.nextAddress() || hi.nextAddress()) {
+                return false;
+            }
+            // Make sure that the lo/hi relationship is ok
+            int res;
+            if (!compareAddresses(peerLoInfo, peerHiInfo, res) || res < 0) {
+                return false;
+            }
+            return true;
+        } catch (Exception) {
+            // failed to resolve hi
+            return false;
+        }
+    } catch (Exception) {
+        // failed to resolve lo
         return false;
     }
-    return true;
 }
 
 /**

Modified: qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp?rev=1611059&r1=1611058&r2=1611059&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/sys/windows/SocketAddress.cpp Wed Jul 16 15:47:12 2014
@@ -173,33 +173,43 @@ std::string SocketAddress::comparisonDet
  * This check is run at acl file load time and not at run tme.
  */
 bool SocketAddress::isComparable(const SocketAddress& hiPeer) const {
-    // May only compare if this socket is IPv4 or IPv6
-    SocketAddress lo(*this);
-    const ::addrinfo& peerLoInfo = getAddrInfo(lo);
-    if (!(peerLoInfo.ai_family == AF_INET || peerLoInfo.ai_family == AF_INET6)) {
-        return false;
-    }
-    // May only compare if peer socket is same family
-    SocketAddress hi(hiPeer);
-    const ::addrinfo& peerHiInfo = getAddrInfo(hi);
-    if (peerLoInfo.ai_family != peerHiInfo.ai_family) {
-        return false;
-    }
-    // Host names that resolve to lists are allowed if they are equal.
-    // For example: localhost, or fjord.lab.example.com
-    if ((*this).asString() == hiPeer.asString()) {
-        return true;
-    }
-    // May only compare if this and peer resolve to single address.
-    if (lo.nextAddress() || hi.nextAddress()) {
-        return false;
-    }
-    // Make sure that the lo/hi relationship is ok
-    int res;
-    if (!compareAddresses(peerLoInfo, peerHiInfo, res) || res < 0) {
+    try {
+        // May only compare if this socket is IPv4 or IPv6
+        SocketAddress lo(*this);
+        const ::addrinfo& peerLoInfo = getAddrInfo(lo);
+        if (!(peerLoInfo.ai_family == AF_INET || peerLoInfo.ai_family == AF_INET6)) {
+            return false;
+        }
+        try {
+            // May only compare if peer socket is same family
+            SocketAddress hi(hiPeer);
+            const ::addrinfo& peerHiInfo = getAddrInfo(hi);
+            if (peerLoInfo.ai_family != peerHiInfo.ai_family) {
+                return false;
+            }
+            // Host names that resolve to lists are allowed if they are equal.
+            // For example: localhost, or fjord.lab.example.com
+            if ((*this).asString() == hiPeer.asString()) {
+                return true;
+            }
+            // May only compare if this and peer resolve to single address.
+            if (lo.nextAddress() || hi.nextAddress()) {
+                return false;
+            }
+            // Make sure that the lo/hi relationship is ok
+            int res;
+            if (!compareAddresses(peerLoInfo, peerHiInfo, res) || res < 0) {
+                return false;
+            }
+            return true;
+        } catch (Exception) {
+            // failed to resolve hi
+            return false;
+        }
+    } catch (Exception) {
+        // failed to resolve lo
         return false;
     }
-    return true;
 }
 
 /**

Modified: qpid/trunk/qpid/cpp/src/tests/AclHost.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/AclHost.cpp?rev=1611059&r1=1611058&r2=1611059&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/AclHost.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/AclHost.cpp Wed Jul 16 15:47:12 2014
@@ -20,6 +20,7 @@
 #include "unit_test.h"
 #include "test_tools.h"
 #include "qpid/AclHost.h"
+#include "qpid/sys/SocketAddress.h"
 #include <boost/assign.hpp>
 
 using namespace std;
@@ -33,87 +34,133 @@ QPID_AUTO_TEST_SUITE(AclHostTestSuite)
 
 #define ACLURL_CHECK_INVALID(STR) BOOST_CHECK_THROW(AclHost(STR), AclHost::Invalid)
 
+#define SENSE_IP_VERSIONS() \
+  bool haveIPv4(true); \
+  try { \
+    sys::SocketAddress sa("1.1.1.1", ""); \
+    sa.firstAddress(); \
+} catch (qpid::Exception) { \
+    haveIPv4 = false; \
+} \
+  bool haveIPv6(true); \
+  try { \
+    sys::SocketAddress sa("::1", ""); \
+    sa.firstAddress(); \
+} catch (qpid::Exception) { \
+    haveIPv6 = false; \
+} \
+(void) haveIPv4; \
+(void) haveIPv6;
+
 QPID_AUTO_TEST_CASE(TestParseTcpIPv4) {
-  BOOST_CHECK_EQUAL(AclHost("1.1.1.1").str(),         "(1.1.1.1,1.1.1.1)");
-  BOOST_CHECK_EQUAL(AclHost("1.1.1.1,2.2.2.2").str(), "(1.1.1.1,2.2.2.2)");
+    SENSE_IP_VERSIONS();
+    if (haveIPv4) {
+        BOOST_CHECK_EQUAL(AclHost("1.1.1.1").str(),         "(1.1.1.1,1.1.1.1)");
+        BOOST_CHECK_EQUAL(AclHost("1.1.1.1,2.2.2.2").str(), "(1.1.1.1,2.2.2.2)");
+    }
 }
 
-// QPID_AUTO_TEST_CASE(TestParseTcpIPv6) {
-//   BOOST_CHECK_EQUAL(AclHost("[::1]").str(),         "([::1],[::1])");
-//   BOOST_CHECK_EQUAL(AclHost("[::1],::5").str(),     "([::1],[::5])");
-// }
+QPID_AUTO_TEST_CASE(TestParseTcpIPv6) {
+    SENSE_IP_VERSIONS();
+    if (haveIPv6) {
+        BOOST_CHECK_EQUAL(AclHost("[::1]").str(),         "([::1],[::1])");
+        BOOST_CHECK_EQUAL(AclHost("[::1],::5").str(),     "([::1],[::5])");
+    }
+}
 
 QPID_AUTO_TEST_CASE(TestParseAll) {
-  BOOST_CHECK_EQUAL(AclHost("").str(), "(all)");
+    SENSE_IP_VERSIONS();
+    if (haveIPv4 || haveIPv6) {
+        BOOST_CHECK_EQUAL(AclHost("").str(), "(all)");
+    }
 }
 
-// QPID_AUTO_TEST_CASE(TestInvalidMixedIpFamilies) {
-//   ACLURL_CHECK_INVALID("1.1.1.1,[::1]");
-//   ACLURL_CHECK_INVALID("[::1],1.1.1.1");
-// }
+QPID_AUTO_TEST_CASE(TestInvalidMixedIpFamilies) {
+    SENSE_IP_VERSIONS();
+    if (haveIPv4 && haveIPv6) {
+        ACLURL_CHECK_INVALID("1.1.1.1,[::1]");
+        ACLURL_CHECK_INVALID("[::1],1.1.1.1");
+    }
+}
 
 QPID_AUTO_TEST_CASE(TestMalformedIPv4) {
-  ACLURL_CHECK_INVALID("1.1.1.1.1");
-  ACLURL_CHECK_INVALID("1.1.1.777");
-  ACLURL_CHECK_INVALID("1.1.1.1abcd");
-  ACLURL_CHECK_INVALID("1.1.1.*");
+    SENSE_IP_VERSIONS();
+    if (haveIPv4) {
+        ACLURL_CHECK_INVALID("1.1.1.1.1");
+        ACLURL_CHECK_INVALID("1.1.1.777");
+        ACLURL_CHECK_INVALID("1.1.1.1abcd");
+        ACLURL_CHECK_INVALID("1.1.1.*");
+    }
 }
 
 QPID_AUTO_TEST_CASE(TestRangeWithInvertedSizeOrder) {
-  ACLURL_CHECK_INVALID("1.1.1.100,1.1.1.1");
-//   ACLURL_CHECK_INVALID("[FF::1],[::1]");
+    SENSE_IP_VERSIONS();
+    if (haveIPv4) {
+        ACLURL_CHECK_INVALID("1.1.1.100,1.1.1.1");
+    }
+    if (haveIPv6) {
+        ACLURL_CHECK_INVALID("[FF::1],[::1]");
+    }
 }
 
 QPID_AUTO_TEST_CASE(TestSingleHostResolvesMultipleAddresses) {
-  AclHost XX("localhost");
+    SENSE_IP_VERSIONS();
+    AclHost XX("localhost");
 }
 
 QPID_AUTO_TEST_CASE(TestMatchSingleAddresses) {
-    AclHost host1("1.1.1.1");
-    BOOST_CHECK(host1.match("1.1.1.1") == true);
-    BOOST_CHECK(host1.match("1.2.1.1") == false);
-
-//     AclHost host2("FF::1");
-//     BOOST_CHECK(host2.match("00FF:0000::1") == true);
-}
-
-QPID_AUTO_TEST_CASE(TestMatchMultipleAddresses) {
-    AclHost host1("localhost");
-    BOOST_CHECK(host1.match("127.0.0.1") == true);
-//     BOOST_CHECK(host1.match("::1")       == true);
-    BOOST_CHECK(host1.match("128.1.1.1") == false);
-//     BOOST_CHECK(host1.match("::abcd")    == false);
+    SENSE_IP_VERSIONS();
+    if (haveIPv4) {
+        AclHost host1("1.1.1.1");
+        BOOST_CHECK(host1.match("1.1.1.1") == true);
+        BOOST_CHECK(host1.match("1.2.1.1") == false);
+    }
+    if (haveIPv6) {
+        AclHost host2("FF::1");
+        BOOST_CHECK(host2.match("00FF:0000::1") == true);
+    }
 }
 
 QPID_AUTO_TEST_CASE(TestMatchIPv4Range) {
-    AclHost host1("192.168.0.0,192.168.255.255");
-    BOOST_CHECK(host1.match("128.1.1.1")       == false);
-    BOOST_CHECK(host1.match("192.167.255.255") == false);
-    BOOST_CHECK(host1.match("192.168.0.0")     == true);
-    BOOST_CHECK(host1.match("192.168.0.1")     == true);
-    BOOST_CHECK(host1.match("192.168.1.0")     == true);
-    BOOST_CHECK(host1.match("192.168.255.254") == true);
-    BOOST_CHECK(host1.match("192.168.255.255") == true);
-    BOOST_CHECK(host1.match("192.169.0.0")     == false);
-//     BOOST_CHECK(host1.match("::1")             == false);
-}
-
-// QPID_AUTO_TEST_CASE(TestMatchIPv6Range) {
-//     AclHost host1("::10,::1:0");
-//     BOOST_CHECK(host1.match("::1")     == false);
-//     BOOST_CHECK(host1.match("::f")     == false);
-//     BOOST_CHECK(host1.match("::10")    == true);
-//     BOOST_CHECK(host1.match("::11")    == true);
-//     BOOST_CHECK(host1.match("::ffff")  == true);
-//     BOOST_CHECK(host1.match("::1:0")   == true);
-//     BOOST_CHECK(host1.match("::1:1")   == false);
-//     BOOST_CHECK(host1.match("192.169.0.0")     == false);
-//     AclHost host2("[fc00::],[fc00::ff]");
-//     BOOST_CHECK(host2.match("fc00::")     == true);
-//     BOOST_CHECK(host2.match("fc00::1")    == true);
-//     BOOST_CHECK(host2.match("fc00::ff")   == true);
-//     BOOST_CHECK(host2.match("fc00::100")  == false);
-// }
+    SENSE_IP_VERSIONS();
+    if (haveIPv4) {
+        AclHost host1("192.168.0.0,192.168.255.255");
+        BOOST_CHECK(host1.match("128.1.1.1")       == false);
+        BOOST_CHECK(host1.match("192.167.255.255") == false);
+        BOOST_CHECK(host1.match("192.168.0.0")     == true);
+        BOOST_CHECK(host1.match("192.168.0.1")     == true);
+        BOOST_CHECK(host1.match("192.168.1.0")     == true);
+        BOOST_CHECK(host1.match("192.168.255.254") == true);
+        BOOST_CHECK(host1.match("192.168.255.255") == true);
+        BOOST_CHECK(host1.match("192.169.0.0")     == false);
+        if (haveIPv6) {
+            BOOST_CHECK(host1.match("::1")             == false);
+        }
+    }
+}
+
+QPID_AUTO_TEST_CASE(TestMatchIPv6Range) {
+    SENSE_IP_VERSIONS();
+    if (haveIPv6) {
+        AclHost host1("::10,::1:0");
+        BOOST_CHECK(host1.match("::1")     == false);
+        BOOST_CHECK(host1.match("::f")     == false);
+        BOOST_CHECK(host1.match("::10")    == true);
+        BOOST_CHECK(host1.match("::11")    == true);
+        BOOST_CHECK(host1.match("::ffff")  == true);
+        BOOST_CHECK(host1.match("::1:0")   == true);
+        BOOST_CHECK(host1.match("::1:1")   == false);
+        if (haveIPv4) {
+            BOOST_CHECK(host1.match("192.169.0.0")     == false);
+        }
+        AclHost host2("[fc00::],[fc00::ff]");
+        BOOST_CHECK(host2.match("fc00::")     == true);
+        BOOST_CHECK(host2.match("fc00::1")    == true);
+        BOOST_CHECK(host2.match("fc00::ff")   == true);
+        BOOST_CHECK(host2.match("fc00::100")  == false);
+
+    }
+}
 QPID_AUTO_TEST_SUITE_END()
 
 }} // namespace qpid::tests



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org