From d650a90289a964623f8122e003c18a0ef54b11b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Sun, 30 Jul 2017 14:48:06 +0200 Subject: [PATCH] qubespolicy: fix handling ask,default_target= --- qubespolicy/__init__.py | 1 - qubespolicy/tests/__init__.py | 9 +++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/qubespolicy/__init__.py b/qubespolicy/__init__.py index 3473bfc9..0d8a6452 100755 --- a/qubespolicy/__init__.py +++ b/qubespolicy/__init__.py @@ -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 diff --git a/qubespolicy/tests/__init__.py b/qubespolicy/tests/__init__.py index 536d1b22..1f937e95 100644 --- a/qubespolicy/tests/__init__.py +++ b/qubespolicy/tests/__init__.py @@ -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):