##// END OF EJS Templates
http: pass user to readauthforuri() (fix 4a43e23b8c55)...
Patrick Mezard -
r15025:0593e8f8 stable
parent child Browse files
Show More
@@ -58,7 +58,7 b' class httpsendfile(object):'
58 return self._len
58 return self._len
59
59
60 # moved here from url.py to avoid a cycle
60 # moved here from url.py to avoid a cycle
61 def readauthforuri(ui, uri):
61 def readauthforuri(ui, uri, user):
62 # Read configuration
62 # Read configuration
63 config = dict()
63 config = dict()
64 for key, val in ui.configitems('auth'):
64 for key, val in ui.configitems('auth'):
@@ -72,10 +72,6 b' def readauthforuri(ui, uri):'
72 gdict[setting] = val
72 gdict[setting] = val
73
73
74 # Find the best match
74 # Find the best match
75 uri = util.url(uri)
76 user = uri.user
77 uri.user = uri.password = None
78 uri = str(uri)
79 scheme, hostpath = uri.split('://', 1)
75 scheme, hostpath = uri.split('://', 1)
80 bestuser = None
76 bestuser = None
81 bestlen = 0
77 bestlen = 0
@@ -238,7 +234,11 b' class http2handler(urllib2.HTTPHandler, '
238 return self.do_open(HTTPConnection, req, False)
234 return self.do_open(HTTPConnection, req, False)
239
235
240 def https_open(self, req):
236 def https_open(self, req):
241 res = readauthforuri(self.ui, req.get_full_url())
237 # req.get_full_url() does not contain credentials and we may
238 # need them to match the certificates.
239 url = req.get_full_url()
240 user, password = self.pwmgr.find_stored_password(url)
241 res = readauthforuri(self.ui, url, user)
242 if res:
242 if res:
243 group, auth = res
243 group, auth = res
244 self.auth = auth
244 self.auth = auth
@@ -26,7 +26,7 b' class passwordmgr(urllib2.HTTPPasswordMg'
26 return (user, passwd)
26 return (user, passwd)
27
27
28 if not user or not passwd:
28 if not user or not passwd:
29 res = httpconnectionmod.readauthforuri(self.ui, authuri)
29 res = httpconnectionmod.readauthforuri(self.ui, authuri, user)
30 if res:
30 if res:
31 group, auth = res
31 group, auth = res
32 user, passwd = auth.get('username'), auth.get('password')
32 user, passwd = auth.get('username'), auth.get('password')
@@ -53,6 +53,10 b' class passwordmgr(urllib2.HTTPPasswordMg'
53 msg = _('http auth: user %s, password %s\n')
53 msg = _('http auth: user %s, password %s\n')
54 self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set'))
54 self.ui.debug(msg % (user, passwd and '*' * len(passwd) or 'not set'))
55
55
56 def find_stored_password(self, authuri):
57 return urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
58 self, None, authuri)
59
56 class proxyhandler(urllib2.ProxyHandler):
60 class proxyhandler(urllib2.ProxyHandler):
57 def __init__(self, ui):
61 def __init__(self, ui):
58 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
62 proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
@@ -342,7 +346,11 b' if has_https:'
342 return keepalive.KeepAliveHandler._start_transaction(self, h, req)
346 return keepalive.KeepAliveHandler._start_transaction(self, h, req)
343
347
344 def https_open(self, req):
348 def https_open(self, req):
345 res = httpconnectionmod.readauthforuri(self.ui, req.get_full_url())
349 # req.get_full_url() does not contain credentials and we may
350 # need them to match the certificates.
351 url = req.get_full_url()
352 user, password = self.pwmgr.find_stored_password(url)
353 res = httpconnectionmod.readauthforuri(self.ui, url, user)
346 if res:
354 if res:
347 group, auth = res
355 group, auth = res
348 self.auth = auth
356 self.auth = auth
@@ -37,10 +37,10 b' def test(auth, urls=None):'
37 print 'URI:', uri
37 print 'URI:', uri
38 try:
38 try:
39 pm = url.passwordmgr(ui)
39 pm = url.passwordmgr(ui)
40 authinfo = util.url(uri).authinfo()[1]
40 u, authinfo = util.url(uri).authinfo()
41 if authinfo is not None:
41 if authinfo is not None:
42 pm.add_password(*authinfo)
42 pm.add_password(*authinfo)
43 print ' ', pm.find_user_password('test', uri)
43 print ' ', pm.find_user_password('test', u)
44 except Abort, e:
44 except Abort, e:
45 print 'abort'
45 print 'abort'
46
46
General Comments 0
You need to be logged in to leave comments. Login now