From 5490cd74b48ebdd4d902c2a2acd98ad6418fa99e Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 22 Sep 2025 11:31:24 +0000 Subject: [PATCH] tests: add test for passing user defined classes and instances from parent -> child It's well known that unpickling data received from an untrusted source is not secure. But since children trust their parents and ancestors, unpickling data received from a parent or ancestor should be supported. Add a test for this use case. Signed-off-by: Marc Hartmayer --- tests/call_function_test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/call_function_test.py b/tests/call_function_test.py index 1e838bda..b60108e9 100644 --- a/tests/call_function_test.py +++ b/tests/call_function_test.py @@ -42,6 +42,14 @@ class TargetClass: def add_numbers_with_offset(cls, 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): @@ -58,6 +66,18 @@ class CallFunctionTest(testlib.RouterMixin, testlib.TestCase): 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): exc = self.assertRaises(mitogen.core.CallError, lambda: self.local.call(function_that_fails))