update more tests to new actions schema

This commit is contained in:
Marek Wolan
2025-01-17 14:38:59 +00:00
parent 03cab0fcec
commit 858406c4a3
48 changed files with 351 additions and 413 deletions

View File

@@ -386,52 +386,52 @@ agents:
52: # old action num: 28
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 0
53: # old action num: 29
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 1
54: # old action num: 30
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 2
55: # old action num: 31
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 3
56: # old action num: 32
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 4
57: # old action num: 33
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 5
58: # old action num: 34
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 6
59: # old action num: 35
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 7
60: # old action num: 36
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 8
61: # old action num: 37
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 9
62: # old action num: 38
action: "host_nic_disable"

View File

@@ -39,10 +39,6 @@ agents:
node_name: client_2
application_name: WebBrowser
reward_function:
reward_components:
- type: DUMMY
agent_settings:
action_probabilities:
0: 0.4

View File

@@ -51,9 +51,6 @@ agents:
0: 0.4
1: 0.6
- ref: defender
team: BLUE
type: ProxyAgent

View File

@@ -477,52 +477,52 @@ agents:
52: # old action num: 28
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 0
53: # old action num: 29
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 1
54: # old action num: 30
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 2
55: # old action num: 31
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 3
56: # old action num: 32
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 4
57: # old action num: 33
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 5
58: # old action num: 34
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 6
59: # old action num: 35
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 7
60: # old action num: 36
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 8
61: # old action num: 37
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 9
62: # old action num: 38
action: "host_nic_disable"

View File

@@ -62,7 +62,7 @@ agents:
action: node_application_execute
options:
node_name: client_1
application_id: WebBrowser
application_name: WebBrowser
agent_settings:
action_probabilities:

View File

@@ -529,82 +529,82 @@ agents:
action: "host_nic_disable"
options:
node_name: domain_controller
nic_id: 0
nic_num: 1
63: # old action num: 39
action: "host_nic_enable"
options:
node_name: domain_controller
nic_id: 0
nic_num: 1
64: # old action num: 40
action: "host_nic_disable"
options:
node_name: web_server
nic_id: 0
nic_num: 1
65: # old action num: 41
action: "host_nic_enable"
options:
node_name: web_server
nic_id: 0
nic_num: 1
66: # old action num: 42
action: "host_nic_disable"
options:
node_name: database_server
nic_id: 0
nic_num: 1
67: # old action num: 43
action: "host_nic_enable"
options:
node_name: database_server
nic_id: 0
nic_num: 1
68: # old action num: 44
action: "host_nic_disable"
options:
node_name: backup_server
nic_id: 0
nic_num: 1
69: # old action num: 45
action: "host_nic_enable"
options:
node_name: backup_server
nic_id: 0
nic_num: 1
70: # old action num: 46
action: "host_nic_disable"
options:
node_name: security_suite
nic_id: 0
nic_num: 1
71: # old action num: 47
action: "host_nic_enable"
options:
node_name: security_suite
nic_id: 0
nic_num: 1
72: # old action num: 48
action: "host_nic_disable"
options:
node_name: security_suite
nic_id: 1
nic_num: 2
73: # old action num: 49
action: "host_nic_enable"
options:
node_name: security_suite
nic_id: 1
nic_num: 2
74: # old action num: 50
action: "host_nic_disable"
options:
node_name: client_1
nic_id: 0
nic_num: 1
75: # old action num: 51
action: "host_nic_enable"
options:
node_name: client_1
nic_id: 0
nic_num: 1
76: # old action num: 52
action: "host_nic_disable"
options:
node_name: client_2
nic_id: 0
nic_num: 1
77: # old action num: 53
action: "host_nic_enable"
options:
node_name: client_2
nic_id: 0
nic_num: 1

View File

@@ -109,12 +109,12 @@ agents:
position: 1
permission: PERMIT
src_ip: 192.168.0.10
dst_ip: 0.0.0.0
dst_ip: ALL
src_port: 80
dst_port: HTTP
protocol_name: TCP
src_wildcard: 0
dst_wildcard: 0
src_wildcard: NONE
dst_wildcard: NONE
2:
action: firewall_acl_remove_rule
options:
@@ -135,8 +135,8 @@ agents:
src_port: ARP
dst_port: DNS
protocol_name: ICMP
source_wildcard_id: 0
dest_wildcard_id: 0
src_wildcard: NONE
dst_wildcard: NONE
4:
action: firewall_acl_remove_rule
options:
@@ -157,8 +157,8 @@ agents:
src_port: HTTP
dst_port: HTTP
protocol_name: UDP
source_wildcard_id: 0
dest_wildcard_id: 0
src_wildcard: NONE
dst_wildcard: NONE
6:
action: firewall_acl_remove_rule
options:
@@ -179,8 +179,8 @@ agents:
src_port: HTTP
dst_port: HTTP
protocol_name: TCP
source_wildcard_id: 0
dest_wildcard_id: 0
src_wildcard: NONE
dst_wildcard: NONE
8:
action: firewall_acl_remove_rule
options:
@@ -201,8 +201,8 @@ agents:
src_port: POSTGRES_SERVER
dst_port: POSTGRES_SERVER
protocol_name: ICMP
source_wildcard_id: 0
dest_wildcard_id: 0
src_wildcard: NONE
dst_wildcard: NONE
10:
action: firewall_acl_remove_rule
options:
@@ -223,8 +223,8 @@ agents:
src_port: NONE
dst_port: NONE
protocol_name: none
source_wildcard_id: 0
dest_wildcard_id: 0
src_wildcard: NONE
dst_wildcard: NONE
12:
action: firewall_acl_remove_rule
options:
@@ -237,17 +237,14 @@ agents:
options:
type: network_port_disable
target_nodename: firewall
port_id: 3
port_num: 3
14:
action: network_port_enable
options:
type: network_port_enable
target_nodename: firewall
port_id: 3
agent_settings:
start_step: 5
frequency: 4
variance: 3
port_num: 3

