3 test_description
='git-serve tests'
7 test_expect_success
'Test interactive shell.' '
8 "$GIT_SERVE" 2>&1 | grep -q "Interactive shell is disabled."
11 test_expect_success
'Test help.' '
12 SSH_ORIGINAL_COMMAND=help "$GIT_SERVE" 2>actual &&
15 while read -r line; do
16 echo $line | grep -q "^Commands:$" && continue
17 echo $line | grep -q "^ [a-z]" || return 1
18 [ ${#line} -le 80 ] || return 1
23 test_expect_success
'Test setup-repo and list-repos.' '
24 SSH_ORIGINAL_COMMAND="setup-repo foobar" AUR_USER=user \
26 SSH_ORIGINAL_COMMAND="setup-repo foobar2" AUR_USER=tu \
28 cat >expected <<-EOF &&
31 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user \
32 "$GIT_SERVE" 2>&1 >actual &&
33 test_cmp expected actual
36 test_expect_success
'Test git-receive-pack.' '
37 cat >expected <<-EOF &&
42 SSH_ORIGINAL_COMMAND="git-receive-pack /foobar.git/" \
43 AUR_USER=user AUR_PRIVILEGED=0 \
44 "$GIT_SERVE" 2>&1 >actual &&
45 test_cmp expected actual
48 test_expect_success
'Test git-receive-pack with an invalid repository name.' '
49 SSH_ORIGINAL_COMMAND="git-receive-pack /!.git/" \
50 AUR_USER=user AUR_PRIVILEGED=0 \
51 test_must_fail "$GIT_SERVE" 2>&1 >actual
54 test_expect_success
"Test git-upload-pack." '
55 cat >expected <<-EOF &&
60 SSH_ORIGINAL_COMMAND="git-upload-pack /foobar.git/" \
61 AUR_USER=user AUR_PRIVILEGED=0 \
62 "$GIT_SERVE" 2>&1 >actual &&
63 test_cmp expected actual
66 test_expect_success
"Try to pull from someone else's repository." '
67 cat >expected <<-EOF &&
72 SSH_ORIGINAL_COMMAND="git-upload-pack /foobar2.git/" \
73 AUR_USER=user AUR_PRIVILEGED=0 \
74 "$GIT_SERVE" 2>&1 >actual &&
75 test_cmp expected actual
78 test_expect_success
"Try to push to someone else's repository." '
79 SSH_ORIGINAL_COMMAND="git-receive-pack /foobar2.git/" \
80 AUR_USER=user AUR_PRIVILEGED=0 \
81 test_must_fail "$GIT_SERVE" 2>&1
84 test_expect_success
"Try to push to someone else's repository as Trusted User." '
85 cat >expected <<-EOF &&
90 SSH_ORIGINAL_COMMAND="git-receive-pack /foobar.git/" \
91 AUR_USER=tu AUR_PRIVILEGED=1 \
92 "$GIT_SERVE" 2>&1 >actual &&
93 test_cmp expected actual
96 test_expect_success
"Test restore." '
97 echo "DELETE FROM PackageBases WHERE Name = \"foobar\";" | \
99 cat >expected <<-EOF &&
103 SSH_ORIGINAL_COMMAND="restore foobar" AUR_USER=user AUR_PRIVILEGED=0 \
104 "$GIT_SERVE" 2>&1 >actual
105 test_cmp expected actual
108 test_expect_success
"Try to restore an existing package base." '
109 SSH_ORIGINAL_COMMAND="restore foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
110 test_must_fail "$GIT_SERVE" 2>&1
113 test_expect_success
"Disown all package bases." '
114 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
116 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
118 cat >expected <<-EOF &&
120 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
121 "$GIT_SERVE" 2>&1 >actual &&
122 test_cmp expected actual &&
123 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
124 "$GIT_SERVE" 2>&1 >actual &&
125 test_cmp expected actual
128 test_expect_success
"Adopt a package base as a regular user." '
129 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
131 cat >expected <<-EOF &&
134 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
135 "$GIT_SERVE" 2>&1 >actual &&
136 test_cmp expected actual
139 test_expect_success
"Adopt an already adopted package base." '
140 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
141 test_must_fail "$GIT_SERVE" 2>&1
144 test_expect_success
"Adopt a package base as a Trusted User." '
145 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
147 cat >expected <<-EOF &&
150 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
151 "$GIT_SERVE" 2>&1 >actual &&
152 test_cmp expected actual
155 test_expect_success
"Disown one's own package base as a regular user." '
156 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
158 cat >expected <<-EOF &&
160 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
161 "$GIT_SERVE" 2>&1 >actual &&
162 test_cmp expected actual
165 test_expect_success
"Disown one's own package base as a Trusted User." '
166 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
168 cat >expected <<-EOF &&
170 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
171 "$GIT_SERVE" 2>&1 >actual &&
172 test_cmp expected actual
175 test_expect_success
"Try to steal another user's package as a regular user." '
176 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
178 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
179 test_must_fail "$GIT_SERVE" 2>&1 &&
180 cat >expected <<-EOF &&
182 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
183 "$GIT_SERVE" 2>&1 >actual &&
184 test_cmp expected actual &&
185 cat >expected <<-EOF &&
188 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
189 "$GIT_SERVE" 2>&1 >actual &&
190 test_cmp expected actual &&
191 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
195 test_expect_success
"Try to steal another user's package as a Trusted User." '
196 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
198 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
200 cat >expected <<-EOF &&
202 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
203 "$GIT_SERVE" 2>&1 >actual &&
204 test_cmp expected actual &&
205 cat >expected <<-EOF &&
208 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
209 "$GIT_SERVE" 2>&1 >actual &&
210 test_cmp expected actual &&
211 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
215 test_expect_success
"Try to disown another user's package as a regular user." '
216 SSH_ORIGINAL_COMMAND="adopt foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
218 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=user AUR_PRIVILEGED=0 \
219 test_must_fail "$GIT_SERVE" 2>&1 &&
220 cat >expected <<-EOF &&
223 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=tu AUR_PRIVILEGED=1 \
224 "$GIT_SERVE" 2>&1 >actual &&
225 test_cmp expected actual &&
226 SSH_ORIGINAL_COMMAND="disown foobar2" AUR_USER=tu AUR_PRIVILEGED=1 \
230 test_expect_success
"Try to disown another user's package as a Trusted User." '
231 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
233 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
235 cat >expected <<-EOF &&
237 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user AUR_PRIVILEGED=0 \
238 "$GIT_SERVE" 2>&1 >actual &&
239 test_cmp expected actual &&
240 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
244 test_expect_success
"Adopt a package base and add co-maintainers." '
245 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
247 SSH_ORIGINAL_COMMAND="set-comaintainers foobar user3 user4" \
248 AUR_USER=user AUR_PRIVILEGED=0 \
250 cat >expected <<-EOF &&
254 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
255 sqlite3 aur.db >actual &&
256 test_cmp expected actual
259 test_expect_success
"Update package base co-maintainers." '
260 SSH_ORIGINAL_COMMAND="set-comaintainers foobar user2 user3 user4" \
261 AUR_USER=user AUR_PRIVILEGED=0 \
263 cat >expected <<-EOF &&
268 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
269 sqlite3 aur.db >actual &&
270 test_cmp expected actual
273 test_expect_success
"Try to add co-maintainers to an orphan package base." '
274 SSH_ORIGINAL_COMMAND="set-comaintainers foobar2 user2 user3 user4" \
275 AUR_USER=user AUR_PRIVILEGED=0 \
276 test_must_fail "$GIT_SERVE" 2>&1 &&
277 cat >expected <<-EOF &&
282 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
283 sqlite3 aur.db >actual &&
284 test_cmp expected actual
287 test_expect_success
"Disown a package base and check (co-)maintainer list." '
288 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
290 cat >expected <<-EOF &&
293 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user2 AUR_PRIVILEGED=0 \
294 "$GIT_SERVE" 2>&1 >actual &&
295 test_cmp expected actual &&
296 cat >expected <<-EOF &&
300 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
301 sqlite3 aur.db >actual &&
302 test_cmp expected actual
305 test_expect_success
"Force-disown a package base and check (co-)maintainer list." '
306 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=tu AUR_PRIVILEGED=1 \
308 cat >expected <<-EOF &&
310 SSH_ORIGINAL_COMMAND="list-repos" AUR_USER=user3 AUR_PRIVILEGED=0 \
311 "$GIT_SERVE" 2>&1 >actual &&
312 test_cmp expected actual &&
313 cat >expected <<-EOF &&
315 echo "SELECT * FROM PackageComaintainers ORDER BY Priority;" | \
316 sqlite3 aur.db >actual &&
317 test_cmp expected actual
320 test_expect_success
"Check whether package requests are closed when disowning." '
321 SSH_ORIGINAL_COMMAND="adopt foobar" AUR_USER=user AUR_PRIVILEGED=0 \
323 cat <<-EOD | sqlite3 aur.db &&
324 INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID) VALUES (1, 2, 3, "foobar", 4);
325 INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID) VALUES (2, 3, 3, "foobar", 5);
326 INSERT INTO PackageRequests (ID, ReqTypeID, PackageBaseID, PackageBaseName, UsersID) VALUES (3, 2, 2, "foobar2", 6);
329 SSH_ORIGINAL_COMMAND="disown foobar" AUR_USER=user AUR_PRIVILEGED=0 \
331 cat <<-EOD >expected &&
332 Subject: [PRQ#1] Request Accepted
334 grep "^Subject.*PRQ" sendmail.out >sendmail.parts &&
335 test_cmp sendmail.parts expected &&
336 cat <<-EOD >expected &&
337 1|2|3|foobar||4||The user user disowned the package.|0|2
339 echo "SELECT * FROM PackageRequests WHERE Status = 2;" | sqlite3 aur.db >actual &&
340 test_cmp actual expected