kopia lustrzana https://dev.funkwhale.audio/funkwhale/funkwhale
Fix #266: Ensure we do not store bad mimetypes
rodzic
a00a6162c0
commit
5afc3e4637
|
@ -43,9 +43,9 @@ def get_query(query_string, search_fields):
|
|||
|
||||
|
||||
def guess_mimetype(f):
|
||||
b = min(100000, f.size)
|
||||
b = min(1000000, f.size)
|
||||
t = magic.from_buffer(f.read(b), mime=True)
|
||||
if t == 'application/octet-stream':
|
||||
if not t.startswith('audio/'):
|
||||
# failure, we try guessing by extension
|
||||
mt, _ = mimetypes.guess_type(f.path)
|
||||
if mt:
|
||||
|
|
|
@ -15,9 +15,13 @@ def test_guess_mimetype_try_using_extension(factories, mocker):
|
|||
assert utils.guess_mimetype(f.audio_file) == 'audio/mpeg'
|
||||
|
||||
|
||||
def test_guess_mimetype_try_using_extension_if_fail(factories, mocker):
|
||||
@pytest.mark.parametrize('wrong', [
|
||||
'application/octet-stream',
|
||||
'application/x-empty',
|
||||
])
|
||||
def test_guess_mimetype_try_using_extension_if_fail(wrong, factories, mocker):
|
||||
mocker.patch(
|
||||
'magic.from_buffer', return_value='application/octet-stream')
|
||||
'magic.from_buffer', return_value=wrong)
|
||||
f = factories['music.TrackFile'].build(
|
||||
audio_file__filename='test.mp3')
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Ensure we do not store bad mimetypes (such as application/x-empty) (#266)
|
Ładowanie…
Reference in New Issue