Merge remote-tracking branch 'origin/4.0.0a1-dev' into 4.0.0-dev
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: false
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
game:
|
||||
ports:
|
||||
- ARP
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
# | node_a |------| switch_1 |------| node_b |
|
||||
# -------------- -------------- --------------
|
||||
#
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
# | client_1 |------| switch_1 |------| client_2 |
|
||||
# -------------- -------------- --------------
|
||||
#
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
# | client_1 |------| switch_1 |------| client_2 |
|
||||
# -------------- -------------- --------------
|
||||
#
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: true
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
# | external_computer |------| switch_3 |------| external_server |
|
||||
# ----------------------- -------------- ---------------------
|
||||
#
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
game:
|
||||
ports:
|
||||
- ARP
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: true
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
# | external_computer |------| switch_3 |------| external_server |
|
||||
# ----------------------- -------------- ---------------------
|
||||
#
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
# | client_1 |------| switch_1 |------| client_2 |
|
||||
# -------------- -------------- --------------
|
||||
#
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: false
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: false
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: true
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: false
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
# | client_1 |------| switch_1 |------| client_2 |
|
||||
# -------------- -------------- --------------
|
||||
#
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: true
|
||||
save_step_metadata: false
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
io_settings:
|
||||
save_agent_actions: true
|
||||
save_step_metadata: true
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
game:
|
||||
max_episode_length: 256
|
||||
ports:
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
game:
|
||||
max_episode_length: 256
|
||||
ports:
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
metadata:
|
||||
version: 3.0
|
||||
|
||||
game:
|
||||
max_episode_length: 256
|
||||
ports:
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
from typing import Tuple
|
||||
|
||||
from primaite.game.agent.interface import ProxyAgent
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from tests import TEST_ASSETS_ROOT
|
||||
|
||||
FIREWALL_ACTIONS_NETWORK = TEST_ASSETS_ROOT / "configs/firewall_actions_network.yaml"
|
||||
|
||||
|
||||
def test_router_acl_add_rule_action_shape(game_and_agent: Tuple[PrimaiteGame, ProxyAgent]):
|
||||
"""Test to check ROUTER_ADD_ACL_RULE has the expected action shape."""
|
||||
game, agent = game_and_agent
|
||||
|
||||
# assert that the shape of the actions is correct
|
||||
router_acl_add_rule_action = agent.action_manager.actions.get("ROUTER_ACL_ADDRULE")
|
||||
assert router_acl_add_rule_action.shape.get("source_ip_id") == len(agent.action_manager.ip_address_list)
|
||||
assert router_acl_add_rule_action.shape.get("dest_ip_id") == len(agent.action_manager.ip_address_list)
|
||||
assert router_acl_add_rule_action.shape.get("source_port_id") == len(agent.action_manager.ports)
|
||||
assert router_acl_add_rule_action.shape.get("dest_port_id") == len(agent.action_manager.ports)
|
||||
assert router_acl_add_rule_action.shape.get("protocol_id") == len(agent.action_manager.protocols)
|
||||
@@ -117,7 +117,7 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
|
||||
server_1 = game.simulation.network.get_node_by_hostname("server_1")
|
||||
server_2 = game.simulation.network.get_node_by_hostname("server_2")
|
||||
router = game.simulation.network.get_node_by_hostname("router")
|
||||
assert router.acl.num_rules == 3
|
||||
assert router.acl.num_rules == 4
|
||||
assert client_1.ping("10.0.2.3") # client_1 can ping server_2
|
||||
assert server_2.ping("10.0.1.2") # server_2 can ping client_1
|
||||
|
||||
@@ -140,7 +140,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 6 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
|
||||
@@ -167,8 +167,8 @@ def test_router_acl_addrule_integration(game_and_agent: Tuple[PrimaiteGame, Prox
|
||||
agent.store_action(action)
|
||||
game.step()
|
||||
|
||||
# 5: Check that the ACL now has 5 rules, but that server_1 can still ping server_2
|
||||
assert router.acl.num_rules == 5
|
||||
# 5: Check that the ACL now has 6 rules, but that server_1 can still ping server_2
|
||||
assert router.acl.num_rules == 6
|
||||
assert server_1.ping("10.0.2.3") # Can ping server_2
|
||||
|
||||
|
||||
@@ -199,7 +199,7 @@ def test_router_acl_removerule_integration(game_and_agent: Tuple[PrimaiteGame, P
|
||||
game.step()
|
||||
|
||||
# 3: Check that the ACL now has 2 rules, and that client 1 cannot access example.com
|
||||
assert router.acl.num_rules == 2
|
||||
assert router.acl.num_rules == 3
|
||||
assert not browser.get_webpage()
|
||||
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
|
||||
|
||||
@@ -4,7 +4,7 @@ from primaite.game.agent.scripted_agents.random_agent import RandomAgent
|
||||
|
||||
|
||||
def test_creating_empty_agent():
|
||||
agent = RandomAgent()
|
||||
agent = RandomAgent(config={"ref": "Empty Agent"})
|
||||
assert len(agent.action_manager.action_map) == 0
|
||||
assert isinstance(agent.observation_manager.obs, NullObservation)
|
||||
assert len(agent.reward_function.reward_components) == 0
|
||||
|
||||
@@ -17,4 +17,3 @@ def switch() -> Switch:
|
||||
def test_describe_state(switch):
|
||||
state = switch.describe_state()
|
||||
assert len(state.get("ports")) is 8
|
||||
assert state.get("num_ports") is 8
|
||||
|
||||
@@ -18,7 +18,7 @@ def test_scan(application):
|
||||
|
||||
def test_run_application(application):
|
||||
assert application.operating_state == ApplicationOperatingState.CLOSED
|
||||
assert application.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert application.health_state_actual == SoftwareHealthState.GOOD
|
||||
|
||||
application.run()
|
||||
assert application.operating_state == ApplicationOperatingState.RUNNING
|
||||
@@ -37,9 +37,9 @@ def test_close_application(application):
|
||||
|
||||
def test_application_describe_states(application):
|
||||
assert application.operating_state == ApplicationOperatingState.CLOSED
|
||||
assert application.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert application.health_state_actual == SoftwareHealthState.GOOD
|
||||
|
||||
assert SoftwareHealthState.UNUSED.value == application.describe_state().get("health_state_actual")
|
||||
assert SoftwareHealthState.GOOD.value == application.describe_state().get("health_state_actual")
|
||||
|
||||
application.run()
|
||||
assert SoftwareHealthState.GOOD.value == application.describe_state().get("health_state_actual")
|
||||
|
||||
@@ -22,7 +22,7 @@ def test_scan(service):
|
||||
|
||||
def test_start_service(service):
|
||||
assert service.operating_state == ServiceOperatingState.STOPPED
|
||||
assert service.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert service.health_state_actual == SoftwareHealthState.GOOD
|
||||
service.start()
|
||||
|
||||
assert service.operating_state == ServiceOperatingState.RUNNING
|
||||
@@ -43,7 +43,7 @@ def test_pause_and_resume_service(service):
|
||||
assert service.operating_state == ServiceOperatingState.STOPPED
|
||||
service.resume()
|
||||
assert service.operating_state == ServiceOperatingState.STOPPED
|
||||
assert service.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert service.health_state_actual == SoftwareHealthState.GOOD
|
||||
|
||||
service.start()
|
||||
assert service.health_state_actual == SoftwareHealthState.GOOD
|
||||
@@ -58,11 +58,11 @@ def test_pause_and_resume_service(service):
|
||||
|
||||
def test_restart(service):
|
||||
assert service.operating_state == ServiceOperatingState.STOPPED
|
||||
assert service.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert service.health_state_actual == SoftwareHealthState.GOOD
|
||||
service.restart()
|
||||
# Service is STOPPED. Restart will only work if the service was PAUSED or RUNNING
|
||||
assert service.operating_state == ServiceOperatingState.STOPPED
|
||||
assert service.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert service.health_state_actual == SoftwareHealthState.GOOD
|
||||
|
||||
service.start()
|
||||
assert service.operating_state == ServiceOperatingState.RUNNING
|
||||
@@ -157,11 +157,11 @@ def test_service_fixing(service):
|
||||
def test_enable_disable(service):
|
||||
service.disable()
|
||||
assert service.operating_state == ServiceOperatingState.DISABLED
|
||||
assert service.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert service.health_state_actual == SoftwareHealthState.GOOD
|
||||
|
||||
service.enable()
|
||||
assert service.operating_state == ServiceOperatingState.STOPPED
|
||||
assert service.health_state_actual == SoftwareHealthState.UNUSED
|
||||
assert service.health_state_actual == SoftwareHealthState.GOOD
|
||||
|
||||
|
||||
def test_overwhelm_service(service):
|
||||
|
||||
@@ -39,6 +39,6 @@ def test_software_creation(software):
|
||||
|
||||
|
||||
def test_software_set_health_state(software):
|
||||
assert software.health_state_actual == SoftwareHealthState.UNUSED
|
||||
software.set_health_state(SoftwareHealthState.GOOD)
|
||||
assert software.health_state_actual == SoftwareHealthState.GOOD
|
||||
software.set_health_state(SoftwareHealthState.COMPROMISED)
|
||||
assert software.health_state_actual == SoftwareHealthState.COMPROMISED
|
||||
|
||||
Reference in New Issue
Block a user