Skip to content

Commit 04f3442

Browse files
author
David Wang
authored
1 parent c115476 commit 04f3442

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/sentry/api/endpoints/organization_monitor_checkin_attachment.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from django.core.files.uploadedfile import UploadedFile
34
from django.http.response import FileResponse
45
from rest_framework.request import Request
56
from rest_framework.response import Response
@@ -50,6 +51,9 @@ def post(self, request: Request, project, monitor, checkin) -> Response:
5051
return Response({"detail": "Check-in already has an attachment"}, status=400)
5152

5253
fileobj = request.data["file"]
54+
if not isinstance(fileobj, UploadedFile):
55+
return Response({"detail": "Please upload a valid file object"}, status=400)
56+
5357
if fileobj.size > MAX_ATTACHMENT_SIZE:
5458
return Response({"detail": "Please keep uploads below 100kb"}, status=400)
5559

tests/sentry/api/endpoints/test_organization_monitor_checkin_attachment.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,3 +165,22 @@ def test_duplicate_upload(self):
165165

166166
assert resp.status_code == 400
167167
assert resp.data["detail"] == "Check-in already has an attachment"
168+
169+
def test_invalid_file_upload(self):
170+
monitor = self._create_monitor()
171+
checkin = MonitorCheckIn.objects.create(
172+
monitor=monitor,
173+
project_id=self.project.id,
174+
date_added=monitor.date_added,
175+
status=CheckInStatus.IN_PROGRESS,
176+
)
177+
178+
path = self._path_func(monitor, checkin)
179+
resp = self.client.post(
180+
path,
181+
{"file": "invalid_file"},
182+
format="multipart",
183+
)
184+
185+
assert resp.status_code == 400
186+
assert resp.data["detail"] == "Please upload a valid file object"

0 commit comments

Comments
 (0)