summaryrefslogtreecommitdiff
path: root/tests/files/tests.py
diff options
context:
space:
mode:
authorDerrick Jackson <derrick_jackson@saa.senate.gov>2017-05-10 11:29:12 -0400
committerTim Graham <timograham@gmail.com>2017-05-31 14:52:40 -0400
commit789c290150a0a5e7312e152df281dbcaf4ec174e (patch)
tree8c1086d41f6c8761476f4f9a8aa7717ef7e45f4c /tests/files/tests.py
parent2ec56bb78237ebf58494d7a7f3262482399f0be6 (diff)
Fixed #28170 -- Fixed file_move_safe() crash when moving files to a CIFS mount.
Diffstat (limited to 'tests/files/tests.py')
-rw-r--r--tests/files/tests.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/files/tests.py b/tests/files/tests.py
index 1a383090f9..5e165a998f 100644
--- a/tests/files/tests.py
+++ b/tests/files/tests.py
@@ -1,3 +1,4 @@
+import errno
import gzip
import os
import struct
@@ -340,6 +341,30 @@ class FileMoveSafeTests(unittest.TestCase):
os.close(handle_a)
os.close(handle_b)
+ def test_file_move_copystat_cifs(self):
+ """
+ file_move_safe() ignores a copystat() EPERM PermissionError. This
+ happens when the destination filesystem is CIFS, for example.
+ """
+ copystat_EACCES_error = PermissionError(errno.EACCES, 'msg')
+ copystat_EPERM_error = PermissionError(errno.EPERM, 'msg')
+ handle_a, self.file_a = tempfile.mkstemp()
+ handle_b, self.file_b = tempfile.mkstemp()
+ try:
+ # This exception is required to reach the copystat() call in
+ # file_safe_move().
+ with mock.patch('django.core.files.move.os.rename', side_effect=OSError()):
+ # An error besides EPERM isn't ignored.
+ with mock.patch('django.core.files.move.copystat', side_effect=copystat_EACCES_error):
+ with self.assertRaises(PermissionError):
+ file_move_safe(self.file_a, self.file_b, allow_overwrite=True)
+ # EPERM is ignored.
+ with mock.patch('django.core.files.move.copystat', side_effect=copystat_EPERM_error):
+ self.assertIsNone(file_move_safe(self.file_a, self.file_b, allow_overwrite=True))
+ finally:
+ os.close(handle_a)
+ os.close(handle_b)
+
class SpooledTempTests(unittest.TestCase):
def test_in_memory_spooled_temp(self):