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 20, 2024
1 parent b616089 commit 936b025
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/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 <<EOF
touch /home/\$user/.bashrc
chgrp 10005 /home/\$user/.bashrc
EOF
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/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 <<EOF
touch /home/\$user/.bashrc
chown 10005 /home/\$user/.bashrc
EOF

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,8 @@
#!/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 <<EOF
echo "\$user" > /home/\$user/\$user.txt
chgrp 10005 /home/\$user/\$user.txt
EOF
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/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 <<EOF
echo "\$user" > /home/\$user/\$user.txt
chown 10005 /home/\$user/\$user.txt
EOF
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/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 <<EOF
echo "\$user" > /home/\$user/\$user.txt
chmod -Rf 700 /home/\$user/.*
chmod -f o+r /home/\$user/\$user.txt
EOF
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

USER="cac_user"
useradd -m -s /sbin/nologin $USER
chgrp 10005 /home/$USER
. "$SHARED/accounts_common.sh"

run_foreach_noninteractive_shell_account <<EOF
chgrp 10005 /home/\$user
EOF
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

USER="cac_user"
useradd -m -s /sbin/nologin $USER
chown 10005 /home/$USER
. "$SHARED/accounts_common.sh"

run_foreach_noninteractive_shell_account <<EOF
chown 10005 /home/\$user
EOF
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

USER="cac_user"
useradd -m -s /sbin/nologin $USER
chmod 755 /home/$USER
. "$SHARED/accounts_common.sh"

run_foreach_noninteractive_shell_account <<EOF
chmod 755 /home/\$user
EOF
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/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 <<EOF
echo "umask 022" >> /home/\$user/.bashrc
EOF
17 changes: 17 additions & 0 deletions tests/shared/accounts_common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/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 {
echo "Asd"
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 936b025

Please sign in to comment.