diff --git a/qubes/tests/api_admin.py b/qubes/tests/api_admin.py index 3cff7131..c10ea375 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -155,6 +155,17 @@ class TC_00_VMs(AdminAPITestCase): mock.assert_called_once_with(self.vm, 'test-net') self.app.save.assert_called_once_with() + def test_0301_vm_property_set_vm_none(self): + netvm = self.app.add_new_vm('AppVM', label='red', name='test-net', + template='test-template', provides_network=True) + + with unittest.mock.patch('qubes.vm.VMProperty.__set__') as mock: + value = self.call_mgmt_func(b'admin.vm.property.Set', b'test-vm1', + b'netvm', b'') + self.assertIsNone(value) + mock.assert_called_once_with(self.vm, '') + self.app.save.assert_called_once_with() + def test_032_vm_property_set_vm_invalid1(self): with unittest.mock.patch('qubes.vm.VMProperty.__set__') as mock: with self.assertRaises(qubes.exc.QubesValueError): diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index d9532f53..05639f13 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -442,5 +442,9 @@ class VMProperty(qubes.property): untrusted_vmname = untrusted_newvalue.decode('ascii') except UnicodeDecodeError: raise qubes.exc.QubesValueError + if untrusted_vmname == '': + # allow empty VM name for setting VMProperty value, because it's + # string representation of None (see self._none_value) + return untrusted_vmname validate_name(None, self, untrusted_vmname) return untrusted_vmname