aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
authorJeffrey Ryan <jeffreyryan@tutanota.com>2022-11-16 15:53:15 -0600
committerJeffrey Ryan <jeffreyryan@tutanota.com>2022-11-17 18:57:04 -0600
commit38d4811c890997f20f4a3eea1b429e18bbfb4024 (patch)
treedcc2cc83c9359ff2ad7638dd34137bbbeab5344a /tests/unit_tests
parentMerge pull request #8594 (diff)
downloadmonero-38d4811c890997f20f4a3eea1b429e18bbfb4024.tar.xz
p2p: fix exclusive node DNS resolution for certain hosts [release]
Fixes #8633. The function `append_net_address` did not parse hostname + port addresses (e.g. `bar:29080`) correctly if the hostname did not contain a `'.'` character. @vtnerd comments 1 clear up 2nd conditional statement
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/net.cpp35
1 files changed, 35 insertions, 0 deletions
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