mirror of https://github.com/MISP/PyMISP
new: toggle warning list, add test case
parent
f3a28f464d
commit
b636a320df
|
@ -35,6 +35,18 @@ class ExpandedPyMISP(PyMISP):
|
||||||
to_return['OR'] = or_parameters
|
to_return['OR'] = or_parameters
|
||||||
return to_return
|
return to_return
|
||||||
|
|
||||||
|
def toggle_warninglist(self, warninglist_id: int, force_enable: bool=None):
|
||||||
|
'''Toggle (enable/disable) the status of a warninglist by ID.
|
||||||
|
:param warninglist_id: ID of the WarningList
|
||||||
|
:param force_enable: Force the warning list in the enabled state (does nothing is already enabled)
|
||||||
|
'''
|
||||||
|
query = {'id': warninglist_id}
|
||||||
|
if force_enable is not None:
|
||||||
|
query['enabled'] = force_enable
|
||||||
|
url = urljoin(self.root_url, '/warninglists/toggleEnable')
|
||||||
|
response = self._prepare_request('POST', url, json.dumps(query))
|
||||||
|
return self._check_response(response)
|
||||||
|
|
||||||
def make_timestamp(self, value: DateTypes):
|
def make_timestamp(self, value: DateTypes):
|
||||||
if isinstance(value, datetime):
|
if isinstance(value, datetime):
|
||||||
return datetime.timestamp()
|
return datetime.timestamp()
|
||||||
|
|
|
@ -580,6 +580,30 @@ class TestComprehensive(unittest.TestCase):
|
||||||
# events = self.user_misp_connector.search(value='stuff', searchall=True, pythonify=True)
|
# events = self.user_misp_connector.search(value='stuff', searchall=True, pythonify=True)
|
||||||
# self.assertEqual(len(events), 1)
|
# self.assertEqual(len(events), 1)
|
||||||
|
|
||||||
|
# warninglist
|
||||||
|
# FIXME: the warning lists ID aren't deterministic
|
||||||
|
response = self.admin_misp_connector.toggle_warninglist('17', force_enable=True) # enable ipv4 DNS.
|
||||||
|
self.assertDictEqual(response, {'saved': True, 'success': '1 warninglist(s) enabled'})
|
||||||
|
second.add_attribute('ip-src', '9.9.9.9')
|
||||||
|
second = self.user_misp_connector.update_event(second)
|
||||||
|
|
||||||
|
events = self.user_misp_connector.search(eventid=second.id, pythonify=True)
|
||||||
|
self.assertEqual(len(events), 1)
|
||||||
|
self.assertEqual(events[0].id, second.id)
|
||||||
|
self.assertEqual(len(events[0].attributes), 3)
|
||||||
|
|
||||||
|
events = self.user_misp_connector.search(eventid=second.id, enforce_warninglist=False, pythonify=True)
|
||||||
|
self.assertEqual(len(events), 1)
|
||||||
|
self.assertEqual(events[0].id, second.id)
|
||||||
|
self.assertEqual(len(events[0].attributes), 3)
|
||||||
|
|
||||||
|
events = self.user_misp_connector.search(eventid=second.id, enforce_warninglist=True, pythonify=True)
|
||||||
|
self.assertEqual(len(events), 1)
|
||||||
|
self.assertEqual(events[0].id, second.id)
|
||||||
|
self.assertEqual(len(events[0].attributes), 2)
|
||||||
|
response = self.admin_misp_connector.toggle_warninglist('17') # disable ipv4 DNS.
|
||||||
|
self.assertDictEqual(response, {'saved': True, 'success': '1 warninglist(s) disabled'})
|
||||||
|
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
# attachments
|
# attachments
|
||||||
with open('tests/testlive_comprehensive.py', 'rb') as f:
|
with open('tests/testlive_comprehensive.py', 'rb') as f:
|
||||||
|
|
Loading…
Reference in New Issue