]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/test-trusted-notification-proxy_cc.cc
Merge pull request #14032 from rgacogne/ddist-192-changelog-secpoll
[thirdparty/pdns.git] / pdns / test-trusted-notification-proxy_cc.cc
1 #ifndef BOOST_TEST_DYN_LINK
2 #define BOOST_TEST_DYN_LINK
3 #endif
4
5 #define BOOST_TEST_NO_MAIN
6
7 #include <boost/test/unit_test.hpp>
8 #include "trusted-notification-proxy.hh"
9
10 using namespace boost;
11
12 BOOST_AUTO_TEST_SUITE(test_trusted_notification_proxy_cc)
13
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);
19 }
20
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")));
28
29 addrs = "::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")));
34
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")));
41 }
42
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")));
51
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")));
61
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")));
69
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")));
78 }
79
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")));
90 }
91
92 BOOST_AUTO_TEST_SUITE_END()