From 0526335226fb1cb4c74b5204ca2136087bbc6a71 Mon Sep 17 00:00:00 2001 From: Eric Boren Date: Tue, 18 Sep 2018 16:54:45 +0000 Subject: [PATCH] Revert "gerrit_util: Support OAuth2 bearer tokens in CookieAuthenticator" This reverts commit 18b4479cee3fece5afeb19b79e00bc876550a749. Reason for revert: Breaking WebRTC roller: https://luci-milo.appspot.com/buildbot/client.webrtc.fyi/Auto-roll%20-%20WebRTC%20DEPS/12788 Original change's description: > gerrit_util: Support OAuth2 bearer tokens in CookieAuthenticator > > Change-Id: I9fd3e2fa9ea16d7f057290e77a81f7009c7c9d91 > Reviewed-on: https://chromium-review.googlesource.com/1221826 > Reviewed-by: Vadim Shtayura > Reviewed-by: Andrii Shyshkalov > Commit-Queue: Eric Boren TBR=vadimsh@chromium.org,dnj@chromium.org,borenet@chromium.org,tandrii@chromium.org Change-Id: I93bbd2d09cd2b27d9a7aa98fc15d60c5033a38cd No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/1231433 Reviewed-by: Eric Boren Commit-Queue: Eric Boren --- gerrit_util.py | 13 ++++--------- tests/git_cl_test.py | 13 ------------- 2 files changed, 4 insertions(+), 22 deletions(-) diff --git a/gerrit_util.py b/gerrit_util.py index 9b5214660..f7bd210d3 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -200,13 +200,11 @@ class CookiesAuthenticator(Authenticator): continue domain, xpath, key, value = fields[0], fields[2], fields[5], fields[6] if xpath == '/' and key == 'o': - if value.startswith('git-'): - login, secret_token = value.split('=', 1) - gitcookies[domain] = (login, secret_token) - else: - gitcookies[domain] = ('', value) + login, secret_token = value.split('=', 1) + gitcookies[domain] = (login, secret_token) except (IndexError, ValueError, TypeError) as exc: LOGGER.warning(exc) + return gitcookies def _get_auth_for_host(self, host): @@ -218,10 +216,7 @@ class CookiesAuthenticator(Authenticator): def get_auth_header(self, host): a = self._get_auth_for_host(host) if a: - if a[0]: - return 'Basic %s' % (base64.b64encode('%s:%s' % (a[0], a[2]))) - else: - return 'Bearer %s' % a[2] + return 'Basic %s' % (base64.b64encode('%s:%s' % (a[0], a[2]))) return None def get_auth_email(self, host): diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index 6df29c6c1..cb20c194c 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -24,7 +24,6 @@ import metrics # We have to disable monitoring before importing git_cl. metrics.DISABLE_METRICS_COLLECTION = True -import gerrit_util import git_cl import git_common import git_footers @@ -2105,18 +2104,6 @@ class TestGitCl(TestCase): auth={}, skip_auth_check=True) self.assertIsNone(cl.EnsureAuthenticated(force=False)) - def test_gerrit_ensure_authenticated_bearer_token(self): - cl = self._test_gerrit_ensure_authenticated_common(auth={ - 'chromium.googlesource.com': - ('', None, 'secret'), - 'chromium-review.googlesource.com': - ('', None, 'secret'), - }) - self.assertIsNone(cl.EnsureAuthenticated(force=False)) - header = gerrit_util.CookiesAuthenticator().get_auth_header( - 'chromium.googlesource.com') - self.assertTrue('Bearer' in header) - def test_cmd_set_commit_rietveld(self): self.mock(git_cl._RietveldChangelistImpl, 'SetFlags', lambda _, v: self._mocked_call(['SetFlags', v]))