Umoxfo commented on a change in pull request #25: NET-405 Support for IPv6 in SubnetUtils URL: https://github.com/apache/commons-net/pull/25#discussion_r280973373
########## File path: src/test/java/org/apache/commons/net/SubnetUtilsTest.java ########## @@ -375,4 +375,52 @@ public void testNET641() { assertFalse(new SubnetUtils("192.168.1.0/31").getInfo().isInRange("0.0.0.0")); assertFalse(new SubnetUtils("192.168.1.0/32").getInfo().isInRange("0.0.0.0")); } + + /** + * Test case for IPv6 addresses + * + * Relate to NET-405 + */ + public void testIP6Address() { + //Valid address test + SubnetUtils subnetUtils = new SubnetUtils("2001:db8:3c0d:5b6d:0:0:42:8329/58"); + SubnetInfo subnetInfo = subnetUtils.getInfo(); + assertEquals("CIDR-Notation", "2001:db8:3c0d:5b6d::42:8329/58", subnetInfo.getCIDRNotation()); + assertEquals("Lowest Address", "2001:db8:3c0d:5b40::", subnetInfo.getLowAddress()); + assertEquals("Highest Address", "2001:db8:3c0d:5b7f:ffff:ffff:ffff:ffff", subnetInfo.getHighAddress()); + assertEquals("Address counts", "1180591620717411303424", subnetInfo.getAddressCountString()); + + //Address range test + assertTrue(subnetInfo.isInRange("2001:db8:3c0d:5b6d:0:0:42:8329")); + assertTrue(subnetInfo.isInRange("2001:db8:3c0d:5b40::")); + assertTrue(subnetInfo.isInRange("2001:db8:3c0d:5b7f:ffff:ffff:ffff:ffff")); + assertTrue(subnetInfo.isInRange("2001:db8:3c0d:5b53:0:0:0:1")); + assertFalse(subnetInfo.isInRange("2001:db8:3c0d:5b3f:ffff:ffff:ffff:ffff")); + assertFalse(subnetInfo.isInRange("2001:db8:3c0d:5b80::")); + + //Invalid address test + try { + //No colons + new SubnetUtils("2001db83c0d5b6d004283291/58"); + + //Out of Range + new SubnetUtils("2001d:b83c0:d5b6d:2428:3291f:b8:b75fe:abef5/58"); + + //Beginning a Colon + new SubnetUtils(":2001:db8:0:2:0:9abc/58"); + + //Zero Compression +// subnetUtils = new SubnetUtils("2001:db8::2::9abc/58"); + + //Length + new SubnetUtils("2001:db8:3c0d:5b6d:0:0:42:8329:1/58"); + + //Out of Subnet + new SubnetUtils("2001:db8:3c0d:5b6d:0:0:42:8329/129"); + + fail("Should have thrown IllegalArgumentException"); + } catch (IllegalArgumentException expected) { + // Ignored Review comment: I will modify it but take time. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services