fix: Update Sharing group info from full object

Fix #1049
pull/1050/head
Raphaël Vinot 2023-08-23 10:52:52 +02:00
parent 79de851be8
commit 1597669ea6
2 changed files with 11 additions and 6 deletions

View File

@ -2046,6 +2046,7 @@ class PyMISP:
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:

View File

@ -2271,10 +2271,14 @@ class TestComprehensive(unittest.TestCase):
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))
@ -2293,7 +2297,7 @@ class TestComprehensive(unittest.TestCase):
# 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
@ -2307,7 +2311,7 @@ class TestComprehensive(unittest.TestCase):
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)