[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>
changes/27/5867127/2
Allen Li 7 months ago committed by LUCI CQ
parent 6e9a3df972
commit 6429a2f9e5

@ -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

Loading…
Cancel
Save