Skip to content

Commit

Permalink
Fix nologin_ignored tests for rules using create_local_interactive_us…
Browse files Browse the repository at this point in the history
…ers_object

The solution deduplicates most of the code to test/shared/accounts_common.sh,
as proposed in PR review.
  • Loading branch information
mpurg committed Feb 21, 2024
1 parent b616089 commit c2d3784
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"

Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 16 additions & 0 deletions tests/shared/accounts_common.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit c2d3784

Please sign in to comment.