From a46a43635fa4e723d229bf0d0f7f1632786b5690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 15 Mar 2019 05:35:36 +0100 Subject: [PATCH] qubespolicy: fix default target if it's a keyword Compare "api name", not "display name" when selecting default target in confirmation dialog. And add test for this case. Fixes QubesOS/qubes-issues#4881 --- qubespolicy/gtkhelpers.py | 9 +++++++-- qubespolicy/rpcconfirmation.py | 2 +- qubespolicy/tests/rpcconfirmation.py | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/qubespolicy/gtkhelpers.py b/qubespolicy/gtkhelpers.py index f68ed938..b53ec002 100644 --- a/qubespolicy/gtkhelpers.py +++ b/qubespolicy/gtkhelpers.py @@ -117,13 +117,18 @@ class VMListModeler: def apply_model(self, destination_object, vm_list, selection_trigger=None, activation_trigger=None): if isinstance(destination_object, Gtk.ComboBox): - list_store = Gtk.ListStore(int, str, GdkPixbuf.Pixbuf) + list_store = Gtk.ListStore(int, str, GdkPixbuf.Pixbuf, str) for entry_no, display_name in zip(itertools.count(), sorted(self._entries)): entry = self._entries[display_name] if entry['api_name'] in vm_list: - list_store.append([entry_no, display_name, entry['icon']]) + list_store.append([ + entry_no, + display_name, + entry['icon'], + entry['api_name'], + ]) destination_object.set_model(list_store) destination_object.set_id_column(1) diff --git a/qubespolicy/rpcconfirmation.py b/qubespolicy/rpcconfirmation.py index ec16b56f..0a89eb97 100644 --- a/qubespolicy/rpcconfirmation.py +++ b/qubespolicy/rpcconfirmation.py @@ -97,7 +97,7 @@ class RPCConfirmationWindow: found = False for item in model: - if item[1] == target: + if item[3] == target: found = True self._rpc_combo_box.set_active_iter( diff --git a/qubespolicy/tests/rpcconfirmation.py b/qubespolicy/tests/rpcconfirmation.py index e353a495..f0c426ca 100755 --- a/qubespolicy/tests/rpcconfirmation.py +++ b/qubespolicy/tests/rpcconfirmation.py @@ -253,6 +253,7 @@ class RPCConfirmationWindowTestWithTarget(RPCConfirmationWindowTestBase): if after_focus_timer: self.assertTrue(self._rpc_ok_button.get_sensitive()) self.assertTrue(self._focus_helper.can_perform_action()) + self.assertEqual(self._target_name, 'test-target') else: self.assertFalse(self._rpc_ok_button.get_sensitive()) self.assertFalse(self._focus_helper.can_perform_action()) @@ -262,6 +263,30 @@ class RPCConfirmationWindowTestWithTarget(RPCConfirmationWindowTestBase): self.assertIsNotNone(self._target_name) +class RPCConfirmationWindowTestWithDispVMTarget(RPCConfirmationWindowTestBase): + def __init__(self, test_method): + RPCConfirmationWindowTestBase.__init__(self, test_method, + source_name="test-source", rpc_operation="test.Operation", + target_name="@dispvm:test-disp6") + + def test_lifecycle_open_ok(self): + self._lifecycle_start(select_target=False) + self._lifecycle_click(click_type="ok") + + def assert_initial_state(self, after_focus_timer): + self.assertIsNotNone(self._target_name) + self.assertFalse(self.test_clicked_ok) + self.assertFalse(self.test_clicked_cancel) + self.assertFalse(self._confirmed) + if after_focus_timer: + self.assertTrue(self._rpc_ok_button.get_sensitive()) + self.assertTrue(self._focus_helper.can_perform_action()) + self.assertEqual(self._target_name, '@dispvm:test-disp6') + else: + self.assertFalse(self._rpc_ok_button.get_sensitive()) + self.assertFalse(self._focus_helper.can_perform_action()) + + class RPCConfirmationWindowTestWithTargetInvalid(unittest.TestCase): def __init__(self, *args, **kwargs): unittest.TestCase.__init__(self, *args, **kwargs)