3 . "$(dirname "$0")/testlib.sh"
5 ensure_git_version_isnt $VERSION_LOWER "2.3.0"
7 begin_test "credentails with url-specific helper skips askpass"
11 reponame="url-specific-helper"
12 setup_remote_repo "$reponame"
14 clone_repo "$reponame" "$reponame"
15 git config credential.useHttpPath false
16 git config credential.helper ""
17 git config credential.$GITSERVER.helper "lfstest"
22 git add .gitattributes a.dat
23 git commit -m "initial commit"
26 GIT_ASKPASS="lfs-bad-cmd" GIT_TRACE=1 git push origin master 2>&1 | tee push.log
28 [ "0" -eq "$(grep "filling with GIT_ASKPASS" push.log | wc -l)" ]
32 begin_test "credentials without useHttpPath, with bad path password"
36 reponame="no-httppath-bad-password"
37 setup_remote_repo "$reponame"
39 printf "path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
41 clone_repo "$reponame" without-path
42 git config credential.useHttpPath false
43 git checkout -b without-path
45 git lfs track "*.dat" 2>&1 | tee track.log
46 grep "Tracking \"\*.dat\"" track.log
50 git add .gitattributes
51 git commit -m "add a.dat"
53 GIT_TRACE=1 git push origin without-path 2>&1 | tee push.log
54 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
57 [ "1" -eq "$(cat push.log | grep "creds: git credential approve" | wc -l)" ]
59 [ "1" -eq "$(cat push.log | grep "creds: git credential fill" | wc -l)" ]
61 echo "credential calls have no path:"
62 credcalls="$(grep "creds: git credential" push.log)"
63 [ "0" -eq "$(echo "$credcalls" | grep "no-httppath-bad-password" | wc -l)" ]
64 expected="$(echo "$credcalls" | wc -l)"
65 [ "$expected" -eq "$(printf "$credcalls" | grep '", "")' | wc -l)" ]
69 begin_test "credentials with url-specific useHttpPath, with bad path password"
73 reponame="url-specific-httppath-bad-password"
74 setup_remote_repo "$reponame"
76 printf "path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
78 clone_repo "$reponame" with-url-specific-path
79 git config credential.$GITSERVER.useHttpPath false
80 git config lfs.locksverify false
81 git checkout -b without-path
83 git lfs track "*.dat" 2>&1 | tee track.log
84 grep "Tracking \"\*.dat\"" track.log
88 git add .gitattributes
89 git commit -m "add a.dat"
91 GIT_TRACE=1 git push origin without-path 2>&1 | tee push.log
92 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
95 [ "1" -eq "$(cat push.log | grep "creds: git credential approve" | wc -l)" ]
97 [ "1" -eq "$(cat push.log | grep "creds: git credential fill" | wc -l)" ]
101 begin_test "credentials with useHttpPath, with wrong password"
105 reponame="httppath-bad-password"
106 setup_remote_repo "$reponame"
108 printf "path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
110 clone_repo "$reponame" with-path-wrong-pass
111 git checkout -b with-path-wrong-pass
113 git lfs track "*.dat" 2>&1 | tee track.log
114 grep "Tracking \"\*.dat\"" track.log
117 contents_oid=$(calc_oid "$contents")
119 printf "$contents" > a.dat
121 git add .gitattributes
122 git commit -m "add a.dat"
124 GIT_TRACE=1 git push origin with-path-wrong-pass 2>&1 | tee push.log
125 [ "0" = "$(grep -c "Uploading LFS objects: 100% (1/1), 0 B" push.log)" ]
127 [ "0" -eq "$(cat push.log | grep "creds: git credential approve" | wc -l)" ]
129 [ "2" -eq "$(cat push.log | grep "creds: git credential fill" | wc -l)" ]
133 begin_test "credentials with useHttpPath, with correct password"
137 reponame="$(basename "$0" ".sh")"
138 setup_remote_repo "$reponame"
140 printf "path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame"
142 clone_repo "$reponame" with-path-correct-pass
143 git checkout -b with-path-correct-pass
145 git lfs track "*.dat" 2>&1 | tee track.log
146 grep "Tracking \"\*.dat\"" track.log
148 # creating new branch does not re-send any objects existing on other
149 # remote branches anymore, generate new object, different from prev tests
151 contents_oid=$(calc_oid "$contents")
153 printf "$contents" > b.dat
155 git add .gitattributes
156 git commit -m "add b.dat"
158 GIT_TRACE=1 git push origin with-path-correct-pass 2>&1 | tee push.log
159 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
161 [ "1" -eq "$(cat push.log | grep "creds: git credential approve" | wc -l)" ]
163 [ "1" -eq "$(cat push.log | grep "creds: git credential fill" | wc -l)" ]
164 echo "credential calls have path:"
165 credcalls="$(grep "creds: git credential" push.log)"
166 [ "0" -eq "$(echo "$credcalls" | grep '", "")' | wc -l)" ]
167 expected="$(echo "$credcalls" | wc -l)"
168 [ "$expected" -eq "$(printf "$credcalls" | grep "t-credentials" | wc -l)" ]
172 begin_test "git credential"
176 printf "git:server" > "$CREDSDIR/credential-test.com"
177 printf "git:path" > "$CREDSDIR/credential-test.com--some-path"
184 host=credential-test.com
185 path=some/path" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log
188 expected="protocol=http
189 host=credential-test.com
194 [ "$expected" = "$(cat cred.log)" ]
196 git config credential.useHttpPath false
199 host=credential-test.com" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log
202 expected="protocol=http
203 host=credential-test.com
206 [ "$expected" = "$(cat cred.log)" ]
209 host=credential-test.com
210 path=some/path" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log
213 expected="protocol=http
214 host=credential-test.com
218 [ "$expected" = "$(cat cred.log)" ]
223 if [[ $(uname) == *"MINGW"* ]]; then
224 NETRCFILE="$HOME/_netrc"
226 NETRCFILE="$HOME/.netrc"
230 begin_test "credentials from netrc"
234 printf "machine localhost\nlogin netrcuser\npassword netrcpass\n" >> "$NETRCFILE"
236 echo "GITSERVER $GITSERVER"
239 # prevent prompts on Windows particularly
243 setup_remote_repo "$reponame"
245 clone_repo "$reponame" repo
247 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
248 git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
251 git lfs track "*.dat"
252 echo "push a" > a.dat
253 git add .gitattributes a.dat
254 git commit -m "add a.dat"
256 GIT_TRACE=1 git lfs push netrc master 2>&1 | tee push.log
257 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
258 echo "any git credential calls:"
259 [ "0" -eq "$(cat push.log | grep "git credential" | wc -l)" ]
263 begin_test "credentials from netrc with unknown keyword"
267 printf "machine localhost\nlogin netrcuser\nnot-a-key something\npassword netrcpass\n" >> "$NETRCFILE"
269 echo "GITSERVER $GITSERVER"
272 # prevent prompts on Windows particularly
276 setup_remote_repo "$reponame"
278 clone_repo "$reponame" repo2
280 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
281 git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
284 git lfs track "*.dat"
285 echo "push a" > a.dat
286 git add .gitattributes a.dat
287 git commit -m "add a.dat"
289 GIT_TRACE=1 git lfs push netrc master 2>&1 | tee push.log
290 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
291 echo "any git credential calls:"
292 [ "0" -eq "$(cat push.log | grep "git credential" | wc -l)" ]
296 begin_test "credentials from netrc with bad password"
300 printf "machine localhost\nlogin netrcuser\npassword badpass\n" >> "$NETRCFILE"
302 echo "GITSERVER $GITSERVER"
305 # prevent prompts on Windows particularly
309 setup_remote_repo "$reponame"
311 clone_repo "$reponame" repo3
313 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
314 git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
317 git lfs track "*.dat"
318 echo "push a" > a.dat
319 git add .gitattributes a.dat
320 git commit -m "add a.dat"
322 git push netrc master 2>&1 | tee push.log
323 [ "0" = "$(grep -c "Uploading LFS objects: 100% (1/1), 7 B" push.log)" ]
327 begin_test "credentials from lfs.url"
331 reponame="requirecreds-lfsurl"
332 setup_remote_repo "$reponame"
333 clone_repo "$reponame" "$reponame"
335 git lfs track "*.dat"
336 echo "push a" > a.dat
337 git add .gitattributes a.dat
338 git commit -m "add a.dat"
342 git lfs push origin master 2>&1 | tee push.log
343 grep "Uploading LFS objects: 0% (0/1), 0 B" push.log
346 gitserverhost=$(echo "$GITSERVER" | cut -d'/' -f3)
347 git config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs
349 git lfs push origin master 2>&1 | tee push.log
350 grep "Uploading LFS objects: 0% (0/1), 0 B" push.log
353 rm -rf .git/lfs/objects
354 git config lfs.url http://$gitserverhost/$reponame.git/info/lfs
356 git lfs fetch --all 2>&1 | tee fetch.log
357 grep "Downloading LFS objects: 0% (0/1), 0 B" fetch.log
360 rm -rf .git/lfs/objects
361 git config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs
363 git lfs fetch --all 2>&1 | tee fetch.log
364 grep "Downloading LFS objects: 100% (1/1), 7 B" fetch.log
368 begin_test "credentials from remote.origin.url"
372 reponame="requirecreds-remoteurl"
373 setup_remote_repo "$reponame"
374 clone_repo "$reponame" "$reponame"
376 git lfs track "*.dat"
377 echo "push b" > b.dat
378 git add .gitattributes b.dat
379 git commit -m "add b.dat"
383 git lfs push origin master 2>&1 | tee push.log
384 grep "Uploading LFS objects: 0% (0/1), 0 B" push.log
387 gitserverhost=$(echo "$GITSERVER" | cut -d'/' -f3)
388 git config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git
390 git lfs push origin master 2>&1 | tee push.log
391 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
394 rm -rf .git/lfs/objects
395 git config remote.origin.url http://$gitserverhost/$reponame.git
397 git lfs fetch --all 2>&1 | tee fetch.log
398 # Missing authentication causes `git lfs fetch` to fail before the progress
399 # meter is printed to the TTY.
402 rm -rf .git/lfs/objects
403 git config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git
405 git lfs fetch --all 2>&1 | tee fetch.log
406 grep "Downloading LFS objects: 100% (1/1), 7 B" fetch.log