Merge remote-tracking branch 'origin/dev' into feature/2769-implement-user-account-action-space
This commit is contained in:
@@ -99,7 +99,7 @@ agents:
|
||||
num_files: 1
|
||||
num_nics: 2
|
||||
include_num_access: false
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
routers:
|
||||
- hostname: router_1
|
||||
num_ports: 0
|
||||
|
||||
34
tests/assets/configs/basic_node_with_users.yaml
Normal file
34
tests/assets/configs/basic_node_with_users.yaml
Normal file
@@ -0,0 +1,34 @@
|
||||
io_settings:
|
||||
save_step_metadata: false
|
||||
save_pcap_logs: true
|
||||
save_sys_logs: true
|
||||
sys_log_level: WARNING
|
||||
agent_log_level: INFO
|
||||
save_agent_logs: true
|
||||
write_agent_log_to_terminal: True
|
||||
|
||||
|
||||
game:
|
||||
max_episode_length: 256
|
||||
ports:
|
||||
- ARP
|
||||
protocols:
|
||||
- ICMP
|
||||
- UDP
|
||||
|
||||
|
||||
simulation:
|
||||
network:
|
||||
nodes:
|
||||
- hostname: client_1
|
||||
type: computer
|
||||
ip_address: 192.168.10.11
|
||||
subnet_mask: 255.255.255.0
|
||||
default_gateway: 192.168.10.1
|
||||
users:
|
||||
- username: jane.doe
|
||||
password: '1234'
|
||||
is_admin: true
|
||||
- username: john.doe
|
||||
password: password_1
|
||||
is_admin: false
|
||||
@@ -92,7 +92,7 @@ agents:
|
||||
- NONE
|
||||
tcp:
|
||||
- DNS
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
routers:
|
||||
- hostname: router_1
|
||||
num_ports: 0
|
||||
|
||||
@@ -111,7 +111,7 @@ agents:
|
||||
num_files: 1
|
||||
num_nics: 2
|
||||
include_num_access: false
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
routers:
|
||||
- hostname: router_1
|
||||
num_ports: 0
|
||||
|
||||
@@ -68,7 +68,7 @@ agents:
|
||||
num_files: 1
|
||||
num_nics: 2
|
||||
include_num_access: false
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
routers:
|
||||
- hostname: router_1
|
||||
num_ports: 0
|
||||
|
||||
@@ -89,7 +89,7 @@ agents:
|
||||
- NONE
|
||||
tcp:
|
||||
- DNS
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
routers:
|
||||
- hostname: router_1
|
||||
num_ports: 0
|
||||
|
||||
@@ -44,7 +44,7 @@ agents:
|
||||
num_files: 1
|
||||
num_nics: 1
|
||||
include_num_access: false
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
|
||||
- type: LINKS
|
||||
label: LINKS
|
||||
|
||||
@@ -89,7 +89,7 @@ agents:
|
||||
- NONE
|
||||
tcp:
|
||||
- DNS
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
routers:
|
||||
- hostname: router_1
|
||||
num_ports: 0
|
||||
|
||||
@@ -120,7 +120,7 @@ agents:
|
||||
num_files: 1
|
||||
num_nics: 2
|
||||
include_num_access: false
|
||||
include_nmne: true
|
||||
include_nmne: false
|
||||
routers:
|
||||
- hostname: router_1
|
||||
num_ports: 0
|
||||
|
||||
@@ -30,21 +30,21 @@ from primaite.simulator.system.services.service import Service
|
||||
from primaite.simulator.system.services.web_server.web_server import WebServer
|
||||
from tests import TEST_ASSETS_ROOT
|
||||
|
||||
rayinit(local_mode=True)
|
||||
rayinit()
|
||||
ACTION_SPACE_NODE_VALUES = 1
|
||||
ACTION_SPACE_NODE_ACTION_VALUES = 1
|
||||
|
||||
_LOGGER = getLogger(__name__)
|
||||
|
||||
|
||||
class TestService(Service):
|
||||
class DummyService(Service):
|
||||
"""Test Service class"""
|
||||
|
||||
def describe_state(self) -> Dict:
|
||||
return super().describe_state()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
kwargs["name"] = "TestService"
|
||||
kwargs["name"] = "DummyService"
|
||||
kwargs["port"] = Port.HTTP
|
||||
kwargs["protocol"] = IPProtocol.TCP
|
||||
super().__init__(**kwargs)
|
||||
@@ -75,15 +75,15 @@ def uc2_network() -> Network:
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def service(file_system) -> TestService:
|
||||
return TestService(
|
||||
name="TestService", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="test_service")
|
||||
def service(file_system) -> DummyService:
|
||||
return DummyService(
|
||||
name="DummyService", port=Port.ARP, file_system=file_system, sys_log=SysLog(hostname="dummy_service")
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def service_class():
|
||||
return TestService
|
||||
return DummyService
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
|
||||
@@ -22,8 +22,7 @@ def test_passing_actions_down(monkeypatch) -> None:
|
||||
for n in [pc1, pc2, srv, s1]:
|
||||
sim.network.add_node(n)
|
||||
|
||||
database_service = DatabaseService(file_system=srv.file_system)
|
||||
srv.install_service(database_service)
|
||||
srv.software_manager.install(DatabaseService)
|
||||
|
||||
downloads_folder = pc1.file_system.create_folder("downloads")
|
||||
pc1.file_system.create_file("bermuda_triangle.png", folder_name="downloads")
|
||||
|
||||
@@ -45,7 +45,7 @@ def test_fix_duration_set_from_config():
|
||||
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
|
||||
|
||||
# in config - services take 3 timesteps to fix
|
||||
for service in SERVICE_TYPES_MAPPING:
|
||||
for service in ["DNSClient", "DNSServer", "DatabaseService", "WebServer", "FTPClient", "FTPServer", "NTPServer"]:
|
||||
assert client_1.software_manager.software.get(service) is not None
|
||||
assert client_1.software_manager.software.get(service).fixing_duration == 3
|
||||
|
||||
@@ -53,7 +53,7 @@ def test_fix_duration_set_from_config():
|
||||
# remove test applications from list
|
||||
applications = set(Application._application_registry) - set(TestApplications)
|
||||
|
||||
for application in applications:
|
||||
for application in ["RansomwareScript", "WebBrowser", "DataManipulationBot", "DoSBot", "DatabaseClient"]:
|
||||
assert client_1.software_manager.software.get(application) is not None
|
||||
assert client_1.software_manager.software.get(application).fixing_duration == 1
|
||||
|
||||
@@ -64,17 +64,13 @@ def test_fix_duration_for_one_item():
|
||||
client_1: Computer = game.simulation.network.get_node_by_hostname("client_1")
|
||||
|
||||
# in config - services take 3 timesteps to fix
|
||||
services = copy.copy(SERVICE_TYPES_MAPPING)
|
||||
services.pop("DatabaseService")
|
||||
for service in services:
|
||||
for service in ["DNSClient", "DNSServer", "WebServer", "FTPClient", "FTPServer", "NTPServer"]:
|
||||
assert client_1.software_manager.software.get(service) is not None
|
||||
assert client_1.software_manager.software.get(service).fixing_duration == 2
|
||||
|
||||
# in config - applications take 1 timestep to fix
|
||||
# remove test applications from list
|
||||
applications = set(Application._application_registry) - set(TestApplications)
|
||||
applications.remove("DatabaseClient")
|
||||
for applications in applications:
|
||||
for applications in ["RansomwareScript", "WebBrowser", "DataManipulationBot", "DoSBot"]:
|
||||
assert client_1.software_manager.software.get(applications) is not None
|
||||
assert client_1.software_manager.software.get(applications).fixing_duration == 2
|
||||
|
||||
|
||||
@@ -9,9 +9,11 @@ from gymnasium import spaces
|
||||
from primaite.game.agent.interface import ProxyAgent
|
||||
from primaite.game.agent.observations.nic_observations import NICObservation
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from primaite.simulator.network.hardware.base import NetworkInterface
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import NIC
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.network.nmne import NMNEConfig
|
||||
from primaite.simulator.sim_container import Simulation
|
||||
from primaite.simulator.system.applications.database_client import DatabaseClient
|
||||
from primaite.simulator.system.applications.web_browser import WebBrowser
|
||||
@@ -75,6 +77,18 @@ def test_nic(simulation):
|
||||
|
||||
nic_obs = NICObservation(where=["network", "nodes", pc.hostname, "NICs", 1], include_nmne=True)
|
||||
|
||||
# Set the NMNE configuration to capture DELETE/ENCRYPT queries as MNEs
|
||||
nmne_config = {
|
||||
"capture_nmne": True, # Enable the capture of MNEs
|
||||
"nmne_capture_keywords": [
|
||||
"DELETE",
|
||||
"ENCRYPT",
|
||||
], # Specify "DELETE/ENCRYPT" SQL command as a keyword for MNE detection
|
||||
}
|
||||
|
||||
# Apply the NMNE configuration settings
|
||||
NetworkInterface.nmne_config = NMNEConfig(**nmne_config)
|
||||
|
||||
assert nic_obs.space["nic_status"] == spaces.Discrete(3)
|
||||
assert nic_obs.space["NMNE"]["inbound"] == spaces.Discrete(4)
|
||||
assert nic_obs.space["NMNE"]["outbound"] == spaces.Discrete(4)
|
||||
@@ -144,7 +158,7 @@ def test_nic_monitored_traffic(simulation):
|
||||
pc2: Computer = simulation.network.get_node_by_hostname("client_2")
|
||||
|
||||
nic_obs = NICObservation(
|
||||
where=["network", "nodes", pc.hostname, "NICs", 1], include_nmne=True, monitored_traffic=monitored_traffic
|
||||
where=["network", "nodes", pc.hostname, "NICs", 1], include_nmne=False, monitored_traffic=monitored_traffic
|
||||
)
|
||||
|
||||
simulation.pre_timestep(0) # apply timestep to whole sim
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
from primaite.game.agent.observations.nic_observations import NICObservation
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import NIC
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.network.nmne import set_nmne_config
|
||||
from primaite.simulator.network.nmne import NMNEConfig
|
||||
from primaite.simulator.sim_container import Simulation
|
||||
from primaite.simulator.system.applications.database_client import DatabaseClient, DatabaseClientConnection
|
||||
|
||||
|
||||
def test_capture_nmne(uc2_network):
|
||||
def test_capture_nmne(uc2_network: Network):
|
||||
"""
|
||||
Conducts a test to verify that Malicious Network Events (MNEs) are correctly captured.
|
||||
|
||||
@@ -33,7 +35,7 @@ def test_capture_nmne(uc2_network):
|
||||
}
|
||||
|
||||
# Apply the NMNE configuration settings
|
||||
set_nmne_config(nmne_config)
|
||||
NIC.nmne_config = NMNEConfig(**nmne_config)
|
||||
|
||||
# Assert that initially, there are no captured MNEs on both web and database servers
|
||||
assert web_server_nic.nmne == {}
|
||||
@@ -82,7 +84,7 @@ def test_capture_nmne(uc2_network):
|
||||
assert db_server_nic.nmne == {"direction": {"inbound": {"keywords": {"*": 3}}}}
|
||||
|
||||
|
||||
def test_describe_state_nmne(uc2_network):
|
||||
def test_describe_state_nmne(uc2_network: Network):
|
||||
"""
|
||||
Conducts a test to verify that Malicious Network Events (MNEs) are correctly represented in the nic state.
|
||||
|
||||
@@ -110,7 +112,7 @@ def test_describe_state_nmne(uc2_network):
|
||||
}
|
||||
|
||||
# Apply the NMNE configuration settings
|
||||
set_nmne_config(nmne_config)
|
||||
NIC.nmne_config = NMNEConfig(**nmne_config)
|
||||
|
||||
# Assert that initially, there are no captured MNEs on both web and database servers
|
||||
web_server_nic_state = web_server_nic.describe_state()
|
||||
@@ -190,7 +192,7 @@ def test_describe_state_nmne(uc2_network):
|
||||
assert db_server_nic_state["nmne"] == {"direction": {"inbound": {"keywords": {"*": 4}}}}
|
||||
|
||||
|
||||
def test_capture_nmne_observations(uc2_network):
|
||||
def test_capture_nmne_observations(uc2_network: Network):
|
||||
"""
|
||||
Tests the NICObservation class's functionality within a simulated network environment.
|
||||
|
||||
@@ -219,7 +221,7 @@ def test_capture_nmne_observations(uc2_network):
|
||||
}
|
||||
|
||||
# Apply the NMNE configuration settings
|
||||
set_nmne_config(nmne_config)
|
||||
NIC.nmne_config = NMNEConfig(**nmne_config)
|
||||
|
||||
# Define observations for the NICs of the database and web servers
|
||||
db_server_nic_obs = NICObservation(where=["network", "nodes", "database_server", "NICs", 1], include_nmne=True)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
import yaml
|
||||
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from primaite.simulator.network.hardware.base import UserManager
|
||||
from tests import TEST_ASSETS_ROOT
|
||||
|
||||
|
||||
def test_users_from_config():
|
||||
config_path = TEST_ASSETS_ROOT / "configs" / "basic_node_with_users.yaml"
|
||||
|
||||
with open(config_path, "r") as f:
|
||||
config_dict = yaml.safe_load(f)
|
||||
network = PrimaiteGame.from_config(cfg=config_dict).simulation.network
|
||||
|
||||
client_1 = network.get_node_by_hostname("client_1")
|
||||
|
||||
user_manager: UserManager = client_1.software_manager.software["UserManager"]
|
||||
|
||||
assert len(user_manager.users) == 3
|
||||
|
||||
assert user_manager.users["jane.doe"].password == "1234"
|
||||
assert user_manager.users["jane.doe"].is_admin
|
||||
|
||||
assert user_manager.users["john.doe"].password == "password_1"
|
||||
assert not user_manager.users["john.doe"].is_admin
|
||||
@@ -23,7 +23,7 @@ def populated_node(
|
||||
server.power_on()
|
||||
server.software_manager.install(service_class)
|
||||
|
||||
service = server.software_manager.software.get("TestService")
|
||||
service = server.software_manager.software.get("DummyService")
|
||||
service.start()
|
||||
|
||||
return server, service
|
||||
@@ -42,7 +42,7 @@ def test_service_on_offline_node(service_class):
|
||||
computer.power_on()
|
||||
computer.software_manager.install(service_class)
|
||||
|
||||
service: Service = computer.software_manager.software.get("TestService")
|
||||
service: Service = computer.software_manager.software.get("DummyService")
|
||||
|
||||
computer.power_off()
|
||||
|
||||
|
||||
@@ -0,0 +1,274 @@
|
||||
# © Crown-owned copyright 2024, Defence Science and Technology Laboratory UK
|
||||
from typing import Tuple
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.base import User
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def client_server_network() -> Tuple[Computer, Server, Network]:
|
||||
network = Network()
|
||||
|
||||
client = Computer(
|
||||
hostname="client",
|
||||
ip_address="192.168.1.2",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
client.power_on()
|
||||
|
||||
server = Server(
|
||||
hostname="server",
|
||||
ip_address="192.168.1.3",
|
||||
subnet_mask="255.255.255.0",
|
||||
default_gateway="192.168.1.1",
|
||||
start_up_duration=0,
|
||||
)
|
||||
server.power_on()
|
||||
|
||||
network.connect(client.network_interface[1], server.network_interface[1])
|
||||
|
||||
return client, server, network
|
||||
|
||||
|
||||
def test_local_login_success(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
assert not client.user_session_manager.local_user_logged_in
|
||||
|
||||
client.user_session_manager.local_login(username="admin", password="admin")
|
||||
|
||||
assert client.user_session_manager.local_user_logged_in
|
||||
|
||||
|
||||
def test_login_count_increases(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
admin_user: User = client.user_manager.users["admin"]
|
||||
|
||||
assert admin_user.num_of_logins == 0
|
||||
|
||||
client.user_session_manager.local_login(username="admin", password="admin")
|
||||
|
||||
assert admin_user.num_of_logins == 1
|
||||
|
||||
client.user_session_manager.local_login(username="admin", password="admin")
|
||||
|
||||
# shouldn't change as user is already logged in
|
||||
assert admin_user.num_of_logins == 1
|
||||
|
||||
client.user_session_manager.local_logout()
|
||||
|
||||
client.user_session_manager.local_login(username="admin", password="admin")
|
||||
|
||||
assert admin_user.num_of_logins == 2
|
||||
|
||||
|
||||
def test_local_login_failure(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
assert not client.user_session_manager.local_user_logged_in
|
||||
|
||||
client.user_session_manager.local_login(username="jane.doe", password="12345")
|
||||
|
||||
assert not client.user_session_manager.local_user_logged_in
|
||||
|
||||
|
||||
def test_new_user_local_login_success(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
assert not client.user_session_manager.local_user_logged_in
|
||||
|
||||
client.user_manager.add_user(username="jane.doe", password="12345")
|
||||
|
||||
client.user_session_manager.local_login(username="jane.doe", password="12345")
|
||||
|
||||
assert client.user_session_manager.local_user_logged_in
|
||||
|
||||
|
||||
def test_new_local_login_clears_previous_login(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
assert not client.user_session_manager.local_user_logged_in
|
||||
|
||||
current_session_id = client.user_session_manager.local_login(username="admin", password="admin")
|
||||
|
||||
assert client.user_session_manager.local_user_logged_in
|
||||
|
||||
assert client.user_session_manager.local_session.user.username == "admin"
|
||||
|
||||
client.user_manager.add_user(username="jane.doe", password="12345")
|
||||
|
||||
new_session_id = client.user_session_manager.local_login(username="jane.doe", password="12345")
|
||||
|
||||
assert client.user_session_manager.local_user_logged_in
|
||||
|
||||
assert client.user_session_manager.local_session.user.username == "jane.doe"
|
||||
|
||||
assert new_session_id != current_session_id
|
||||
|
||||
|
||||
def test_new_local_login_attempt_same_uses_persists(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
assert not client.user_session_manager.local_user_logged_in
|
||||
|
||||
current_session_id = client.user_session_manager.local_login(username="admin", password="admin")
|
||||
|
||||
assert client.user_session_manager.local_user_logged_in
|
||||
|
||||
assert client.user_session_manager.local_session.user.username == "admin"
|
||||
|
||||
new_session_id = client.user_session_manager.local_login(username="admin", password="admin")
|
||||
|
||||
assert client.user_session_manager.local_user_logged_in
|
||||
|
||||
assert client.user_session_manager.local_session.user.username == "admin"
|
||||
|
||||
assert new_session_id == current_session_id
|
||||
|
||||
|
||||
def test_remote_login_success(client_server_network):
|
||||
# partial test for now until we get the terminal application in so that amn actual remote connection can be made
|
||||
client, server, network = client_server_network
|
||||
|
||||
assert not server.user_session_manager.remote_sessions
|
||||
|
||||
remote_session_id = server.user_session_manager.remote_login(
|
||||
username="admin", password="admin", remote_ip_address="192.168.1.10"
|
||||
)
|
||||
|
||||
assert server.user_session_manager.validate_remote_session_uuid(remote_session_id)
|
||||
|
||||
server.user_session_manager.remote_logout(remote_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(remote_session_id)
|
||||
|
||||
|
||||
def test_remote_login_failure(client_server_network):
|
||||
# partial test for now until we get the terminal application in so that amn actual remote connection can be made
|
||||
client, server, network = client_server_network
|
||||
|
||||
assert not server.user_session_manager.remote_sessions
|
||||
|
||||
remote_session_id = server.user_session_manager.remote_login(
|
||||
username="jane.doe", password="12345", remote_ip_address="192.168.1.10"
|
||||
)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(remote_session_id)
|
||||
|
||||
|
||||
def test_new_user_remote_login_success(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
server.user_manager.add_user(username="jane.doe", password="12345")
|
||||
|
||||
remote_session_id = server.user_session_manager.remote_login(
|
||||
username="jane.doe", password="12345", remote_ip_address="192.168.1.10"
|
||||
)
|
||||
|
||||
assert server.user_session_manager.validate_remote_session_uuid(remote_session_id)
|
||||
|
||||
server.user_session_manager.remote_logout(remote_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(remote_session_id)
|
||||
|
||||
|
||||
def test_max_remote_sessions_same_user(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
remote_session_ids = [
|
||||
server.user_session_manager.remote_login(username="admin", password="admin", remote_ip_address="192.168.1.10")
|
||||
for _ in range(server.user_session_manager.max_remote_sessions)
|
||||
]
|
||||
|
||||
assert all([server.user_session_manager.validate_remote_session_uuid(id) for id in remote_session_ids])
|
||||
|
||||
|
||||
def test_max_remote_sessions_different_users(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
remote_session_ids = []
|
||||
|
||||
for i in range(server.user_session_manager.max_remote_sessions):
|
||||
username = str(uuid4())
|
||||
password = "12345"
|
||||
server.user_manager.add_user(username=username, password=password)
|
||||
|
||||
remote_session_ids.append(
|
||||
server.user_session_manager.remote_login(
|
||||
username=username, password=password, remote_ip_address="192.168.1.10"
|
||||
)
|
||||
)
|
||||
|
||||
assert all([server.user_session_manager.validate_remote_session_uuid(id) for id in remote_session_ids])
|
||||
|
||||
|
||||
def test_max_remote_sessions_limit_reached(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
remote_session_ids = [
|
||||
server.user_session_manager.remote_login(username="admin", password="admin", remote_ip_address="192.168.1.10")
|
||||
for _ in range(server.user_session_manager.max_remote_sessions)
|
||||
]
|
||||
|
||||
assert all([server.user_session_manager.validate_remote_session_uuid(id) for id in remote_session_ids])
|
||||
|
||||
assert len(server.user_session_manager.remote_sessions) == server.user_session_manager.max_remote_sessions
|
||||
|
||||
fourth_attempt_session_id = server.user_session_manager.remote_login(
|
||||
username="admin", password="admin", remote_ip_address="192.168.1.10"
|
||||
)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(fourth_attempt_session_id)
|
||||
|
||||
assert all([server.user_session_manager.validate_remote_session_uuid(id) for id in remote_session_ids])
|
||||
|
||||
|
||||
def test_single_remote_logout_others_persist(client_server_network):
|
||||
client, server, network = client_server_network
|
||||
|
||||
server.user_manager.add_user(username="jane.doe", password="12345")
|
||||
server.user_manager.add_user(username="john.doe", password="12345")
|
||||
|
||||
admin_session_id = server.user_session_manager.remote_login(
|
||||
username="admin", password="admin", remote_ip_address="192.168.1.10"
|
||||
)
|
||||
|
||||
jane_session_id = server.user_session_manager.remote_login(
|
||||
username="jane.doe", password="12345", remote_ip_address="192.168.1.10"
|
||||
)
|
||||
|
||||
john_session_id = server.user_session_manager.remote_login(
|
||||
username="john.doe", password="12345", remote_ip_address="192.168.1.10"
|
||||
)
|
||||
|
||||
server.user_session_manager.remote_logout(admin_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(admin_session_id)
|
||||
|
||||
assert server.user_session_manager.validate_remote_session_uuid(jane_session_id)
|
||||
|
||||
assert server.user_session_manager.validate_remote_session_uuid(john_session_id)
|
||||
|
||||
server.user_session_manager.remote_logout(jane_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(admin_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(jane_session_id)
|
||||
|
||||
assert server.user_session_manager.validate_remote_session_uuid(john_session_id)
|
||||
|
||||
server.user_session_manager.remote_logout(john_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(admin_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(jane_session_id)
|
||||
|
||||
assert not server.user_session_manager.validate_remote_session_uuid(john_session_id)
|
||||
@@ -13,7 +13,7 @@ from primaite.simulator.network.hardware.node_operating_state import NodeOperati
|
||||
from primaite.simulator.network.hardware.nodes.host.host_node import HostNode
|
||||
from primaite.simulator.network.hardware.nodes.network.router import ACLAction, Router
|
||||
from primaite.simulator.network.transmission.transport_layer import Port
|
||||
from tests.conftest import DummyApplication, TestService
|
||||
from tests.conftest import DummyApplication, DummyService
|
||||
|
||||
|
||||
def test_successful_node_file_system_creation_request(example_network):
|
||||
@@ -61,7 +61,7 @@ def test_successful_application_requests(example_network):
|
||||
def test_successful_service_requests(example_network):
|
||||
net = example_network
|
||||
server_1 = net.get_node_by_hostname("server_1")
|
||||
server_1.software_manager.install(TestService)
|
||||
server_1.software_manager.install(DummyService)
|
||||
|
||||
# Careful: the order here is important, for example we cannot run "stop" unless we run "start" first
|
||||
for verb in [
|
||||
@@ -77,7 +77,7 @@ def test_successful_service_requests(example_network):
|
||||
"scan",
|
||||
"fix",
|
||||
]:
|
||||
resp_1 = net.apply_request(["node", "server_1", "service", "TestService", verb])
|
||||
resp_1 = net.apply_request(["node", "server_1", "service", "DummyService", verb])
|
||||
assert resp_1 == RequestResponse(status="success", data={})
|
||||
server_1.apply_timestep(timestep=1)
|
||||
server_1.apply_timestep(timestep=1)
|
||||
|
||||
@@ -7,6 +7,7 @@ from primaite.simulator.file_system.folder import Folder
|
||||
from primaite.simulator.network.hardware.base import Node, NodeOperatingState
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.system.software import SoftwareHealthState
|
||||
from tests.conftest import DummyApplication, DummyService
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -47,7 +48,7 @@ def test_node_shutdown(node):
|
||||
assert node.operating_state == NodeOperatingState.OFF
|
||||
|
||||
|
||||
def test_node_os_scan(node, service, application):
|
||||
def test_node_os_scan(node):
|
||||
"""Test OS Scanning."""
|
||||
node.operating_state = NodeOperatingState.ON
|
||||
|
||||
@@ -55,13 +56,15 @@ def test_node_os_scan(node, service, application):
|
||||
# TODO implement processes
|
||||
|
||||
# add services to node
|
||||
node.software_manager.install(DummyService)
|
||||
service = node.software_manager.software.get("DummyService")
|
||||
service.set_health_state(SoftwareHealthState.COMPROMISED)
|
||||
node.install_service(service=service)
|
||||
assert service.health_state_visible == SoftwareHealthState.UNUSED
|
||||
|
||||
# add application to node
|
||||
node.software_manager.install(DummyApplication)
|
||||
application = node.software_manager.software.get("DummyApplication")
|
||||
application.set_health_state(SoftwareHealthState.COMPROMISED)
|
||||
node.install_application(application=application)
|
||||
assert application.health_state_visible == SoftwareHealthState.UNUSED
|
||||
|
||||
# add folder and file to node
|
||||
@@ -91,7 +94,7 @@ def test_node_os_scan(node, service, application):
|
||||
assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT
|
||||
|
||||
|
||||
def test_node_red_scan(node, service, application):
|
||||
def test_node_red_scan(node):
|
||||
"""Test revealing to red"""
|
||||
node.operating_state = NodeOperatingState.ON
|
||||
|
||||
@@ -99,12 +102,14 @@ def test_node_red_scan(node, service, application):
|
||||
# TODO implement processes
|
||||
|
||||
# add services to node
|
||||
node.install_service(service=service)
|
||||
node.software_manager.install(DummyService)
|
||||
service = node.software_manager.software.get("DummyService")
|
||||
assert service.revealed_to_red is False
|
||||
|
||||
# add application to node
|
||||
node.software_manager.install(DummyApplication)
|
||||
application = node.software_manager.software.get("DummyApplication")
|
||||
application.set_health_state(SoftwareHealthState.COMPROMISED)
|
||||
node.install_application(application=application)
|
||||
assert application.revealed_to_red is False
|
||||
|
||||
# add folder and file to node
|
||||
|
||||
Reference in New Issue
Block a user