From 74cfb46086926b390554f3466a098b9762318751 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Sep 01 2020 09:23:13 +0000 Subject: PR#2382: hub: [multicall] cast args of exception to str Merges #2382 https://pagure.io/koji/pull-request/2382 Fixes: #2381 https://pagure.io/koji/issue/2381 hub: [multicall] raise unexpected error when the Exception contains non-str arg --- diff --git a/hub/kojixmlrpc.py b/hub/kojixmlrpc.py index f9d80cd..8359051 100644 --- a/hub/kojixmlrpc.py +++ b/hub/kojixmlrpc.py @@ -341,7 +341,7 @@ class ModXMLRPCRequestHandler(object): # a circular reference. exc_type, exc_value = sys.exc_info()[:2] faultCode = getattr(exc_type, 'faultCode', 1) - faultString = ', '.join(exc_value.args) + faultString = ', '.join([str(arg) for arg in exc_value.args]) trace = traceback.format_exception(*sys.exc_info()) # traceback is not part of the multicall spec, # but we include it for debugging purposes diff --git a/tests/test_hub/test_multicall.py b/tests/test_hub/test_multicall.py new file mode 100644 index 0000000..34a424d --- /dev/null +++ b/tests/test_hub/test_multicall.py @@ -0,0 +1,40 @@ +import mock +import unittest + +import kojixmlrpc +from kojixmlrpc import Fault, HandlerRegistry, ModXMLRPCRequestHandler + + +class DummyExports(object): + + def foo(self, bar, err=None): + if err: + raise err + return bar + + +class TestMulticall(unittest.TestCase): + + def test_multicall(self): + kojixmlrpc.kojihub = mock.MagicMock() + kojixmlrpc.context.opts = mock.MagicMock() + kojixmlrpc.context.session = mock.MagicMock() + self.registry = HandlerRegistry() + self.exports = DummyExports() + self.registry.register_instance(self.exports) + calls = [{'methodName': 'foo', 'params': [1]}, + {'methodName': 'non', 'params': [mock.ANY]}, + {'methodName': 'foo', 'params': [2, Exception('with int arg', 1)]}, + {'methodName': 'foo', 'params': [3, Fault(2, 'xmlrpc fault')]}] + h = ModXMLRPCRequestHandler(self.registry) + h.check_session = mock.MagicMock() + h.enforce_lockout = mock.MagicMock() + kojixmlrpc.context.event_id = mock.MagicMock() + rv = h.multiCall(calls) + self.assertEqual(rv, [[1], + {'faultCode': 1000, 'faultString': 'Invalid method: non', + 'traceback': mock.ANY}, + {'faultCode': 1, 'faultString': 'with int arg, 1', + 'traceback': mock.ANY}, + {'faultCode': 2, 'faultString': 'xmlrpc fault'}]) + self.assertFalse(hasattr(kojixmlrpc.context, 'event_id'))