#2257: add firewall via config + fix router hop ip address + shuffling around tests
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import yaml
|
||||
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from tests import TEST_ASSETS_ROOT
|
||||
|
||||
BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml"
|
||||
|
||||
DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml"
|
||||
|
||||
|
||||
def load_config(config_path: Union[str, Path]) -> PrimaiteGame:
|
||||
"""Returns a PrimaiteGame object which loads the contents of a given yaml path."""
|
||||
with open(config_path, "r") as f:
|
||||
cfg = yaml.safe_load(f)
|
||||
|
||||
return PrimaiteGame.from_config(cfg)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import pytest
|
||||
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.network.hardware.nodes.network.firewall import Firewall
|
||||
from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def dmz_config() -> Network:
|
||||
game = load_config(DMZ_NETWORK)
|
||||
return game.simulation.network
|
||||
|
||||
|
||||
def test_firewall_is_in_configuration(dmz_config):
|
||||
"""Test that the firewall exists in the configuration file."""
|
||||
network: Network = dmz_config
|
||||
|
||||
assert network.get_node_by_hostname("firewall")
|
||||
|
||||
|
||||
def test_firewall_routes_are_correctly_added(dmz_config):
|
||||
"""Test that the firewall routes have been correctly added to and configured in the network."""
|
||||
network: Network = dmz_config
|
||||
|
||||
firewall: Firewall = network.get_node_by_hostname("firewall")
|
||||
client_1: Computer = network.get_node_by_hostname("client_1")
|
||||
dmz_server: Server = network.get_node_by_hostname("dmz_server")
|
||||
external_computer: Computer = network.get_node_by_hostname("external_computer")
|
||||
external_server: Server = network.get_node_by_hostname("external_server")
|
||||
|
||||
# there should be a route to client_1
|
||||
assert firewall.route_table.find_best_route(client_1.network_interface[1].ip_address)
|
||||
assert dmz_server.ping(client_1.network_interface[1].ip_address)
|
||||
assert external_computer.ping(client_1.network_interface[1].ip_address)
|
||||
assert external_server.ping(client_1.network_interface[1].ip_address)
|
||||
|
||||
|
||||
def test_firewall_acl_rules_correctly_added():
|
||||
"""
|
||||
Test that makes sure that the firewall ACLs have been configured onto the firewall
|
||||
node via configuration file.
|
||||
"""
|
||||
pass
|
||||
@@ -0,0 +1,54 @@
|
||||
import pytest
|
||||
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.network.hardware.nodes.network.router import Router
|
||||
from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config
|
||||
|
||||
|
||||
@pytest.fixture(scope="function")
|
||||
def dmz_config() -> Network:
|
||||
game = load_config(DMZ_NETWORK)
|
||||
return game.simulation.network
|
||||
|
||||
|
||||
def test_router_is_in_configuration(dmz_config):
|
||||
"""Test that the router exists in the configuration file."""
|
||||
network: Network = dmz_config
|
||||
|
||||
assert network.get_node_by_hostname("router_1")
|
||||
|
||||
|
||||
def test_router_routes_are_correctly_added(dmz_config):
|
||||
"""Test that makes sure that router routes have been added from the configuration file."""
|
||||
network: Network = dmz_config
|
||||
|
||||
router_1: Router = network.get_node_by_hostname("router_1")
|
||||
client_1: Computer = network.get_node_by_hostname("client_1")
|
||||
dmz_server: Server = network.get_node_by_hostname("dmz_server")
|
||||
external_computer: Computer = network.get_node_by_hostname("external_computer")
|
||||
external_server: Server = network.get_node_by_hostname("external_server")
|
||||
|
||||
# there should be a route to dmz_server
|
||||
assert router_1.route_table.find_best_route(dmz_server.network_interface[1].ip_address)
|
||||
assert client_1.ping(dmz_server.network_interface[1].ip_address)
|
||||
assert external_computer.ping(dmz_server.network_interface[1].ip_address)
|
||||
assert external_server.ping(dmz_server.network_interface[1].ip_address)
|
||||
|
||||
# there should be a route to external_computer
|
||||
assert router_1.route_table.find_best_route(external_computer.network_interface[1].ip_address)
|
||||
assert client_1.ping(external_computer.network_interface[1].ip_address)
|
||||
assert dmz_server.ping(external_computer.network_interface[1].ip_address)
|
||||
assert external_server.ping(external_computer.network_interface[1].ip_address)
|
||||
|
||||
# there should be a route to external_server
|
||||
assert router_1.route_table.find_best_route(external_server.network_interface[1].ip_address)
|
||||
assert client_1.ping(external_server.network_interface[1].ip_address)
|
||||
assert dmz_server.ping(external_server.network_interface[1].ip_address)
|
||||
assert external_computer.ping(external_server.network_interface[1].ip_address)
|
||||
|
||||
|
||||
def test_router_acl_rules_correctly_added():
|
||||
"""Test that makes sure that the router ACLs have been configured onto the router node via configuration file."""
|
||||
pass
|
||||
@@ -0,0 +1,26 @@
|
||||
from primaite.config.load import example_config_path
|
||||
from primaite.simulator.network.container import Network
|
||||
from tests.integration_tests.configuration_file_parsing import DMZ_NETWORK, load_config
|
||||
|
||||
|
||||
def test_example_config():
|
||||
"""Test that the example config can be parsed properly."""
|
||||
game = load_config(example_config_path())
|
||||
network: Network = game.simulation.network
|
||||
|
||||
assert len(network.nodes) == 10 # 10 nodes in example network
|
||||
assert len(network.routers) == 1 # 1 router in network
|
||||
assert len(network.switches) == 2 # 2 switches in network
|
||||
assert len(network.servers) == 5 # 5 servers in network
|
||||
|
||||
|
||||
def test_dmz_config():
|
||||
"""Test that the DMZ network config can be parsed properly."""
|
||||
game = load_config(DMZ_NETWORK)
|
||||
|
||||
network: Network = game.simulation.network
|
||||
|
||||
assert len(network.nodes) == 9 # 9 nodes in network
|
||||
assert len(network.routers) == 2 # 2 routers in network
|
||||
assert len(network.switches) == 3 # 3 switches in network
|
||||
assert len(network.servers) == 2 # 2 servers in network
|
||||
@@ -1,76 +0,0 @@
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import yaml
|
||||
|
||||
from primaite.game.game import PrimaiteGame
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.network.hardware.nodes.host.server import Server
|
||||
from primaite.simulator.network.hardware.nodes.network.router import Router
|
||||
from tests import TEST_ASSETS_ROOT
|
||||
|
||||
DMZ_NETWORK = TEST_ASSETS_ROOT / "configs/dmz_network.yaml"
|
||||
|
||||
|
||||
def load_config(config_path: Union[str, Path]) -> PrimaiteGame:
|
||||
"""Returns a PrimaiteGame object which loads the contents of a given yaml path."""
|
||||
with open(config_path, "r") as f:
|
||||
cfg = yaml.safe_load(f)
|
||||
|
||||
return PrimaiteGame.from_config(cfg)
|
||||
|
||||
|
||||
def test_dmz_config():
|
||||
"""Test that the DMZ network config can be parsed properly."""
|
||||
game = load_config(DMZ_NETWORK)
|
||||
|
||||
network: Network = game.simulation.network
|
||||
|
||||
assert len(network.nodes) == 9 # 9 nodes in network
|
||||
assert len(network.routers) == 2 # 2 routers in network
|
||||
assert len(network.switches) == 3 # 3 switches in network
|
||||
assert len(network.servers) == 2 # 2 servers in network
|
||||
|
||||
|
||||
def test_router_routes_are_correctly_added():
|
||||
"""Test that makes sure that router routes have been added from the configuration file."""
|
||||
game = load_config(DMZ_NETWORK)
|
||||
|
||||
network: Network = game.simulation.network
|
||||
|
||||
router_1: Router = network.get_node_by_hostname("router_1")
|
||||
client_1: Computer = network.get_node_by_hostname("client_1")
|
||||
dmz_server: Server = network.get_node_by_hostname("dmz_server")
|
||||
external_computer: Computer = network.get_node_by_hostname("external_computer")
|
||||
external_server: Server = network.get_node_by_hostname("external_server")
|
||||
|
||||
# test that client_1 has a route to the DMZ and external nodes - they are on a second router
|
||||
|
||||
# there should be a route to the dmz server
|
||||
assert router_1.route_table.find_best_route(dmz_server.network_interface[1].ip_address)
|
||||
# ping DMZ server
|
||||
# assert client_1.ping(dmz_server.network_interface[1].ip_address)
|
||||
|
||||
|
||||
def test_firewall_node_added_to_network():
|
||||
"""Test that the firewall has been correctly added to and configured in the network."""
|
||||
pass
|
||||
|
||||
|
||||
def test_router_acl_rules_correctly_added():
|
||||
"""Test that makes sure that the router ACLs have been configured onto the router node via configuration file."""
|
||||
pass
|
||||
|
||||
|
||||
def test_firewall_routes_are_correctly_added():
|
||||
"""Test that the firewall routes have been correctly added to and configured in the network."""
|
||||
pass
|
||||
|
||||
|
||||
def test_firewall_acl_rules_correctly_added():
|
||||
"""
|
||||
Test that makes sure that the firewall ACLs have been configured onto the firewall
|
||||
node via configuration file.
|
||||
"""
|
||||
pass
|
||||
@@ -1,14 +1,6 @@
|
||||
from ipaddress import IPv4Address
|
||||
from pathlib import Path
|
||||
from typing import Union
|
||||
|
||||
import yaml
|
||||
|
||||
from primaite.config.load import example_config_path
|
||||
from primaite.game.agent.data_manipulation_bot import DataManipulationAgent
|
||||
from primaite.game.agent.interface import ProxyAgent, RandomAgent
|
||||
from primaite.game.game import APPLICATION_TYPES_MAPPING, PrimaiteGame, SERVICE_TYPES_MAPPING
|
||||
from primaite.simulator.network.container import Network
|
||||
from primaite.game.game import APPLICATION_TYPES_MAPPING, SERVICE_TYPES_MAPPING
|
||||
from primaite.simulator.network.hardware.nodes.host.computer import Computer
|
||||
from primaite.simulator.system.applications.database_client import DatabaseClient
|
||||
from primaite.simulator.system.applications.red_applications.data_manipulation_bot import DataManipulationBot
|
||||
@@ -22,47 +14,7 @@ from primaite.simulator.system.services.ftp.ftp_server import FTPServer
|
||||
from primaite.simulator.system.services.ntp.ntp_client import NTPClient
|
||||
from primaite.simulator.system.services.ntp.ntp_server import NTPServer
|
||||
from primaite.simulator.system.services.web_server.web_server import WebServer
|
||||
from tests import TEST_ASSETS_ROOT
|
||||
|
||||
BASIC_CONFIG = TEST_ASSETS_ROOT / "configs/basic_switched_network.yaml"
|
||||
|
||||
|
||||
def load_config(config_path: Union[str, Path]) -> PrimaiteGame:
|
||||
"""Returns a PrimaiteGame object which loads the contents of a given yaml path."""
|
||||
with open(config_path, "r") as f:
|
||||
cfg = yaml.safe_load(f)
|
||||
|
||||
return PrimaiteGame.from_config(cfg)
|
||||
|
||||
|
||||
def test_example_config():
|
||||
"""Test that the example config can be parsed properly."""
|
||||
game = load_config(example_config_path())
|
||||
|
||||
assert len(game.agents) == 4 # red, blue and 2 green agents
|
||||
|
||||
# green agent 1
|
||||
assert game.agents[0].agent_name == "client_2_green_user"
|
||||
assert isinstance(game.agents[0], RandomAgent)
|
||||
|
||||
# green agent 2
|
||||
assert game.agents[1].agent_name == "client_1_green_user"
|
||||
assert isinstance(game.agents[1], RandomAgent)
|
||||
|
||||
# red agent
|
||||
assert game.agents[2].agent_name == "client_1_data_manipulation_red_bot"
|
||||
assert isinstance(game.agents[2], DataManipulationAgent)
|
||||
|
||||
# blue agent
|
||||
assert game.agents[3].agent_name == "defender"
|
||||
assert isinstance(game.agents[3], ProxyAgent)
|
||||
|
||||
network: Network = game.simulation.network
|
||||
|
||||
assert len(network.nodes) == 10 # 10 nodes in example network
|
||||
assert len(network.routers) == 1 # 1 router in network
|
||||
assert len(network.switches) == 2 # 2 switches in network
|
||||
assert len(network.servers) == 5 # 5 servers in network
|
||||
from tests.integration_tests.configuration_file_parsing import BASIC_CONFIG, load_config
|
||||
|
||||
|
||||
def test_node_software_install():
|
||||
|
||||
Reference in New Issue
Block a user