Skip to content

Commit

Permalink
Merge pull request #1226 from SEKOIA-IO/fix/synchronize-asset-putreq
Browse files Browse the repository at this point in the history
fix put json req
  • Loading branch information
rombernier authored Dec 11, 2024
2 parents 1bfaaa4 + 311f150 commit a25e193
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Sekoia.io/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## 2024-12-11 - 2.65.11
## 2024-12-10 - 2.65.12

### Changed

Expand Down
2 changes: 1 addition & 1 deletion Sekoia.io/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"name": "Sekoia.io",
"uuid": "92d8bb47-7c51-445d-81de-ae04edbb6f0a",
"slug": "sekoia.io",
"version": "2.65.11",
"version": "2.65.12",
"categories": [
"Generic"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ def get_assets(search_query: str, also_search_in_detection_properties: bool = Fa

def post_request(endpoint: str, json_data: str) -> Dict[str, Any]:
api_path = urljoin(base_url + "/", endpoint)
response = session.post(api_path, json=json_data)
response = session.post(api_path, data=json_data)
if not response.ok:
self.error(f"HTTP POST request failed: {api_path} with status code {response.status_code}")
return response.json()

def put_request(endpoint: str, json_data: str) -> None:
api_path = urljoin(base_url + "/", endpoint)
response = session.put(api_path, json=json_data)
response = session.put(api_path, data=json_data)
# print(f"\nresponse.status_code: {response.status_code}")
if not response.ok:
self.error(f"HTTP PUT request failed: {api_path} with status code {response.status_code}")

Expand Down
29 changes: 25 additions & 4 deletions Sekoia.io/tests/operation_center_action/test_synchronize_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def match_detection_properties(request):
"atoms": {"email": ["[email protected]"], "department": ["engineering"]},
"community_uuid": "community-1234",
}
assert post_request.json() == json.dumps(expected_post_payload), "POST request payload mismatch."
assert post_request.json() == expected_post_payload, "POST request payload mismatch."

def test_on_asset_found_and_merge(self, requests_mock, action_instance, arguments):
def test_one_asset_found_and_merge(self, requests_mock, action_instance, arguments):
"""
Test the SynchronizeAssetsWithAD action for the scenario where multiple assets are found,
and one of them is edited while merging the others.
Expand Down Expand Up @@ -244,7 +244,7 @@ def match_detection_properties(request):
"props": {"dept": "engineering"},
"atoms": {"email": ["[email protected]"], "department": ["engineering"]},
}
assert put_request.json() == json.dumps(expected_put_payload), "PUT request payload mismatch."
assert put_request.json() == expected_put_payload, "PUT request payload mismatch."

def test_multiple_assets_found_and_merge(self, requests_mock, action_instance, arguments):
"""
Expand Down Expand Up @@ -351,7 +351,7 @@ def match_detection_properties(request):
"props": {"dept": "engineering"},
"atoms": {"email": ["[email protected]"], "department": ["engineering"]},
}
assert put_request.json() == json.dumps(expected_put_payload), "PUT request payload mismatch."
assert put_request.json() == expected_put_payload, "PUT request payload mismatch."

# Verify POST merge request payload
post_merge_requests = [
Expand All @@ -368,3 +368,24 @@ def match_detection_properties(request):

# Assert 'sources' list contains the same elements, regardless of order
assert set(post_merge["sources"]) == set(expected_merge_payload["sources"]), "Sources mismatch."

# def test_one_asset_found_and_merge_testapp(self):
# # Extract configuration from the mock module
# base_url = "https://app.test.sekoia.io"
# api_key = "TO_ADD"

# app_test_arg = Arguments( # TO COMPLETE
# user_ad_data={},
# asset_synchronization_configuration={},
# community_uuid="",
# )

# configuration = {
# "base_url": base_url,
# "api_key": api_key,
# }
# module = MockModule(configuration=configuration)
# action = SynchronizeAssetsWithAD()
# action.module = module
# # Execute the action
# response = action.run(app_test_arg)

0 comments on commit a25e193

Please sign in to comment.