summaryrefslogtreecommitdiff
path: root/tests/setup_user_test
blob: 2185c0d1cda5c390c2f5e209f978308ad7af6972 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	setup_user_usage \
	setup_user_fullname \
	setup_user_interactive_no \
	setup_user_interactive \
	setup_user_interactive_fullname \
	setup_user_interactive_singlename \
	setup_user_groups_commas \
	setup_user_groups_spaces \
	setup_user_admin

setup_user_usage_body() {
	test_usage setup-user
}

setup_user_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"adduser -D testuser" \
		-e empty \
		setup-user testuser
}

setup_user_fullname_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"adduser.* -D .*testuser" \
		-o match:"adduser.* -g Joe User .*testuser" \
		-e empty \
		setup-user -f "Joe User" testuser
}

setup_user_interactive_no_body() {
	init_env
	(
		echo "no"
	) | atf_check -s exit:0 \
		-o match:"Setup a user" \
		-o not-match:"adduser.*" \
		-e empty \
		setup-user
}

setup_user_interactive_body() {
	init_env
	(
		echo "testuser"
		echo "Joe User"
		echo "none"
	) | atf_check -s exit:0 \
		-o match:"Setup a user" \
		-o match:"Full name for user testuser" \
		-o not-match:"adduser.* -D .*testuser" \
		-o match:"adduser.* -g Joe User .*testuser" \
		-e empty \
		setup-user
}

setup_user_interactive_fullname_body() {
	init_env
	(
		echo ""
	) | atf_check -s exit:0 \
		-o match:"Setup a user.*\[juser\]" \
		-o not-match:"Full name for user juser" \
		-o not-match:"adduser.* -D .*" \
		-o match:"adduser.* -g Joe User .*juser" \
		-e empty \
		setup-user -f "Joe User" -k none
}

setup_user_interactive_singlename_body() {
	init_env
	(
		echo ""
	) | atf_check -s exit:0 \
		-o match:"Setup a user.*\[joe\]" \
		-o not-match:"Full name for user" \
		-o not-match:"adduser.* -D .*" \
		-o match:"adduser.* -g Joe .*joe" \
		-e empty \
		setup-user -f "Joe" -k none
}

setup_user_groups_commas_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"addgroup testuser wheel" \
		-o match:"addgroup testuser audio" \
		-o match:"addgroup testuser video" \
		-e empty \
		setup-user -g wheel,audio,video testuser
}

setup_user_groups_spaces_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"addgroup testuser wheel" \
		-o match:"addgroup testuser audio" \
		-o match:"addgroup testuser video" \
		-e empty \
		setup-user -g "wheel audio video" testuser
}

setup_user_admin_body() {
	init_env
	atf_check -s exit:0 \
		-o match:"addgroup testuser wheel" \
		-e empty \
		setup-user -a testuser
		grep wheel etc/doas.d/doas.conf

}