From e6676399141bbc2b175fb3b6de598d05aa27e03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret=20=28fepitre=29?= Date: Sun, 20 Oct 2019 17:36:06 +0200 Subject: [PATCH] tests: add test for guivm and keyboard_layout --- qubes/tests/vm/qubesvm.py | 65 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/qubes/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py index f5550a48..fafb2353 100644 --- a/qubes/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -1469,6 +1469,71 @@ class TC_90_QubesVM(QubesVMTestsMixin, qubes.tests.QubesTestCase): netvm.create_qdb_entries() self.assertEqual(test_qubesdb.data, expected) + @unittest.mock.patch('qubes.utils.get_timezone') + @unittest.mock.patch('qubes.utils.urandom') + @unittest.mock.patch('qubes.vm.qubesvm.QubesVM.untrusted_qdb') + def test_622_qdb_keyboard_layout(self, mock_qubesdb, mock_urandom, + mock_timezone): + mock_urandom.return_value = b'A' * 64 + mock_timezone.return_value = 'UTC' + template = self.get_vm( + cls=qubes.vm.templatevm.TemplateVM, name='template') + template.netvm = None + guivm = self.get_vm(cls=qubes.vm.appvm.AppVM, template=template, + name='sys-gui', qid=2, provides_network=False) + vm = self.get_vm(cls=qubes.vm.appvm.AppVM, template=template, + name='appvm', qid=3) + vm.netvm = None + vm.guivm = guivm + guivm.features['keyboard-layout'] = 'fr' + vm.events_enabled = True + test_qubesdb = TestQubesDB() + mock_qubesdb.write.side_effect = test_qubesdb.write + mock_qubesdb.rm.side_effect = test_qubesdb.rm + vm.create_qdb_entries() + self.maxDiff = None + + iptables_header = ( + '# Generated by Qubes Core on {}\n' + '*filter\n' + ':INPUT DROP [0:0]\n' + ':FORWARD DROP [0:0]\n' + ':OUTPUT ACCEPT [0:0]\n' + '-A INPUT -i vif+ -p udp -m udp --dport 68 -j DROP\n' + '-A INPUT -m conntrack --ctstate ' + 'RELATED,ESTABLISHED -j ACCEPT\n' + '-A INPUT -p icmp -j ACCEPT\n' + '-A INPUT -i lo -j ACCEPT\n' + '-A INPUT -j REJECT --reject-with ' + 'icmp-host-prohibited\n' + '-A FORWARD -m conntrack --ctstate ' + 'RELATED,ESTABLISHED -j ACCEPT\n' + '-A FORWARD -i vif+ -o vif+ -j DROP\n' + 'COMMIT\n'.format(datetime.datetime.now().ctime())) + + self.assertEqual(test_qubesdb.data, { + '/name': 'test-inst-appvm', + '/type': 'AppVM', + '/default-user': 'user', + '/keyboard-layout': 'fr', + '/qubes-vm-type': 'AppVM', + '/qubes-gui-domain-xid': '{}'.format(guivm.xid), + '/qubes-debug-mode': '0', + '/qubes-base-template': 'test-inst-template', + '/qubes-timezone': 'UTC', + '/qubes-random-seed': base64.b64encode(b'A' * 64), + '/qubes-vm-persistence': 'rw-only', + '/qubes-vm-updateable': 'False', + '/qubes-block-devices': '', + '/qubes-usb-devices': '', + '/qubes-iptables': 'reload', + '/qubes-iptables-error': '', + '/qubes-iptables-header': iptables_header, + '/qubes-service/qubes-update-check': '0', + '/qubes-service/meminfo-writer': '1', + }) + + @asyncio.coroutine def coroutine_mock(self, mock, *args, **kwargs): return mock(*args, **kwargs)