diff options
author | luigi1111 <luigi1111w@gmail.com> | 2019-09-24 10:42:29 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2019-09-24 10:42:29 -0500 |
commit | 3f6096867d916e832d5d7b84ae89ec249b696f96 (patch) | |
tree | 501f975e433eebe7d3defc701f9739f43ee26c83 /tests/unit_tests | |
parent | Merge pull request #5907 (diff) | |
parent | p2p: fix bans taking port into account (diff) | |
download | monero-3f6096867d916e832d5d7b84ae89ec249b696f96.tar.xz |
Merge pull request #5916
7b076d5 p2p: fix bans taking port into account (moneromooo-monero)
Diffstat (limited to 'tests/unit_tests')
-rw-r--r-- | tests/unit_tests/ban.cpp | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp index 17fba90c6..b710f9226 100644 --- a/tests/unit_tests/ban.cpp +++ b/tests/unit_tests/ban.cpp @@ -36,6 +36,7 @@ #include "cryptonote_protocol/cryptonote_protocol_handler.inl" #define MAKE_IPV4_ADDRESS(a,b,c,d) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),0} +#define MAKE_IPV4_ADDRESS_PORT(a,b,c,d,e) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),e} #define MAKE_IPV4_SUBNET(a,b,c,d,e) epee::net_utils::ipv4_network_subnet{MAKE_IP(a,b,c,d),e} namespace cryptonote { @@ -94,10 +95,10 @@ typedef nodetool::node_server<cryptonote::t_cryptonote_protocol_handler<test_cor static bool is_blocked(Server &server, const epee::net_utils::network_address &address, time_t *t = NULL) { - std::map<epee::net_utils::network_address, time_t> hosts = server.get_blocked_hosts(); + std::map<std::string, time_t> hosts = server.get_blocked_hosts(); for (auto rec: hosts) { - if (rec.first == address) + if (rec.first == address.host_str()) { if (t) *t = rec.second; @@ -240,5 +241,22 @@ TEST(ban, subnet) ASSERT_TRUE(server.get_blocked_subnets().size() == 0); } +TEST(ban, ignores_port) +{ + time_t seconds; + test_core pr_core; + cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL); + Server server(cprotocol); + cprotocol.set_p2p_endpoint(&server); + + ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,5))); + ASSERT_TRUE(server.block_host(MAKE_IPV4_ADDRESS_PORT(1,2,3,4,5), std::numeric_limits<time_t>::max() - 1)); + ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,5))); + ASSERT_TRUE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,6))); + ASSERT_TRUE(server.unblock_host(MAKE_IPV4_ADDRESS_PORT(1,2,3,4,5))); + ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,5))); + ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,6))); +} + namespace nodetool { template class node_server<cryptonote::t_cryptonote_protocol_handler<test_core>>; } namespace cryptonote { template class t_cryptonote_protocol_handler<test_core>; } |