git-lfs/t/t-extra-header.sh

131 lines
3.8 KiB
Bash
Raw Normal View History

#!/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 master 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 master 2>&1 | tee curl.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "expected \`git push origin master\` 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 master 2>&1 | tee curl.log
if [ "0" -ne "${PIPESTATUS[0]}" ]; then
echo >&2 "expected \`git push origin master\` 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
Properly handle config options for URLs with upper case letters Git configuration options have a complicated situation with regard to case. For the most part, they are case-insensitive: you may write any case into the file, but Git interprets it as lower case. However, there are exceptions. Because the middle component of a three-component option can be a URL, branch name, or remote name, this component (and only this component) is treated as case sensitive. Since this component can be a URL, which may (and, due to the ".git" portion, usually does) contain a dot, the first component of the config option is read up until the first dot, and the last component is read from the end to the last dot. When git config writes a value into the file, it preserves the case the user has provided, and when it prints the config values, it canonicalizes the keys by folding the case-insensitive portions to lowercase. Git LFS then reads this canonicalized form in as our source of config options, relieving us from having to parse the files ourselves. However, when we read this data in, we forced the key to lowercase, and when we looked up a key, we also forced the key we were looking up to lowercase. While this behavior was wrong (since URLs, at least, are case-sensitive), it did happen to mostly work if the configuration didn't contain settings for two URLs differing in case. In the 2.7.0 cycle, we changed the way we did URL config lookups to match the way Git does them. Previously, we performed configuration lookups on several possible keys (forcing them to lower case, URL portion included) and took the first that matched. Now, we directly compare the URL we're connecting to (which may be in mixed case) to the values we got in the configuration (which we've forced to lowercase). Consequently, we will fail to find configuration options for a mixed-case URL, resulting in things like "http.extraHeader" not being used. Fix this issue by letting Git do the canonicalization of configuration keys for us instead of lowercasing them ourselves and then canonicalizing the key when looking it up in the table. Add tests for this behavior with "http.extraHeader" in the integration suite and several canonicalization assertions in the unit tests. Update several tests to use the canonical version of the data in their test data stores, and add a check to avoid noncanonical test data. Co-authored-by: Taylor Blau <me@ttaylorr.com>
2019-03-28 22:06:50 +00:00
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 master 2>&1 | tee curl.log
grep "> X-Foo: bar" curl.log
grep "> X-Foo: baz" curl.log
)
end_test