mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-06 11:35:24 +08:00
Merge pull request #7852 from minrk/open-perm
Catch IOError in addition to OSError. Closes #7848
This commit is contained in:
commit
50c8c5feed
@ -61,7 +61,7 @@ class FileManagerMixin(object):
|
||||
"""context manager for turning permission errors into 403."""
|
||||
try:
|
||||
yield
|
||||
except OSError as e:
|
||||
except (OSError, IOError) as e:
|
||||
if e.errno in {errno.EPERM, errno.EACCES}:
|
||||
# make 403 error message without root prefix
|
||||
# this may not work perfectly on unicode paths on Python 2,
|
||||
|
@ -5,6 +5,7 @@ from __future__ import print_function
|
||||
import os
|
||||
import time
|
||||
|
||||
from nose import SkipTest
|
||||
from tornado.web import HTTPError
|
||||
from unittest import TestCase
|
||||
from tempfile import NamedTemporaryFile
|
||||
@ -129,6 +130,25 @@ class TestFileContentsManager(TestCase):
|
||||
[symlink_model, file_model],
|
||||
)
|
||||
|
||||
def test_403(self):
|
||||
if hasattr(os, 'getuid'):
|
||||
if os.getuid() == 0:
|
||||
raise SkipTest("Can't test permissions as root")
|
||||
|
||||
with TemporaryDirectory() as td:
|
||||
cm = FileContentsManager(root_dir=td)
|
||||
model = cm.new_untitled(type='file')
|
||||
os_path = cm._get_os_path(model['path'])
|
||||
|
||||
os.chmod(os_path, 0o400)
|
||||
try:
|
||||
with cm.open(os_path, 'w') as f:
|
||||
f.write(u"don't care")
|
||||
except HTTPError as e:
|
||||
self.assertEqual(e.status_code, 403)
|
||||
else:
|
||||
self.fail("Should have raised HTTPError(403)")
|
||||
|
||||
|
||||
class TestContentsManager(TestCase):
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user