Просмотр исходного кода

[gerrit_util] Fix ShouldUseSSO with no account

Bug: b/366261039
Change-Id: I77cd3a45ebb6e67eebcae6dc44a30b46b954a545
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5867127
Commit-Queue: Allen Li <ayatane@chromium.org>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Allen Li 11 месяцев назад
Родитель
Сommit
6429a2f9e5
1 измененных файлов с 8 добавлено и 1 удалено
  1. 8 1
      gerrit_util.py

+ 8 - 1
gerrit_util.py

@@ -201,7 +201,14 @@ def ShouldUseSSO(host: str, email: str) -> bool:
         LOGGER.debug("SSO=False: not chromium.org")
         LOGGER.debug("SSO=False: not chromium.org")
         return False
         return False
     authenticator = SSOAuthenticator()
     authenticator = SSOAuthenticator()
-    records = GetAccountEmails(host, 'self', authenticator=authenticator)
+    try:
+        records = GetAccountEmails(host, 'self', authenticator=authenticator)
+    except GerritError as e:
+        if e.http_status == 400:
+            # This is likely because the user doesn't have an account on the Gerrit host.
+            LOGGER.debug("SSO=False: get account emails returned 400")
+            return False
+        raise
     if any(email == r['email'] for r in records):
     if any(email == r['email'] for r in records):
         LOGGER.debug("SSO=True: email is linked to google.com")
         LOGGER.debug("SSO=True: email is linked to google.com")
         return True
         return True