Improve user management in test cases

This commit is contained in:
Charles Herlin 2019-02-14 11:15:51 +01:00
parent 7ad0df963c
commit edcaaeab4c
2 changed files with 7 additions and 13 deletions

View File

@ -6,28 +6,25 @@ test_audit() {
# shellcheck disable=2154 # shellcheck disable=2154
run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
useradd usertest1 useradd -u 1001 usertest1
useradd usertest2 useradd -o -u 1001 usertest2
sed -i 's/1001/1000/g' /etc/passwd
# Proceed to operation that will end up to a non compliant system # Proceed to operation that will end up to a non compliant system
describe Tests purposely failing describe Tests purposely failing
register_test retvalshouldbe 1 register_test retvalshouldbe 1
register_test contain "[ KO ] Duplicate UID (1000): usertest1 usertest2" register_test contain "[ KO ] Duplicate UID (1001): usertest1 usertest2"
run noncompliant /opt/debian-cis/bin/hardening/"${script}".sh --audit-all run noncompliant /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
# shellcheck disable=2016 # shellcheck disable=2016
echo 'EXCEPTIONS="$EXCEPTIONS 1000"' >> /opt/debian-cis/etc/conf.d/"${script}".cfg echo 'EXCEPTIONS="$EXCEPTIONS 1001"' >> /opt/debian-cis/etc/conf.d/"${script}".cfg
describe Adding exceptions describe Adding exceptions
register_test retvalshouldbe 0 register_test retvalshouldbe 0
register_test contain "[ OK ] No duplicate UIDs apart from configured exceptions: (1000): usertest1 usertest2" register_test contain "[ OK ] No duplicate UIDs apart from configured exceptions: (1001): usertest1 usertest2"
run exception /opt/debian-cis/bin/hardening/"${script}".sh --audit-all run exception /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
# Cleanup # Cleanup
userdel usertest1 userdel usertest1
userdel usertest2 userdel usertest2
sed -i '/usertest1/d' /etc/group
sed -i '/usertest2/d' /etc/group
} }

View File

@ -6,8 +6,7 @@ test_audit() {
# shellcheck disable=2154 # shellcheck disable=2154
run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all run blank /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
useradd usertest1 useradd -o -u 0 usertest1
sed -i 's/1000/0/g' /etc/passwd
# Proceed to operation that will end up to a non compliant system # Proceed to operation that will end up to a non compliant system
describe Tests purposely failing describe Tests purposely failing
@ -24,8 +23,6 @@ test_audit() {
run exception /opt/debian-cis/bin/hardening/"${script}".sh --audit-all run exception /opt/debian-cis/bin/hardening/"${script}".sh --audit-all
# Cleanup # Cleanup
sed -i '/usertest1/d' /etc/passwd userdel -f usertest1
sed -i '/usertest1/d' /etc/shadow
sed -i '/usertest1/d' /etc/group
} }