From daca32db3631fc0539f071fadfd6721dd2e90f95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 30 Aug 2019 14:19:52 +0200 Subject: [PATCH] fix: Event delegation was incorrect --- pymisp/aping.py | 17 ++--------------- tests/testlive_comprehensive.py | 11 +++++++---- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/pymisp/aping.py b/pymisp/aping.py index ff1c24d..99b14d6 100644 --- a/pymisp/aping.py +++ b/pymisp/aping.py @@ -1779,25 +1779,12 @@ class ExpandedPyMISP(PyMISP): def accept_event_delegation(self, delegation: Union[MISPEventDelegation, int, str], pythonify: bool=False): delegation_id = self.__get_uuid_or_id_from_abstract_misp(delegation) delegation = self._prepare_request('POST', f'event_delegations/acceptDelegation/{delegation_id}') - delegation = self._check_response(delegation, expect_json=True) - if not (self.global_pythonify or pythonify) or 'errors' in delegation: - return delegation - e = MISPEvent() - e.from_dict(**delegation) - return e + return self._check_response(delegation, expect_json=True) def discard_event_delegation(self, delegation: Union[MISPEventDelegation, int, str], pythonify: bool=False): delegation_id = self.__get_uuid_or_id_from_abstract_misp(delegation) delegation = self._prepare_request('POST', f'event_delegations/deleteDelegation/{delegation_id}') - delegation = self._check_response(delegation, expect_json=True) - if self._old_misp((2, 4, 114), '2020-01-01', sys._getframe().f_code.co_name) and isinstance(delegation, list): - # FIXME: https://github.com/MISP/MISP/issues/5056 - delegation = delegation[0] - if not (self.global_pythonify or pythonify) or 'errors' in delegation: - return delegation - e = MISPEvent() - e.from_dict(**delegation) - return e + return self._check_response(delegation, expect_json=True) def delegate_event(self, event: Union[MISPEvent, int, str, UUID]=None, organisation: Union[MISPOrganisation, int, str, UUID]=None, diff --git a/tests/testlive_comprehensive.py b/tests/testlive_comprehensive.py index c460972..c2eb617 100644 --- a/tests/testlive_comprehensive.py +++ b/tests/testlive_comprehensive.py @@ -1884,7 +1884,9 @@ class TestComprehensive(unittest.TestCase): # Test delegation delegations = self.delegate_user_misp_connector.event_delegations() self.assertEqual(delegations[0].id, delegation.id) - e = self.delegate_user_misp_connector.accept_event_delegation(delegation) + r = self.delegate_user_misp_connector.accept_event_delegation(delegation) + self.assertEqual(r['message'], 'Event ownership transferred.') + e = self.delegate_user_misp_connector.get_event(e) self.assertTrue(isinstance(e, MISPEvent), e) self.assertEqual(e.info, 'Test Roles') self.assertEqual(e.org.name, 'Test Org - delegate') @@ -1892,13 +1894,14 @@ class TestComprehensive(unittest.TestCase): self.assertEqual(r['message'], 'Event deleted.', r) e = test_roles_user_connector.add_event(base_event) delegation = test_roles_user_connector.delegate_event(e, self.test_org_delegate) - e = test_roles_user_connector.discard_event_delegation(delegation.id) + r = test_roles_user_connector.discard_event_delegation(delegation.id) + self.assertEqual(r['message'], 'Delegation request deleted.') + + e = test_roles_user_connector.get_event(e) self.assertTrue(isinstance(e, MISPEvent), e) self.assertEqual(e.info, 'Test Roles') self.assertEqual(e.org_id, int(self.test_org.id)) finally: - # time.sleep(200) - # NOTE: When the delegation will work, we need to delete as site admin. self.user_misp_connector.delete_event(e) # Publisher