Merge branch 'main' into update_sharing_group

pull/761/head
Raphaël Vinot 2021-06-22 11:26:06 -07:00 committed by GitHub
commit 9db81ed052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 1 deletions

View File

@ -1092,7 +1092,7 @@ class PyMISP:
return to_return
def get_taxonomy(self, taxonomy: Union[MISPTaxonomy, int, str, UUID], pythonify: bool = False) -> Union[Dict, MISPTaxonomy]:
"""Get a taxonomy by id from a MISP instance
"""Get a taxonomy by id or namespace from a MISP instance
:param taxonomy: taxonomy to get
:param pythonify: Returns a PyMISP Object instead of the plain json output
@ -1921,6 +1921,7 @@ class PyMISP:
s.from_dict(**sharing_group_j)
return s
def update_sharing_group(self, sharing_group: Union[MISPSharingGroup, dict], sharing_group_id: Optional[int] = None, pythonify: bool = False) -> Union[Dict, MISPSharingGroup]:
"""Update sharing group parameters
@ -1940,6 +1941,16 @@ class PyMISP:
s.from_dict(**updated_sharing_group)
return s
def sharing_group_exists(self, sharing_group: Union[MISPSharingGroup, int, str, UUID]) -> bool:
"""Fast check if sharing group exists.
:param sharing_group: Sharing group to check
"""
sharing_group_id = get_uuid_or_id_from_abstract_misp(sharing_group)
r = self._prepare_request('HEAD', f'sharing_groups/view/{sharing_group_id}')
return self._check_head_response(r)
def delete_sharing_group(self, sharing_group: Union[MISPSharingGroup, int, str, UUID]) -> Dict:
"""Delete a sharing group
@ -2039,6 +2050,15 @@ class PyMISP:
o.from_dict(**organisation_j)
return o
def organisation_exists(self, organisation: Union[MISPOrganisation, int, str, UUID]) -> bool:
"""Fast check if organisation exists.
:param organisation: Organisation to check
"""
organisation_id = get_uuid_or_id_from_abstract_misp(organisation)
r = self._prepare_request('HEAD', f'organisations/view/{organisation_id}')
return self._check_head_response(r)
def add_organisation(self, organisation: MISPOrganisation, pythonify: bool = False) -> Union[Dict, MISPOrganisation]:
"""Add an organisation

View File

@ -1576,6 +1576,8 @@ class TestComprehensive(unittest.TestCase):
# Get list
taxonomies = self.admin_misp_connector.taxonomies(pythonify=True)
self.assertTrue(isinstance(taxonomies, list))
# Test fetching taxonomy by ID
list_name_test = 'tlp'
for tax in taxonomies:
if tax.namespace == list_name_test:
@ -1583,10 +1585,17 @@ class TestComprehensive(unittest.TestCase):
r = self.admin_misp_connector.get_taxonomy(tax, pythonify=True)
self.assertEqual(r.namespace, list_name_test)
self.assertTrue('enabled' in r)
# Test fetching taxonomy by namespace
r = self.admin_misp_connector.get_taxonomy("tlp", pythonify=True)
self.assertEqual(r.namespace, "tlp")
r = self.admin_misp_connector.enable_taxonomy(tax)
self.assertEqual(r['message'], 'Taxonomy enabled')
r = self.admin_misp_connector.enable_taxonomy_tags(tax)
self.assertEqual(r['name'], 'The tag(s) has been saved.')
r = self.admin_misp_connector.disable_taxonomy(tax)
self.assertEqual(r['message'], 'Taxonomy disabled')
@ -2077,10 +2086,16 @@ class TestComprehensive(unittest.TestCase):
sharing_group = self.admin_misp_connector.add_sharing_group(sg, pythonify=True)
self.assertEqual(sharing_group.name, 'Testcases SG')
self.assertEqual(sharing_group.releasability, 'Testing')
# Change releasability
r = self.admin_misp_connector.update_sharing_group({"releasability": "Testing updated"}, sharing_group)
self.assertEqual(sharing_group.releasability, 'Testing updated')
# Test `sharing_group_exists` method
self.assertTrue(self.admin_misp_connector.sharing_group_exists(sharing_group))
self.assertTrue(self.admin_misp_connector.sharing_group_exists(sharing_group.id))
self.assertTrue(self.admin_misp_connector.sharing_group_exists(sharing_group.uuid))
# add org
r = self.admin_misp_connector.add_org_to_sharing_group(sharing_group,
self.test_org, extend=True)
@ -2129,6 +2144,10 @@ class TestComprehensive(unittest.TestCase):
r = self.admin_misp_connector.delete_sharing_group(sharing_group.id)
self.assertEqual(r['message'], 'SharingGroup deleted')
self.assertFalse(self.admin_misp_connector.sharing_group_exists(sharing_group))
self.assertFalse(self.admin_misp_connector.sharing_group_exists(sharing_group.id))
self.assertFalse(self.admin_misp_connector.sharing_group_exists(sharing_group.uuid))
def test_feeds(self):
# Add
feed = MISPFeed()