2025-01-02 15:05:06 +00:00
|
|
|
# © Crown-owned copyright 2025, Defence Science and Technology Laboratory UK
|
2023-10-25 17:08:01 +01:00
|
|
|
from gymnasium import spaces
|
2023-09-25 16:04:04 +01:00
|
|
|
|
2024-03-08 14:08:35 +00:00
|
|
|
from primaite.game.agent.observations.file_system_observations import FileObservation
|
2024-02-05 08:44:10 +00:00
|
|
|
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
2023-09-25 16:04:04 +01:00
|
|
|
from primaite.simulator.sim_container import Simulation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_file_observation():
|
|
|
|
|
sim = Simulation()
|
2025-02-03 11:18:34 +00:00
|
|
|
pc: Computer = Computer.from_config(
|
|
|
|
|
config={"type": "computer", "hostname": "beep", "ip_address": "123.123.123.123", "subnet_mask": "255.255.255.0"}
|
|
|
|
|
)
|
2023-09-25 16:04:04 +01:00
|
|
|
sim.network.add_node(pc)
|
|
|
|
|
f = pc.file_system.create_file(file_name="dog.png")
|
|
|
|
|
|
|
|
|
|
state = sim.describe_state()
|
|
|
|
|
|
|
|
|
|
dog_file_obs = FileObservation(
|
2025-01-27 16:35:40 +00:00
|
|
|
where=["network", "nodes", pc.config.hostname, "file_system", "folders", "root", "files", "dog.png"],
|
2024-04-01 00:54:55 +01:00
|
|
|
include_num_access=False,
|
2025-01-21 13:08:36 +00:00
|
|
|
file_system_requires_scan=False,
|
2023-09-25 16:04:04 +01:00
|
|
|
)
|
2023-10-09 18:33:30 +01:00
|
|
|
assert dog_file_obs.observe(state) == {"health_status": 1}
|
2023-09-25 16:04:04 +01:00
|
|
|
assert dog_file_obs.space == spaces.Dict({"health_status": spaces.Discrete(6)})
|