issue #615: fix up FileService tests for new logic
Can't perform authorization test in the same process so easily any more since it checks is_privileged
This commit is contained in:
parent
588859423a
commit
7d4ae6cec4
|
@ -22,15 +22,26 @@ class FetchTest(testlib.RouterMixin, testlib.TestCase):
|
||||||
return recv, msg
|
return recv, msg
|
||||||
|
|
||||||
def test_unauthorized(self):
|
def test_unauthorized(self):
|
||||||
|
l1 = self.router.local()
|
||||||
|
|
||||||
service = self.klass(self.router)
|
service = self.klass(self.router)
|
||||||
recv, msg = self.replyable_msg()
|
pool = mitogen.service.Pool(
|
||||||
service.fetch(
|
router=self.router,
|
||||||
path='/etc/shadow',
|
services=[service],
|
||||||
sender=None,
|
size=1,
|
||||||
msg=msg,
|
|
||||||
)
|
)
|
||||||
e = self.assertRaises(mitogen.core.CallError,
|
try:
|
||||||
lambda: recv.get().unpickle())
|
e = self.assertRaises(mitogen.core.CallError,
|
||||||
|
lambda: l1.call(
|
||||||
|
mitogen.service.FileService.get,
|
||||||
|
context=self.router.myself(),
|
||||||
|
path='/etc/shadow',
|
||||||
|
out_fp=None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
pool.stop()
|
||||||
|
|
||||||
expect = service.unregistered_msg % ('/etc/shadow',)
|
expect = service.unregistered_msg % ('/etc/shadow',)
|
||||||
self.assertTrue(expect in e.args[0])
|
self.assertTrue(expect in e.args[0])
|
||||||
|
|
||||||
|
@ -85,30 +96,57 @@ class FetchTest(testlib.RouterMixin, testlib.TestCase):
|
||||||
self._validate_response(recv.get().unpickle())
|
self._validate_response(recv.get().unpickle())
|
||||||
|
|
||||||
def test_prefix_authorized_abspath_bad(self):
|
def test_prefix_authorized_abspath_bad(self):
|
||||||
recv = mitogen.core.Receiver(self.router)
|
l1 = self.router.local()
|
||||||
service = self.klass(self.router)
|
|
||||||
service.register_prefix('/etc')
|
|
||||||
recv, msg = self.replyable_msg()
|
|
||||||
service.fetch(
|
|
||||||
path='/etc/foo/bar/../../../passwd',
|
|
||||||
sender=recv.to_sender(),
|
|
||||||
msg=msg,
|
|
||||||
)
|
|
||||||
self.assertEquals(None, recv.get().unpickle())
|
|
||||||
|
|
||||||
def test_prefix_authorized_abspath_bad(self):
|
|
||||||
recv = mitogen.core.Receiver(self.router)
|
|
||||||
service = self.klass(self.router)
|
service = self.klass(self.router)
|
||||||
service.register_prefix('/etc')
|
service.register_prefix('/etc')
|
||||||
recv, msg = self.replyable_msg()
|
|
||||||
service.fetch(
|
pool = mitogen.service.Pool(
|
||||||
path='/etc/../shadow',
|
router=self.router,
|
||||||
sender=recv.to_sender(),
|
services=[service],
|
||||||
msg=msg,
|
size=1,
|
||||||
)
|
)
|
||||||
e = self.assertRaises(mitogen.core.CallError,
|
path = '/etc/foo/bar/../../../passwd'
|
||||||
lambda: recv.get().unpickle())
|
try:
|
||||||
expect = service.unregistered_msg % ('/etc/../shadow',)
|
e = self.assertRaises(mitogen.core.CallError,
|
||||||
|
lambda: l1.call(
|
||||||
|
mitogen.service.FileService.get,
|
||||||
|
context=self.router.myself(),
|
||||||
|
path=path,
|
||||||
|
out_fp=None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
pool.stop()
|
||||||
|
|
||||||
|
expect = service.unregistered_msg % (path,)
|
||||||
|
self.assertTrue(expect in e.args[0])
|
||||||
|
|
||||||
|
def test_prefix_authorized_abspath_good(self):
|
||||||
|
l1 = self.router.local()
|
||||||
|
|
||||||
|
service = self.klass(self.router)
|
||||||
|
service.register_prefix('/etc')
|
||||||
|
path = '/etc/../shadow'
|
||||||
|
|
||||||
|
pool = mitogen.service.Pool(
|
||||||
|
router=self.router,
|
||||||
|
services=[service],
|
||||||
|
size=1,
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
e = self.assertRaises(mitogen.core.CallError,
|
||||||
|
lambda: l1.call(
|
||||||
|
mitogen.service.FileService.get,
|
||||||
|
context=self.router.myself(),
|
||||||
|
path=path,
|
||||||
|
out_fp=None
|
||||||
|
)
|
||||||
|
)
|
||||||
|
finally:
|
||||||
|
pool.stop()
|
||||||
|
|
||||||
|
expect = service.unregistered_msg % (path,)
|
||||||
self.assertTrue(expect in e.args[0])
|
self.assertTrue(expect in e.args[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue