tests: add test for passing user classes and instances

It's well known that unpickling data received from an untrusted source is not
secure. But since children trust the parents and ancestors, unpickling data
received from a parent or ancestor should be supported. Add a test for this use
case.
pull/642/head
Marc Hartmayer 5 years ago committed by Alex Willmer
parent 89c0cc94d1
commit 819582e8ee

@ -42,6 +42,14 @@ class TargetClass:
def add_numbers_with_offset(cls, x, y): def add_numbers_with_offset(cls, x, y):
return cls.offset + x + y return cls.offset + x + y
@classmethod
def passing_crazy_type(cls, crazy_cls):
return crazy_cls.__name__
@classmethod
def passing_crazy_type_instance(cls, crazy):
return crazy.__class__.__name__
class CallFunctionTest(testlib.RouterMixin, testlib.TestCase): class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
@ -58,6 +66,18 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase):
103, 103,
) )
def test_succeeds_passing_class(self):
self.assertEqual(
self.local.call(TargetClass.passing_crazy_type, CrazyType),
'CrazyType'
)
def test_succeeds_passing_class_instance(self):
self.assertEqual(
self.local.call(TargetClass.passing_crazy_type_instance, CrazyType()),
'CrazyType'
)
def test_crashes(self): def test_crashes(self):
exc = self.assertRaises(mitogen.core.CallError, exc = self.assertRaises(mitogen.core.CallError,
lambda: self.local.call(function_that_fails)) lambda: self.local.call(function_that_fails))

Loading…
Cancel
Save