Fix the KDE test for keyring_password.

This commit is contained in:
Lukáš Růžička 2024-05-10 17:34:57 +02:00
parent bea118971b
commit 5f8bb47f32
2 changed files with 90 additions and 47 deletions

View File

@ -13,36 +13,37 @@ sub run {
my $desktop = get_var("DESKTOP");
my $user = get_var("USER") || "test";
# Switch to console
# Switch to console to perform several setting tasks.
$self->root_console(tty => 3);
# We install the necessary packages.
# While KWalletManager is part of KDE by default, seahorse
# have been removed from Gnome so we need to install it.
if ($desktop eq "gnome") {
assert_script_run("dnf -y install seahorse");
}
# Enable and start SSHd.
assert_script_run("systemctl enable sshd.service --now");
# Check that it is running (the assertion will fail if not)
assert_script_run("systemctl status sshd.service --no-pager");
# Create the SSH keys for the user.
# Change to the normal user
# Create the SSH keys for the regular user.
# Switch to the user's account.
enter_cmd("su -l $user");
sleep 1;
sleep 2;
# Create the SSH key.
enter_cmd("ssh-keygen");
sleep 1;
# Confirm the location of the key.
sleep 2;
# Press enter to create the key in default location.
send_key("ret");
sleep 1;
# Create a password for the key.
sleep 2;
# Create a password for the SSH key.
type_very_safely("sshpassword\n");
sleep 1;
sleep 2;
type_very_safely("sshpassword\n");
sleep 1;
# Logout the regular user
sleep 2;
# Logout the regular user and return
# back to the root console.
enter_cmd("exit");
}

View File

@ -7,66 +7,104 @@ use utils;
# to the system keyring. We will start a wallet application
# and check that the password is listed in that application.
sub export_kde_vars {
# On KDE, it is possible to update and reuse the keyring
# on Konsole if correct environmental variables are set.
# Set them now.
enter_cmd('export SSH_ASKPASS=/usr/bin/ksshaskpass');
sleep 2;
enter_cmd('export SSH_ASKPASS_REQUIRE=prefer');
sleep 2;
}
sub connect_localhost {
# Use some method to connect to the local host. This should
# trigger the keyring and the login credentials should
# be stored for later reuse. Pass $type eq "reconnect"
# to use this function repetitiously.
my $type = shift;
my $user = get_var("USER_LOGIN", "test");
my $pass = get_var("USER_PASSWORD", "weakpassword");
# Use the file explorer to establish the connection
# to the localhost.
if (get_var("DESKTOP") eq "gnome") {
# On Gnome, we will use Nautilus to establish an SFTP
# connection to the localhost.
menu_launch_type("nautilus");
assert_screen("apps_run_files");
# Add a network connection - click on the icon and
# fill in the necessary fields.
assert_and_click("nautilus_other_locations");
assert_and_click("nautilus_enter_address");
type_very_safely("ssh://$user");
type_very_safely('@localhost');
send_key("ret");
# If we perform this for the first time, ergo
# we do not want to "reconnect", also perform
# extra steps to store the password.
if ($type ne "reconnect") {
wait_still_screen(3);
type_very_safely($pass);
assert_and_click("nautilus_remember_password");
assert_and_click("nautilus_unlock");
}
# When the connection has been established, let us
# confirm and close the application.
assert_screen("nautilus_connection_established");
send_key("alt-f4");
}
else {
menu_launch_type("dolphin");
assert_screen("dolphin_runs");
assert_and_click("dolphin_explore_network");
assert_and_click("dolphin_add_network_folder");
assert_and_click("dolphin_rbutton_ssh");
assert_and_click("kde_button_next");
type_very_safely("SSH folder");
send_key("tab");
type_very_safely($user);
send_key("tab");
type_very_safely("127.0.0.1");
for my $i (1..3) {
send_key("tab");
# On KDE, Dolphin has a bug that prevents the application
# from connecting easily (as in Gnome). Manually, this is
# not a big deal, as one could react accordingly, but with
# automation, this approach is basically useless.
# Therefore, we will use a different approach - we will enable
# CLI keyring integration and perform an SFTP connection
# in Konsole.
menu_launch_type("konsole");
assert_screen("konsole_runs");
# Export the environmental variables.
export_kde_vars();
# Connect the sftp.
type_very_safely('sftp ' . $user . '@localhost' . "\n");
# If performed for the first time, also deal with the
# password storing which is a little painful on KDE.
if ($type ne "reconnect") {
# First, we check that the yes no dialogue is present.
# And type "yes" into it.
assert_screen("keyring_askpass_yesno");
type_very_safely("yes\n");
# Then check the password dialogue and fill it in.
# Also click on Remember password and confirm with
# the OK button.
assert_screen("keyring_askpass_password");
type_very_safely("$pass");
assert_and_click("keyring_askpass_remember");
assert_and_click("keyring_askpass_confirm");
}
type_very_safely("/");
assert_and_click("dolphin_save_and_connect");
assert_and_click("kde_dismiss_notification");
assert_and_click("dolphin_dont_askagain");
assert_and_click("dolphin_connect_anyway");
assert_screen("dolphin_network_ssh_connected");
# Check that we have logged in and exit the application.
# On "reconnect" the password storing routine will not be
# used and we should still be able to get logged in as
# the credentials are already stored.
assert_and_click("keyring_sftp_logged");
type_very_safely("bye\n");
}
}
sub check_stored {
# This subroutine will run the keyring application on either
# desktop and check that the password has been stored there.
# On KDE, we will use the KWalletManager.
if (get_var("DESKTOP") eq "kde") {
# Start the KDE wallet application and maximize it.
menu_launch_type("kwalletmanager");
assert_screen("kwalletmanager_runs");
send_key("super-pgup");
# Navigate to the stored entry and check that
# the credentials are stored there.
assert_and_dclick("keyring_sshkeys_unfold");
assert_and_dclick("keyring_sshkey_values");
assert_screen("keyring_keys_values");
# Navigate to the stored entry and check
# that the credentials are stored there.
assert_and_dclick("keyring_wallet_passwords_unfold");
assert_and_dclick("keyring_wallet_password_stored");
assert_and_click("keyring_wallet_password_details");
assert_and_click("keyring_wallet_password_reveal");
assert_screen("keyring_wallet_password");
}
else {
# Start the Seahorse application and maximize it.
@ -90,8 +128,6 @@ sub run {
my $user = get_var("USER_LOGIN", "test");
my $pass = get_var("USER_PASSWORD", "weakpassword");
enter_cmd("echo 'Starting test for keyring_password.'");
# We are still at the root console, but for the following steps,
# there is nothing we should be doing there, so we switch back
# to the graphical desktop.
@ -99,6 +135,8 @@ sub run {
# Lets connect to localhost via SSH. This should result in
# asking for a password and storing the credentials for later use.
# The following routine uses different approaches on different
# desktops.
connect_localhost("connect");
# Check that the password has been stored.
check_stored();
@ -106,14 +144,18 @@ sub run {
# Reboot the machine, log onto the session again.
$self->root_console(tty => 3);
enter_cmd("reboot");
# Boot to login screen and type in the password.
boot_to_login_screen();
send_key("ret");
if ($desktop eq "gnome") {
send_key("ret");
}
type_very_safely("$pass\n");
wait_still_screen(3);
send_key("esc");
# Reconnect without using password. We still should be
# able to log in.
# Repeat the connection procedure, this time we will not
# expect to be using any passwords as this should be handled
# by the keyring.
connect_localhost("reconnect");
}