summaryrefslogtreecommitdiff
path: root/tests/file_storage
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2021-06-02 01:03:52 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2021-06-02 12:20:22 +0200
commitec2727efef605437eb572d51ca9afbb3a60eda40 (patch)
tree85dc0a1a2b837f76c8a815db720ca022af153f0f /tests/file_storage
parentd9cee3f5f2f90938d2c2c0230be40c7d50aef53d (diff)
downloaddjango-ec2727efef605437eb572d51ca9afbb3a60eda40.tar.gz
Fixed #28154 -- Prevented infinite loop in FileSystemStorage.save() when a broken symlink with the same name exists.
Diffstat (limited to 'tests/file_storage')
-rw-r--r--tests/file_storage/tests.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py
index 381bc6b7b5..8b69617752 100644
--- a/tests/file_storage/tests.py
+++ b/tests/file_storage/tests.py
@@ -28,6 +28,7 @@ from django.test import (
from django.test.utils import requires_tz_support
from django.urls import NoReverseMatch, reverse_lazy
from django.utils import timezone
+from django.utils._os import symlinks_supported
from .models import (
Storage, callable_storage, temp_storage, temp_storage_location,
@@ -297,6 +298,16 @@ class FileStorageTests(SimpleTestCase):
self.storage.delete('path/to/test.file')
+ @unittest.skipUnless(symlinks_supported(), 'Must be able to symlink to run this test.')
+ def test_file_save_broken_symlink(self):
+ """A new path is created on save when a broken symlink is supplied."""
+ nonexistent_file_path = os.path.join(self.temp_dir, 'nonexistent.txt')
+ broken_symlink_path = os.path.join(self.temp_dir, 'symlink.txt')
+ os.symlink(nonexistent_file_path, broken_symlink_path)
+ f = ContentFile('some content')
+ f_name = self.storage.save(broken_symlink_path, f)
+ self.assertIs(os.path.exists(os.path.join(self.temp_dir, f_name)), True)
+
def test_save_doesnt_close(self):
with TemporaryUploadedFile('test', 'text/plain', 1, 'utf8') as file:
file.write(b'1')