qubespolicy: fix handling ask,default_target=

This commit is contained in:
Marek Marczykowski-Górecki 2017-07-30 14:48:06 +02:00
parent 502f753be9
commit d650a90289
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
2 changed files with 9 additions and 1 deletions

View File

@ -378,7 +378,6 @@ class PolicyAction(object):
:return: None
'''
assert self.action == Action.ask
assert self.target is None
if response:
assert target in self.targets_for_ask
self.target = target

View File

@ -444,6 +444,15 @@ class TC_10_PolicyAction(qubes.tests.QubesTestCase):
action.handle_user_response(False, None)
self.assertEqual(action.action, qubespolicy.Action.deny)
def test_013_handle_user_response_with_default_target(self):
rule = qubespolicy.PolicyRule(
'$anyvm $anyvm ask,default_target=test-vm2')
action = qubespolicy.PolicyAction('test.service', 'test-vm1',
None, rule, 'test-vm2', ['test-vm2', 'test-vm3'])
action.handle_user_response(True, 'test-vm2')
self.assertEqual(action.action, qubespolicy.Action.allow)
self.assertEqual(action.target, 'test-vm2')
@unittest.mock.patch('qubespolicy.qubesd_call')
@unittest.mock.patch('subprocess.call')
def test_020_execute(self, mock_subprocess, mock_qubesd_call):