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