|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +. "$(dirname "$0")/testlib.sh" |
| 4 | + |
| 5 | +ensure_git_version_isnt $VERSION_LOWER "2.3.0" |
| 6 | + |
| 7 | +export CREDSDIR="$REMOTEDIR/creds-credentials-protect" |
| 8 | +setup_creds |
| 9 | + |
| 10 | +# Copy the default record file for the test credential helper to match the |
| 11 | +# hostname used in the Git LFS configurations of the tests. |
| 12 | +cp "$CREDSDIR/127.0.0.1" "$CREDSDIR/localhost" |
| 13 | + |
| 14 | +begin_test "credentials rejected with line feed" |
| 15 | +( |
| 16 | + set -e |
| 17 | + |
| 18 | + reponame="protect-linefeed" |
| 19 | + setup_remote_repo "$reponame" |
| 20 | + clone_repo "$reponame" "$reponame" |
| 21 | + |
| 22 | + contents="a" |
| 23 | + contents_oid=$(calc_oid "$contents") |
| 24 | + |
| 25 | + git lfs track "*.dat" |
| 26 | + printf "%s" "$contents" >a.dat |
| 27 | + git add .gitattributes a.dat |
| 28 | + git commit -m "add a.dat" |
| 29 | + |
| 30 | + # Using localhost instead of 127.0.0.1 in the LFS API URL ensures this URL |
| 31 | + # is used when filling credentials rather than the Git remote URL, which |
| 32 | + # would otherwise be used since it would have the same scheme and hostname. |
| 33 | + gitserver="$(echo "$GITSERVER" | sed 's/127\.0\.0\.1/localhost/')" |
| 34 | + testreponame="test%0a$reponame" |
| 35 | + git config lfs.url "$gitserver/$testreponame.git/info/lfs" |
| 36 | + |
| 37 | + GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log |
| 38 | + if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 39 | + echo >&2 "fatal: expected 'git lfs push' to fail ..." |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + grep "batch response: Git credentials for $gitserver.* not found" push.log |
| 43 | + grep "credential value for path contains newline" push.log |
| 44 | + refute_server_object "$testreponame" "$contents_oid" |
| 45 | + |
| 46 | + git config credential.protectProtocol false |
| 47 | + |
| 48 | + GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log |
| 49 | + if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 50 | + echo >&2 "fatal: expected 'git lfs push' to fail ..." |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + grep "batch response: Git credentials for $gitserver.* not found" push.log |
| 54 | + grep "credential value for path contains newline" push.log |
| 55 | + refute_server_object "$testreponame" "$contents_oid" |
| 56 | +) |
| 57 | +end_test |
| 58 | + |
| 59 | +begin_test "credentials rejected with carriage return" |
| 60 | +( |
| 61 | + set -e |
| 62 | + |
| 63 | + reponame="protect-return" |
| 64 | + setup_remote_repo "$reponame" |
| 65 | + clone_repo "$reponame" "$reponame" |
| 66 | + |
| 67 | + contents="a" |
| 68 | + contents_oid=$(calc_oid "$contents") |
| 69 | + |
| 70 | + git lfs track "*.dat" |
| 71 | + printf "%s" "$contents" >a.dat |
| 72 | + git add .gitattributes a.dat |
| 73 | + git commit -m "add a.dat" |
| 74 | + |
| 75 | + # Using localhost instead of 127.0.0.1 in the LFS API URL ensures this URL |
| 76 | + # is used when filling credentials rather than the Git remote URL, which |
| 77 | + # would otherwise be used since it would have the same scheme and hostname. |
| 78 | + gitserver="$(echo "$GITSERVER" | sed 's/127\.0\.0\.1/localhost/')" |
| 79 | + testreponame="test%0d$reponame" |
| 80 | + git config lfs.url "$gitserver/$testreponame.git/info/lfs" |
| 81 | + |
| 82 | + GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log |
| 83 | + if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 84 | + echo >&2 "fatal: expected 'git lfs push' to fail ..." |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | + grep "batch response: Git credentials for $gitserver.* not found" push.log |
| 88 | + grep "credential value for path contains carriage return" push.log |
| 89 | + refute_server_object "$testreponame" "$contents_oid" |
| 90 | + |
| 91 | + git config credential.protectProtocol false |
| 92 | + |
| 93 | + git lfs push origin main 2>&1 | tee push.log |
| 94 | + if [ "0" -ne "${PIPESTATUS[0]}" ]; then |
| 95 | + echo >&2 "fatal: expected 'git lfs push' to succeed ..." |
| 96 | + exit 1 |
| 97 | + fi |
| 98 | + [ $(grep -c "Uploading LFS objects: 100% (1/1)" push.log) -eq 1 ] |
| 99 | + assert_server_object "$testreponame" "$contents_oid" |
| 100 | +) |
| 101 | +end_test |
| 102 | + |
| 103 | +begin_test "credentials rejected with null byte" |
| 104 | +( |
| 105 | + set -e |
| 106 | + |
| 107 | + reponame="protect-null" |
| 108 | + setup_remote_repo "$reponame" |
| 109 | + clone_repo "$reponame" "$reponame" |
| 110 | + |
| 111 | + contents="a" |
| 112 | + contents_oid=$(calc_oid "$contents") |
| 113 | + |
| 114 | + git lfs track "*.dat" |
| 115 | + printf "%s" "$contents" >a.dat |
| 116 | + git add .gitattributes a.dat |
| 117 | + git commit -m "add a.dat" |
| 118 | + |
| 119 | + # Using localhost instead of 127.0.0.1 in the LFS API URL ensures this URL |
| 120 | + # is used when filling credentials rather than the Git remote URL, which |
| 121 | + # would otherwise be used since it would have the same scheme and hostname. |
| 122 | + gitserver="$(echo "$GITSERVER" | sed 's/127\.0\.0\.1/localhost/')" |
| 123 | + testreponame="test%00$reponame" |
| 124 | + git config lfs.url "$gitserver/$testreponame.git/info/lfs" |
| 125 | + |
| 126 | + GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log |
| 127 | + if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 128 | + echo >&2 "fatal: expected 'git lfs push' to fail ..." |
| 129 | + exit 1 |
| 130 | + fi |
| 131 | + grep "batch response: Git credentials for $gitserver.* not found" push.log |
| 132 | + grep "credential value for path contains null byte" push.log |
| 133 | + refute_server_object "$testreponame" "$contents_oid" |
| 134 | + |
| 135 | + git config credential.protectProtocol false |
| 136 | + |
| 137 | + GIT_TRACE=1 git lfs push origin main 2>&1 | tee push.log |
| 138 | + if [ "0" -eq "${PIPESTATUS[0]}" ]; then |
| 139 | + echo >&2 "fatal: expected 'git lfs push' to fail ..." |
| 140 | + exit 1 |
| 141 | + fi |
| 142 | + grep "batch response: Git credentials for $gitserver.* not found" push.log |
| 143 | + grep "credential value for path contains null byte" push.log |
| 144 | + refute_server_object "$testreponame" "$contents_oid" |
| 145 | +) |
| 146 | +end_test |
0 commit comments