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