View File

@@ -43,34 +43,30 @@ agents:
action: configure_database_client
options:
node_name: client_1
config:
server_ip_address: 10.0.0.5
server_ip_address: 10.0.0.5
5:
action: configure_database_client
options:
node_name: client_1
config:
server_password: correct_password
server_password: correct_password
6:
action: c2_server_ransomware_configure
options:
node_name: client_2
config:
server_ip_address: 10.0.0.5
server_password: correct_password
payload: ENCRYPT
server_ip_address: 10.0.0.5
server_password: correct_password
payload: ENCRYPT
7:
action: configure_dos_bot
options:
node_name: client_3
config:
target_ip_address: 10.0.0.5
target_port: POSTGRES_SERVER
payload: DELETE
repeat: true
port_scan_p_of_success: 1.0
dos_intensity: 1.0
max_sessions: 1000
target_ip_address: 10.0.0.5
target_port: POSTGRES_SERVER
payload: DELETE
repeat: true
port_scan_p_of_success: 1.0
dos_intensity: 1.0
max_sessions: 1000
8:
action: node_application_install
options:

View File

@@ -469,52 +469,52 @@ agents:
52: # old action num: 28
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 0
53: # old action num: 29
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 1
54: # old action num: 30
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 2
55: # old action num: 31
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 3
56: # old action num: 32
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 4
57: # old action num: 33
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 5
58: # old action num: 34
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 6
59: # old action num: 35
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 7
60: # old action num: 36
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 8
61: # old action num: 37
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 9
62: # old action num: 38
action: "host_nic_disable"
@@ -983,52 +983,52 @@ agents:
52: # old action num: 28
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 0
53: # old action num: 29
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 1
54: # old action num: 30
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 2
55: # old action num: 31
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 3
56: # old action num: 32
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 4
57: # old action num: 33
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 5
58: # old action num: 34
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 6
59: # old action num: 35
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 7
60: # old action num: 36
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 8
61: # old action num: 37
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 9
62: # old action num: 38
action: "host_nic_disable"

View File

@@ -28,7 +28,7 @@ agents:
0:
action: node_nmap_ping_scan
options:
node_name: client_1
source_node: client_1
target_ip_address: 192.168.1.0/24
show: False

View File

@@ -519,82 +519,82 @@ agents:
action: "host_nic_disable"
options:
node_name: domain_controller
nic_id: 0
nic_num: 1
63: # old action num: 39
action: "host_nic_enable"
options:
node_name: domain_controller
nic_id: 0
nic_num: 1
64: # old action num: 40
action: "host_nic_disable"
options:
node_name: web_server
nic_id: 0
nic_num: 1
65: # old action num: 41
action: "host_nic_enable"
options:
node_name: web_server
nic_id: 0
nic_num: 1
66: # old action num: 42
action: "host_nic_disable"
options:
node_name: database_server
nic_id: 0
nic_num: 1
67: # old action num: 43
action: "host_nic_enable"
options:
node_name: database_server
nic_id: 0
nic_num: 1
68: # old action num: 44
action: "host_nic_disable"
options:
node_name: backup_server
nic_id: 0
nic_num: 1
69: # old action num: 45
action: "host_nic_enable"
options:
node_name: backup_server
nic_id: 0
nic_num: 1
70: # old action num: 46
action: "host_nic_disable"
options:
node_name: security_suite
nic_id: 0
nic_num: 1
71: # old action num: 47
action: "host_nic_enable"
options:
node_name: security_suite
nic_id: 0
nic_num: 1
72: # old action num: 48
action: "host_nic_disable"
options:
node_name: security_suite
nic_id: 1
nic_num: 2
73: # old action num: 49
action: "host_nic_enable"
options:
node_name: security_suite
nic_id: 1
nic_num: 2
74: # old action num: 50
action: "host_nic_disable"
options:
node_name: client_1
nic_id: 0
nic_num: 1
75: # old action num: 51
action: "host_nic_enable"
options:
node_name: client_1
nic_id: 0
nic_num: 1
76: # old action num: 52
action: "host_nic_disable"
options:
node_name: client_2
nic_id: 0
nic_num: 1
77: # old action num: 53
action: "host_nic_enable"
options:
node_name: client_2
nic_id: 0
nic_num: 1
reward_function:
reward_components:

