diff options
| author | Charles E. Rolke <chug@apache.org> | 2014-07-16 15:47:12 +0000 |
|---|---|---|
| committer | Charles E. Rolke <chug@apache.org> | 2014-07-16 15:47:12 +0000 |
| commit | 29d37f899af4e87d5034c39d60a8a0c95b98d0f5 (patch) | |
| tree | 22f5a1d06177fe336a988cd2e4300b135fc05471 /qpid/cpp/src/tests/AclHost.cpp | |
| parent | f49cf6532cb59e0886d5a4a88d7d63f9f36652ca (diff) | |
| download | qpid-python-29d37f899af4e87d5034c39d60a8a0c95b98d0f5.tar.gz | |
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.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1611059 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/cpp/src/tests/AclHost.cpp')
| -rw-r--r-- | qpid/cpp/src/tests/AclHost.cpp | 163 |
1 files changed, 105 insertions, 58 deletions
diff --git a/qpid/cpp/src/tests/AclHost.cpp b/qpid/cpp/src/tests/AclHost.cpp index 5fa87711e5..7d60c5a63d 100644 --- a/qpid/cpp/src/tests/AclHost.cpp +++ b/qpid/cpp/src/tests/AclHost.cpp @@ -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); + 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) { -// 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); -// } +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 |
