##// END OF EJS Templates
svn: properly pass credentials from URL during import.
marcink -
r523:563cae9b stable
parent child Browse files
Show More
@@ -18,7 +18,9 b''
18 18 from __future__ import absolute_import
19 19
20 20 import os
21 import subprocess
21 22 from urllib2 import URLError
23 import urlparse
22 24 import logging
23 25 import posixpath as vcspath
24 26 import StringIO
@@ -350,15 +352,27 b' class SvnRemote(object):'
350 352 self._factory.repo(wire, create=True,
351 353 compatible_version=compatible_version)
352 354
355 def get_url_and_credentials(self, src_url):
356 obj = urlparse.urlparse(src_url)
357 username = obj.username or None
358 password = obj.password or None
359 return username, password, src_url
360
353 361 def import_remote_repository(self, wire, src_url):
354 362 repo_path = wire['path']
355 363 if not self.is_path_valid_repository(wire, repo_path):
356 364 raise Exception(
357 365 "Path %s is not a valid Subversion repository." % repo_path)
358 366
359 import subprocess
367 username, password, src_url = self.get_url_and_credentials(src_url)
368 rdump_cmd = ['svnrdump', 'dump', '--non-interactive',
369 '--trust-server-cert-failures=unknown-ca']
370 if username and password:
371 rdump_cmd += ['--username', username, '--password', password]
372 rdump_cmd += [src_url]
373
360 374 rdump = subprocess.Popen(
361 ['svnrdump', 'dump', '--non-interactive', src_url],
375 rdump_cmd,
362 376 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
363 377 load = subprocess.Popen(
364 378 ['svnadmin', 'load', repo_path], stdin=rdump.stdout)
@@ -64,3 +64,19 b' def test_svn_libraries_can_be_imported()'
64 64 import svn
65 65 import svn.client
66 66 assert svn.client is not None
67
68
69 @pytest.mark.parametrize('example_url, parts', [
70 ('http://server.com', (None, None, 'http://server.com')),
71 ('http://user@server.com', ('user', None, 'http://user@server.com')),
72 ('http://user:pass@server.com', ('user', 'pass', 'http://user:pass@server.com')),
73 ('<script>', (None, None, '<script>')),
74 ('http://', (None, None, 'http://')),
75 ])
76 def test_username_password_extraction_from_url(example_url, parts):
77 from vcsserver import svn
78
79 remote = svn.SvnRemote(None)
80 remote.is_path_valid_repository = lambda wire, path: True
81
82 assert remote.get_url_and_credentials(example_url) == parts
General Comments 0
You need to be logged in to leave comments. Login now