diff --git a/pymisp/api.py b/pymisp/api.py index 0824050..ef135c6 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -454,14 +454,18 @@ class PyMISP: o.from_dict(**updated_object) return o - def delete_object(self, misp_object: Union[MISPObject, int, str, UUID]) -> Dict: + def delete_object(self, misp_object: Union[MISPObject, int, str, UUID], hard: bool = False) -> Dict: """Delete an object from a MISP instance :param misp_object: object to delete + :param hard: flag for hard delete """ object_id = get_uuid_or_id_from_abstract_misp(misp_object) - response = self._prepare_request('POST', f'objects/delete/{object_id}') - return self._check_json_response(response) + data = {} + if hard: + data['hard'] = 1 + r = self._prepare_request('POST', f'objects/delete/{object_id}', data=data) + return self._check_json_response(r) def add_object_reference(self, misp_object_reference: MISPObjectReference, pythonify: bool = False) -> Union[Dict, MISPObjectReference]: """Add a reference to an object diff --git a/tests/testlive_comprehensive.py b/tests/testlive_comprehensive.py index 11b48ce..8108828 100644 --- a/tests/testlive_comprehensive.py +++ b/tests/testlive_comprehensive.py @@ -1244,7 +1244,14 @@ class TestComprehensive(unittest.TestCase): # Test delete object r = self.user_misp_connector.delete_object(second.objects[0]) - self.assertEqual(r['message'], 'Object deleted') + self.assertEqual(r['message'], 'Object deleted', r) + new_second = self.admin_misp_connector.get_event(second, deleted=[0, 1], pythonify=True) + self.assertEqual(len(new_second.objects), 1) + # Hard delete + response = self.admin_misp_connector.delete_object(second.objects[0], hard=True) + self.assertEqual(response['message'], 'Object deleted') + new_second = self.admin_misp_connector.get_event(second, deleted=[0, 1], pythonify=True) + self.assertEqual(len(new_second.objects), 0) finally: # Delete event self.admin_misp_connector.delete_event(first)