tests: Add a test case for QubesVM.is_fully_usable

This commit adds a test case for the QubesVM class's is_fully_usable
method. The verified scenarios are as follows:

* The VM has qrexec enabled, and the qrexec service has been
  successfully started.
  (The VM becomes "fully usable" in this case.)

* The VM has qrexec enabled, and the qrexec service has failed to start
  (Error handling case; the VM is *not* fully usable.)

* The VM does *not* have qrexec enabled.
  (The VM becomes "fully usable" in this case.)
This commit is contained in:
M. Vefa Bicakci 2020-03-09 00:19:06 -04:00
parent 2d55841a5e
commit 5d755eb065
No known key found for this signature in database
GPG Key ID: 1DF87CE3B3A5DFAF

View File

@ -2049,3 +2049,39 @@ class TC_90_QubesVM(QubesVMTestsMixin, qubes.tests.QubesTestCase):
self.assertEqual(exc.exception.returncode, 1)
self.assertEqual(exc.exception.output, b'stdout')
self.assertEqual(exc.exception.stderr, b'stderr')
@unittest.mock.patch('os.path.exists')
def test_720_is_fully_usable(self, mock_os_path_exists):
vm_name = 'workvm'
qrexec_file_name = '/var/run/qubes/qrexec.{}'.format(
'test-inst-{}'.format(vm_name))
vm = self.get_vm(cls=qubes.vm.appvm.AppVM, name=vm_name)
# Dummy xid; greater than 0 to indicate a running AppVM
vm._qubesprop_xid = 10
self.assertGreater(vm.xid, 0)
with self.subTest('with_qrexec_started'):
mock_os_path_exists.return_value = True
vm.features['qrexec'] = True
fully_usable = vm.is_fully_usable()
mock_os_path_exists.assert_called_once_with(qrexec_file_name)
self.assertEqual(fully_usable, True)
mock_os_path_exists.reset_mock()
with self.subTest('with_qrexec_error'):
mock_os_path_exists.return_value = False
vm.features['qrexec'] = True
fully_usable = vm.is_fully_usable()
mock_os_path_exists.assert_called_once_with(qrexec_file_name)
self.assertEqual(fully_usable, False)
mock_os_path_exists.reset_mock()
with self.subTest('without_qrexec'):
vm.features['qrexec'] = False
fully_usable = vm.is_fully_usable()
mock_os_path_exists.assert_not_called()
self.assertEqual(fully_usable, True)