Add tests for user files endpoint and add regex filter

This commit is contained in:
Joseph Schorr 2017-04-21 16:13:18 -04:00
parent 4bb725dce0
commit 5bba018009
2 changed files with 61 additions and 22 deletions

View file

@ -75,7 +75,7 @@ class DelegateUserfiles(object):
def get_file_id_path(self, file_id):
# Note: We use basename here to prevent paths with ..'s and absolute paths.
return os.path.join(self._prefix, os.path.basename(file_id))
return os.path.join(self._prefix or '', os.path.basename(file_id))
def prepare_for_drop(self, mime_type, requires_cors=True):
""" Returns a signed URL to upload a file to our bucket. """
@ -137,20 +137,21 @@ class Userfiles(object):
location = app.config.get('USERFILES_LOCATION')
path = app.config.get('USERFILES_PATH', None)
handler_name = 'userfiles_handlers'
if path is not None:
handler_name = 'userfiles_handlers'
userfiles = DelegateUserfiles(app, distributed_storage, location, path,
handler_name=handler_name)
userfiles = DelegateUserfiles(app, distributed_storage, location, path,
handler_name=handler_name)
app.add_url_rule('/userfiles/<regex("[0-9a-zA-Z-]+"):file_id>',
view_func=UserfilesHandlers.as_view(handler_name,
distributed_storage=distributed_storage,
location=location,
files=userfiles))
app.add_url_rule('/userfiles/<file_id>',
view_func=UserfilesHandlers.as_view(handler_name,
distributed_storage=distributed_storage,
location=location,
files=userfiles))
# register extension with app
app.extensions = getattr(app, 'extensions', {})
app.extensions['userfiles'] = userfiles
# register extension with app
app.extensions = getattr(app, 'extensions', {})
app.extensions['userfiles'] = userfiles
return userfiles
def __getattr__(self, name):