mirror of https://github.com/MISP/PyMISP
chg: Allow response of delete to be pythonify, add in nosetest
parent
c949c09225
commit
a8169a42c0
|
@ -486,7 +486,7 @@ class PyMISP:
|
||||||
er.from_dict(**updated_event_report)
|
er.from_dict(**updated_event_report)
|
||||||
return er
|
return er
|
||||||
|
|
||||||
def delete_event_report(self, event_report: Union[MISPEventReport, int, str, UUID], hard: bool = False) -> Dict:
|
def delete_event_report(self, event_report: Union[MISPEventReport, int, str, UUID], hard: bool = False, pythonify: bool = False) -> Dict:
|
||||||
"""Delete an event report from a MISP instance
|
"""Delete an event report from a MISP instance
|
||||||
|
|
||||||
:param event_report: event report to delete
|
:param event_report: event report to delete
|
||||||
|
@ -498,7 +498,12 @@ class PyMISP:
|
||||||
request_url += "/1"
|
request_url += "/1"
|
||||||
r = self._prepare_request('POST', request_url)
|
r = self._prepare_request('POST', request_url)
|
||||||
response = self._check_json_response(r)
|
response = self._check_json_response(r)
|
||||||
|
if not (self.global_pythonify or pythonify) or 'errors' in response or hard:
|
||||||
|
# Hard will permanently delete, must return JSON
|
||||||
return response
|
return response
|
||||||
|
er = MISPEventReport()
|
||||||
|
er.from_dict(**response)
|
||||||
|
return er
|
||||||
|
|
||||||
# ## END Event Report ###
|
# ## END Event Report ###
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ logger = logging.getLogger('pymisp')
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from pymisp import register_user, PyMISP, MISPEvent, MISPOrganisation, MISPUser, Distribution, ThreatLevel, Analysis, MISPObject, MISPAttribute, MISPSighting, MISPShadowAttribute, MISPTag, MISPSharingGroup, MISPFeed, MISPServer, MISPUserSetting, MISPEventBlocklist
|
from pymisp import register_user, PyMISP, MISPEvent, MISPOrganisation, MISPUser, Distribution, ThreatLevel, Analysis, MISPObject, MISPAttribute, MISPSighting, MISPShadowAttribute, MISPTag, MISPSharingGroup, MISPFeed, MISPServer, MISPUserSetting, MISPEventBlocklist, MISPEventReport
|
||||||
from pymisp.tools import CSVLoader, DomainIPObject, ASNObject, GenericObjectGenerator
|
from pymisp.tools import CSVLoader, DomainIPObject, ASNObject, GenericObjectGenerator
|
||||||
from pymisp.exceptions import MISPServerError
|
from pymisp.exceptions import MISPServerError
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -2652,6 +2652,44 @@ class TestComprehensive(unittest.TestCase):
|
||||||
for blo in to_delete['bl_organisations']:
|
for blo in to_delete['bl_organisations']:
|
||||||
self.admin_misp_connector.delete_organisation_blocklist(blo)
|
self.admin_misp_connector.delete_organisation_blocklist(blo)
|
||||||
|
|
||||||
|
def test_event_report(self):
|
||||||
|
event = self.create_simple_event()
|
||||||
|
new_event_report = MISPEventReport()
|
||||||
|
new_event_report.name = "Test Event Report"
|
||||||
|
new_event_report.content = "# Example report markdown"
|
||||||
|
new_event_report.distribution = 5 # Inherit
|
||||||
|
try:
|
||||||
|
event = self.user_misp_connector.add_event(event)
|
||||||
|
new_event_report = self.user_misp_connector.add_event_report(event.id, new_event_report)
|
||||||
|
# The event report should be linked by Event ID
|
||||||
|
self.assertEqual(event.id, new_event_report.event_id)
|
||||||
|
|
||||||
|
event = self.user_misp_connector.get_event(event)
|
||||||
|
# The Event Report should be present on the event
|
||||||
|
self.assertEqual(new_event_report.id, event.event_reports[0].id)
|
||||||
|
|
||||||
|
new_event_report.name = "Updated Event Report"
|
||||||
|
new_event_report.content = "Updated content"
|
||||||
|
new_event_report = self.user_misp_connector.update_event_report(new_event_report)
|
||||||
|
# The event report should be updatable
|
||||||
|
self.assertTrue(new_event_report.name == "Updated Event Report")
|
||||||
|
self.assertTrue(new_event_report.content == "Updated content")
|
||||||
|
|
||||||
|
event_reports = self.user_misp_connector.get_event_reports(event.id)
|
||||||
|
# The event report should be requestable by the Event ID
|
||||||
|
self.assertEqual(new_event_report.id, event_reports[0].id)
|
||||||
|
|
||||||
|
new_event_report = self.user_misp_connector.delete_event_report(new_event_report)
|
||||||
|
# The event report should be soft-deletable
|
||||||
|
self.assertTrue(new_event_report.deleted)
|
||||||
|
|
||||||
|
response = self.user_misp_connector.delete_event_report(new_event_report, True)
|
||||||
|
self.assertTrue(response['success'])
|
||||||
|
finally:
|
||||||
|
self.user_misp_connector.delete_event(event)
|
||||||
|
self.user_misp_connector.delete_event_report(new_event_report)
|
||||||
|
|
||||||
|
|
||||||
@unittest.skip("Internal use only")
|
@unittest.skip("Internal use only")
|
||||||
def missing_methods(self):
|
def missing_methods(self):
|
||||||
skip = [
|
skip = [
|
||||||
|
|
Loading…
Reference in New Issue