blob: 2211f67ba62ae0fa76caeac8a02e5b7990da4e77 (
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
#!/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_fullname_existing \
setup_user_interactive_singlename \
setup_user_interactive_suggest_ssh \
setup_user_groups_commas \
setup_user_groups_spaces \
setup_user_admin \
setup_user_keys_opt \
setup_user_unlock
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" >answers
atf_check -s exit:0 \
-o match:"Setup a user" \
-o not-match:"adduser.*" \
-e empty \
setup-user <answers
}
setup_user_interactive_body() {
init_env
(
echo "testuser"
echo "Joe User"
echo "none"
) >answers
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 <answers
}
setup_user_interactive_fullname_body() {
init_env
echo "" >answers
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 <answers
}
setup_user_interactive_fullname_existing_body() {
init_env
(
echo "existinguser"
echo "testuser"
) >answers
ADDUSER_EXIST=existinguser atf_check -s exit:0 \
-o match:"Setup a user.*\[existinguser\]" \
-o match:"Setup a user.*\) adduser" \
-o match:"adduser.* -g existinguser .*testuser" \
-e match:"adduser: user 'existinguser' in use" \
setup-user -f "existinguser" -k none <answers
}
setup_user_interactive_singlename_body() {
init_env
echo "" >answers
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 <answers
}
setup_user_interactive_suggest_ssh_body() {
init_env
( echo "testuser"
echo "FullName"
echo "al"
echo ""
)>answers
export WGETCONTENT='ssh-id from alpine'
atf_check -s exit:0 \
-o match:"Setup a user" \
-o match:"Full name for user" \
-o match:"Enter ssh key.*none" \
-o match:"Enter ssh key.*gitlab.alpinelinux.org.*testuser.keys" \
-o match:"adduser.* -g FullName .*testuser" \
-e empty \
setup-user <answers
grep -x "$WGETCONTENT" home/testuser/.ssh/authorized_keys \
|| atf_fail "ssh key not fetched from alpinelinux"
atf_check -o match:"^700$" \
stat -c "%a" home/testuser/.ssh
atf_check -o match:"^600$" \
stat -c "%a" home/testuser/.ssh/authorized_keys
}
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
}
setup_user_keys_opt_body() {
init_env
export WGETCONTENT='ssh-id from alpine'
atf_check -s exit:0 \
-o match:"adduser.* -D .*testuser" \
setup-user -k https://gitlab.alpinelinux.org/user.keys testuser
grep -x "$WGETCONTENT" home/testuser/.ssh/authorized_keys \
|| atf_fail "ssh key not fetched from alpinelinux"
atf_check -o match:"^700$" \
stat -c "%a" home/testuser/.ssh
atf_check -o match:"^600$" \
stat -c "%a" home/testuser/.ssh/authorized_keys
}
setup_user_unlock_body() {
init_env
atf_check -s exit:0 \
-o match:"passwd -u testuser" \
-e empty \
setup-user -u testuser
}
|