#1961: node scanning + applying timestep to all components within node + node revealing to red
This commit is contained in:
@@ -4,9 +4,10 @@ import shutil
|
||||
import tempfile
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Union
|
||||
from typing import Any, Dict, Union
|
||||
from unittest.mock import patch
|
||||
|
||||
import nodeenv
|
||||
import pytest
|
||||
|
||||
from primaite import getLogger
|
||||
@@ -15,6 +16,7 @@ from primaite.primaite_session import PrimaiteSession
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.networks import arcd_uc2_network
|
||||
from primaite.simulator.network.transmission.transport_layer import Port
|
||||
from primaite.simulator.system.applications.application import Application
|
||||
from primaite.simulator.system.core.sys_log import SysLog
|
||||
from primaite.simulator.system.services.service import Service
|
||||
from tests.mock_and_patch.get_session_path_mock import get_temp_session_path
|
||||
@@ -36,6 +38,13 @@ class TestService(Service):
|
||||
pass
|
||||
|
||||
|
||||
class TestApplication(Application):
|
||||
"""Test Application class"""
|
||||
|
||||
def describe_state(self) -> Dict:
|
||||
pass
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def uc2_network() -> Network:
|
||||
return arcd_uc2_network()
|
||||
@@ -48,6 +57,13 @@ def service(file_system) -> TestService:
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def application(file_system) -> TestApplication:
|
||||
return TestApplication(
|
||||
name="TestApplication", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_application")
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def file_system() -> FileSystem:
|
||||
return Node(hostname="fs_node").file_system
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user