diff options
author | Lee Clagett <code@leeclagett.com> | 2024-01-29 21:10:00 -0500 |
---|---|---|
committer | Lee *!* Clagett <code@leeclagett.com> | 2024-01-30 13:36:21 -0500 |
commit | 98ee46f2491dc6252040d96df5a17a237f53ebf7 (patch) | |
tree | d534260e89fbadc155199a3a3bbd096152380686 /tests/unit_tests/net.cpp | |
parent | Merge pull request #9080 (diff) | |
download | monero-98ee46f2491dc6252040d96df5a17a237f53ebf7.tar.xz |
Disable/fix ports with I2P
Diffstat (limited to '')
-rw-r--r-- | tests/unit_tests/net.cpp | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp index af0f07db0..dc79f80a1 100644 --- a/tests/unit_tests/net.cpp +++ b/tests/unit_tests/net.cpp @@ -555,8 +555,6 @@ TEST(i2p_address, invalid) EXPECT_TRUE(net::i2p_address::make(".b32.i2p:").has_error()); EXPECT_TRUE(net::i2p_address::make(b32_i2p + 1).has_error()); EXPECT_TRUE(net::i2p_address::make(boost::string_ref{b32_i2p, sizeof(b32_i2p) - 2}).has_error()); - EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":65536").has_error()); - EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":-1").has_error()); std::string i2p{b32_i2p}; i2p.at(10) = 1; @@ -570,7 +568,7 @@ TEST(i2p_address, unblockable_types) ASSERT_NE(nullptr, i2p.host_str()); EXPECT_STREQ("<unknown i2p host>", i2p.host_str()); EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str()); - EXPECT_EQ(0u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); EXPECT_TRUE(i2p.is_unknown()); EXPECT_FALSE(i2p.is_local()); EXPECT_FALSE(i2p.is_loopback()); @@ -581,7 +579,7 @@ TEST(i2p_address, unblockable_types) ASSERT_NE(nullptr, i2p.host_str()); EXPECT_STREQ("<unknown i2p host>", i2p.host_str()); EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str()); - EXPECT_EQ(0u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); EXPECT_TRUE(i2p.is_unknown()); EXPECT_FALSE(i2p.is_local()); EXPECT_FALSE(i2p.is_loopback()); @@ -596,14 +594,14 @@ TEST(i2p_address, valid) const auto address1 = net::i2p_address::make(b32_i2p); ASSERT_TRUE(address1.has_value()); - EXPECT_EQ(0u, address1->port()); + EXPECT_EQ(1u, address1->port()); EXPECT_STREQ(b32_i2p, address1->host_str()); EXPECT_STREQ(b32_i2p, address1->str().c_str()); EXPECT_TRUE(address1->is_blockable()); net::i2p_address address2{*address1}; - EXPECT_EQ(0u, address2.port()); + EXPECT_EQ(1u, address2.port()); EXPECT_STREQ(b32_i2p, address2.host_str()); EXPECT_STREQ(b32_i2p, address2.str().c_str()); EXPECT_TRUE(address2.is_blockable()); @@ -620,9 +618,9 @@ TEST(i2p_address, valid) address2 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p_2} + ":6545")); - EXPECT_EQ(6545, address2.port()); + EXPECT_EQ(1u, address2.port()); EXPECT_STREQ(b32_i2p_2, address2.host_str()); - EXPECT_EQ(std::string{b32_i2p_2} + ":6545", address2.str().c_str()); + EXPECT_EQ(std::string{b32_i2p_2}, address2.str().c_str()); EXPECT_TRUE(address2.is_blockable()); EXPECT_FALSE(address2.equal(*address1)); EXPECT_FALSE(address1->equal(address2)); @@ -635,22 +633,22 @@ TEST(i2p_address, valid) EXPECT_FALSE(address2.less(*address1)); EXPECT_TRUE(address1->less(address2)); - net::i2p_address address3 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p} + ":", 65535)); + net::i2p_address address3 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p} + ":65535")); - EXPECT_EQ(65535, address3.port()); + EXPECT_EQ(1u, address3.port()); EXPECT_STREQ(b32_i2p, address3.host_str()); - EXPECT_EQ(std::string{b32_i2p} + ":65535", address3.str().c_str()); + EXPECT_EQ(std::string{b32_i2p}, address3.str().c_str()); EXPECT_TRUE(address3.is_blockable()); - EXPECT_FALSE(address3.equal(*address1)); - EXPECT_FALSE(address1->equal(address3)); - EXPECT_FALSE(address3 == *address1); - EXPECT_FALSE(*address1 == address3); - EXPECT_TRUE(address3 != *address1); - EXPECT_TRUE(*address1 != address3); + EXPECT_TRUE(address3.equal(*address1)); + EXPECT_TRUE(address1->equal(address3)); + EXPECT_TRUE(address3 == *address1); + EXPECT_TRUE(*address1 == address3); + EXPECT_FALSE(address3 != *address1); + EXPECT_FALSE(*address1 != address3); EXPECT_TRUE(address3.is_same_host(*address1)); EXPECT_TRUE(address1->is_same_host(address3)); EXPECT_FALSE(address3.less(*address1)); - EXPECT_TRUE(address1->less(address3)); + EXPECT_FALSE(address1->less(address3)); EXPECT_FALSE(address3.equal(address2)); EXPECT_FALSE(address2.equal(address3)); @@ -666,8 +664,8 @@ TEST(i2p_address, valid) TEST(i2p_address, generic_network_address) { - const epee::net_utils::network_address i2p1{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))}; - const epee::net_utils::network_address i2p2{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))}; + const epee::net_utils::network_address i2p1{MONERO_UNWRAP(net::i2p_address::make(b32_i2p))}; + const epee::net_utils::network_address i2p2{MONERO_UNWRAP(net::i2p_address::make(b32_i2p))}; const epee::net_utils::network_address ip{epee::net_utils::ipv4_network_address{100, 200}}; EXPECT_EQ(i2p1, i2p2); @@ -675,7 +673,7 @@ TEST(i2p_address, generic_network_address) EXPECT_LT(ip, i2p1); EXPECT_STREQ(b32_i2p, i2p1.host_str().c_str()); - EXPECT_EQ(std::string{b32_i2p} + ":8080", i2p1.str()); + EXPECT_STREQ(b32_i2p, i2p1.str().c_str()); EXPECT_EQ(epee::net_utils::address_type::i2p, i2p1.get_type_id()); EXPECT_EQ(epee::net_utils::address_type::i2p, i2p2.get_type_id()); EXPECT_EQ(epee::net_utils::address_type::ipv4, ip.get_type_id()); @@ -703,11 +701,11 @@ TEST(i2p_address, epee_serializev_b32) { epee::byte_slice buffer{}; { - test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))}; + test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p))}; EXPECT_FALSE(command.i2p.is_unknown()); EXPECT_NE(net::i2p_address{}, command.i2p); EXPECT_STREQ(b32_i2p, command.i2p.host_str()); - EXPECT_EQ(10u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); epee::serialization::portable_storage stg{}; EXPECT_TRUE(command.store(stg)); @@ -719,7 +717,7 @@ TEST(i2p_address, epee_serializev_b32) EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, command.i2p); EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str()); - EXPECT_EQ(0u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); epee::serialization::portable_storage stg{}; EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); @@ -728,7 +726,7 @@ TEST(i2p_address, epee_serializev_b32) EXPECT_FALSE(command.i2p.is_unknown()); EXPECT_NE(net::i2p_address{}, command.i2p); EXPECT_STREQ(b32_i2p, command.i2p.host_str()); - EXPECT_EQ(10u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); // make sure that exceeding max buffer doesn't destroy i2p_address::_load { @@ -747,7 +745,7 @@ TEST(i2p_address, epee_serializev_b32) EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, command.i2p); EXPECT_STRNE(b32_i2p, command.i2p.host_str()); - EXPECT_EQ(0u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); } TEST(i2p_address, epee_serialize_unknown) @@ -758,7 +756,7 @@ TEST(i2p_address, epee_serialize_unknown) EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, command.i2p); EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str()); - EXPECT_EQ(0u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); epee::serialization::portable_storage stg{}; EXPECT_TRUE(command.store(stg)); @@ -770,7 +768,7 @@ TEST(i2p_address, epee_serialize_unknown) EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, command.i2p); EXPECT_STRNE(b32_i2p, command.i2p.host_str()); - EXPECT_EQ(0u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); epee::serialization::portable_storage stg{}; EXPECT_TRUE(stg.load_from_binary(epee::to_span(buffer))); @@ -779,7 +777,7 @@ TEST(i2p_address, epee_serialize_unknown) EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, command.i2p); EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str()); - EXPECT_EQ(0u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); // make sure that exceeding max buffer doesn't destroy i2p_address::_load { @@ -798,18 +796,18 @@ TEST(i2p_address, epee_serialize_unknown) EXPECT_TRUE(command.i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, command.i2p); EXPECT_STRNE(b32_i2p, command.i2p.host_str()); - EXPECT_EQ(0u, command.i2p.port()); + EXPECT_EQ(1u, command.i2p.port()); } TEST(i2p_address, boost_serialize_b32) { std::string buffer{}; { - const net::i2p_address i2p = MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10)); + const net::i2p_address i2p = MONERO_UNWRAP(net::i2p_address::make(b32_i2p)); EXPECT_FALSE(i2p.is_unknown()); EXPECT_NE(net::i2p_address{}, i2p); EXPECT_STREQ(b32_i2p, i2p.host_str()); - EXPECT_EQ(10u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); std::ostringstream stream{}; { @@ -824,7 +822,7 @@ TEST(i2p_address, boost_serialize_b32) EXPECT_TRUE(i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, i2p); EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str()); - EXPECT_EQ(0u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); std::istringstream stream{buffer}; boost::archive::portable_binary_iarchive archive{stream}; @@ -833,7 +831,7 @@ TEST(i2p_address, boost_serialize_b32) EXPECT_FALSE(i2p.is_unknown()); EXPECT_NE(net::i2p_address{}, i2p); EXPECT_STREQ(b32_i2p, i2p.host_str()); - EXPECT_EQ(10u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); } TEST(i2p_address, boost_serialize_unknown) @@ -844,7 +842,7 @@ TEST(i2p_address, boost_serialize_unknown) EXPECT_TRUE(i2p.is_unknown()); EXPECT_EQ(net::i2p_address::unknown(), i2p); EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str()); - EXPECT_EQ(0u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); std::ostringstream stream{}; { @@ -859,7 +857,7 @@ TEST(i2p_address, boost_serialize_unknown) EXPECT_TRUE(i2p.is_unknown()); EXPECT_EQ(net::i2p_address{}, i2p); EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str()); - EXPECT_EQ(0u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); std::istringstream stream{buffer}; boost::archive::portable_binary_iarchive archive{stream}; @@ -868,7 +866,7 @@ TEST(i2p_address, boost_serialize_unknown) EXPECT_TRUE(i2p.is_unknown()); EXPECT_EQ(net::i2p_address::unknown(), i2p); EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str()); - EXPECT_EQ(0u, i2p.port()); + EXPECT_EQ(1u, i2p.port()); } TEST(get_network_address, i2p) @@ -884,16 +882,13 @@ TEST(get_network_address, i2p) ASSERT_TRUE(bool(address)); EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id()); EXPECT_STREQ(b32_i2p, address->host_str().c_str()); - EXPECT_EQ(std::string{b32_i2p} + ":1000", address->str()); + EXPECT_EQ(std::string{b32_i2p}, address->str()); address = net::get_network_address(std::string{b32_i2p} + ":2000", 1000); ASSERT_TRUE(bool(address)); EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id()); EXPECT_STREQ(b32_i2p, address->host_str().c_str()); - EXPECT_EQ(std::string{b32_i2p} + ":2000", address->str()); - - address = net::get_network_address(std::string{b32_i2p} + ":65536", 1000); - EXPECT_EQ(net::error::invalid_port, address); + EXPECT_EQ(std::string{b32_i2p}, address->str()); } TEST(get_network_address, ipv4) |