Changeset View
Changeset View
Standalone View
Standalone View
tests/test-hgweb-auth.py
from __future__ import absolute_import, print_function | from __future__ import absolute_import, print_function | ||||
from mercurial import demandimport | from mercurial import demandimport | ||||
demandimport.enable() | demandimport.enable() | ||||
from mercurial import ( | from mercurial import ( | ||||
error, | error, | ||||
pycompat, | pycompat, | ||||
ui as uimod, | ui as uimod, | ||||
url, | url, | ||||
util, | util, | ||||
) | ) | ||||
from mercurial.utils import stringutil | from mercurial.utils import ( | ||||
stringutil, | |||||
urlutil, | |||||
) | |||||
urlerr = util.urlerr | urlerr = util.urlerr | ||||
urlreq = util.urlreq | urlreq = util.urlreq | ||||
class myui(uimod.ui): | class myui(uimod.ui): | ||||
def interactive(self): | def interactive(self): | ||||
return False | return False | ||||
Show All 33 Lines | def test(auth, urls=None): | ||||
auth = {k: v for k, v in auth.items() if v is not None} | auth = {k: v for k, v in auth.items() if v is not None} | ||||
ui = writeauth(auth) | ui = writeauth(auth) | ||||
def _test(uri): | def _test(uri): | ||||
print('URI:', pycompat.strurl(uri)) | print('URI:', pycompat.strurl(uri)) | ||||
try: | try: | ||||
pm = url.passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm()) | pm = url.passwordmgr(ui, urlreq.httppasswordmgrwithdefaultrealm()) | ||||
u, authinfo = util.url(uri).authinfo() | u, authinfo = urlutil.url(uri).authinfo() | ||||
if authinfo is not None: | if authinfo is not None: | ||||
pm.add_password(*_stringifyauthinfo(authinfo)) | pm.add_password(*_stringifyauthinfo(authinfo)) | ||||
print( | print( | ||||
' ', | ' ', | ||||
tuple( | tuple( | ||||
pycompat.strurl(a) | pycompat.strurl(a) | ||||
for a in pm.find_user_password('test', pycompat.strurl(u)) | for a in pm.find_user_password('test', pycompat.strurl(u)) | ||||
), | ), | ||||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | test( | ||||
{b'y.prefix': b'http://y@example.org/foo', b'y.password': b'ypassword'}, | {b'y.prefix': b'http://y@example.org/foo', b'y.password': b'ypassword'}, | ||||
urls=[b'http://example.org/foo'], | urls=[b'http://example.org/foo'], | ||||
) | ) | ||||
def testauthinfo(fullurl, authurl): | def testauthinfo(fullurl, authurl): | ||||
print('URIs:', fullurl, authurl) | print('URIs:', fullurl, authurl) | ||||
pm = urlreq.httppasswordmgrwithdefaultrealm() | pm = urlreq.httppasswordmgrwithdefaultrealm() | ||||
ai = _stringifyauthinfo(util.url(pycompat.bytesurl(fullurl)).authinfo()[1]) | ai = _stringifyauthinfo( | ||||
urlutil.url(pycompat.bytesurl(fullurl)).authinfo()[1] | |||||
) | |||||
pm.add_password(*ai) | pm.add_password(*ai) | ||||
print(pm.find_user_password('test', authurl)) | print(pm.find_user_password('test', authurl)) | ||||
print('\n*** Test urllib2 and util.url\n') | print('\n*** Test urllib2 and urlutil.url\n') | ||||
testauthinfo('http://user@example.com:8080/foo', 'http://example.com:8080/foo') | testauthinfo('http://user@example.com:8080/foo', 'http://example.com:8080/foo') |