Skip to content

Commit 5f1b788

Browse files
authored
Merge pull request #448 from stratosphereips/ondra-fix-block-action-serialization
Ondra fix block action serialization
2 parents d634424 + 4e7f035 commit 5f1b788

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,4 @@ figures/*
158158
.vscode/settings.json
159159
trajectories/*
160160
*.tar.gz
161+
casts/*

netsecgame/game_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def from_dict(cls, data_dict: Dict[str, Any]) -> Action:
448448
params: Dict[str, Any] = {}
449449
for k, v in data_dict["parameters"].items():
450450
match k:
451-
case "source_host" | "target_host" | "blocked_host":
451+
case "source_host" | "target_host" | "blocked_host" | "blocked_ip":
452452
params[k] = IP.from_dict(v)
453453
case "target_network":
454454
params[k] = Network.from_dict(v)

tests/components/test_action.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,23 @@ def test_action_to_dict_quit_game(self):
450450
assert action_dict["action_type"] == str(action.type)
451451
assert len(action_dict["parameters"]) == 0
452452

453+
def test_action_to_dict_block_ip(self):
454+
action = Action(
455+
action_type=ActionType.BlockIP,
456+
parameters={
457+
"target_host": IP("192.168.1.0"),
458+
"source_host": IP("192.168.1.1"),
459+
"blocked_ip": IP("1.1.1.1")
460+
}
461+
)
462+
action_dict = action.as_dict
463+
new_action = Action.from_dict(action_dict)
464+
assert action == new_action
465+
assert action_dict["action_type"] == str(action.type)
466+
assert action_dict["parameters"]["target_host"] == {'ip': '192.168.1.0'}
467+
assert action_dict["parameters"]["source_host"] == {'ip': '192.168.1.1'}
468+
assert action_dict["parameters"]["blocked_ip"] == {'ip': '1.1.1.1'}
469+
453470
def test_action_type_eq_unsupported(self):
454471
"""Test ActionType equality with unsupported type"""
455472
assert (ActionType.FindData == 123) is False

0 commit comments

Comments
 (0)