diff options
| author | Derrick Jackson <derrick_jackson@saa.senate.gov> | 2017-05-10 11:29:12 -0400 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2017-05-31 15:02:32 -0400 |
| commit | 7250393f31cf8000833312e381501b4575fdb1f1 (patch) | |
| tree | 5c3d802b1b492b6d5e3ff9ea92188cafeb6aeec8 /tests | |
| parent | 877d7b71ae952b3bc946e5187d6c23039a71614d (diff) | |
[1.11.x] Fixed #28170 -- Fixed file_move_safe() crash when moving files to a CIFS mount.
Backport of 789c290150a0a5e7312e152df281dbcaf4ec174e from master
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/files/tests.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/files/tests.py b/tests/files/tests.py index 72a121fcfe..02d6d43b3c 100644 --- a/tests/files/tests.py +++ b/tests/files/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals +import errno import gzip import os import struct @@ -317,6 +318,31 @@ 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 = OSError(errno.EACCES, 'msg') + copystat_EPERM_error = OSError(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(OSError) as e: + file_move_safe(self.file_a, self.file_b, allow_overwrite=True) + self.assertEqual(e.exception.errno, errno.EACCES) + # 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): |
