Пример #1
0
def test_preserve_private_prefixes(anonymizer_v4, start, end, subnet):
    """Test that private-use prefixes are preserved by default."""
    ip_int_start = int(anonymizer_v4.make_addr(start))
    ip_int_start_anon = anonymizer_v4.anonymize(ip_int_start)

    ip_int_end = int(anonymizer_v4.make_addr(end))
    ip_int_end_anon = anonymizer_v4.anonymize(ip_int_end)

    network = ipaddress.ip_network(_ensure_unicode(subnet))

    # Make sure addresses in the block stay in the block
    assert (ipaddress.ip_address(ip_int_start_anon) in network)
    assert (ipaddress.ip_address(ip_int_end_anon) in network)
Пример #2
0
def test_preserve_custom_prefixes():
    """Test that a custom prefix is preserved correctly."""
    subnet = '170.0.0.0/8'
    anonymizer = IpAnonymizer(SALT, [subnet])

    ip_start = int(anonymizer.make_addr('170.0.0.0'))
    ip_start_anon = anonymizer.anonymize(ip_start)

    ip_end = int(anonymizer.make_addr('170.255.255.255'))
    ip_end_anon = anonymizer.anonymize(ip_end)

    network = ipaddress.ip_network(_ensure_unicode(subnet))

    # Make sure the anonymized addresses are different from the originals
    assert (ip_start_anon != ip_start)
    assert (ip_end_anon != ip_end)

    # Make sure the anonymized addresses have the same prefix as the originals
    assert (ipaddress.ip_address(ip_start_anon) in network)
    assert (ipaddress.ip_address(ip_end_anon) in network)