diff options
author | Jon Atack <jon@atack.com> | 2020-09-13 11:04:50 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2020-10-02 16:40:15 +0200 |
commit | 5cb5fd3005435f3a7ca0c3401951d1db8db4fb88 (patch) | |
tree | e4dae68446186c2fad4612b9b078c20797908bc5 /src | |
parent | df2129a2349b1877049f250551f49a4592e73765 (diff) |
test: add test coverage for CNetAddr ipv6 scoped addresses
Diffstat (limited to 'src')
-rw-r--r-- | src/test/net_tests.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp index 261396cd0c..92792569a7 100644 --- a/src/test/net_tests.cpp +++ b/src/test/net_tests.cpp @@ -246,6 +246,25 @@ BOOST_AUTO_TEST_CASE(cnetaddr_basic) BOOST_CHECK(!addr.IsBindAny()); BOOST_CHECK_EQUAL(addr.ToString(), "1122:3344:5566:7788:9900:aabb:ccdd:eeff"); + // IPv6, scoped/link-local. See https://tools.ietf.org/html/rfc4007 + // We support non-negative decimal integers (uint32_t) as zone id indices. + // Test with a fairly-high value, e.g. 32, to avoid locally reserved ids. + const std::string link_local{"fe80::1"}; + const std::string scoped_addr{link_local + "%32"}; + BOOST_REQUIRE(LookupHost(scoped_addr, addr, false)); + BOOST_REQUIRE(addr.IsValid()); + BOOST_REQUIRE(addr.IsIPv6()); + BOOST_CHECK(!addr.IsBindAny()); + const std::string addr_str{addr.ToString()}; + BOOST_CHECK(addr_str == scoped_addr || addr_str == "fe80:0:0:0:0:0:0:1"); + // The fallback case "fe80:0:0:0:0:0:0:1" is needed for macOS 10.14/10.15 and (probably) later. + // Test that the delimiter "%" and default zone id of 0 can be omitted for the default scope. + BOOST_REQUIRE(LookupHost(link_local + "%0", addr, false)); + BOOST_REQUIRE(addr.IsValid()); + BOOST_REQUIRE(addr.IsIPv6()); + BOOST_CHECK(!addr.IsBindAny()); + BOOST_CHECK_EQUAL(addr.ToString(), link_local); + // TORv2 BOOST_REQUIRE(addr.SetSpecial("6hzph5hv6337r6p2.onion")); BOOST_REQUIRE(addr.IsValid()); |