"""Offline checks for the proposed OpenWrt sandbox configuration.""" import importlib.util import ipaddress import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[2] spec = importlib.util.spec_from_file_location('sandbox_config', ROOT / 'scripts/network-sandbox-config.py') module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) class NetworkSandboxConfigTests(unittest.TestCase): def test_vlan_networks_are_disjoint(self): self.assertFalse(module.SUBNETS[10].overlaps(module.SUBNETS[20])) self.assertFalse(module.SUBNETS[10].overlaps(ipaddress.ip_network('192.168.100.0/24'))) def test_default_deny_and_private_network_rules(self): configs = module.build_configs() self.assertIn("option forward 'REJECT'", configs['firewall']) for vid in (10, 20): self.assertIn(f"option device 'eth1.{vid}'", configs['network']) self.assertIn(f"option src 'lab{vid}'", configs['firewall']) for cidr in module.BLOCKED_NETWORKS: self.assertIn(f"option dest_ip '{cidr}'", configs['firewall']) self.assertNotIn("option dest 'lab20'", configs['firewall']) if __name__ == '__main__': unittest.main()