Skip to content

Commit

Permalink
qubespolicy: fix default target if it's a keyword
Browse files Browse the repository at this point in the history
Compare "api name", not "display name" when selecting default target in
confirmation dialog.
And add test for this case.

Fixes QubesOS/qubes-issues#4881

(cherry picked from commit a46a436)
  • Loading branch information
marmarek committed Apr 4, 2019
1 parent 2de1715 commit 4318ec7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
9 changes: 7 additions & 2 deletions qubespolicy/gtkhelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,18 @@ def _entry_activate(self, activation_trigger, combo, entry_box, whitelist):
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)
Expand Down
2 changes: 1 addition & 1 deletion qubespolicy/rpcconfirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _set_initial_target(self, source, target):

found = False
for item in model:
if item[1] == target:
if item[3] == target:
found = True

self._rpc_combo_box.set_active_iter(
Expand Down
25 changes: 25 additions & 0 deletions qubespolicy/tests/rpcconfirmation.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def assert_initial_state(self, after_focus_timer):
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())
Expand All @@ -262,6 +263,30 @@ def _lifecycle_click(self, click_type):
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)
Expand Down

0 comments on commit 4318ec7

Please sign in to comment.