289
293
class ChrootDecoratorTransportTest(TestCase):
290
294
"""Chroot decoration specific tests."""
296
def test_abspath(self):
297
# The abspath is always relative to the chroot_url.
298
server = ChrootServer(get_transport('memory:///foo/bar/'))
300
transport = get_transport(server.get_url())
301
self.assertEqual(server.get_url(), transport.abspath('/'))
303
subdir_transport = transport.clone('subdir')
304
self.assertEqual(server.get_url(), subdir_transport.abspath('/'))
307
def test_clone(self):
308
server = ChrootServer(get_transport('memory:///foo/bar/'))
310
transport = get_transport(server.get_url())
311
# relpath from root and root path are the same
312
relpath_cloned = transport.clone('foo')
313
abspath_cloned = transport.clone('/foo')
314
self.assertEqual(server, relpath_cloned.server)
315
self.assertEqual(server, abspath_cloned.server)
318
def test_chroot_url_preserves_chroot(self):
319
"""Calling get_transport on a chroot transport's base should produce a
320
transport with exactly the same behaviour as the original chroot
323
This is so that it is not possible to escape a chroot by doing::
324
url = chroot_transport.base
325
parent_url = urlutils.join(url, '..')
326
new_transport = get_transport(parent_url)
328
server = ChrootServer(get_transport('memory:///path/subpath'))
330
transport = get_transport(server.get_url())
331
new_transport = get_transport(transport.base)
332
self.assertEqual(transport.server, new_transport.server)
333
self.assertEqual(transport.base, new_transport.base)
336
def test_urljoin_preserves_chroot(self):
337
"""Using urlutils.join(url, '..') on a chroot URL should not produce a
338
URL that escapes the intended chroot.
340
This is so that it is not possible to escape a chroot by doing::
341
url = chroot_transport.base
342
parent_url = urlutils.join(url, '..')
343
new_transport = get_transport(parent_url)
345
server = ChrootServer(get_transport('memory:///path/'))
347
transport = get_transport(server.get_url())
349
InvalidURLJoin, urlutils.join, transport.base, '..')
353
class ChrootServerTest(TestCase):
292
355
def test_construct(self):
293
from bzrlib.transport import chroot
294
transport = chroot.ChrootTransportDecorator('chroot+memory:///pathA/')
295
self.assertEqual('memory:///pathA/', transport.chroot_url)
297
transport = chroot.ChrootTransportDecorator(
298
'chroot+memory:///path/B', chroot='memory:///path/')
299
self.assertEqual('memory:///path/', transport.chroot_url)
301
def test_append_file(self):
302
transport = get_transport('chroot+memory:///foo/bar')
303
self.assertRaises(PathNotChild, transport.append_file, '/foo', None)
305
def test_append_bytes(self):
306
transport = get_transport('chroot+memory:///foo/bar')
307
self.assertRaises(PathNotChild, transport.append_bytes, '/foo', 'bytes')
309
def test_clone(self):
310
transport = get_transport('chroot+memory:///foo/bar')
311
self.assertRaises(PathNotChild, transport.clone, '/foo')
313
def test_delete(self):
314
transport = get_transport('chroot+memory:///foo/bar')
315
self.assertRaises(PathNotChild, transport.delete, '/foo')
317
def test_delete_tree(self):
318
transport = get_transport('chroot+memory:///foo/bar')
319
self.assertRaises(PathNotChild, transport.delete_tree, '/foo')
322
transport = get_transport('chroot+memory:///foo/bar')
323
self.assertRaises(PathNotChild, transport.get, '/foo')
325
def test_get_bytes(self):
326
transport = get_transport('chroot+memory:///foo/bar')
327
self.assertRaises(PathNotChild, transport.get_bytes, '/foo')
330
transport = get_transport('chroot+memory:///foo/bar')
331
self.assertRaises(PathNotChild, transport.has, '/foo')
333
def test_list_dir(self):
334
transport = get_transport('chroot+memory:///foo/bar')
335
self.assertRaises(PathNotChild, transport.list_dir, '/foo')
337
def test_lock_read(self):
338
transport = get_transport('chroot+memory:///foo/bar')
339
self.assertRaises(PathNotChild, transport.lock_read, '/foo')
341
def test_lock_write(self):
342
transport = get_transport('chroot+memory:///foo/bar')
343
self.assertRaises(PathNotChild, transport.lock_write, '/foo')
345
def test_mkdir(self):
346
transport = get_transport('chroot+memory:///foo/bar')
347
self.assertRaises(PathNotChild, transport.mkdir, '/foo')
349
def test_put_bytes(self):
350
transport = get_transport('chroot+memory:///foo/bar')
351
self.assertRaises(PathNotChild, transport.put_bytes, '/foo', 'bytes')
353
def test_put_file(self):
354
transport = get_transport('chroot+memory:///foo/bar')
355
self.assertRaises(PathNotChild, transport.put_file, '/foo', None)
357
def test_rename(self):
358
transport = get_transport('chroot+memory:///foo/bar')
359
self.assertRaises(PathNotChild, transport.rename, '/aaa', 'bbb')
360
self.assertRaises(PathNotChild, transport.rename, 'ccc', '/d')
362
def test_rmdir(self):
363
transport = get_transport('chroot+memory:///foo/bar')
364
self.assertRaises(PathNotChild, transport.rmdir, '/foo')
367
transport = get_transport('chroot+memory:///foo/bar')
368
self.assertRaises(PathNotChild, transport.stat, '/foo')
356
backing_transport = MemoryTransport()
357
server = ChrootServer(backing_transport)
358
self.assertEqual(backing_transport, server.backing_transport)
360
def test_setUp(self):
361
backing_transport = MemoryTransport()
362
server = ChrootServer(backing_transport)
364
self.assertTrue(server.scheme in _protocol_handlers.keys())
366
def test_tearDown(self):
367
backing_transport = MemoryTransport()
368
server = ChrootServer(backing_transport)
371
self.assertFalse(server.scheme in _protocol_handlers.keys())
373
def test_get_url(self):
374
backing_transport = MemoryTransport()
375
server = ChrootServer(backing_transport)
377
self.assertEqual('chroot-%d:///' % id(server), server.get_url())
371
381
class ReadonlyDecoratorTransportTest(TestCase):