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
def from_dict(self, **kwargs):
if kwargs.get('Attribute'):
kwargs = kwargs.get('Attribute')
if kwargs.get('type') and kwargs.get('category'):
if kwargs['type'] not in self.__category_type_mapping[kwargs['category']]:
if self.__strict:

View File

@ -3,7 +3,7 @@
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
import time
@ -85,6 +85,7 @@ class TestComprehensive(unittest.TestCase):
def test_search_value_attribute(self):
me = self.create_event_org_only()
try:
# Create event
created_event = self.admin_misp_connector.add_event(me)
c_me = MISPEvent()
@ -97,11 +98,13 @@ class TestComprehensive(unittest.TestCase):
# Search as user
response = user_misp_connector.search(controller='attributes', value=me.attributes[0].value)
self.assertEqual(response, [])
finally:
# Delete event
self.admin_misp_connector.delete_event(c_me.id)
def test_search_tag_event(self):
me = self.create_event_with_tags()
try:
# Create event
created_event = self.admin_misp_connector.add_event(me)
c_me = MISPEvent()
@ -114,6 +117,7 @@ class TestComprehensive(unittest.TestCase):
# Search as user
response = user_misp_connector.search(value='tlp:white___test')
self.assertEqual(response, [])
finally:
# Delete event
self.admin_misp_connector.delete_event(c_me.id)
@ -301,6 +305,27 @@ class TestComprehensive(unittest.TestCase):
# Delete event
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")
def test_search_tag_attribute(self):
me = self.create_event_with_tags()