##// END OF EJS Templates
deps: bumped venusian==3.1.0 for python 3.12 compat
deps: bumped venusian==3.1.0 for python 3.12 compat

File last commit:

r1327:278da2b3 default
r1333:7f098036 default
Show More
test_lib.py
143 lines | 4.8 KiB | text/x-python | PythonLexer
git-lfs: added vcsserver handling of git-lfs objects....
r180 # RhodeCode VCSServer provides access to different vcs backends via network.
core: updated copyrights to 2024
r1327 # Copyright (C) 2014-2024 RhodeCode GmbH
git-lfs: added vcsserver handling of git-lfs objects....
r180 #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import os
import pytest
core: moved str_utils and type_utils to lib so it's consistent with ce, and easier to sync up codebases
r1249 from vcsserver.lib.str_utils import safe_bytes
git-lfs: added vcsserver handling of git-lfs objects....
r180 from vcsserver.git_lfs.lib import OidHandler, LFSOidStore
@pytest.fixture()
def lfs_store(tmpdir):
repo = 'test'
fix(git-lfs): fixed security problem with allowing off-chain attacks to replace OID data without validating hash for already present oids....
r1300 oid = '65f23e22a9bfedda96929b3cfcb8b6d2fdd34a2e877ddb81f45d79ab05710e12'
git-lfs: don't store oid under repo-path....
r181 store = LFSOidStore(oid=oid, repo=repo, store_location=str(tmpdir))
git-lfs: added vcsserver handling of git-lfs objects....
r180 return store
@pytest.fixture()
def oid_handler(lfs_store):
store = lfs_store
repo = store.repo
oid = store.oid
oid_handler = OidHandler(
store=store, repo_name=repo, auth=('basic', 'xxxx'),
oid=oid,
obj_size='1024', obj_data={}, obj_href='http://localhost/handle_oid',
obj_verify_href='http://localhost/verify')
return oid_handler
lint: auto-fixes
r1152 class TestOidHandler:
git-lfs: added vcsserver handling of git-lfs objects....
r180
@pytest.mark.parametrize('exec_action', [
'download',
'upload',
])
def test_exec_action(self, exec_action, oid_handler):
handler = oid_handler.exec_operation(exec_action)
assert handler
def test_exec_action_undefined(self, oid_handler):
with pytest.raises(AttributeError):
oid_handler.exec_operation('wrong')
def test_download_oid_not_existing(self, oid_handler):
response, has_errors = oid_handler.exec_operation('download')
assert response is None
assert has_errors['error'] == {
'code': 404,
fix(git-lfs): fixed security problem with allowing off-chain attacks to replace OID data without validating hash for already present oids....
r1300 'message': 'object: 65f23e22a9bfedda96929b3cfcb8b6d2fdd34a2e877ddb81f45d79ab05710e12 does not exist in store'
}
git-lfs: added vcsserver handling of git-lfs objects....
r180
def test_download_oid(self, oid_handler):
store = oid_handler.get_store()
git-lfs: don't store oid under repo-path....
r181 if not os.path.isdir(os.path.dirname(store.oid_path)):
os.makedirs(os.path.dirname(store.oid_path))
git-lfs: added vcsserver handling of git-lfs objects....
r180
with open(store.oid_path, 'wb') as f:
python3: code change for py3 support...
r1048 f.write(safe_bytes('CONTENT'))
git-lfs: added vcsserver handling of git-lfs objects....
r180
response, has_errors = oid_handler.exec_operation('download')
assert has_errors is None
assert response['download'] == {
'header': {'Authorization': 'basic xxxx'},
'href': 'http://localhost/handle_oid'
}
def test_upload_oid_that_exists(self, oid_handler):
store = oid_handler.get_store()
git-lfs: don't store oid under repo-path....
r181 if not os.path.isdir(os.path.dirname(store.oid_path)):
os.makedirs(os.path.dirname(store.oid_path))
git-lfs: added vcsserver handling of git-lfs objects....
r180
with open(store.oid_path, 'wb') as f:
python3: code change for py3 support...
r1048 f.write(safe_bytes('CONTENT'))
git-lfs: fixed tests for upload, and added new for file verification.
r201 oid_handler.obj_size = 7
git-lfs: added vcsserver handling of git-lfs objects....
r180 response, has_errors = oid_handler.exec_operation('upload')
assert has_errors is None
assert response is None
git-lfs: fixed tests for upload, and added new for file verification.
r201 def test_upload_oid_that_exists_but_has_wrong_size(self, oid_handler):
store = oid_handler.get_store()
if not os.path.isdir(os.path.dirname(store.oid_path)):
os.makedirs(os.path.dirname(store.oid_path))
with open(store.oid_path, 'wb') as f:
python3: code change for py3 support...
r1048 f.write(safe_bytes('CONTENT'))
git-lfs: fixed tests for upload, and added new for file verification.
r201
oid_handler.obj_size = 10240
response, has_errors = oid_handler.exec_operation('upload')
assert has_errors is None
assert response['upload'] == {
'header': {'Authorization': 'basic xxxx',
'Transfer-Encoding': 'chunked'},
'href': 'http://localhost/handle_oid',
}
git-lfs: added vcsserver handling of git-lfs objects....
r180 def test_upload_oid(self, oid_handler):
response, has_errors = oid_handler.exec_operation('upload')
assert has_errors is None
assert response['upload'] == {
git-lfs: fixed tests for upload, and added new for file verification.
r201 'header': {'Authorization': 'basic xxxx',
'Transfer-Encoding': 'chunked'},
git-lfs: added vcsserver handling of git-lfs objects....
r180 'href': 'http://localhost/handle_oid'
}
lint: auto-fixes
r1152 class TestLFSStore:
git-lfs: added vcsserver handling of git-lfs objects....
r180 def test_write_oid(self, lfs_store):
oid_location = lfs_store.oid_path
assert not os.path.isfile(oid_location)
engine = lfs_store.get_engine(mode='wb')
with engine as f:
python3: code change for py3 support...
r1048 f.write(safe_bytes('CONTENT'))
git-lfs: added vcsserver handling of git-lfs objects....
r180
assert os.path.isfile(oid_location)
def test_detect_has_oid(self, lfs_store):
assert lfs_store.has_oid() is False
engine = lfs_store.get_engine(mode='wb')
with engine as f:
python3: code change for py3 support...
r1048 f.write(safe_bytes('CONTENT'))
git-lfs: added vcsserver handling of git-lfs objects....
r180
python3: code change for py3 support...
r1048 assert lfs_store.has_oid() is True