# HG changeset patch # User Marcin Kuzminski # Date 2018-12-20 00:01:02 # Node ID 1fb993c1ee05d54a9a3b25ca0ac6708588824537 # Parent 2e5cf1746364ec5b224e5f483e115aac93ddbac5 svn: support proxy-prefix properly fixes #5521 diff --git a/rhodecode/lib/middleware/simplesvn.py b/rhodecode/lib/middleware/simplesvn.py --- a/rhodecode/lib/middleware/simplesvn.py +++ b/rhodecode/lib/middleware/simplesvn.py @@ -51,7 +51,8 @@ class SimpleSvnApp(object): data = environ['wsgi.input'] req_method = environ['REQUEST_METHOD'] has_content_length = 'CONTENT_LENGTH' in environ - path_info = self._get_url(environ['PATH_INFO']) + path_info = self._get_url( + self.config.get('subversion_http_server_url', ''), environ['PATH_INFO']) transfer_encoding = environ.get('HTTP_TRANSFER_ENCODING', '') log.debug('Handling: %s method via `%s`', req_method, path_info) @@ -117,9 +118,9 @@ class SimpleSvnApp(object): response_headers) return response.iter_content(chunk_size=1024) - def _get_url(self, path): - url_path = urlparse.urljoin( - self.config.get('subversion_http_server_url', ''), path) + def _get_url(self, svn_http_server, path): + svn_http_server_url = (svn_http_server or '').rstrip('/') + url_path = urlparse.urljoin(svn_http_server_url + '/', (path or '').lstrip('/')) url_path = urllib.quote(url_path, safe="/:=~+!$,;'") return url_path diff --git a/rhodecode/tests/lib/middleware/test_simplesvn.py b/rhodecode/tests/lib/middleware/test_simplesvn.py --- a/rhodecode/tests/lib/middleware/test_simplesvn.py +++ b/rhodecode/tests/lib/middleware/test_simplesvn.py @@ -161,9 +161,17 @@ class TestSimpleSvnApp(object): response_headers = self.app._get_response_headers(headers) assert sorted(response_headers) == sorted(expected_headers) - def test_get_url(self): - url = self.app._get_url(self.path) - expected_url = '{}{}'.format(self.host.strip('/'), self.path) + @pytest.mark.parametrize('svn_http_url, path_info, expected_url', [ + ('http://localhost:8200', '/repo_name', 'http://localhost:8200/repo_name'), + ('http://localhost:8200///', '/repo_name', 'http://localhost:8200/repo_name'), + ('http://localhost:8200', '/group/repo_name', 'http://localhost:8200/group/repo_name'), + ('http://localhost:8200/', '/group/repo_name', 'http://localhost:8200/group/repo_name'), + ('http://localhost:8200/prefix', '/repo_name', 'http://localhost:8200/prefix/repo_name'), + ('http://localhost:8200/prefix', 'repo_name', 'http://localhost:8200/prefix/repo_name'), + ('http://localhost:8200/prefix', '/group/repo_name', 'http://localhost:8200/prefix/group/repo_name') + ]) + def test_get_url(self, svn_http_url, path_info, expected_url): + url = self.app._get_url(svn_http_url, path_info) assert url == expected_url def test_call(self):