def test__anonymize_value(val): """Test sensitive item anonymization.""" pwd_lookup = {} anon_val = _anonymize_value(val, pwd_lookup, {}) val_format = _check_sensitive_item_format(val) anon_val_format = _check_sensitive_item_format(anon_val) # Confirm the anonymized value does not match the original value assert anon_val != val # Confirm format for anonmymized value matches format of the original value assert anon_val_format == val_format if val_format == _sensitive_item_formats.md5: org_salt_size = len(val.split("$")[2]) anon_salt_size = len(anon_val.split("$")[2]) # Make sure salt size is preserved for md5 sensitive items # (Cisco should stay 4 character, Juniper 8 character, etc) assert org_salt_size == anon_salt_size # Confirm reanonymizing same source value results in same anonymized value assert anon_val == _anonymize_value(val, pwd_lookup, {})
def test__check_sensitive_item_format(val, format_): """Test sensitive item format detection.""" item_format = _check_sensitive_item_format(val) assert item_format == format_