Jelajahi Sumber

[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 bulan lalu
induk
melakukan
6429a2f9e5
1 mengubah file dengan 8 tambahan dan 1 penghapusan
  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")
         return False
     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):
         LOGGER.debug("SSO=True: email is linked to google.com")
         return True