#2888: Use fixing_duration from ConfigSchema.

This commit is contained in:
Nick Todd
2025-01-06 16:33:57 +00:00
parent 695ebb5ec7
commit cb4e10921e
7 changed files with 38 additions and 44 deletions

View File

@@ -185,7 +185,7 @@ simulation:
options:
db_server_ip: 192.168.1.10
server_password: arcd
fix_duration: 1
fixing_duration: 1
- type: DataManipulationBot
options:
port_scan_p_of_success: 0.8
@@ -208,7 +208,7 @@ simulation:
arcd.com: 192.168.1.10
- type: DatabaseService
options:
fix_duration: 5
fixing_duration: 5
backup_server_ip: 192.168.1.10
- type: WebServer
- type: FTPClient

View File

@@ -179,19 +179,19 @@ simulation:
applications:
- type: NMAP
options:
fix_duration: 1
fixing_duration: 1
- type: RansomwareScript
options:
fix_duration: 1
fixing_duration: 1
- type: WebBrowser
options:
target_url: http://arcd.com/users/
fix_duration: 1
fixing_duration: 1
- type: DatabaseClient
options:
db_server_ip: 192.168.1.10
server_password: arcd
fix_duration: 1
fixing_duration: 1
- type: DataManipulationBot
options:
port_scan_p_of_success: 0.8
@@ -199,44 +199,44 @@ simulation:
payload: "DELETE"
server_ip: 192.168.1.21
server_password: arcd
fix_duration: 1
fixing_duration: 1
- type: DoSBot
options:
target_ip_address: 192.168.10.21
payload: SPOOF DATA
port_scan_p_of_success: 0.8
fix_duration: 1
fixing_duration: 1
services:
- type: DNSClient
options:
dns_server: 192.168.1.10
fix_duration: 3
fixing_duration: 3
- type: DNSServer
options:
fix_duration: 3
fixing_duration: 3
domain_mapping:
arcd.com: 192.168.1.10
- type: DatabaseService
options:
backup_server_ip: 192.168.1.10
fix_duration: 3
fixing_duration: 3
- type: WebServer
options:
fix_duration: 3
fixing_duration: 3
- type: FTPClient
options:
fix_duration: 3
fixing_duration: 3
- type: FTPServer
options:
server_password: arcd
fix_duration: 3
fixing_duration: 3
- type: NTPClient
options:
ntp_server_ip: 192.168.1.10
fix_duration: 3
fixing_duration: 3
- type: NTPServer
options:
fix_duration: 3
fixing_duration: 3
- hostname: client_2
type: computer
ip_address: 192.168.10.22

View File

@@ -27,27 +27,27 @@ def load_config(config_path: Union[str, Path]) -> PrimaiteGame:
return PrimaiteGame.from_config(cfg)
def test_default_fix_duration():
"""Test that software with no defined fix duration in config uses the default fix duration of 2."""
def test_default_fixing_duration():
"""Test that software with no defined fixing duration in config uses the default fixing duration of 2."""
game = load_config(TEST_CONFIG)
client_2: Computer = game.simulation.network.get_node_by_hostname("client_2")
database_client: DatabaseClient = client_2.software_manager.software.get("DatabaseClient")
assert database_client.fixing_duration == 2
assert database_client.config.fixing_duration == 2
dns_client: DNSClient = client_2.software_manager.software.get("DNSClient")
assert dns_client.fixing_duration == 2
assert dns_client.config.fixing_duration == 2
def test_fix_duration_set_from_config():
"""Test to check that the fix duration set for applications and services works as intended."""
def test_fixing_duration_set_from_config():
"""Test to check that the fixing duration set for applications and services works as intended."""
game = load_config(TEST_CONFIG)
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
# in config - services take 3 timesteps to fix
for service in ["DNSClient", "DNSServer", "DatabaseService", "WebServer", "FTPClient", "FTPServer", "NTPServer"]:
assert client_1.software_manager.software.get(service) is not None
assert client_1.software_manager.software.get(service).fixing_duration == 3
assert client_1.software_manager.software.get(service).config.fixing_duration == 3
# in config - applications take 1 timestep to fix
# remove test applications from list
@@ -55,27 +55,27 @@ def test_fix_duration_set_from_config():
for application in ["RansomwareScript", "WebBrowser", "DataManipulationBot", "DoSBot", "DatabaseClient"]:
assert client_1.software_manager.software.get(application) is not None
assert client_1.software_manager.software.get(application).fixing_duration == 1
assert client_1.software_manager.software.get(application).config.fixing_duration == 1
def test_fix_duration_for_one_item():
"""Test that setting fix duration for one application does not affect other components."""
def test_fixing_duration_for_one_item():
"""Test that setting fixing duration for one application does not affect other components."""
game = load_config(ONE_ITEM_CONFIG)
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
# in config - services take 3 timesteps to fix
for service in ["DNSClient", "DNSServer", "WebServer", "FTPClient", "FTPServer", "NTPServer"]:
assert client_1.software_manager.software.get(service) is not None
assert client_1.software_manager.software.get(service).fixing_duration == 2
assert client_1.software_manager.software.get(service).config.fixing_duration == 2
# in config - applications take 1 timestep to fix
# remove test applications from list
for applications in ["RansomwareScript", "WebBrowser", "DataManipulationBot", "DoSBot"]:
assert client_1.software_manager.software.get(applications) is not None
assert client_1.software_manager.software.get(applications).fixing_duration == 2
assert client_1.software_manager.software.get(applications).config.fixing_duration == 2
database_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient")
assert database_client.fixing_duration == 1
assert database_client.config.fixing_duration == 1
database_service: DatabaseService = client_1.software_manager.software.get("DatabaseService")
assert database_service.fixing_duration == 5
assert database_service.config.fixing_duration == 5