Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unicode error during audit #129

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions detect_secrets/core/audit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import print_function
from __future__ import unicode_literals

import codecs
import itertools
Expand Down
6 changes: 5 additions & 1 deletion testing/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ def __init__(self):
self.clear()

def add(self, message, *args, **kwargs):
self.message += str(message) + '\n'
try:
# For python 2.x compatible
self.message += unicode(message) + '\n'
except NameError:
self.message += str(message) + '\n'

def clear(self):
self.message = ''
Expand Down
34 changes: 34 additions & 0 deletions tests/core/audit_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import absolute_import
from __future__ import unicode_literals

import string
import textwrap
Expand Down Expand Up @@ -685,6 +686,39 @@ def test_keyword_secret_in_yaml_file(self, mock_printer):

""")[1:-1]

def test_unicode_in_output(self, mock_printer):
# Instead of mocking open, read from file with
# unicode in it to mimic the audit error
self.run_logic(
secret=potential_secret_factory(
type_='Base64 High Entropy String',
filename="test_data/config.md",
secret='ToCynx5Se4e2PtoZxEhW7lUJcOX15c54',
lineno=10,
).json(),
settings=[
{
"base64_limit": 4.5,
"name": "Base64HighEntropyString",
},
],
)

assert uncolor(mock_printer.message) == textwrap.dedent("""
Secret: 1 of 2
Filename: test_data/config.md
Secret Type: Base64 High Entropy String
----------
5:Test Unicode in non ini file would not fail on python 2.7.
6:
7:\u256D\u2500 diagnose
8:\u2570\u00BB ssh to server x:22324241234423414
9:
10:key="ToCynx5Se4e2PtoZxEhW7lUJcOX15c54"
----------

""")[1:-1]


class TestGetUserDecision(object):

Expand Down