| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . 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="$(gitscip-shell system . . git. config remote.origin.url).git/info/lfs" |
| 14 | gitscip-shell system . . git. config --add "http.$url.extraHeader" "X-Foo: bar" |
| 15 | gitscip-shell system . . git. config --add "http.$url.extraHeader" "X-Foo: baz" |
| 16 | |
| 17 | gitscip-shell system . . git. lfs track "*.dat" |
| 18 | printfscip-shell system . . printf. "contents" > a.dat |
| 19 | gitscip-shell system . . git. add .gitattributes a.dat |
| 20 | gitscip-shell system . . git. commit -m "initial commit" |
| 21 | |
| 22 | GIT_CURL_VERBOSE=1 GIT_TRACE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. curl.log |
| 23 | |
| 24 | grepscip-shell system . . grep. "> X-Foo: bar" curl.log |
| 25 | grepscip-shell system . . 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 $(echoscip-shell system . . echo. -n $user:$pass | base64scip-shell system . . base64.)" |
| 41 | |
| 42 | gitscip-shell system . . git. config --add "http.extraHeader" "Authorization: $auth" |
| 43 | |
| 44 | gitscip-shell system . . git. lfs track "*.dat" |
| 45 | printfscip-shell system . . printf. "contents" > a.dat |
| 46 | gitscip-shell system . . git. add .gitattributes a.dat |
| 47 | gitscip-shell system . . git. commit -m "initial commit" |
| 48 | |
| 49 | gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. curl.log |
| 50 | if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then |
| 51 | echoscip-shell system . . echo. >&2 "expected \`git push origin main\` to succeed, didn't" |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: filling with GIT_ASKPASS" curl.log)" ] |
| 56 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" curl.log)" ] |
| 57 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: git credential cache" curl.log)" ] |
| 58 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" curl.log)" ] |
| 59 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . 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 $(echoscip-shell system . . echo. -n $user:$pass | base64scip-shell system . . base64.)" |
| 75 | |
| 76 | gitscip-shell system . . 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 | gitscip-shell system . . git. config --local --add "http.extraHeader" "AUTHORIZATION: $auth" |
| 80 | |
| 81 | gitscip-shell system . . git. lfs track "*.dat" |
| 82 | printfscip-shell system . . printf. "contents" > a.dat |
| 83 | gitscip-shell system . . git. add .gitattributes a.dat |
| 84 | gitscip-shell system . . git. commit -m "initial commit" |
| 85 | |
| 86 | gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. curl.log |
| 87 | if [scip-shell system . . `[`. "0" -ne "${PIPESTATUS[0]}" ]; then |
| 88 | echoscip-shell system . . echo. >&2 "expected \`git push origin main\` to succeed, didn't" |
| 89 | exit 1 |
| 90 | fi |
| 91 | |
| 92 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: filling with GIT_ASKPASS" curl.log)" ] |
| 93 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: git credential approve" curl.log)" ] |
| 94 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: git credential cache" curl.log)" ] |
| 95 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . grep. -c "creds: git credential fill" curl.log)" ] |
| 96 | [scip-shell system . . `[`. "0" -eq "$(grepscip-shell system . . 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="$(gitscip-shell system . . git. config remote.origin.url).git" |
| 117 | gitscip-shell system . . git. config --add "http.$url.ExtraHeader" "X-Foo: bar" |
| 118 | gitscip-shell system . . git. config --add "http.$url.ExtraHeader" "X-Foo: baz" |
| 119 | |
| 120 | gitscip-shell system . . git. lfs track "*.dat" |
| 121 | printfscip-shell system . . printf. "contents" > a.dat |
| 122 | gitscip-shell system . . git. add .gitattributes a.dat |
| 123 | gitscip-shell system . . git. commit -m "initial commit" |
| 124 | |
| 125 | GIT_CURL_VERBOSE=1 GIT_TRACE=1 gitscip-shell system . . git. push origin main 2>&1 | teescip-shell system . . tee. curl.log |
| 126 | |
| 127 | grepscip-shell system . . grep. "> X-Foo: bar" curl.log |
| 128 | grepscip-shell system . . grep. "> X-Foo: baz" curl.log |
| 129 | ) |
| 130 | end_test |