Skip to content

Commit

Permalink
fix: Update Sharing group info from full object
Browse files Browse the repository at this point in the history
Fix #1049
  • Loading branch information
Rafiot committed Aug 23, 2023
1 parent 79de851 commit 1597669
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions pymisp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,7 @@ def update_sharing_group(self, sharing_group: Union[MISPSharingGroup, dict], sha
sid = get_uuid_or_id_from_abstract_misp(sharing_group)
else:
sid = get_uuid_or_id_from_abstract_misp(sharing_group_id)
sharing_group.pop('modified', None) # Quick fix for https://github.com/MISP/PyMISP/issues/1049 - remove when fixed in MISP.
r = self._prepare_request('POST', f'sharing_groups/edit/{sid}', data=sharing_group)
updated_sharing_group = self._check_json_response(r)
if not (self.global_pythonify or pythonify) or 'errors' in updated_sharing_group:
Expand Down
16 changes: 10 additions & 6 deletions tests/testlive_comprehensive.py
Original file line number Diff line number Diff line change
Expand Up @@ -2271,10 +2271,14 @@ def test_sharing_groups(self):
self.assertEqual(sharing_group.releasability, 'Testing')

# Change releasability
r = self.admin_misp_connector.update_sharing_group({"releasability": "Testing updated"}, sharing_group, pythonify=True)
self.assertEqual(r.releasability, 'Testing updated')
r = self.admin_misp_connector.update_sharing_group({"releasability": "Testing updated - 2"}, sharing_group)
self.assertEqual(r['SharingGroup']['releasability'], 'Testing updated - 2')
r = self.admin_misp_connector.update_sharing_group({"releasability": "Testing updated"}, sharing_group)
self.assertEqual(r['SharingGroup']['releasability'], 'Testing updated')
r = self.admin_misp_connector.update_sharing_group({"releasability": "Testing updated - 2"}, sharing_group, pythonify=True)
self.assertEqual(r.releasability, 'Testing updated - 2')
# Change name
r.name = 'Testcases SG - new name'
r = self.admin_misp_connector.update_sharing_group(r, pythonify=True)
self.assertEqual(r.name, 'Testcases SG - new name')

# Test `sharing_group_exists` method
self.assertTrue(self.admin_misp_connector.sharing_group_exists(sharing_group))
Expand All @@ -2293,7 +2297,7 @@ def test_sharing_groups(self):
# Get list
sharing_groups = self.admin_misp_connector.sharing_groups(pythonify=True)
self.assertTrue(isinstance(sharing_groups, list))
self.assertEqual(sharing_groups[0].name, 'Testcases SG')
self.assertEqual(sharing_groups[0].name, 'Testcases SG - new name')

# Use the SG

Expand All @@ -2307,7 +2311,7 @@ def test_sharing_groups(self):
try:
first = self.user_misp_connector.add_event(first)
first = self.admin_misp_connector.change_sharing_group_on_entity(first, sharing_group.id, pythonify=True)
self.assertEqual(first.SharingGroup['name'], 'Testcases SG')
self.assertEqual(first.SharingGroup['name'], 'Testcases SG - new name')

first_object = self.admin_misp_connector.change_sharing_group_on_entity(first.objects[0], sharing_group.id, pythonify=True)
self.assertEqual(first_object.sharing_group_id, sharing_group.id)
Expand Down

0 comments on commit 1597669

Please sign in to comment.