diff --git a/tests/search_index_result.json b/tests/search_index_result.json new file mode 100644 index 0000000..bef46d0 --- /dev/null +++ b/tests/search_index_result.json @@ -0,0 +1,69 @@ +[ + { + "id": "3", + "org": "", + "date": "2016-12-01", + "info": "Another random Event", + "published": false, + "uuid": "5758ebf5-c898-48e6-9fe9-5665c0a83866", + "attribute_count": "2", + "analysis": "0", + "orgc": "", + "timestamp": "1465681801", + "distribution": "3", + "proposal_email_lock": false, + "locked": false, + "threat_level_id": "1", + "publish_timestamp": "0", + "sharing_group_id": "0", + "org_id": "1", + "orgc_id": "1", + "Org": { + "id": "1", + "name": "ORGNAME" + }, + "Orgc": { + "id": "1", + "name": "ORGNAME" + }, + "EventTag": [ + { + "id": "9760", + "event_id": "6028", + "tag_id": "4", + "Tag": { + "id": "4", + "name": "TLP:GREEN", + "colour": "#33822d", + "exportable": true + } + }, + { + "id": "9801", + "event_id": "3", + "tag_id": "1", + "Tag": { + "id": "1", + "name": "for_intelmq_processing", + "colour": "#00ad1c", + "exportable": true + } + }, + { + "id": "9803", + "event_id": "3", + "tag_id": "6", + "Tag": { + "id": "6", + "name": "ecsirt:malicious-code=\"ransomware\"", + "colour": "#005a5a", + "exportable": true + } + } + ], + "SharingGroup": { + "id": null, + "name": null + } + } +] diff --git a/tests/test_offline.py b/tests/test_offline.py index b4854af..162b641 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -29,6 +29,7 @@ class TestOffline(unittest.TestCase): self.auth_error_msg = {"name": "Authentication failed. Please make sure you pass the API key of an API enabled user along in the Authorization header.", "message": "Authentication failed. Please make sure you pass the API key of an API enabled user along in the Authorization header.", "url": "\/events\/1"} + self.search_index_result = json.load(open('tests/search_index_result.json', 'r')) def initURI(self, m): m.register_uri('GET', self.domain + 'events/1', json=self.auth_error_msg, status_code=403) @@ -40,6 +41,7 @@ class TestOffline(unittest.TestCase): m.register_uri('DELETE', self.domain + 'events/2', json={'message': 'Event deleted.'}) m.register_uri('DELETE', self.domain + 'events/3', json={'errors': ['Invalid event'], 'message': 'Invalid event', 'name': 'Invalid event', 'url': '/events/3'}) m.register_uri('DELETE', self.domain + 'attributes/2', json={'message': 'Attribute deleted.'}) + m.register_uri('GET', self.domain + 'events/index/searchtag:1', json=self.search_index_result) def test_getEvent(self, m): self.initURI(m) @@ -126,5 +128,11 @@ class TestOffline(unittest.TestCase): json.dumps(misp_event, cls=EncodeUpdate) json.dumps(misp_event, cls=EncodeFull) + def test_searchIndexByTag (self, m): + self.initURI(m) + pymisp = PyMISP(self.domain, self.key) + response = pymisp.search_index(tag="1") + self.assertEqual(response['response'],self.search_index_result) + if __name__ == '__main__': unittest.main()