diff --git a/pymisp/api.py b/pymisp/api.py index b511937..8fc1bc4 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1940,6 +1940,15 @@ 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 diff --git a/tests/testlive_comprehensive.py b/tests/testlive_comprehensive.py index a102a79..839a79c 100644 --- a/tests/testlive_comprehensive.py +++ b/tests/testlive_comprehensive.py @@ -2081,6 +2081,10 @@ class TestComprehensive(unittest.TestCase): 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 +2133,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()