[2.2.x] Refs #32718 -- Fixed file_storage.test_generate_filename and model_fields.test_filefield tests on Python 3.5.
This commit is contained in:
parent
5fe4970bd0
commit
63f0d7a0f6
|
@ -71,7 +71,7 @@ class GenerateFilenameStorageTests(SimpleTestCase):
|
|||
]
|
||||
f = FileField(upload_to='some/folder/')
|
||||
for file_name, msg_file_name in candidates:
|
||||
msg = f"Could not derive file name from '{msg_file_name}'"
|
||||
msg = "Could not derive file name from '%s'" % msg_file_name
|
||||
with self.subTest(file_name=file_name):
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
f.generate_filename(None, file_name)
|
||||
|
@ -89,7 +89,7 @@ class GenerateFilenameStorageTests(SimpleTestCase):
|
|||
'/tmp/../path',
|
||||
]
|
||||
for file_name in candidates:
|
||||
msg = f"Detected path traversal attempt in '{file_name}'"
|
||||
msg = "Detected path traversal attempt in '%s'" % file_name
|
||||
with self.subTest(file_name=file_name):
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
f.generate_filename(None, file_name)
|
||||
|
@ -145,7 +145,7 @@ class GenerateFilenameStorageTests(SimpleTestCase):
|
|||
'$.$.$',
|
||||
]
|
||||
for file_name in candidates:
|
||||
msg = f"Detected path traversal attempt in '/tmp/{file_name}'"
|
||||
msg = "Detected path traversal attempt in '/tmp/%s'" % file_name
|
||||
with self.subTest(file_name=file_name):
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
f.generate_filename(None, file_name)
|
||||
|
@ -157,7 +157,7 @@ class GenerateFilenameStorageTests(SimpleTestCase):
|
|||
f = FileField(upload_to=upload_to)
|
||||
candidates = ['..', '.', '']
|
||||
for file_name in candidates:
|
||||
msg = f"Could not derive file name from '/tmp/{file_name}'"
|
||||
msg = "Could not derive file name from '/tmp/%s'" % file_name
|
||||
with self.subTest(file_name=file_name):
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
f.generate_filename(None, file_name)
|
||||
|
|
|
@ -66,7 +66,7 @@ class FileFieldTests(TestCase):
|
|||
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}'"
|
||||
msg = "Detected path traversal attempt in '%s'" % tmp.name
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
document.save()
|
||||
|
||||
|
|
Loading…
Reference in New Issue