View File

@@ -472,52 +472,52 @@ agents:
52: # old action num: 28
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 0
53: # old action num: 29
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 1
54: # old action num: 30
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 2
55: # old action num: 31
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 3
56: # old action num: 32
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 4
57: # old action num: 33
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 5
58: # old action num: 34
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 6
59: # old action num: 35
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 7
60: # old action num: 36
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 8
61: # old action num: 37
action: "router_acl_remove_rule"
options:
target_router_hostname: router_1
target_router: router_1
position: 9
62: # old action num: 38
action: "host_nic_disable"
@@ -618,14 +618,13 @@ agents:
action: node_application_execute
options:
node_name: domain_controller
application_id: 0
application_name: DoSBot
82:
action: configure_dos_bot
options:
node_name: domain_controller
config:
target_ip_address: 192.168.1.14
target_port: POSTGRES_SERVER
target_ip_address: 192.168.1.14
target_port: POSTGRES_SERVER
reward_function:
reward_components:

View File

@@ -33,22 +33,22 @@ def test_application_cannot_perform_actions_unless_running(game_and_agent_fixtur
browser.close()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_scan", {"node_id": 0, "application_id": 0})
action = ("node_application_scan", {"node_name": "client_1", "application_name": "WebBrowser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_close", {"node_id": 0, "application_id": 0})
action = ("node_application_close", {"node_name": "client_1", "application_name": "WebBrowser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_fix", {"node_id": 0, "application_id": 0})
action = ("node_application_fix", {"node_name": "client_1", "application_name": "WebBrowser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED
action = ("node_application_execute", {"node_id": 0, "application_id": 0})
action = ("node_application_execute", {"node_name": "client_1", "application_name": "WebBrowser"})
agent.store_action(action)
game.step()
assert browser.operating_state == ApplicationOperatingState.CLOSED

View File

@@ -47,7 +47,7 @@ def test_c2_beacon_default(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgen
action = (
"node_application_install",
{"node_id": 1, "application_name": "C2Beacon"},
{"node_name": "server_1", "application_name": "C2Beacon"},
)
agent.store_action(action)
game.step()
@@ -56,13 +56,11 @@ def test_c2_beacon_default(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgen
action = (
"configure_c2_beacon",
{
"node_id": 1,
"config": {
"c2_server_ip_address": "10.0.1.2",
"keep_alive_frequency": 5,
"masquerade_protocol": "TCP",
"masquerade_port": "HTTP",
},
"node_name": "server_1",
"c2_server_ip_address": "10.0.1.2",
"keep_alive_frequency": 5,
"masquerade_protocol": "TCP",
"masquerade_port": "HTTP",
},
)
agent.store_action(action)
@@ -71,7 +69,7 @@ def test_c2_beacon_default(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgen
action = (
"node_application_execute",
{"node_id": 1, "application_id": 0},
{"node_name": "server_1", "application_name": "C2Beacon"},
)
agent.store_action(action)
game.step()
@@ -103,14 +101,12 @@ 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_id": 0,
"node_name": "client_1",
"ip_address": None,
"account": {
"username": "admin",
"password": "admin",
},
"username": "admin",
"password": "admin",
"commands": [
["software_manager", "application", "install", "RansomwareScript"],
["software_manager", "application", "install", "DatabaseClient"],
@@ -124,7 +120,7 @@ def test_c2_server_ransomware(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
action = (
"c2_server_ransomware_configure",
{
"node_id": 0,
"node_name": "client_1",
"config": {"server_ip_address": "10.0.2.3", "payload": "ENCRYPT"},
},
)
@@ -143,7 +139,7 @@ def test_c2_server_ransomware(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
action = (
"c2_server_ransomware_launch",
{
"node_id": 0,
"node_name": "client_1",
},
)
agent.store_action(action)
@@ -183,15 +179,13 @@ def test_c2_server_data_exfiltration(game_and_agent_fixture: Tuple[PrimaiteGame,
action = (
"c2_server_data_exfiltrate",
{
"node_id": 0,
"node_name": "client_1",
"target_file_name": "database.db",
"target_folder_name": "database",
"exfiltration_folder_name": "spoils",
"target_ip_address": "10.0.2.3",
"account": {
"username": "admin",
"password": "admin",
},
"username": "admin",
"password": "admin",
},
)
agent.store_action(action)

View File

@@ -27,7 +27,6 @@ class TestConfigureDatabaseAction:
def test_configure_ip_password(self, game_and_agent):
game, agent = game_and_agent
agent: ControlledAgent
agent.action_manager.actions["configure_database_client"] = ConfigureDatabaseClientAction(agent.action_manager)
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
@@ -38,10 +37,8 @@ class TestConfigureDatabaseAction:
"configure_database_client",
{
"node_name": "client_1",
"model_config": {
"server_ip_address": "192.168.1.99",
"server_password": "admin123",
},
"server_ip_address": "192.168.1.99",
"server_password": "admin123",
},
)
agent.store_action(action)
@@ -53,7 +50,6 @@ class TestConfigureDatabaseAction:
def test_configure_ip(self, game_and_agent):
game, agent = game_and_agent
agent: ControlledAgent
agent.action_manager.actions["configure_database_client"] = ConfigureDatabaseClientAction(agent.action_manager)
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
@@ -63,10 +59,8 @@ class TestConfigureDatabaseAction:
action = (
"configure_database_client",
{
"node_id": 0,
"config": {
"server_ip_address": "192.168.1.99",
},
"node_name": "client_1",
"server_ip_address": "192.168.1.99",
},
)
agent.store_action(action)
@@ -78,7 +72,6 @@ class TestConfigureDatabaseAction:
def test_configure_password(self, game_and_agent):
game, agent = game_and_agent
agent: ControlledAgent
agent.action_manager.actions["configure_database_client"] = ConfigureDatabaseClientAction(agent.action_manager)
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
@@ -89,10 +82,8 @@ class TestConfigureDatabaseAction:
action = (
"configure_database_client",
{
"node_id": 0,
"config": {
"server_password": "admin123",
},
"node_name": "client_1",
"server_password": "admin123",
},
)
agent.store_action(action)
@@ -120,9 +111,6 @@ class TestConfigureRansomwareScriptAction:
def test_configure_ip_password(self, game_and_agent, config):
game, agent = game_and_agent
agent: ControlledAgent
agent.action_manager.actions["c2_server_ransomware_configure"] = ConfigureRansomwareScriptAction(
agent.action_manager
)
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
@@ -135,7 +123,7 @@ class TestConfigureRansomwareScriptAction:
action = (
"c2_server_ransomware_configure",
{"node_id": 0, "config": config},
{"node_name": "client_1", **config},
)
agent.store_action(action)
game.step()
@@ -151,9 +139,6 @@ class TestConfigureRansomwareScriptAction:
def test_invalid_config(self, game_and_agent):
game, agent = game_and_agent
agent: ControlledAgent
agent.action_manager.actions["c2_server_ransomware_configure"] = ConfigureRansomwareScriptAction(
agent.action_manager
)
# make sure there is a database client on this node
client_1 = game.simulation.network.get_node_by_hostname("client_1")
@@ -162,7 +147,7 @@ class TestConfigureRansomwareScriptAction:
action = (
"c2_server_ransomware_configure",
{
"node_id": 0,
"node_name": "client_1",
"config": {"server_password": "admin123", "bad_option": 70},
},
)
@@ -175,7 +160,6 @@ class TestConfigureDoSBot:
def test_configure_dos_bot(self, game_and_agent):
game, agent = game_and_agent
agent: ControlledAgent
agent.action_manager.actions["configure_dos_bot"] = ConfigureDoSBotAction(agent.action_manager)
client_1 = game.simulation.network.get_node_by_hostname("client_1")
client_1.software_manager.install(DoSBot)
@@ -184,16 +168,14 @@ class TestConfigureDoSBot:
action = (
"configure_dos_bot",
{
"node_id": 0,
"config": {
"target_ip_address": "192.168.1.99",
"target_port": "POSTGRES_SERVER",
"payload": "HACC",
"repeat": False,
"port_scan_p_of_success": 0.875,
"dos_intensity": 0.75,
"max_sessions": 50,
},
"node_name": "client_1",
"target_ip_address": "192.168.1.99",
"target_port": "POSTGRES_SERVER",
"payload": "HACC",
"repeat": False,
"port_scan_p_of_success": 0.875,
"dos_intensity": 0.75,
"max_sessions": 50,
},
)
agent.store_action(action)

View File

@@ -34,7 +34,7 @@ def test_create_file(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
action = (
"node_file_create",
{"node_id": 0, "folder_name": random_folder, "file_name": random_file},
{"node_name": "client_1", "folder_name": random_folder, "file_name": random_file},
)
agent.store_action(action)
game.step()
@@ -52,7 +52,7 @@ def test_file_delete_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
action = (
"node_file_delete",
{"node_id": 0, "folder_id": 0, "file_id": 0},
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
game.step()
@@ -73,7 +73,7 @@ def test_file_scan_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent
action = (
"node_file_scan",
{"node_id": 0, "folder_id": 0, "file_id": 0},
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
game.step()
@@ -94,7 +94,7 @@ def test_file_repair_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
action = (
"node_file_repair",
{"node_id": 0, "folder_id": 0, "file_id": 0},
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
game.step()
@@ -114,7 +114,7 @@ def test_file_restore_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAg
action = (
"node_file_restore",
{"node_id": 0, "folder_id": 0, "file_id": 0},
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
game.step()
@@ -133,7 +133,7 @@ def test_file_corrupt_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAg
action = (
"node_file_corrupt",
{"node_id": 0, "folder_id": 0, "file_id": 0},
{"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
)
agent.store_action(action)
game.step()
@@ -151,7 +151,7 @@ def test_file_access_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
action = (
"node_file_access",
{"node_id": 0, "folder_name": file.folder_name, "file_name": file.name},
{"node_name": "client_1", "folder_name": file.folder_name, "file_name": file.name},
)
agent.store_action(action)
game.step()

View File

@@ -34,7 +34,7 @@ def test_create_folder(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
action = (
"node_folder_create",
{
"node_id": 0,
"node_name": "client_1",
"folder_name": random_folder,
},
)
@@ -62,8 +62,8 @@ def test_folder_scan_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAge
action = (
"node_folder_scan",
{
"node_id": 0, # client_1,
"folder_id": 0, # downloads
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads
},
)
agent.store_action(action)
@@ -89,8 +89,8 @@ def test_folder_repair_action(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyA
action = (
"node_folder_repair",
{
"node_id": 0, # client_1,
"folder_id": 0, # downloads
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads
},
)
agent.store_action(action)
@@ -113,8 +113,8 @@ def test_folder_restore_action(game_and_agent_fixture: Tuple[PrimaiteGame, Proxy
action = (
"node_folder_restore",
{
"node_id": 0, # client_1,
"folder_id": 0, # downloads
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads
},
)
agent.store_action(action)

View File

@@ -31,8 +31,8 @@ def test_nic_cannot_be_turned_off_if_not_on(game_and_agent_fixture: Tuple[Primai
action = (
"host_nic_disable",
{
"node_id": 0, # client_1
"nic_id": 0, # the only nic (eth-1)
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
},
)
agent.store_action(action)
@@ -52,8 +52,8 @@ def test_nic_cannot_be_turned_on_if_already_on(game_and_agent_fixture: Tuple[Pri
action = (
"host_nic_enable",
{
"node_id": 0, # client_1
"nic_id": 0, # the only nic (eth-1)
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
},
)
agent.store_action(action)
@@ -73,8 +73,8 @@ def test_that_a_nic_can_be_enabled_and_disabled(game_and_agent_fixture: Tuple[Pr
action = (
"host_nic_disable",
{
"node_id": 0, # client_1
"nic_id": 0, # the only nic (eth-1)
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
},
)
agent.store_action(action)
@@ -85,8 +85,8 @@ def test_that_a_nic_can_be_enabled_and_disabled(game_and_agent_fixture: Tuple[Pr
action = (
"host_nic_enable",
{
"node_id": 0, # client_1
"nic_id": 0, # the only nic (eth-1)
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
},
)
agent.store_action(action)

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_id": 0})
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", {"node_id": 0})
action = ("do_nothing", {})
agent.store_action(action)
game.step()
assert client_1.operating_state == NodeOperatingState.OFF
# turn it on
action = ("node_startup", {"node_id": 0})
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", {"node_id": 0})
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_id": 0})
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", {"node_id": 0})
action = ("do_nothing", {})
agent.store_action(action)
game.step()
assert client_1.operating_state == NodeOperatingState.OFF
# turn it ff
action = ("node_shutdown", {"node_id": 0})
action = ("node_shutdown", {"node_name": "client_1"})
agent.store_action(action)
game.step()

View File

@@ -31,7 +31,7 @@ def test_service_start(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
dns_server.pause()
assert dns_server.operating_state == ServiceOperatingState.PAUSED
action = ("node_service_start", {"node_id": 1, "service_id": 0})
action = ("node_service_start", {"node_name": "server_1", "service_name": "DNSServer"})
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_id": 1, "service_id": 0})
action = ("node_service_start", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
@@ -54,7 +54,7 @@ def test_service_resume(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent])
server_1: Server = game.simulation.network.get_node_by_hostname("server_1")
dns_server = server_1.software_manager.software.get("DNSServer")
action = ("node_service_resume", {"node_id": 1, "service_id": 0})
action = ("node_service_resume", {"node_name": "server_1", "service_name": "DNSServer"})
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_id": 1, "service_id": 0})
action = ("node_service_resume", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
@@ -80,27 +80,27 @@ def test_service_cannot_perform_actions_unless_running(game_and_agent_fixture: T
dns_server.stop()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_scan", {"node_id": 1, "service_id": 0})
action = ("node_service_scan", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_pause", {"node_id": 1, "service_id": 0})
action = ("node_service_pause", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_resume", {"node_id": 1, "service_id": 0})
action = ("node_service_resume", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_restart", {"node_id": 1, "service_id": 0})
action = ("node_service_restart", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED
action = ("node_service_fix", {"node_id": 1, "service_id": 0})
action = ("node_service_fix", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
assert dns_server.operating_state == ServiceOperatingState.STOPPED

View File

@@ -36,9 +36,9 @@ def test_remote_login(game_and_agent_fixture: Tuple[PrimaiteGame, ProxyAgent]):
server_1_usm.add_user("user123", "password", is_admin=True)
action = (
"SSH_TO_REMOTE",
"node_session_remote_login",
{
"node_id": 0,
"node_name": "client_1",
"username": "user123",
"password": "password",
"remote_ip": str(server_1.network_interface[1].ip_address),
@@ -68,9 +68,9 @@ def test_remote_login_wrong_password(game_and_agent_fixture: Tuple[PrimaiteGame,
server_1_usm.add_user("user123", "password", is_admin=True)
action = (
"SSH_TO_REMOTE",
"node_session_remote_login",
{
"node_id": 0,
"node_name": "client_1",
"username": "user123",
"password": "wrong_password",
"remote_ip": str(server_1.network_interface[1].ip_address),
@@ -100,12 +100,13 @@ def test_remote_login_change_password(game_and_agent_fixture: Tuple[PrimaiteGame
server_1_um.add_user("user123", "password", is_admin=True)
action = (
"node_accounts_change_password",
"node_account_change_password",
{
"node_id": 1, # server_1
"node_name": "server_1", # server_1
"username": "user123",
"current_password": "password",
"new_password": "different_password",
"remote_ip": str(server_1.network_interface[1].ip_address),
},
)
agent.store_action(action)
@@ -126,9 +127,9 @@ def test_change_password_logs_out_user(game_and_agent_fixture: Tuple[PrimaiteGam
# Log in remotely
action = (
"SSH_TO_REMOTE",
"node_session_remote_login",
{
"node_id": 0,
"node_name": "client_1",
"username": "user123",
"password": "password",
"remote_ip": str(server_1.network_interface[1].ip_address),
@@ -139,12 +140,13 @@ def test_change_password_logs_out_user(game_and_agent_fixture: Tuple[PrimaiteGam
# Change password
action = (
"node_accounts_change_password",
"node_account_change_password",
{
"node_id": 1, # server_1
"node_name": "server_1", # server_1
"username": "user123",
"current_password": "password",
"new_password": "different_password",
"remote_ip": str(server_1.network_interface[1].ip_address),
},
)
agent.store_action(action)
@@ -154,7 +156,7 @@ def test_change_password_logs_out_user(game_and_agent_fixture: Tuple[PrimaiteGam
action = (
"node_send_remote_command",
{
"node_id": 0,
"node_name": "client_1",
"remote_ip": str(server_1.network_interface[1].ip_address),
"command": ["file_system", "create", "file", "folder123", "doggo.pdf", False],
},

View File

@@ -25,7 +25,7 @@ def test_mask_contents_correct():
if act_type == "node_nic_enable":
node_name = act_params["node_name"]
node_obj = net.get_node_by_hostname(node_name)
nic_obj = node_obj.network_interface[act_params["nic_id"] + 1]
nic_obj = node_obj.network_interface[act_params["nic_num"]]
assert nic_obj.enabled
assert not mask[action_num]
nic_obj.disable()
@@ -36,7 +36,7 @@ def test_mask_contents_correct():
if act_type == "node_nic_disable":
node_name = act_params["node_name"]
node_obj = net.get_node_by_hostname(node_name)
nic_obj = node_obj.network_interface[act_params["nic_id"] + 1]
nic_obj = node_obj.network_interface[act_params["nic_num"]]
assert nic_obj.enabled
assert mask[action_num]
nic_obj.disable()

View File

@@ -56,7 +56,7 @@ def test_node_service_scan_integration(game_and_agent: Tuple[PrimaiteGame, Proxy
assert svc.health_state_visible == SoftwareHealthState.UNUSED
# 2: Scan and check that the visible state is now correct
action = ("node_service_scan", {"type": "node_service_scan", "node_name": "server_1", "service_name": "DNSServer"})
action = ("node_service_scan", {"node_name": "server_1", "service_name": "DNSServer"})
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", {"type": "node_service_scan", "node_name": "server_1", "service_name": "DNSServer"})
action = ("node_service_scan", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
assert svc.health_state_actual == SoftwareHealthState.COMPROMISED
@@ -88,7 +88,7 @@ def test_node_service_fix_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
svc.health_state_actual = SoftwareHealthState.COMPROMISED
# 2: Apply a patch action
action = ("node_service_fix", {"type": "node_service_fix", "node_name": "server_1", "service_name": "DNSServer"})
action = ("node_service_fix", {"node_name": "server_1", "service_name": "DNSServer"})
agent.store_action(action)
game.step()
@@ -123,7 +123,6 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
action = (
"router_acl_add_rule",
{
"type": "router_acl_add_rule",
"target_router": "router",
"position": 4,
"permission": "DENY",
@@ -151,7 +150,6 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
action = (
"router_acl_add_rule",
{
"type": "router_acl_add_rule",
"target_router": "router",
"position": 5, # 5th rule
"permission": "DENY", # DENY
@@ -192,7 +190,6 @@ def test_router_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, P
action = (
"router_acl_remove_rule",
{
"type": "router_acl_remove_rule",
"target_router": "router",
"position": 3, # 4th rule
},
@@ -226,7 +223,6 @@ def test_host_nic_disable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
action = (
"host_nic_disable",
{
"type": "host_nic_disable",
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
},
@@ -258,7 +254,6 @@ def test_host_nic_enable_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAg
action = (
"host_nic_enable",
{
"type": "host_nic_enable",
"node_name": "client_1", # client_1
"nic_num": 1, # the only nic (eth-1)
},
@@ -286,7 +281,6 @@ def test_node_file_scan_integration(game_and_agent: Tuple[PrimaiteGame, ProxyAge
action = (
"node_file_scan",
{
"type": "node_file_scan",
"node_name": "client_1", # client_1,
"folder_name": "downloads", # downloads,
"file_name": "cat.png", # cat.png
@@ -324,7 +318,6 @@ def test_node_file_delete_integration(game_and_agent: Tuple[PrimaiteGame, ProxyA
action = (
"node_file_delete",
{
"type": "node_file_delete",
"node_name": "client_1", # client_1
"folder_name": "downloads", # downloads
"file_name": "cat.png", # cat.png
@@ -348,7 +341,6 @@ def test_node_file_create(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
action = (
"node_file_create",
{
"type": "node_file_create",
"node_name": "client_1",
"folder_name": "test",
"file_name": "file.txt",
@@ -370,7 +362,6 @@ def test_node_file_access(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
action = (
"node_file_create",
{
"type": "node_file_create",
"node_name": "client_1",
"folder_name": "test",
"file_name": "file.txt",
@@ -384,7 +375,6 @@ def test_node_file_access(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
action = (
"node_file_access",
{
"type": "node_file_access",
"node_name": "client_1",
"folder_name": "test",
"file_name": "file.txt",
@@ -405,7 +395,6 @@ def test_node_folder_create(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
action = (
"node_folder_create",
{
"type": "node_folder_create",
"node_name": "client_1",
"folder_name": "test",
},
@@ -434,7 +423,6 @@ def test_network_router_port_disable_integration(game_and_agent: Tuple[PrimaiteG
action = (
"network_port_disable",
{
"type": "network_port_disable",
"target_nodename": "router", # router
"port_id": 1, # port 1
},
@@ -467,7 +455,6 @@ def test_network_router_port_enable_integration(game_and_agent: Tuple[PrimaiteGa
action = (
"network_port_enable",
{
"type": "network_port_enable",
"target_nodename": "router", # router
"port_id": 1, # port 1
},
@@ -498,7 +485,7 @@ 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",
{"type": "node_application_scan", "node_name": "client_1", "application_name": "WebBrowser"},
{"node_name": "client_1", "application_name": "WebBrowser"},
)
agent.store_action(action)
game.step()
@@ -512,7 +499,7 @@ 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",
{"type": "node_application_scan", "node_name": "client_1", "application_name": "WebBrowser"},
{"node_name": "client_1", "application_name": "WebBrowser"},
)
agent.store_action(action)
game.step()
@@ -536,7 +523,7 @@ def test_node_application_fix_integration(game_and_agent: Tuple[PrimaiteGame, Pr
# 2: Apply a fix action
action = (
"node_application_fix",
{"type": "node_application_fix", "node_name": "client_1", "application_name": "WebBrowser"},
{"node_name": "client_1", "application_name": "WebBrowser"},
)
agent.store_action(action)
game.step()
@@ -565,7 +552,7 @@ def test_node_application_close_integration(game_and_agent: Tuple[PrimaiteGame,
# 2: Apply a close action
action = (
"node_application_close",
{"type": "node_application_close", "node_name": "client_1", "application_name": "WebBrowser"},
{"node_name": "client_1", "application_name": "WebBrowser"},
)
agent.store_action(action)
game.step()
@@ -587,7 +574,7 @@ def test_node_application_install_and_uninstall_integration(game_and_agent: Tupl
action = (
"node_application_install",
{"type": "node_application_install", "node_name": "client_1", "application_name": "DoSBot"},
{"node_name": "client_1", "application_name": "DoSBot"},
)
agent.store_action(action)
game.step()
@@ -596,7 +583,7 @@ def test_node_application_install_and_uninstall_integration(game_and_agent: Tupl
action = (
"node_application_remove",
{"type": "node_application_remove", "node_name": "client_1", "application_name": "DoSBot"},
{"node_name": "client_1", "application_name": "DoSBot"},
)
agent.store_action(action)
game.step()

View File

@@ -38,7 +38,7 @@ def test_WebpageUnavailablePenalty(game_and_agent: tuple[PrimaiteGame, Controlle
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_id": 0, "application_id": 0}))
agent.store_action(("node_application_execute", {"node_name": "client_1", "application_name": "WebBrowser"}))
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_id": 0, "application_id": 0}))
agent.store_action(("node_application_execute", {"node_name": "client_1", "application_name": "WebBrowser"}))
game.step()
assert agent.reward_function.current_reward == -0.7
@@ -160,7 +160,7 @@ def test_action_penalty():
last_action_response=AgentHistoryItem(
timestep=0,
action="node_application_execute",
parameters={"node_id": 0, "application_id": 1},
parameters={"node_name": "client", "application_name": "WebBrowser"},
request=["execute"],
response=RequestResponse.from_bool(True),
),
@@ -197,7 +197,7 @@ def test_action_penalty_e2e(game_and_agent: tuple[PrimaiteGame, ControlledAgent]
game.step()
assert agent.reward_function.current_reward == 0.125
action = ("node_file_scan", {"node_id": 0, "folder_id": 0, "file_id": 0})
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

View File

@@ -2,6 +2,7 @@
from unittest.mock import Mock
import pytest
from pydantic import ValidationError
from primaite.game.agent.actions import ActionManager
from primaite.game.agent.actions.manager import DoNothingAction
@@ -37,7 +38,7 @@ def test_do_nothing_action_form_request():
],
) # flake8: noqa
@pytest.mark.parametrize(
"node_name, service_name, expect_to_do_nothing",
"node_name, service_name, expect_failure",
[
("pc_1", "chrome", False),
(None, "chrome", True),
@@ -45,34 +46,15 @@ def test_do_nothing_action_form_request():
(None, None, True),
],
) # flake8: noqa
def test_service_action_form_request(node_name, service_name, expect_to_do_nothing, action_class, action_verb):
def test_service_action_form_request(node_name, service_name, expect_failure, action_class, action_verb):
"""Test that the ServiceScanAction can form a request and that it is correct."""
request = action_class.form_request(
config=action_class.ConfigSchema(node_name=node_name, service_name=service_name)
)
if expect_to_do_nothing:
assert request == ["do_nothing"]
if expect_failure:
with pytest.raises(ValidationError):
request = action_class.form_request(
config=action_class.ConfigSchema(node_name=node_name, service_name=service_name)
)
else:
request = action_class.form_request(
config=action_class.ConfigSchema(node_name=node_name, service_name=service_name)
)
assert request == ["network", "node", node_name, "service", service_name, action_verb]
@pytest.mark.parametrize(
"node_name, service_name, expect_to_do_nothing",
[
("pc_1", "chrome", False),
(None, "chrome", True),
("pc_1", None, True),
(None, None, True),
],
) # flake8: noqa
def test_service_scan_form_request(node_name, service_name, expect_to_do_nothing):
"""Test that the ServiceScanAction can form a request and that it is correct."""
request = NodeServiceScanAction.form_request(
NodeServiceScanAction.ConfigSchema(node_id=node_name, service_id=service_name)
)
if expect_to_do_nothing:
assert request == ["do_nothing"]
else:
assert request == ["network", "node", node_name, "service", service_name, "scan"]

View File

@@ -39,6 +39,8 @@ def test_creating_agent_from_dict():
}
agent = RandomAgent(
config={
"ref": "random_agent",
"team": "BLUE",
"action_space": action_config,
"observation_space": observation_config,
"reward_function": reward_config,

View File

@@ -98,7 +98,7 @@ class TestFileSystemRequiresScan:
"""
cfg = yaml.safe_load(obs_cfg_yaml)
manager = ObservationManager(cfg)
manager = ObservationManager(config=cfg)
hosts: List[HostObservation] = manager.obs.components["NODES"].hosts
for i, host in enumerate(hosts):

View File

@@ -92,7 +92,7 @@ class TestWebpageUnavailabilitySticky:
# agent did a successful fetch
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
response = RequestResponse(status="success", data={})
browser_history.append({"outcome": 200})
@@ -115,7 +115,7 @@ class TestWebpageUnavailabilitySticky:
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
@@ -127,7 +127,7 @@ class TestWebpageUnavailabilitySticky:
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
@@ -153,7 +153,7 @@ class TestWebpageUnavailabilitySticky:
# agent did a successful fetch
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
response = RequestResponse(status="success", data={})
browser_history.append({"outcome": 200})
@@ -175,7 +175,7 @@ class TestWebpageUnavailabilitySticky:
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
@@ -187,7 +187,7 @@ class TestWebpageUnavailabilitySticky:
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
@@ -217,7 +217,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
# agent did a successful fetch
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
@@ -238,7 +238,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
@@ -249,7 +249,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
@@ -276,7 +276,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
# agent did a successful fetch
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
@@ -297,7 +297,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
@@ -308,7 +308,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_id": 0, "application_id": 0}
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}