xref: /freebsd/usr.sbin/pw/tests/pw_lock_test.sh (revision d6b92ffa)
1# $FreeBSD$
2
3# Import helper functions
4. $(atf_get_srcdir)/helper_functions.shin
5
6# Test locking and unlocking a user account
7atf_test_case user_locking cleanup
8user_locking_body() {
9	populate_etc_skel
10	${PW} useradd test || atf_fail "Creating test user"
11	${PW} lock test || atf_fail "Locking the user"
12	atf_check -s exit:0 -o match:"^test:\*LOCKED\*\*:1001:" \
13		grep "^test:\*LOCKED\*\*:1001:" $HOME/master.passwd
14	${PW} unlock test || atf_fail "Locking the user"
15	atf_check -s exit:0 -o match:"^test:\*:1001:" \
16		grep "^test:\*:1001:" $HOME/master.passwd
17}
18
19atf_test_case numeric_locking cleanup
20numeric_locking_body() {
21	populate_etc_skel
22	${PW} useradd test || atf_fail "Creating test user"
23	${PW} lock 1001 || atf_fail "Locking the user"
24	atf_check -s exit:0 -o match:"^test:\*LOCKED\*\*:1001:" \
25		grep "^test:\*LOCKED\*\*:1001:" $HOME/master.passwd
26	${PW} unlock 1001 || atf_fail "Unlocking the user"
27	atf_check -s exit:0 -o match:"^test:\*:1001:" \
28		grep "^test:\*:1001:" $HOME/master.passwd
29	# Now numeric names
30	${PW} useradd -n 1001 || atf_fail "Creating test user"
31	${PW} lock 1001 || atf_fail "Locking the user"
32	atf_check -s exit:0 -o match:"^1001:\*LOCKED\*\*:1002:" \
33		grep "^1001:\*LOCKED\*\*:1002:" $HOME/master.passwd
34	${PW} unlock 1001 || atf_fail "Unlocking the user"
35	atf_check -s exit:0 -o match:"^1001:\*:1002:" \
36		grep "^1001:\*:1002:" $HOME/master.passwd
37}
38
39atf_init_test_cases() {
40	atf_add_test_case user_locking
41	atf_add_test_case numeric_locking
42}
43