Parcourir la source

[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 <iannucci@chromium.org>
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
Allen Li il y a 1 an
Parent
commit
397bf12548
2 fichiers modifiés avec 8 ajouts et 1 suppressions
  1. 4 0
      gerrit_util.py
  2. 4 1
      tests/gerrit_util_test.py

+ 4 - 0
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

+ 4 - 1
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'))