mirror of
https://github.com/caronc/apprise-api.git
synced 2025-08-19 02:45:55 +02:00
Better non-root permission handling (#55)
This commit is contained in:
@@ -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()
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user