2020-11-27 09:22:47 +01:00
# shellcheck shell=bash
2017-12-20 15:14:30 +01:00
# run-shellcheck
test_audit( ) {
2020-11-05 14:24:57 +01:00
# shellcheck disable=2154
2023-09-25 14:24:01 +02:00
run blank " ${ CIS_CHECKS_DIR } / ${ script } .sh " --audit-all
2020-11-05 14:24:57 +01:00
# shellcheck disable=2016
2023-09-25 14:24:01 +02:00
echo 'EXCEPT="$EXCEPT debian"' >>" ${ CIS_CONF_DIR } /conf.d/ ${ script } .cfg "
2020-11-05 14:24:57 +01:00
2017-12-20 15:14:30 +01:00
describe Running on blank host
register_test retvalshouldbe 0
2020-11-05 12:06:14 +01:00
dismiss_count_for_test
2017-12-20 15:14:30 +01:00
register_test contain "There is no carte-blanche sudo permission in"
# shellcheck disable=2154
2023-09-25 14:24:01 +02:00
run blank " ${ CIS_CHECKS_DIR } / ${ script } .sh " --audit-all
2017-12-20 15:14:30 +01:00
# Proceed to operation that will end up to a non compliant system
useradd -s /bin/bash jeantestuser
2020-12-04 14:08:01 +01:00
echo 'jeantestuser ALL = (ALL) NOPASSWD:ALL' >>/etc/sudoers.d/jeantestuser
2017-12-20 15:14:30 +01:00
describe Fail: Not compliant system
register_test retvalshouldbe 1
register_test contain "[ KO ] jeantestuser ALL = (ALL) NOPASSWD:ALL is present in /etc/sudoers.d/jeantestuser"
2023-09-25 14:24:01 +02:00
run userallcmd " ${ CIS_CHECKS_DIR } / ${ script } .sh " --audit-all
2017-12-20 15:14:30 +01:00
# shellcheck disable=2016
2023-09-25 14:24:01 +02:00
echo 'EXCEPT="$EXCEPT debian jeantestuser"' >>" ${ CIS_CONF_DIR } /conf.d/ ${ script } .cfg "
2017-12-20 15:14:30 +01:00
describe Adding jeantestuser to exceptions
register_test retvalshouldbe 0
register_test contain "[ OK ] jeantestuser ALL = (ALL) NOPASSWD:ALL is present in /etc/sudoers.d/jeantestuser but was EXCUSED because jeantestuser is part of exceptions"
2023-09-25 14:24:01 +02:00
run userexcept " ${ CIS_CHECKS_DIR } / ${ script } .sh " --audit-all
2017-12-20 15:14:30 +01:00
rm -f /etc/sudoers.d/jeantestuser
userdel jeantestuser
}