Skip to content

Commit

Permalink
validate file_format in upload_url
Browse files Browse the repository at this point in the history
  • Loading branch information
ozer550 committed Sep 21, 2022
1 parent d3002e8 commit 36a42f4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contentcuration/contentcuration/tests/viewsets/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,22 @@ def test_duration_invalid(self):

self.assertEqual(response.status_code, 400)

def test_invalid_file_format_upload(self):
self.client.force_authenticate(user=self.user)
file = {
"size": 1000,
"checksum": uuid.uuid4().hex,
"name": "le_studio",
"file_format": "ppx",
"preset": format_presets.AUDIO,
"duration": 10.123
}
response = self.client.post(
reverse("file-upload-url"), file, format="json",
)

self.assertEqual(response.status_code, 400)

def test_insufficient_storage(self):
self.file["size"] = 100000000000000

Expand Down
4 changes: 4 additions & 0 deletions contentcuration/contentcuration/viewsets/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.core.exceptions import PermissionDenied
from django.http import HttpResponseBadRequest
from le_utils.constants import file_formats
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
Expand Down Expand Up @@ -164,6 +165,9 @@ def upload_url(self, request):
filepath, checksum_base64, 600, content_length=size
)

if file_format not in dict(file_formats.choices):
return HttpResponseBadRequest("Invalid file_format!")

file = File(
file_size=size,
checksum=checksum,
Expand Down

0 comments on commit 36a42f4

Please sign in to comment.