# HG changeset patch # User Daniel Dourvaris # Date 2019-07-02 12:39:44 # Node ID 43af4e52b104b7272ba3a54cb1064900b1ce380c # Parent 5644458b055f186d0b927fe51ddef274f691eb4e git-lfs: fixed bug #5399 git-lfs application failed to generate HTTPS urls properly. diff --git a/vcsserver/git_lfs/app.py b/vcsserver/git_lfs/app.py --- a/vcsserver/git_lfs/app.py +++ b/vcsserver/git_lfs/app.py @@ -90,6 +90,8 @@ def lfs_objects_batch(request): repo = request.matchdict.get('repo') data = request.json operation = data.get('operation') + http_scheme = request.registry.git_lfs_http_scheme + if operation not in ('download', 'upload'): log.debug('LFS: unsupported operation:%s', operation) return write_response_error( @@ -114,8 +116,10 @@ def lfs_objects_batch(request): obj_data = {'oid': oid} - obj_href = request.route_url('lfs_objects_oid', repo=repo, oid=oid) - obj_verify_href = request.route_url('lfs_objects_verify', repo=repo) + obj_href = request.route_url('lfs_objects_oid', repo=repo, oid=oid, + _scheme=http_scheme) + obj_verify_href = request.route_url('lfs_objects_verify', repo=repo, + _scheme=http_scheme) store = LFSOidStore( oid, repo, store_location=request.registry.git_lfs_store_path) handler = OidHandler( @@ -274,11 +278,12 @@ def git_lfs_app(config): config.add_notfound_view(not_found, renderer='json') -def create_app(git_lfs_enabled, git_lfs_store_path): +def create_app(git_lfs_enabled, git_lfs_store_path, git_lfs_http_scheme): config = Configurator() if git_lfs_enabled: config.include(git_lfs_app) config.registry.git_lfs_store_path = git_lfs_store_path + config.registry.git_lfs_http_scheme = git_lfs_http_scheme else: # not found handler for API, reporting disabled LFS support config.add_notfound_view(lfs_disabled, renderer='json') diff --git a/vcsserver/git_lfs/tests/test_lfs_app.py b/vcsserver/git_lfs/tests/test_lfs_app.py --- a/vcsserver/git_lfs/tests/test_lfs_app.py +++ b/vcsserver/git_lfs/tests/test_lfs_app.py @@ -26,7 +26,17 @@ from vcsserver.git_lfs.app import create @pytest.fixture(scope='function') def git_lfs_app(tmpdir): custom_app = WebObTestApp(create_app( - git_lfs_enabled=True, git_lfs_store_path=str(tmpdir))) + git_lfs_enabled=True, git_lfs_store_path=str(tmpdir), + git_lfs_http_scheme='http')) + custom_app._store = str(tmpdir) + return custom_app + + +@pytest.fixture(scope='function') +def git_lfs_https_app(tmpdir): + custom_app = WebObTestApp(create_app( + git_lfs_enabled=True, git_lfs_store_path=str(tmpdir), + git_lfs_http_scheme='https')) custom_app._store = str(tmpdir) return custom_app @@ -58,7 +68,7 @@ class TestLFSApplication(object): assert json.loads(response.text) == { u'message': u'GIT LFS locking api not supported'} - def test_app_batch_api_missing_auth(self, git_lfs_app,): + def test_app_batch_api_missing_auth(self, git_lfs_app): git_lfs_app.post_json( '/repo/info/lfs/objects/batch', params={}, status=403) @@ -155,8 +165,31 @@ class TestLFSApplication(object): assert json.loads(response.text) == { 'objects': expected_objects, 'transfer': 'basic'} + def test_app_batch_api_upload_for_https(self, git_lfs_https_app, http_auth): + params = {'operation': 'upload', + 'objects': [{'oid': '123', 'size': '1024'}]} + response = git_lfs_https_app.post_json( + '/repo/info/lfs/objects/batch', params=params, + extra_environ=http_auth) + expected_objects = [ + {u'authenticated': True, + u'actions': { + u'upload': { + u'header': {u'Authorization': u'Basic XXXXX', + u'Transfer-Encoding': u'chunked'}, + u'href': u'https://localhost/repo/info/lfs/objects/123'}, + u'verify': { + u'header': {u'Authorization': u'Basic XXXXX'}, + u'href': u'https://localhost/repo/info/lfs/verify'} + }, + u'oid': u'123', + u'size': u'1024'} + ] + assert json.loads(response.text) == { + 'objects': expected_objects, 'transfer': 'basic'} + def test_app_verify_api_missing_data(self, git_lfs_app): - params = {'oid': 'missing',} + params = {'oid': 'missing'} response = git_lfs_app.post_json( '/repo/info/lfs/verify', params=params, status=400) diff --git a/vcsserver/scm_app.py b/vcsserver/scm_app.py --- a/vcsserver/scm_app.py +++ b/vcsserver/scm_app.py @@ -218,8 +218,8 @@ class GitLFSHandler(object): self.git_path = git_path self.update_server_info = update_server_info - def get_app(self, git_lfs_enabled, git_lfs_store_path): - app = git_lfs.create_app(git_lfs_enabled, git_lfs_store_path) + def get_app(self, git_lfs_enabled, git_lfs_store_path, git_lfs_http_scheme): + app = git_lfs.create_app(git_lfs_enabled, git_lfs_store_path, git_lfs_http_scheme) return app @@ -228,7 +228,8 @@ def create_git_lfs_wsgi_app(repo_path, r update_server_info = config.pop('git_update_server_info') git_lfs_enabled = config.pop('git_lfs_enabled') git_lfs_store_path = config.pop('git_lfs_store_path') + git_lfs_http_scheme = config.pop('git_lfs_http_scheme', 'http') app = GitLFSHandler( repo_path, repo_name, git_path, update_server_info, config) - return app.get_app(git_lfs_enabled, git_lfs_store_path) + return app.get_app(git_lfs_enabled, git_lfs_store_path, git_lfs_http_scheme)