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
pull/618/head
David Wilson 5 years ago
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 = 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/foo/bar/../../../passwd', router=self.router,
sender=recv.to_sender(), services=[service],
msg=msg, size=1,
) )
self.assertEquals(None, recv.get().unpickle()) path = '/etc/foo/bar/../../../passwd'
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])
def test_prefix_authorized_abspath_good(self):
l1 = self.router.local()
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() path = '/etc/../shadow'
service.fetch(
path='/etc/../shadow', pool = mitogen.service.Pool(
sender=recv.to_sender(), router=self.router,
msg=msg, services=[service],
size=1,
) )
e = self.assertRaises(mitogen.core.CallError, try:
lambda: recv.get().unpickle()) e = self.assertRaises(mitogen.core.CallError,
expect = service.unregistered_msg % ('/etc/../shadow',) 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…
Cancel
Save