mirror of https://github.com/MISP/PyMISP
fix: Automatically skip empty string in add_attribute at object level
Fix #439 Re-enable test cases.pull/471/head
parent
f0c103b73c
commit
cebdc2ef3f
|
@ -1303,8 +1303,8 @@ class MISPObject(AbstractMISP):
|
|||
dictionary with all the keys supported by MISPAttribute"""
|
||||
if simple_value is not None: # /!\ The value *can* be 0
|
||||
value = {'value': simple_value}
|
||||
if value.get('value') is None:
|
||||
# FIXME: Add a warning to the user, silently discarding the call isn't the best idea
|
||||
if value.get('value') in [None, '']:
|
||||
logger.warning("The value of the attribute you're trying to add is None or empty string, skipping it. Object relation: {}".format(object_relation))
|
||||
return None
|
||||
if self._known_template:
|
||||
if self._definition['attributes'].get(object_relation):
|
||||
|
|
|
@ -72,6 +72,10 @@ class TestMISPEvent(unittest.TestCase):
|
|||
|
||||
def test_object_tag(self):
|
||||
self.mispevent.add_object(name='file', strict=True)
|
||||
a = self.mispevent.objects[0].add_attribute('filename', value='')
|
||||
self.assertEqual(a, None)
|
||||
a = self.mispevent.objects[0].add_attribute('filename', value=None)
|
||||
self.assertEqual(a, None)
|
||||
a = self.mispevent.objects[0].add_attribute('filename', value='bar', Tag=[{'name': 'blah'}])
|
||||
del a.uuid
|
||||
self.assertEqual(self.mispevent.objects[0].attributes[0].tags[0].name, 'blah')
|
||||
|
|
|
@ -1529,12 +1529,16 @@ class TestComprehensive(unittest.TestCase):
|
|||
self.admin_misp_connector.delete_event(second)
|
||||
self.admin_misp_connector.delete_event(third)
|
||||
|
||||
@unittest.skip('Need rework.')
|
||||
def test_search_logs(self):
|
||||
# FIXME: https://github.com/MISP/MISP/issues/4872
|
||||
r = self.admin_misp_connector.update_user({'email': 'testusr-changed@user.local'}, self.test_usr)
|
||||
r = self.admin_misp_connector.search_logs(model='User', created=date.today(), pythonify=True)
|
||||
for entry in r[-2:]:
|
||||
self.assertEqual(entry.action, 'add')
|
||||
for entry in r[-1:]:
|
||||
self.assertEqual(entry.action, 'edit')
|
||||
r = self.admin_misp_connector.search_logs(email='admin@admin.test', created=date.today(), pythonify=True)
|
||||
for entry in r[-1:]:
|
||||
self.assertEqual(entry.action, 'edit')
|
||||
r = self.admin_misp_connector.update_user({'email': 'testusr@user.local'}, self.test_usr)
|
||||
|
||||
def test_live_acl(self):
|
||||
missing_acls = self.admin_misp_connector.remote_acl
|
||||
|
|
Loading…
Reference in New Issue