From 7bf60055762ca430bb3a338591bdb9626c61a12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 30 Aug 2019 11:45:56 +0200 Subject: [PATCH] new: [Community] Request access --- pymisp/aping.py | 22 ++++++++++++++++++---- tests/testlive_comprehensive.py | 10 ++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/pymisp/aping.py b/pymisp/aping.py index b9c446b..ff1c24d 100644 --- a/pymisp/aping.py +++ b/pymisp/aping.py @@ -1740,10 +1740,24 @@ class ExpandedPyMISP(PyMISP): c.from_dict(**community) return c - def request_community_access(self, community: Union[MISPCommunity, int, str, UUID], sync: bool=False, - requestor_org_description: str='', requestor_email_user: str='', - message: str='', anonymise: bool=False): - pass + def request_community_access(self, community: Union[MISPCommunity, int, str, UUID], + requestor_email_address: str=None, + requestor_gpg_key: str=None, + requestor_organisation_name: str=None, + requestor_organisation_uuid: str=None, + requestor_organisation_description: str=None, + message: str=None, sync: bool=False, + anonymise_requestor_server: bool=False, + mock: bool=False): + community_id = self.__get_uuid_or_id_from_abstract_misp(community) + to_post = {'org_name': requestor_organisation_name, + 'org_uuid': requestor_organisation_uuid, + 'org_description': requestor_organisation_description, + 'email': requestor_email_address, 'gpgkey': requestor_gpg_key, + 'message': message, 'anonymise': anonymise_requestor_server, 'sync': sync, + 'mock': mock} + r = self._prepare_request('POST', f'communities/requestAccess/{community_id}', data=to_post) + return self._check_response(r, expect_json=True) # ## END Communities ### diff --git a/tests/testlive_comprehensive.py b/tests/testlive_comprehensive.py index 333bf97..e0205c6 100644 --- a/tests/testlive_comprehensive.py +++ b/tests/testlive_comprehensive.py @@ -17,6 +17,8 @@ import urllib3 import time from uuid import uuid4 +import email + import logging logging.disable(logging.CRITICAL) @@ -1924,11 +1926,19 @@ class TestComprehensive(unittest.TestCase): # Delete event self.admin_misp_connector.delete_event(first) + @unittest.skipIf(sys.version_info < (3, 6), 'Not supported on python < 3.6') def test_communities(self): communities = self.admin_misp_connector.communities(pythonify=True) self.assertEqual(communities[0].name, 'CIRCL Private Sector Information Sharing Community - aka MISPPRIV') community = self.admin_misp_connector.get_community(communities[1], pythonify=True) self.assertEqual(community.name, 'CIRCL n/g CSIRT information sharing community - aka MISP') + r = self.admin_misp_connector.request_community_access(community, mock=False) + self.assertTrue(r['message'], 'Request sent.') + r = self.admin_misp_connector.request_community_access(community, mock=True) + mail = email.message_from_string(r['headers'] + '\n' + r['message']) + for k, v in mail.items(): + if k == 'To': + self.assertEqual(v, 'info@circl.lu') def test_upload_stix(self): # FIXME https://github.com/MISP/MISP/issues/4892