From e91d4a7d2d62f22b1ceb7f08d8af18c282b7c8db Mon Sep 17 00:00:00 2001 From: hrifflet Date: Fri, 8 Mar 2019 11:33:33 +0000 Subject: [PATCH 1/3] Add new function PyMISP.change_disablecorrelation(attribute_uuid,disable_correlation) to be able to enable/disable correlation on attributes. --- pymisp/api.py | 7 +++++++ tests/test_offline.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/pymisp/api.py b/pymisp/api.py index 2ae60fa..9d4355f 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1032,6 +1032,13 @@ class PyMISP(object): query = {"comment": comment} return self.__query('edit/{}'.format(attribute_uuid), query, controller='attributes') + def change_disablecorrelation(self, attribute_uuid, disable_correlation): + """Change the disable_correlation flag""" + if disable_correlation not in [0, 1]: + raise Exception('disable_correlation can only be 0 or 1') + query = {"disable_correlation": disable_correlation} + return self.__query('edit/{}'.format(attribute_uuid), query, controller='attributes') + # ############################## # ###### Attribute update ###### # ############################## diff --git a/tests/test_offline.py b/tests/test_offline.py index 2a5178f..03b9c09 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -409,6 +409,20 @@ class TestOffline(unittest.TestCase): except Exception: pass + def test_change_disablecorrelation(self, m): + self.initURI(m) + pymisp = PyMISP(self.domain, self.key) + self.assertEqual({}, pymisp.change_disable_correlation(self.key, 1)) + + def test_change_disablecorrelation_invalid(self, m): + self.initURI(m) + pymisp = PyMISP(self.domain, self.key) + try: + pymisp.change_disablecorrelation(self.key, 42) + self.assertFalse('Exception required for off domain value') + except Exception: + pass + def test_proposal_view_default(self, m): self.initURI(m) pymisp = PyMISP(self.domain, self.key) From 2edc6eedcaf3091256c4a1567d1229bcaec1d045 Mon Sep 17 00:00:00 2001 From: l3m0ntr33 Date: Fri, 8 Mar 2019 16:04:09 +0100 Subject: [PATCH 2/3] Fix a type on function name. --- tests/test_offline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_offline.py b/tests/test_offline.py index 03b9c09..80fb211 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -412,7 +412,7 @@ class TestOffline(unittest.TestCase): def test_change_disablecorrelation(self, m): self.initURI(m) pymisp = PyMISP(self.domain, self.key) - self.assertEqual({}, pymisp.change_disable_correlation(self.key, 1)) + self.assertEqual({}, pymisp.change_disablecorrelation(self.key, 1)) def test_change_disablecorrelation_invalid(self, m): self.initURI(m) From ec6439ce34936eedc5898c850431b2af6190acc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 11 Mar 2019 11:32:54 +0100 Subject: [PATCH 3/3] fix: Slight changes in new .change_disable_correlation method --- pymisp/api.py | 7 ++++--- tests/test_offline.py | 14 -------------- tests/testlive_comprehensive.py | 4 ++++ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index 9ce2f67..92004d9 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -1032,10 +1032,11 @@ class PyMISP(object): query = {"comment": comment} return self.__query('edit/{}'.format(attribute_uuid), query, controller='attributes') - def change_disablecorrelation(self, attribute_uuid, disable_correlation): + def change_disable_correlation(self, attribute_uuid, disable_correlation): """Change the disable_correlation flag""" - if disable_correlation not in [0, 1]: - raise Exception('disable_correlation can only be 0 or 1') + possible_values = [0, 1, False, True] + if disable_correlation not in possible_values: + raise Exception('disable_correlation can only be in {}'.format(', '.join(possible_values))) query = {"disable_correlation": disable_correlation} return self.__query('edit/{}'.format(attribute_uuid), query, controller='attributes') diff --git a/tests/test_offline.py b/tests/test_offline.py index 80fb211..2a5178f 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -409,20 +409,6 @@ class TestOffline(unittest.TestCase): except Exception: pass - def test_change_disablecorrelation(self, m): - self.initURI(m) - pymisp = PyMISP(self.domain, self.key) - self.assertEqual({}, pymisp.change_disablecorrelation(self.key, 1)) - - def test_change_disablecorrelation_invalid(self, m): - self.initURI(m) - pymisp = PyMISP(self.domain, self.key) - try: - pymisp.change_disablecorrelation(self.key, 42) - self.assertFalse('Exception required for off domain value') - except Exception: - pass - def test_proposal_view_default(self, m): self.initURI(m) pymisp = PyMISP(self.domain, self.key) diff --git a/tests/testlive_comprehensive.py b/tests/testlive_comprehensive.py index cec8b52..9ec2ca8 100644 --- a/tests/testlive_comprehensive.py +++ b/tests/testlive_comprehensive.py @@ -703,6 +703,10 @@ class TestComprehensive(unittest.TestCase): self.assertEqual(attribute.comment, 'This is the modified comment') attribute = self.user_misp_connector.change_comment(first.attributes[0].uuid, 'This is the modified comment, again') self.assertEqual(attribute['Attribute']['comment'], 'This is the modified comment, again') + attribute = self.user_misp_connector.change_disable_correlation(first.attributes[0].uuid, True) + self.assertEqual(attribute['Attribute']['disable_correlation'], True) + attribute = self.user_misp_connector.change_disable_correlation(first.attributes[0].uuid, 0) + self.assertEqual(attribute['Attribute']['disable_correlation'], False) finally: # Delete event self.admin_misp_connector.delete_event(first.id)