diff --git a/tests/test_main.py b/tests/test_main.py --- a/tests/test_main.py +++ b/tests/test_main.py @@ -39,10 +39,19 @@ def test_applies_largefiles_patch_only_i @pytest.mark.parametrize('given, expected', [ + ('bad', 'bad'), + ('query&foo=bar', 'query&foo=bar'), + ('equery&auth_token=bar', 'equery&auth_token=*****'), + ('a;b;c;query&foo=bar&auth_token=secret', + 'a&b&c&query&foo=bar&auth_token=*****'), + ('', ''), + (None, None), ('foo=bar', 'foo=bar'), ('auth_token=secret', 'auth_token=*****'), - ('auth_token=secret&api_key=secret2', 'auth_token=*****&api_key=*****'), - ('auth_token=secret&api_key=secret2¶m=value', 'auth_token=*****&api_key=*****¶m=value'), + ('auth_token=secret&api_key=secret2', + 'auth_token=*****&api_key=*****'), + ('auth_token=secret&api_key=secret2¶m=value', + 'auth_token=*****&api_key=*****¶m=value'), ]) def test_obfuscate_qs(given, expected): assert expected == obfuscate_qs(given) diff --git a/vcsserver/base.py b/vcsserver/base.py --- a/vcsserver/base.py +++ b/vcsserver/base.py @@ -72,10 +72,14 @@ class RepoFactory(object): def obfuscate_qs(query_string): + if query_string is None: + return None + parsed = [] - for k, v in urlparse.parse_qsl(query_string): + for k, v in urlparse.parse_qsl(query_string, keep_blank_values=True): if k in ['auth_token', 'api_key']: v = "*****" parsed.append((k, v)) - return '&'.join('{}={}'.format(k,v) for k,v in parsed) + return '&'.join('{}{}'.format( + k, '={}'.format(v) if v else '') for k, v in parsed)