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 checkout -b without-path
82 git lfs track "*.dat" 2>&1 | tee track.log
83 grep "Tracking \"\*.dat\"" track.log
87 git add .gitattributes
88 git commit -m "add a.dat"
90 GIT_TRACE=1 git push origin without-path 2>&1 | tee push.log
91 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
94 [ "1" -eq "$(cat push.log | grep "creds: git credential approve" | wc -l)" ]
96 [ "1" -eq "$(cat push.log | grep "creds: git credential fill" | wc -l)" ]
100 begin_test "credentials with useHttpPath, with wrong password"
104 reponame="httppath-bad-password"
105 setup_remote_repo "$reponame"
107 printf "path:wrong" > "$CREDSDIR/127.0.0.1--$reponame"
109 clone_repo "$reponame" with-path-wrong-pass
110 git checkout -b with-path-wrong-pass
112 git lfs track "*.dat" 2>&1 | tee track.log
113 grep "Tracking \"\*.dat\"" track.log
116 contents_oid=$(calc_oid "$contents")
118 printf "$contents" > a.dat
120 git add .gitattributes
121 git commit -m "add a.dat"
123 GIT_TRACE=1 git push origin with-path-wrong-pass 2>&1 | tee push.log
124 [ "0" = "$(grep -c "Uploading LFS objects: 100% (1/1), 0 B" push.log)" ]
126 [ "0" -eq "$(cat push.log | grep "creds: git credential approve" | wc -l)" ]
128 [ "2" -eq "$(cat push.log | grep "creds: git credential fill" | wc -l)" ]
132 begin_test "credentials with useHttpPath, with correct password"
136 reponame="$(basename "$0" ".sh")"
137 setup_remote_repo "$reponame"
139 printf "path:$reponame" > "$CREDSDIR/127.0.0.1--$reponame"
141 clone_repo "$reponame" with-path-correct-pass
142 git checkout -b with-path-correct-pass
144 git lfs track "*.dat" 2>&1 | tee track.log
145 grep "Tracking \"\*.dat\"" track.log
147 # creating new branch does not re-send any objects existing on other
148 # remote branches anymore, generate new object, different from prev tests
150 contents_oid=$(calc_oid "$contents")
152 printf "$contents" > b.dat
154 git add .gitattributes
155 git commit -m "add b.dat"
157 GIT_TRACE=1 git push origin with-path-correct-pass 2>&1 | tee push.log
158 grep "Uploading LFS objects: 100% (1/1), 1 B" push.log
160 [ "1" -eq "$(cat push.log | grep "creds: git credential approve" | wc -l)" ]
162 [ "1" -eq "$(cat push.log | grep "creds: git credential fill" | wc -l)" ]
163 echo "credential calls have path:"
164 credcalls="$(grep "creds: git credential" push.log)"
165 [ "0" -eq "$(echo "$credcalls" | grep '", "")' | wc -l)" ]
166 expected="$(echo "$credcalls" | wc -l)"
167 [ "$expected" -eq "$(printf "$credcalls" | grep "test-credentials" | wc -l)" ]
171 begin_test "git credential"
175 printf "git:server" > "$CREDSDIR/credential-test.com"
176 printf "git:path" > "$CREDSDIR/credential-test.com--some-path"
183 host=credential-test.com
184 path=some/path" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log
187 expected="protocol=http
188 host=credential-test.com
193 [ "$expected" = "$(cat cred.log)" ]
195 git config credential.useHttpPath false
198 host=credential-test.com" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log
201 expected="protocol=http
202 host=credential-test.com
205 [ "$expected" = "$(cat cred.log)" ]
208 host=credential-test.com
209 path=some/path" | GIT_TERMINAL_PROMPT=0 git credential fill > cred.log
212 expected="protocol=http
213 host=credential-test.com
217 [ "$expected" = "$(cat cred.log)" ]
222 if [[ $(uname) == *"MINGW"* ]]; then
223 NETRCFILE="$HOME/_netrc"
225 NETRCFILE="$HOME/.netrc"
229 begin_test "credentials from netrc"
233 printf "machine localhost\nlogin netrcuser\npassword netrcpass\n" >> "$NETRCFILE"
235 echo "GITSERVER $GITSERVER"
238 # prevent prompts on Windows particularly
242 setup_remote_repo "$reponame"
244 clone_repo "$reponame" repo
246 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
247 git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
250 git lfs track "*.dat"
251 echo "push a" > a.dat
252 git add .gitattributes a.dat
253 git commit -m "add a.dat"
255 GIT_TRACE=1 git lfs push netrc master 2>&1 | tee push.log
256 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
257 echo "any git credential calls:"
258 [ "0" -eq "$(cat push.log | grep "git credential" | wc -l)" ]
262 begin_test "credentials from netrc with bad password"
266 printf "machine localhost\nlogin netrcuser\npassword badpass\n" >> "$NETRCFILE"
268 echo "GITSERVER $GITSERVER"
271 # prevent prompts on Windows particularly
275 setup_remote_repo "$reponame"
277 clone_repo "$reponame" repo2
279 # Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
280 git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
283 git lfs track "*.dat"
284 echo "push a" > a.dat
285 git add .gitattributes a.dat
286 git commit -m "add a.dat"
288 git push netrc master 2>&1 | tee push.log
289 [ "0" = "$(grep -c "Uploading LFS objects: 100% (1/1), 7 B" push.log)" ]
293 begin_test "credentials from lfs.url"
297 reponame="requirecreds"
298 setup_remote_repo "$reponame"
299 clone_repo "$reponame" requirecreds-lfsurl
301 git lfs track "*.dat"
302 echo "push a" > a.dat
303 git add .gitattributes a.dat
304 git commit -m "add a.dat"
308 git lfs push origin master 2>&1 | tee push.log
309 grep "Uploading LFS objects: 0% (0/1), 0 B" push.log
312 gitserverhost=$(echo "$GITSERVER" | cut -d'/' -f3)
313 git config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs
315 git lfs push origin master 2>&1 | tee push.log
316 grep "Uploading LFS objects: 0% (0/1), 0 B" push.log
319 rm -rf .git/lfs/objects
320 git config lfs.url http://$gitserverhost/$reponame.git/info/lfs
322 git lfs fetch --all 2>&1 | tee fetch.log
323 grep "Downloading LFS objects: 0% (0/1), 0 B" fetch.log
326 rm -rf .git/lfs/objects
327 git config lfs.url http://requirecreds:pass@$gitserverhost/$reponame.git/info/lfs
329 git lfs fetch --all 2>&1 | tee fetch.log
330 grep "Downloading LFS objects: 100% (1/1), 7 B" fetch.log
334 begin_test "credentials from remote.origin.url"
338 reponame="requirecreds"
339 setup_remote_repo "$reponame"
340 clone_repo "$reponame" requirecreds-remoteurl
342 git lfs track "*.dat"
343 echo "push b" > b.dat
344 git add .gitattributes b.dat
345 git commit -m "add b.dat"
349 git lfs push origin master 2>&1 | tee push.log
350 grep "Uploading LFS objects: 0% (0/1), 0 B" push.log
353 gitserverhost=$(echo "$GITSERVER" | cut -d'/' -f3)
354 git config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git
356 git lfs push origin master 2>&1 | tee push.log
357 grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
360 rm -rf .git/lfs/objects
361 git config remote.origin.url http://$gitserverhost/$reponame.git
363 git lfs fetch --all 2>&1 | tee fetch.log
364 # Missing authentication causes `git lfs fetch` to fail before the progress
365 # meter is printed to the TTY.
368 rm -rf .git/lfs/objects
369 git config remote.origin.url http://requirecreds:pass@$gitserverhost/$reponame.git
371 git lfs fetch --all 2>&1 | tee fetch.log
372 grep "Downloading LFS objects: 100% (1/1), 7 B" fetch.log