catch no bulk post body

This commit is contained in:
Jan Friedli 2020-07-14 22:49:24 +02:00
parent 5d1e6b3235
commit 2ba8d74fa7
No known key found for this signature in database
GPG key ID: F945FA2FCA30549D
2 changed files with 10 additions and 0 deletions

View file

@ -106,6 +106,8 @@ class APIBulkDownloadCreator(Resource):
def post(self): def post(self):
utils.check_upload_folder(current_app.config['UPLOAD_FOLDER']) utils.check_upload_folder(current_app.config['UPLOAD_FOLDER'])
data = request.json data = request.json
if not data:
abort(400, message="Post Body Required")
if not self.v.validate(data): if not self.v.validate(data):
abort(400, message=self.v.errors) abort(400, message=self.v.errors)
# prevent the zip file from being overwritten # prevent the zip file from being overwritten

View file

@ -263,6 +263,14 @@ class Mat2APITestCase(unittest.TestCase):
request = self.app.get(upload_two['download_link']) request = self.app.get(upload_two['download_link'])
self.assertEqual(request.status_code, 404) self.assertEqual(request.status_code, 404)
def test_api_bulk_empty_body(self):
request = self.app.post(
'/api/download/bulk',
)
self.assertEqual(400, request.status_code)
error_message = request.get_json()['message']
self.assertEqual("Post Body Required", error_message)
def test_api_bulk_download_validation(self): def test_api_bulk_download_validation(self):
post_body = { post_body = {
u'download_list': [ u'download_list': [