mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
[5.1.x] Fixed #35604, Refs #35326 -- Made FileSystemStorage.exists() behaviour independent from allow_overwrite.
Partially reverts0b33a3abc2. Storage.exists(name) was documented to "return False if the name is available for a new file." but return True if the file exists. This is ambiguous in the overwrite file case. It will now always return whether the file exists. Thank you to Natalia Bidart and Josh Schneier for the review. Backport of8d6a20b656from main.
This commit is contained in:
@@ -80,11 +80,14 @@ class GenerateFilenameStorageTests(SimpleTestCase):
|
||||
("", ""),
|
||||
]
|
||||
s = FileSystemStorage()
|
||||
s_overwrite = FileSystemStorage(allow_overwrite=True)
|
||||
msg = "Could not derive file name from '%s'"
|
||||
for file_name, base_name in candidates:
|
||||
with self.subTest(file_name=file_name):
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg % base_name):
|
||||
s.get_available_name(file_name)
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg % base_name):
|
||||
s_overwrite.get_available_name(file_name)
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg % base_name):
|
||||
s.generate_filename(file_name)
|
||||
|
||||
@@ -98,11 +101,14 @@ class GenerateFilenameStorageTests(SimpleTestCase):
|
||||
("\\tmp\\..\\path", "/tmp/.."),
|
||||
]
|
||||
s = FileSystemStorage()
|
||||
s_overwrite = FileSystemStorage(allow_overwrite=True)
|
||||
for file_name, path in candidates:
|
||||
msg = "Detected path traversal attempt in '%s'" % path
|
||||
with self.subTest(file_name=file_name):
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
s.get_available_name(file_name)
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
s_overwrite.get_available_name(file_name)
|
||||
with self.assertRaisesMessage(SuspiciousFileOperation, msg):
|
||||
s.generate_filename(file_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user