Skip to content

Commit

Permalink
[IMP] Changed verb of update ioc endpoint (POST /api/v2/iocs/{identif…
Browse files Browse the repository at this point in the history
…ier}) into PUT
  • Loading branch information
c8y3 committed Oct 16, 2024
1 parent 24b8121 commit a60a5f7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion source/app/blueprints/rest/v2/case/api_v2_ioc_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def get_case_ioc(identifier):
return response_api_not_found()


@api_v2_ioc_blueprint.route('/iocs/<int:identifier>', methods=['POST'])
@api_v2_ioc_blueprint.route('/iocs/<int:identifier>', methods=['PUT'])
@ac_api_requires()
def update_ioc(identifier):
ioc_schema = IocSchemaForAPIV2()
Expand Down
3 changes: 3 additions & 0 deletions tests/iris.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions tests/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,25 @@ 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)
response_as_string = self._convert_response_to_string(response)
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):
Expand Down
8 changes: 8 additions & 0 deletions tests/tests_rest_iocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit a60a5f7

Please sign in to comment.