26 lines
1.3 KiB
Python
26 lines
1.3 KiB
Python
import importlib.util
|
|
from pathlib import Path
|
|
import unittest
|
|
|
|
spec = importlib.util.spec_from_file_location('configure_device', Path(__file__).resolve().parents[1] / 'tools/configure-device.py')
|
|
config = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(config)
|
|
|
|
class ConfigurationTests(unittest.TestCase):
|
|
def test_networks_and_interface_cannot_inject_filter_commands(self):
|
|
for interface in ['vlan; accept;', 'x"; reject;', 'vlan\n4']:
|
|
with self.assertRaises(ValueError):
|
|
config.settings(interface, '10.12.4.171', ['10.0.0.0/8'], 0)
|
|
for network in ['0.0.0.0/0', '10.1.2.3/8', '10.0.0.0/8; accept;', '::/0']:
|
|
with self.assertRaises(ValueError):
|
|
config.settings('funkfeuer-olsr', '10.12.4.171', [network], 0)
|
|
|
|
def test_generated_configuration_owns_only_reserved_routing(self):
|
|
address, rule, source = config.settings('funkfeuer-olsr', '10.12.4.171', ['10.0.0.0/8', '193.33.150.0/23'], 1)
|
|
self.assertEqual(address, '10.12.4.171')
|
|
self.assertIn('bgp-communities includes 64513:698', rule)
|
|
self.assertIn('else { reject; }', rule)
|
|
self.assertIn('set gw funkfeuer-olsr', rule)
|
|
self.assertIn('MainIp 10.12.4.171', source)
|
|
self.assertNotIn('Hna4', source)
|