mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-9787: Fix wrong return value in NetUtils.isNetworkAWithinNetworkB
This commit is contained in:
parent
6dced70aa8
commit
99fcb1f2b0
|
|
@ -875,7 +875,7 @@ public class NetUtils {
|
|||
Long[] cidrBLong = cidrToLong(cidrB);
|
||||
|
||||
long shift = MAX_CIDR - cidrBLong[1];
|
||||
return cidrALong[0] >> shift == cidrBLong[0] >> shift;
|
||||
return (cidrALong[0] >> shift == cidrBLong[0] >> shift) && (cidrALong[1] >= cidrBLong[1]);
|
||||
}
|
||||
|
||||
static boolean areCidrsNotEmpty(String cidrA, String cidrB) {
|
||||
|
|
|
|||
|
|
@ -504,6 +504,19 @@ public class NetUtilsTest {
|
|||
assertEquals(false, NetUtils.isNetworkAWithinNetworkB("", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNetworkAWithinNetworkB() {
|
||||
assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.30.0/23"));
|
||||
assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.30.0/22"));
|
||||
assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/23", "192.168.30.0/24"));
|
||||
assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/22", "192.168.30.0/24"));
|
||||
assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/24", "192.168.28.0/23"));
|
||||
assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/24", "192.168.28.0/22"));
|
||||
assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/23", "192.168.28.0/24"));
|
||||
assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/22", "192.168.28.0/24"));
|
||||
assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.28.0/22"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsNetworksOverlapWithEmptyValues() {
|
||||
assertEquals(false, NetUtils.isNetworksOverlap("", null));
|
||||
|
|
|
|||
Loading…
Reference in New Issue