From 6429a2f9e57cf54f50020e040732f47dd4343e6b Mon Sep 17 00:00:00 2001 From: Allen Li Date: Tue, 17 Sep 2024 20:29:02 +0000 Subject: [PATCH] [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 Reviewed-by: Josip Sokcevic --- gerrit_util.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/gerrit_util.py b/gerrit_util.py index 9801765ed..c5cf716a5 100644 --- a/gerrit_util.py +++ b/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