2018-01-03 22:51:20 +03:00
|
|
|
# no-check-code -- see T24862348
|
|
|
|
|
2018-01-17 14:23:44 +03:00
|
|
|
import test_hgsubversion_util
|
svnwrap: fix handling of quotable URLs (fixes #197, refs #132)
The way hgsubversion handles URLs that may or may not be quoted is
somewhat fragile. As part of fixing issue 132 in 06d89c2063a2, the
path component of URLs was always quoted. The URL has been attempted
encoded since the initial check-in.
The fix from 06d89c2063a2 was incomplete; reverting it allows us to
clone a URL with a '~' in it.[1] Encoding the URL as UTF-8 seldom
works as expected, as the default string encoding is ASCII, causing
Python to be unable to decode any URL containing an 8-bit
character.
The core problem here is that we don't know whether the URL specified
by the user is quoted or not. Rather than trying to deal with this
ourselves, we pass the problem on to Subversion. Then, we obtain the
URL from the RA instance, where it is always quoted. (It's worth
noting that the editor interface, on the other hand, always deals with
unquoted paths...)
Thus, the following invariants should apply to SubversionRepo
attributes:
- svn_url and root will always be quoted.
- subdir will always be unquoted.
Tests are added that verify that it won't affect the conversion
whether a URL is specified in quoted or unquoted form. Furthermore, a
test fixture for this is added *twice*, so that we can thoroughly test
both quoted and unquoted URLs. I'm not adding a test dedicated to
tildes in URLs; it doesn't seem necessary.
[1] Such as <https://svn.kenai.com/svn/winsw~subversion>.
2010-10-05 06:00:36 +04:00
|
|
|
|
|
|
|
import urllib
|
|
|
|
|
2018-01-11 03:20:54 +03:00
|
|
|
from hgext.hgsubversion.svnwrap import parse_url
|
|
|
|
from hgext.hgsubversion import svnrepo
|
2009-04-06 19:19:51 +04:00
|
|
|
|
2018-01-17 14:23:44 +03:00
|
|
|
class TestSubversionUrls(test_hgsubversion_util.TestBase):
|
2009-04-06 19:19:51 +04:00
|
|
|
def test_standard_url(self):
|
2016-06-12 00:36:57 +03:00
|
|
|
self.check_parse_url((None, None, 'file:///var/svn/repo'),
|
|
|
|
('file:///var/svn/repo', ))
|
2009-04-06 19:19:51 +04:00
|
|
|
|
|
|
|
def test_user_url(self):
|
2016-06-12 00:36:57 +03:00
|
|
|
self.check_parse_url(
|
2009-07-19 05:44:33 +04:00
|
|
|
('joe', None, 'https://svn.testurl.com/repo'),
|
2016-06-12 00:36:57 +03:00
|
|
|
('https://joe@svn.testurl.com/repo', ))
|
|
|
|
self.check_parse_url(
|
2009-07-19 05:44:33 +04:00
|
|
|
('bob', None, 'https://svn.testurl.com/repo'),
|
2016-06-12 00:36:57 +03:00
|
|
|
('https://joe@svn.testurl.com/repo', 'bob', ))
|
2009-04-06 19:19:51 +04:00
|
|
|
|
|
|
|
def test_password_url(self):
|
2016-06-12 00:36:57 +03:00
|
|
|
self.check_parse_url(
|
2009-07-19 05:44:33 +04:00
|
|
|
(None, 't3stpw', 'svn+ssh://svn.testurl.com/repo'),
|
2016-06-12 00:36:57 +03:00
|
|
|
('svn+ssh://:t3stpw@svn.testurl.com/repo', ))
|
|
|
|
self.check_parse_url(
|
2009-07-19 05:44:33 +04:00
|
|
|
(None, '123abc', 'svn+ssh://svn.testurl.com/repo'),
|
2016-06-12 00:36:57 +03:00
|
|
|
('svn+ssh://:t3stpw@svn.testurl.com/repo', None, '123abc', ))
|
2009-04-06 19:19:51 +04:00
|
|
|
|
2009-06-06 20:53:21 +04:00
|
|
|
def test_svnssh_preserve_user(self):
|
2016-06-12 00:36:57 +03:00
|
|
|
self.check_parse_url(
|
2011-10-12 11:35:25 +04:00
|
|
|
('user', 't3stpw', 'svn+ssh://user@svn.testurl.com/repo',),
|
2016-06-12 00:36:57 +03:00
|
|
|
('svn+ssh://user:t3stpw@svn.testurl.com/repo', ))
|
|
|
|
self.check_parse_url(
|
2011-10-12 11:35:25 +04:00
|
|
|
('bob', '123abc', 'svn+ssh://bob@svn.testurl.com/repo',),
|
2016-06-12 00:36:57 +03:00
|
|
|
('svn+ssh://user:t3stpw@svn.testurl.com/repo', 'bob', '123abc', ))
|
|
|
|
self.check_parse_url(
|
2011-10-12 11:35:25 +04:00
|
|
|
('user2', None, 'svn+ssh://user2@svn.testurl.com/repo',),
|
2016-06-12 00:36:57 +03:00
|
|
|
('svn+ssh://user2@svn.testurl.com/repo', ))
|
|
|
|
self.check_parse_url(
|
2011-10-12 11:35:25 +04:00
|
|
|
('bob', None, 'svn+ssh://bob@svn.testurl.com/repo',),
|
2016-06-12 00:36:57 +03:00
|
|
|
('svn+ssh://user2@svn.testurl.com/repo', 'bob', ))
|
2009-06-06 20:53:21 +04:00
|
|
|
|
2009-04-06 19:19:51 +04:00
|
|
|
def test_user_password_url(self):
|
2016-06-12 00:36:57 +03:00
|
|
|
self.check_parse_url(
|
2009-07-19 05:44:33 +04:00
|
|
|
('joe', 't3stpw', 'https://svn.testurl.com/repo'),
|
2016-06-12 00:36:57 +03:00
|
|
|
('https://joe:t3stpw@svn.testurl.com/repo', ))
|
|
|
|
self.check_parse_url(
|
2009-07-19 05:44:33 +04:00
|
|
|
('bob', '123abc', 'https://svn.testurl.com/repo'),
|
2016-06-12 00:36:57 +03:00
|
|
|
('https://joe:t3stpw@svn.testurl.com/repo', 'bob', '123abc', ))
|
2009-04-06 19:19:51 +04:00
|
|
|
|
2009-07-19 05:44:33 +04:00
|
|
|
def test_url_rewriting(self):
|
2018-01-17 14:23:44 +03:00
|
|
|
ui = test_hgsubversion_util.testui()
|
2009-07-19 05:44:33 +04:00
|
|
|
ui.setconfig('hgsubversion', 'username', 'bob')
|
|
|
|
repo = svnrepo.svnremoterepo(ui, 'svn+ssh://joe@foo/bar')
|
2010-09-29 20:04:26 +04:00
|
|
|
self.assertEqual('svn+ssh://bob@foo/bar', repo.svnauth[0])
|
2016-06-12 00:36:57 +03:00
|
|
|
self.assertEqual('svn+ssh://bob@foo/bar', repo.svnurl)
|
2009-04-06 19:19:51 +04:00
|
|
|
|
Revive svn+http(s) URLs support (issue94)
Telling svn from mercurial repository automatically is not always possible, or
at least not seamlessly. Let 'http://repo.com/svn' be an svn repository,
protected with basic authentication. Trying to clone it directly does something
like:
1- Open it like a mercurial repository:
* send between command, ask for credentials, fail
* fallback to static-http, ask for crendentials two times, fail
2- Open it like an svn repository
Mercurial [auth] facility is helpful here, but few people know about it, and it
may seem weird to store svn credentials in mercurial configuration. An svn-like
password manager would not help either because all connections attempts in [1]
fail and it's unlikely we would store credentials in this situation. Instead,
we can clone 'svn+http://repo.com/svn', which will skip step [1].
2009-07-19 05:44:33 +04:00
|
|
|
repo = svnrepo.svnremoterepo(ui, 'svn+http://joe@foo/bar')
|
|
|
|
self.assertEqual(('http://foo/bar', 'bob', None), repo.svnauth)
|
2016-06-12 00:36:57 +03:00
|
|
|
self.assertEqual('http://foo/bar', repo.svnurl)
|
Revive svn+http(s) URLs support (issue94)
Telling svn from mercurial repository automatically is not always possible, or
at least not seamlessly. Let 'http://repo.com/svn' be an svn repository,
protected with basic authentication. Trying to clone it directly does something
like:
1- Open it like a mercurial repository:
* send between command, ask for credentials, fail
* fallback to static-http, ask for crendentials two times, fail
2- Open it like an svn repository
Mercurial [auth] facility is helpful here, but few people know about it, and it
may seem weird to store svn credentials in mercurial configuration. An svn-like
password manager would not help either because all connections attempts in [1]
fail and it's unlikely we would store credentials in this situation. Instead,
we can clone 'svn+http://repo.com/svn', which will skip step [1].
2009-07-19 05:44:33 +04:00
|
|
|
|
2009-07-21 00:00:37 +04:00
|
|
|
repo = svnrepo.svnremoterepo(ui, 'svn+https://joe@foo/bar')
|
|
|
|
self.assertEqual(('https://foo/bar', 'bob', None), repo.svnauth)
|
2016-06-12 00:36:57 +03:00
|
|
|
self.assertEqual('https://foo/bar', repo.svnurl)
|
2009-07-21 00:00:37 +04:00
|
|
|
|
svnwrap: fix handling of quotable URLs (fixes #197, refs #132)
The way hgsubversion handles URLs that may or may not be quoted is
somewhat fragile. As part of fixing issue 132 in 06d89c2063a2, the
path component of URLs was always quoted. The URL has been attempted
encoded since the initial check-in.
The fix from 06d89c2063a2 was incomplete; reverting it allows us to
clone a URL with a '~' in it.[1] Encoding the URL as UTF-8 seldom
works as expected, as the default string encoding is ASCII, causing
Python to be unable to decode any URL containing an 8-bit
character.
The core problem here is that we don't know whether the URL specified
by the user is quoted or not. Rather than trying to deal with this
ourselves, we pass the problem on to Subversion. Then, we obtain the
URL from the RA instance, where it is always quoted. (It's worth
noting that the editor interface, on the other hand, always deals with
unquoted paths...)
Thus, the following invariants should apply to SubversionRepo
attributes:
- svn_url and root will always be quoted.
- subdir will always be unquoted.
Tests are added that verify that it won't affect the conversion
whether a URL is specified in quoted or unquoted form. Furthermore, a
test fixture for this is added *twice*, so that we can thoroughly test
both quoted and unquoted URLs. I'm not adding a test dedicated to
tildes in URLs; it doesn't seem necessary.
[1] Such as <https://svn.kenai.com/svn/winsw~subversion>.
2010-10-05 06:00:36 +04:00
|
|
|
def test_quoting(self):
|
|
|
|
ui = self.ui()
|
2012-04-19 20:29:28 +04:00
|
|
|
repo_path = self.load_svndump('non_ascii_path_1.svndump')
|
svnwrap: fix handling of quotable URLs (fixes #197, refs #132)
The way hgsubversion handles URLs that may or may not be quoted is
somewhat fragile. As part of fixing issue 132 in 06d89c2063a2, the
path component of URLs was always quoted. The URL has been attempted
encoded since the initial check-in.
The fix from 06d89c2063a2 was incomplete; reverting it allows us to
clone a URL with a '~' in it.[1] Encoding the URL as UTF-8 seldom
works as expected, as the default string encoding is ASCII, causing
Python to be unable to decode any URL containing an 8-bit
character.
The core problem here is that we don't know whether the URL specified
by the user is quoted or not. Rather than trying to deal with this
ourselves, we pass the problem on to Subversion. Then, we obtain the
URL from the RA instance, where it is always quoted. (It's worth
noting that the editor interface, on the other hand, always deals with
unquoted paths...)
Thus, the following invariants should apply to SubversionRepo
attributes:
- svn_url and root will always be quoted.
- subdir will always be unquoted.
Tests are added that verify that it won't affect the conversion
whether a URL is specified in quoted or unquoted form. Furthermore, a
test fixture for this is added *twice*, so that we can thoroughly test
both quoted and unquoted URLs. I'm not adding a test dedicated to
tildes in URLs; it doesn't seem necessary.
[1] Such as <https://svn.kenai.com/svn/winsw~subversion>.
2010-10-05 06:00:36 +04:00
|
|
|
|
2018-01-17 14:23:44 +03:00
|
|
|
repo_url = test_hgsubversion_util.fileurl(repo_path)
|
svnwrap: fix handling of quotable URLs (fixes #197, refs #132)
The way hgsubversion handles URLs that may or may not be quoted is
somewhat fragile. As part of fixing issue 132 in 06d89c2063a2, the
path component of URLs was always quoted. The URL has been attempted
encoded since the initial check-in.
The fix from 06d89c2063a2 was incomplete; reverting it allows us to
clone a URL with a '~' in it.[1] Encoding the URL as UTF-8 seldom
works as expected, as the default string encoding is ASCII, causing
Python to be unable to decode any URL containing an 8-bit
character.
The core problem here is that we don't know whether the URL specified
by the user is quoted or not. Rather than trying to deal with this
ourselves, we pass the problem on to Subversion. Then, we obtain the
URL from the RA instance, where it is always quoted. (It's worth
noting that the editor interface, on the other hand, always deals with
unquoted paths...)
Thus, the following invariants should apply to SubversionRepo
attributes:
- svn_url and root will always be quoted.
- subdir will always be unquoted.
Tests are added that verify that it won't affect the conversion
whether a URL is specified in quoted or unquoted form. Furthermore, a
test fixture for this is added *twice*, so that we can thoroughly test
both quoted and unquoted URLs. I'm not adding a test dedicated to
tildes in URLs; it doesn't seem necessary.
[1] Such as <https://svn.kenai.com/svn/winsw~subversion>.
2010-10-05 06:00:36 +04:00
|
|
|
subdir = '/b\xC3\xB8b'
|
|
|
|
quoted_subdir = urllib.quote(subdir)
|
|
|
|
|
|
|
|
repo1 = svnrepo.svnremoterepo(ui, repo_url + subdir)
|
|
|
|
repo2 = svnrepo.svnremoterepo(ui, repo_url + quoted_subdir)
|
|
|
|
self.assertEqual(repo1.svnurl, repo2.svnurl)
|
2016-06-12 00:36:57 +03:00
|
|
|
|
|
|
|
def check_parse_url(self, expected, args):
|
|
|
|
self.assertEqual(expected, parse_url(*args))
|
|
|
|
if len(args) == 1:
|
|
|
|
repo = svnrepo.svnremoterepo(self.ui(), path=args[0])
|
|
|
|
self.assertEqual(expected[2], repo.svnauth[0])
|
|
|
|
self.assertEqual(expected[2], repo.svnurl)
|
2018-01-17 14:23:44 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import silenttestrunner
|
|
|
|
silenttestrunner.main(__name__)
|
|
|
|
|