Update configs to new action naming schema and remove redundant agent config
This commit is contained in:
@@ -19,12 +19,7 @@ from primaite.game.agent.actions.service import (
|
||||
|
||||
def test_do_nothing_action_form_request():
|
||||
"""Test that the do_nothingAction can form a request and that it is correct."""
|
||||
manager = Mock()
|
||||
|
||||
action = DoNothingAction(manager=manager)
|
||||
|
||||
request = action.form_request()
|
||||
|
||||
request = DoNothingAction.form_request(DoNothingAction.ConfigSchema())
|
||||
assert request == ["do_nothing"]
|
||||
|
||||
|
||||
@@ -52,13 +47,9 @@ def test_do_nothing_action_form_request():
|
||||
) # flake8: noqa
|
||||
def test_service_action_form_request(node_name, service_name, expect_to_do_nothing, action_class, action_verb):
|
||||
"""Test that the ServiceScanAction can form a request and that it is correct."""
|
||||
manager: ActionManager = Mock()
|
||||
manager.get_node_name_by_idx.return_value = node_name
|
||||
manager.get_service_name_by_idx.return_value = service_name
|
||||
|
||||
action = action_class(manager=manager, num_nodes=1, num_services=1)
|
||||
|
||||
request = action.form_request(node_id=0, service_id=0)
|
||||
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"]
|
||||
@@ -77,13 +68,9 @@ def test_service_action_form_request(node_name, service_name, expect_to_do_nothi
|
||||
) # 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."""
|
||||
manager: ActionManager = Mock()
|
||||
manager.get_node_name_by_idx.return_value = node_name
|
||||
manager.get_service_name_by_idx.return_value = service_name
|
||||
|
||||
action = NodeServiceScanAction(manager=manager, num_nodes=1, num_services=1)
|
||||
|
||||
request = action.form_request(node_id=0, service_id=0)
|
||||
request = NodeServiceScanAction.form_request(
|
||||
NodeServiceScanAction.ConfigSchema(node_id=node_name, service_id=service_name)
|
||||
)
|
||||
|
||||
if expect_to_do_nothing:
|
||||
assert request == ["do_nothing"]
|
||||
|
||||
@@ -98,7 +98,7 @@ class TestFileSystemRequiresScan:
|
||||
"""
|
||||
|
||||
cfg = yaml.safe_load(obs_cfg_yaml)
|
||||
manager = ObservationManager.from_config(cfg)
|
||||
manager = ObservationManager(cfg)
|
||||
|
||||
hosts: List[HostObservation] = manager.obs.components["NODES"].hosts
|
||||
for i, host in enumerate(hosts):
|
||||
|
||||
@@ -17,39 +17,39 @@ def test_probabilistic_agent():
|
||||
"""
|
||||
N_TRIALS = 10_000
|
||||
P_DO_NOTHING = 0.1
|
||||
P_NODE_APPLICATION_EXECUTE = 0.3
|
||||
P_NODE_FILE_DELETE = 0.6
|
||||
P_node_application_execute = 0.3
|
||||
P_node_file_delete = 0.6
|
||||
MIN_DO_NOTHING = 850
|
||||
MAX_DO_NOTHING = 1150
|
||||
MIN_NODE_APPLICATION_EXECUTE = 2800
|
||||
MAX_NODE_APPLICATION_EXECUTE = 3200
|
||||
MIN_NODE_FILE_DELETE = 5750
|
||||
MAX_NODE_FILE_DELETE = 6250
|
||||
MIN_node_application_execute = 2800
|
||||
MAX_node_application_execute = 3200
|
||||
MIN_node_file_delete = 5750
|
||||
MAX_node_file_delete = 6250
|
||||
|
||||
action_space_cfg = {
|
||||
"act_map": {
|
||||
"action_map": {
|
||||
0: {"action": "do_nothing", "options": {}},
|
||||
1: {"action": "node_application_execute", "options": {"node_id": 0, "application_id": 0}},
|
||||
2: {"action": "node_file_delete", "options": {"node_id": 0, "folder_id": 0, "file_id": 0}},
|
||||
1: {
|
||||
"action": "node_application_execute",
|
||||
"options": {"node_name": "client_1", "application_name": "WebBrowser"},
|
||||
},
|
||||
2: {
|
||||
"action": "node_file_delete",
|
||||
"options": {"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
|
||||
},
|
||||
},
|
||||
"options": {},
|
||||
}
|
||||
|
||||
game = PrimaiteGame()
|
||||
game.options = PrimaiteGameOptions(ports=[], protocols=[])
|
||||
|
||||
observation_space_cfg = None
|
||||
|
||||
reward_function_cfg = {}
|
||||
|
||||
pa_config = {
|
||||
"type": "ProbabilisticAgent",
|
||||
"game": game,
|
||||
"ref": "ProbabilisticAgent",
|
||||
"team": "BLUE",
|
||||
"action_space": action_space_cfg,
|
||||
"observation_space": observation_space_cfg,
|
||||
"reward_function": reward_function_cfg,
|
||||
"agent_settings": {
|
||||
"action_probabilities": {0: P_DO_NOTHING, 1: P_NODE_APPLICATION_EXECUTE, 2: P_NODE_FILE_DELETE},
|
||||
"action_probabilities": {0: P_DO_NOTHING, 1: P_node_application_execute, 2: P_node_file_delete},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -70,5 +70,5 @@ def test_probabilistic_agent():
|
||||
raise AssertionError("Probabilistic agent produced an unexpected action.")
|
||||
|
||||
assert MIN_DO_NOTHING < do_nothing_count < MAX_DO_NOTHING
|
||||
assert MIN_NODE_APPLICATION_EXECUTE < node_application_execute_count < MAX_NODE_APPLICATION_EXECUTE
|
||||
assert MIN_NODE_FILE_DELETE < node_file_delete_count < MAX_NODE_FILE_DELETE
|
||||
assert MIN_node_application_execute < node_application_execute_count < MAX_node_application_execute
|
||||
assert MIN_node_file_delete < node_file_delete_count < MAX_node_file_delete
|
||||
|
||||
@@ -91,7 +91,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
assert reward.calculate(state, last_action_response) == 0
|
||||
|
||||
# agent did a successful fetch
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
@@ -104,7 +104,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
|
||||
# THE IMPORTANT BIT
|
||||
# agent did nothing, because reward is not sticky, it goes back to 0
|
||||
action, params, request = "DO_NOTHING", {}, ["do_nothing"]
|
||||
action, params, request = "do_nothing", {}, ["do_nothing"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
browser_history = []
|
||||
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
|
||||
@@ -114,7 +114,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
assert reward.calculate(state, last_action_response) == 0.0
|
||||
|
||||
# agent fails to fetch, get a -1.0 reward
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
@@ -126,7 +126,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
assert reward.calculate(state, last_action_response) == -1.0
|
||||
|
||||
# agent fails again to fetch, get a -1.0 reward again
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
@@ -142,7 +142,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
reward = WebpageUnavailablePenalty(config=schema)
|
||||
|
||||
# no response codes yet, reward is 0
|
||||
action, params, request = "DO_NOTHING", {}, ["do_nothing"]
|
||||
action, params, request = "do_nothing", {}, ["do_nothing"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
browser_history = []
|
||||
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
|
||||
@@ -152,7 +152,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
assert reward.calculate(state, last_action_response) == 0
|
||||
|
||||
# agent did a successful fetch
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
@@ -165,7 +165,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
|
||||
# THE IMPORTANT BIT
|
||||
# agent did nothing, because reward is sticky, it stays at 1.0
|
||||
action, params, request = "DO_NOTHING", {}, ["do_nothing"]
|
||||
action, params, request = "do_nothing", {}, ["do_nothing"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
|
||||
last_action_response = AgentHistoryItem(
|
||||
@@ -174,7 +174,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
assert reward.calculate(state, last_action_response) == 1.0
|
||||
|
||||
# agent fails to fetch, get a -1.0 reward
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
@@ -186,7 +186,7 @@ class TestWebpageUnavailabilitySticky:
|
||||
assert reward.calculate(state, last_action_response) == -1.0
|
||||
|
||||
# agent fails again to fetch, get a -1.0 reward again
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
@@ -207,7 +207,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
reward = GreenAdminDatabaseUnreachablePenalty(config=schema)
|
||||
|
||||
# no response codes yet, reward is 0
|
||||
action, params, request = "DO_NOTHING", {}, ["do_nothing"]
|
||||
action, params, request = "do_nothing", {}, ["do_nothing"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
|
||||
last_action_response = AgentHistoryItem(
|
||||
@@ -216,7 +216,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
assert reward.calculate(state, last_action_response) == 0
|
||||
|
||||
# agent did a successful fetch
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
@@ -228,7 +228,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
|
||||
# THE IMPORTANT BIT
|
||||
# agent did nothing, because reward is not sticky, it goes back to 0
|
||||
action, params, request = "DO_NOTHING", {}, ["do_nothing"]
|
||||
action, params, request = "do_nothing", {}, ["do_nothing"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
|
||||
last_action_response = AgentHistoryItem(
|
||||
@@ -237,7 +237,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
assert reward.calculate(state, last_action_response) == 0.0
|
||||
|
||||
# agent fails to fetch, get a -1.0 reward
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
@@ -248,7 +248,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
assert reward.calculate(state, last_action_response) == -1.0
|
||||
|
||||
# agent fails again to fetch, get a -1.0 reward again
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
@@ -266,7 +266,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
reward = GreenAdminDatabaseUnreachablePenalty(config=schema)
|
||||
|
||||
# no response codes yet, reward is 0
|
||||
action, params, request = "DO_NOTHING", {}, ["do_nothing"]
|
||||
action, params, request = "do_nothing", {}, ["do_nothing"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
|
||||
last_action_response = AgentHistoryItem(
|
||||
@@ -275,7 +275,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
assert reward.calculate(state, last_action_response) == 0
|
||||
|
||||
# agent did a successful fetch
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
@@ -287,7 +287,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
|
||||
# THE IMPORTANT BIT
|
||||
# agent did nothing, because reward is not sticky, it goes back to 0
|
||||
action, params, request = "DO_NOTHING", {}, ["do_nothing"]
|
||||
action, params, request = "do_nothing", {}, ["do_nothing"]
|
||||
response = RequestResponse(status="success", data={})
|
||||
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
|
||||
last_action_response = AgentHistoryItem(
|
||||
@@ -296,7 +296,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
assert reward.calculate(state, last_action_response) == 1.0
|
||||
|
||||
# agent fails to fetch, get a -1.0 reward
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
@@ -307,7 +307,7 @@ class TestGreenAdminDatabaseUnreachableSticky:
|
||||
assert reward.calculate(state, last_action_response) == -1.0
|
||||
|
||||
# agent fails again to fetch, get a -1.0 reward again
|
||||
action = "NODE_APPLICATION_EXECUTE"
|
||||
action = "node_application_execute"
|
||||
params = {"node_id": 0, "application_id": 0}
|
||||
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
|
||||
response = RequestResponse(status="failure", data={})
|
||||
|
||||
@@ -46,7 +46,7 @@ def test_file_reveal_to_red_scan(file_system):
|
||||
assert file.revealed_to_red is True
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="NODE_FILE_CHECKHASH not implemented")
|
||||
@pytest.mark.skip(reason="node_file_checkhash not implemented")
|
||||
def test_simulated_file_check_hash(file_system):
|
||||
file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder")
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ def test_file_scan_request(populated_file_system):
|
||||
assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="NODE_FILE_CHECKHASH not implemented")
|
||||
@pytest.mark.skip(reason="node_file_checkhash not implemented")
|
||||
def test_file_checkhash_request(populated_file_system):
|
||||
"""Test that an agent can request a file hash check."""
|
||||
fs, folder, file = populated_file_system
|
||||
|
||||
@@ -120,7 +120,7 @@ def test_folder_corrupt_repair(file_system):
|
||||
assert file.health_status == FileSystemItemHealthStatus.GOOD
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="NODE_FILE_CHECKHASH not implemented")
|
||||
@pytest.mark.skip(reason="node_file_checkhash not implemented")
|
||||
def test_simulated_folder_check_hash(file_system):
|
||||
folder: Folder = file_system.create_folder(folder_name="test_folder")
|
||||
file_system.create_file(file_name="test_file.txt", folder_name="test_folder")
|
||||
|
||||
@@ -51,7 +51,7 @@ def test_folder_scan_request(populated_file_system):
|
||||
assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT
|
||||
|
||||
|
||||
@pytest.mark.skip(reason="NODE_FOLDER_CHECKHASH not implemented")
|
||||
@pytest.mark.skip(reason="node_folder_checkhash not implemented")
|
||||
def test_folder_checkhash_request(populated_file_system):
|
||||
"""Test that an agent can request a folder hash check."""
|
||||
fs, folder, file = populated_file_system
|
||||
|
||||
Reference in New Issue
Block a user