From bb38aa2f8eb4b6b0e675a592b2296a30370720e6 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Mon, 24 Jun 2024 21:11:50 +0000 Subject: [PATCH] [gerrit_util] Use SSO only if configured with appropriate email So you can use chromium.org or other accounts in some repos Bug: b/348024314 Change-Id: Ice6b6d9e6e827a606a2ce7f3b127d4660df1aedf Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5641255 Reviewed-by: Gavin Mak Commit-Queue: Allen Li --- gerrit_util.py | 7 ++++--- tests/gerrit_util_test.py | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gerrit_util.py b/gerrit_util.py index 9294d46cb..70c4bd68f 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -303,9 +303,10 @@ class SSOAuthenticator(Authenticator): @classmethod def is_applicable(cls) -> bool: - """If the git-remote-sso binary is in $PATH, we consider this - authenticator to be applicable.""" - return bool(cls._resolve_sso_cmd()) + if not cls._resolve_sso_cmd(): + return False + email = scm.GIT.GetConfig(os.getcwd(), 'user.email', default='') + return email.endswith('@google.com') @classmethod def _parse_config(cls, config: str) -> SSOInfo: diff --git a/tests/gerrit_util_test.py b/tests/gerrit_util_test.py index 444a36f05..80b126542 100755 --- a/tests/gerrit_util_test.py +++ b/tests/gerrit_util_test.py @@ -623,7 +623,9 @@ class SSOAuthenticatorTest(unittest.TestCase): self.assertEqual(self.sso._resolve_sso_cmd(), ('/fake/git-remote-sso', '-print_config', 'sso://*.git.corp.google.com')) - self.assertTrue(self.sso.is_applicable()) + with mock.patch('scm.GIT.GetConfig') as p: + p.side_effect = ['firefly@google.com'] + self.assertTrue(self.sso.is_applicable()) @mock.patch('gerrit_util.ssoHelper.find_cmd', return_value=None) def testCmdAssemblyNotFound(self, _):