diff options
author | Thomas Winget <tewinget@gmail.com> | 2014-09-17 15:35:52 -0400 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2014-09-23 22:58:07 +0200 |
commit | 578050e91d8fad8834a7c180a15824f5a46940f9 (patch) | |
tree | ca6c05a0ef75aa30f50b37fb62b7985919d8876b /tests | |
parent | Updated CMake files -- added libunbound linker flag (diff) | |
download | monero-578050e91d8fad8834a7c180a15824f5a46940f9.tar.xz |
ipv4 and ipv6 resolution working
IPv4 and IPv6 name resolution working.
Unit tests written (and passing).
net_node.{h,inl} code modified to use DNS seeds.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_tests/dns_resolver.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp new file mode 100644 index 000000000..fe8fe602b --- /dev/null +++ b/tests/unit_tests/dns_resolver.cpp @@ -0,0 +1,65 @@ +#include "gtest/gtest.h" + +#include "common/dns_utils.h" + +TEST(DNSResolver, IPv4Success) +{ + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv4("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("93.184.216.119", ips[0].c_str()); + + ips = tools::DNSResolver::instance().get_ipv4("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("93.184.216.119", ips[0].c_str()); +} + +TEST(DNSResolver, IPv4Failure) +{ + // guaranteed by IANA/ICANN/RFC to be invalid + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv4("example.invalid"); + + ASSERT_EQ(0, ips.size()); + + ips = tools::DNSResolver::instance().get_ipv4("example.invalid"); + + ASSERT_EQ(0, ips.size()); +} + +TEST(DNSResolver, IPv6Success) +{ + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv6("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str()); + + ips = tools::DNSResolver::instance().get_ipv6("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str()); +} + +TEST(DNSResolver, IPv6Failure) +{ + // guaranteed by IANA/ICANN/RFC to be invalid + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv6("example.invalid"); + + ASSERT_EQ(0, ips.size()); + + ips = tools::DNSResolver::instance().get_ipv6("example.invalid"); + + ASSERT_EQ(0, ips.size()); +} |