2014-12-29 12:46:16 +01:00
|
|
|
#!/usr/bin/python2 -O
|
2015-01-19 18:03:23 +01:00
|
|
|
# vim: fileencoding=utf-8
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=protected-access
|
2015-01-19 18:03:23 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# The Qubes OS Project, https://www.qubes-os.org/
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014-2015 Joanna Rutkowska <joanna@invisiblethingslab.com>
|
|
|
|
# Copyright (C) 2014-2015 Wojtek Porczyk <woju@invisiblethingslab.com>
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
import qubes
|
2015-10-14 22:02:11 +02:00
|
|
|
import qubes.exc
|
2015-01-20 14:09:47 +01:00
|
|
|
import qubes.config
|
2014-12-29 12:46:16 +01:00
|
|
|
import qubes.vm.qubesvm
|
|
|
|
|
2015-01-05 14:41:59 +01:00
|
|
|
import qubes.tests
|
|
|
|
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
class TestProp(object):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2014-12-29 12:46:16 +01:00
|
|
|
__name__ = 'testprop'
|
|
|
|
|
|
|
|
|
|
|
|
class TestVM(object):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=too-few-public-methods
|
2014-12-29 12:46:16 +01:00
|
|
|
def __init__(self):
|
|
|
|
self.running = False
|
|
|
|
self.installed_by_rpm = False
|
|
|
|
|
|
|
|
def is_running(self):
|
|
|
|
return self.running
|
|
|
|
|
|
|
|
|
2015-01-05 14:41:59 +01:00
|
|
|
class TC_00_setters(qubes.tests.QubesTestCase):
|
2014-12-29 12:46:16 +01:00
|
|
|
def setUp(self):
|
|
|
|
self.vm = TestVM()
|
|
|
|
self.prop = TestProp()
|
|
|
|
|
|
|
|
|
|
|
|
def test_000_setter_qid(self):
|
|
|
|
self.assertEqual(
|
|
|
|
qubes.vm.qubesvm._setter_qid(self.vm, self.prop, 5), 5)
|
|
|
|
|
|
|
|
def test_001_setter_qid_lt_0(self):
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_qid(self.vm, self.prop, -1)
|
|
|
|
|
|
|
|
def test_002_setter_qid_gt_max(self):
|
|
|
|
with self.assertRaises(ValueError):
|
2015-01-20 14:09:47 +01:00
|
|
|
qubes.vm.qubesvm._setter_qid(self.vm,
|
|
|
|
self.prop, qubes.config.max_qid + 5)
|
2014-12-29 12:46:16 +01:00
|
|
|
|
|
|
|
|
|
|
|
def test_010_setter_name(self):
|
|
|
|
self.assertEqual(
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'),
|
|
|
|
'test_name-1')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_011_setter_name_not_a_string(self):
|
|
|
|
# pylint: disable=invalid-name
|
|
|
|
with self.assertRaises(TypeError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, False)
|
|
|
|
|
|
|
|
def test_012_setter_name_longer_than_31(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32)
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_013_setter_name_illegal_character(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_014_setter_name_first_not_letter(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_015_setter_name_running(self):
|
2014-12-29 12:46:16 +01:00
|
|
|
self.vm.running = True
|
2015-10-14 22:02:11 +02:00
|
|
|
with self.assertRaises(qubes.exc.QubesVMNotHaltedError):
|
2014-12-29 12:46:16 +01:00
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
|
|
|
|
|
2015-12-29 20:35:04 +01:00
|
|
|
def test_016_setter_name_installed_by_rpm(self):
|
2015-01-19 19:02:28 +01:00
|
|
|
# pylint: disable=invalid-name
|
2014-12-29 12:46:16 +01:00
|
|
|
self.vm.installed_by_rpm = True
|
2015-10-14 22:02:11 +02:00
|
|
|
with self.assertRaises(qubes.exc.QubesException):
|
2014-12-29 12:46:16 +01:00
|
|
|
qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname')
|
|
|
|
|
|
|
|
|
|
|
|
@unittest.skip('test not implemented')
|
|
|
|
def test_020_setter_kernel(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2015-01-05 14:41:59 +01:00
|
|
|
class TC_90_QubesVM(qubes.tests.QubesTestCase):
|
2015-12-29 20:35:04 +01:00
|
|
|
def setUp(self):
|
|
|
|
super(TC_90_QubesVM, self).setUp()
|
|
|
|
self.app = qubes.tests.vm.TestApp()
|
|
|
|
|
2015-01-19 17:06:30 +01:00
|
|
|
def test_000_init(self):
|
2015-12-29 22:04:00 +01:00
|
|
|
qubes.vm.qubesvm.QubesVM(self.app, None,
|
2015-12-29 20:35:04 +01:00
|
|
|
qid=1, name=qubes.tests.VMPREFIX + 'test')
|
|
|
|
|
|
|
|
def test_001_init_no_qid_or_name(self):
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
qubes.vm.qubesvm.QubesVM(self.app, None,
|
|
|
|
name=qubes.tests.VMPREFIX + 'test')
|
|
|
|
with self.assertRaises(AssertionError):
|
|
|
|
qubes.vm.qubesvm.QubesVM(self.app, None,
|
|
|
|
qid=1)
|
|
|
|
|
|
|
|
def test_003_init_fire_domain_init(self):
|
|
|
|
class TestVM2(qubes.vm.qubesvm.QubesVM):
|
|
|
|
event_fired = False
|
|
|
|
@qubes.events.handler('domain-init')
|
2015-12-29 22:04:00 +01:00
|
|
|
def on_domain_init(self, event): # pylint: disable=unused-argument
|
2015-12-29 20:35:04 +01:00
|
|
|
self.__class__.event_fired = True
|
|
|
|
|
2015-12-29 22:04:00 +01:00
|
|
|
TestVM2(self.app, None, qid=1, name=qubes.tests.VMPREFIX + 'test')
|
2015-12-29 20:35:04 +01:00
|
|
|
self.assertTrue(TestVM2.event_fired)
|