admin-api: fix handling admin.vm.property.Set with None VM value

Setting VMProperty to None VM should be encoded as '' value (according
to VMProperty._none_value). But value validation rejected this value.

QubesOS/qubes-issues#2622
This commit is contained in:
Marek Marczykowski-Górecki 2017-05-25 12:27:30 +02:00
parent 305fb5b6d0
commit 607dcbaf37
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 15 additions and 0 deletions

View File

@ -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):

View File

@ -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