From 491272f14f131eaa176e979d48463b2b72161664 Mon Sep 17 00:00:00 2001 From: "dnj@chromium.org" Date: Tue, 7 Apr 2015 17:59:05 +0000 Subject: [PATCH] Try internal authentication URL if external fails. BUG=chromium:356813 TEST=local - Deleted cookies file, ran without patch, 404. - Deleted cookies file, ran on internal network, works! Review URL: https://codereview.chromium.org/1068973002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@294701 0039d316-1c4b-4281-b951-d872f2087c98 --- third_party/upload.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/third_party/upload.py b/third_party/upload.py index 0aae84c1ea..c9a45b5906 100755 --- a/third_party/upload.py +++ b/third_party/upload.py @@ -289,7 +289,7 @@ class AbstractRpcServer(object): req.add_header(key, value) return req - def _GetAuthToken(self, email, password): + def _GetAuthToken(self, email, password, internal=False): """Uses ClientLogin to authenticate the user, returning an auth token. Args: @@ -307,8 +307,9 @@ class AbstractRpcServer(object): if self.host.endswith(".google.com"): # Needed for use inside Google. account_type = "HOSTED" + service = ('ClientLogin') if not internal else ('ClientAuth') req = self._CreateRequest( - url="https://www.google.com/accounts/ClientLogin", + url="https://www.google.com/accounts/%s" % (service,), data=urllib.urlencode({ "Email": email, "Passwd": password, @@ -371,12 +372,32 @@ class AbstractRpcServer(object): authentication cookie, it returns a 401 response (or a 302) and directs us to authenticate ourselves with ClientLogin. """ + INTERNAL_ERROR_MAP = { + "badauth": "BadAuthentication", + "cr": "CaptchaRequired", + "adel": "AccountDeleted", + "adis": "AccountDisabled", + "sdis": "ServiceDisabled", + "ire": "ServiceUnavailable", + } + for i in range(3): credentials = self.auth_function() + + # Try external, then internal. + e = None try: auth_token = self._GetAuthToken(credentials[0], credentials[1]) - except ClientLoginError, e: + except urllib2.HTTPError: + try: + auth_token = self._GetAuthToken(credentials[0], credentials[1], + internal=True) + except ClientLoginError, exc: + e = exc + if e: print >> sys.stderr, '' + if internal: + e.reason = INTERNAL_ERROR_MAP.get(e.reason, e.reason) if e.reason == "BadAuthentication": if e.info == "InvalidSecondFactor": print >> sys.stderr, ( @@ -409,7 +430,7 @@ class AbstractRpcServer(object): print >> sys.stderr, "The service is not available; try again later." else: # Unknown error. - raise + raise e print >> sys.stderr, '' continue self._GetAuthCookie(auth_token)