瀏覽代碼

Fix gerrit new-password URL

This change fixes gerrit new-password URL from <host>-review.googlesource.com/new-password to <host>.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 <sokcevic@chromium.org>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
Aravind Vasudevan 2 年之前
父節點
當前提交
a02b4bf030
共有 4 個文件被更改,包括 14 次插入12 次删除
  1. 5 2
      gerrit_util.py
  2. 5 6
      tests/gerrit_util_test.py
  3. 3 3
      tests/git_cl_creds_check_report.txt
  4. 1 1
      tests/git_cl_test.py

+ 5 - 2
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

+ 5 - 6
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):

+ 3 - 3
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

+ 1 - 1
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())