From 273fedf74156a0249d672c80b3b43c4df6f6d966 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 15 Nov 2020 12:08:38 +0100 Subject: smoketest: tunnel: validate if local/remote address matches proper address family Certain tunnel types require that the local and remote IP is either both IPv4 or IPv6, add a check which ensures that an error is throws if this is not the case. --- smoketest/scripts/cli/test_interfaces_tunnel.py | 58 +++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'smoketest') diff --git a/smoketest/scripts/cli/test_interfaces_tunnel.py b/smoketest/scripts/cli/test_interfaces_tunnel.py index 1033196ce..c11426d01 100755 --- a/smoketest/scripts/cli/test_interfaces_tunnel.py +++ b/smoketest/scripts/cli/test_interfaces_tunnel.py @@ -156,6 +156,64 @@ class TunnelInterfaceTest(BasicInterfaceTest.BaseTest): self.assertEqual(self.local_v6, conf['linkinfo']['info_data']['local']) self.assertEqual(remote_ip6, conf['linkinfo']['info_data']['remote']) + def test_ipv4_local_remove_addr(self): + """ When running tests ensure that for certain encapsulation types the + local and remote IP address is actually an IPv4 address """ + + interface = f'tun1000' + local_if_addr = f'10.10.200.1/24' + for encapsulation in ['ipip', 'sit', 'gre']: + self.session.set(self._base_path + [interface, 'address', local_if_addr]) + self.session.set(self._base_path + [interface, 'encapsulation', encapsulation]) + self.session.set(self._base_path + [interface, 'local-ip', self.local_v6]) + self.session.set(self._base_path + [interface, 'remote-ip', remote_ip6]) + + # Encapsulation mode requires IPv6 local-ip + with self.assertRaises(ConfigSessionError): + self.session.commit() + self.session.set(self._base_path + [interface, 'local-ip', self.local_v4]) + + # Encapsulation mode requires IPv6 local-ip + with self.assertRaises(ConfigSessionError): + self.session.commit() + self.session.set(self._base_path + [interface, 'remote-ip', remote_ip4]) + + # Check if commit is ok + self.session.commit() + + # cleanup this instance + self.session.delete(self._base_path + [interface]) + self.session.commit() + + def test_ipv6_local_remove_addr(self): + """ When running tests ensure that for certain encapsulation types the + local and remote IP address is actually an IPv6 address """ + + interface = f'tun1010' + local_if_addr = f'10.10.200.1/24' + for encapsulation in ['ipip6', 'ip6ip6', 'ip6gre']: + self.session.set(self._base_path + [interface, 'address', local_if_addr]) + self.session.set(self._base_path + [interface, 'encapsulation', encapsulation]) + self.session.set(self._base_path + [interface, 'local-ip', self.local_v4]) + self.session.set(self._base_path + [interface, 'remote-ip', remote_ip4]) + + # Encapsulation mode requires IPv6 local-ip + with self.assertRaises(ConfigSessionError): + self.session.commit() + self.session.set(self._base_path + [interface, 'local-ip', self.local_v6]) + + # Encapsulation mode requires IPv6 local-ip + with self.assertRaises(ConfigSessionError): + self.session.commit() + self.session.set(self._base_path + [interface, 'remote-ip', remote_ip6]) + + # Check if commit is ok + self.session.commit() + + # cleanup this instance + self.session.delete(self._base_path + [interface]) + self.session.commit() + def test_ip6ip6(self): interface = 'tun120' encapsulation = 'ip6ip6' -- cgit v1.2.3