#3062 - First pass at unifying naming convention for discriminators (still errors) [skip ci]

This commit is contained in:
Marek Wolan
2025-02-03 16:24:03 +00:00
parent 055c853b0f
commit abccf4afc5
195 changed files with 2824 additions and 2802 deletions

View File

@@ -21,7 +21,7 @@ from primaite.game.agent.actions.service import (
def test_do_nothing_action_form_request():
"""Test that the do_nothingAction can form a request and that it is correct."""
request = DoNothingAction.form_request(DoNothingAction.ConfigSchema())
assert request == ["do_nothing"]
assert request == ["do-nothing"]
@pytest.mark.parametrize(

View File

@@ -13,15 +13,15 @@ def test_creating_empty_agent():
def test_creating_agent_from_dict():
action_config = {
"action_map": {
0: {"action": "do_nothing", "options": {}},
0: {"action": "do-nothing", "options": {}},
1: {
"action": "node_application_execute",
"action": "node-application-execute",
"options": {"node_name": "client", "application_name": "database"},
},
}
}
observation_config = {
"type": "FILE",
"type": "file",
"options": {
"file_name": "dog.pdf",
"include_num_access": False,
@@ -31,7 +31,7 @@ def test_creating_agent_from_dict():
reward_config = {
"reward_components": [
{
"type": "DATABASE_FILE_INTEGRITY",
"type": "database-file-integrity",
"weight": 0.3,
"options": {"node_hostname": "server", "folder_name": "database", "file_name": "database.db"},
}

View File

@@ -21,17 +21,17 @@ class TestFileSystemRequiresScan:
def test_obs_config(self, yaml_option_string, expected_val):
"""Check that the default behaviour is to set FileSystemRequiresScan to True."""
obs_cfg_yaml = f"""
type: CUSTOM
type: custom
options:
components:
- type: NODES
- type: nodes
label: NODES
options:
hosts:
- hostname: domain_controller
- hostname: web_server
services:
- service_name: WebServer
- service_name: web-server
- hostname: database_server
folders:
- folder_name: database
@@ -77,7 +77,7 @@ class TestFileSystemRequiresScan:
- UDP
num_rules: 10
- type: LINKS
- type: links
label: LINKS
options:
link_references:
@@ -91,7 +91,7 @@ class TestFileSystemRequiresScan:
- switch_2:eth-1<->client_1:eth-1
- switch_2:eth-2<->client_2:eth-1
- switch_2:eth-7<->security_suite:eth-2
- type: "NONE"
- type: "none"
label: ICS
options: {{}}

View File

@@ -28,13 +28,13 @@ def test_probabilistic_agent():
action_space_cfg = {
"action_map": {
0: {"action": "do_nothing", "options": {}},
0: {"action": "do-nothing", "options": {}},
1: {
"action": "node_application_execute",
"options": {"node_name": "client_1", "application_name": "WebBrowser"},
"action": "node-application-execute",
"options": {"node_name": "client_1", "application_name": "web-browser"},
},
2: {
"action": "node_file_delete",
"action": "node-file-delete",
"options": {"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"},
},
},
@@ -44,8 +44,8 @@ def test_probabilistic_agent():
game.options = PrimaiteGameOptions(ports=[], protocols=[])
pa_config = {
"type": "ProbabilisticAgent",
"ref": "ProbabilisticAgent",
"type": "probabilistic-agent",
"ref": "probabilistic-agent",
"team": "BLUE",
"action_space": action_space_cfg,
"agent_settings": {
@@ -60,11 +60,11 @@ def test_probabilistic_agent():
node_file_delete_count = 0
for _ in range(N_TRIALS):
a = pa.get_action(0)
if a == ("do_nothing", {}):
if a == ("do-nothing", {}):
do_nothing_count += 1
elif a == ("node_application_execute", {"node_name": "client_1", "application_name": "WebBrowser"}):
elif a == ("node-application-execute", {"node_name": "client_1", "application_name": "web-browser"}):
node_application_execute_count += 1
elif a == ("node_file_delete", {"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"}):
elif a == ("node-file-delete", {"node_name": "client_1", "folder_name": "downloads", "file_name": "cat.png"}):
node_file_delete_count += 1
else:
raise AssertionError("Probabilistic agent produced an unexpected action.")

View File

@@ -81,22 +81,22 @@ class TestWebpageUnavailabilitySticky:
reward = WebpageUnavailablePenalty(config=schema)
# no response codes yet, reward is 0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
browser_history = []
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 0
# agent did a successful fetch
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "web-browser"}
request = ["network", "node", "computer", "application", "web-browser", "execute"]
response = RequestResponse(status="success", data={})
browser_history.append({"outcome": 200})
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
@@ -104,34 +104,34 @@ class TestWebpageUnavailabilitySticky:
# THE IMPORTANT BIT
# agent did nothing, because reward is not sticky, it goes back to 0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
browser_history = []
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 0.0
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "web-browser"}
request = ["network", "node", "computer", "application", "web-browser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == -1.0
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "web-browser"}
request = ["network", "node", "computer", "application", "web-browser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
@@ -142,22 +142,22 @@ class TestWebpageUnavailabilitySticky:
reward = WebpageUnavailablePenalty(config=schema)
# no response codes yet, reward is 0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
browser_history = []
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 0
# agent did a successful fetch
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "web-browser"}
request = ["network", "node", "computer", "application", "web-browser", "execute"]
response = RequestResponse(status="success", data={})
browser_history.append({"outcome": 200})
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
@@ -165,33 +165,33 @@ class TestWebpageUnavailabilitySticky:
# THE IMPORTANT BIT
# agent did nothing, because reward is sticky, it stays at 1.0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 1.0
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "web-browser"}
request = ["network", "node", "computer", "application", "web-browser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == -1.0
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "WebBrowser"}
request = ["network", "node", "computer", "application", "WebBrowser", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "web-browser"}
request = ["network", "node", "computer", "application", "web-browser", "execute"]
response = RequestResponse(status="failure", data={})
browser_history.append({"outcome": 404})
state = {"network": {"nodes": {"computer": {"applications": {"WebBrowser": {"history": browser_history}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"web-browser": {"history": browser_history}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
@@ -207,20 +207,20 @@ class TestGreenAdminDatabaseUnreachableSticky:
reward = GreenAdminDatabaseUnreachablePenalty(config=schema)
# no response codes yet, reward is 0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 0
# agent did a successful fetch
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "database-client"}
request = ["network", "node", "computer", "application", "database-client", "execute"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
@@ -228,31 +228,31 @@ class TestGreenAdminDatabaseUnreachableSticky:
# THE IMPORTANT BIT
# agent did nothing, because reward is not sticky, it goes back to 0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 0.0
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "database-client"}
request = ["network", "node", "computer", "application", "database-client", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == -1.0
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "database-client"}
request = ["network", "node", "computer", "application", "database-client", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
@@ -266,20 +266,20 @@ class TestGreenAdminDatabaseUnreachableSticky:
reward = GreenAdminDatabaseUnreachablePenalty(config=schema)
# no response codes yet, reward is 0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 0
# agent did a successful fetch
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "database-client"}
request = ["network", "node", "computer", "application", "database-client", "execute"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
@@ -287,31 +287,31 @@ class TestGreenAdminDatabaseUnreachableSticky:
# THE IMPORTANT BIT
# agent did nothing, because reward is not sticky, it goes back to 0
action, params, request = "do_nothing", {}, ["do_nothing"]
action, params, request = "do-nothing", {}, ["do-nothing"]
response = RequestResponse(status="success", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == 1.0
# agent fails to fetch, get a -1.0 reward
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "database-client"}
request = ["network", "node", "computer", "application", "database-client", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)
assert reward.calculate(state, last_action_response) == -1.0
# agent fails again to fetch, get a -1.0 reward again
action = "node_application_execute"
params = {"node_name": "computer", "application_name": "DatabaseClient"}
request = ["network", "node", "computer", "application", "DatabaseClient", "execute"]
action = "node-application-execute"
params = {"node_name": "computer", "application_name": "database-client"}
request = ["network", "node", "computer", "application", "database-client", "execute"]
response = RequestResponse(status="failure", data={})
state = {"network": {"nodes": {"computer": {"applications": {"DatabaseClient": {}}}}}}
state = {"network": {"nodes": {"computer": {"applications": {"database-client": {}}}}}}
last_action_response = AgentHistoryItem(
timestep=0, action=action, parameters=params, request=request, response=response
)

View File

@@ -46,7 +46,7 @@ def test_file_reveal_to_red_scan(file_system):
assert file.revealed_to_red is True
@pytest.mark.skip(reason="node_file_checkhash not implemented")
@pytest.mark.skip(reason="node-file-checkhash not implemented")
def test_simulated_file_check_hash(file_system):
file: File = file_system.create_file(file_name="test_file.txt", folder_name="test_folder")

View File

@@ -32,7 +32,7 @@ def test_file_scan_request(populated_file_system):
assert file.visible_health_status == FileSystemItemHealthStatus.CORRUPT
@pytest.mark.skip(reason="node_file_checkhash not implemented")
@pytest.mark.skip(reason="node-file-checkhash not implemented")
def test_file_checkhash_request(populated_file_system):
"""Test that an agent can request a file hash check."""
fs, folder, file = populated_file_system

View File

@@ -120,7 +120,7 @@ def test_folder_corrupt_repair(file_system):
assert file.health_status == FileSystemItemHealthStatus.GOOD
@pytest.mark.skip(reason="node_file_checkhash not implemented")
@pytest.mark.skip(reason="node-file-checkhash not implemented")
def test_simulated_folder_check_hash(file_system):
folder: Folder = file_system.create_folder(folder_name="test_folder")
file_system.create_file(file_name="test_file.txt", folder_name="test_folder")

View File

@@ -51,7 +51,7 @@ def test_folder_scan_request(populated_file_system):
assert file2.visible_health_status == FileSystemItemHealthStatus.CORRUPT
@pytest.mark.skip(reason="node_folder_checkhash not implemented")
@pytest.mark.skip(reason="node-folder-checkhash not implemented")
def test_folder_checkhash_request(populated_file_system):
"""Test that an agent can request a folder hash check."""
fs, folder, file = populated_file_system

View File

@@ -57,13 +57,13 @@ def test_node_os_scan(node):
# add services to node
node.software_manager.install(DummyService)
service = node.software_manager.software.get("DummyService")
service = node.software_manager.software.get("dummy-service")
service.set_health_state(SoftwareHealthState.COMPROMISED)
assert service.health_state_visible == SoftwareHealthState.UNUSED
# add application to node
node.software_manager.install(DummyApplication)
application = node.software_manager.software.get("DummyApplication")
application = node.software_manager.software.get("dummy-application")
application.set_health_state(SoftwareHealthState.COMPROMISED)
assert application.health_state_visible == SoftwareHealthState.UNUSED
@@ -103,12 +103,12 @@ def test_node_red_scan(node):
# add services to node
node.software_manager.install(DummyService)
service = node.software_manager.software.get("DummyService")
service = node.software_manager.software.get("dummy-service")
assert service.revealed_to_red is False
# add application to node
node.software_manager.install(DummyApplication)
application = node.software_manager.software.get("DummyApplication")
application = node.software_manager.software.get("dummy-application")
application.set_health_state(SoftwareHealthState.COMPROMISED)
assert application.revealed_to_red is False

View File

@@ -56,7 +56,7 @@ def test_office_lan_from_config(kwargs):
net = Network()
config = dict(
type="office_lan",
type="office-lan",
lan_name=kwargs["lan_name"],
subnet_base=kwargs["subnet_base"],
pcs_ip_block_start=kwargs["pcs_ip_block_start"],

View File

@@ -44,8 +44,8 @@ def setup_c2(given_network: Network):
computer_a: Computer = network.get_node_by_hostname("computer_a")
computer_b: Computer = network.get_node_by_hostname("computer_b")
c2_beacon: C2Beacon = computer_b.software_manager.software.get("C2Beacon")
c2_server: C2Server = computer_a.software_manager.software.get("C2Server")
c2_beacon: C2Beacon = computer_b.software_manager.software.get("c2-beacon")
c2_server: C2Server = computer_a.software_manager.software.get("c2-server")
c2_beacon.configure(c2_server_ip_address="192.168.0.1", keep_alive_frequency=2)
c2_server.run()

View File

@@ -20,13 +20,13 @@ def dm_client() -> Node:
@pytest.fixture
def dm_bot(dm_client) -> DataManipulationBot:
return dm_client.software_manager.software.get("DataManipulationBot")
return dm_client.software_manager.software.get("data-manipulation-bot")
def test_create_dm_bot(dm_client):
data_manipulation_bot: DataManipulationBot = dm_client.software_manager.software.get("DataManipulationBot")
data_manipulation_bot: DataManipulationBot = dm_client.software_manager.software.get("data-manipulation-bot")
assert data_manipulation_bot.name == "DataManipulationBot"
assert data_manipulation_bot.name == "data-manipulation-bot"
assert data_manipulation_bot.port == PORT_LOOKUP["NONE"]
assert data_manipulation_bot.protocol == PROTOCOL_LOOKUP["NONE"]
assert data_manipulation_bot.payload == "DELETE"
@@ -75,8 +75,8 @@ def test_dm_bot_perform_data_manipulation_success(dm_bot):
def test_dm_bot_fails_without_db_client(dm_client):
dm_client.software_manager.uninstall("DatabaseClient")
dm_bot = dm_client.software_manager.software.get("DataManipulationBot")
dm_client.software_manager.uninstall("database-client")
dm_bot = dm_client.software_manager.software.get("data-manipulation-bot")
assert dm_bot._host_db_client is None
dm_bot.attack_stage = DataManipulationAttackStage.PORT_SCAN
dm_bot._perform_data_manipulation(p_of_success=1.0)

View File

@@ -18,7 +18,7 @@ def dos_bot() -> DoSBot:
computer.power_on()
computer.software_manager.install(DoSBot)
dos_bot: DoSBot = computer.software_manager.software.get("DoSBot")
dos_bot: DoSBot = computer.software_manager.software.get("dos-bot")
dos_bot.configure(target_ip_address=IPv4Address("192.168.0.1"))
return dos_bot

View File

@@ -5,18 +5,18 @@ from primaite.simulator.system.applications.application import Application
def test_adding_to_app_registry():
class temp_application(Application, discriminator="temp_app"):
class temp_application(Application, discriminator="temp-app"):
pass
assert Application._registry["temp_app"] is temp_application
assert Application._registry["temp-app"] is temp_application
with pytest.raises(ValueError):
class another_application(Application, discriminator="temp_app"):
class another_application(Application, discriminator="temp-app"):
pass
# This is kinda evil...
# Because pytest doesn't reimport classes from modules, registering this temporary test application will change the
# state of the Application registry for all subsequently run tests. So, we have to delete and unregister the class.
del temp_application
Application._registry.pop("temp_app")
Application._registry.pop("temp-app")

View File

@@ -20,7 +20,7 @@ def database_client_on_computer() -> Tuple[DatabaseClient, Computer]:
db_server = Server(hostname="db_server", ip_address="192.168.0.1", subnet_mask="255.255.255.0", start_up_duration=0)
db_server.power_on()
db_server.software_manager.install(DatabaseService)
db_server.software_manager.software["DatabaseService"].start()
db_server.software_manager.software["database-service"].start()
db_client = Computer(
hostname="db_client", ip_address="192.168.0.2", subnet_mask="255.255.255.0", start_up_duration=0
@@ -28,7 +28,7 @@ def database_client_on_computer() -> Tuple[DatabaseClient, Computer]:
db_client.power_on()
db_client.software_manager.install(DatabaseClient)
database_client: DatabaseClient = db_client.software_manager.software.get("DatabaseClient")
database_client: DatabaseClient = db_client.software_manager.software.get("database-client")
database_client.configure(server_ip_address=IPv4Address("192.168.0.1"))
database_client.run()

View File

@@ -21,7 +21,7 @@ def web_browser() -> WebBrowser:
)
computer.power_on()
# Web Browser should be pre-installed in computer
web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser")
web_browser: WebBrowser = computer.software_manager.software.get("web-browser")
web_browser.run()
assert web_browser.operating_state is ApplicationOperatingState.RUNNING
return web_browser
@@ -37,8 +37,8 @@ def test_create_web_client():
)
computer.power_on()
# Web Browser should be pre-installed in computer
web_browser: WebBrowser = computer.software_manager.software.get("WebBrowser")
assert web_browser.name is "WebBrowser"
web_browser: WebBrowser = computer.software_manager.software.get("web-browser")
assert web_browser.name is "web-browser"
assert web_browser.port is PORT_LOOKUP["HTTP"]
assert web_browser.protocol is PROTOCOL_LOOKUP["TCP"]

View File

@@ -11,7 +11,7 @@ def database_server() -> Node:
node = Computer(hostname="db_node", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0)
node.power_on()
node.software_manager.install(DatabaseService)
node.software_manager.software.get("DatabaseService").start()
node.software_manager.software.get("database-service").start()
return node

View File

@@ -26,14 +26,14 @@ def dns_client() -> Computer:
def test_create_dns_client(dns_client):
assert dns_client is not None
dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient")
assert dns_client_service.name is "DNSClient"
dns_client_service: DNSClient = dns_client.software_manager.software.get("dns-client")
assert dns_client_service.name is "dns-client"
assert dns_client_service.port is PORT_LOOKUP["DNS"]
assert dns_client_service.protocol is PROTOCOL_LOOKUP["TCP"]
def test_dns_client_add_domain_to_cache_when_not_running(dns_client):
dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient")
dns_client_service: DNSClient = dns_client.software_manager.software.get("dns-client")
assert dns_client.operating_state is NodeOperatingState.OFF
assert dns_client_service.operating_state is ServiceOperatingState.STOPPED
@@ -46,7 +46,7 @@ def test_dns_client_add_domain_to_cache_when_not_running(dns_client):
def test_dns_client_check_domain_exists_when_not_running(dns_client):
dns_client.operating_state = NodeOperatingState.ON
dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient")
dns_client_service: DNSClient = dns_client.software_manager.software.get("dns-client")
dns_client_service.start()
assert dns_client.operating_state is NodeOperatingState.ON
@@ -73,7 +73,7 @@ def test_dns_client_check_domain_exists_when_not_running(dns_client):
def test_dns_client_check_domain_in_cache(dns_client):
"""Test to make sure that the check_domain_in_cache returns the correct values."""
dns_client.operating_state = NodeOperatingState.ON
dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient")
dns_client_service: DNSClient = dns_client.software_manager.software.get("dns-client")
dns_client_service.start()
# add a domain to the dns client cache
@@ -85,7 +85,7 @@ def test_dns_client_check_domain_in_cache(dns_client):
def test_dns_client_receive(dns_client):
"""Test to make sure the DNS Client knows how to deal with request responses."""
dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient")
dns_client_service: DNSClient = dns_client.software_manager.software.get("dns-client")
dns_client_service.receive(
payload=DNSPacket(
@@ -99,6 +99,6 @@ def test_dns_client_receive(dns_client):
def test_dns_client_receive_non_dns_payload(dns_client):
dns_client_service: DNSClient = dns_client.software_manager.software.get("DNSClient")
dns_client_service: DNSClient = dns_client.software_manager.software.get("dns-client")
assert dns_client_service.receive(payload=None) is False

View File

@@ -30,15 +30,15 @@ def dns_server() -> Node:
def test_create_dns_server(dns_server):
assert dns_server is not None
dns_server_service: DNSServer = dns_server.software_manager.software.get("DNSServer")
assert dns_server_service.name is "DNSServer"
dns_server_service: DNSServer = dns_server.software_manager.software.get("dns-server")
assert dns_server_service.name is "dns-server"
assert dns_server_service.port is PORT_LOOKUP["DNS"]
assert dns_server_service.protocol is PROTOCOL_LOOKUP["TCP"]
def test_dns_server_domain_name_registration(dns_server):
"""Test to check if the domain name registration works."""
dns_server_service: DNSServer = dns_server.software_manager.software.get("DNSServer")
dns_server_service: DNSServer = dns_server.software_manager.software.get("dns-server")
# register the web server in the domain controller
dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12"))
@@ -50,7 +50,7 @@ def test_dns_server_domain_name_registration(dns_server):
def test_dns_server_receive(dns_server):
"""Test to make sure that the DNS Server correctly responds to a DNS Client request."""
dns_server_service: DNSServer = dns_server.software_manager.software.get("DNSServer")
dns_server_service: DNSServer = dns_server.software_manager.software.get("dns-server")
# register the web server in the domain controller
dns_server_service.dns_register(domain_name="real-domain.com", domain_ip_address=IPv4Address("192.168.1.12"))
@@ -60,7 +60,7 @@ def test_dns_server_receive(dns_server):
client.dns_server = IPv4Address("192.168.1.10")
network = Network()
network.connect(dns_server.network_interface[1], client.network_interface[1])
dns_client: DNSClient = client.software_manager.software["DNSClient"] # noqa
dns_client: DNSClient = client.software_manager.software["dns-client"] # noqa
dns_client.check_domain_exists("fake-domain.com")
assert dns_client.check_domain_exists("fake-domain.com") is False

View File

@@ -29,8 +29,8 @@ def ftp_client() -> Node:
def test_create_ftp_client(ftp_client):
assert ftp_client is not None
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient")
assert ftp_client_service.name is "FTPClient"
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("ftp-client")
assert ftp_client_service.name is "ftp-client"
assert ftp_client_service.port is PORT_LOOKUP["FTP"]
assert ftp_client_service.protocol is PROTOCOL_LOOKUP["TCP"]
@@ -51,7 +51,7 @@ def test_ftp_client_store_file(ftp_client):
status_code=FTPStatusCode.OK,
)
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient")
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("ftp-client")
ftp_client_service.receive(response)
assert ftp_client.file_system.get_file(folder_name="downloads", file_name="file.txt")
@@ -65,7 +65,7 @@ def test_ftp_should_not_process_commands_if_service_not_running(ftp_client):
status_code=FTPStatusCode.OK,
)
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient")
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("ftp-client")
ftp_client_service.stop()
assert ftp_client_service.operating_state is ServiceOperatingState.STOPPED
assert ftp_client_service._process_ftp_command(payload=payload).status_code is FTPStatusCode.ERROR
@@ -75,7 +75,7 @@ def test_ftp_tries_to_senf_file__that_does_not_exist(ftp_client):
"""Method send_file should return false if no file to send."""
assert ftp_client.file_system.get_file(folder_name="root", file_name="test.txt") is None
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient")
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("ftp-client")
assert ftp_client_service.operating_state is ServiceOperatingState.RUNNING
assert (
ftp_client_service.send_file(
@@ -91,7 +91,7 @@ def test_ftp_tries_to_senf_file__that_does_not_exist(ftp_client):
def test_offline_ftp_client_receives_request(ftp_client):
"""Receive should return false if the node the ftp client is installed on is offline."""
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient")
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("ftp-client")
ftp_client.power_off()
for i in range(ftp_client.shut_down_duration + 1):
@@ -111,7 +111,7 @@ def test_offline_ftp_client_receives_request(ftp_client):
def test_receive_should_fail_if_payload_is_not_ftp(ftp_client):
"""Receive should return false if the node the ftp client is installed on is not an FTPPacket."""
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient")
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("ftp-client")
assert ftp_client_service.receive(payload=None) is False
@@ -122,5 +122,5 @@ def test_receive_should_ignore_payload_with_none_status_code(ftp_client):
ftp_command_args=PORT_LOOKUP["FTP"],
status_code=None,
)
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("FTPClient")
ftp_client_service: FTPClient = ftp_client.software_manager.software.get("ftp-client")
assert ftp_client_service.receive(payload=payload) is False

View File

@@ -28,8 +28,8 @@ def ftp_server() -> Node:
def test_create_ftp_server(ftp_server):
assert ftp_server is not None
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer")
assert ftp_server_service.name is "FTPServer"
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("ftp-server")
assert ftp_server_service.name is "ftp-server"
assert ftp_server_service.port is PORT_LOOKUP["FTP"]
assert ftp_server_service.protocol is PROTOCOL_LOOKUP["TCP"]
@@ -49,7 +49,7 @@ def test_ftp_server_store_file(ftp_server):
packet_payload_size=24,
)
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer")
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("ftp-server")
ftp_server_service.receive(response)
assert ftp_server.file_system.get_file(folder_name="downloads", file_name="file.txt")
@@ -63,7 +63,7 @@ def test_ftp_server_should_send_error_if_port_arg_is_invalid(ftp_server):
packet_payload_size=24,
)
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer")
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("ftp-server")
assert ftp_server_service._process_ftp_command(payload=payload).status_code is FTPStatusCode.ERROR
@@ -71,7 +71,7 @@ def test_ftp_server_receives_non_ftp_packet(ftp_server):
"""Receive should return false if the service receives a non ftp packet."""
response: FTPPacket = None
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer")
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("ftp-server")
assert ftp_server_service.receive(response) is False
@@ -87,7 +87,7 @@ def test_offline_ftp_server_receives_request(ftp_server):
packet_payload_size=24,
)
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("FTPServer")
ftp_server_service: FTPServer = ftp_server.software_manager.software.get("ftp-server")
ftp_server_service.stop()
assert ftp_server_service.operating_state is ServiceOperatingState.STOPPED
assert ftp_server_service.receive(response) is False

View File

@@ -18,7 +18,7 @@ from primaite.simulator.network.protocols.ssh import (
SSHTransportMessage,
SSHUserCredentials,
)
from primaite.simulator.system.applications.red_applications.ransomware_script import RansomwareScript
from primaite.simulator.system.applications.red_applications.ransomware_script import ransomware_script
from primaite.simulator.system.services.dns.dns_server import DNSServer
from primaite.simulator.system.services.service import ServiceOperatingState
from primaite.simulator.system.services.terminal.terminal import RemoteTerminalConnection, Terminal
@@ -33,7 +33,7 @@ def terminal_on_computer() -> Tuple[Terminal, Computer]:
hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0
)
computer.power_on()
terminal: Terminal = computer.software_manager.software.get("Terminal")
terminal: Terminal = computer.software_manager.software.get("terminal")
return terminal, computer
@@ -82,7 +82,7 @@ def wireless_wan_network():
)
router_1.acl.add_rule(action=ACLAction.PERMIT, protocol=PROTOCOL_LOOKUP["ICMP"], position=23)
# add ACL rule to allow SSH traffic
# add acl rule to allow SSH traffic
router_1.acl.add_rule(
action=ACLAction.PERMIT, src_port=PORT_LOOKUP["SSH"], dst_port=PORT_LOOKUP["SSH"], position=21
)
@@ -142,25 +142,25 @@ def test_terminal_creation(terminal_on_computer):
def test_terminal_install_default():
"""Terminal should be auto installed onto Nodes"""
"""terminal should be auto installed onto Nodes"""
computer = Computer(hostname="node_a", ip_address="192.168.0.10", subnet_mask="255.255.255.0", start_up_duration=0)
computer.power_on()
assert computer.software_manager.software.get("Terminal")
assert computer.software_manager.software.get("terminal")
def test_terminal_not_on_switch():
"""Ensure terminal does not auto-install to switch"""
test_switch = Switch(hostname="Test")
assert not test_switch.software_manager.software.get("Terminal")
assert not test_switch.software_manager.software.get("terminal")
def test_terminal_send(basic_network):
"""Test that Terminal can send valid commands."""
"""Test that terminal can send valid commands."""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
payload: SSHPacket = SSHPacket(
@@ -178,7 +178,7 @@ def test_terminal_receive(basic_network):
"""Test that terminal can receive and process commands"""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
folder_name = "Downloads"
@@ -199,14 +199,14 @@ def test_terminal_receive(basic_network):
def test_terminal_install(basic_network):
"""Test that Terminal can successfully process an INSTALL request"""
"""Test that terminal can successfully process an INSTALL request"""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
payload: SSHPacket = SSHPacket(
payload=["software_manager", "application", "install", "RansomwareScript"],
payload=["software_manager", "application", "install", "ransomware-script"],
transport_message=SSHTransportMessage.SSH_MSG_SERVICE_REQUEST,
connection_message=SSHConnectionMessage.SSH_MSG_CHANNEL_OPEN,
)
@@ -215,16 +215,16 @@ def test_terminal_install(basic_network):
username="admin", password="admin", ip_address="192.168.0.11"
)
term_a_on_node_b.execute(["software_manager", "application", "install", "RansomwareScript"])
term_a_on_node_b.execute(["software_manager", "application", "install", "ransomware-script"])
assert computer_b.software_manager.software.get("RansomwareScript")
assert computer_b.software_manager.software.get("ransomware-script")
def test_terminal_fail_when_closed(basic_network):
"""Ensure Terminal won't attempt to send/receive when off"""
"""Ensure terminal won't attempt to send/receive when off"""
network: Network = basic_network
computer: Computer = network.get_node_by_hostname("node_a")
terminal: Terminal = computer.software_manager.software.get("Terminal")
terminal: Terminal = computer.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
terminal.operating_state = ServiceOperatingState.STOPPED
@@ -233,12 +233,12 @@ def test_terminal_fail_when_closed(basic_network):
def test_terminal_disconnect(basic_network):
"""Test Terminal disconnects"""
"""Test terminal disconnects"""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
terminal_b: Terminal = computer_b.software_manager.software.get("Terminal")
terminal_b: Terminal = computer_b.software_manager.software.get("terminal")
assert len(terminal_b._connections) == 0
@@ -256,10 +256,10 @@ def test_terminal_disconnect(basic_network):
def test_terminal_ignores_when_off(basic_network):
"""Terminal should ignore commands when not running"""
"""terminal should ignore commands when not running"""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
@@ -269,14 +269,14 @@ def test_terminal_ignores_when_off(basic_network):
terminal_a.operating_state = ServiceOperatingState.STOPPED
assert not term_a_on_term_b.execute(["software_manager", "application", "install", "RansomwareScript"])
assert not term_a_on_term_b.execute(["software_manager", "application", "install", "ransomware-script"])
def test_computer_remote_login_to_router(wireless_wan_network):
"""Test to confirm that a computer can SSH into a router."""
pc_a, _, router_1, _ = wireless_wan_network
pc_a_terminal: Terminal = pc_a.software_manager.software.get("Terminal")
pc_a_terminal: Terminal = pc_a.software_manager.software.get("terminal")
assert len(pc_a_terminal._connections) == 0
@@ -284,18 +284,18 @@ def test_computer_remote_login_to_router(wireless_wan_network):
assert len(pc_a_terminal._connections) == 1
payload = ["software_manager", "application", "install", "RansomwareScript"]
payload = ["software_manager", "application", "install", "ransomware-script"]
pc_a_on_router_1.execute(payload)
assert router_1.software_manager.software.get("RansomwareScript")
assert router_1.software_manager.software.get("ransomware-script")
def test_router_remote_login_to_computer(wireless_wan_network):
"""Test to confirm that a router can ssh into a computer."""
pc_a, _, router_1, _ = wireless_wan_network
router_1_terminal: Terminal = router_1.software_manager.software.get("Terminal")
router_1_terminal: Terminal = router_1.software_manager.software.get("terminal")
assert len(router_1_terminal._connections) == 0
@@ -303,21 +303,21 @@ def test_router_remote_login_to_computer(wireless_wan_network):
assert len(router_1_terminal._connections) == 1
payload = ["software_manager", "application", "install", "RansomwareScript"]
payload = ["software_manager", "application", "install", "ransomware-script"]
router_1_on_pc_a.execute(payload)
assert pc_a.software_manager.software.get("RansomwareScript")
assert pc_a.software_manager.software.get("ransomware-script")
def test_router_blocks_SSH_traffic(wireless_wan_network):
"""Test to check that router will block SSH traffic if no ACL rule."""
"""Test to check that router will block SSH traffic if no acl rule."""
pc_a, _, router_1, _ = wireless_wan_network
# Remove rule that allows SSH traffic.
router_1.acl.remove_rule(position=21)
pc_a_terminal: Terminal = pc_a.software_manager.software.get("Terminal")
pc_a_terminal: Terminal = pc_a.software_manager.software.get("terminal")
assert len(pc_a_terminal._connections) == 0
@@ -330,8 +330,8 @@ def test_SSH_across_network(wireless_wan_network):
"""Test to show ability to SSH across a network."""
pc_a, pc_b, router_1, router_2 = wireless_wan_network
terminal_a: Terminal = pc_a.software_manager.software.get("Terminal")
terminal_b: Terminal = pc_b.software_manager.software.get("Terminal")
terminal_a: Terminal = pc_a.software_manager.software.get("terminal")
terminal_b: Terminal = pc_b.software_manager.software.get("terminal")
router_2.acl.add_rule(
action=ACLAction.PERMIT, src_port=PORT_LOOKUP["SSH"], dst_port=PORT_LOOKUP["SSH"], position=21
@@ -348,7 +348,7 @@ def test_multiple_remote_terminals_same_node(basic_network):
"""Test to check that multiple remote terminals can be spawned by one node."""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
assert len(terminal_a._connections) == 0
@@ -366,10 +366,10 @@ def test_terminal_rejects_commands_if_disconnect(basic_network):
"""Test to check terminal will ignore commands from disconnected connections"""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
terminal_b: Terminal = computer_b.software_manager.software.get("Terminal")
terminal_b: Terminal = computer_b.software_manager.software.get("terminal")
remote_connection = terminal_a.login(username="admin", password="admin", ip_address="192.168.0.11")
@@ -381,9 +381,9 @@ def test_terminal_rejects_commands_if_disconnect(basic_network):
assert len(terminal_a._connections) == 0
assert len(terminal_b._connections) == 0
assert remote_connection.execute(["software_manager", "application", "install", "RansomwareScript"]) is False
assert remote_connection.execute(["software_manager", "application", "install", "ransomware-script"]) is False
assert not computer_b.software_manager.software.get("RansomwareScript")
assert not computer_b.software_manager.software.get("ransomware-script")
assert remote_connection.is_active is False
@@ -392,9 +392,9 @@ def test_terminal_connection_timeout(basic_network):
"""Test that terminal_connections are affected by UserSession timeout."""
network: Network = basic_network
computer_a: Computer = network.get_node_by_hostname("node_a")
terminal_a: Terminal = computer_a.software_manager.software.get("Terminal")
terminal_a: Terminal = computer_a.software_manager.software.get("terminal")
computer_b: Computer = network.get_node_by_hostname("node_b")
terminal_b: Terminal = computer_b.software_manager.software.get("Terminal")
terminal_b: Terminal = computer_b.software_manager.software.get("terminal")
remote_connection = terminal_a.login(username="admin", password="admin", ip_address="192.168.0.11")

View File

@@ -25,14 +25,14 @@ def web_server() -> Server:
)
node.power_on()
node.software_manager.install(WebServer)
node.software_manager.software.get("WebServer").start()
node.software_manager.software.get("web-server").start()
return node
def test_create_web_server(web_server):
assert web_server is not None
web_server_service: WebServer = web_server.software_manager.software.get("WebServer")
assert web_server_service.name is "WebServer"
web_server_service: WebServer = web_server.software_manager.software.get("web-server")
assert web_server_service.name is "web-server"
assert web_server_service.port is PORT_LOOKUP["HTTP"]
assert web_server_service.protocol is PROTOCOL_LOOKUP["TCP"]
@@ -40,7 +40,7 @@ def test_create_web_server(web_server):
def test_handling_get_request_not_found_path(web_server):
payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/fake-path")
web_server_service: WebServer = web_server.software_manager.software.get("WebServer")
web_server_service: WebServer = web_server.software_manager.software.get("web-server")
response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload)
assert response.status_code == HttpStatusCode.NOT_FOUND
@@ -49,7 +49,7 @@ def test_handling_get_request_not_found_path(web_server):
def test_handling_get_request_home_page(web_server):
payload = HttpRequestPacket(request_method=HttpRequestMethod.GET, request_url="http://domain.com/")
web_server_service: WebServer = web_server.software_manager.software.get("WebServer")
web_server_service: WebServer = web_server.software_manager.software.get("web-server")
response: HttpResponsePacket = web_server_service._handle_get_request(payload=payload)
assert response.status_code == HttpStatusCode.OK

View File

@@ -15,7 +15,7 @@ class TestSoftware(Service, discriminator="TestSoftware"):
class ConfigSchema(Service.ConfigSchema):
"""ConfigSChema for TestSoftware."""
type: str = "TestSoftware"
type: str = "test-software"
config: "TestSoftware.ConfigSchema" = Field(default_factory=lambda: TestSoftware.ConfigSchema())
@@ -26,7 +26,7 @@ class TestSoftware(Service, discriminator="TestSoftware"):
@pytest.fixture(scope="function")
def software(file_system):
return TestSoftware(
name="TestSoftware",
name="test-software",
port=PORT_LOOKUP["ARP"],
file_system=file_system,
sys_log=SysLog(hostname="test_service"),