From 7beacfd95fb6c48f8f3581bd58be1addd42a1422 Mon Sep 17 00:00:00 2001 From: Czar Echavez Date: Mon, 12 Feb 2024 11:41:55 +0000 Subject: [PATCH] #2258: missing some configuration items + added more tests --- src/primaite/game/game.py | 11 ++++++++++- tests/assets/configs/basic_switched_network.yaml | 6 ++++++ tests/integration_tests/game_configuration.py | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/primaite/game/game.py b/src/primaite/game/game.py index 6ccd2f59..c03bca36 100644 --- a/src/primaite/game/game.py +++ b/src/primaite/game/game.py @@ -283,7 +283,16 @@ class PrimaiteGame: opt = service_cfg["options"] new_service.configure_backup(backup_server=IPv4Address(opt.get("backup_server_ip"))) new_service.start() - + if service_type == "FTPServer": + if "options" in service_cfg: + opt = service_cfg["options"] + new_service.server_password = opt.get("server_password") + new_service.start() + if service_type == "NTPClient": + if "options" in service_cfg: + opt = service_cfg["options"] + new_service.ntp_server = IPv4Address(opt.get("ntp_server_ip")) + new_service.start() if "applications" in node_cfg: for application_cfg in node_cfg["applications"]: new_application = None diff --git a/tests/assets/configs/basic_switched_network.yaml b/tests/assets/configs/basic_switched_network.yaml index 0050a0cb..d1cec079 100644 --- a/tests/assets/configs/basic_switched_network.yaml +++ b/tests/assets/configs/basic_switched_network.yaml @@ -85,6 +85,7 @@ simulation: type: DatabaseClient options: db_server_ip: 192.168.1.10 + server_password: arcd - ref: data_manipulation_bot type: DataManipulationBot options: @@ -92,6 +93,7 @@ simulation: data_manipulation_p_of_success: 0.8 payload: "DELETE" server_ip: 192.168.1.21 + server_password: arcd - ref: dos_bot type: DoSBot options: @@ -116,8 +118,12 @@ simulation: type: WebServer - ref: client_1_ftp_server type: FTPServer + options: + server_password: arcd - ref: client_1_ntp_client type: NTPClient + options: + ntp_server_ip: 192.168.1.10 - ref: client_1_ntp_server type: NTPServer - ref: client_2 diff --git a/tests/integration_tests/game_configuration.py b/tests/integration_tests/game_configuration.py index 9db894c5..3bd870e3 100644 --- a/tests/integration_tests/game_configuration.py +++ b/tests/integration_tests/game_configuration.py @@ -9,7 +9,7 @@ from primaite.game.agent.data_manipulation_bot import DataManipulationAgent from primaite.game.agent.interface import ProxyAgent, RandomAgent from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING from primaite.simulator.network.container import Network -from primaite.simulator.network.hardware.nodes.computer import Computer +from primaite.simulator.network.hardware.nodes.host.computer import Computer from primaite.simulator.system.applications.database_client import DatabaseClient from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot from primaite.simulator.system.applications.red_applications.dos_bot import DoSBot @@ -109,6 +109,7 @@ def test_database_client_install(): database_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient") assert database_client.server_ip_address == IPv4Address("192.168.1.10") + assert database_client.server_password == "arcd" def test_data_manipulation_bot_install(): @@ -122,6 +123,7 @@ def test_data_manipulation_bot_install(): assert data_manipulation_bot.payload == "DELETE" assert data_manipulation_bot.data_manipulation_p_of_success == 0.8 assert data_manipulation_bot.port_scan_p_of_success == 0.8 + assert data_manipulation_bot.server_password == "arcd" def test_dos_bot_install(): @@ -149,6 +151,16 @@ def test_dns_client_install(): assert dns_client.dns_server == IPv4Address("192.168.1.10") +def test_dns_server_install(): + """Test that the DNS Client service can be configured via config.""" + game = load_config(BASIC_CONFIG) + client_1: Computer = game.simulation.network.get_node_by_hostname("client_1") + + dns_server: DNSServer = client_1.software_manager.software.get("DNSServer") + + assert dns_server.dns_lookup("arcd.com") == IPv4Address("192.168.1.10") + + def test_database_service_install(): """Test that the Database Service can be configured via config.""" game = load_config(BASIC_CONFIG) @@ -186,6 +198,7 @@ def test_ftp_server_install(): ftp_server_service: FTPServer = client_1.software_manager.software.get("FTPServer") assert ftp_server_service is not None + assert ftp_server_service.server_password == "arcd" def test_ntp_client_install(): @@ -195,6 +208,7 @@ def test_ntp_client_install(): ntp_client_service: NTPClient = client_1.software_manager.software.get("NTPClient") assert ntp_client_service is not None + assert ntp_client_service.ntp_server == IPv4Address("192.168.1.10") def test_ntp_server_install():