Debian Codegraph @

t/t-credentials.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
4
5 ensure_git_version_isnt $VERSION_LOWER "2.3.0"
6
7 export CREDSDIR="$REMOTEDIR/creds-credentials"
8 setup_creds
9
10 begin_test "credentials with url-specific helper skips askpass"
11 (
12 set -e
13
14 reponame="url-specific-helper"
15 setup_remote_repo "$reponame"
16
17 clone_repo "$reponame" "$reponame"
18 gitscip-shell system . . git. config credential.useHttpPath false
19 gitscip-shell system . . git. config credential.helper ""
20 gitscip-shell system . . git. config credential.$GITSERVER.helper "lfstest"
21
22 gitscip-shell system . . git. lfs track "*.dat"
23 echoscip-shell system . . echo. "hello" > a.dat
24
25 gitscip-shell system . . git. add .gitattributes a.dat
26 gitscip-shell system . . git. commit -m "initial commit"
27
28 # askpass is skipped
29 GIT_ASKPASS="lfs-bad-cmd" GIT_TRACE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. push.log
30
31 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "filling with GIT_ASKPASS" push.log)" ]
32 )
33 end_test
34
35 begin_test "credentials without useHttpPath, with bad path password"
36 (
37 set -e
38
39 reponame="no-httppath-bad-password"
40 setup_remote_repo "$reponame"
41
42 printfscip-shell system . . printf. ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
43
44 clone_repo "$reponame" without-path
45 gitscip-shell system . . git. config credential.useHttpPath false
46 gitscip-shell system . . git. checkout -b without-path
47
48 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
49 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
50
51 printfscip-shell system . . printf. "a" > a.dat
52 gitscip-shell system . . git. add a.dat
53 gitscip-shell system . . git. add .gitattributes
54 gitscip-shell system . . git. commit -m "add a.dat"
55
56 GIT_TRACE=1 gitscip-shell system . . git. push origin without-path 2>&1 | teescip-shell system . . tee. push.log
57 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
58
59 echoscip-shell system . . echo. "approvals:"
60 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
61 echoscip-shell system . . echo. "fills:"
62 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
63
64 echoscip-shell system . . echo. "credential calls have no path:"
65 credcalls="$(grepscip-shell system . . grep. "creds: git credential" push.log)"
66 [scip-shell system . . `[`. 0 -eq "$(echoscip-shell system . . echo. "$credcalls" | grepscip-shell system . . grep. -c "no-httppath-bad-password")" ]
67 expected="$(echoscip-shell system . . echo. "$credcalls" | wcscip-shell system . . wc. -l)"
68 [scip-shell system . . `[`. "$expected" -eq "$(printfscip-shell system . . printf. "%s" "$credcalls" | grepscip-shell system . . grep. -c '", "")')" ]
69 )
70 end_test
71
72 begin_test "credentials with url-specific useHttpPath, with bad path password"
73 (
74 set -e
75
76 reponame="url-specific-httppath-bad-password"
77 setup_remote_repo "$reponame"
78
79 printfscip-shell system . . printf. ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
80
81 clone_repo "$reponame" with-url-specific-path
82 gitscip-shell system . . git. config credential.$GITSERVER.useHttpPath false
83 gitscip-shell system . . git. config lfs.locksverify false
84 gitscip-shell system . . git. checkout -b without-path
85
86 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
87 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
88
89 printfscip-shell system . . printf. "a" > a.dat
90 gitscip-shell system . . git. add a.dat
91 gitscip-shell system . . git. add .gitattributes
92 gitscip-shell system . . git. commit -m "add a.dat"
93
94 GIT_TRACE=1 gitscip-shell system . . git. push origin without-path 2>&1 | teescip-shell system . . tee. push.log
95 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
96
97 echoscip-shell system . . echo. "approvals:"
98 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
99 echoscip-shell system . . echo. "fills:"
100 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
101 )
102 end_test
103
104 begin_test "credentials with useHttpPath, with wrong password"
105 (
106 set -e
107
108 reponame="httppath-bad-password"
109 setup_remote_repo "$reponame"
110
111 printfscip-shell system . . printf. ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
112
113 clone_repo "$reponame" with-path-wrong-pass
114 gitscip-shell system . . git. checkout -b with-path-wrong-pass
115
116 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
117 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
118
119 contents="a"
120 contents_oid=$(calc_oid "$contents")
121
122 printfscip-shell system . . printf. "%s" "$contents" > a.dat
123 gitscip-shell system . . git. add a.dat
124 gitscip-shell system . . git. add .gitattributes
125 gitscip-shell system . . git. commit -m "add a.dat"
126
127 GIT_TRACE=1 gitscip-shell system . . git. push origin with-path-wrong-pass 2>&1 | teescip-shell system . . tee. push.log
128 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Uploading LFS objects: 100% (1/1)" push.log)" ]
129
130 # Requests to both the Locking API and the Batch API should receive 403s.
131 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "Authorization error: $GITSERVER/$reponame.*/locks/verify" push.log)" ]
132 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "batch response: Authorization error: $GITSERVER/$reponame" push.log)" ]
133
134 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
135 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
136
137 refute_server_object "$reponame" "$contents_oid"
138 )
139 end_test
140
141 begin_test "credentials with useHttpPath, with wrong password and 401 response"
142 (
143 set -e
144
145 reponame="httppath-bad-password-401-unauth"
146 setup_remote_repo "$reponame"
147
148 printfscip-shell system . . printf. ":path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
149
150 clone_repo "$reponame" with-path-wrong-pass-401-unauth
151 gitscip-shell system . . git. checkout -b with-path-wrong-pass-401-unauth
152
153 gitscip-shell system . . git. lfs track "*.dat"
154
155 contents="a"
156 contents_oid="$(calc_oid "$contents")"
157 printfscip-shell system . . printf. "%s" "$contents" >a.dat
158
159 gitscip-shell system . . git. add .gitattributes a.dat
160 gitscip-shell system . . git. commit -m "initial commit"
161
162 GIT_TRACE=1 gitscip-shell system . . git. push origin with-path-wrong-pass-401-unauth 2>&1 | teescip-shell system . . tee. push.log
163 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Uploading LFS objects: 100% (1/1), 1 B" push.log)" ]
164
165 # Requests to both the Locking API and the Batch API should receive 401s
166 # until the maximum number of authentication attempts is reached for both.
167 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "api: too many authentication attempts" push.log)" ]
168 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "batch response: too many authentication attempts" push.log)" ]
169
170 # Note that the first request to the Locking API is made without an
171 # Authorization header, so no credentials are retrieved for that request
172 # and it is not counted toward the authentication attempt limit.
173 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
174 [scip-shell system . . `[`. 6 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
175
176 refute_server_object "$reponame" "$contents_oid"
177 )
178 end_test
179
180 begin_test "credentials with useHttpPath, with correct password"
181 (
182 set -e
183
184 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
185 setup_remote_repo "$reponame"
186
187 printfscip-shell system . . printf. ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame"
188
189 clone_repo "$reponame" with-path-correct-pass
190 gitscip-shell system . . git. checkout -b with-path-correct-pass
191
192 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
193 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
194
195 # creating new branch does not re-send any objects existing on other
196 # remote branches anymore, generate new object, different from prev tests
197 contents="b"
198 contents_oid=$(calc_oid "$contents")
199
200 printfscip-shell system . . printf. "%s" "$contents" > b.dat
201 gitscip-shell system . . git. add b.dat
202 gitscip-shell system . . git. add .gitattributes
203 gitscip-shell system . . git. commit -m "add b.dat"
204
205 GIT_TRACE=1 gitscip-shell system . . git. push origin with-path-correct-pass 2>&1 | teescip-shell system . . tee. push.log
206 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
207 echoscip-shell system . . echo. "approvals:"
208 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
209 echoscip-shell system . . echo. "fills:"
210 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
211 echoscip-shell system . . echo. "credential calls have path:"
212 credcalls="$(grepscip-shell system . . grep. "creds: git credential" push.log)"
213 [scip-shell system . . `[`. 0 -eq "$(echoscip-shell system . . echo. "$credcalls" | grepscip-shell system . . grep. -c '", "")')" ]
214 expected="$(echoscip-shell system . . echo. "$credcalls" | wcscip-shell system . . wc. -l)"
215 [scip-shell system . . `[`. "$expected" -eq "$(printfscip-shell system . . printf. "%s" "$credcalls" | grepscip-shell system . . grep. -c "t-credentials")" ]
216 )
217 end_test
218
219 begin_test "credentials send wwwauth[] by default"
220 (
221 set -e
222 ensure_git_version_isnt $VERSION_LOWER "2.41.0"
223 export LFS_TEST_CREDS_WWWAUTH=required
224
225 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-wwwauth-required"
226 setup_remote_repo "$reponame"
227
228 printfscip-shell system . . printf. ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame"
229
230 clone_repo "$reponame" "$reponame"
231 gitscip-shell system . . git. checkout -b new-branch
232
233 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
234 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
235
236 # creating new branch does not re-send any objects existing on other
237 # remote branches anymore, generate new object, different from prev tests
238 contents="b"
239 contents_oid=$(calc_oid "$contents")
240
241 printfscip-shell system . . printf. "%s" "$contents" > b.dat
242 gitscip-shell system . . git. add b.dat
243 gitscip-shell system . . git. add .gitattributes
244 gitscip-shell system . . git. commit -m "add b.dat"
245
246 GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 gitscip-shell system . . git. push origin new-branch 2>&1 | teescip-shell system . . tee. push.log
247 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
248 echoscip-shell system . . echo. "approvals:"
249 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
250 echoscip-shell system . . echo. "fills:"
251 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
252 echoscip-shell system . . echo. "credential calls have path:"
253 credcalls="$(grepscip-shell system . . grep. "creds: git credential" push.log)"
254 [scip-shell system . . `[`. 0 -eq "$(echoscip-shell system . . echo. "$credcalls" | grepscip-shell system . . grep. -c '", "")')" ]
255 expected="$(echoscip-shell system . . echo. "$credcalls" | wcscip-shell system . . wc. -l)"
256 [scip-shell system . . `[`. "$expected" -eq "$(printfscip-shell system . . printf. "%s" "$credcalls" | grepscip-shell system . . grep. -c "t-credentials")" ]
257 )
258 end_test
259
260 begin_test "credentials sends wwwauth[] and fails with finicky helper"
261 (
262 set -e
263 ensure_git_version_isnt $VERSION_LOWER "2.41.0"
264 export LFS_TEST_CREDS_WWWAUTH=forbidden
265
266 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-wwwauth-forbidden-finicky"
267 setup_remote_repo "$reponame"
268
269 printfscip-shell system . . printf. ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame"
270
271 clone_repo "$reponame" "$reponame"
272 gitscip-shell system . . git. checkout -b new-branch
273
274 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
275 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
276
277 # creating new branch does not re-send any objects existing on other
278 # remote branches anymore, generate new object, different from prev tests
279 contents="b"
280 contents_oid=$(calc_oid "$contents")
281
282 printfscip-shell system . . printf. "%s" "$contents" > b.dat
283 gitscip-shell system . . git. add b.dat
284 gitscip-shell system . . git. add .gitattributes
285 gitscip-shell system . . git. commit -m "add b.dat"
286
287 GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 gitscip-shell system . . git. push origin new-branch 2>&1 | teescip-shell system . . tee. push.log
288 echoscip-shell system . . echo. "approvals:"
289 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
290 echoscip-shell system . . echo. "fills:"
291 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
292 )
293 end_test
294
295 begin_test "credentials skips wwwauth[] with option"
296 (
297 set -e
298 ensure_git_version_isnt $VERSION_LOWER "2.41.0"
299 export LFS_TEST_CREDS_WWWAUTH=forbidden
300
301 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-wwwauth-skip"
302 setup_remote_repo "$reponame"
303 gitscip-shell system . . git. config --global credential.$GITSERVER.skipwwwauth true
304
305 printfscip-shell system . . printf. ":path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame"
306
307 clone_repo "$reponame" "$reponame"
308 gitscip-shell system . . git. checkout -b new-branch
309
310 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
311 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
312
313 # creating new branch does not re-send any objects existing on other
314 # remote branches anymore, generate new object, different from prev tests
315 contents="b"
316 contents_oid=$(calc_oid "$contents")
317
318 printfscip-shell system . . printf. "%s" "$contents" > b.dat
319 gitscip-shell system . . git. add b.dat
320 gitscip-shell system . . git. add .gitattributes
321 gitscip-shell system . . git. commit -m "add b.dat"
322
323 GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 gitscip-shell system . . git. push origin new-branch 2>&1 | teescip-shell system . . tee. push.log
324 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
325 echoscip-shell system . . echo. "approvals:"
326 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
327 echoscip-shell system . . echo. "fills:"
328 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
329 echoscip-shell system . . echo. "credential calls have path:"
330 credcalls="$(grepscip-shell system . . grep. "creds: git credential" push.log)"
331 [scip-shell system . . `[`. 0 -eq "$(echoscip-shell system . . echo. "$credcalls" | grepscip-shell system . . grep. -c '", "")')" ]
332 expected="$(echoscip-shell system . . echo. "$credcalls" | wcscip-shell system . . wc. -l)"
333 [scip-shell system . . `[`. "$expected" -eq "$(printfscip-shell system . . printf. "%s" "$credcalls" | grepscip-shell system . . grep. -c "t-credentials")" ]
334 )
335 end_test
336
337 begin_test "credentials can authenticate with Bearer auth"
338 (
339 set -e
340 gitscip-shell system . . git. credential capability </dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. "capability authtype" || exit 0
341
342 reponame="auth-bearer-token"
343 setup_remote_repo "$reponame"
344
345 printfscip-shell system . . printf. "Bearer::token" > "$CREDSDIR/127.0.0.1--$reponame"
346
347 clone_repo "$reponame" "$reponame"
348 gitscip-shell system . . git. checkout -b new-branch
349
350 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
351 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
352
353 contents="b"
354
355 printfscip-shell system . . printf. "%s" "$contents" > b.dat
356 gitscip-shell system . . git. add b.dat
357 gitscip-shell system . . git. add .gitattributes
358 gitscip-shell system . . git. commit -m "add b.dat"
359
360 GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin new-branch 2>&1 | teescip-shell system . . tee. push.log
361 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
362 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
363 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
364 )
365 end_test
366
367 begin_test "credentials can authenticate with multistage auth"
368 (
369 set -e
370 [scip-shell system . . `[`. $(gitscip-shell system . . git. credential capability </dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -c -E "capability (authtype|state)") -eq 2 ] || exit 0
371
372 reponame="auth-multistage-token"
373 setup_remote_repo "$reponame"
374
375 printfscip-shell system . . printf. 'Multistage::cred2of2:state1:state2:\n' >"$CREDSDIR/127.0.0.1--$reponame"
376 # Note that the entry with the empty, generic "match state" value in the
377 # fourth field must be ordered after all other entries so that it does not
378 # always match the current request.
379 printfscip-shell system . . printf. 'Multistage::cred1of2::state1:true\n' >>"$CREDSDIR/127.0.0.1--$reponame"
380
381 clone_repo "$reponame" "$reponame"
382 gitscip-shell system . . git. checkout -b new-branch
383
384 gitscip-shell system . . git. lfs track "*.dat" 2>&1 | teescip-shell system . . tee. track.log
385 grepscip-shell system . . grep. "Tracking \"\*.dat\"" track.log
386
387 contents="b"
388
389 printfscip-shell system . . printf. "%s" "$contents" > b.dat
390 gitscip-shell system . . git. add b.dat
391 gitscip-shell system . . git. add .gitattributes
392 gitscip-shell system . . git. commit -m "add b.dat"
393
394 GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin new-branch 2>&1 | teescip-shell system . . tee. push.log
395 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 1 B" push.log
396
397 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
398 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
399 )
400 end_test
401
402 begin_test "credentials with multistage auth loop fails"
403 (
404 set -e
405 [scip-shell system . . `[`. $(gitscip-shell system . . git. credential capability </dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -c -E "capability (authtype|state)") -eq 2 ] || exit 0
406
407 reponame="auth-multistage-loop"
408 setup_remote_repo "$reponame"
409
410 # Note that we define an endless transition from "state1" to "state1"
411 # so our git-credential-lfstest utility will simulate an invalid
412 # credential helper.
413 printfscip-shell system . . printf. 'Multistage::cred1of2:state1:state1:true\n' >"$CREDSDIR/127.0.0.1--$reponame"
414 # Note that the entry with the empty, generic "match state" value in the
415 # fourth field must be ordered after all other entries so that it does not
416 # always match the current request.
417 printfscip-shell system . . printf. 'Multistage::cred1of2::state1:true\n' >>"$CREDSDIR/127.0.0.1--$reponame"
418
419 clone_repo "$reponame" "$reponame"
420 gitscip-shell system . . git. checkout -b new-branch
421
422 gitscip-shell system . . git. lfs track "*.dat"
423
424 contents="b"
425 contents_oid="$(calc_oid "$contents")"
426 printfscip-shell system . . printf. "%s" "$contents" >b.dat
427
428 gitscip-shell system . . git. add .gitattributes b.dat
429 gitscip-shell system . . git. commit -m "initial commit"
430
431 GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin new-branch 2>&1 | teescip-shell system . . tee. push.log
432 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Uploading LFS objects: 100% (1/1)" push.log)" ]
433
434 # Requests to both the Locking API and the Batch API should receive 401s
435 # until the maximum number of authentication attempts is reached for both.
436 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "api: too many authentication attempts" push.log)" ]
437 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "batch response: too many authentication attempts" push.log)" ]
438
439 # Note that the first request to the Locking API is made without an
440 # Authorization header, so no credentials are retrieved for that request
441 # and it is not counted toward the authentication attempt limit.
442 [scip-shell system . . `[`. 6 -eq "$(grepscip-shell system . . grep. -c "Authorization: Multistage cred1" push.log)" ]
443
444 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
445 [scip-shell system . . `[`. 6 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
446
447 refute_server_object "$reponame" "$contents_oid"
448 )
449 end_test
450
451 begin_test "credentials with multistage auth above limit fails and resets"
452 (
453 set -e
454 [scip-shell system . . `[`. $(gitscip-shell system . . git. credential capability </dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -c -E "capability (authtype|state)") -eq 2 ] || exit 0
455
456 reponame="auth-multistage-limit-reset"
457 setup_remote_repo "$reponame"
458
459 printfscip-shell system . . printf. 'Multistage::cred4of4:state3:state4:true\n' >>"$CREDSDIR/127.0.0.1--$reponame"
460 printfscip-shell system . . printf. 'Multistage::cred3of4:state2:state3:true\n' >>"$CREDSDIR/127.0.0.1--$reponame"
461 printfscip-shell system . . printf. 'Multistage::cred2of4:state1:state2:true\n' >>"$CREDSDIR/127.0.0.1--$reponame"
462 # Note that the entry with the empty, generic "match state" value in the
463 # fourth field must be ordered after all other entries so that it does not
464 # always match the current request.
465 printfscip-shell system . . printf. 'Multistage::cred1of4::state1:true\n' >>"$CREDSDIR/127.0.0.1--$reponame"
466
467 clone_repo "$reponame" "$reponame"
468 gitscip-shell system . . git. checkout -b new-branch
469
470 gitscip-shell system . . git. lfs track "*.dat"
471
472 contents="b"
473 contents_oid="$(calc_oid "$contents")"
474 printfscip-shell system . . printf. "%s" "$contents" >b.dat
475
476 gitscip-shell system . . git. add .gitattributes b.dat
477 gitscip-shell system . . git. commit -m "initial commit"
478
479 GIT_TERMINAL_PROMPT=0 GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 gitscip-shell system . . git. push origin new-branch 2>&1 | teescip-shell system . . tee. push.log
480 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Uploading LFS objects: 100% (1/1)" push.log)" ]
481
482 # Requests to both the Locking API and the Batch API should receive 401s
483 # until the maximum number of authentication attempts is reached for both.
484 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "api: too many authentication attempts" push.log)" ]
485 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "batch response: too many authentication attempts" push.log)" ]
486
487 # Note that the first request to the Locking API is made without an
488 # Authorization header, so no credentials are retrieved for that request
489 # and it is not counted toward the authentication attempt limit.
490 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "Authorization: Multistage cred1of4" push.log)" ]
491 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "Authorization: Multistage cred2of4" push.log)" ]
492 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "Authorization: Multistage cred3of4" push.log)" ]
493 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Authorization: Multistage cred4of4" push.log)" ]
494
495 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
496 [scip-shell system . . `[`. 6 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
497
498 refute_server_object "$reponame" "$contents_oid"
499 )
500 end_test
501
502 begin_test "git credential"
503 (
504 set -e
505
506 printfscip-shell system . . printf. ":git:server" > "$CREDSDIR/credential-test.com"
507 printfscip-shell system . . printf. ":git:path" > "$CREDSDIR/credential-test.com--some-path"
508 # Note that the entry with the empty, generic "match state" value in the
509 # fourth field must be ordered after all other entries so that it does not
510 # always match the current request.
511 printfscip-shell system . . printf. 'Multistage::bazquux:state1:state2:\nMultistage::foobar::state1:true' > "$CREDSDIR/example.com"
512
513 mkdirscip-shell system . . mkdir. empty
514 cd empty
515 gitscip-shell system . . git. init
516
517 echoscip-shell system . . echo. "protocol=http
518 host=credential-test.com
519 path=some/path" | GIT_TERMINAL_PROMPT=0 gitscip-shell system . . git. credential fill > cred.log
520 catscip-shell system . . cat. cred.log
521
522 expected="protocol=http
523 host=credential-test.com
524 path=some/path
525 username=git
526 password=path"
527
528 [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. cred.log)" ]
529
530 gitscip-shell system . . git. config credential.useHttpPath false
531
532 echoscip-shell system . . echo. "protocol=http
533 host=credential-test.com" | GIT_TERMINAL_PROMPT=0 gitscip-shell system . . git. credential fill > cred.log
534 catscip-shell system . . cat. cred.log
535
536 expected="protocol=http
537 host=credential-test.com
538 username=git
539 password=server"
540 [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. cred.log)" ]
541
542 echoscip-shell system . . echo. "protocol=http
543 host=credential-test.com
544 path=some/path" | GIT_TERMINAL_PROMPT=0 gitscip-shell system . . git. credential fill > cred.log
545 catscip-shell system . . cat. cred.log
546
547 expected="protocol=http
548 host=credential-test.com
549 username=git
550 password=server"
551
552 [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. cred.log)" ]
553
554 [scip-shell system . . `[`. $(gitscip-shell system . . git. credential capability </dev/nullscip-shell filesystem . . `/dev/null`. | grepscip-shell system . . grep. -c -E "capability (authtype|state)") -eq 2 ] || exit 0
555
556 echoscip-shell system . . echo. "capability[]=authtype
557 capability[]=state
558 protocol=http
559 host=example.com" | GIT_TERMINAL_PROMPT=0 gitscip-shell system . . git. credential fill > cred.log
560 catscip-shell system . . cat. cred.log
561
562 expected="capability[]=authtype
563 capability[]=state
564 authtype=Multistage
565 credential=foobar
566 protocol=http
567 host=example.com
568 continue=1
569 state[]=lfstest:state1"
570
571 [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. cred.log)" ]
572
573 echoscip-shell system . . echo. "capability[]=authtype
574 capability[]=state
575 protocol=http
576 host=example.com
577 state[]=lfstest:state1" | GIT_TERMINAL_PROMPT=0 gitscip-shell system . . git. credential fill > cred.log
578 catscip-shell system . . cat. cred.log
579
580 expected="capability[]=authtype
581 capability[]=state
582 authtype=Multistage
583 credential=bazquux
584 protocol=http
585 host=example.com
586 state[]=lfstest:state2"
587
588 [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. cred.log)" ]
589 )
590 end_test
591
592 NETRCFILES=".netrc"
593 if [scip-shell system . . `[`. "$IS_WINDOWS" -eq 1 ]; then
594 NETRCFILES+=" _netrc"
595 fi
596
597 for netrcfile in $NETRCFILES; do
598 begin_test "credentials from netrc ($netrcfile)"
599 (
600 set -e
601
602 printfscip-shell system . . printf. "machine localhost\nlogin netrcuser\npassword netrcpass\n" >"$HOME/$netrcfile"
603 echoscip-shell system . . echo. $HOME
604 echoscip-shell system . . echo. "GITSERVER $GITSERVER"
605 catscip-shell system . . cat. "$HOME/$netrcfile"
606
607 # prevent prompts on Windows particularly
608 export SSH_ASKPASS=
609
610 reponame="netrctest-$netrcfile"
611 setup_remote_repo "$reponame"
612
613 clone_repo "$reponame" "${reponame}-assert"
614
615 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
616 gitscip-shell system . . git. remote add "netrc" "$(echoscip-shell system . . echo. $GITSERVER | sedscip-shell system . . sed. s/127.0.0.1/localhost/)/netrctest"
617 gitscip-shell system . . git. lfs env
618
619 gitscip-shell system . . git. lfs track "*.dat"
620 echoscip-shell system . . echo. "push a" > a.dat
621 gitscip-shell system . . git. add .gitattributes a.dat
622 gitscip-shell system . . git. commit -m "add a.dat"
623
624 GIT_TRACE=1 gitscip-shell system . . git. lfs push netrc main 2>&1 | teescip-shell system . . tee. push.log
625 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 7 B" push.log
626 echoscip-shell system . . echo. "any netrc credential calls:"
627 [scip-shell system . . `[`. 4 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential" push.log)" ]
628
629 echoscip-shell system . . echo. "any netrc credential fills:"
630 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential fill" push.log)" ]
631
632 echoscip-shell system . . echo. "any netrc credential approvals:"
633 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential approve" push.log)" ]
634 )
635 end_test
636 done
637
638 begin_test "credentials from netrc with unknown keyword"
639 (
640 set -e
641
642 printfscip-shell system . . printf. "machine localhost\nlogin netrcuser\nnot-a-key something\npassword netrcpass\n" >"$HOME/.netrc"
643 echoscip-shell system . . echo. $HOME
644 echoscip-shell system . . echo. "GITSERVER $GITSERVER"
645 catscip-shell system . . cat. "$HOME/.netrc"
646
647 # prevent prompts on Windows particularly
648 export SSH_ASKPASS=
649
650 reponame="netrctest"
651 setup_remote_repo "$reponame"
652
653 clone_repo "$reponame" repo2
654
655 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
656 gitscip-shell system . . git. remote add "netrc" "$(echoscip-shell system . . echo. $GITSERVER | sedscip-shell system . . sed. s/127.0.0.1/localhost/)/netrctest"
657 gitscip-shell system . . git. lfs env
658
659 gitscip-shell system . . git. lfs track "*.dat"
660 echoscip-shell system . . echo. "push a" > a.dat
661 gitscip-shell system . . git. add .gitattributes a.dat
662 gitscip-shell system . . git. commit -m "add a.dat"
663
664 GIT_TRACE=1 gitscip-shell system . . git. lfs push netrc main 2>&1 | teescip-shell system . . tee. push.log
665 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 7 B" push.log
666 echoscip-shell system . . echo. "any netrc credential calls:"
667 [scip-shell system . . `[`. 4 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential" push.log)" ]
668
669 echoscip-shell system . . echo. "any netrc credential fills:"
670 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential fill" push.log)" ]
671
672 echoscip-shell system . . echo. "any netrc credential approvals:"
673 [scip-shell system . . `[`. 2 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential approve" push.log)" ]
674 )
675 end_test
676
677 begin_test "credentials from netrc with bad password"
678 (
679 set -e
680
681 printfscip-shell system . . printf. "machine localhost\nlogin netrcuser\npassword badpass\n" >"$HOME/.netrc"
682 echoscip-shell system . . echo. $HOME
683 echoscip-shell system . . echo. "GITSERVER $GITSERVER"
684 catscip-shell system . . cat. "$HOME/.netrc"
685
686 # prevent prompts on Windows particularly
687 export SSH_ASKPASS=
688
689 reponame="netrctest"
690 setup_remote_repo "$reponame"
691
692 clone_repo "$reponame" repo3
693
694 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
695 gitscip-shell system . . git. remote add "netrc" "$(echoscip-shell system . . echo. $GITSERVER | sedscip-shell system . . sed. s/127.0.0.1/localhost/)/netrctest"
696 gitscip-shell system . . git. lfs env
697
698 gitscip-shell system . . git. lfs track "*.dat"
699 echoscip-shell system . . echo. "push a" > a.dat
700 gitscip-shell system . . git. add .gitattributes a.dat
701 gitscip-shell system . . git. commit -m "add a.dat"
702
703 gitscip-shell system . . git. push netrc main 2>&1 | teescip-shell system . . tee. push.log
704 [scip-shell system . . `[`. 0 -eq "$(grepscip-shell system . . grep. -c "Uploading LFS objects: 100% (1/1), 7 B" push.log)" ]
705 )
706 end_test
707
708 begin_test "credentials with bad netrc creds will retry"
709 (
710 set -e
711
712 printfscip-shell system . . printf. "machine localhost\nlogin netrcuser\npassword badpassretry\n" >"$HOME/.netrc"
713 echoscip-shell system . . echo. $HOME
714 echoscip-shell system . . echo. "GITSERVER $GITSERVER"
715 catscip-shell system . . cat. "$HOME/.netrc"
716
717 # prevent prompts on Windows particularly
718 export SSH_ASKPASS=
719
720 # ensure we provide the correct creds through ASKPASS so we can fall back
721 # when .netrc fails
722 export LFS_ASKPASS_USERNAME="netrcuser"
723 export LFS_ASKPASS_PASSWORD="netrcpass"
724
725 reponame="netrctest"
726 setup_remote_repo "$reponame"
727
728 clone_repo "$reponame" repo4
729
730 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
731 gitscip-shell system . . git. remote add "netrc" "$(echoscip-shell system . . echo. $GITSERVER | sedscip-shell system . . sed. s/127.0.0.1/localhost/)/netrctest"
732 gitscip-shell system . . git. lfs env
733
734 gitscip-shell system . . git. lfs track "*.dat"
735 echoscip-shell system . . echo. "push a" > a.dat
736 gitscip-shell system . . git. add .gitattributes a.dat
737 gitscip-shell system . . git. commit -m "add a.dat"
738
739 GIT_TRACE=1 GIT_ASKPASS="lfs-askpass" gitscip-shell system . . git. push netrc main 2>&1 | teescip-shell system . . tee. push.log
740 grepscip-shell system . . grep. -c "Uploading LFS objects: 100% (1/1), 7 B" push.log
741
742 # netrc credentials should be attempted then rejected for the lock request
743 echoscip-shell system . . echo. "netrc credentials attempted:"
744 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential fill" push.log)" ]
745
746 echoscip-shell system . . echo. "netrc credentials rejected:"
747 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "netrc: git credential reject" push.log)" ]
748
749 # credhelper should then use askpass to find the proper credentials, which
750 # should be successful
751 echoscip-shell system . . echo. "askpass credentials attempted:"
752 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" push.log)" ]
753
754 echoscip-shell system . . echo. "askpass credentials approved:"
755 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" push.log)" ]
756
757 # askpass creds should be cached and used for the batch request
758 echoscip-shell system . . echo. "cached credentials used:"
759 [scip-shell system . . `[`. 1 -eq "$(grepscip-shell system . . grep. -c "creds: git credential cache" push.log)" ]
760 )
761 end_test
762
763 begin_test "credentials from lfs.url"
764 (
765 set -e
766
767 reponame="requirecreds-lfsurl"
768 setup_remote_repo "$reponame"
769 clone_repo "$reponame" "$reponame"
770
771 gitscip-shell system . . git. lfs track "*.dat"
772 echoscip-shell system . . echo. "push a" > a.dat
773 gitscip-shell system . . git. add .gitattributes a.dat
774 gitscip-shell system . . git. commit -m "add a.dat"
775
776 echoscip-shell system . . echo. "bad push"
777 gitscip-shell system . . git. lfs env
778 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
779 grepscip-shell system . . grep. "Uploading LFS objects: 0% (0/1), 0 B" push.log
780
781 echoscip-shell system . . echo. "good push"
782 gitserverhost=$(echoscip-shell system . . echo. "$GITSERVER" | cutscip-shell system . . cut. -d'/' -f3)
783 gitscip-shell system . . git. config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs
784 gitscip-shell system . . git. lfs env
785 GIT_TRACE=1 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
786 # A 401 indicates URL access mode for the /storage endpoint
787 # was used instead of for the lfsapi endpoint
788 grepscip-shell system . . grep. "HTTP: 401" push.log
789 # Ensure we didn't make a second batch request, which means the request
790 # was successfully retried internally
791 grepscip-shell system . . grep. "tq: retrying object" push.log && exit 1
792 grepscip-shell system . . grep. "Uploading LFS objects: 0% (0/1), 0 B" push.log
793
794 echoscip-shell system . . echo. "bad fetch"
795 rmscip-shell system . . rm. -rf .git/lfs/objects
796 gitscip-shell system . . git. config lfs.url http://$gitserverhost/$reponame.git/info/lfs
797 gitscip-shell system . . git. lfs env
798 gitscip-shell system . . git. lfs fetch --all 2>&1 | teescip-shell system . . tee. fetch.log
799 grepscip-shell system . . grep. "Downloading LFS objects: 0% (0/1), 0 B" fetch.log
800
801 echoscip-shell system . . echo. "good fetch"
802 rmscip-shell system . . rm. -rf .git/lfs/objects
803 gitscip-shell system . . git. config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs
804 gitscip-shell system . . git. lfs env
805 GIT_TRACE=1 gitscip-shell system . . git. lfs fetch --all 2>&1 | teescip-shell system . . tee. fetch.log
806 # No 401 should occur as we've already set an access mode for the
807 # storage endpoint during the push
808 grepscip-shell system . . grep. "HTTP: 401" fetch.log && exit 1
809 gitscip-shell system . . git. lfs fsck
810
811 echoscip-shell system . . echo. "good fetch, setting access mode"
812 rmscip-shell system . . rm. -rf .git/lfs/objects
813 gitscip-shell system . . git. config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs
814 gitscip-shell system . . git. config lfs.http://$gitserverhost/storage/.access "None"
815 gitscip-shell system . . git. lfs env
816 GIT_TRACE=1 gitscip-shell system . . git. lfs fetch --all 2>&1 | teescip-shell system . . tee. fetch.log
817 # A 401 indicates URL access mode for the /storage endpoint
818 # was used instead of for the lfsapi endpoint
819 grepscip-shell system . . grep. "HTTP: 401" fetch.log
820 # Ensure we didn't make a second batch request, which means the request
821 # was successfully retried internally
822 grepscip-shell system . . grep. "tq: retrying object" fetch.log && exit 1
823
824 gitscip-shell system . . git. lfs fsck
825 )
826 end_test
827
828 begin_test "credentials from remote.origin.url"
829 (
830 set -e
831
832 reponame="requirecreds-remoteurl"
833 setup_remote_repo "$reponame"
834 clone_repo "$reponame" "$reponame"
835
836 gitscip-shell system . . git. lfs track "*.dat"
837 echoscip-shell system . . echo. "push b" > b.dat
838 gitscip-shell system . . git. add .gitattributes b.dat
839 gitscip-shell system . . git. commit -m "add b.dat"
840
841 echoscip-shell system . . echo. "bad push"
842 gitscip-shell system . . git. lfs env
843 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
844 grepscip-shell system . . grep. "Uploading LFS objects: 0% (0/1), 0 B" push.log
845
846 echoscip-shell system . . echo. "good push"
847 gitserverhost=$(echoscip-shell system . . echo. "$GITSERVER" | cutscip-shell system . . cut. -d'/' -f3)
848 gitscip-shell system . . git. config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git
849 gitscip-shell system . . git. lfs env
850 GIT_TRACE=1 gitscip-shell system . . git. lfs push origin main 2>&1 | teescip-shell system . . tee. push.log
851 # A 401 indicates URL access mode for the /storage endpoint
852 # was used instead of for the lfsapi endpoint
853 grepscip-shell system . . grep. "HTTP: 401" push.log
854 # Ensure we didn't make a second batch request, which means the request
855 # was successfully retried internally
856 grepscip-shell system . . grep. "tq: retrying object" push.log && exit 1
857 grepscip-shell system . . grep. "Uploading LFS objects: 100% (1/1), 7 B" push.log
858
859 echoscip-shell system . . echo. "bad fetch"
860 rmscip-shell system . . rm. -rf .git/lfs/objects
861 gitscip-shell system . . git. config remote.origin.url http://$gitserverhost/$reponame.git
862 gitscip-shell system . . git. lfs env
863 gitscip-shell system . . git. lfs fetch --all 2>&1 | teescip-shell system . . tee. fetch.log
864 # Missing authentication causes `git lfs fetch` to fail before the progress
865 # meter is printed to the TTY.
866
867 echoscip-shell system . . echo. "good fetch"
868 rmscip-shell system . . rm. -rf .git/lfs/objects
869 gitscip-shell system . . git. config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git
870 gitscip-shell system . . git. lfs env
871 GIT_TRACE=1 gitscip-shell system . . git. lfs fetch --all 2>&1 | teescip-shell system . . tee. fetch.log
872 # No 401 should occur as we've already set an access mode for the
873 # storage endpoint during the push
874 grepscip-shell system . . grep. "HTTP: 401" fetch.log && exit 1
875 gitscip-shell system . . git. lfs fsck
876
877 echoscip-shell system . . echo. "good fetch, setting access mode"
878 rmscip-shell system . . rm. -rf .git/lfs/objects
879 gitscip-shell system . . git. config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git
880 gitscip-shell system . . git. config lfs.http://$gitserverhost/storage/.access "None"
881 gitscip-shell system . . git. lfs env
882 GIT_TRACE=1 gitscip-shell system . . git. lfs fetch --all 2>&1 | teescip-shell system . . tee. fetch.log
883 # A 401 indicates URL access mode for the /storage endpoint
884 # was used instead of for the lfsapi endpoint
885 grepscip-shell system . . grep. "HTTP: 401" fetch.log
886 # Ensure we didn't make a second batch request, which means the request
887 # was successfully retried internally
888 grepscip-shell system . . grep. "tq: retrying object" fetch.log && exit 1
889
890 gitscip-shell system . . git. lfs fsck
891 )
892 end_test