[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 <gavinmak@google.com>
Commit-Queue: Allen Li <ayatane@chromium.org>
changes/55/5641255/10
Allen Li 10 months ago committed by LUCI CQ
parent 005e60ceda
commit bb38aa2f8e

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

@ -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, _):

Loading…
Cancel
Save