diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit_tests/dns_resolver.cpp | 11 | ||||
-rw-r--r-- | tests/unit_tests/net.cpp | 35 |
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp index a6b733592..d56cbe45b 100644 --- a/tests/unit_tests/dns_resolver.cpp +++ b/tests/unit_tests/dns_resolver.cpp @@ -158,6 +158,17 @@ TEST(DNSResolver, GetTXTRecord) EXPECT_STREQ("donate.getmonero.org", addr.c_str()); } +TEST(DNSResolver, Localhost) +{ + tools::DNSResolver resolver = tools::DNSResolver::create(); + + bool avail, valid; + std::vector<std::string> ips = resolver.get_ipv4("localhost", avail, valid); + + ASSERT_EQ(1, ips.size()); + ASSERT_EQ("127.0.0.1", ips[0]); +} + bool is_equal(const char *s, const std::vector<std::string> &v) { return v.size() == 1 && v[0] == s; } TEST(DNS_PUBLIC, empty) { EXPECT_TRUE(tools::dns_utils::parse_dns_public("").empty()); } diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp index 838f1af37..af0f07db0 100644 --- a/tests/unit_tests/net.cpp +++ b/tests/unit_tests/net.cpp @@ -938,6 +938,41 @@ TEST(get_network_address, ipv4subnet) namespace { + void na_host_and_port_test(std::string addr, std::string exp_host, std::string exp_port) + { + std::string host{"xxxxx"}; + std::string port{"xxxxx"}; + net::get_network_address_host_and_port(addr, host, port); + EXPECT_EQ(exp_host, host); + EXPECT_EQ(exp_port, port); + } +} // anonymous namespace + +TEST(get_network_address_host_and_port, ipv4) +{ + na_host_and_port_test("9.9.9.9", "9.9.9.9", "xxxxx"); + na_host_and_port_test("9.9.9.9:18081", "9.9.9.9", "18081"); +} + +TEST(get_network_address_host_and_port, ipv6) +{ + na_host_and_port_test("::ffff", "::ffff", "xxxxx"); + na_host_and_port_test("[::ffff]", "::ffff", "xxxxx"); + na_host_and_port_test("[::ffff]:00231", "::ffff", "00231"); + na_host_and_port_test("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", "xxxxx"); + na_host_and_port_test("[7777:7777:7777:7777:7777:7777:7777:7777]", "7777:7777:7777:7777:7777:7777:7777:7777", "xxxxx"); + na_host_and_port_test("[7777:7777:7777:7777:7777:7777:7777:7777]:48080", "7777:7777:7777:7777:7777:7777:7777:7777", "48080"); +} + +TEST(get_network_address_host_and_port, hostname) +{ + na_host_and_port_test("localhost", "localhost", "xxxxx"); + na_host_and_port_test("bar:29080", "bar", "29080"); // Issue https://github.com/monero-project/monero/issues/8633 + na_host_and_port_test("xmrchain.net:18081", "xmrchain.net", "18081"); +} + +namespace +{ using stream_type = boost::asio::ip::tcp; struct io_thread |