Skip to content

Commit

Permalink
Adding a new unit test, different approach.
Browse files Browse the repository at this point in the history
  • Loading branch information
truthbk committed Oct 29, 2015
1 parent ab50e69 commit 92adb42
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions tests/core/test_flare.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# stdlib
import os.path
import unittest
import re

# 3p
import mock
Expand Down Expand Up @@ -32,6 +33,11 @@ def get_mocked_temp():
'uri_password' : 'password_uri.yaml',
}

password_tests = {
'uri_password' : ' - server: mongodb://datadog:V3pZC7ghx1ne82XkyqLnOW36@localhost:27017/admin',
'uri_password_expected' : ' - server: mongodb://datadog:********@localhost:27017/admin',
}


def mocked_strftime(t):
return '1'
Expand Down Expand Up @@ -138,3 +144,14 @@ def test_uri_password(self, mock_config, mock_tempdir, mock_strftime):
" - this file contains a password in a uri which has been removed in the version collected"
)

@attr(requires='core_integration')
@mock.patch('utils.flare.strftime', side_effect=mocked_strftime)
@mock.patch('tempfile.gettempdir', side_effect=get_mocked_temp)
@mock.patch('utils.flare.get_config', side_effect=get_mocked_config)
def test_uri_password_regex(self, mock_config, mock_tempdir, mock_strftime):
f = Flare()
line = re.sub(f.URI_REGEX, r'\1://\2:********@', password_tests['uri_password'])
self.assertEqual(
line,
password_tests['uri_password_expected']
)
2 changes: 1 addition & 1 deletion utils/flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def _strip_password(self, file_path):
password_found = ' - this file contains a password which '\
'has been removed in the version collected'
if self.URI_REGEX.match(line):
line = re.sub(self.URI_REGEX, r'\1://\2:*******@', line)
line = re.sub(self.URI_REGEX, r'\1://\2:********@', line)
password_found = ' - this file contains a password in a uri which '\
'has been removed in the version collected'
if not self.COMMENT_REGEX.match(line):
Expand Down

0 comments on commit 92adb42

Please sign in to comment.