Show More
@@ -16,8 +16,10 b'' | |||||
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 | import mock |
|
18 | import mock | |
|
19 | import pytest | |||
19 |
|
20 | |||
20 | from vcsserver import main |
|
21 | from vcsserver import main | |
|
22 | from vcsserver.base import obfuscate_qs | |||
21 |
|
23 | |||
22 |
|
24 | |||
23 | @mock.patch('vcsserver.main.VcsServerCommand', mock.Mock()) |
|
25 | @mock.patch('vcsserver.main.VcsServerCommand', mock.Mock()) | |
@@ -34,3 +36,13 b' def test_applies_largefiles_patch(patch_' | |||||
34 | mock.Mock(side_effect=Exception("Must not be called"))) |
|
36 | mock.Mock(side_effect=Exception("Must not be called"))) | |
35 | def test_applies_largefiles_patch_only_if_mercurial_is_available(): |
|
37 | def test_applies_largefiles_patch_only_if_mercurial_is_available(): | |
36 | main.main([]) |
|
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 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 | import logging |
|
18 | import logging | |
19 |
|
19 | import urlparse | ||
20 |
|
20 | |||
21 | log = logging.getLogger(__name__) |
|
21 | log = logging.getLogger(__name__) | |
22 |
|
22 | |||
@@ -69,3 +69,13 b' class RepoFactory(object):' | |||||
69 | 'INIT %s@%s repo object based on wire %s. Context: %s', |
|
69 | 'INIT %s@%s repo object based on wire %s. Context: %s', | |
70 | self.__class__.__name__, wire['path'], wire, context) |
|
70 | self.__class__.__name__, wire['path'], wire, context) | |
71 | return createfunc() |
|
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 | from vcsserver import exceptions, settings, subprocessio |
|
36 | from vcsserver import exceptions, settings, subprocessio | |
37 | from vcsserver.utils import safe_str |
|
37 | from vcsserver.utils import safe_str | |
38 | from vcsserver.base import RepoFactory |
|
38 | from vcsserver.base import RepoFactory, obfuscate_qs | |
39 | from vcsserver.hgcompat import ( |
|
39 | from vcsserver.hgcompat import ( | |
40 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler) |
|
40 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler) | |
41 |
|
41 | |||
@@ -170,6 +170,7 b' class GitRemote(object):' | |||||
170 | url_obj = url_parser(url) |
|
170 | url_obj = url_parser(url) | |
171 | test_uri, _ = url_obj.authinfo() |
|
171 | test_uri, _ = url_obj.authinfo() | |
172 | url_obj.passwd = '*****' |
|
172 | url_obj.passwd = '*****' | |
|
173 | url_obj.query = obfuscate_qs(url_obj.query) | |||
173 | cleaned_uri = str(url_obj) |
|
174 | cleaned_uri = str(url_obj) | |
174 | log.info("Checking URL for remote cloning/import: %s", cleaned_uri) |
|
175 | log.info("Checking URL for remote cloning/import: %s", cleaned_uri) | |
175 |
|
176 |
@@ -28,7 +28,7 b' from mercurial import commands' | |||||
28 | from mercurial import unionrepo |
|
28 | from mercurial import unionrepo | |
29 |
|
29 | |||
30 | from vcsserver import exceptions |
|
30 | from vcsserver import exceptions | |
31 | from vcsserver.base import RepoFactory |
|
31 | from vcsserver.base import RepoFactory, obfuscate_qs | |
32 | from vcsserver.hgcompat import ( |
|
32 | from vcsserver.hgcompat import ( | |
33 | archival, bin, clone, config as hgconfig, diffopts, hex, |
|
33 | archival, bin, clone, config as hgconfig, diffopts, hex, | |
34 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler, |
|
34 | hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler, | |
@@ -329,6 +329,8 b' class HgRemote(object):' | |||||
329 | url_obj = url_parser(url) |
|
329 | url_obj = url_parser(url) | |
330 | test_uri, authinfo = url_obj.authinfo() |
|
330 | test_uri, authinfo = url_obj.authinfo() | |
331 | url_obj.passwd = '*****' |
|
331 | url_obj.passwd = '*****' | |
|
332 | url_obj.query = obfuscate_qs(url_obj.query) | |||
|
333 | ||||
332 | cleaned_uri = str(url_obj) |
|
334 | cleaned_uri = str(url_obj) | |
333 | log.info("Checking URL for remote cloning/import: %s", cleaned_uri) |
|
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