Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,4 @@ figures/*
.vscode/settings.json
trajectories/*
*.tar.gz
casts/*
2 changes: 1 addition & 1 deletion netsecgame/game_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def from_dict(cls, data_dict: Dict[str, Any]) -> Action:
params: Dict[str, Any] = {}
for k, v in data_dict["parameters"].items():
match k:
case "source_host" | "target_host" | "blocked_host":
case "source_host" | "target_host" | "blocked_host" | "blocked_ip":
params[k] = IP.from_dict(v)
case "target_network":
params[k] = Network.from_dict(v)
Expand Down
17 changes: 17 additions & 0 deletions tests/components/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,23 @@ def test_action_to_dict_quit_game(self):
assert action_dict["action_type"] == str(action.type)
assert len(action_dict["parameters"]) == 0

def test_action_to_dict_block_ip(self):
action = Action(
action_type=ActionType.BlockIP,
parameters={
"target_host": IP("192.168.1.0"),
"source_host": IP("192.168.1.1"),
"blocked_ip": IP("1.1.1.1")
}
)
action_dict = action.as_dict
new_action = Action.from_dict(action_dict)
assert action == new_action
assert action_dict["action_type"] == str(action.type)
assert action_dict["parameters"]["target_host"] == {'ip': '192.168.1.0'}
assert action_dict["parameters"]["source_host"] == {'ip': '192.168.1.1'}
assert action_dict["parameters"]["blocked_ip"] == {'ip': '1.1.1.1'}

def test_action_type_eq_unsupported(self):
"""Test ActionType equality with unsupported type"""
assert (ActionType.FindData == 123) is False
Expand Down