Better non-root permission handling (#55)

This commit is contained in:
Chris Caron
2021-10-30 16:58:15 -04:00
committed by GitHub
parent ddb209264b
commit e65b80cb11
8 changed files with 121 additions and 50 deletions

View File

@@ -107,6 +107,19 @@ class AddTests(SimpleTestCase):
)
assert response.status_code == 400
# Test the handling of underlining disk/write exceptions
with patch('os.makedirs') as mock_mkdirs:
mock_mkdirs.side_effect = OSError()
# We'll fail to write our key now
response = self.client.post(
'/add/{}'.format(key),
data=json.dumps({'urls': 'mailto://user:pass@yahoo.ca'}),
content_type='application/json',
)
# internal errors are correctly identified
assert response.status_code == 500
# Test the handling of underlining disk/write exceptions
with patch('gzip.open') as mock_open:
mock_open.side_effect = OSError()

View File

@@ -36,7 +36,7 @@ from django.conf import settings
import logging
# Get an instance of a logger
logger = logging.getLogger(__name__)
logger = logging.getLogger('django')
class AppriseStoreMode(object):
@@ -120,7 +120,13 @@ class AppriseConfigCache(object):
# First two characters are reserved for cache level directory writing.
path, filename = self.path(key)
os.makedirs(path, exist_ok=True)
try:
os.makedirs(path, exist_ok=True)
except OSError:
# Permission error
logger.error('Could not create directory {}'.format(path))
return False
# Write our file to a temporary file
_, tmp_path = tempfile.mkstemp(suffix='.tmp', dir=path)