def test__is_ip__network_true__happy_path(): """Test that any valid ipv4/v6 address will return True for non-network addresses when network=False""" fake = faker.Faker() fake.add_provider(providers.internet) test_cases = [ fake.ipv4(network=False), fake.ipv6(network=False), ] for ip in test_cases: assert lib.is_ip(ip, network=False), \ "should return True for {}".format(ip)
def test__is_ip__not_net__negative(): """Test that a network ip will cause False to be returned, when network=False""" fake = faker.Faker() fake.add_provider(providers.internet) test_cases = [ fake.ipv4(network=True), fake.ipv6(network=True), ] for ip in test_cases: assert not lib.is_ip(ip, network=False), \ "should return False for {}".format(ip)
def firewall(target, action, dsthost, dstports, icmptype=None, proto="tcp"): assert exists_or_throws(target) assert action in ["accept", "drop" ], "action should be accept or drop: {}".format(action) lib.assert_valid_dstports(dstports) assert lib.is_ip( dsthost, network=True), "dsthost should be a valid ip address: {}".format( dsthost) assert proto in ["tcp", "udp", "icmp" ], "proto must be icmp, tcp, or udp: {}".format(proto) _command = "qvm-firewall {0} add action={1} dsthost={2} proto={3}".format( target, action, dsthost, proto) if icmptype is not None: assert type(icmptype) is int and 0 <= icmptype <= 43, \ "icmptype must be an integer, 0 <= n <= 43: {}".format(icmptype) assert proto == "icmp", "proto must be icmp if setting icmp type: {}".format( proto) _command += " icmptype={}".format(icmptype) lib.run(_command, target, "user", show_message=False)
def test__is_ip__fuzz_random_string(random_string): assert not lib.is_ip(random_string), \ "should return False for {}".format(random_string)
def test__is_ip__invalid_type__negative_fuzz(value): """Tests random types. IP addresses must be strings.""" assert not lib.is_ip(value), \ "should return False for {}".format(value)