From 82abc6143278c626a013e3e15c82a3ddc370bf96 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Thu, 26 Sep 2024 08:57:27 -0700 Subject: [PATCH] Factor DM login process out of _graphical_wait_login There are several other tests doing the same thing (but not as safely, in some cases). To improve reliability and reduce duplication, let's factor this out into utils.pm and reuse it where appropriate. Signed-off-by: Adam Williamson --- lib/utils.pm | 34 ++++++++++++++++++- .../applications/keyring/keyring_password.pm | 13 +++---- .../keyring/keyring_passwordless.pm | 13 +++---- tests/desktop_fprint.pm | 5 +-- tests/desktop_notifications.pm | 13 ++----- 5 files changed, 44 insertions(+), 34 deletions(-) diff --git a/lib/utils.pm b/lib/utils.pm index c654277e..182d1845 100644 --- a/lib/utils.pm +++ b/lib/utils.pm @@ -7,7 +7,7 @@ use Exporter; use lockapi; use testapi qw(is_serial_terminal :DEFAULT); -our @EXPORT = qw/run_with_error_check type_safely type_very_safely desktop_vt boot_to_login_screen console_login console_switch_layout desktop_switch_layout console_loadkeys_us do_bootloader boot_decrypt check_release menu_launch_type setup_repos repo_setup get_workarounds disable_updates_repos cleanup_workaround_repo console_initial_setup handle_welcome_screen gnome_initial_setup anaconda_create_user check_desktop quit_firefox advisory_get_installed_packages acnp_handle_output advisory_check_nonmatching_packages start_with_launcher quit_with_shortcut disable_firefox_studies select_rescue_mode copy_devcdrom_as_isofile get_release_number check_left_bar check_top_bar check_prerelease check_version spell_version_number _assert_and_click is_branched rec_log repos_mirrorlist register_application get_registered_applications solidify_wallpaper check_and_install_git download_testdata make_serial_writable set_update_notification_timestamp kde_doublek_workaround/; +our @EXPORT = qw/run_with_error_check type_safely type_very_safely desktop_vt boot_to_login_screen console_login console_switch_layout desktop_switch_layout console_loadkeys_us do_bootloader boot_decrypt check_release menu_launch_type setup_repos repo_setup get_workarounds disable_updates_repos cleanup_workaround_repo console_initial_setup handle_welcome_screen gnome_initial_setup anaconda_create_user check_desktop quit_firefox advisory_get_installed_packages acnp_handle_output advisory_check_nonmatching_packages start_with_launcher quit_with_shortcut disable_firefox_studies select_rescue_mode copy_devcdrom_as_isofile get_release_number check_left_bar check_top_bar check_prerelease check_version spell_version_number _assert_and_click is_branched rec_log repos_mirrorlist register_application get_registered_applications solidify_wallpaper check_and_install_git download_testdata make_serial_writable set_update_notification_timestamp kde_doublek_workaround dm_perform_login/; # We introduce this global variable to hold the list of applications that have @@ -1777,4 +1777,36 @@ sub kde_doublek_workaround { wait_still_screen 3; } +# handle login at a graphical DM once we have reached the initial +# DM screen. Factored out of _graphical_wait_login for reuse by +# tests that reboot and need to login afterwards +sub dm_perform_login { + my ($desktop, $password) = @_; + # GDM 3.24.1 dumps a cursor in the middle of the screen here... + mouse_hide; + if ($desktop eq 'gnome') { + # we have to hit enter to get the password dialog, and it + # doesn't always work for some reason so just try it three + # times + send_key_until_needlematch("graphical_login_input", "ret", 3, 5); + } + assert_screen "graphical_login_input"; + # seems like we often double-type on aarch64 if we start right + # away + wait_still_screen(stilltime => 5, similarity_level => 38); + if (get_var("SWITCHED_LAYOUT")) { + # see _do_install_and_reboot; when layout is switched + # user password is doubled to contain both US and native + # chars + desktop_switch_layout 'ascii'; + type_very_safely $password; + desktop_switch_layout 'native'; + type_very_safely $password; + } + else { + type_very_safely $password; + } + send_key "ret"; +} + 1; diff --git a/tests/applications/keyring/keyring_password.pm b/tests/applications/keyring/keyring_password.pm index 2e0056f7..3ad62800 100644 --- a/tests/applications/keyring/keyring_password.pm +++ b/tests/applications/keyring/keyring_password.pm @@ -126,13 +126,6 @@ sub check_stored { } } -sub perform_login { - my $password = shift; - send_key("ret") if ($desktop eq "gnome"); - type_very_safely("$password\n"); - check_desktop; -} - sub run { my $self = shift; @@ -142,7 +135,8 @@ sub run { desktop_vt(); if (check_screen("login_screen", timeout => 30)) { - perform_login($pass); + dm_perform_login($desktop, $pass); + check_desktop; } # Lets connect to localhost via SSH. This should result in @@ -159,7 +153,8 @@ sub run { # Boot to login screen and type in the password. boot_to_login_screen(); - perform_login($pass); + dm_perform_login($desktop, $pass); + check_desktop; # Repeat the connection procedure, but skip the password # handling process as this will be done by the keyring. diff --git a/tests/applications/keyring/keyring_passwordless.pm b/tests/applications/keyring/keyring_passwordless.pm index c1aa00fd..d2dfcf5c 100644 --- a/tests/applications/keyring/keyring_passwordless.pm +++ b/tests/applications/keyring/keyring_passwordless.pm @@ -76,13 +76,6 @@ sub connect_localhost { enter_cmd("exit"); } -sub perform_login { - my $password = shift; - send_key("ret") if ($desktop eq "gnome"); - type_very_safely("$password\n"); - check_desktop; -} - sub run { my $self = shift; @@ -99,7 +92,8 @@ sub run { # If we arrive to a login screen, perform login if (check_screen("login_screen", timeout => 30)) { - perform_login($pass); + dm_perform_login($desktop, $pass); + check_desktop; } # Use SSH to connect to the localhost. @@ -110,7 +104,8 @@ sub run { enter_cmd("reboot"); # Log in. boot_to_login_screen(); - perform_login($pass); + dm_perform_login($desktop, $pass); + check_desktop; # Reconnect without using password. We still should be # able to log in. diff --git a/tests/desktop_fprint.pm b/tests/desktop_fprint.pm index 39905670..b8ec680e 100644 --- a/tests/desktop_fprint.pm +++ b/tests/desktop_fprint.pm @@ -20,10 +20,7 @@ sub run { # "Login with a reader, but no enrolled prints" type_string "reboot\n"; assert_screen "graphical_login", 180; - mouse_hide; - send_key_until_needlematch("graphical_login_input", "ret", 3, 5); - type_very_safely "weakpassword"; - send_key "ret"; + dm_perform_login('gnome', 'weakpassword'); check_desktop(timeout => 60); wait_still_screen 10; $self->root_console(tty => 5); diff --git a/tests/desktop_notifications.pm b/tests/desktop_notifications.pm index bfac456a..012b22f4 100644 --- a/tests/desktop_notifications.pm +++ b/tests/desktop_notifications.pm @@ -77,19 +77,10 @@ sub run { type_string "systemctl start graphical.target\n"; # we trust systemd to switch us to the right tty here if (get_var("BOOTFROM")) { + my $password = get_var("USER_PASSWORD", "weakpassword"); assert_screen 'graphical_login', 60; wait_still_screen 10, 30; - # GDM 3.24.1 dumps a cursor in the middle of the screen here... - mouse_hide; - if ($desktop eq 'gnome') { - # we have to hit enter to get the password dialog, and it - # doesn't always work for some reason so just try it three - # times - send_key_until_needlematch("graphical_login_input", "ret", 3, 5); - } - assert_screen "graphical_login_input"; - type_very_safely get_var("USER_PASSWORD", "weakpassword"); - send_key 'ret'; + dm_perform_login($desktop, $password); } check_desktop(timeout => 90); # now, WE WAIT. this is just an unconditional wait - rather than