ソースを参照

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
Marek Marczykowski-Górecki 5 年 前
コミット
a46a43635f

+ 7 - 2
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)

+ 1 - 1
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(

+ 25 - 0
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)