def test_analyze_quotes_required_negatives(self, file_content, file_extension): logic = KeywordDetector() f = mock_file_object(file_content) output = logic.analyze( f, 'mock_filename{}'.format(file_extension), ) assert len(output) == 0
def test_analyze(self, file_content): logic = KeywordDetector() f = mock_file_object(file_content) output = logic.analyze(f, 'mock_filename') assert len(output) == 1 for potential_secret in output: assert 'mock_filename' == potential_secret.filename generated = list(logic.secret_generator(file_content)) assert len(generated) == len(output)
def test_analyze_objective_c_positives(self, file_content): logic = KeywordDetector() f = mock_file_object(file_content) output = logic.analyze(f, 'mock_filename.m') assert len(output) == 1 for potential_secret in output: assert 'mock_filename.m' == potential_secret.filename assert (potential_secret.secret_hash == PotentialSecret. hash_secret('m{{h}o)p${e]nob(ody[finds>-_$#thisone}}'))
def test_analyze_yaml_negatives(self, file_content, file_extension): logic = KeywordDetector() # Make it start with `{{`, (and end with `}}`) so it hits our false-positive check f = mock_file_object(file_content.replace('m{', '{')) output = logic.analyze( f, 'mock_filename{}'.format(file_extension), ) assert len(output) == 0
def test_analyze_example_negatives(self, file_content): logic = KeywordDetector() # Make it start with `<`, (and end with `>`) so it hits our false-positive check f = mock_file_object( file_content.replace('m{', '<').replace('}', '>'), ) output = logic.analyze( f, 'mock_filename.example', ) assert len(output) == 0
def test_analyze_quotes_required_positives(self, file_content, file_extension): logic = KeywordDetector() f = mock_file_object(file_content) mock_filename = 'mock_filename{}'.format(file_extension) output = logic.analyze(f, mock_filename) assert len(output) == 1 for potential_secret in output: assert mock_filename == potential_secret.filename assert (potential_secret.secret_hash == PotentialSecret. hash_secret('m{{h}o)p${e]nob(ody[finds>-_$#thisone}}'))
def test_analyze_standard_positives_with_automaton(self, file_content): automaton = ahocorasick.Automaton() word = 'thisone' automaton.add_word(word, word) automaton.make_automaton() logic = KeywordDetector(automaton=automaton) f = mock_file_object(file_content) output = logic.analyze(f, 'mock_filename') # All skipped due to automaton assert len(output) == 0
def test_analyze_standard_positives_with_automaton(self, file_content): automaton = ahocorasick.Automaton() word = 'thisone' if is_python_2(): # pragma: no cover # Due to pyahocorasick word = word.encode('utf-8') automaton.add_word(word, word) automaton.make_automaton() logic = KeywordDetector(automaton=automaton) f = mock_file_object(file_content) output = logic.analyze(f, 'mock_filename') # All skipped due to automaton assert len(output) == 0
def test_analyze_with_line_exclude(self, file_content): logic = KeywordDetector(keyword_exclude='thisone') f = mock_file_object(file_content) output = logic.analyze(f, 'mock_filename.foo') assert len(output) == 0
def test_analyze_php_negatives(self, file_content): logic = KeywordDetector() f = mock_file_object(file_content) output = logic.analyze(f, 'mock_filename.php') assert len(output) == 0
def test_analyze_python_negatives(self, secret_with_no_quote): logic = KeywordDetector() f = mock_file_object(secret_with_no_quote) output = logic.analyze(f, 'mock_filename.py') assert len(output) == 0
def test_analyze_php_negatives(self, secret_starting_with_dollar_sign): logic = KeywordDetector() f = mock_file_object(secret_starting_with_dollar_sign) output = logic.analyze(f, 'mock_filename.php') assert len(output) == 0
def test_analyze_javascript_negatives(self, js_negative): logic = KeywordDetector() f = mock_file_object(js_negative) output = logic.analyze(f, 'mock_filename.js') assert len(output) == 0
def test_analyze_standard_negatives(self, negative): logic = KeywordDetector() f = mock_file_object(negative) output = logic.analyze(f, 'mock_filename.foo') assert len(output) == 0