Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/scripts_cf14.0/cloudfile_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'cf_sso_group_map': 'provider subject_type namespace external_id group_id',
'cf_dir_acl': 'repo_id path_hash path subject_type provider namespace external_id permission inherit share_mode revision',
'cf_edit_guard': 'repo_id path_hash path guard_id generation owner_uid owner_native_user terminal_type terminal_name checkout_ip proof_digest base_file_id lease_expires_at created_at updated_at',
'cf_file_protection': 'repo_id path_hash path file_id protected_by protected_at',
'cf_file_protection': 'repo_id path_hash path file_id entry_type protected_by protected_at',
'cf_audit_event': 'id repo_id object_type object_id operation operator source before after source_path target_path path_hash commit_id result failure_reason occurred_at',
}
INDEXES = {
Expand Down
47 changes: 46 additions & 1 deletion tests/e2e/full/file_protection_native.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,48 @@ def denied(label,action):
except Exception:pass
assert api.get_repo(repo) is not None
checks.append('C whole repo delete denied')
assert api.post_dir(repo, '/design', 'empty', OWNER) == 0
nested_share = api.create_virtual_repo(repo, '/design/empty', 'shared empty folder', '', OWNER)
assert nested_share
directory = {'repo_id': repo, 'entry_type': 'dir', 'path': '/design',
'expected_object_id': api.get_dir_id_by_path(repo, '/design')}
shared = api.create_virtual_repo(repo, '/design', 'shared design', '', OWNER)
assert shared
assert p._state_change(admin, directory, True, v2=True).status_code == 200
before = api.get_repo(repo).head_cmmt_id
for target, parent in ((repo, '/design'), (shared, '/'), (nested_share, '/')):
target_head = api.get_repo(target).head_cmmt_id
try:
api.post_dir(target, parent, 'blocked', OWNER)
except Exception:
pass
assert api.get_repo(target).head_cmmt_id == target_head
assert not api.get_dir_id_by_path(target, parent.rstrip('/') + '/blocked')
assert api.get_repo(repo).head_cmmt_id == before
for target, parent in ((repo, '/design/empty'), (nested_share, '/')):
token = api.get_scoped_upload_token(target, parent, OWNER, False)
upload = requests.post('http://127.0.0.1:8082/upload-api/' + token,
data={'parent_dir': parent},
files={'file': ('blocked.txt', b'blocked')}, timeout=15)
assert upload.status_code == 423, (upload.status_code, upload.text)
assert not api.get_file_id_by_path(target, parent.rstrip('/') + '/blocked.txt')
assert api.post_dir(repo, '/', 'editable-sibling', OWNER) == 0
view = p.ObjectProtectionStatus()
for target, expected_direct in ((shared, True), (nested_share, False)):
request = SimpleNamespace(user=admin, query_params={'repo_id': target, 'path': '/', 'entry_type': 'dir'})
root_state = view.get(request)
assert root_state.status_code == 200, root_state.data
assert root_state.data['direct'] == expected_direct and root_state.data['protected']
assert not root_state.data['native_repo'] and root_state.data['path'] == '/'
request = SimpleNamespace(user=admin, query_params={'repo_id': shared, 'path': '/original.prt', 'entry_type': 'file'})
state_result = view.get(request)
assert state_result.status_code == 200 and state_result.data['inherited'], state_result.data
assert api.get_file_id_by_path(shared, '/original.prt') == state['file']
assert p._state_change(admin, body, False).status_code == 409
assert p._state_change(admin, directory, False, v2=True).status_code == 200
assert api.post_dir(repo, '/design', 'editable-again', OWNER) == 0
assert p.read_batch(repo, [body['path']]) == {body['path']: state['file']}
checks.append('Directory protects source and existing virtual share, preserves sibling writes and nested file protection')
response=p._state_change(admin,body,False); assert response.status_code==200,response.data
response=requests.post(baseurl+'publish',headers={'Authorization':'Bearer '+old_optimistic,'X-CF-Action':'optimistic','X-CF-Base-ID':state['file'],'X-CF-SHA256':hashlib.sha256(content).hexdigest()},data=content,timeout=15)
assert response.status_code==200,(response.status_code,response.text)
Expand Down Expand Up @@ -166,7 +208,10 @@ def start():
raise RuntimeError('native socket readiness timeout')
start(); subprocess.run([sys.executable,__file__,'init'],check=True)
process.terminate();process.wait(timeout=10)
state=json.loads((ROOT/'state.json').read_text()); (ROOT/'conf/seafile.conf').write_text(config+'protection_repo_ids = '+state['repo']+'\ncheckout_enabled = true\ncheckout_repo_ids = '+state['repo']+'\n')
state=json.loads((ROOT/'state.json').read_text())
with admin.cursor() as cursor:
for feature in ('protection', 'checkout'):
cursor.execute('INSERT INTO cf_repo_feature(repo_id,feature) VALUES (%s,%s)', (state['repo'], feature))
start()
go_process=subprocess.Popen([str(PKG/'seafile/bin/fileserver'),'-F',str(ROOT/'conf'),'-d',str(ROOT/'data'),'-l',str(ROOT/'go.log')],stdout=(ROOT/'go.stderr').open('w'),stderr=subprocess.STDOUT)
import requests
Expand Down
Loading