Skip to content

Commit 2edefc5

Browse files
committed
t/t-credentials.sh: also test .netrc on Windows
In previous commits in this PR we revised the ParseNetrc() function in our "creds" package to support both ".netrc" and "_netrc" files on Windows, whereas it has previously only supported "_netrc" files. This change will align the behaviour of the Git LFS client with that of contemporary versions of curl and Git, as they now support both filenames on Windows. Specifically, this support was added in commit curl/curl@f9c7ba9, which was included in curl v7.66.0. To validate these changes, we also update our t/t-credentials.sh test script so it runs the key "credentials from netrc" test twice on Windows, once with a ".netrc" file and once with a legacy "_netrc" file. As well, we adjust the other tests which previously used a "_netrc" file on Windows to simply use a ".netrc" file, as this should work on all systems now.
1 parent 6863d06 commit 2edefc5

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

t/t-credentials.sh

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -437,61 +437,60 @@ state[]=lfstest:state2"
437437
)
438438
end_test
439439

440-
441-
if [[ $(uname) == *"MINGW"* ]]; then
442-
NETRCFILE="$HOME/_netrc"
443-
else
444-
NETRCFILE="$HOME/.netrc"
440+
NETRCFILES=".netrc"
441+
if [ "$IS_WINDOWS" -eq 1 ]; then
442+
NETRCFILES+=" _netrc"
445443
fi
446444

445+
for netrcfile in $NETRCFILES; do
446+
begin_test "credentials from netrc ($netrcfile)"
447+
(
448+
set -e
447449

448-
begin_test "credentials from netrc"
449-
(
450-
set -e
450+
printf "machine localhost\nlogin netrcuser\npassword netrcpass\n" >"$HOME/$netrcfile"
451+
echo $HOME
452+
echo "GITSERVER $GITSERVER"
453+
cat "$HOME/$netrcfile"
451454

452-
printf "machine localhost\nlogin netrcuser\npassword netrcpass\n" >> "$NETRCFILE"
453-
echo $HOME
454-
echo "GITSERVER $GITSERVER"
455-
cat $NETRCFILE
455+
# prevent prompts on Windows particularly
456+
export SSH_ASKPASS=
456457

457-
# prevent prompts on Windows particularly
458-
export SSH_ASKPASS=
458+
reponame="netrctest-$netrcfile"
459+
setup_remote_repo "$reponame"
459460

460-
reponame="netrctest"
461-
setup_remote_repo "$reponame"
461+
clone_repo "$reponame" "${reponame}-assert"
462462

463-
clone_repo "$reponame" repo
463+
# Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
464+
git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
465+
git lfs env
464466

465-
# Need a remote named "localhost" or 127.0.0.1 in netrc will interfere with the other auth
466-
git remote add "netrc" "$(echo $GITSERVER | sed s/127.0.0.1/localhost/)/netrctest"
467-
git lfs env
467+
git lfs track "*.dat"
468+
echo "push a" > a.dat
469+
git add .gitattributes a.dat
470+
git commit -m "add a.dat"
468471

469-
git lfs track "*.dat"
470-
echo "push a" > a.dat
471-
git add .gitattributes a.dat
472-
git commit -m "add a.dat"
472+
GIT_TRACE=1 git lfs push netrc main 2>&1 | tee push.log
473+
grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
474+
echo "any netrc credential calls:"
475+
[ "4" -eq "$(cat push.log | grep "netrc: git credential" | wc -l)" ]
473476

474-
GIT_TRACE=1 git lfs push netrc main 2>&1 | tee push.log
475-
grep "Uploading LFS objects: 100% (1/1), 7 B" push.log
476-
echo "any netrc credential calls:"
477-
[ "4" -eq "$(cat push.log | grep "netrc: git credential" | wc -l)" ]
477+
echo "any netrc credential fills:"
478+
[ "2" -eq "$(cat push.log | grep "netrc: git credential fill" | wc -l)" ]
478479

479-
echo "any netrc credential fills:"
480-
[ "2" -eq "$(cat push.log | grep "netrc: git credential fill" | wc -l)" ]
481-
482-
echo "any netrc credential approvals:"
483-
[ "2" -eq "$(cat push.log | grep "netrc: git credential approve" | wc -l)" ]
484-
)
485-
end_test
480+
echo "any netrc credential approvals:"
481+
[ "2" -eq "$(cat push.log | grep "netrc: git credential approve" | wc -l)" ]
482+
)
483+
end_test
484+
done
486485

487486
begin_test "credentials from netrc with unknown keyword"
488487
(
489488
set -e
490489

491-
printf "machine localhost\nlogin netrcuser\nnot-a-key something\npassword netrcpass\n" >> "$NETRCFILE"
490+
printf "machine localhost\nlogin netrcuser\nnot-a-key something\npassword netrcpass\n" >"$HOME/.netrc"
492491
echo $HOME
493492
echo "GITSERVER $GITSERVER"
494-
cat $NETRCFILE
493+
cat "$HOME/.netrc"
495494

496495
# prevent prompts on Windows particularly
497496
export SSH_ASKPASS=
@@ -527,10 +526,10 @@ begin_test "credentials from netrc with bad password"
527526
(
528527
set -e
529528

530-
printf "machine localhost\nlogin netrcuser\npassword badpass\n" >> "$NETRCFILE"
529+
printf "machine localhost\nlogin netrcuser\npassword badpass\n" >"$HOME/.netrc"
531530
echo $HOME
532531
echo "GITSERVER $GITSERVER"
533-
cat $NETRCFILE
532+
cat "$HOME/.netrc"
534533

535534
# prevent prompts on Windows particularly
536535
export SSH_ASKPASS=
@@ -558,10 +557,10 @@ begin_test "credentials with bad netrc creds will retry"
558557
(
559558
set -e
560559

561-
printf "machine localhost\nlogin netrcuser\npassword badpassretry\n" >> "$NETRCFILE"
560+
printf "machine localhost\nlogin netrcuser\npassword badpassretry\n" >"$HOME/.netrc"
562561
echo $HOME
563562
echo "GITSERVER $GITSERVER"
564-
cat $NETRCFILE
563+
cat "$HOME/.netrc"
565564

566565
# prevent prompts on Windows particularly
567566
export SSH_ASKPASS=

0 commit comments

Comments
 (0)