diff --git a/.gitignore b/.gitignore index ec0973af..0d5350f9 100755 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ figures/* .vscode/settings.json trajectories/* *.tar.gz +casts/* diff --git a/netsecgame/game_components.py b/netsecgame/game_components.py index 4b3d3ec1..2dd9eddd 100755 --- a/netsecgame/game_components.py +++ b/netsecgame/game_components.py @@ -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) diff --git a/tests/components/test_action.py b/tests/components/test_action.py index 5fa036b0..d2169c4d 100644 --- a/tests/components/test_action.py +++ b/tests/components/test_action.py @@ -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