2016-04-20 13:41:33 +02:00
|
|
|
# pylint: disable=protected-access
|
|
|
|
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2016 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2014-2016 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
2016-04-20 13:41:33 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2016-04-20 13:41:33 +02:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-10-12 00:11:50 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2016-04-20 13:41:33 +02:00
|
|
|
#
|
2017-10-12 00:11:50 +02:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, see <https://www.gnu.org/licenses/>.
|
2016-04-20 13:41:33 +02:00
|
|
|
#
|
2017-01-18 22:16:46 +01:00
|
|
|
|
2016-05-21 03:47:28 +02:00
|
|
|
import unittest
|
2016-04-20 13:41:33 +02:00
|
|
|
|
|
|
|
import qubes
|
|
|
|
import qubes.vm.qubesvm
|
|
|
|
|
|
|
|
import qubes.tests
|
|
|
|
import qubes.tests.vm.qubesvm
|
|
|
|
|
|
|
|
class TC_00_NetVMMixin(
|
|
|
|
qubes.tests.vm.qubesvm.QubesVMTestsMixin, qubes.tests.QubesTestCase):
|
|
|
|
def setUp(self):
|
|
|
|
super(TC_00_NetVMMixin, self).setUp()
|
|
|
|
self.app = qubes.tests.vm.TestApp()
|
2016-05-21 03:30:53 +02:00
|
|
|
self.app.vmm.offline_mode = True
|
2016-04-20 13:41:33 +02:00
|
|
|
|
|
|
|
def setup_netvms(self, vm):
|
|
|
|
# usage of QubesVM here means that those tests should be after
|
|
|
|
# testing properties used here
|
|
|
|
self.netvm1 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=2,
|
|
|
|
name=qubes.tests.VMPREFIX + 'netvm1',
|
2017-12-01 02:59:17 +01:00
|
|
|
provides_network=True, netvm=None)
|
2016-04-20 13:41:33 +02:00
|
|
|
self.netvm2 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=3,
|
|
|
|
name=qubes.tests.VMPREFIX + 'netvm2',
|
2017-12-01 02:59:17 +01:00
|
|
|
provides_network=True, netvm=None)
|
2016-04-20 13:41:33 +02:00
|
|
|
self.nonetvm = qubes.vm.qubesvm.QubesVM(self.app, None, qid=4,
|
|
|
|
name=qubes.tests.VMPREFIX + 'nonet')
|
2016-05-20 04:22:28 +02:00
|
|
|
self.app.domains = qubes.app.VMCollection(self.app)
|
2016-04-20 13:41:33 +02:00
|
|
|
for domain in (vm, self.netvm1, self.netvm2, self.nonetvm):
|
|
|
|
self.app.domains._dict[domain.qid] = domain
|
|
|
|
self.app.default_netvm = self.netvm1
|
|
|
|
self.app.default_fw_netvm = self.netvm1
|
2017-09-19 17:01:29 +02:00
|
|
|
self.addCleanup(self.cleanup_netvms)
|
|
|
|
|
|
|
|
def cleanup_netvms(self):
|
|
|
|
self.netvm1.close()
|
|
|
|
self.netvm2.close()
|
|
|
|
self.nonetvm.close()
|
2017-12-03 03:21:35 +01:00
|
|
|
try:
|
|
|
|
self.app.domains.close()
|
|
|
|
except AttributeError:
|
|
|
|
pass
|
2017-09-19 17:01:29 +02:00
|
|
|
del self.netvm1
|
|
|
|
del self.netvm2
|
|
|
|
del self.nonetvm
|
|
|
|
del self.app.default_netvm
|
|
|
|
del self.app.default_fw_netvm
|
2016-04-20 13:41:33 +02:00
|
|
|
|
|
|
|
|
2016-06-02 22:02:06 +02:00
|
|
|
@qubes.tests.skipUnlessDom0
|
2016-04-20 13:41:33 +02:00
|
|
|
def test_140_netvm(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
|
|
|
|
self.assertPropertyValue(vm, 'netvm', self.netvm2, self.netvm2,
|
|
|
|
self.netvm2.name)
|
|
|
|
del vm.netvm
|
|
|
|
self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
|
|
|
|
self.assertPropertyValue(vm, 'netvm', self.netvm2.name, self.netvm2,
|
|
|
|
self.netvm2.name)
|
|
|
|
self.assertPropertyValue(vm, 'netvm', None, None, '')
|
|
|
|
|
|
|
|
def test_141_netvm_invalid(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'netvm', 'invalid')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'netvm', 123)
|
|
|
|
|
|
|
|
def test_142_netvm_netvm(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'netvm', self.nonetvm)
|
|
|
|
|
|
|
|
def test_143_netvm_loopback(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.app.domains = {1: vm, vm: vm}
|
2017-09-19 17:01:29 +02:00
|
|
|
self.addCleanup(self.app.domains.clear)
|
2016-04-20 13:41:33 +02:00
|
|
|
self.assertPropertyInvalidValue(vm, 'netvm', vm)
|
|
|
|
|
2017-09-27 02:19:36 +02:00
|
|
|
def test_144_netvm_loopback2(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
vm.netvm = None
|
|
|
|
self.netvm2.netvm = self.netvm1
|
|
|
|
vm.provides_network = True
|
|
|
|
self.netvm1.netvm = vm
|
|
|
|
self.assertPropertyInvalidValue(vm, 'netvm', self.netvm2)
|
|
|
|
|
2016-10-31 03:09:45 +01:00
|
|
|
def test_150_ip(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
self.assertPropertyDefaultValue(vm, 'ip', '10.137.0.' + str(vm.qid))
|
|
|
|
vm.ip = '192.168.1.1'
|
|
|
|
self.assertEqual(vm.ip, '192.168.1.1')
|
|
|
|
|
|
|
|
def test_151_ip_invalid(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
self.assertPropertyInvalidValue(vm, 'ip', 'abcd')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'ip', 'a.b.c.d')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'ip', '1111.2222.3333.4444')
|
|
|
|
# TODO: implement and add here: 0.0.0.0, 333.333.333.333
|
2017-12-01 03:24:34 +01:00
|
|
|
|
|
|
|
def test_160_ip6(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
self.assertPropertyDefaultValue(vm, 'ip6', None)
|
|
|
|
vm.netvm.features['ipv6'] = True
|
|
|
|
self.assertPropertyDefaultValue(vm, 'ip6',
|
|
|
|
'{}::a89:{:x}'.format(qubes.config.qubes_ipv6_prefix, vm.qid))
|
|
|
|
vm.ip6 = 'abcd:efff::1'
|
|
|
|
self.assertEqual(vm.ip6, 'abcd:efff::1')
|
|
|
|
|
|
|
|
def test_161_ip6_invalid(self):
|
|
|
|
vm = self.get_vm()
|
|
|
|
self.setup_netvms(vm)
|
|
|
|
vm.netvm.features['ipv6'] = True
|
|
|
|
self.assertPropertyInvalidValue(vm, 'ip', 'zzzz')
|
|
|
|
self.assertPropertyInvalidValue(vm, 'ip',
|
|
|
|
'1:2:3:4:5:6:7:8:0:a:b:c:d:e:f:0')
|