##// END OF EJS Templates
fix(auth-info): fixed auth credentials problem for HG Fixes RCCE-33...
super-admin -
r1196:b009ad36 default
parent child Browse files
Show More
@@ -41,7 +41,7 b' from dulwich.server import update_server'
41 41
42 42 import rhodecode
43 43 from vcsserver import exceptions, settings, subprocessio
44 from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_bytes
44 from vcsserver.str_utils import safe_str, safe_int, safe_bytes, ascii_bytes, convert_to_str
45 45 from vcsserver.base import RepoFactory, obfuscate_qs, ArchiveNode, store_archive_in_cache, BytesEnvelope, BinaryEnvelope
46 46 from vcsserver.hgcompat import (
47 47 hg_url as url_parser, httpbasicauthhandler, httpdigestauthhandler)
@@ -461,18 +461,10 b' class GitRemote(RemoteBase):'
461 461 url_obj = url_parser(safe_bytes(url))
462 462 authinfo = url_obj.authinfo()[1]
463 463
464 def _convert_to_strings(data):
465 if isinstance(data, bytes):
466 return safe_str(data)
467 elif isinstance(data, tuple):
468 return tuple(_convert_to_strings(item) for item in data)
469 else:
470 return data
471
472 464 if authinfo:
473 465 # create a password manager
474 466 passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
475 passmgr.add_password(*_convert_to_strings(authinfo))
467 passmgr.add_password(*convert_to_str(authinfo))
476 468
477 469 handlers.extend((httpbasicauthhandler(passmgr),
478 470 httpdigestauthhandler(passmgr)))
@@ -14,6 +14,7 b''
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software Foundation,
16 16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17 18 import binascii
18 19 import io
19 20 import logging
@@ -23,7 +24,7 b' import urllib.request'
23 24 import urllib.parse
24 25 import hashlib
25 26
26 from hgext import largefiles, rebase, purge
27 from hgext import largefiles, rebase
27 28
28 29 from mercurial import commands
29 30 from mercurial import unionrepo
@@ -74,10 +75,9 b' from vcsserver.hgcompat import ('
74 75 RequirementError,
75 76 alwaysmatcher,
76 77 patternmatcher,
77 hgutil,
78 78 hgext_strip,
79 79 )
80 from vcsserver.str_utils import ascii_bytes, ascii_str, safe_str, safe_bytes
80 from vcsserver.str_utils import ascii_bytes, ascii_str, safe_str, safe_bytes, convert_to_str
81 81 from vcsserver.vcs_base import RemoteBase
82 82 from vcsserver.config import hooks as hooks_config
83 83 from vcsserver.lib.exc_tracking import format_exc
@@ -488,7 +488,7 b' class HgRemote(RemoteBase):'
488 488 if authinfo:
489 489 # create a password manager
490 490 passmgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
491 passmgr.add_password(*authinfo)
491 passmgr.add_password(*convert_to_str(authinfo))
492 492
493 493 handlers.extend((httpbasicauthhandler(passmgr),
494 494 httpdigestauthhandler(passmgr)))
@@ -131,3 +131,14 b' def ascii_str(str_) -> str:'
131 131 if not isinstance(str_, bytes):
132 132 raise ValueError(f'ascii_str cannot convert other types than bytes: got: {type(str_)}')
133 133 return str_.decode('ascii')
134
135
136 def convert_to_str(data):
137 if isinstance(data, bytes):
138 return safe_str(data)
139 elif isinstance(data, tuple):
140 return tuple(convert_to_str(item) for item in data)
141 elif isinstance(data, list):
142 return list(convert_to_str(item) for item in data)
143 else:
144 return data
@@ -16,7 +16,7 b''
16 16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 17
18 18 import pytest
19 from vcsserver.str_utils import ascii_bytes, ascii_str
19 from vcsserver.str_utils import ascii_bytes, ascii_str, convert_to_str
20 20
21 21
22 22 @pytest.mark.parametrize('given, expected', [
@@ -51,3 +51,19 b' def test_ascii_str(given, expected):'
51 51 def test_ascii_str_raises(given):
52 52 with pytest.raises(ValueError):
53 53 ascii_str(given)
54
55
56 @pytest.mark.parametrize('given, expected', [
57 ('a', 'a'),
58 (b'a', 'a'),
59 # tuple
60 (('a', b'b', b'c'), ('a', 'b', 'c')),
61 # nested tuple
62 (('a', b'b', (b'd', b'e')), ('a', 'b', ('d', 'e'))),
63 # list
64 (['a', b'b', b'c'], ['a', 'b', 'c']),
65 # mixed
66 (['a', b'b', b'c', (b'b1', b'b2')], ['a', 'b', 'c', ('b1', 'b2')])
67 ])
68 def test_convert_to_str(given, expected):
69 assert convert_to_str(given) == expected
General Comments 0
You need to be logged in to leave comments. Login now