Add tests for account and password expiration.

Approved by:	will
This commit is contained in:
Brad Davis 2015-02-17 14:48:16 +00:00
parent d6b3ef634c
commit 258e07800c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=278902

View File

@ -63,6 +63,108 @@ user_add_comments_invalid_noupdate_body() {
atf_check -s exit:1 -o empty grep "^test:.*" $HOME/master.passwd
}
# Test add user with alternate homedir
atf_test_case user_add_homedir
user_add_homedir_body() {
populate_etc_skel
atf_check -s exit:0 ${PW} useradd test -d /foo/bar
atf_check -s exit:0 -o match:"^test:\*:.*::0:0:User &:/foo/bar:.*" \
${PW} usershow test
}
# Test add user with account expiration as an epoch date
atf_test_case user_add_account_expiration_epoch
user_add_account_expiration_epoch_body() {
populate_etc_skel
DATE=`date -j -v+1d "+%s"`
atf_check -s exit:0 ${PW} useradd test -e ${DATE}
atf_check -s exit:0 -o match:"^test:\*:.*::0:${DATE}:.*" \
${PW} usershow test
}
# Test add user with account expiration as a DD-MM-YYYY date
atf_test_case user_add_account_expiration_date_numeric
user_add_account_expiration_date_numeric_body() {
populate_etc_skel
DATE=`date -j -v+1d "+%d-%m-%Y"`
EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
atf_check -s exit:0 ${PW} useradd test -e ${DATE}
atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
${PW} usershow test
}
# Test add user with account expiration as a DD-MM-YYYY date
atf_test_case user_add_account_expiration_date_month
user_add_account_expiration_date_month_body() {
populate_etc_skel
DATE=`date -j -v+1d "+%d-%b-%Y"`
EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
atf_check -s exit:0 ${PW} useradd test -e ${DATE}
atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
${PW} usershow test
}
# Test add user with account expiration as a relative date
atf_test_case user_add_account_expiration_date_relative
user_add_account_expiration_date_relative_body() {
populate_etc_skel
EPOCH=`date -j -v+13m "+%s"`
atf_check -s exit:0 ${PW} useradd test -e +13o
atf_check -s exit:0 -o match:"^test:\*:.*::0:${EPOCH}:User &:.*" \
${PW} usershow test
}
# Test add user with password expiration as an epoch date
atf_test_case user_add_password_expiration_epoch
user_add_password_expiration_epoch_body() {
populate_etc_skel
DATE=`date -j -v+1d "+%s"`
atf_check -s exit:0 ${PW} useradd test -p ${DATE}
atf_check -s exit:0 -o match:"^test:\*:.*::${DATE}:0:.*" \
${PW} usershow test
}
# Test add user with password expiration as a DD-MM-YYYY date
atf_test_case user_add_password_expiration_date_numeric
user_add_password_expiration_date_numeric_body() {
populate_etc_skel
DATE=`date -j -v+1d "+%d-%m-%Y"`
EPOCH=`date -j -f "%d-%m-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
atf_check -s exit:0 ${PW} useradd test -p ${DATE}
atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
${PW} usershow test
}
# Test add user with password expiration as a DD-MMM-YYYY date
atf_test_case user_add_password_expiration_date_month
user_add_password_expiration_date_month_body() {
populate_etc_skel
DATE=`date -j -v+1d "+%d-%b-%Y"`
EPOCH=`date -j -f "%d-%b-%Y %H:%M:%S" "${DATE} 00:00:00" "+%s"`
atf_check -s exit:0 ${PW} useradd test -p ${DATE}
atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
${PW} usershow test
}
# Test add user with password expiration as a relative date
atf_test_case user_add_password_expiration_date_relative
user_add_password_expiration_date_relative_body() {
populate_etc_skel
EPOCH=`date -j -v+13m "+%s"`
atf_check -s exit:0 ${PW} useradd test -p +13o
atf_check -s exit:0 -o match:"^test:\*:.*::${EPOCH}:0:User &:.*" \
${PW} usershow test
}
atf_init_test_cases() {
atf_add_test_case user_add
atf_add_test_case user_add_noupdate
@ -70,4 +172,13 @@ atf_init_test_cases() {
atf_add_test_case user_add_comments_noupdate
atf_add_test_case user_add_comments_invalid
atf_add_test_case user_add_comments_invalid_noupdate
atf_add_test_case user_add_homedir
atf_add_test_case user_add_account_expiration_epoch
atf_add_test_case user_add_account_expiration_date_numeric
atf_add_test_case user_add_account_expiration_date_month
atf_add_test_case user_add_account_expiration_date_relative
atf_add_test_case user_add_password_expiration_epoch
atf_add_test_case user_add_password_expiration_date_numeric
atf_add_test_case user_add_password_expiration_date_month
atf_add_test_case user_add_password_expiration_date_relative
}