Ensure empty service value delete /var/run/qubes-service/ file

- Add tests and stop patch path from Marek's comment
This commit is contained in:
Frédéric Pierret (fepitre) 2020-03-08 10:01:26 +01:00
parent bdc3c6588b
commit a61bb9a0cb
No known key found for this signature in database
GPG Key ID: 484010B5CDC576E2
2 changed files with 26 additions and 4 deletions

View File

@ -98,8 +98,11 @@ class ServicesExtension(qubes.ext.Extension):
vm.untrusted_qdb.write('/qubes-service/{}'.format(service),
str(int(bool(value))))
if vm.name == "dom0" and str(int(bool(value))) == "1":
self.add_dom0_service(vm, service)
if vm.name == "dom0":
if str(int(bool(value))) == "1":
self.add_dom0_service(vm, service)
else:
self.remove_dom0_service(vm, service)
@qubes.ext.handler('domain-feature-delete:*')
def on_domain_feature_delete(self, vm, event, feature):
@ -136,6 +139,8 @@ class ServicesExtension(qubes.ext.Extension):
service = feature[len('service.'):]
if str(int(bool(value))) == "1":
self.add_dom0_service(vm, service)
else:
self.remove_dom0_service(vm, service)
@qubes.ext.handler('features-request')
def supported_services(self, vm, event, untrusted_features):

View File

@ -336,6 +336,7 @@ class TC_20_Services(qubes.tests.QubesTestCase):
self.base_dir_patch = mock.patch.dict(
qubes.config.system_path, {'dom0_services_dir': self.test_base_dir})
self.base_dir_patch.start()
self.addCleanup(self.base_dir_patch.stop)
service = 'guivm-gui-agent'
service_path = self.test_base_dir + '/' + service
@ -343,7 +344,6 @@ class TC_20_Services(qubes.tests.QubesTestCase):
self.dom0,
'feature-set:service.service.guivm-gui-agent',
'service.guivm-gui-agent', '1')
self.assertEqual(os.path.exists(service_path), True)
def test_014_feature_delete_dom0(self):
@ -351,6 +351,7 @@ class TC_20_Services(qubes.tests.QubesTestCase):
self.base_dir_patch = mock.patch.dict(
qubes.config.system_path, {'dom0_services_dir': self.test_base_dir})
self.base_dir_patch.start()
self.addCleanup(self.base_dir_patch.stop)
service = 'guivm-gui-agent'
service_path = self.test_base_dir + '/' + service
@ -364,4 +365,20 @@ class TC_20_Services(qubes.tests.QubesTestCase):
'feature-delete:service.service.guivm-gui-agent',
'service.guivm-gui-agent')
self.assertEqual(os.path.exists(service_path), False)
self.assertEqual(os.path.exists(service_path), False)
def test_014_feature_set_empty_value_dom0(self):
self.test_base_dir = '/tmp/qubes-test-dir'
self.base_dir_patch = mock.patch.dict(
qubes.config.system_path, {'dom0_services_dir': self.test_base_dir})
self.base_dir_patch.start()
self.addCleanup(self.base_dir_patch.stop)
service = 'guivm-gui-agent'
service_path = self.test_base_dir + '/' + service
self.ext.on_domain_feature_set(
self.dom0,
'feature-set:service.service.guivm-gui-agent',
'service.guivm-gui-agent', '')
self.assertEqual(os.path.exists(service_path), False)