Skip to content

Commit

Permalink
Add data about username being unicode or containg spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophia Castellarin authored and msarahan committed May 30, 2019
1 parent 13ec663 commit a08e392
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
6 changes: 4 additions & 2 deletions conda/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,9 +1241,11 @@ def _execute_upload(self, error_report):
'User-Agent': self.user_agent,
}
_timeout = self.http_timeout
data = json.dumps(error_report, sort_keys=True, cls=EntityEncoder) + '\n'
username = pwd.getpwuid(os.getuid()).pw_name
data = data.replace(username, "USERNAME_REMOVED")
error_report['is_unicode'] = True if isinstance(username, bytes) else False
error_report['has_spaces'] = True if " " in str(username) else False
data = json.dumps(error_report, sort_keys=True, cls=EntityEncoder) + '\n'
data = data.replace(str(username), "USERNAME_REMOVED")
response = None
try:
# requests does not follow HTTP standards for redirects of non-GET methods
Expand Down
42 changes: 42 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,48 @@ def test_print_unexpected_error_message_upload_3(self, isatty_mock, input_mock,
assert c.stdout == ''
assert "conda version" in c.stderr

@patch('requests.post', side_effect=(
AttrDict(headers=AttrDict(Location='somewhere.else'), status_code=302,
raise_for_status=lambda: None),
AttrDict(raise_for_status=lambda: None),
))
@patch('pwd.getpwuid', return_value=pwd.struct_passwd(([
'name with space', 'name with space', 'name with space', 'name with space',
'name with space', 'name with space', 'name with spaces'])
))
def test_print_unexpected_error_message_upload_username_with_spaces(self, pwuid, post_mock):
with env_var('CONDA_REPORT_ERRORS', 'true', stack_callback=conda_tests_ctxt_mgmt_def_pol):
with captured() as c:
ExceptionHandler()(_raise_helper, AssertionError())

error_data = json.loads(post_mock.call_args[1].get("data"))
assert error_data.get("has_spaces") == True
assert error_data.get("is_unicode") == False
assert post_mock.call_count == 2
assert c.stdout == ''
assert "conda version" in c.stderr

@patch('requests.post', side_effect=(
AttrDict(headers=AttrDict(Location='somewhere.else'), status_code=302,
raise_for_status=lambda: None),
AttrDict(raise_for_status=lambda: None),
))
@patch('pwd.getpwuid', return_value=pwd.struct_passwd(([
b'unicodename', b'unicodename', b'unicodename', b'unicodename',
b'unicodename', b'unicodename', b'unicodename'])
))
def test_print_unexpected_error_message_upload_username_with_unicode(self, pwuid, post_mock):
with env_var('CONDA_REPORT_ERRORS', 'true', stack_callback=conda_tests_ctxt_mgmt_def_pol):
with captured() as c:
ExceptionHandler()(_raise_helper, AssertionError())

error_data = json.loads(post_mock.call_args[1].get("data"))
assert error_data.get("has_spaces") == False
assert error_data.get("is_unicode") == True
assert post_mock.call_count == 2
assert c.stdout == ''
assert "conda version" in c.stderr

@patch('requests.post', return_value=None)
@patch('conda.exceptions.input', return_value='n')
def test_print_unexpected_error_message_opt_out_1(self, input_mock, post_mock):
Expand Down

0 comments on commit a08e392

Please sign in to comment.