Пример #1
0
def test_false_positives(anonymizer_v4, anonymizer_v6, line):
    """Test that text without a valid address is not anonymized."""
    anon_line = anonymize_ip_addr(anonymizer_v4, line)
    anon_line = anonymize_ip_addr(anonymizer_v6, anon_line)

    # Confirm the anonymized line is unchanged
    assert line == anon_line
Пример #2
0
    def anonymize_ip(self, item: dict, anondata: str) -> str:
        """Anonymize the IP address in the data and in the item header

        Anonymize the IP addresses, v4 and v6, in the supplied data. Also
        anonymize the IP address in the data header. Both are specific to the
        run-once=gather format of Suzieq
        """
        item['address'] = anonymize_ip_addr(self.anonv4, item['address'])
        item['address'] = anonymize_ip_addr(self.anonv6, item['address'])

        if not anondata:
            return anondata

        anondata = anonymize_ip_addr(self.anonv4, anondata, False)
        anondata = anonymize_ip_addr(self.anonv6, anondata, False)

        return anondata
Пример #3
0
def anonymize_line_general(anonymizer, line, ip_addrs):
    """Test IP address removal from config lines."""
    line_w_ip = line.format(*ip_addrs)
    anon_line = anonymize_ip_addr(anonymizer, line_w_ip)

    # Now anonymize each IP address individually & build another anonymized line
    anon_ip_addrs = [
        anonymize_ip_addr(anonymizer, ip_addr) for ip_addr in ip_addrs
    ]
    individually_anon_line = line.format(*anon_ip_addrs)

    # Make sure anonymizing each address individually is the same as
    # anonymizing all at once
    assert anon_line == individually_anon_line

    for ip_addr in ip_addrs:
        # Make sure the original ip address(es) are removed from the anonymized line
        assert ip_addr not in anon_line