new: [test] Attribute modification

pull/265/head
Raphaël Vinot 2018-08-17 15:09:17 +02:00
parent 75b15af427
commit 2c03fb96c2
2 changed files with 56 additions and 29 deletions

View File

@ -163,6 +163,8 @@ class MISPAttribute(AbstractMISP):
return misp_shadow_attribute return misp_shadow_attribute
def from_dict(self, **kwargs): def from_dict(self, **kwargs):
if kwargs.get('Attribute'):
kwargs = kwargs.get('Attribute')
if kwargs.get('type') and kwargs.get('category'): if kwargs.get('type') and kwargs.get('category'):
if kwargs['type'] not in self.__category_type_mapping[kwargs['category']]: if kwargs['type'] not in self.__category_type_mapping[kwargs['category']]:
if self.__strict: if self.__strict:

View File

@ -3,7 +3,7 @@
import unittest import unittest
from pymisp import ExpandedPyMISP, MISPEvent, MISPOrganisation, MISPUser, Distribution, ThreatLevel, Analysis from pymisp import ExpandedPyMISP, MISPEvent, MISPOrganisation, MISPUser, Distribution, ThreatLevel, Analysis, MISPAttribute
from datetime import datetime, timedelta from datetime import datetime, timedelta
import time import time
@ -85,37 +85,41 @@ class TestComprehensive(unittest.TestCase):
def test_search_value_attribute(self): def test_search_value_attribute(self):
me = self.create_event_org_only() me = self.create_event_org_only()
# Create event try:
created_event = self.admin_misp_connector.add_event(me) # Create event
c_me = MISPEvent() created_event = self.admin_misp_connector.add_event(me)
c_me.load(created_event) c_me = MISPEvent()
# Search as admin c_me.load(created_event)
response = self.admin_misp_connector.search(controller='attributes', value=me.attributes[0].value) # Search as admin
self.assertEqual(len(response), 1) response = self.admin_misp_connector.search(controller='attributes', value=me.attributes[0].value)
# Connect as user self.assertEqual(len(response), 1)
user_misp_connector = ExpandedPyMISP(url, self.test_usr.authkey) # Connect as user
# Search as user user_misp_connector = ExpandedPyMISP(url, self.test_usr.authkey)
response = user_misp_connector.search(controller='attributes', value=me.attributes[0].value) # Search as user
self.assertEqual(response, []) response = user_misp_connector.search(controller='attributes', value=me.attributes[0].value)
# Delete event self.assertEqual(response, [])
self.admin_misp_connector.delete_event(c_me.id) finally:
# Delete event
self.admin_misp_connector.delete_event(c_me.id)
def test_search_tag_event(self): def test_search_tag_event(self):
me = self.create_event_with_tags() me = self.create_event_with_tags()
# Create event try:
created_event = self.admin_misp_connector.add_event(me) # Create event
c_me = MISPEvent() created_event = self.admin_misp_connector.add_event(me)
c_me.load(created_event) c_me = MISPEvent()
# Search as admin c_me.load(created_event)
response = self.admin_misp_connector.search(tags='tlp:white___test') # Search as admin
self.assertEqual(len(response), 1) response = self.admin_misp_connector.search(tags='tlp:white___test')
# Connect as user self.assertEqual(len(response), 1)
user_misp_connector = ExpandedPyMISP(url, self.test_usr.authkey) # Connect as user
# Search as user user_misp_connector = ExpandedPyMISP(url, self.test_usr.authkey)
response = user_misp_connector.search(value='tlp:white___test') # Search as user
self.assertEqual(response, []) response = user_misp_connector.search(value='tlp:white___test')
# Delete event self.assertEqual(response, [])
self.admin_misp_connector.delete_event(c_me.id) finally:
# Delete event
self.admin_misp_connector.delete_event(c_me.id)
@unittest.skip("currently failing") @unittest.skip("currently failing")
def test_search_tag_event_fancy(self): def test_search_tag_event_fancy(self):
@ -301,6 +305,27 @@ class TestComprehensive(unittest.TestCase):
# Delete event # Delete event
self.admin_misp_connector.delete_event(first_to_delete.id) self.admin_misp_connector.delete_event(first_to_delete.id)
def test_edit_attribute(self):
first = self.create_event_org_only()
user_misp_connector = ExpandedPyMISP(url, self.test_usr.authkey, debug=False)
try:
first.attributes[0].comment = 'This is the original comment'
first_created_event = user_misp_connector.add_event(first)
first_to_delete = MISPEvent()
first_to_delete.load(first_created_event)
first_to_delete.attributes[0].comment = 'This is the modified comment'
response = user_misp_connector.update_attribute(first_to_delete.attributes[0].id, first_to_delete.attributes[0])
tmp_attr = MISPAttribute()
tmp_attr.from_dict(**response)
self.assertEqual(tmp_attr.comment, 'This is the modified comment')
response = user_misp_connector.change_comment(first_to_delete.attributes[0].uuid, 'This is the modified comment, again')
tmp_attr = MISPAttribute()
tmp_attr.from_dict(**response)
self.assertEqual(tmp_attr.comment, 'This is the modified comment, again')
finally:
# Delete event
self.admin_misp_connector.delete_event(first_to_delete.id)
@unittest.skip("currently failing") @unittest.skip("currently failing")
def test_search_tag_attribute(self): def test_search_tag_attribute(self):
me = self.create_event_with_tags() me = self.create_event_with_tags()