Skip to content

Commit

Permalink
test: add test coverage for CNetAddr ipv6 scoped addresses
Browse files Browse the repository at this point in the history
Summary:
This is a backport of [[bitcoin/bitcoin#19951 | core#19951]] [1/2]
bitcoin/bitcoin@5cb5fd3

Test Plan: `ninja check`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10425
  • Loading branch information
jonatack authored and PiRK committed Nov 3, 2021
1 parent 2d13fb5 commit 710e9ae
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/test/net_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,26 @@ BOOST_AUTO_TEST_CASE(cnetaddr_basic) {
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());
Expand Down

0 comments on commit 710e9ae

Please sign in to comment.