|
|
|
|
@ -5,6 +5,7 @@ from __future__ import print_function
|
|
|
|
|
import os
|
|
|
|
|
import sys
|
|
|
|
|
import time
|
|
|
|
|
from contextlib import contextmanager
|
|
|
|
|
|
|
|
|
|
from nose import SkipTest
|
|
|
|
|
from tornado.web import HTTPError
|
|
|
|
|
@ -164,7 +165,17 @@ class TestContentsManager(TestCase):
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
self._temp_dir.cleanup()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
|
def assertRaisesHTTPError(self, status, msg=None):
|
|
|
|
|
msg = msg or "Should have raised HTTPError(%i)" % status
|
|
|
|
|
try:
|
|
|
|
|
yield
|
|
|
|
|
except HTTPError as e:
|
|
|
|
|
self.assertEqual(e.status_code, status)
|
|
|
|
|
else:
|
|
|
|
|
self.fail(msg)
|
|
|
|
|
|
|
|
|
|
def make_dir(self, api_path):
|
|
|
|
|
"""make a subdirectory at api_path
|
|
|
|
|
|
|
|
|
|
@ -461,4 +472,29 @@ class TestContentsManager(TestCase):
|
|
|
|
|
cm.mark_trusted_cells(nb, path)
|
|
|
|
|
cm.check_and_sign(nb, path)
|
|
|
|
|
assert cm.notary.check_signature(nb)
|
|
|
|
|
|
|
|
|
|
def test_escape_root(self):
|
|
|
|
|
cm = self.contents_manager
|
|
|
|
|
# make foo, bar next to root
|
|
|
|
|
with open(os.path.join(cm.root_dir, '..', 'foo'), 'w') as f:
|
|
|
|
|
f.write('foo')
|
|
|
|
|
with open(os.path.join(cm.root_dir, '..', 'bar'), 'w') as f:
|
|
|
|
|
f.write('bar')
|
|
|
|
|
|
|
|
|
|
with self.assertRaisesHTTPError(404):
|
|
|
|
|
cm.get('..')
|
|
|
|
|
with self.assertRaisesHTTPError(404):
|
|
|
|
|
cm.get('foo/../../../bar')
|
|
|
|
|
with self.assertRaisesHTTPError(404):
|
|
|
|
|
cm.delete('../foo')
|
|
|
|
|
with self.assertRaisesHTTPError(404):
|
|
|
|
|
cm.rename('../foo', '../bar')
|
|
|
|
|
with self.assertRaisesHTTPError(404):
|
|
|
|
|
cm.save(model={
|
|
|
|
|
'type': 'file',
|
|
|
|
|
'content': u'',
|
|
|
|
|
'format': 'text',
|
|
|
|
|
}, path='../foo')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|