Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't sanitize forward slashes in packfile upload #1077

Closed
wants to merge 1 commit into from
Closed
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 api/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def sanitize_string_to_filename(value):
http://stackoverflow.com/a/7406369
"""

keepcharacters = (' ', '.', '_', '-')
keepcharacters = (' ', '.', '_', '-', '/')
return "".join([c for c in value if c.isalnum() or c in keepcharacters]).rstrip()

def obj_from_map(_map):
Expand Down
35 changes: 34 additions & 1 deletion tests/integration_tests/python/test_uploads.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import copy
import cStringIO
import datetime
import json

import dateutil.parser
import os
import pytest
import tarfile


# TODO switch to upload_file_form in all uid(-match)/label/reaper upload tests
Expand Down Expand Up @@ -1069,7 +1072,7 @@ def test_packfile_upload(data_builder, file_form, as_admin, as_root, api_db):

# upload to packfile
r = as_admin.post('/projects/' + project + '/packfile',
params={'token': token}, files=file_form('one.csv'))
params={'token': token}, files=file_form('a/one.csv'))
assert r.ok

metadata_json = json.dumps({
Expand Down Expand Up @@ -1131,6 +1134,36 @@ def test_packfile_upload(data_builder, file_form, as_admin, as_root, api_db):
acquisition = api_db.acquisitions.find_one({'label':'test-packfile-timestamp', 'timestamp':{'$type':'date'}})
assert acquisition.get('label') == 'test-packfile-timestamp'

# Download packfile to unzip and check that file has forward slash

r = as_admin.post('/download', json={
'optional': False,
'nodes': [
{'level': 'acquisition', '_id': str(acquisition.get('_id'))},
]
})
assert r.ok
ticket = r.json()['ticket']

# Perform the download
r = as_admin.get('/download', params={'ticket': ticket})
assert r.ok

tar_file = cStringIO.StringIO(r.content)
tar = tarfile.open(mode="r", fileobj=tar_file)

# Verify a single file in tar with correct file name
for tarinfo in tar:

tar_packfile = cStringIO.StringIO(r.content)
tar_pack = tarfile.open(mode="r", fileobj=tar_file)

for pack_info in tar_pack:
assert os.path.basename(tarinfo.name) == 'a/one.csv'
tar_pack.close()

tar.close()


# Test that acquisition timestamp is used to differenciate acquisitions and session code for sessions

Expand Down