xref: /freebsd/usr.sbin/pw/tests/pw_lock_test.sh (revision d0b2dbfa)
1458cbf0aSEnji Cooper
2458cbf0aSEnji Cooper# Import helper functions
3458cbf0aSEnji Cooper. $(atf_get_srcdir)/helper_functions.shin
4458cbf0aSEnji Cooper
5458cbf0aSEnji Cooper# Test locking and unlocking a user account
6458cbf0aSEnji Cooperatf_test_case user_locking cleanup
7458cbf0aSEnji Cooperuser_locking_body() {
8458cbf0aSEnji Cooper	populate_etc_skel
9458cbf0aSEnji Cooper	${PW} useradd test || atf_fail "Creating test user"
10458cbf0aSEnji Cooper	${PW} lock test || atf_fail "Locking the user"
11458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*LOCKED\*\*:1001:" \
12458cbf0aSEnji Cooper		grep "^test:\*LOCKED\*\*:1001:" $HOME/master.passwd
13458cbf0aSEnji Cooper	${PW} unlock test || atf_fail "Locking the user"
14458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:1001:" \
15458cbf0aSEnji Cooper		grep "^test:\*:1001:" $HOME/master.passwd
16458cbf0aSEnji Cooper}
17458cbf0aSEnji Cooper
18458cbf0aSEnji Cooperatf_test_case numeric_locking cleanup
19458cbf0aSEnji Coopernumeric_locking_body() {
20458cbf0aSEnji Cooper	populate_etc_skel
21458cbf0aSEnji Cooper	${PW} useradd test || atf_fail "Creating test user"
22458cbf0aSEnji Cooper	${PW} lock 1001 || atf_fail "Locking the user"
23458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*LOCKED\*\*:1001:" \
24458cbf0aSEnji Cooper		grep "^test:\*LOCKED\*\*:1001:" $HOME/master.passwd
25458cbf0aSEnji Cooper	${PW} unlock 1001 || atf_fail "Unlocking the user"
26458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^test:\*:1001:" \
27458cbf0aSEnji Cooper		grep "^test:\*:1001:" $HOME/master.passwd
28458cbf0aSEnji Cooper	# Now numeric names
29458cbf0aSEnji Cooper	${PW} useradd -n 1001 || atf_fail "Creating test user"
30458cbf0aSEnji Cooper	${PW} lock 1001 || atf_fail "Locking the user"
31458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^1001:\*LOCKED\*\*:1002:" \
32458cbf0aSEnji Cooper		grep "^1001:\*LOCKED\*\*:1002:" $HOME/master.passwd
33458cbf0aSEnji Cooper	${PW} unlock 1001 || atf_fail "Unlocking the user"
34458cbf0aSEnji Cooper	atf_check -s exit:0 -o match:"^1001:\*:1002:" \
35458cbf0aSEnji Cooper		grep "^1001:\*:1002:" $HOME/master.passwd
36458cbf0aSEnji Cooper}
37458cbf0aSEnji Cooper
38458cbf0aSEnji Cooperatf_init_test_cases() {
39458cbf0aSEnji Cooper	atf_add_test_case user_locking
40458cbf0aSEnji Cooper	atf_add_test_case numeric_locking
41458cbf0aSEnji Cooper}
42