From c2d3784a4027d7f5f0e773d5e568deddfae17a49 Mon Sep 17 00:00:00 2001 From: Miha Purg Date: Tue, 20 Feb 2024 14:38:02 +0100 Subject: [PATCH] Fix nologin_ignored tests for rules using create_local_interactive_users_object The solution deduplicates most of the code to test/shared/accounts_common.sh, as proposed in PR review. --- .../interactive_user_nologin_ignored.pass.sh | 7 +++---- .../interactive_user_nologin_ignored.pass.sh | 8 ++++---- .../interactive_user_nologin_ignored.pass.sh | 5 +++-- .../interactive_user_nologin_ignored.pass.sh | 7 +++---- .../interactive_user_nologin_ignored.pass.sh | 7 +++---- .../interactive_user_nologin_ignored.pass.sh | 8 +++----- .../interactive_user_nologin_ignored.pass.sh | 6 +++--- .../interactive_user_nologin_ignored.pass.sh | 6 +++--- .../interactive_user_nologin_ignored.pass.sh | 6 +++--- .../interactive_user_nologin_ignored.pass.sh | 6 +++--- tests/shared/accounts_common.sh | 16 ++++++++++++++++ 11 files changed, 47 insertions(+), 35 deletions(-) create mode 100644 tests/shared/accounts_common.sh diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_group_ownership/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_group_ownership/tests/interactive_user_nologin_ignored.pass.sh index 7c720dc18fe..d592d08566e 100644 --- a/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_group_ownership/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_group_ownership/tests/interactive_user_nologin_ignored.pass.sh @@ -1,6 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -touch /home/$USER/.bashrc -chgrp 10005 /home/$USER/.bashrc +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "touch /home/\$user/.bashrc; chgrp 10005 /home/\$user/.bashrc" diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_user_ownership/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_user_ownership/tests/interactive_user_nologin_ignored.pass.sh index 36d643d6fab..9f2fd2e971c 100644 --- a/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_user_ownership/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_dot_user_ownership/tests/interactive_user_nologin_ignored.pass.sh @@ -1,6 +1,6 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -touch /home/$USER/.bashrc -chown 10005 /home/$USER/.bashrc +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "touch /home/\$user/.bashrc; chown 10005 /home/\$user/.bashrc" + diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_user_nologin_ignored.pass.sh index 5229620ce40..c85049f9e3a 100644 --- a/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/accounts_user_interactive_home_directory_exists/tests/interactive_user_nologin_ignored.pass.sh @@ -1,4 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -M -s /sbin/nologin $USER +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "rm -rf /home/\$user" diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_groupownership/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_groupownership/tests/interactive_user_nologin_ignored.pass.sh index 8b5f56858da..64369a5c039 100644 --- a/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_groupownership/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_groupownership/tests/interactive_user_nologin_ignored.pass.sh @@ -1,6 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -echo "$USER" > /home/$USER/$USER.txt -chgrp 10005 /home/$USER/$USER.txt +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "echo \$user > /home/\$user/\$user.txt; chgrp 10005 /home/\$user/\$user.txt" diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_ownership/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_ownership/tests/interactive_user_nologin_ignored.pass.sh index fe5d2ce61a9..a7437017e0c 100644 --- a/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_ownership/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_ownership/tests/interactive_user_nologin_ignored.pass.sh @@ -1,6 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -echo "$USER" > /home/$USER/$USER.txt -chown 10005 /home/$USER/$USER.txt +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "echo \$user > /home/\$user/\$user.txt; chown 10005 /home/\$user/\$user.txt" diff --git a/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_permissions/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_permissions/tests/interactive_user_nologin_ignored.pass.sh index 9cda12a7d88..5973ac853cf 100644 --- a/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_permissions/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/accounts_users_home_files_permissions/tests/interactive_user_nologin_ignored.pass.sh @@ -1,7 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -echo "$USER" > /home/$USER/$USER.txt -chmod -Rf 700 /home/$USER/.* -chmod -f o+r /home/$USER/$USER.txt +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "echo \$user > /home/\$user/\$user.txt; chmod -Rf 700 /home/\$user/.*; chmod -f o+r /home/\$user/\$user.txt" diff --git a/linux_os/guide/system/accounts/accounts-session/file_groupownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/file_groupownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh index 46e21d8eae4..fe96e34c448 100644 --- a/linux_os/guide/system/accounts/accounts-session/file_groupownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/file_groupownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh @@ -1,5 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -chgrp 10005 /home/$USER +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "chgrp 10005 /home/\$user" diff --git a/linux_os/guide/system/accounts/accounts-session/file_ownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/file_ownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh index 5ad82630ff6..f74cd375ec4 100644 --- a/linux_os/guide/system/accounts/accounts-session/file_ownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/file_ownership_home_directories/tests/interactive_user_nologin_ignored.pass.sh @@ -1,5 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -chown 10005 /home/$USER +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "chown 10005 /home/\$user" diff --git a/linux_os/guide/system/accounts/accounts-session/file_permissions_home_directories/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/file_permissions_home_directories/tests/interactive_user_nologin_ignored.pass.sh index ac6f94038f7..d6e5a01dd70 100644 --- a/linux_os/guide/system/accounts/accounts-session/file_permissions_home_directories/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/file_permissions_home_directories/tests/interactive_user_nologin_ignored.pass.sh @@ -1,5 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -chmod 755 /home/$USER +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "chmod 755 /home/\$user" diff --git a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_interactive_users/tests/interactive_user_nologin_ignored.pass.sh b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_interactive_users/tests/interactive_user_nologin_ignored.pass.sh index a146ac47f98..f877adb1d13 100644 --- a/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_interactive_users/tests/interactive_user_nologin_ignored.pass.sh +++ b/linux_os/guide/system/accounts/accounts-session/user_umask/accounts_umask_interactive_users/tests/interactive_user_nologin_ignored.pass.sh @@ -1,5 +1,5 @@ #!/bin/bash -USER="cac_user" -useradd -m -s /sbin/nologin $USER -echo "umask 022" >> /home/$USER/.bashrc +. "$SHARED/accounts_common.sh" + +run_foreach_noninteractive_shell_account "echo 'umask 022' >> /home/\$user/.bashrc" diff --git a/tests/shared/accounts_common.sh b/tests/shared/accounts_common.sh new file mode 100644 index 00000000000..ca6f9d152f5 --- /dev/null +++ b/tests/shared/accounts_common.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# for each noninteractive shell, create user account +# and eval ommands which are passed in as function arguments +function run_foreach_noninteractive_shell_account { + for shell in "/sbin/nologin" \ + "/usr/sbin/nologin" \ + "/bin/false" \ + "/usr/bin/false"; do + + user=cac_user${shell//\//_} + useradd -m -s $shell $user + + eval "$*" + done +}