#3062 - First pass at unifying naming convention for discriminators (still errors) [skip ci]

This commit is contained in:
Marek Wolan
2025-02-03 16:24:03 +00:00
parent 055c853b0f
commit abccf4afc5
195 changed files with 2824 additions and 2802 deletions

View File

@@ -28,27 +28,27 @@ def test_application_cannot_perform_actions_unless_running(game_and_agent_fixtur
game, agent = game_and_agent_fixture
client_1 = game.simulation.network.get_node_by_hostname("client_1")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.close()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_scan", {"node_name": "client_1", "application_name": "WebBrowser"})
action = ("node-application-scan", {"node_name": "client_1", "application_name": "web-browser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_close", {"node_name": "client_1", "application_name": "WebBrowser"})
action = ("node-application-close", {"node_name": "client_1", "application_name": "web-browser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_fix", {"node_name": "client_1", "application_name": "WebBrowser"})
action = ("node-application-fix", {"node_name": "client_1", "application_name": "web-browser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_execute", {"node_name": "client_1", "application_name": "WebBrowser"})
action = ("node-application-execute", {"node_name": "client_1", "application_name": "web-browser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED

View File

@@ -32,7 +32,7 @@ def game_and_agent_fixture(game_and_agent):
c2_server_host = game.simulation.network.get_node_by_hostname("client_1")
c2_server_host.software_manager.install(software_class=C2Server)
c2_server: C2Server = c2_server_host.software_manager.software["C2Server"]
c2_server: C2Server = c2_server_host.software_manager.software["c2-server"]
c2_server.run()
return (game, agent)
@@ -46,15 +46,15 @@ def test_c2_beacon_default(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgen
server_1: Server = game.simulation.network.get_node_by_hostname("server_1")
action = (
"node_application_install",
{"node_name": "server_1", "application_name": "C2Beacon"},
"node-application-install",
{"node_name": "server_1", "application_name": "c2-beacon"},
)
agent.store_action(action)
game.step()
assert agent.history[-1].response.status == "success"
action = (
"configure_c2_beacon",
"configure-c2-beacon",
{
"node_name": "server_1",
"c2_server_ip_address": "10.0.1.2",
@@ -68,15 +68,15 @@ def test_c2_beacon_default(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgen
assert agent.history[-1].response.status == "success"
action = (
"node_application_execute",
{"node_name": "server_1", "application_name": "C2Beacon"},
"node-application-execute",
{"node_name": "server_1", "application_name": "c2-beacon"},
)
agent.store_action(action)
game.step()
assert agent.history[-1].response.status == "success"
# Asserting that we've confirmed our connection
c2_beacon: C2Beacon = server_1.software_manager.software["C2Beacon"]
c2_beacon: C2Beacon = server_1.software_manager.software["c2-beacon"]
assert c2_beacon.c2_connection_active == True
@@ -91,9 +91,9 @@ def test_c2_server_ransomware(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
# Installing a database on Server_2 for the ransomware to attack
server_2: Server = game.simulation.network.get_node_by_hostname("server_2")
server_2.software_manager.install(DatabaseService)
server_2.software_manager.software["DatabaseService"].start()
server_2.software_manager.software["database-service"].start()
# Configuring the C2 to connect to client 1 (C2 Server)
c2_beacon: C2Beacon = server_1.software_manager.software["C2Beacon"]
c2_beacon: C2Beacon = server_1.software_manager.software["c2-beacon"]
c2_beacon.configure(c2_server_ip_address=IPv4Address("10.0.1.2"))
c2_beacon.establish()
assert c2_beacon.c2_connection_active == True
@@ -101,15 +101,15 @@ def test_c2_server_ransomware(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
# C2 Action 1: Installing the RansomwareScript & Database client via Terminal
action = (
"c2_server_terminal_command",
"c2-server-terminal-command",
{
"node_name": "client_1",
"ip_address": None,
"username": "admin",
"password": "admin",
"commands": [
["software_manager", "application", "install", "RansomwareScript"],
["software_manager", "application", "install", "DatabaseClient"],
["software_manager", "application", "install", "ransomware-script"],
["software_manager", "application", "install", "database-client"],
],
},
)
@@ -118,7 +118,7 @@ def test_c2_server_ransomware(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
assert agent.history[-1].response.status == "success"
action = (
"c2_server_ransomware_configure",
"c2-server-ransomware-configure",
{
"node_name": "client_1",
"server_ip_address": "10.0.2.3",
@@ -131,14 +131,14 @@ def test_c2_server_ransomware(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
# Stepping a few timesteps to allow for the RansowmareScript to finish installing.
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
game.step()
game.step()
action = (
"c2_server_ransomware_launch",
"c2-server-ransomware-launch",
{
"node_name": "client_1",
},
@@ -162,10 +162,10 @@ def test_c2_server_data_exfiltration(game_and_agent_fixture: Tuple[PrimaiteGame,
# Installing a database on Server_2 (creates a database.db file.)
server_2: Server = game.simulation.network.get_node_by_hostname("server_2")
server_2.software_manager.install(DatabaseService)
server_2.software_manager.software["DatabaseService"].start()
server_2.software_manager.software["database-service"].start()
# Configuring the C2 to connect to client 1 (C2 Server)
c2_beacon: C2Beacon = server_1.software_manager.software["C2Beacon"]
c2_beacon: C2Beacon = server_1.software_manager.software["c2-beacon"]
c2_beacon.configure(c2_server_ip_address=IPv4Address("10.0.1.2"))
c2_beacon.establish()
assert c2_beacon.c2_connection_active == True
@@ -178,7 +178,7 @@ def test_c2_server_data_exfiltration(game_and_agent_fixture: Tuple[PrimaiteGame,
# C2 Action: Data exfiltrate.
action = (
"c2_server_data_exfiltrate",
"c2-server-data-exfiltrate",
{
"node_name": "client_1",
"target_file_name": "database.db",

View File

@@ -31,10 +31,10 @@ class TestConfigureDatabaseAction:
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(DatabaseClient)
db_client: DatabaseClient = client_1.software_manager.software["DatabaseClient"]
db_client: DatabaseClient = client_1.software_manager.software["database-client"]
action = (
"configure_database_client",
"configure-database-client",
{
"node_name": "client_1",
"server_ip_address": "192.168.1.99",
@@ -54,10 +54,10 @@ class TestConfigureDatabaseAction:
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(DatabaseClient)
db_client: DatabaseClient = client_1.software_manager.software["DatabaseClient"]
db_client: DatabaseClient = client_1.software_manager.software["database-client"]
action = (
"configure_database_client",
"configure-database-client",
{
"node_name": "client_1",
"server_ip_address": "192.168.1.99",
@@ -76,11 +76,11 @@ class TestConfigureDatabaseAction:
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(DatabaseClient)
db_client: DatabaseClient = client_1.software_manager.software["DatabaseClient"]
db_client: DatabaseClient = client_1.software_manager.software["database-client"]
old_ip = db_client.server_ip_address
action = (
"configure_database_client",
"configure-database-client",
{
"node_name": "client_1",
"server_password": "admin123",
@@ -115,14 +115,14 @@ class TestConfigureRansomwareScriptAction:
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(RansomwareScript)
ransomware_script: RansomwareScript = client_1.software_manager.software["RansomwareScript"]
ransomware_script: RansomwareScript = client_1.software_manager.software["ransomware-script"]
old_ip = ransomware_script.server_ip_address
old_pw = ransomware_script.server_password
old_payload = ransomware_script.payload
action = (
"configure_ransomware_script",
"configure-ransomware-script",
{"node_name": "client_1", **config},
)
agent.store_action(action)
@@ -143,9 +143,9 @@ class TestConfigureRansomwareScriptAction:
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(RansomwareScript)
ransomware_script: RansomwareScript = client_1.software_manager.software["RansomwareScript"]
ransomware_script: RansomwareScript = client_1.software_manager.software["ransomware-script"]
action = (
"configure_ransomware_script",
"configure-ransomware-script",
{
"node_name": "client_1",
"config": {"server_password": "admin123", "bad_option": 70},
@@ -163,10 +163,10 @@ class TestConfigureDoSBot:
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(DoSBot)
dos_bot: DoSBot = client_1.software_manager.software["DoSBot"]
dos_bot: DoSBot = client_1.software_manager.software["dos-bot"]
action = (
"configure_dos_bot",
"configure-dos-bot",
{
"node_name": "client_1",
"target_ip_address": "192.168.1.99",
@@ -196,11 +196,11 @@ class TestConfigureYAML:
# make sure there's no db client on the node yet
client_1 = env.game.simulation.network.get_node_by_hostname("client_1")
assert client_1.software_manager.software.get("DatabaseClient") is None
assert client_1.software_manager.software.get("database-client") is None
# take the install action, check that the db gets installed, step to get it to finish installing
env.step(1)
db_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient")
db_client: DatabaseClient = client_1.software_manager.software.get("database-client")
assert isinstance(db_client, DatabaseClient)
assert db_client.operating_state == ApplicationOperatingState.INSTALLING
env.step(0)
@@ -224,11 +224,11 @@ class TestConfigureYAML:
def test_c2_server_ransomware_configure(self):
env = PrimaiteGymEnv(env_config=APP_CONFIG_YAML)
client_2 = env.game.simulation.network.get_node_by_hostname("client_2")
assert client_2.software_manager.software.get("RansomwareScript") is None
assert client_2.software_manager.software.get("ransomware-script") is None
# install ransomware script
env.step(2)
ransom = client_2.software_manager.software.get("RansomwareScript")
ransom = client_2.software_manager.software.get("ransomware-script")
assert isinstance(ransom, RansomwareScript)
assert ransom.operating_state == ApplicationOperatingState.INSTALLING
env.step(0)
@@ -250,17 +250,17 @@ class TestConfigureYAML:
assert ransom.attack()
db_server = env.game.simulation.network.get_node_by_hostname("server_1")
db_service: DatabaseService = db_server.software_manager.software.get("DatabaseService")
db_service: DatabaseService = db_server.software_manager.software.get("database-service")
assert db_service.db_file.health_status == FileSystemItemHealthStatus.CORRUPT
def test_configure_dos_bot(self):
env = PrimaiteGymEnv(env_config=APP_CONFIG_YAML)
client_3 = env.game.simulation.network.get_node_by_hostname("client_3")
assert client_3.software_manager.software.get("DoSBot") is None
assert client_3.software_manager.software.get("dos-bot") is None
# install DoSBot
env.step(3)
bot = client_3.software_manager.software.get("DoSBot")
bot = client_3.software_manager.software.get("dos-bot")
assert isinstance(bot, DoSBot)
assert bot.operating_state == ApplicationOperatingState.INSTALLING
env.step(0)

View File

@@ -33,7 +33,7 @@ def test_create_file(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
assert client_1.file_system.get_file(folder_name=random_folder, file_name=random_file) is None
action = (
"node_file_create",
"node-file-create",
{"node_name": "client_1", "folder_name": random_folder, "file_name": random_file},
)
agent.store_action(action)
@@ -51,7 +51,7 @@ def test_file_delete_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
assert file.deleted is False
action = (
"node_file_delete",
"node-file-delete",
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
@@ -72,7 +72,7 @@ def test_file_scan_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent
assert file.visible_health_status == FileSystemItemHealthStatus.NONE
action = (
"node_file_scan",
"node-file-scan",
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
@@ -93,7 +93,7 @@ def test_file_repair_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
assert file.health_status == FileSystemItemHealthStatus.CORRUPT
action = (
"node_file_repair",
"node-file-repair",
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
@@ -113,7 +113,7 @@ def test_file_restore_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAg
assert file.health_status == FileSystemItemHealthStatus.CORRUPT
action = (
"node_file_restore",
"node-file-restore",
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
@@ -132,7 +132,7 @@ def test_file_corrupt_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAg
assert file.health_status == FileSystemItemHealthStatus.GOOD
action = (
"node_file_corrupt",
"node-file-corrupt",
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
@@ -150,7 +150,7 @@ def test_file_access_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
assert file.num_access == 0
action = (
"node_file_access",
"node-file-access",
{"node_name": "client_1", "folder_name": file.folder_name, "file_name": file.name},
)
agent.store_action(action)

View File

@@ -32,7 +32,7 @@ def test_create_folder(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
assert client_1.file_system.get_folder(folder_name=random_folder) is None
action = (
"node_folder_create",
"node-folder-create",
{
"node_name": "client_1",
"folder_name": random_folder,
@@ -60,7 +60,7 @@ def test_folder_scan_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
assert folder.visible_health_status == FileSystemItemHealthStatus.NONE
action = (
"node_folder_scan",
"node-folder-scan",
{
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads
@@ -87,7 +87,7 @@ def test_folder_repair_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
assert folder.health_status == FileSystemItemHealthStatus.CORRUPT
action = (
"node_folder_repair",
"node-folder-repair",
{
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads
@@ -111,7 +111,7 @@ def test_folder_restore_action(game_and_agent_fixture: Tuple[PrimaiteGame, Proxy
assert folder.health_status == FileSystemItemHealthStatus.CORRUPT
action = (
"node_folder_restore",
"node-folder-restore",
{
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads

View File

@@ -29,7 +29,7 @@ def test_nic_cannot_be_turned_off_if_not_on(game_and_agent_fixture: Tuple[Primai
assert nic.enabled is False
action = (
"host_nic_disable",
"host-nic-disable",
{
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
@@ -50,7 +50,7 @@ def test_nic_cannot_be_turned_on_if_already_on(game_and_agent_fixture: Tuple[Pri
assert nic.enabled
action = (
"host_nic_enable",
"host-nic-enable",
{
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
@@ -71,7 +71,7 @@ def test_that_a_nic_can_be_enabled_and_disabled(game_and_agent_fixture: Tuple[Pr
assert nic.enabled
action = (
"host_nic_disable",
"host-nic-disable",
{
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
@@ -83,7 +83,7 @@ def test_that_a_nic_can_be_enabled_and_disabled(game_and_agent_fixture: Tuple[Pr
assert nic.enabled is False
action = (
"host_nic_enable",
"host-nic-enable",
{
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)

View File

@@ -29,28 +29,28 @@ def test_node_startup_shutdown(game_and_agent_fixture: Tuple[PrimaiteGame, Proxy
assert client_1.operating_state == NodeOperatingState.ON
# turn it off
action = ("node_shutdown", {"node_name": "client_1"})
action = ("node-shutdown", {"node_name": "client_1"})
agent.store_action(action)
game.step()
assert client_1.operating_state == NodeOperatingState.SHUTTING_DOWN
for i in range(client_1.shut_down_duration + 1):
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
assert client_1.operating_state == NodeOperatingState.OFF
# turn it on
action = ("node_startup", {"node_name": "client_1"})
action = ("node-startup", {"node_name": "client_1"})
agent.store_action(action)
game.step()
assert client_1.operating_state == NodeOperatingState.BOOTING
for i in range(client_1.start_up_duration + 1):
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
@@ -65,7 +65,7 @@ def test_node_cannot_be_started_up_if_node_is_already_on(game_and_agent_fixture:
assert client_1.operating_state == NodeOperatingState.ON
# turn it on
action = ("node_startup", {"node_name": "client_1"})
action = ("node-startup", {"node_name": "client_1"})
agent.store_action(action)
game.step()
@@ -80,14 +80,14 @@ def test_node_cannot_be_shut_down_if_node_is_already_off(game_and_agent_fixture:
client_1.power_off()
for i in range(client_1.shut_down_duration + 1):
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
assert client_1.operating_state == NodeOperatingState.OFF
# turn it ff
action = ("node_shutdown", {"node_name": "client_1"})
action = ("node-shutdown", {"node_name": "client_1"})
agent.store_action(action)
game.step()

View File

@@ -26,12 +26,12 @@ def test_service_start(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
game, agent = game_and_agent_fixture
server_1: Server = game.simulation.network.get_node_by_hostname("server_1")
dns_server = server_1.software_manager.software.get("DNSServer")
dns_server = server_1.software_manager.software.get("dns-server")
dns_server.pause()
assert dns_server.operating_state == ServiceOperatingState.PAUSED
action = ("node_service_start", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-start", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.PAUSED
@@ -40,7 +40,7 @@ def test_service_start(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_start", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-start", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
@@ -52,9 +52,9 @@ def test_service_resume(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent])
game, agent = game_and_agent_fixture
server_1: Server = game.simulation.network.get_node_by_hostname("server_1")
dns_server = server_1.software_manager.software.get("DNSServer")
dns_server = server_1.software_manager.software.get("dns-server")
action = ("node_service_resume", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-resume", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.RUNNING
@@ -63,7 +63,7 @@ def test_service_resume(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent])
assert dns_server.operating_state == ServiceOperatingState.PAUSED
action = ("node_service_resume", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-resume", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
@@ -75,32 +75,32 @@ def test_service_cannot_perform_actions_unless_running(game_and_agent_fixture: T
game, agent = game_and_agent_fixture
server_1: Server = game.simulation.network.get_node_by_hostname("server_1")
dns_server = server_1.software_manager.software.get("DNSServer")
dns_server = server_1.software_manager.software.get("dns-server")
dns_server.stop()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_scan", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-scan", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_pause", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-pause", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_resume", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-resume", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_restart", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-restart", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_fix", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-fix", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED

View File

@@ -32,11 +32,11 @@ def test_remote_login(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
client_1 = game.simulation.network.get_node_by_hostname("client_1")
# create a new user account on server_1 that will be logged into remotely
server_1_usm: UserManager = server_1.software_manager.software["UserManager"]
server_1_usm: UserManager = server_1.software_manager.software["user-manager"]
server_1_usm.add_user("user123", "password", is_admin=True)
action = (
"node_session_remote_login",
"node-session-remote-login",
{
"node_name": "client_1",
"username": "user123",
@@ -64,11 +64,11 @@ def test_remote_login_wrong_password(game_and_agent_fixture: Tuple[PrimaiteGame,
client_1 = game.simulation.network.get_node_by_hostname("client_1")
# create a new user account on server_1 that will be logged into remotely
server_1_usm: UserManager = server_1.software_manager.software["UserManager"]
server_1_usm: UserManager = server_1.software_manager.software["user-manager"]
server_1_usm.add_user("user123", "password", is_admin=True)
action = (
"node_session_remote_login",
"node-session-remote-login",
{
"node_name": "client_1",
"username": "user123",
@@ -96,11 +96,11 @@ def test_remote_login_change_password(game_and_agent_fixture: Tuple[PrimaiteGame
client_1 = game.simulation.network.get_node_by_hostname("client_1")
# create a new user account on server_1 that will be logged into remotely
server_1_um: UserManager = server_1.software_manager.software["UserManager"]
server_1_um: UserManager = server_1.software_manager.software["user-manager"]
server_1_um.add_user("user123", "password", is_admin=True)
action = (
"node_account_change_password",
"node-account-change-password",
{
"node_name": "server_1", # server_1
"username": "user123",
@@ -122,12 +122,12 @@ def test_change_password_logs_out_user(game_and_agent_fixture: Tuple[PrimaiteGam
client_1 = game.simulation.network.get_node_by_hostname("client_1")
# create a new user account on server_1 that will be logged into remotely
server_1_usm: UserManager = server_1.software_manager.software["UserManager"]
server_1_usm: UserManager = server_1.software_manager.software["user-manager"]
server_1_usm.add_user("user123", "password", is_admin=True)
# Log in remotely
action = (
"node_session_remote_login",
"node-session-remote-login",
{
"node_name": "client_1",
"username": "user123",
@@ -140,7 +140,7 @@ def test_change_password_logs_out_user(game_and_agent_fixture: Tuple[PrimaiteGam
# Change password
action = (
"node_account_change_password",
"node-account-change-password",
{
"node_name": "server_1", # server_1
"username": "user123",
@@ -154,7 +154,7 @@ def test_change_password_logs_out_user(game_and_agent_fixture: Tuple[PrimaiteGam
# Assert that the user cannot execute an action
action = (
"node_send_remote_command",
"node-send-remote-command",
{
"node_name": "client_1",
"remote_ip": str(server_1.network_interface[1].ip_address),

View File

@@ -28,7 +28,7 @@ def test_acl_observations(simulation):
# quick set up of ntp
client_1.software_manager.install(NTPClient)
ntp_client: NTPClient = client_1.software_manager.software.get("NTPClient")
ntp_client: NTPClient = client_1.software_manager.software.get("ntp-client")
ntp_client.configure(server.network_interface.get(1).ip_address)
server.software_manager.install(NTPServer)

View File

@@ -43,23 +43,23 @@ def simulation(example_network) -> Simulation:
computer: Computer = example_network.get_node_by_hostname("client_1")
server: Server = example_network.get_node_by_hostname("server_1")
web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser")
web_browser: WebBrowser = computer.software_manager.software.get("web-browser")
web_browser.run()
# Install DNS Client service on computer
computer.software_manager.install(DNSClient)
dns_client: DNSClient = computer.software_manager.software.get("DNSClient")
dns_client: DNSClient = computer.software_manager.software.get("dns-client")
# set dns server
dns_client.dns_server = server.network_interface[1].ip_address
# Install Web Server service on server
server.software_manager.install(WebServer)
web_server_service: WebServer = server.software_manager.software.get("WebServer")
web_server_service: WebServer = server.software_manager.software.get("web-server")
web_server_service.start()
# Install DNS Server service on server
server.software_manager.install(DNSServer)
dns_server: DNSServer = server.software_manager.software.get("DNSServer")
dns_server: DNSServer = server.software_manager.software.get("dns-server")
# register arcd.com to DNS
dns_server.dns_register(
domain_name="arcd.com",
@@ -190,7 +190,7 @@ def test_nic_monitored_traffic(simulation):
assert traffic_obs["tcp"][53]["outbound"] == 0
# send a database query
browser: WebBrowser = pc.software_manager.software.get("WebBrowser")
browser: WebBrowser = pc.software_manager.software.get("web-browser")
browser.config.target_url = f"http://arcd.com/"
browser.get_webpage()

View File

@@ -26,10 +26,10 @@ def test_service_observation(simulation):
# install software on the computer
pc.software_manager.install(NTPServer)
ntp_server = pc.software_manager.software.get("NTPServer")
ntp_server = pc.software_manager.software.get("ntp-server")
assert ntp_server
service_obs = ServiceObservation(where=["network", "nodes", pc.hostname, "services", "NTPServer"])
service_obs = ServiceObservation(where=["network", "nodes", pc.hostname, "services", "ntp-server"])
assert service_obs.space["operating_status"] == spaces.Discrete(7)
assert service_obs.space["health_status"] == spaces.Discrete(5)
@@ -51,10 +51,10 @@ def test_application_observation(simulation):
# install software on the computer
pc.software_manager.install(DatabaseClient)
web_browser: WebBrowser = pc.software_manager.software.get("WebBrowser")
web_browser: WebBrowser = pc.software_manager.software.get("web-browser")
assert web_browser
app_obs = ApplicationObservation(where=["network", "nodes", pc.hostname, "applications", "WebBrowser"])
app_obs = ApplicationObservation(where=["network", "nodes", pc.hostname, "applications", "web-browser"])
web_browser.close()
observation_state = app_obs.observe(simulation.describe_state())

View File

@@ -24,12 +24,12 @@ def test_rng_seed_set(create_env):
env.reset(seed=3)
for i in range(100):
env.step(0)
a = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do_nothing"]
a = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do-nothing"]
env.reset(seed=3)
for i in range(100):
env.step(0)
b = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do_nothing"]
b = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do-nothing"]
assert a == b
@@ -40,11 +40,11 @@ def test_rng_seed_unset(create_env):
env.reset()
for i in range(100):
env.step(0)
a = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do_nothing"]
a = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do-nothing"]
env.reset()
for i in range(100):
env.step(0)
b = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do_nothing"]
b = [item.timestep for item in env.game.agents["client_2_green_user"].history if item.action != "do-nothing"]
assert a != b

View File

@@ -44,13 +44,13 @@ def test_mask_contents_correct():
assert not mask[action_num]
nic_obj.enable()
if act_type == "router_acl_add_rule":
if act_type == "router-acl-add-rule":
assert mask[action_num]
if act_type == "router_acl_remove_rule":
if act_type == "router-acl-remove-rule":
assert mask[action_num]
if act_type == "node_reset":
if act_type == "node-reset":
node_name = act_params["node_name"]
node_obj = net.get_node_by_hostname(node_name)
assert node_obj.operating_state is NodeOperatingState.ON
@@ -60,7 +60,7 @@ def test_mask_contents_correct():
assert not mask[action_num]
node_obj.operating_state = NodeOperatingState.ON
if act_type == "node_shutdown":
if act_type == "node-shutdown":
node_name = act_params["node_name"]
node_obj = net.get_node_by_hostname(node_name)
assert node_obj.operating_state is NodeOperatingState.ON
@@ -70,7 +70,7 @@ def test_mask_contents_correct():
assert not mask[action_num]
node_obj.operating_state = NodeOperatingState.ON
if act_type == "node_os_scan":
if act_type == "node-os-scan":
node_name = act_params["node_name"]
node_obj = net.get_node_by_hostname(node_name)
assert node_obj.operating_state is NodeOperatingState.ON
@@ -80,7 +80,7 @@ def test_mask_contents_correct():
assert not mask[action_num]
node_obj.operating_state = NodeOperatingState.ON
if act_type == "node_startup":
if act_type == "node-startup":
node_name = act_params["node_name"]
node_obj = net.get_node_by_hostname(node_name)
assert node_obj.operating_state is NodeOperatingState.ON
@@ -90,13 +90,13 @@ def test_mask_contents_correct():
assert mask[action_num]
node_obj.operating_state = NodeOperatingState.ON
if act_type == "do_nothing":
if act_type == "do-nothing":
assert mask[action_num]
if act_type == "node_service_disable":
if act_type == "node-service-disable":
assert mask[action_num]
if act_type in ["node_service_scan", "node_service_stop", "node_service_pause"]:
if act_type in ["node-service-scan", "node-service-stop", "node-service-pause"]:
node_name = act_params["node_name"]
service_name = act_params["service_name"]
node_obj = net.get_node_by_hostname(node_name)
@@ -108,7 +108,7 @@ def test_mask_contents_correct():
assert not mask[action_num]
service_obj.operating_state = ServiceOperatingState.RUNNING
if act_type == "node_service_resume":
if act_type == "node-service-resume":
node_name = act_params["node_name"]
service_name = act_params["service_name"]
node_obj = net.get_node_by_hostname(node_name)
@@ -120,7 +120,7 @@ def test_mask_contents_correct():
assert mask[action_num]
service_obj.operating_state = ServiceOperatingState.RUNNING
if act_type == "node_service_start":
if act_type == "node-service-start":
node_name = act_params["node_name"]
service_name = act_params["service_name"]
node_obj = net.get_node_by_hostname(node_name)
@@ -132,7 +132,7 @@ def test_mask_contents_correct():
assert mask[action_num]
service_obj.operating_state = ServiceOperatingState.RUNNING
if act_type == "node_service_enable":
if act_type == "node-service-enable":
node_name = act_params["node_name"]
service_name = act_params["service_name"]
node_obj = net.get_node_by_hostname(node_name)
@@ -144,7 +144,7 @@ def test_mask_contents_correct():
assert mask[action_num]
service_obj.operating_state = ServiceOperatingState.RUNNING
if act_type in ["node_file_scan", "node_file_checkhash", "node_file_delete"]:
if act_type in ["node-file-scan", "node-file-checkhash", "node-file-delete"]:
node_name = act_params["node_name"]
folder_name = act_params["folder_name"]
file_name = act_params["file_name"]

View File

@@ -35,7 +35,7 @@ def test_do_nothing_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAgent])
"""Test that the do_nothingAction can form a request and that it is accepted by the simulation."""
game, agent = game_and_agent
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
@@ -51,12 +51,12 @@ def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, Proxy
game, agent = game_and_agent
# 1: Check that the service starts off in a good state, and that visible state is hidden until first scan
svc = game.simulation.network.get_node_by_hostname("server_1").software_manager.software.get("DNSServer")
svc = game.simulation.network.get_node_by_hostname("server_1").software_manager.software.get("dns-server")
assert svc.health_state_actual == SoftwareHealthState.GOOD
assert svc.health_state_visible == SoftwareHealthState.UNUSED
# 2: Scan and check that the visible state is now correct
action = ("node_service_scan", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-scan", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert svc.health_state_actual == SoftwareHealthState.GOOD
@@ -67,7 +67,7 @@ def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, Proxy
assert svc.health_state_visible == SoftwareHealthState.GOOD
# 4: Scan and check that the visible state is now correct
action = ("node_service_scan", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-scan", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
assert svc.health_state_actual == SoftwareHealthState.COMPROMISED
@@ -84,11 +84,11 @@ def test_node_service_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
game, agent = game_and_agent
# 1: Corrupt the service
svc = game.simulation.network.get_node_by_hostname("server_1").software_manager.software.get("DNSServer")
svc = game.simulation.network.get_node_by_hostname("server_1").software_manager.software.get("dns-server")
svc.health_state_actual = SoftwareHealthState.COMPROMISED
# 2: Apply a patch action
action = ("node_service_fix", {"node_name": "server_1", "service_name": "DNSServer"})
action = ("node-service-fix", {"node_name": "server_1", "service_name": "dns-server"})
agent.store_action(action)
game.step()
@@ -96,7 +96,7 @@ def test_node_service_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
assert svc.health_state_actual == SoftwareHealthState.FIXING
# 4: perform a few do-nothing steps and check that the service is now in the good state
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
assert svc.health_state_actual == SoftwareHealthState.GOOD
@@ -106,7 +106,7 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
"""
Test that the RouterACLAddRuleAction can form a request and that it is accepted by the simulation.
The ACL starts off with 4 rules, and we add a rule, and check that the ACL now has 5 rules.
The acl starts off with 4 rules, and we add a rule, and check that the acl now has 5 rules.
"""
game, agent = game_and_agent
@@ -121,7 +121,7 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
# 2: Add a rule to block client 1 from reaching server 2 on router
action = (
"router_acl_add_rule",
"router-acl-add-rule",
{
"target_router": "router",
"position": 4,
@@ -138,7 +138,7 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
agent.store_action(action)
game.step()
# 3: Check that the ACL now has 5 rules, and that client 1 cannot ping server 2
# 3: Check that the acl now has 5 rules, and that client 1 cannot ping server 2
assert router.acl.num_rules == 5
assert not client_1.ping("10.0.2.3") # Cannot ping server_2
assert client_1.ping("10.0.2.2") # Can ping server_1
@@ -148,7 +148,7 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
# 4: Add a rule to block server_1 from reaching server_2 on router (this should not affect comms as they are on same subnet)
action = (
"router_acl_add_rule",
"router-acl-add-rule",
{
"target_router": "router",
"position": 5, # 5th rule
@@ -181,14 +181,14 @@ def test_router_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, P
server_1 = game.simulation.network.get_node_by_hostname("server_1")
router = game.simulation.network.get_node_by_hostname("router")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.run()
browser.config.target_url = "http://www.example.com"
assert browser.get_webpage() # check that the browser can access example.com before we block it
# 2: Remove rule that allows HTTP traffic across the network
action = (
"router_acl_remove_rule",
"router-acl-remove-rule",
{
"target_router": "router",
"position": 3, # 4th rule
@@ -200,7 +200,7 @@ def test_router_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, P
# 3: Check that the ACL now has 3 rules, and that client 1 cannot access example.com
assert router.acl.num_rules == 3
assert not browser.get_webpage()
client_1.software_manager.software.get("DNSClient").dns_cache.clear()
client_1.software_manager.software.get("dns-client").dns_cache.clear()
assert client_1.ping("10.0.2.2") # pinging still works because ICMP is allowed
assert client_1.ping("10.0.2.3")
@@ -214,14 +214,14 @@ def test_host_nic_disable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
server_1 = game.simulation.network.get_node_by_hostname("server_1")
server_2 = game.simulation.network.get_node_by_hostname("server_2")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.run()
browser.config.target_url = "http://www.example.com"
assert browser.get_webpage() # check that the browser can access example.com before we block it
# 2: Disable the NIC on client_1
action = (
"host_nic_disable",
"host-nic-disable",
{
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
@@ -252,7 +252,7 @@ def test_host_nic_enable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAg
# 2: Use action to enable nic
action = (
"host_nic_enable",
"host-nic-enable",
{
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
@@ -279,7 +279,7 @@ def test_node_file_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAge
# 2: perform a scan and make sure nothing has changed
action = (
"node_file_scan",
"node-file-scan",
{
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads,
@@ -316,7 +316,7 @@ def test_node_file_delete_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
# 2: delete the file
action = (
"node_file_delete",
"node-file-delete",
{
"node_name": "client_1", # client_1
"folder_name": "downloads", # downloads
@@ -339,7 +339,7 @@ def test_node_file_create(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
client_1 = game.simulation.network.get_node_by_hostname("client_1")
action = (
"node_file_create",
"node-file-create",
{
"node_name": "client_1",
"folder_name": "test",
@@ -360,7 +360,7 @@ def test_node_file_access(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
client_1 = game.simulation.network.get_node_by_hostname("client_1") #
action = (
"node_file_create",
"node-file-create",
{
"node_name": "client_1",
"folder_name": "test",
@@ -373,7 +373,7 @@ def test_node_file_access(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
assert client_1.file_system.get_file(folder_name="test", file_name="file.txt").num_access == 0
action = (
"node_file_access",
"node-file-access",
{
"node_name": "client_1",
"folder_name": "test",
@@ -393,7 +393,7 @@ def test_node_folder_create(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
client_1 = game.simulation.network.get_node_by_hostname("client_1") #
action = (
"node_folder_create",
"node-folder-create",
{
"node_name": "client_1",
"folder_name": "test",
@@ -414,14 +414,14 @@ def test_network_router_port_disable_integration(game_and_agent: Tuple[PrimaiteG
server_1 = game.simulation.network.get_node_by_hostname("server_1")
router = game.simulation.network.get_node_by_hostname("router")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.run()
browser.config.target_url = "http://www.example.com"
assert browser.get_webpage() # check that the browser can access example.com before we block it
# 2: Disable the NIC on client_1
action = (
"network_port_disable",
"network-port-disable",
{
"target_nodename": "router", # router
"port_num": 1, # port 1
@@ -453,7 +453,7 @@ def test_network_router_port_enable_integration(game_and_agent: Tuple[PrimaiteGa
# 2: Use action to enable port
action = (
"network_port_enable",
"network-port-enable",
{
"target_nodename": "router", # router
"port_num": 1, # port 1
@@ -474,7 +474,7 @@ def test_node_application_scan_integration(game_and_agent: Tuple[PrimaiteGame, P
# 1: Check that http traffic is going across the network nicely.
client_1 = game.simulation.network.get_node_by_hostname("client_1")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.run()
browser.config.target_url = "http://www.example.com"
assert browser.get_webpage() # check that the browser can access example.com
@@ -484,8 +484,8 @@ def test_node_application_scan_integration(game_and_agent: Tuple[PrimaiteGame, P
# 2: Scan and check that the visible state is now correct
action = (
"node_application_scan",
{"node_name": "client_1", "application_name": "WebBrowser"},
"node-application-scan",
{"node_name": "client_1", "application_name": "web-browser"},
)
agent.store_action(action)
game.step()
@@ -498,8 +498,8 @@ def test_node_application_scan_integration(game_and_agent: Tuple[PrimaiteGame, P
# 4: Scan and check that the visible state is now correct
action = (
"node_application_scan",
{"node_name": "client_1", "application_name": "WebBrowser"},
"node-application-scan",
{"node_name": "client_1", "application_name": "web-browser"},
)
agent.store_action(action)
game.step()
@@ -517,13 +517,13 @@ def test_node_application_fix_integration(game_and_agent: Tuple[PrimaiteGame, Pr
# 1: Check that http traffic is going across the network nicely.
client_1 = game.simulation.network.get_node_by_hostname("client_1")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.health_state_actual = SoftwareHealthState.COMPROMISED
# 2: Apply a fix action
action = (
"node_application_fix",
{"node_name": "client_1", "application_name": "WebBrowser"},
"node-application-fix",
{"node_name": "client_1", "application_name": "web-browser"},
)
agent.store_action(action)
game.step()
@@ -532,7 +532,7 @@ def test_node_application_fix_integration(game_and_agent: Tuple[PrimaiteGame, Pr
assert browser.health_state_actual == SoftwareHealthState.FIXING
# 4: perform a few do-nothing steps and check that the application is now in the good state
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
assert browser.health_state_actual == SoftwareHealthState.GOOD
@@ -545,14 +545,14 @@ def test_node_application_close_integration(game_and_agent: Tuple[PrimaiteGame,
game, agent = game_and_agent
client_1 = game.simulation.network.get_node_by_hostname("client_1")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.run()
assert browser.operating_state == ApplicationOperatingState.RUNNING
# 2: Apply a close action
action = (
"node_application_close",
{"node_name": "client_1", "application_name": "WebBrowser"},
"node-application-close",
{"node_name": "client_1", "application_name": "web-browser"},
)
agent.store_action(action)
game.step()
@@ -570,25 +570,25 @@ def test_node_application_install_and_uninstall_integration(game_and_agent: Tupl
client_1 = game.simulation.network.get_node_by_hostname("client_1")
assert client_1.software_manager.software.get("DoSBot") is None
assert client_1.software_manager.software.get("dos-bot") is None
action = (
"node_application_install",
{"node_name": "client_1", "application_name": "DoSBot"},
"node-application-install",
{"node_name": "client_1", "application_name": "dos-bot"},
)
agent.store_action(action)
game.step()
assert client_1.software_manager.software.get("DoSBot") is not None
assert client_1.software_manager.software.get("dos-bot") is not None
action = (
"node_application_remove",
{"node_name": "client_1", "application_name": "DoSBot"},
"node-application-remove",
{"node_name": "client_1", "application_name": "dos-bot"},
)
agent.store_action(action)
game.step()
assert client_1.software_manager.software.get("DoSBot") is None
assert client_1.software_manager.software.get("dos-bot") is None
def test_firewall_acl_add_remove_rule_integration():

View File

@@ -27,18 +27,18 @@ def test_WebpageUnavailablePenalty(game_and_agent: tuple[PrimaiteGame, Controlle
comp = WebpageUnavailablePenalty(config=schema)
client_1 = game.simulation.network.get_node_by_hostname("client_1")
browser: WebBrowser = client_1.software_manager.software.get("WebBrowser")
browser: WebBrowser = client_1.software_manager.software.get("web-browser")
browser.run()
browser.config.target_url = "http://www.example.com"
agent.reward_function.register_component(comp, 0.7)
# Check that before trying to fetch the webpage, the reward is 0.0
agent.store_action(("do_nothing", {}))
agent.store_action(("do-nothing", {}))
game.step()
assert agent.reward_function.current_reward == 0.0
# Check that successfully fetching the webpage yields a reward of 0.7
agent.store_action(("node_application_execute", {"node_name": "client_1", "application_name": "WebBrowser"}))
agent.store_action(("node-application-execute", {"node_name": "client_1", "application_name": "web-browser"}))
game.step()
assert agent.reward_function.current_reward == 0.7
@@ -50,7 +50,7 @@ def test_WebpageUnavailablePenalty(game_and_agent: tuple[PrimaiteGame, Controlle
src_port=PORT_LOOKUP["HTTP"],
dst_port=PORT_LOOKUP["HTTP"],
)
agent.store_action(("node_application_execute", {"node_name": "client_1", "application_name": "WebBrowser"}))
agent.store_action(("node-application-execute", {"node_name": "client_1", "application_name": "web-browser"}))
game.step()
assert agent.reward_function.current_reward == -0.7
@@ -62,12 +62,12 @@ def test_uc2_rewards(game_and_agent: tuple[PrimaiteGame, ControlledAgent]):
server_1: Server = game.simulation.network.get_node_by_hostname("server_1")
server_1.software_manager.install(DatabaseService)
db_service = server_1.software_manager.software.get("DatabaseService")
db_service = server_1.software_manager.software.get("database-service")
db_service.start()
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(DatabaseClient)
db_client: DatabaseClient = client_1.software_manager.software.get("DatabaseClient")
db_client: DatabaseClient = client_1.software_manager.software.get("database-client")
db_client.configure(server_ip_address=server_1.network_interface[1].ip_address)
db_client.run()
@@ -79,11 +79,11 @@ def test_uc2_rewards(game_and_agent: tuple[PrimaiteGame, ControlledAgent]):
schema = GreenAdminDatabaseUnreachablePenalty.ConfigSchema(node_hostname="client_1", sticky=True)
comp = GreenAdminDatabaseUnreachablePenalty(config=schema)
request = ["network", "node", "client_1", "application", "DatabaseClient", "execute"]
request = ["network", "node", "client_1", "application", "database-client", "execute"]
response = game.simulation.apply_request(request)
state = game.get_sim_state()
ahi = AgentHistoryItem(
timestep=0, action="node_application_execute", parameters={}, request=request, response=response
timestep=0, action="node-application-execute", parameters={}, request=request, response=response
)
reward_value = comp.calculate(state, last_action_response=ahi)
assert reward_value == 1.0
@@ -94,7 +94,7 @@ def test_uc2_rewards(game_and_agent: tuple[PrimaiteGame, ControlledAgent]):
response = game.simulation.apply_request(request)
state = game.get_sim_state()
ahi = AgentHistoryItem(
timestep=0, action="node_application_execute", parameters={}, request=request, response=response
timestep=0, action="node-application-execute", parameters={}, request=request, response=response
)
reward_value = comp.calculate(
state,
@@ -154,13 +154,13 @@ def test_action_penalty():
# Penalty = ActionPenalty(action_penalty=-0.75, do_nothing_penalty=0.125)
Penalty = ActionPenalty(config=schema)
# Assert that penalty is applied if action isn't do_nothing
# Assert that penalty is applied if action isn't do-nothing
reward_value = Penalty.calculate(
state={},
last_action_response=AgentHistoryItem(
timestep=0,
action="node_application_execute",
parameters={"node_name": "client", "application_name": "WebBrowser"},
action="node-application-execute",
parameters={"node_name": "client", "application_name": "web-browser"},
request=["execute"],
response=RequestResponse.from_bool(True),
),
@@ -168,14 +168,14 @@ def test_action_penalty():
assert reward_value == -0.75
# Assert that no penalty applied for a do_nothing action
# Assert that no penalty applied for a do-nothing action
reward_value = Penalty.calculate(
state={},
last_action_response=AgentHistoryItem(
timestep=0,
action="do_nothing",
action="do-nothing",
parameters={},
request=["do_nothing"],
request=["do-nothing"],
response=RequestResponse.from_bool(True),
),
)
@@ -192,12 +192,12 @@ def test_action_penalty_e2e(game_and_agent: tuple[PrimaiteGame, ControlledAgent]
agent.reward_function.register_component(comp, 1.0)
action = ("do_nothing", {})
action = ("do-nothing", {})
agent.store_action(action)
game.step()
assert agent.reward_function.current_reward == 0.125
action = ("node_file_scan", {"node_name": "client", "folder_name": "downloads", "file_name": "document.pdf"})
action = ("node-file-scan", {"node_name": "client", "folder_name": "downloads", "file_name": "document.pdf"})
agent.store_action(action)
game.step()
assert agent.reward_function.current_reward == -0.75