diff --git a/pymisp/api.py b/pymisp/api.py index a59967b..d40cb04 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1071,7 +1071,7 @@ class PyMISP(object): Returns the version of the instance. """ session = self.__prepare_session() - url = urljoin(self.root_url, 'servers/getVersion') + url = urljoin(self.root_url, 'servers/getVersion.json') response = session.get(url) return self._check_response(response) diff --git a/tests/sharing_groups.json b/tests/sharing_groups.json new file mode 100644 index 0000000..96a3e5f --- /dev/null +++ b/tests/sharing_groups.json @@ -0,0 +1,100 @@ +{ + "response": [ + { + "SharingGroup": { + "id": "1", + "name": "PrivateTrustedGroup", + "description": "", + "releasability": "", + "local": true, + "active": true + }, + "Organisation": { + "id": "1", + "name": "CIRCL", + "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" + }, + "SharingGroupOrg": [ + { + "id": "1", + "sharing_group_id": "1", + "org_id": "1", + "extend": true, + "Organisation": { + "name": "CIRCL", + "id": "1", + "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" + } + }, + { + "id": "2", + "sharing_group_id": "1", + "org_id": "2", + "extend": false, + "Organisation": { + "name": "PifPafPoum", + "id": "2", + "uuid": "56bf12a7-c19c-4b98-83e7-d9bb02de0b81" + } + } + ], + "SharingGroupServer": [ + { + "all_orgs": false, + "server_id": "0", + "sharing_group_id": "1", + "Server": [] + } + ], + "editable": true + }, + { + "SharingGroup": { + "id": "2", + "name": "test", + "description": "", + "releasability": "", + "local": true, + "active": true + }, + "Organisation": { + "id": "1", + "name": "CIRCL", + "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" + }, + "SharingGroupOrg": [ + { + "id": "3", + "sharing_group_id": "2", + "org_id": "1", + "extend": true, + "Organisation": { + "name": "CIRCL", + "id": "1", + "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f" + } + }, + { + "id": "4", + "sharing_group_id": "2", + "org_id": "2", + "extend": false, + "Organisation": { + "name": "PifPafPoum", + "id": "2", + "uuid": "56bf12a7-c19c-4b98-83e7-d9bb02de0b81" + } + } + ], + "SharingGroupServer": [ + { + "all_orgs": false, + "server_id": "0", + "sharing_group_id": "2", + "Server": [] + } + ], + "editable": true + } + ] +} diff --git a/tests/test_offline.py b/tests/test_offline.py index 26e702c..afb4f34 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -5,7 +5,7 @@ import unittest import requests_mock import json -import pymisp +import pymisp as pm from pymisp import PyMISP @@ -18,9 +18,11 @@ class TestOffline(unittest.TestCase): self.key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' self.event = {'Event': json.load(open('tests/misp_event.json', 'r'))} self.types = json.load(open('tests/describeTypes.json', 'r')) + self.sharing_groups = json.load(open('tests/sharing_groups.json', 'r')) def initURI(self, m): - m.register_uri('GET', self.domain + 'servers/getVersion', json={"version": pymisp.__version__[1:]}) + m.register_uri('GET', self.domain + 'servers/getVersion.json', json={"version": "2.4.50"}) + m.register_uri('GET', self.domain + 'sharing_groups/index.json', json=self.sharing_groups) m.register_uri('GET', self.domain + 'attributes/describeTypes.json', json=self.types) m.register_uri('GET', self.domain + 'events/2', json=self.event) m.register_uri('POST', self.domain + 'events/2', json=self.event) @@ -55,7 +57,6 @@ class TestOffline(unittest.TestCase): self.assertEqual(d, {'errors': ['Invalid event'], 'message': 'Invalid event', 'name': 'Invalid event', 'url': '/events/3'}) def test_deleteAttribute(self, m): - # FIXME: https://github.com/MISP/MISP/issues/1449 self.initURI(m) pymisp = PyMISP(self.domain, self.key, debug=True) d = pymisp.delete_attribute(2) @@ -70,3 +71,17 @@ class TestOffline(unittest.TestCase): self.assertEqual(e, pub) e = pymisp.publish(self.event) self.assertEqual(e, {'error': 'Already published'}) + + def test_getVersions(self, m): + self.initURI(m) + pymisp = PyMISP(self.domain, self.key, debug=True) + api_version = pymisp.get_api_version() + self.assertEqual(api_version, {'version': pm.__version__}) + server_version = pymisp.get_version() + self.assertEqual(server_version, {"version": "2.4.50"}) + + def test_getSharingGroups(self, m): + self.initURI(m) + pymisp = PyMISP(self.domain, self.key, debug=True) + sharing_groups = pymisp.get_sharing_groups() + self.assertEqual(sharing_groups, self.sharing_groups['response'][0])