##// END OF EJS Templates
Some diagnostics. Still - the way to detect good/bad password is needed
Marcin Kasperski -
r9:129fb242 default
parent child Browse files
Show More
@@ -28,6 +28,7 b' try:'
28 from mercurial.url import passwordmgr
28 from mercurial.url import passwordmgr
29 except:
29 except:
30 from mercurial.httprepo import passwordmgr
30 from mercurial.httprepo import passwordmgr
31 from mercurial.httprepo import httprepository
31
32
32 import keyring
33 import keyring
33 import getpass
34 import getpass
@@ -70,6 +71,8 b' class PasswordStore(object):'
70 keyring.set_password(KEYRING_SERVICE,
71 keyring.set_password(KEYRING_SERVICE,
71 self._format_key(url, username),
72 self._format_key(url, username),
72 password)
73 password)
74 def clear_password(self, url, username):
75 self.set_password(url, username, "")
73 def _format_key(self, url, username):
76 def _format_key(self, url, username):
74 return "%s@@%s" % (username, url)
77 return "%s@@%s" % (username, url)
75
78
@@ -100,8 +103,8 b' def find_user_password(self, realm, auth'
100 cache_key = (realm, base_url)
103 cache_key = (realm, base_url)
101 cached_auth = self._pwd_cache.get(cache_key)
104 cached_auth = self._pwd_cache.get(cache_key)
102 if cached_auth:
105 if cached_auth:
103 self.ui.debug("Found cached auth tokens: %s, %s\n" % (
106 self.ui.debug("Found cached auth tokens for %s: %s, %s\n" % (
104 cached_auth[0], cached_auth[1] and '********' or ''))
107 base_url, cached_auth[0], cached_auth[1] and '********' or ''))
105 return cached_auth
108 return cached_auth
106
109
107 # Loading username (and maybe password) from [auth] in local .hg/hgrc
110 # Loading username (and maybe password) from [auth] in local .hg/hgrc
@@ -130,12 +133,14 b' def find_user_password(self, realm, auth'
130 user, pwd and '********' or ''))
133 user, pwd and '********' or ''))
131
134
132 # username still not known? Asking
135 # username still not known? Asking
136 prompted = False
133 if not user:
137 if not user:
134 if not self.ui.interactive():
138 if not self.ui.interactive():
135 raise util.Abort(_('mercurial_keyring: http authorization required'))
139 raise util.Abort(_('mercurial_keyring: http authorization required'))
136 self.ui.write(_("http authorization required\n"))
140 self.ui.write(_("http authorization required\n"))
137 self.ui.status(_("realm: %s\n") % realm)
141 self.ui.status(_("realm: %s\n") % realm)
138 user = self.ui.prompt(_("user:"), default=None)
142 user = self.ui.prompt(_("user:"), default=None)
143 prompted = True
139
144
140 # username known and still no password? Time to check keyring
145 # username known and still no password? Time to check keyring
141 if user and not pwd:
146 if user and not pwd:
@@ -145,14 +150,36 b' def find_user_password(self, realm, auth'
145
150
146 # password still not known? Asking
151 # password still not known? Asking
147 if not pwd:
152 if not pwd:
148 if not self.ui.interactive():
153 if not prompted:
149 raise util.Abort(_('mercurial_keyring: http authorization required'))
154 if not self.ui.interactive():
150 pwd = self.ui.getpass(_("password: "))
155 raise util.Abort(_('mercurial_keyring: http authorization required'))
156 self.ui.write(_("http authorization required\n"))
157 self.ui.status(_("realm: %s\n") % realm)
158 pwd = self.ui.getpass(_("password for %s: ") % user)
159 else:
160 pwd = self.ui.getpass(_("password: "))
151 password_store.set_password(base_url, user, pwd)
161 password_store.set_password(base_url, user, pwd)
152 self.ui.debug("Saved keyring password for %s\n" % user)
162 self.ui.debug("Saved keyring password for %s\n" % user)
153
163
154 self._pwd_cache[cache_key] = (user, pwd)
164 self._pwd_cache[cache_key] = (user, pwd)
155
165
166 self.ui.debug("Returning auth tokens for %s: %s, %s\n" % (
167 base_url, user, pwd and '********' or ''))
156 return user, pwd
168 return user, pwd
157 #return None, None
169 #return None, None
158
170
171 ############################################################
172
173 # We patch httprespository.do_cmd to grab information that
174 # the request failed due to wrong auth - and clear the wrong
175 # password
176
177 orig_do_cmd = httprepository.do_cmd
178
179 @monkeypatch_method(httprepository)
180 def do_cmd(self, cmd, **args):
181 try:
182 orig_do_cmd(self, cmd, **args)
183 except util.Abort, e:
184 self.ui.debug("Authorization failed for %s\n" % self.url())
185 raise
General Comments 0
You need to be logged in to leave comments. Login now