summaryrefslogtreecommitdiff
path: root/tests/model_fields
diff options
context:
space:
mode:
Diffstat (limited to 'tests/model_fields')
-rw-r--r--tests/model_fields/test_filefield.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/model_fields/test_filefield.py b/tests/model_fields/test_filefield.py
index 51e29f6d25..fb9426e2d1 100644
--- a/tests/model_fields/test_filefield.py
+++ b/tests/model_fields/test_filefield.py
@@ -5,6 +5,7 @@ import tempfile
import unittest
from pathlib import Path
+from django.core.exceptions import SuspiciousFileOperation
from django.core.files import File, temp
from django.core.files.base import ContentFile
from django.core.files.uploadedfile import TemporaryUploadedFile
@@ -63,6 +64,15 @@ class FileFieldTests(TestCase):
d.refresh_from_db()
self.assertIs(d.myfile.instance, d)
+ @unittest.skipIf(sys.platform == 'win32', "Crashes with OSError on Windows.")
+ def test_save_without_name(self):
+ with tempfile.NamedTemporaryFile(suffix='.txt') as tmp:
+ document = Document.objects.create(myfile='something.txt')
+ document.myfile = File(tmp)
+ msg = f"Detected path traversal attempt in '{tmp.name}'"
+ with self.assertRaisesMessage(SuspiciousFileOperation, msg):
+ document.save()
+
def test_defer(self):
Document.objects.create(myfile='something.txt')
self.assertEqual(Document.objects.defer('myfile')[0].myfile, 'something.txt')