diff --git a/source/app/blueprints/rest/v2/case/api_v2_ioc_routes.py b/source/app/blueprints/rest/v2/case/api_v2_ioc_routes.py index a1064ae3f..9b62ac9ed 100644 --- a/source/app/blueprints/rest/v2/case/api_v2_ioc_routes.py +++ b/source/app/blueprints/rest/v2/case/api_v2_ioc_routes.py @@ -139,7 +139,7 @@ def get_case_ioc(identifier): return response_api_not_found() -@api_v2_ioc_blueprint.route('/iocs/', methods=['POST']) +@api_v2_ioc_blueprint.route('/iocs/', methods=['PUT']) @ac_api_requires() def update_ioc(identifier): ioc_schema = IocSchemaForAPIV2() diff --git a/tests/iris.py b/tests/iris.py index c0982f5d1..909be3303 100644 --- a/tests/iris.py +++ b/tests/iris.py @@ -45,6 +45,9 @@ def create(self, path, body, query_parameters=None): def get(self, path, query_parameters=None): return self._api.get(path, query_parameters=query_parameters) + def update(self, path, body): + return self._api.put(path, body) + def delete(self, path): return self._api.delete(path) diff --git a/tests/rest_api.py b/tests/rest_api.py index d8c9f875f..e338d8fdb 100644 --- a/tests/rest_api.py +++ b/tests/rest_api.py @@ -38,6 +38,13 @@ def _convert_response_to_string(response): except JSONDecodeError: return f'{response.status_code}' + def post(self, path, payload, query_parameters=None): + url = self._build_url(path) + response = requests.post(url, headers=self._headers, params=query_parameters, json=payload) + response_as_string = self._convert_response_to_string(response) + print(f'POST {url} {payload} => {response_as_string}') + return response + def get(self, path, query_parameters=None): url = self._build_url(path) response = requests.get(url, headers=self._headers, params=query_parameters) @@ -45,11 +52,11 @@ def get(self, path, query_parameters=None): print(f'GET {url} => {response_as_string}') return response - def post(self, path, payload, query_parameters=None): + def put(self, path, payload): url = self._build_url(path) - response = requests.post(url, headers=self._headers, params=query_parameters, json=payload) + response = requests.put(url, headers=self._headers, json=payload) response_as_string = self._convert_response_to_string(response) - print(f'POST {url} {payload} => {response_as_string}') + print(f'PUT {url} {payload} => {response_as_string}') return response def delete(self, path, query_parameters=None): diff --git a/tests/tests_rest_iocs.py b/tests/tests_rest_iocs.py index 36a0c2bc3..ad4f8dedd 100644 --- a/tests/tests_rest_iocs.py +++ b/tests/tests_rest_iocs.py @@ -156,3 +156,11 @@ def test_create_ioc_should_not_create_two_iocs_with_identical_type_and_value(sel self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body) response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body) self.assertEqual(400, response.status_code) + + def test_update_ioc_should_not_fail(self): + case_identifier = self._subject.create_dummy_case() + body = {'ioc_type_id': 1, 'ioc_tlp_id': 2, 'ioc_value': '8.8.8.8', 'ioc_description': 'rewrw', 'ioc_tags': ''} + response = self._subject.create(f'/api/v2/cases/{case_identifier}/iocs', body).json() + ioc_identifier = response['ioc_id'] + response = self._subject.update(f'/api/v2/iocs/{ioc_identifier}', {'ioc_value': '9.9.9.9'}) + self.assertEqual(200, response.status_code)