1 #ifndef BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_NO_MAIN
7 #include <boost/test/unit_test.hpp>
8 #include "trusted-notification-proxy.hh"
10 using namespace boost
;
12 BOOST_AUTO_TEST_SUITE(test_trusted_notification_proxy_cc
)
14 BOOST_AUTO_TEST_CASE(test_trusted_notification_proxy_bad_addrs
) {
15 string addrs
= "127.0.0.1111";
16 BOOST_CHECK_THROW(pdns::parseTrustedNotificationProxy(addrs
), PDNSException
);
17 addrs
= "127.0.0.1,:::2";
18 BOOST_CHECK_THROW(pdns::parseTrustedNotificationProxy(addrs
), PDNSException
);
21 BOOST_AUTO_TEST_CASE(test_trusted_notification_proxy_addresses_only
) {
22 string addrs
= "127.0.0.1";
23 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
24 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.1")));
25 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.2")));
26 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
27 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
30 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
31 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
32 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8::1")));
33 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
35 addrs
= "::1,192.0.2.4";
36 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
37 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
38 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.4")));
39 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8::1")));
40 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
43 BOOST_AUTO_TEST_CASE(test_trusted_notification_proxy_with_netmasks
) {
44 string addrs
= "127.0.0.0/8";
45 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
46 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.1")));
47 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.2")));
48 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("128.0.0.2")));
49 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
50 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
52 addrs
= "192.0.2.0/25";
53 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
54 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.1")));
55 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.2")));
56 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("128.0.0.2")));
57 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
58 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.128")));
59 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
60 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8::1")));
62 addrs
= "2001:db8:15::/64";
63 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
64 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.1")));
65 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
66 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
67 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8::1")));
68 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8:15::fee:1:2")));
70 addrs
= "192.0.2.0/24,2001:db8:16::/64";
71 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
72 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.1")));
73 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
74 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8::1")));
75 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8:15::fee:1:2")));
76 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
77 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8:16::5353")));
80 BOOST_AUTO_TEST_CASE(test_trusted_notification_proxy_with_netmasks_and_addresses
) {
81 string addrs
= "192.0.2.1,2001:db8:16::/64";
82 BOOST_CHECK_NO_THROW(pdns::parseTrustedNotificationProxy(addrs
));
83 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("127.0.0.1")));
84 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("::1")));
85 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8::1")));
86 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8:15::fee:1:2")));
87 BOOST_CHECK(!pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.2")));
88 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("192.0.2.1")));
89 BOOST_CHECK(pdns::isAddressTrustedNotificationProxy(ComboAddress("2001:db8:16::5353")));
92 BOOST_AUTO_TEST_SUITE_END()