my-homelab-configs/tests/jeannie/test_network_sandbox_wan.py

32 lines
1.1 KiB
Python

import importlib.util
from pathlib import Path
import unittest
from unittest.mock import patch
path = Path(__file__).resolve().parents[2] / 'scripts/network-sandbox-wan-host.py'
spec = importlib.util.spec_from_file_location('sandbox_wan_host', path)
wan = importlib.util.module_from_spec(spec)
spec.loader.exec_module(wan)
class WanGuardTest(unittest.TestCase):
def test_guard_blocks_private_ranges_before_permitting_ipv4(self):
with patch.object(wan, 'run') as run:
wan.install_guard()
calls = [call.args for call in run.call_args_list]
for cidr in wan.BLOCKED:
self.assertTrue(any('dst_ip' in c and cidr in c and 'drop' in c for c in calls))
self.assertEqual(calls[-1][-2:], ('action', 'drop'))
self.assertIn('all', calls[-1])
def test_cleanup_disables_tap_before_qmp(self):
with patch.object(wan, 'run') as run, patch.object(wan, 'qmp') as qmp:
wan.isolate()
run.assert_called_once_with('ip', 'link', 'set', 'dev', wan.TAP, 'down')
qmp.assert_called_once_with(False)
if __name__ == '__main__':
unittest.main()