def test_all_subnets_have_one_matching_ip(self): ips = util.generate_ips("10.0.0.1", "10.0.0.40") ips.extend(util.generate_ips("10.0.1.1", "10.0.1.40")) # regardless of extra IPs that may not match. The requirement # is already satisfied ips.extend(util.generate_ips("10.1.2.1", "10.1.2.40")) subnets = ["10.0.0.1/16", "10.0.1.1/16"] assert new.validate_host_ip(ips, subnets) is None
class TestIpInSubnet(object): @pytest.mark.parametrize('ip', util.generate_ips("10.0.0.1", "10.0.0.255")) def test_correct_for_10_0_0_255(self, ip): assert net.ip_in_subnet(ip, "10.0.0.0/16") @pytest.mark.parametrize('ip', util.generate_ips("10.0.0.1", "10.0.0.255")) def test_false_for_10_0_0_255(self, ip): assert net.ip_in_subnet(ip, "10.2.0.0/24") is False @pytest.mark.parametrize('ip', util.generate_ips("255.255.255.1", "255.255.255.255")) def test_false_for_255_addresses(self, ip): assert net.ip_in_subnet(ip, "10.9.1.0/16") is False @pytest.mark.parametrize('ip', util.generate_ips("172.7.1.1", "172.7.1.255")) def test_false_for_172_addresses(self, ip): assert net.ip_in_subnet(ip, "172.3.0.0/16") is False @pytest.mark.parametrize('ip', util.generate_ips("10.9.8.0", "10.9.8.255")) def test_true_for_16_subnets(self, ip): assert net.ip_in_subnet(ip, "10.9.1.0/16") is True @pytest.mark.parametrize('ip', util.generate_ips("10.9.8.0", "10.9.8.255")) def test_false_for_24_subnets(self, ip): assert net.ip_in_subnet(ip, "10.9.1.0/24") is False
def test_for_all_subnets_all_ips_match(self): ips = util.generate_ips("10.0.0.1", "10.0.0.40") ips.extend(util.generate_ips("10.0.1.1", "10.0.1.40")) subnets = ["10.0.0.1/16", "10.0.1.1/16"] assert new.validate_host_ip(ips, subnets) is None
def test_not_all_subnets_have_one_matching_ip(self): ips = util.generate_ips("10.0.0.1", "10.0.0.40") ips.extend(util.generate_ips("10.0.1.1", "10.0.1.40")) subnets = ["10.0.0.1/16", "10.1.1.1/16"] with pytest.raises(RuntimeError): new.validate_host_ip(ips, subnets)