From 397bf12548652b88da026fe94eb76f12f8d6ae00 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Sat, 20 Jul 2024 03:10:09 +0000 Subject: [PATCH] [git_cl] Default to SSO with missing email This is a safer default if SSO is available Bug: b/351071334 Change-Id: I2d6b3b5c0fbe3fb7b9783de3d7548be7f14d7391 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5723448 Reviewed-by: Robbie Iannucci Reviewed-by: Yiwei Zhang Commit-Queue: Allen Li --- gerrit_util.py | 4 ++++ tests/gerrit_util_test.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gerrit_util.py b/gerrit_util.py index c09c331b6..8fafa8a56 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -183,6 +183,10 @@ def ShouldUseSSO(host: str, email: str) -> bool: if not ssoHelper.find_cmd(): LOGGER.debug("SSO=False: no SSO command") return False + if not email: + LOGGER.debug( + "SSO=True: email is empty or missing (and SSO command available)") + return True if email.endswith('@google.com'): LOGGER.debug("SSO=True: email is google.com") return True diff --git a/tests/gerrit_util_test.py b/tests/gerrit_util_test.py index 113257a5f..4d7629f17 100755 --- a/tests/gerrit_util_test.py +++ b/tests/gerrit_util_test.py @@ -744,7 +744,10 @@ class ShouldUseSSOTest(unittest.TestCase): self.assertFalse( gerrit_util.ShouldUseSSO('fake-host', 'firefly@google.com')) - def testGoogle(self): + def testEmptyEmail(self): + self.assertTrue(gerrit_util.ShouldUseSSO('fake-host', '')) + + def testGoogleEmail(self): self.assertTrue( gerrit_util.ShouldUseSSO('fake-host', 'firefly@google.com'))