def test_wildcard_attributes(self): rule = ExitPolicyRule('reject *:*') self.assertEqual(AddressType.WILDCARD, rule.get_address_type()) self.assertEqual(None, rule.address) self.assertEqual(None, rule.get_mask()) self.assertEqual(None, rule.get_masked_bits()) self.assertEqual(1, rule.min_port) self.assertEqual(65535, rule.max_port)
def test_valid_ipv4_addresses(self): test_inputs = { '0.0.0.0': ('0.0.0.0', '255.255.255.255', 32), '127.0.0.1/32': ('127.0.0.1', '255.255.255.255', 32), '192.168.0.50/24': ('192.168.0.50', '255.255.255.0', 24), '255.255.255.255/0': ('255.255.255.255', '0.0.0.0', 0), } for rule_addr, attr in test_inputs.items(): address, mask, masked_bits = attr rule = ExitPolicyRule('accept %s:*' % rule_addr) self.assertEqual(AddressType.IPv4, rule.get_address_type()) self.assertEqual(address, rule.address) self.assertEqual(mask, rule.get_mask()) self.assertEqual(masked_bits, rule.get_masked_bits())
def test_valid_ipv4_addresses(self): test_inputs = { "0.0.0.0": ("0.0.0.0", "255.255.255.255", 32), "127.0.0.1/32": ("127.0.0.1", "255.255.255.255", 32), "192.168.0.50/24": ("192.168.0.50", "255.255.255.0", 24), "255.255.255.255/0": ("255.255.255.255", "0.0.0.0", 0), } for rule_addr, attr in test_inputs.items(): address, mask, masked_bits = attr rule = ExitPolicyRule("accept %s:*" % rule_addr) self.assertEquals(AddressType.IPv4, rule.get_address_type()) self.assertEquals(address, rule.address) self.assertEquals(mask, rule.get_mask()) self.assertEquals(masked_bits, rule.get_masked_bits())
def test_valid_ipv6_addresses(self): test_inputs = { '[fe80:0000:0000:0000:0202:b3ff:fe1e:8329]': ('FE80:0000:0000:0000:0202:B3FF:FE1E:8329', 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', 128), '[FE80::0202:b3ff:fe1e:8329]': ('FE80:0000:0000:0000:0202:B3FF:FE1E:8329', 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', 128), '[0000:0000:0000:0000:0000:0000:0000:0000]/0': ('0000:0000:0000:0000:0000:0000:0000:0000', '0000:0000:0000:0000:0000:0000:0000:0000', 0), '[::]': ('0000:0000:0000:0000:0000:0000:0000:0000', 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF', 128), } for rule_addr, attr in test_inputs.items(): address, mask, masked_bits = attr rule = ExitPolicyRule('accept %s:*' % rule_addr) self.assertEqual(AddressType.IPv6, rule.get_address_type()) self.assertEqual(address, rule.address) self.assertEqual(mask, rule.get_mask()) self.assertEqual(masked_bits, rule.get_masked_bits())
def test_valid_ipv6_addresses(self): test_inputs = { "[fe80:0000:0000:0000:0202:b3ff:fe1e:8329]": ("FE80:0000:0000:0000:0202:B3FF:FE1E:8329", "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 128), "[FE80::0202:b3ff:fe1e:8329]": ("FE80:0000:0000:0000:0202:B3FF:FE1E:8329", "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 128), "[0000:0000:0000:0000:0000:0000:0000:0000]/0": ("0000:0000:0000:0000:0000:0000:0000:0000", "0000:0000:0000:0000:0000:0000:0000:0000", 0), "[::]": ("0000:0000:0000:0000:0000:0000:0000:0000", "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF", 128), } for rule_addr, attr in test_inputs.items(): address, mask, masked_bits = attr rule = ExitPolicyRule("accept %s:*" % rule_addr) self.assertEquals(AddressType.IPv6, rule.get_address_type()) self.assertEquals(address, rule.address) self.assertEquals(mask, rule.get_mask()) self.assertEquals(masked_bits, rule.get_masked_bits())