aboutsummaryrefslogtreecommitdiff
path: root/tests/unit_tests
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2018-06-20 14:22:44 -0500
committerluigi1111 <luigi1111w@gmail.com>2018-06-20 14:22:44 -0500
commitc678413a890851c12285cce71509573f9730071b (patch)
tree1f276c7aa74c6177e0f52df7335162c2e2e4266d /tests/unit_tests
parentMerge pull request #3897 (diff)
parentunit_tests: add tests for local IP range detection (diff)
downloadmonero-c678413a890851c12285cce71509573f9730071b.tar.xz
Merge pull request #3902
f8dd433 epee: fix detection of 172.16.0.0/172.31.255.255 local IP range (moneromooo-monero) 5db9e3c unit_tests: add tests for local IP range detection (moneromooo-monero)
Diffstat (limited to 'tests/unit_tests')
-rw-r--r--tests/unit_tests/epee_utils.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 3969f50f6..3474000d8 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -45,6 +45,7 @@
#include "boost/archive/portable_binary_oarchive.hpp"
#include "hex.h"
#include "net/net_utils_base.h"
+#include "net/local_ip.h"
#include "p2p/net_peerlist_boost_serialization.h"
#include "span.h"
#include "string_tools.h"
@@ -648,3 +649,34 @@ TEST(NetUtils, NetworkAddress)
EXPECT_THROW(address1.as<epee::net_utils::ipv4_network_address>(), std::bad_cast);
EXPECT_NO_THROW(address1.as<custom_address>());
}
+
+static bool is_local(const char *s)
+{
+ uint32_t ip;
+ CHECK_AND_ASSERT_THROW_MES(epee::string_tools::get_ip_int32_from_string(ip, s), std::string("Invalid IP address: ") + s);
+ return epee::net_utils::is_ip_local(ip);
+}
+
+TEST(NetUtils, PrivateRanges)
+{
+ ASSERT_EQ(is_local("10.0.0.0"), true);
+ ASSERT_EQ(is_local("10.255.0.0"), true);
+ ASSERT_EQ(is_local("127.0.0.0"), false); // loopback is not considered local
+ ASSERT_EQ(is_local("192.167.255.255"), false);
+ ASSERT_EQ(is_local("192.168.0.0"), true);
+ ASSERT_EQ(is_local("192.168.255.255"), true);
+ ASSERT_EQ(is_local("192.169.0.0"), false);
+ ASSERT_EQ(is_local("172.0.0.0"), false);
+ ASSERT_EQ(is_local("172.15.255.255"), false);
+ ASSERT_EQ(is_local("172.16.0.0"), true);
+ ASSERT_EQ(is_local("172.16.255.255"), true);
+ ASSERT_EQ(is_local("172.31.255.255"), true);
+ ASSERT_EQ(is_local("172.32.0.0"), false);
+ ASSERT_EQ(is_local("0.0.0.0"), false);
+ ASSERT_EQ(is_local("255.255.255.254"), false);
+ ASSERT_EQ(is_local("11.255.255.255"), false);
+ ASSERT_EQ(is_local("0.0.0.10"), false);
+ ASSERT_EQ(is_local("0.0.168.192"), false);
+ ASSERT_EQ(is_local("0.0.30.172"), false);
+ ASSERT_EQ(is_local("0.0.30.127"), false);
+}