Skip to content

Commit

Permalink
Create non-root user in jeos-firstboot wizard
Browse files Browse the repository at this point in the history
A new feature has been implemented and jeos-firstboot wizard can
create a non root user directly in the UI. As of now the feature has landed
in sle-micro 6.1 only.

 - ticket: [test fails in firstrun - handle non-root user creation screen](https://progress.opensuse.org/issues/165180)
  • Loading branch information
mloviska committed Aug 14, 2024
1 parent cdfd608 commit 1164671
Showing 1 changed file with 42 additions and 11 deletions.
53 changes: 42 additions & 11 deletions tests/jeos/firstrun.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use base "opensusebasetest";
use strict;
use warnings;
use testapi;
use version_utils qw(is_jeos is_sle is_tumbleweed is_leap is_opensuse is_microos is_sle_micro is_vmware is_bootloader_sdboot is_community_jeos);
use version_utils qw(is_jeos is_sle is_tumbleweed is_leap is_opensuse is_microos is_sle_micro is_vmware is_bootloader_sdboot is_community_jeos is_staging);
use Utils::Architectures;
use Utils::Backends;
use jeos qw(expect_mount_by_uuid);
Expand Down Expand Up @@ -114,6 +114,40 @@ sub verify_partition_label {
script_output('sfdisk -l') =~ m/Disklabel type:\s+$label/ or die "Wrong partion label found, expected '$label'";
}

sub create_user_in_terminal {
return if script_run("getent passwd $username") == 0;

assert_script_run "useradd -m $username -c '$realname'";
assert_script_run "echo $username:$password | chpasswd";
}

sub create_users_in_ui {
my %args = @_;

use Data::Dumper;

if (exists($args{root}) && !!$args{root}) {
foreach my $password_needle (qw(jeos-root-password jeos-confirm-root-password)) {
assert_screen $password_needle;
type_password;
send_key 'ret';
}
} else {
assert_screen 'jeos-create-non-root';
assert_screen_change { type_string $username };
send_key "down";
assert_screen_change { type_string $realname };
assert_screen 'jeos-create-non-root-check';
send_key "down";

type_password;
wait_screen_change(sub { send_key "down" }, 25);
type_password;
send_key 'ret';
}

}

sub run {
my ($self) = @_;
my $lang = is_sle('15+') ? 'en_US' : get_var('JEOSINSTLANG', 'en_US');
Expand Down Expand Up @@ -187,11 +221,7 @@ sub run {
send_key 'ret';

# Enter password & Confirm
foreach my $password_needle (qw(jeos-root-password jeos-confirm-root-password)) {
assert_screen $password_needle;
type_password;
send_key 'ret';
}
create_users_in_ui(root => 1);

if (is_bootloader_sdboot) {
send_key_until_needlematch 'jeos-fde-option-enroll-root-pw', 'down' unless check_screen('jeos-fde-option-enroll-root-pw', 1);
Expand All @@ -217,7 +247,6 @@ sub run {
# Select FDE with pass and tpm
assert_screen "alp-fde-pass-tpm";
# with the latest ALP 9.2/SLEM 3.4 build, this step takes more time than usual.
wait_screen_change(sub { send_key "ret" }, 25);
assert_screen("alp-fde-newluks", timeout => 120);
type_password;
send_key "ret";
Expand All @@ -234,6 +263,10 @@ sub run {
send_key 'n';
}

if ((is_tumbleweed && is_staging) || is_sle_micro('>6.0')) {
create_users_in_ui();
}

if (is_generalhw && is_aarch64 && !is_leap("<15.4") && !is_tumbleweed) {
assert_screen 'jeos-please-configure-wifi';
send_key 'n';
Expand Down Expand Up @@ -296,10 +329,8 @@ sub run {

# Create user account, if image doesn't already contain user
# (which is the case for SLE images that were already prepared by openQA)
if (script_run("getent passwd $username") != 0) {
assert_script_run "useradd -m $username -c '$realname'";
assert_script_run "echo $username:$password | chpasswd";
}
# new jeos-firstboot supports non-root user creation
create_user_in_terminal;

if (check_var('FLAVOR', 'JeOS-for-RaspberryPi')) {
assert_script_run("echo 'PermitRootLogin yes' > /etc/ssh/sshd_config.d/permit-root-login.conf");
Expand Down

0 comments on commit 1164671

Please sign in to comment.