From a02b4bf030ddda5d1ffa36ef0325dff4226ec47d Mon Sep 17 00:00:00 2001 From: Aravind Vasudevan Date: Fri, 3 Feb 2023 17:52:03 +0000 Subject: [PATCH] Fix gerrit new-password URL This change fixes gerrit new-password URL from -review.googlesource.com/new-password to .googlesource.com/new-password. Fixed: 1412557 Change-Id: I0c73e890fa9db5e2172d9a88cbc50703675e9f50 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4219808 Reviewed-by: Josip Sokcevic Reviewed-by: Joanna Wang Commit-Queue: Aravind Vasudevan --- gerrit_util.py | 7 +++++-- tests/gerrit_util_test.py | 11 +++++------ tests/git_cl_creds_check_report.txt | 6 +++--- tests/git_cl_test.py | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/gerrit_util.py b/gerrit_util.py index 666875604..89ac99061 100644 --- a/gerrit_util.py +++ b/gerrit_util.py @@ -146,8 +146,11 @@ class CookiesAuthenticator(Authenticator): assert not host.startswith('http') # Assume *.googlesource.com pattern. parts = host.split('.') - if not parts[0].endswith('-review'): - parts[0] += '-review' + + # remove -review suffix if present. + if parts[0].endswith('-review'): + parts[0] = parts[0][:-len('-review')] + return 'https://%s/new-password' % ('.'.join(parts)) @classmethod diff --git a/tests/gerrit_util_test.py b/tests/gerrit_util_test.py index d22b41723..96d28b4aa 100755 --- a/tests/gerrit_util_test.py +++ b/tests/gerrit_util_test.py @@ -105,20 +105,19 @@ class CookiesAuthenticatorTest(unittest.TestCase): def testGetNewPasswordUrl(self): auth = gerrit_util.CookiesAuthenticator() + self.assertEqual('https://chromium.googlesource.com/new-password', + auth.get_new_password_url('chromium.googlesource.com')) self.assertEqual( - 'https://chromium-review.googlesource.com/new-password', - auth.get_new_password_url('chromium.googlesource.com')) - self.assertEqual( - 'https://chrome-internal-review.googlesource.com/new-password', + 'https://chrome-internal.googlesource.com/new-password', auth.get_new_password_url('chrome-internal-review.googlesource.com')) def testGetNewPasswordMessage(self): auth = gerrit_util.CookiesAuthenticator() self.assertIn( - 'https://chromium-review.googlesource.com/new-password', + 'https://chromium.googlesource.com/new-password', auth.get_new_password_message('chromium-review.googlesource.com')) self.assertIn( - 'https://chrome-internal-review.googlesource.com/new-password', + 'https://chrome-internal.googlesource.com/new-password', auth.get_new_password_message('chrome-internal.googlesource.com')) def testGetGitcookiesPath(self): diff --git a/tests/git_cl_creds_check_report.txt b/tests/git_cl_creds_check_report.txt index 4680043cd..b513bce54 100644 --- a/tests/git_cl_creds_check_report.txt +++ b/tests/git_cl_creds_check_report.txt @@ -19,6 +19,6 @@ You can manually remove corresponding lines in your ~%(sep)s.gitcookies file and visit the following URLs with correct account to generate correct credential lines: - https://conflict-review.googlesource.com/new-password - https://gpartial-review.googlesource.com/new-password - https://partial-review.googlesource.com/new-password + https://conflict.googlesource.com/new-password + https://gpartial.googlesource.com/new-password + https://partial.googlesource.com/new-password diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index f4e884e38..a43cfef71 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -2329,7 +2329,7 @@ class TestGitCl(unittest.TestCase): 'These are read from ~%(sep)s.gitcookies ' '(or legacy ~%(sep)s%(netrc)s)\n' 'You can (re)generate your credentials by visiting ' - 'https://chromium-review.googlesource.com/new-password\n' % { + 'https://chromium.googlesource.com/new-password\n' % { 'sep': os.sep, 'netrc': NETRC_FILENAME, }, sys.stderr.getvalue())