def test_pwd_removal_preserve_trailing_whitespace(regexes, whitespace): """Test trailing whitespace is preserved in config lines.""" config_line = "{line}{whitespace}".format(line="password secret", whitespace=whitespace) pwd_lookup = {} processed_line = replace_matching_item(regexes, config_line, pwd_lookup) assert processed_line.endswith(whitespace)
def test_pwd_removal_prepend(regexes, config_line, sensitive_text, prepend_text): """Test that sensitive lines are still anonymized correctly if preceded by allowed text.""" config_line = prepend_text + config_line.format(sensitive_text) pwd_lookup = {} assert sensitive_text not in replace_matching_item(regexes, config_line, pwd_lookup)
def test_pwd_removal_and_preserve_reserved_word(regexes, config_line, sensitive_text): """Test removal of passwords when reserved words must be skipped.""" config_line = config_line.format(sensitive_text) pwd_lookup = {} assert sensitive_text not in replace_matching_item(regexes, config_line, pwd_lookup)
def test_pwd_removal_preserve_leading_whitespace(regexes, whitespace): """Test leading whitespace is preserved in config lines.""" config_line = '{whitespace}{line}'.format(line='password secret', whitespace=whitespace) pwd_lookup = {} processed_line = replace_matching_item(regexes, config_line, pwd_lookup) assert (processed_line.startswith(whitespace))
def test_pwd_removal_insensitive_lines(regexes, config_line): """Make sure benign lines are not affected by sensitive_item_removal.""" pwd_lookup = {} # Collapse all whitespace in original config_line and add newline since # that will be done by replace_matching_item config_line = "{}\n".format(" ".join(config_line.split())) assert config_line == replace_matching_item(regexes, config_line, pwd_lookup)
def test_pwd_removal(regexes, raw_config_line, sensitive_text): """Test removal of passwords and communities from config lines.""" config_line = raw_config_line.format(sensitive_text) pwd_lookup = {} anon_line = replace_matching_item(regexes, config_line, pwd_lookup) # Make sure the output line does not contain the sensitive text assert sensitive_text not in anon_line if _LINE_SCRUBBED_MESSAGE not in anon_line: # If the line wasn't "completely scrubbed", # make sure context was preserved anon_val = _anonymize_value(sensitive_text, pwd_lookup, {}) assert anon_line == raw_config_line.format(anon_val)
def test_pwd_removal_preserve_context(regexes, config_line, anon_line): """Test that context is preserved replacing/removing passwords.""" pwd_lookup = {} assert anon_line == replace_matching_item(regexes, config_line, pwd_lookup)
def test_pwd_removal_preserve_reserved_word(regexes, config_line): """Test that reserved words are preserved even if they appear in password lines.""" pwd_lookup = {} assert config_line == replace_matching_item(regexes, config_line, pwd_lookup)
def test_pwd_removal_with_whitespace(regexes): """Test removal of password when a sensitive line contains extra whitespace.""" sensitive_text = "RemoveMe" sensitive_line = " password 0 \t{}".format(sensitive_text) assert sensitive_text not in replace_matching_item(regexes, sensitive_line, {})
def test_pwd_removal(regexes, config_line, sensitive_text): """Test removal of passwords and communities from config lines.""" config_line = config_line.format(sensitive_text) pwd_lookup = {} assert (sensitive_text not in replace_matching_item(regexes, config_line, pwd_lookup))