Support usernames that contain '@' and ssh Git URLs

Our company-internal Gerrit uses federated logins (Shibboleth/SAML), and
the login names happen to include the at-signs. This needed a patch to
Gerrit ([1], released in 2.13.10) to allow them. Cloning using regular
git tools as well as through the gertty work, but `git-review --list`
complained because it couldn't parse these URLs.

[1] https://gerrit-review.googlesource.com/c/94914/

Change-Id: I6c1c75a585184ee3fb2847c1e6d30802e53f8b4c
This commit is contained in:
Jan Kundrát 2017-02-03 12:22:51 +01:00 committed by Jan Kundrát
parent 514958d3f3
commit 9b68a44f38
2 changed files with 40 additions and 1 deletions

View File

@ -525,7 +525,7 @@ def parse_gerrit_ssh_params_from_git_url(git_url):
hostname = parsed_url.path[2:].split("/")[0]
if "@" in hostname:
(username, hostname) = hostname.split("@")
(username, _, hostname) = hostname.rpartition("@")
if ":" in hostname:
(hostname, port) = hostname.split(":")

View File

@ -423,3 +423,42 @@ class DownloadFlagUnitTest(testtools.TestCase):
'https://review.openstack.org/c/org/project/+/12345']
)
self.assertEqual('12345', args.cid)
class RepoUrlParsingTest(testtools.TestCase):
"""Test Git URL parsing"""
def test_ssh_openstack(self):
self.assertEqual(
cmd.parse_gerrit_ssh_params_from_git_url(
'ssh://someone@review.openstack.org:29418/x/y'),
('review.openstack.org', 'someone', '29418',
'x/y'))
def test_ssh_no_user_no_port(self):
self.assertEqual(
cmd.parse_gerrit_ssh_params_from_git_url(
'ssh://review.openstack.org/openstack-infra/git-review'),
('review.openstack.org', None, None,
'openstack-infra/git-review'))
def test_ssh_at_sign(self):
self.assertEqual(
cmd.parse_gerrit_ssh_params_from_git_url(
'ssh://someone@example.org@review.openstack.org:29418/x/y'),
('review.openstack.org', 'someone@example.org', '29418',
'x/y'))
def test_ssh_at_signs_excessive(self):
self.assertEqual(
cmd.parse_gerrit_ssh_params_from_git_url(
'ssh://x@y@example.org@review.openstack.org:29418/x/y'),
('review.openstack.org', 'x@y@example.org', '29418',
'x/y'))
def test_ssh_at_sign_escaped(self):
self.assertEqual(
cmd.parse_gerrit_ssh_params_from_git_url(
r'ssh://someone%40example.org@review.openstack.org:29418/x/y'),
('review.openstack.org', r'someone%40example.org', '29418',
'x/y'))