Show More
@@ -16,8 +16,10 b'' | |||
|
16 | 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 | 17 | |
|
18 | 18 | import mock |
|
19 | import pytest | |
|
19 | 20 | |
|
20 | 21 | from vcsserver import main |
|
22 | from vcsserver.base import obfuscate_qs | |
|
21 | 23 | |
|
22 | 24 | |
|
23 | 25 | @mock.patch('vcsserver.main.VcsServerCommand', mock.Mock()) |
@@ -34,3 +36,13 b' def test_applies_largefiles_patch(patch_' | |||
|
34 | 36 | mock.Mock(side_effect=Exception("Must not be called"))) |
|
35 | 37 | def test_applies_largefiles_patch_only_if_mercurial_is_available(): |
|
36 | 38 | main.main([]) |
|
39 | ||
|
40 | ||
|
41 | @pytest.mark.parametrize('given, expected', [ | |
|
42 | ('foo=bar', 'foo=bar'), | |
|
43 | ('auth_token=secret', 'auth_token=*****'), | |
|
44 | ('auth_token=secret&api_key=secret2', 'auth_token=*****&api_key=*****'), | |
|
45 | ('auth_token=secret&api_key=secret2¶m=value', 'auth_token=*****&api_key=*****¶m=value'), | |
|
46 | ]) | |
|
47 | def test_obfuscate_qs(given, expected): | |
|
48 | assert expected == obfuscate_qs(given) |
@@ -16,7 +16,7 b'' | |||
|
16 | 16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 | 17 | |
|
18 | 18 | import logging |
|
19 | ||
|
19 | import urlparse | |
|
20 | 20 | |
|
21 | 21 | log = logging.getLogger(__name__) |
|
22 | 22 | |
@@ -69,3 +69,13 b' class RepoFactory(object):' | |||
|
69 | 69 | 'INIT %s@%s repo object based on wire %s. Context: %s', |
|
70 | 70 | self.__class__.__name__, wire['path'], wire, context) |
|
71 | 71 | return createfunc() |
|
72 | ||
|
73 | ||
|
74 | def obfuscate_qs(query_string): | |
|
75 | parsed = [] | |
|
76 | for k, v in urlparse.parse_qsl(query_string): | |
|
77 | if k in ['auth_token', 'api_key']: | |
|
78 | v = "*****" | |
|
79 | parsed.append((k, v)) | |
|
80 | ||
|
81 | return '&'.join('{}={}'.format(k,v) for k,v in parsed) |
@@ -35,7 +35,7 b' from dulwich.server import update_server' | |||
|
35 | 35 | |
|
36 | 36 | from vcsserver import exceptions, settings, subprocessio |
|
37 | 37 | from vcsserver.utils import safe_str |
|
38 | from vcsserver.base import RepoFactory | |
|
38 | from vcsserver.base import RepoFactory, obfuscate_qs | |
|
39 | 39 | from vcsserver.hgcompat import ( |
|
40 | 40 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler) |
|
41 | 41 | |
@@ -170,6 +170,7 b' class GitRemote(object):' | |||
|
170 | 170 | url_obj = url_parser(url) |
|
171 | 171 | test_uri, _ = url_obj.authinfo() |
|
172 | 172 | url_obj.passwd = '*****' |
|
173 | url_obj.query = obfuscate_qs(url_obj.query) | |
|
173 | 174 | cleaned_uri = str(url_obj) |
|
174 | 175 | log.info("Checking URL for remote cloning/import: %s", cleaned_uri) |
|
175 | 176 |
@@ -28,7 +28,7 b' from mercurial import commands' | |||
|
28 | 28 | from mercurial import unionrepo |
|
29 | 29 | |
|
30 | 30 | from vcsserver import exceptions |
|
31 | from vcsserver.base import RepoFactory | |
|
31 | from vcsserver.base import RepoFactory, obfuscate_qs | |
|
32 | 32 | from vcsserver.hgcompat import ( |
|
33 | 33 | archival, bin, clone, config as hgconfig, diffopts, hex, |
|
34 | 34 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler, |
@@ -329,6 +329,8 b' class HgRemote(object):' | |||
|
329 | 329 | url_obj = url_parser(url) |
|
330 | 330 | test_uri, authinfo = url_obj.authinfo() |
|
331 | 331 | url_obj.passwd = '*****' |
|
332 | url_obj.query = obfuscate_qs(url_obj.query) | |
|
333 | ||
|
332 | 334 | cleaned_uri = str(url_obj) |
|
333 | 335 | log.info("Checking URL for remote cloning/import: %s", cleaned_uri) |
|
334 | 336 |
General Comments 0
You need to be logged in to leave comments.
Login now