mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-10 01:18:03 +03:00
uitests: Add connection user/pass auth testing
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
f6e880b195
commit
485dddf2ed
@ -55,3 +55,53 @@ class UITestConnection(uiutils.UITestCase):
|
||||
manager = self.app.topwin
|
||||
self.sleep(2.5)
|
||||
uiutils.check(lambda: manager.active)
|
||||
|
||||
def testConnectionOpenauth(self):
|
||||
self.app.open(
|
||||
extra_opts=["--test-options=fake-openauth"],
|
||||
window_name="Authentication required")
|
||||
|
||||
dialog = self.app.root.find("Authentication required")
|
||||
def _run():
|
||||
username = dialog.find("Username:.*entry")
|
||||
password = dialog.find("Password:.*entry")
|
||||
username.click()
|
||||
username.text = "foo"
|
||||
self.pressKey("Enter")
|
||||
uiutils.check(lambda: password.focused)
|
||||
password.typeText("bar")
|
||||
|
||||
|
||||
_run()
|
||||
dialog.find("OK", "push button").click()
|
||||
uiutils.check(lambda: not dialog.showing)
|
||||
manager = self.app.root.find("Virtual Machine Manager", "frame")
|
||||
manager.find("^test testdriver.xml$", "table cell")
|
||||
|
||||
# Disconnect and reconnect to trigger it again
|
||||
def _retrigger_connection():
|
||||
manager.click()
|
||||
c = manager.find_fuzzy("testdriver.xml", "table cell")
|
||||
c.click()
|
||||
c.click(button=3)
|
||||
self.app.root.find("conn-disconnect", "menu item").click()
|
||||
manager.click()
|
||||
c = manager.find_fuzzy("testdriver.xml", "table cell")
|
||||
c.click()
|
||||
c.click(button=3)
|
||||
self.app.root.find("conn-connect", "menu item").click()
|
||||
|
||||
_retrigger_connection()
|
||||
dialog = self.app.root.find("Authentication required")
|
||||
_run()
|
||||
self.pressKey("Enter")
|
||||
uiutils.check(lambda: not dialog.showing)
|
||||
manager = self.app.root.find("Virtual Machine Manager", "frame")
|
||||
manager.find("^test testdriver.xml$", "table cell")
|
||||
|
||||
_retrigger_connection()
|
||||
dialog = self.app.root.find("Authentication required")
|
||||
dialog.find("Cancel", "push button").click()
|
||||
uiutils.check(lambda: not dialog.showing)
|
||||
self._click_alert_button("Unable to connect", "Close")
|
||||
manager.find("test testdriver.xml - Not Connected", "table cell")
|
||||
|
@ -911,7 +911,11 @@ class vmmConnection(vmmGObject):
|
||||
exc = None
|
||||
|
||||
try:
|
||||
self._backend.open(connectauth.creds_dialog, self)
|
||||
cb = connectauth.creds_dialog
|
||||
data = self
|
||||
if self.config.CLITestOptions.fake_openauth:
|
||||
testmock.fake_openauth(self, cb, data)
|
||||
self._backend.open(cb, data)
|
||||
return True, None
|
||||
except Exception as e:
|
||||
exc = e
|
||||
|
@ -75,7 +75,7 @@ class _vmmConnectAuth(vmmGObjectUI):
|
||||
noecho = credtype in [
|
||||
libvirt.VIR_CRED_PASSPHRASE,
|
||||
libvirt.VIR_CRED_NOECHOPROMPT]
|
||||
if not prompt:
|
||||
if not prompt: # pragma: no cover
|
||||
raise RuntimeError("No prompt for auth credtype=%s" % credtype)
|
||||
|
||||
prompt += ": "
|
||||
@ -84,6 +84,7 @@ class _vmmConnectAuth(vmmGObjectUI):
|
||||
uiutil.set_grid_row_visible(label, True)
|
||||
label.set_text(prompt)
|
||||
entry.set_visibility(not noecho)
|
||||
entry.get_accessible().set_name(prompt + " entry")
|
||||
|
||||
def run(self):
|
||||
self.topwin.show()
|
||||
@ -96,7 +97,6 @@ class _vmmConnectAuth(vmmGObjectUI):
|
||||
self.creds[0][4] = self.entry1.get_text()
|
||||
if self.entry2.get_visible():
|
||||
self.creds[1][4] = self.entry2.get_text()
|
||||
self.topwin.destroy()
|
||||
return 0
|
||||
|
||||
def _ok_cb(self, src):
|
||||
@ -126,7 +126,8 @@ def creds_dialog(creds, cbdata):
|
||||
_conn = cbdata
|
||||
dialogobj = _vmmConnectAuth(creds)
|
||||
ret = dialogobj.run()
|
||||
except Exception:
|
||||
dialogobj.cleanup()
|
||||
except Exception: # pragma: no cover
|
||||
log.exception("Error from creds dialog")
|
||||
ret = -1
|
||||
retipc.append(ret)
|
||||
|
@ -95,6 +95,17 @@ def schedule_fake_nodedev_event(conn, lifecycle_cb, update_cb):
|
||||
conn.timeout_add(2000, update_cb_wrapper)
|
||||
|
||||
|
||||
def fake_openauth(conn, cb, data):
|
||||
ignore = conn
|
||||
import libvirt
|
||||
creds = [
|
||||
[libvirt.VIR_CRED_USERNAME, "Username", None, None, None],
|
||||
[libvirt.VIR_CRED_PASSPHRASE, "Password", None, None, None],
|
||||
]
|
||||
cb(creds, data)
|
||||
assert all([bool(cred[4]) for cred in creds])
|
||||
|
||||
|
||||
class CLITestOptionsClass:
|
||||
"""
|
||||
Helper class for parsing and tracking --test-* options.
|
||||
@ -152,6 +163,8 @@ class CLITestOptionsClass:
|
||||
libvirtd is restarted.
|
||||
* fake-agent-event: Fake a qemu guest agent API event
|
||||
* fake-nodedev-event: Fake nodedev API events
|
||||
* fake-openauth: Fake user+pass response from libvirt openauth,
|
||||
for testing the TCP URI auth dialog
|
||||
"""
|
||||
def __init__(self, test_options_str):
|
||||
optset = set()
|
||||
@ -194,6 +207,7 @@ class CLITestOptionsClass:
|
||||
self.conn_crash = _get("conn-crash")
|
||||
self.fake_agent_event = _get_value("fake-agent-event")
|
||||
self.fake_nodedev_event = _get_value("fake-nodedev-event")
|
||||
self.fake_openauth = _get("fake-openauth")
|
||||
|
||||
if optset: # pragma: no cover
|
||||
raise RuntimeError("Unknown --test-options keys: %s" % optset)
|
||||
|
Loading…
Reference in New Issue
Block a user