summaryrefslogtreecommitdiffstats
path: root/opnfv_testapi/resources
diff options
context:
space:
mode:
authorStamatis Katsaounis <mokats@intracom-telecom.com>2018-08-24 16:57:38 +0300
committerStamatis Katsaounis <mokats@intracom-telecom.com>2018-08-24 16:57:38 +0300
commit701c05ab78d6ca7df03d729351c52483d26f7784 (patch)
treec93a74ec2a81f88a0d220a291a8c48aa5453f0f5 /opnfv_testapi/resources
parente2e5f5e2c53c03630b3128796bd7db7809bd93bd (diff)
Resolve internal errors 500
* Check that a user uploaded a file and return appropriate error if not * Check that a file is a valid gzip file and return appropriate error if not Change-Id: I17dd1ee459d06687156b7fd36f27353325a0b737 Signed-off-by: Stamatis Katsaounis <mokats@intracom-telecom.com>
Diffstat (limited to 'opnfv_testapi/resources')
-rw-r--r--opnfv_testapi/resources/result_handlers.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/opnfv_testapi/resources/result_handlers.py b/opnfv_testapi/resources/result_handlers.py
index 1f6ec73..b7b5c2b 100644
--- a/opnfv_testapi/resources/result_handlers.py
+++ b/opnfv_testapi/resources/result_handlers.py
@@ -245,9 +245,19 @@ class ResultsUploadHandler(ResultsCLHandler):
@raise 404: pod/project/testcase not exist
@raise 400: body/pod_name/project_name/case_name not provided
"""
- fileinfo = self.request.files['file'][0]
- tar_in = tarfile.open(fileobj=io.BytesIO(fileinfo['body']),
- mode="r:gz")
+ file_array = self.request.files.get('file', None)
+ if file_array is None:
+ msg = 'Please upload a file.'
+ self.finish_request({'code': 403, 'msg': msg})
+ return
+ fileinfo = file_array[0]
+ try:
+ tar_in = tarfile.open(fileobj=io.BytesIO(fileinfo['body']),
+ mode="r:gz")
+ except tarfile.ReadError:
+ msg = 'Please upload a valid gzip file.'
+ self.finish_request({'code': 403, 'msg': msg})
+ return
try:
results = tar_in.extractfile('results/results.json').read()
except KeyError: