def test_determine_audit_results_secret_not_found( self, mock_get_raw_secret_value, mock_get_git_remotes, mock_get_git_sha, ): mock_get_raw_secret_value.side_effect = audit.SecretNotFoundOnSpecifiedLineError( 1) baseline = self.get_audited_baseline(plugins_used={}, is_secret=True) whole_plaintext_line = 'a plaintext line' with mock.patch.object( audit, '_get_file_line', return_value=whole_plaintext_line, autospec=True, ): display_results = audit.determine_audit_results( baseline, '.secrets.baseline') assert display_results['stats']['signal'] == '100.00%' hex_high_results = display_results['plugins']['HexHighEntropyString'][ 'results'] assert len(hex_high_results['true-positives']['mocked_file']) == 1 assert hex_high_results['true-positives']['mocked_file'][0][ 'line'] == whole_plaintext_line assert hex_high_results['true-positives']['mocked_file'][0][ 'plaintext'] is None
def mock_get_raw_secret_value(self, secret_value, secret_lineno, should_find_secret): with mock.patch.object(audit, 'get_raw_secret_value', autospec=True) as m: if should_find_secret: m.return_value = secret_value else: m.side_effect = audit.SecretNotFoundOnSpecifiedLineError(secret_lineno) yield m
def test_determine_audit_results_secret_not_found( self, mock_get_raw_secret_value, mock_get_git_remotes, mock_get_git_sha, ): mock_get_raw_secret_value.side_effect = audit.SecretNotFoundOnSpecifiedLineError(1) baseline = self.get_audited_baseline(plugins_used={}, is_secret=True) whole_plaintext_line = 'a plaintext line' with mock.patch.object( audit, '_get_file_line', return_value=whole_plaintext_line, autospec=True, ): results = audit.determine_audit_results(baseline, '.secrets.baseline') assert whole_plaintext_line in \ results['results']['HexHighEntropyString']['results']['positive']