#1961: node scanning + applying timestep to all components within node + node revealing to red

This commit is contained in:
Czar.Echavez
2023-10-27 17:50:41 +01:00
parent 8783574442
commit 68b22b6444
6 changed files with 216 additions and 18 deletions

View File

@@ -1,6 +1,8 @@
import pytest
from primaite.simulator.file_system.file_system import File, FileSystemItemHealthStatus, Folder
from primaite.simulator.network.hardware.base import Node, NodeOperatingState
from primaite.simulator.system.applications.application import Application
from primaite.simulator.system.processes.process import Process
from primaite.simulator.system.services.service import Service
from primaite.simulator.system.software import SoftwareHealthState
@@ -44,21 +46,31 @@ def test_node_shutdown(node):
assert node.operating_state == NodeOperatingState.OFF
def test_node_os_scan(node):
def test_node_os_scan(node, service, application):
"""Test OS Scanning."""
node.operating_state = NodeOperatingState.ON
# add process to node
node.processes["process"] = Process(name="process")
node.processes["process"].health_state_actual = SoftwareHealthState.COMPROMISED
assert node.processes["process"].health_state_visible == SoftwareHealthState.GOOD
# TODO implement processes
# add services to node
service = Service(name="service")
service.health_state_actual = SoftwareHealthState.COMPROMISED
node.install_service(service=service)
assert service.health_state_visible == SoftwareHealthState.UNUSED
# add application to node
application.health_state_actual = SoftwareHealthState.COMPROMISED
node.install_application(application=application)
assert application.health_state_visible == SoftwareHealthState.UNUSED
# add file to node
# add folder and file to node
folder: Folder = node.file_system.create_folder(folder_name="test_folder")
folder.corrupt()
assert folder.visible_health_status == FileSystemItemHealthStatus.GOOD
file: File = node.file_system.create_file(folder_name="test_folder", file_name="file.txt")
file.corrupt()
assert file.visible_health_status == FileSystemItemHealthStatus.GOOD
# run os scan
node.apply_request(["os", "scan"])
@@ -68,5 +80,46 @@ def test_node_os_scan(node):
node.apply_timestep(timestep=i)
# should update the state of all items
assert node.processes["process"].health_state_visible == SoftwareHealthState.COMPROMISED
# TODO assert process.health_state_visible == SoftwareHealthState.COMPROMISED
assert service.health_state_visible == SoftwareHealthState.COMPROMISED
assert application.health_state_visible == SoftwareHealthState.COMPROMISED
assert folder.visible_health_status == FileSystemItemHealthStatus.CORRUPT
assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT
def test_node_red_scan(node, service, application):
"""Test revealing to red"""
node.operating_state = NodeOperatingState.ON
# add process to node
# TODO implement processes
# add services to node
node.install_service(service=service)
assert service.revealed_to_red is False
# add application to node
application.health_state_actual = SoftwareHealthState.COMPROMISED
node.install_application(application=application)
assert application.revealed_to_red is False
# add folder and file to node
folder: Folder = node.file_system.create_folder(folder_name="test_folder")
assert folder.revealed_to_red is False
file: File = node.file_system.create_file(folder_name="test_folder", file_name="file.txt")
assert file.revealed_to_red is False
# run os scan
node.apply_request(["scan"])
# apply time steps
for i in range(20):
node.apply_timestep(timestep=i)
# should update the state of all items
# TODO assert process.revealed_to_red is True
assert service.revealed_to_red is True
assert application.revealed_to_red is True
assert folder.revealed_to_red is True
assert file.revealed_to_red is True