Bugfix catch attribute errors and updated dependencies

This commit is contained in:
jfriedli 2022-01-24 19:43:12 +00:00
parent 8689aa3c31
commit 71b00c2098
7 changed files with 491 additions and 816 deletions

View file

@ -86,7 +86,7 @@ def upload_file():
download_uri=url_for('routes.download_file', key=key, secret=secret, filename=output_filename), download_uri=url_for('routes.download_file', key=key, secret=secret, filename=output_filename),
meta_after=meta_after, meta_after=meta_after,
) )
except (RuntimeError, ValueError): except (RuntimeError, ValueError, AttributeError):
flash('The type %s could not be cleaned' % mime) flash('The type %s could not be cleaned' % mime)
max_file_size = int(current_app.config['MAX_CONTENT_LENGTH'] / 1024 / 1024) max_file_size = int(current_app.config['MAX_CONTENT_LENGTH'] / 1024 / 1024)

View file

@ -69,7 +69,7 @@ class APIUpload(Resource):
_external=True _external=True
) )
), 201 ), 201
except ValueError: except (ValueError, AttributeError):
current_app.logger.error('Upload - Invalid mime type') current_app.logger.error('Upload - Invalid mime type')
abort(415, message='The filetype is not supported') abort(415, message='The filetype is not supported')
except RuntimeError: except RuntimeError:
@ -119,7 +119,7 @@ class APIClean(Resource):
raise ValueError() raise ValueError()
parser.remove_all() parser.remove_all()
_, _, _, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER']) _, _, _, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER'])
except ValueError: except (ValueError, AttributeError):
current_app.logger.error('Upload - Invalid mime type') current_app.logger.error('Upload - Invalid mime type')
abort(415, message='The filetype is not supported') abort(415, message='The filetype is not supported')
except RuntimeError: except RuntimeError:

1263
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -22,8 +22,8 @@
"@fullhuman/postcss-purgecss": "^4.0.2", "@fullhuman/postcss-purgecss": "^4.0.2",
"autoprefixer": "^10.2.5", "autoprefixer": "^10.2.5",
"cssnano": "^5.0.0", "cssnano": "^5.0.0",
"postcss": "^8.2.8", "postcss": "^8.4.5",
"postcss-cli": "^9.0.0", "postcss-cli": "^9.0.0",
"tailwindcss": "^2.0.4" "tailwindcss": "^3.0.16"
} }
} }

View file

@ -1,7 +1,7 @@
mutagen==1.45.1 mutagen==1.45.1
ffmpeg==1.4 ffmpeg==1.4
bubblewrap==1.2.0 bubblewrap==1.2.0
mat2==0.12.2 mat2==0.12.3
flask==2.0.1 flask==2.0.1
Flask-RESTful==0.3.9 Flask-RESTful==0.3.9
Flask-Cors==3.0.10 Flask-Cors==3.0.10

View file

@ -58,6 +58,14 @@ class Mat2WebTestCase(TestCase):
), follow_redirects=False) ), follow_redirects=False)
self.assertEqual(rv.status_code, 302) self.assertEqual(rv.status_code, 302)
def test_get_upload_bad_file_type(self):
rv = self.client.post('/',
data=dict(
file=(io.BytesIO(b"1,2,3 \n 4,5,6"), 'test.csv'),
), follow_redirects=False)
self.assertEqual(rv.status_code, 200)
self.assertIn(b'The type text/csv could not be cleaned', rv.data)
def test_get_upload_empty_file_redir(self): def test_get_upload_empty_file_redir(self):
rv = self.client.post('/', rv = self.client.post('/',
data=dict( data=dict(

View file

@ -88,6 +88,18 @@ class Mat2APITestCase(unittest.TestCase):
error = request.get_json()['message'] error = request.get_json()['message']
self.assertEqual(error, 'The filetype is not supported') self.assertEqual(error, 'The filetype is not supported')
def test_api_not_supported_extension(self):
request = self.app.post('/api/upload',
data='{"file_name": "test_name.csv", '
'"file": "MSwyLDMKNCw1LDY="}',
headers={'content-type': 'application/json'}
)
self.assertEqual(request.headers['Content-Type'], 'application/json')
self.assertEqual(request.status_code, 415)
error = request.get_json()['message']
self.assertEqual(error, 'The filetype is not supported')
def test_api_supported_extensions(self): def test_api_supported_extensions(self):
rv = self.app.get('/api/extension') rv = self.app.get('/api/extension')
self.assertEqual(rv.status_code, 200) self.assertEqual(rv.status_code, 200)
@ -478,6 +490,20 @@ class Mat2APITestCase(unittest.TestCase):
self.assertEqual(r.headers['Content-Type'], 'text/plain; charset=utf-8') self.assertEqual(r.headers['Content-Type'], 'text/plain; charset=utf-8')
self.assertEqual(r.data, b'') self.assertEqual(r.data, b'')
def test_remove_metadata_not_supported_extension(self):
r = self.app.post(
'/api/remove_metadata',
data=dict(
file=(io.BytesIO(b"1,2,3 \n 4,5,6"), 'test.csv'),
),
follow_redirects=False
)
self.assertEqual(
r.get_json()['message'],
'The filetype is not supported'
)
self.assertEqual(r.status_code, 415)
def test_remove_metdata_validation(self): def test_remove_metdata_validation(self):
r = self.app.post( r = self.app.post(
'/api/remove_metadata', '/api/remove_metadata',