From 1a4aa7f065500515b6f9ab41e885059bb2f9e6fc Mon Sep 17 00:00:00 2001 From: akwizgran <michael@briarproject.org> Date: Wed, 10 Jan 2018 11:00:13 +0000 Subject: [PATCH] Add tests for link-local addresses. --- .../bramble/plugin/tcp/LanTcpPluginTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java index ecc41e2897..ede3df810f 100644 --- a/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java +++ b/bramble-core/src/test/java/org/briarproject/bramble/plugin/tcp/LanTcpPluginTest.java @@ -58,6 +58,9 @@ public class LanTcpPluginTest extends BrambleTestCase { // Local and remote in 192.168.0.0/16 should return true assertTrue(plugin.addressesAreOnSameLan(makeAddress(192, 168, 0, 0), makeAddress(192, 168, 255, 255))); + // Local and remote in 169.254.0.0/16 (link-local) should return true + assertTrue(plugin.addressesAreOnSameLan(makeAddress(169, 254, 0, 0), + makeAddress(169, 254, 255, 255))); // Local and remote in different recognised prefixes should return false assertFalse(plugin.addressesAreOnSameLan(makeAddress(10, 0, 0, 0), makeAddress(172, 31, 255, 255))); @@ -304,6 +307,24 @@ public class LanTcpPluginTest extends BrambleTestCase { assertEquals(0, comparator.compare(prefix10, prefix10)); } + @Test + public void testComparatorPrefersSiteLocalToLinkLocal() throws Exception { + Comparator<InetSocketAddress> comparator = new LanAddressComparator(); + InetSocketAddress prefix192 = new InetSocketAddress("192.168.0.1", 0); + InetSocketAddress prefix172 = new InetSocketAddress("172.16.0.1", 0); + InetSocketAddress prefix10 = new InetSocketAddress("10.0.0.1", 0); + InetSocketAddress linkLocal = new InetSocketAddress("169.254.0.1", 0); + + assertTrue(comparator.compare(prefix192, linkLocal) < 0); + assertTrue(comparator.compare(prefix172, linkLocal) < 0); + assertTrue(comparator.compare(prefix10, linkLocal) < 0); + + assertTrue(comparator.compare(linkLocal, prefix192) > 0); + assertTrue(comparator.compare(linkLocal, prefix172) > 0); + assertTrue(comparator.compare(linkLocal, prefix10) > 0); + assertEquals(0, comparator.compare(linkLocal, linkLocal)); + } + private boolean systemHasLocalIpv4Address() throws Exception { for (NetworkInterface i : Collections.list( NetworkInterface.getNetworkInterfaces())) { -- GitLab