summaryrefslogtreecommitdiff
path: root/tests/cache
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2020-08-21 12:43:45 +0200
committerCarlton Gibson <carlton.gibson@noumenal.es>2020-09-01 09:17:23 +0200
commit1853724acaf17ed7414d54c7d2b5563a25025a71 (patch)
tree66587ddd9c23bc7b0f2ea10897aa57d3519cd015 /tests/cache
parent8d7271578d7b153435b40fe40236ebec43cbf1b9 (diff)
downloaddjango-1853724acaf17ed7414d54c7d2b5563a25025a71.tar.gz
Fixed CVE-2020-24584 -- Fixed permission escalation in intermediate-level directories of the file system cache on Python 3.7+.
Diffstat (limited to 'tests/cache')
-rw-r--r--tests/cache/tests.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index c26183f5b2..d5532fa1e6 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -6,12 +6,13 @@ import os
import pickle
import re
import shutil
+import sys
import tempfile
import threading
import time
import unittest
from pathlib import Path
-from unittest import mock
+from unittest import mock, skipIf
from django.conf import settings
from django.core import management, signals
@@ -1494,6 +1495,28 @@ class FileBasedCacheTests(BaseCacheTests, TestCase):
# Returns the default instead of erroring.
self.assertEqual(cache.get('foo', 'baz'), 'baz')
+ @skipIf(
+ sys.platform == 'win32',
+ 'Windows only partially supports umasks and chmod.',
+ )
+ def test_cache_dir_permissions(self):
+ os.rmdir(self.dirname)
+ dir_path = Path(self.dirname) / 'nested' / 'filebasedcache'
+ for cache_params in settings.CACHES.values():
+ cache_params['LOCATION'] = dir_path
+ setting_changed.send(self.__class__, setting='CACHES', enter=False)
+ cache.set('foo', 'bar')
+ self.assertIs(dir_path.exists(), True)
+ tests = [
+ dir_path,
+ dir_path.parent,
+ dir_path.parent.parent,
+ ]
+ for directory in tests:
+ with self.subTest(directory=directory):
+ dir_mode = directory.stat().st_mode & 0o777
+ self.assertEqual(dir_mode, 0o700)
+
def test_get_does_not_ignore_non_filenotfound_exceptions(self):
with mock.patch('builtins.open', side_effect=OSError):
with self.assertRaises(OSError):