From 680696df245b791d2c6e751c9a73a59624eceb78 Mon Sep 17 00:00:00 2001 From: Kim Hammar Date: Mon, 25 Mar 2024 14:14:52 +0100 Subject: [PATCH] add environment tests --- .flake8 | 2 +- .../envs/050/level_1/test_config.py | 34 +++++++++ .../envs/050/level_10/test_config.py | 34 +++++++++ .../envs/050/level_11/test_config.py | 34 +++++++++ .../envs/050/level_12/test_config.py | 34 +++++++++ .../envs/050/level_13/test_config.py | 34 +++++++++ .../envs/050/level_2/test_config.py | 34 +++++++++ .../envs/050/level_3/test_config.py | 34 +++++++++ .../envs/050/level_4/test_config.py | 34 +++++++++ .../envs/050/level_5/test_config.py | 34 +++++++++ .../envs/050/level_6/test_config.py | 34 +++++++++ .../envs/050/level_7/test_config.py | 34 +++++++++ .../envs/050/level_8/test_config.py | 34 +++++++++ .../envs/050/level_9/test_config.py | 34 +++++++++ .../envs/apt_game/test_config.py | 29 +++++++ .../envs/apt_mdp_attacker/test_config.py | 29 +++++++ .../envs/apt_pomdp_defender/test_config.py | 29 +++++++ simulation-system/envs/cyborg/test_config.py | 29 +++++++ .../test_config.py | 31 ++++++++ .../test_config.py | 32 ++++++++ .../test_config.py | 32 ++++++++ .../test_config.py | 32 ++++++++ .../envs/stopping_game/test_config.py | 75 +++++++++++++++++++ .../envs/stopping_mdp_attacker/test_config.py | 75 +++++++++++++++++++ .../stopping_pomdp_defender/test_config.py | 75 +++++++++++++++++++ .../test_config.py | 44 +++++++++++ .../test_config.py | 44 +++++++++++ .../libs/csle-cli/src/csle_cli/cli.py | 1 + unit_tests.sh | 28 +++++++ 29 files changed, 1028 insertions(+), 1 deletion(-) create mode 100644 emulation-system/envs/050/level_1/test_config.py create mode 100644 emulation-system/envs/050/level_10/test_config.py create mode 100644 emulation-system/envs/050/level_11/test_config.py create mode 100644 emulation-system/envs/050/level_12/test_config.py create mode 100644 emulation-system/envs/050/level_13/test_config.py create mode 100644 emulation-system/envs/050/level_2/test_config.py create mode 100644 emulation-system/envs/050/level_3/test_config.py create mode 100644 emulation-system/envs/050/level_4/test_config.py create mode 100644 emulation-system/envs/050/level_5/test_config.py create mode 100644 emulation-system/envs/050/level_6/test_config.py create mode 100644 emulation-system/envs/050/level_7/test_config.py create mode 100644 emulation-system/envs/050/level_8/test_config.py create mode 100644 emulation-system/envs/050/level_9/test_config.py create mode 100644 simulation-system/envs/apt_game/test_config.py create mode 100644 simulation-system/envs/apt_mdp_attacker/test_config.py create mode 100644 simulation-system/envs/apt_pomdp_defender/test_config.py create mode 100644 simulation-system/envs/cyborg/test_config.py create mode 100644 simulation-system/envs/intrusion_recovery_pomdp_defender/test_config.py create mode 100644 simulation-system/envs/intrusion_response_cmdp_defender/test_config.py create mode 100644 simulation-system/envs/local_intrusion_response_pomdp_attacker/test_config.py create mode 100644 simulation-system/envs/local_intrusion_response_pomdp_defender/test_config.py create mode 100644 simulation-system/envs/stopping_game/test_config.py create mode 100644 simulation-system/envs/stopping_mdp_attacker/test_config.py create mode 100644 simulation-system/envs/stopping_pomdp_defender/test_config.py create mode 100644 simulation-system/envs/workflow_intrusion_response_pomdp_attacker/test_config.py create mode 100644 simulation-system/envs/workflow_intrusion_response_pomdp_defender/test_config.py diff --git a/.flake8 b/.flake8 index 4832e4ff0..158e86b18 100644 --- a/.flake8 +++ b/.flake8 @@ -5,4 +5,4 @@ ignore = E741, W503, W504, F821, W605 rst-roles = class, func, ref rst-directives = envvar, exception rst-substitutions = version -extend-ignore = D401, D400, D100, RST305, RST219, D205, D202, D200, D204, RST206, W293, D403, D402, RST306, E261, E731 \ No newline at end of file +extend-ignore = D401, D400, D100, RST305, RST219, D205, D202, D200, D204, RST206, W293, D403, D402, RST306, E261, E731, E402 \ No newline at end of file diff --git a/emulation-system/envs/050/level_1/test_config.py b/emulation-system/envs/050/level_1/test_config.py new file mode 100644 index 000000000..4934c7675 --- /dev/null +++ b/emulation-system/envs/050/level_1/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-1' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level1-050", network_id=1, level=1, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_10/test_config.py b/emulation-system/envs/050/level_10/test_config.py new file mode 100644 index 000000000..f1a5dad3c --- /dev/null +++ b/emulation-system/envs/050/level_10/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-10' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level10-050", network_id=10, level=10, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_11/test_config.py b/emulation-system/envs/050/level_11/test_config.py new file mode 100644 index 000000000..d5bb7cddb --- /dev/null +++ b/emulation-system/envs/050/level_11/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-11' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level11-050", network_id=11, level=11, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_12/test_config.py b/emulation-system/envs/050/level_12/test_config.py new file mode 100644 index 000000000..2998fd4e7 --- /dev/null +++ b/emulation-system/envs/050/level_12/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-12' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level12-050", network_id=12, level=12, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_13/test_config.py b/emulation-system/envs/050/level_13/test_config.py new file mode 100644 index 000000000..8aa0e34c2 --- /dev/null +++ b/emulation-system/envs/050/level_13/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-13' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level13-050", network_id=13, level=13, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_2/test_config.py b/emulation-system/envs/050/level_2/test_config.py new file mode 100644 index 000000000..a8b7aa859 --- /dev/null +++ b/emulation-system/envs/050/level_2/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-2' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level2-050", network_id=2, level=2, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_3/test_config.py b/emulation-system/envs/050/level_3/test_config.py new file mode 100644 index 000000000..1785c8bf9 --- /dev/null +++ b/emulation-system/envs/050/level_3/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-3' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level3-050", network_id=3, level=3, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_4/test_config.py b/emulation-system/envs/050/level_4/test_config.py new file mode 100644 index 000000000..028be8262 --- /dev/null +++ b/emulation-system/envs/050/level_4/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-4' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level4-050", network_id=4, level=4, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_5/test_config.py b/emulation-system/envs/050/level_5/test_config.py new file mode 100644 index 000000000..32c7cc0fd --- /dev/null +++ b/emulation-system/envs/050/level_5/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-5' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level5-050", network_id=5, level=5, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_6/test_config.py b/emulation-system/envs/050/level_6/test_config.py new file mode 100644 index 000000000..e49eb9b4e --- /dev/null +++ b/emulation-system/envs/050/level_6/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-6' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level6-050", network_id=6, level=6, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_7/test_config.py b/emulation-system/envs/050/level_7/test_config.py new file mode 100644 index 000000000..0dff02b25 --- /dev/null +++ b/emulation-system/envs/050/level_7/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-7' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level7-050", network_id=7, level=7, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_8/test_config.py b/emulation-system/envs/050/level_8/test_config.py new file mode 100644 index 000000000..ba104d657 --- /dev/null +++ b/emulation-system/envs/050/level_8/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-8' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level8-050", network_id=8, level=8, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/emulation-system/envs/050/level_9/test_config.py b/emulation-system/envs/050/level_9/test_config.py new file mode 100644 index 000000000..6fd47e4e8 --- /dev/null +++ b/emulation-system/envs/050/level_9/test_config.py @@ -0,0 +1,34 @@ +from config import default_config + + +class TestEmulationConfigSuite: + """ + Test suite for the emulation configuration for 'level-9' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the emulation configuration + + :return: None + """ + config = default_config(name="csle-level9-050", network_id=9, level=9, version="0.5.0", + time_step_len_seconds=15) + assert config.vuln_config is not None + assert config.containers_config is not None + assert config.flags_config is not None + assert config.resources_config is not None + assert config.topology_config is not None + assert config.traffic_config is not None + assert config.users_config is not None + assert config.vuln_config is not None + assert config.kafka_config is not None + assert config.services_config is not None + assert config.static_attacker_sequences is not None + assert config.ovs_config is not None + assert config.host_manager_config is not None + assert config.snort_ids_manager_config is not None + assert config.ossec_ids_manager_config is not None + assert config.docker_stats_manager_config is not None + assert config.elk_config is not None + assert config.beats_config is not None diff --git a/simulation-system/envs/apt_game/test_config.py b/simulation-system/envs/apt_game/test_config.py new file mode 100644 index 000000000..65c418959 --- /dev/null +++ b/simulation-system/envs/apt_game/test_config.py @@ -0,0 +1,29 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'apt_game' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config(name="csle-apt-game-001", version="0.0.1", N=5, p_a=0.1, num_observations=10) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/apt_mdp_attacker/test_config.py b/simulation-system/envs/apt_mdp_attacker/test_config.py new file mode 100644 index 000000000..eb033a87a --- /dev/null +++ b/simulation-system/envs/apt_mdp_attacker/test_config.py @@ -0,0 +1,29 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'apt_mdp_attacker' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config(name="csle-apt-mdp-attacker-001", version="0.0.1", N=5, p_a=0.1, num_observations=10) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/apt_pomdp_defender/test_config.py b/simulation-system/envs/apt_pomdp_defender/test_config.py new file mode 100644 index 000000000..c63cd8b40 --- /dev/null +++ b/simulation-system/envs/apt_pomdp_defender/test_config.py @@ -0,0 +1,29 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'apt_pomdp_defender' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config(name="csle-apt-pomdp-defender-001", version="0.0.1", N=5, p_a=0.1, num_observations=10) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/cyborg/test_config.py b/simulation-system/envs/cyborg/test_config.py new file mode 100644 index 000000000..7b2d5b769 --- /dev/null +++ b/simulation-system/envs/cyborg/test_config.py @@ -0,0 +1,29 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'cyborg' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config(name="csle-cyborg-001", version="0.0.1") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/intrusion_recovery_pomdp_defender/test_config.py b/simulation-system/envs/intrusion_recovery_pomdp_defender/test_config.py new file mode 100644 index 000000000..c847bf7de --- /dev/null +++ b/simulation-system/envs/intrusion_recovery_pomdp_defender/test_config.py @@ -0,0 +1,31 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'intrusion-recovery-pomdp-defender' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config(name="csle-tolerance-intrusion-recovery-pomdp-defender-001", version="0.0.1", + eta=1, p_a=0.1, p_c_1=0.00001, p_c_2=0.001, p_u=0.02, BTR=20, negate_costs=False, + discount_factor=1, seed=999, num_observations=10) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/intrusion_response_cmdp_defender/test_config.py b/simulation-system/envs/intrusion_response_cmdp_defender/test_config.py new file mode 100644 index 000000000..6c073b629 --- /dev/null +++ b/simulation-system/envs/intrusion_response_cmdp_defender/test_config.py @@ -0,0 +1,32 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'intrusion-response-cmdp-defender' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config( + name="csle-tolerance-intrusion-response-cmdp-defender-001", version="0.0.1", + p_u=0.4, p_a=0.4, p_c=0.01, s_max=20, + initial_state=10, seed=999, discount_factor=1, negate_costs=False, f=3, epsilon_a=0.2) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/local_intrusion_response_pomdp_attacker/test_config.py b/simulation-system/envs/local_intrusion_response_pomdp_attacker/test_config.py new file mode 100644 index 000000000..0e46ac1e9 --- /dev/null +++ b/simulation-system/envs/local_intrusion_response_pomdp_attacker/test_config.py @@ -0,0 +1,32 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'local-intrusion-response-pomdp-attacker' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config(name="csle-intrusion-response-game-local-pomdp-attacker-001", version="0.0.1", + number_of_zones=5, X_max=10, beta=10, reachable=True, initial_zone=3, + attack_success_probability=0.3, eta=0.5, defender_action_cost=1, zone_utility=10, + detection_probability=0.1) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/local_intrusion_response_pomdp_defender/test_config.py b/simulation-system/envs/local_intrusion_response_pomdp_defender/test_config.py new file mode 100644 index 000000000..699235d60 --- /dev/null +++ b/simulation-system/envs/local_intrusion_response_pomdp_defender/test_config.py @@ -0,0 +1,32 @@ +from config_v_001 import default_config + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'local-intrusion-response-pomdp-defender' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config(name="csle-intrusion-response-game-local-pomdp-defender-001", version="0.0.1", + number_of_zones=5, X_max=10, beta=10, reachable=True, initial_zone=3, + attack_success_probability=0.3, eta=0.5, defender_action_cost=1, zone_utility=10, + detection_probability=0.1) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/stopping_game/test_config.py b/simulation-system/envs/stopping_game/test_config.py new file mode 100644 index 000000000..1cd7e3fdc --- /dev/null +++ b/simulation-system/envs/stopping_game/test_config.py @@ -0,0 +1,75 @@ +from config_v_001 import default_config as default_config_v_001 +from config_v_002 import default_config as default_config_v_002 +from config_v_003 import default_config as default_config_v_003 + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'stopping-game' + """ + + def test_create_config_v001(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_001(name="csle-stopping-game-001", version="0.0.1") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None + + def test_create_config_v002(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_002(name="csle-stopping-game-002", version="0.0.2") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None + + def test_create_config_v003(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_003(name="csle-stopping-game-003", version="0.0.3") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/stopping_mdp_attacker/test_config.py b/simulation-system/envs/stopping_mdp_attacker/test_config.py new file mode 100644 index 000000000..7637be645 --- /dev/null +++ b/simulation-system/envs/stopping_mdp_attacker/test_config.py @@ -0,0 +1,75 @@ +from config_v_001 import default_config as default_config_v_001 +from config_v_002 import default_config as default_config_v_002 +from config_v_003 import default_config as default_config_v_003 + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'stopping-mdp-attacker' + """ + + def test_create_config_v001(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_001(name="csle-stopping-mdp-attacker-001", version="0.0.1") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None + + def test_create_config_v002(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_002(name="csle-stopping-mdp-attacker-002", version="0.0.2") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None + + def test_create_config_v003(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_003(name="csle-stopping-mdp-attacker-003", version="0.0.3") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/stopping_pomdp_defender/test_config.py b/simulation-system/envs/stopping_pomdp_defender/test_config.py new file mode 100644 index 000000000..465d60819 --- /dev/null +++ b/simulation-system/envs/stopping_pomdp_defender/test_config.py @@ -0,0 +1,75 @@ +from config_v_001 import default_config as default_config_v_001 +from config_v_002 import default_config as default_config_v_002 +from config_v_003 import default_config as default_config_v_003 + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'stopping-pomdp-defender' + """ + + def test_create_config_v001(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_001(name="csle-stopping-pomdp-defender-001", version="0.0.1") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None + + def test_create_config_v002(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_002(name="csle-stopping-pomdp-defender-002", version="0.0.2") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None + + def test_create_config_v003(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + config = default_config_v_003(name="csle-stopping-pomdp-defender-003", version="0.0.3") + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/workflow_intrusion_response_pomdp_attacker/test_config.py b/simulation-system/envs/workflow_intrusion_response_pomdp_attacker/test_config.py new file mode 100644 index 000000000..b29e24784 --- /dev/null +++ b/simulation-system/envs/workflow_intrusion_response_pomdp_attacker/test_config.py @@ -0,0 +1,44 @@ +from config_v_001 import default_config +import numpy as np + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'workflow-intrusion-response-pomdp-attacker' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + gw_reachable = np.array([0, 1, 2]) + adjacency_matrix = [ + [1, 0, 0, 1, 1, 0], + [0, 1, 0, 1, 0, 1], + [0, 0, 1, 0, 1, 1], + [0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 1] + ] + adjacency_matrix = np.array(adjacency_matrix) + config = default_config(name="csle-intrusion-response-game-workflow-pomdp-attacker-001", version="0.0.1", + number_of_zones=5, X_max=10, beta=10, reachable=True, initial_zone=3, + attack_success_probability=0.3, eta=0.5, defender_action_cost=1, zone_utility=10, + detection_probability=0.1, num_nodes=6, adjacency_matrix=adjacency_matrix, + gw_reachable=gw_reachable, gamma=0.99) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/envs/workflow_intrusion_response_pomdp_defender/test_config.py b/simulation-system/envs/workflow_intrusion_response_pomdp_defender/test_config.py new file mode 100644 index 000000000..df5ffa536 --- /dev/null +++ b/simulation-system/envs/workflow_intrusion_response_pomdp_defender/test_config.py @@ -0,0 +1,44 @@ +from config_v_001 import default_config +import numpy as np + + +class TestSimulationConfigSuite: + """ + Test suite for the simulation configuration for 'workflow-intrusion-response-pomdp-defender' + """ + + def test_create_config(self) -> None: + """ + Tests creation of the simulation configuration + + :return: None + """ + gw_reachable = np.array([0, 1, 2]) + adjacency_matrix = [ + [1, 0, 0, 1, 1, 0], + [0, 1, 0, 1, 0, 1], + [0, 0, 1, 0, 1, 1], + [0, 0, 0, 1, 0, 0], + [0, 0, 0, 0, 1, 0], + [0, 0, 0, 0, 0, 1] + ] + adjacency_matrix = np.array(adjacency_matrix) + config = default_config(name="csle-intrusion-response-game-workflow-pomdp-defender-001", version="0.0.1", + number_of_zones=5, X_max=10, beta=10, reachable=True, initial_zone=3, + attack_success_probability=0.3, eta=0.5, defender_action_cost=1, zone_utility=10, + detection_probability=0.1, num_nodes=6, adjacency_matrix=adjacency_matrix, + gw_reachable=gw_reachable, gamma=0.99) + assert config.players_config is not None + assert config.state_space_config is not None + assert config.joint_action_space_config is not None + assert config.joint_observation_space_config is not None + assert config.transition_operator_config is not None + assert config.observation_function_config is not None + assert config.reward_function_config is not None + assert config.initial_state_distribution_config is not None + assert config.env_parameters_config is not None + assert config.simulation_env_input_config is not None + assert config.gym_env_name is not None + assert config.plot_transition_probabilities is not None + assert config.plot_observation_function is not None + assert config.plot_reward_function is not None diff --git a/simulation-system/libs/csle-cli/src/csle_cli/cli.py b/simulation-system/libs/csle-cli/src/csle_cli/cli.py index 5e60528e7..1e59f865a 100755 --- a/simulation-system/libs/csle-cli/src/csle_cli/cli.py +++ b/simulation-system/libs/csle-cli/src/csle_cli/cli.py @@ -8,6 +8,7 @@ from typing import List, Tuple, Union import click import warnings + warnings.filterwarnings("ignore") from csle_common.dao.simulation_config.simulation_env_config import SimulationEnvConfig from csle_common.util.cluster_util import ClusterUtil diff --git a/unit_tests.sh b/unit_tests.sh index 7705f43d4..89ee90c0d 100755 --- a/unit_tests.sh +++ b/unit_tests.sh @@ -28,5 +28,33 @@ echo "Running Python unit tests for gym-csle-apt-game" cd simulation-system/libs/gym-csle-apt-game; pytest; cd ../../../ echo "Running Python unit tests for gym-csle-cyborg" cd simulation-system/libs/gym-csle-cyborg; pytest; cd ../../../ +echo "Running Python unit tests for CSLE emulation environments" +cd emulation-system/envs/050/level_1; pytest; cd ../../../../ +cd emulation-system/envs/050/level_2; pytest; cd ../../../../ +cd emulation-system/envs/050/level_3; pytest; cd ../../../../ +cd emulation-system/envs/050/level_4; pytest; cd ../../../../ +cd emulation-system/envs/050/level_5; pytest; cd ../../../../ +cd emulation-system/envs/050/level_6; pytest; cd ../../../../ +cd emulation-system/envs/050/level_7; pytest; cd ../../../../ +cd emulation-system/envs/050/level_8; pytest; cd ../../../../ +cd emulation-system/envs/050/level_9; pytest; cd ../../../../ +cd emulation-system/envs/050/level_10; pytest; cd ../../../../ +cd emulation-system/envs/050/level_11; pytest; cd ../../../../ +cd emulation-system/envs/050/level_12; pytest; cd ../../../../ +cd emulation-system/envs/050/level_13; pytest; cd ../../../../ +echo "Running Python unit tests for CSLE simulation environments" +cd simulation-system/envs/apt_game; pytest; cd ../../../ +cd simulation-system/envs/apt_mdp_attacker; pytest; cd ../../../ +cd simulation-system/envs/apt_pomdp_defender; pytest; cd ../../../ +cd simulation-system/envs/cyborg; pytest; cd ../../../ +cd simulation-system/envs/intrusion_recovery_pomdp_defender; pytest; cd ../../../ +cd simulation-system/envs/intrusion_response_cmdp_defender; pytest; cd ../../../ +cd simulation-system/envs/local_intrusion_response_pomdp_attacker; pytest; cd ../../../ +cd simulation-system/envs/local_intrusion_response_pomdp_defender; pytest; cd ../../../ +cd simulation-system/envs/stopping_game; pytest; cd ../../../ +cd simulation-system/envs/stopping_mdp_attacker; pytest; cd ../../../ +cd simulation-system/envs/stopping_pomdp_defender; pytest; cd ../../../ +cd simulation-system/envs/workflow_intrusion_response_pomdp_attacker; pytest; cd ../../../ +cd simulation-system/envs/workflow_intrusion_response_pomdp_defender; pytest; cd ../../../ echo "Running JavaScript unit tests for csle-mgmt-webapp" cd management-system/csle-mgmt-webapp; npm test -- --watchAll=false; cd ../../