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:
parent
bdc3c6588b
commit
a61bb9a0cb
@ -98,8 +98,11 @@ class ServicesExtension(qubes.ext.Extension):
|
|||||||
vm.untrusted_qdb.write('/qubes-service/{}'.format(service),
|
vm.untrusted_qdb.write('/qubes-service/{}'.format(service),
|
||||||
str(int(bool(value))))
|
str(int(bool(value))))
|
||||||
|
|
||||||
if vm.name == "dom0" and str(int(bool(value))) == "1":
|
if vm.name == "dom0":
|
||||||
self.add_dom0_service(vm, service)
|
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:*')
|
@qubes.ext.handler('domain-feature-delete:*')
|
||||||
def on_domain_feature_delete(self, vm, event, feature):
|
def on_domain_feature_delete(self, vm, event, feature):
|
||||||
@ -136,6 +139,8 @@ class ServicesExtension(qubes.ext.Extension):
|
|||||||
service = feature[len('service.'):]
|
service = feature[len('service.'):]
|
||||||
if str(int(bool(value))) == "1":
|
if str(int(bool(value))) == "1":
|
||||||
self.add_dom0_service(vm, service)
|
self.add_dom0_service(vm, service)
|
||||||
|
else:
|
||||||
|
self.remove_dom0_service(vm, service)
|
||||||
|
|
||||||
@qubes.ext.handler('features-request')
|
@qubes.ext.handler('features-request')
|
||||||
def supported_services(self, vm, event, untrusted_features):
|
def supported_services(self, vm, event, untrusted_features):
|
||||||
|
@ -336,6 +336,7 @@ class TC_20_Services(qubes.tests.QubesTestCase):
|
|||||||
self.base_dir_patch = mock.patch.dict(
|
self.base_dir_patch = mock.patch.dict(
|
||||||
qubes.config.system_path, {'dom0_services_dir': self.test_base_dir})
|
qubes.config.system_path, {'dom0_services_dir': self.test_base_dir})
|
||||||
self.base_dir_patch.start()
|
self.base_dir_patch.start()
|
||||||
|
self.addCleanup(self.base_dir_patch.stop)
|
||||||
service = 'guivm-gui-agent'
|
service = 'guivm-gui-agent'
|
||||||
service_path = self.test_base_dir + '/' + service
|
service_path = self.test_base_dir + '/' + service
|
||||||
|
|
||||||
@ -343,7 +344,6 @@ class TC_20_Services(qubes.tests.QubesTestCase):
|
|||||||
self.dom0,
|
self.dom0,
|
||||||
'feature-set:service.service.guivm-gui-agent',
|
'feature-set:service.service.guivm-gui-agent',
|
||||||
'service.guivm-gui-agent', '1')
|
'service.guivm-gui-agent', '1')
|
||||||
|
|
||||||
self.assertEqual(os.path.exists(service_path), True)
|
self.assertEqual(os.path.exists(service_path), True)
|
||||||
|
|
||||||
def test_014_feature_delete_dom0(self):
|
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(
|
self.base_dir_patch = mock.patch.dict(
|
||||||
qubes.config.system_path, {'dom0_services_dir': self.test_base_dir})
|
qubes.config.system_path, {'dom0_services_dir': self.test_base_dir})
|
||||||
self.base_dir_patch.start()
|
self.base_dir_patch.start()
|
||||||
|
self.addCleanup(self.base_dir_patch.stop)
|
||||||
service = 'guivm-gui-agent'
|
service = 'guivm-gui-agent'
|
||||||
service_path = self.test_base_dir + '/' + service
|
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',
|
'feature-delete:service.service.guivm-gui-agent',
|
||||||
'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)
|
||||||
|
Loading…
Reference in New Issue
Block a user