1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "http.<url>.extraHeader"
(
set -e
reponame="copy-headers"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
url="$(git config remote.origin.url).git/info/lfs"
git config --add "http.$url.extraHeader" "X-Foo: bar"
git config --add "http.$url.extraHeader" "X-Foo: baz"
git lfs track "*.dat"
printf "contents" > a.dat
git add .gitattributes a.dat
git commit -m "initial commit"
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git push origin main 2>&1 | tee curl.log
grep "> X-Foo: bar" curl.log
grep "> X-Foo: baz" curl.log
)
end_test
begin_test "http.<url>.extraHeader with authorization"
(
set -e
reponame="requirecreds-extraHeader"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
# See: test/cmd/lfstest-gitserver.go:missingRequiredCreds().
user="requirecreds"
pass="pass"
auth="Basic $(echo -n $user:$pass | base64)"
git config --add "http.extraHeader" "Authorization: $auth"
git lfs track "*.dat"
printf "contents" > a.dat
git add .gitattributes a.dat
git commit -m "initial commit"
git push origin main 2>&1 | tee curl.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "expected \`git push origin main\` to succeed, didn't"
exit 1
fi
[ "0" -eq "$(grep -c "creds: filling with GIT_ASKPASS" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential approve" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential cache" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential fill" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential reject" curl.log)" ]
)
end_test
begin_test "http.<url>.extraHeader with authorization (casing)"
(
set -e
reponame="requirecreds-extraHeaderCasing"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
# See: test/cmd/lfstest-gitserver.go:missingRequiredCreds().
user="requirecreds"
pass="pass"
auth="Basic $(echo -n $user:$pass | base64)"
git config --local --add lfs.access basic
# N.B.: "AUTHORIZATION" is not the correct casing, and is therefore the
# subject of this test. See lfsapi.Client.extraHeaders() for more.
git config --local --add "http.extraHeader" "AUTHORIZATION: $auth"
git lfs track "*.dat"
printf "contents" > a.dat
git add .gitattributes a.dat
git commit -m "initial commit"
git push origin main 2>&1 | tee curl.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "expected \`git push origin main\` to succeed, didn't"
exit 1
fi
[ "0" -eq "$(grep -c "creds: filling with GIT_ASKPASS" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential approve" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential cache" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential fill" curl.log)" ]
[ "0" -eq "$(grep -c "creds: git credential reject" curl.log)" ]
)
end_test
begin_test "http.<url>.extraHeader with mixed-case URLs"
(
set -e
reponame="Mixed-Case-Headers"
setup_remote_repo "$reponame"
clone_repo "$reponame" "$reponame"
# These config options check for several things.
#
# First, we check for mixed-case URLs being read properly and not forced to
# lowercase. Second, we check that the user can specify a config option for
# the Git URL and have that apply to the LFS URL, which exercises the
# URLConfig lookup code. Finally, we also write "ExtraHeader" in mixed-case as
# well to test that we lower-case the rightmost portion of the config key
# during lookup.
url="$(git config remote.origin.url).git"
git config --add "http.$url.ExtraHeader" "X-Foo: bar"
git config --add "http.$url.ExtraHeader" "X-Foo: baz"
git lfs track "*.dat"
printf "contents" > a.dat
git add .gitattributes a.dat
git commit -m "initial commit"
GIT_CURL_VERBOSE=1 GIT_TRACE=1 git push origin main 2>&1 | tee curl.log
grep "> X-Foo: bar" curl.log
grep "> X-Foo: baz" curl.log
)
end_test
|