#2925 PR TAP Test comments.

This commit is contained in:
Archer Bowen
2025-02-27 13:36:45 +00:00
committed by Marek Wolan
parent 0b7cdd451b
commit 5cc885f6e9
4 changed files with 22 additions and 25 deletions

View File

@@ -19,9 +19,9 @@ def uc7_tap001_env() -> PrimaiteGymEnv:
with open(_EXAMPLE_CFG / "uc7_config.yaml", mode="r") as uc7_config:
cfg = yaml.safe_load(uc7_config)
for a in cfg["agents"]:
if a["ref"] == "attacker":
tap_cfg = a
for agents in cfg["agents"]:
if agents["ref"] == "attacker":
tap_cfg = agents
tap_cfg["agent_settings"]["start_step"] = 1
tap_cfg["agent_settings"]["frequency"] = 5
@@ -43,9 +43,9 @@ def uc7_tap003_env(**kwargs) -> PrimaiteGymEnv:
with open(_EXAMPLE_CFG / "uc7_config_tap003.yaml", "r") as uc7_config:
cfg = yaml.safe_load(uc7_config)
for a in cfg["agents"]:
if a["ref"] == "attacker":
tap_cfg = a
for agents in cfg["agents"]:
if agents["ref"] == "attacker":
tap_cfg = agents
tap_cfg["agent_settings"]["start_step"] = 1
tap_cfg["agent_settings"]["frequency"] = 5
@@ -112,7 +112,7 @@ def test_outcome_handler():
env = uc7_tap003_env(repeat_kill_chain=False, repeat_kill_chain_stages=False) # Using TAP003 for PyTests.
tap: TAP003 = env.game.agents["attacker"]
tap.current_kill_chain_stage = BaseKillChain.FAILED
# 6 Iterations as the attacker frequency is set to 5. Therefore, after 6 timesteps we expect the agent to realise it's failed the kill chain.
for _ in range(6):
env.step(0)
assert tap.actions_concluded == True

View File

@@ -22,7 +22,7 @@ VARIANCE = 0 # The timestep variance between kill chain progression (E.g Next t
def uc7_tap003_env() -> PrimaiteGymEnv:
"""Setups the UC7 TAP003 Game with the start_step & frequency set to 1 with probabilities set to 1 as well"""
"""Setups the UC7 TAP003 Game with a 1 timestep start_step, frequency of 2 and probabilities set to 1 as well"""
with open(_EXAMPLE_CFG / "uc7_config_tap003.yaml", mode="r") as uc7_config:
cfg = yaml.safe_load(uc7_config)
cfg["io_settings"]["save_sys_logs"] = False
@@ -50,9 +50,10 @@ def test_tap003_insider_kill_chain_load():
env = uc7_tap003_env() # Using TAP003 for PyTests.
tap: TAP003 = env.game.agents["attacker"]
# Asserting that the Base Kill Chain intEnum stages are loaded
assert BaseKillChain.FAILED in [enums for enums in tap.selected_kill_chain]
assert BaseKillChain.SUCCEEDED in [enums for enums in tap.selected_kill_chain]
assert BaseKillChain.NOT_STARTED in [enums for enums in tap.selected_kill_chain]
kill_chain_enums = [enums for enums in tap.selected_kill_chain]
assert BaseKillChain.FAILED in kill_chain_enums
assert BaseKillChain.SUCCEEDED in kill_chain_enums
assert BaseKillChain.NOT_STARTED in kill_chain_enums
# Asserting that the Insider Kill Chain intenum stages are loaded.
assert len(InsiderKillChain.__members__) == len(tap.selected_kill_chain.__members__)
@@ -62,8 +63,9 @@ def test_tap001_mobile_malware_kill_chain_load():
env = uc7_tap001_env() # Using TAP003 for PyTests.
tap: TAP001 = env.game.agents["attacker"]
# Asserting that the Base Kill Chain intEnum stages are loaded.
assert BaseKillChain.FAILED in [enums for enums in tap.selected_kill_chain]
assert BaseKillChain.SUCCEEDED in [enums for enums in tap.selected_kill_chain]
assert BaseKillChain.NOT_STARTED in [enums for enums in tap.selected_kill_chain]
kill_chain_enums = [enums for enums in tap.selected_kill_chain]
assert BaseKillChain.FAILED in kill_chain_enums
assert BaseKillChain.SUCCEEDED in kill_chain_enums
assert BaseKillChain.NOT_STARTED in kill_chain_enums
# Asserting that the Insider Kill Chain intEnum stages are loaded.
assert len(MobileMalwareKillChain.__members__) == len(tap.selected_kill_chain.__members__)

View File

@@ -22,7 +22,7 @@ VARIANCE = 0 # The timestep variance between kill chain progression (E.g Next t
def uc7_tap001_env(**kwargs) -> PrimaiteGymEnv:
"""Setups the UC7 tap001 Game with the start_step & frequency set to 1 with probabilities set to 1 as well"""
"""Setups the UC7 tap001 game with a 1 timestep start_step, frequency of 2 and probabilities set to 1 as well"""
with open(_EXAMPLE_CFG / "uc7_config.yaml", mode="r") as uc7_config:
cfg = yaml.safe_load(uc7_config)
cfg["io_settings"]["save_sys_logs"] = False
@@ -47,15 +47,15 @@ def test_tap001_repeating_kill_chain():
)
tap001: TAP001 = env.game.agents["attacker"]
# Looping for 50 timesteps - As the agent is set to execute an action every 2 timesteps
# This is the equivalent of the agent taking 20 actions.
# This is the equivalent of the agent taking 25 actions.
for _ in range(50): # This for loop should never actually fully complete.
if tap001.current_kill_chain_stage == BaseKillChain.SUCCEEDED:
break
env.step(0)
# Catches if the above for loop fully completes.
# This test uses a probability of 1 for all stages and a variance of 2 timesteps
# Thus the for loop above should never fail.
# This test uses a probability of 1 for all stages and a frequency of 2 timesteps
# Thus the for loop above should never complete it's full 50 iterations.
# If this occurs then there is an error somewhere in either:
# 1. The TAP Logic
# 2. Failing Agent Actions are causing the TAP to fail. (See tap_return_handler).

View File

@@ -19,12 +19,6 @@ from primaite.simulator.system.services.database.database_service import Databas
# Defining constants.
START_STEP = 1 # The starting step of the agent.
FREQUENCY = 2 # The frequency of kill chain stage progression (E.g it's next attempt at "attacking").
VARIANCE = 0 # The timestep variance between kill chain progression (E.g Next timestep = Frequency +/- variance)
# Defining constants.
START_STEP = 1 # The starting step of the agent.
FREQUENCY = 2 # The frequency of kill chain stage progression (E.g it's next attempt at "attacking").
VARIANCE = 0 # The timestep variance between kill chain progression (E.g Next timestep = Frequency +/- variance)
@@ -60,7 +54,8 @@ def test_tap001_kill_chain_stage_DOWNLOAD():
starting_host = env.game.simulation.network.get_node_by_hostname(tap001.starting_node)
assert tap001.current_kill_chain_stage == BaseKillChain.NOT_STARTED
# Frequency is set to two steps
# Frequency is set to two steps so we need to step through the environment a couple of times
# In order for TAP001 to move onto the next kill chain stage.
env.step(0)
env.step(0)