Skip to content

Commit 45904f9

Browse files
committed
Add test case with empty context
1 parent bbe8275 commit 45904f9

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

aikido_zen/background_process/cloud_connection_manager/on_detected_attack_test.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,33 @@ def test_on_detected_attack_with_user(mock_connection_manager):
189189

190190
# Verify the user is included in the attack data
191191
assert event["attack"]["user"] == "test_user"
192+
193+
194+
def test_on_detected_attack_no_context_and_attack_data(mock_connection_manager):
195+
attack = {
196+
"payload": {"key": "value"},
197+
"metadata": {"test": "true"},
198+
}
199+
200+
on_detected_attack(
201+
mock_connection_manager,
202+
attack=attack,
203+
context=None,
204+
blocked=False,
205+
stack=None,
206+
)
207+
208+
# Extract the call arguments for the report method
209+
_, event, _ = mock_connection_manager.api.report.call_args[0]
210+
211+
# Verify the request attribute in the payload
212+
request_data = event["request"]
213+
attack_data = event["attack"]
214+
215+
assert request_data is None
216+
assert attack_data["user"] is None
217+
218+
assert attack_data["blocked"] == False
219+
assert attack_data["metadata"] == {"test": "true"}
220+
assert attack_data["payload"] == '{"key": "value"}'
221+
assert attack_data["stack"] is None

0 commit comments

Comments
 (0)