| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "batch storage HTTP download of corrupt object" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="batch-storage-download-corrupt-http" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" "$reponame" |
| 12 | |
| 13 | git lfs track "*.dat" |
| 14 | git add .gitattributes |
| 15 | git commit -m "initial commit" |
| 16 | |
| 17 | initial_sha="$(git rev-parse HEAD)" |
| 18 | |
| 19 | # This content announces to the server that it should corrupt the |
| 20 | # contents of the object before returning it. |
| 21 | contents="storage-download-corrupt" |
| 22 | contents_oid="$(calc_oid "$contents")" |
| 23 | printf "%s" "$contents" > a.dat |
| 24 | |
| 25 | git add a.dat |
| 26 | git commit -m "add a.dat" |
| 27 | |
| 28 | git push origin main |
| 29 | |
| 30 | assert_server_object "$reponame" "$contents_oid" |
| 31 | |
| 32 | rm -f a.dat |
| 33 | rm -rf .git/lfs/objects |
| 34 | |
| 35 | # We expect the server to corrupt the object's contents by inverting |
| 36 | # the case of each character. |
| 37 | inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")" |
| 38 | |
| 39 | GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log |
| 40 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 41 | |
| 42 | grep "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log |
| 43 | grep "Failed to fetch some objects" pull.log |
| 44 | |
| 45 | refute_local_object "$contents_oid" |
| 46 | refute_local_object "$inverted_contents_oid" |
| 47 | |
| 48 | expected="${contents_oid:0:10} - a.dat" |
| 49 | [ "$expected" = "$(git lfs ls-files)" ] |
| 50 | |
| 51 | git lfs fsck --objects 2>&1 | tee fsck.log |
| 52 | [ 1 -eq "${PIPESTATUS[0]}" ] |
| 53 | |
| 54 | grep "objects: openError: a.dat ($contents_oid) could not be checked: .*" fsck.log |
| 55 | |
| 56 | # Test again using "git pull", which should not advance HEAD after the |
| 57 | # smudge filter reports an error. |
| 58 | git reset --hard HEAD^ |
| 59 | |
| 60 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git pull origin main 2>&1 | tee pull.log |
| 61 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 62 | |
| 63 | grep "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log |
| 64 | grep "Smudge error: Error downloading a.dat ($contents_oid)" pull.log |
| 65 | |
| 66 | refute_local_object "$contents_oid" |
| 67 | refute_local_object "$inverted_contents_oid" |
| 68 | |
| 69 | [ "$initial_sha" = "$(git rev-parse HEAD)" ] |
| 70 | |
| 71 | [ -z "$(git lfs ls-files)" ] |
| 72 | |
| 73 | git lfs fsck --objects 2>&1 | tee fsck.log |
| 74 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 75 | |
| 76 | grep "Git LFS fsck OK" fsck.log |
| 77 | ) |
| 78 | end_test |
| 79 | |
| 80 | begin_test "batch storage SSH download of corrupt object" |
| 81 | ( |
| 82 | set -e |
| 83 | |
| 84 | setup_pure_ssh |
| 85 | |
| 86 | reponame="batch-storage-download-corrupt-ssh" |
| 87 | setup_remote_repo "$reponame" |
| 88 | clone_repo "$reponame" "$reponame" |
| 89 | |
| 90 | sshurl=$(ssh_remote "$reponame") |
| 91 | git config lfs.url "$sshurl" |
| 92 | |
| 93 | git lfs track "*.dat" |
| 94 | git add .gitattributes |
| 95 | git commit -m "initial commit" |
| 96 | |
| 97 | initial_sha="$(git rev-parse HEAD)" |
| 98 | |
| 99 | contents="storage-download-corrupt" |
| 100 | contents_oid="$(calc_oid "$contents")" |
| 101 | printf "%s" "$contents" > a.dat |
| 102 | |
| 103 | git add a.dat |
| 104 | git commit -m "add a.dat" |
| 105 | |
| 106 | git push origin main |
| 107 | |
| 108 | assert_remote_object "$reponame" "$contents_oid" "${#contents}" |
| 109 | |
| 110 | rm -f a.dat |
| 111 | rm -rf .git/lfs/objects |
| 112 | |
| 113 | # We corrupt the object's contents in the remote repository by inverting |
| 114 | # the case of each character. |
| 115 | inverted_contents="$(invert_case "$contents")" |
| 116 | inverted_contents_oid="$(calc_oid "$inverted_contents")" |
| 117 | |
| 118 | remote_path="$(canonical_path "$REMOTEDIR/$reponame.git")" |
| 119 | pushd "$remote_path" |
| 120 | printf "%s" "$inverted_contents" >"$(local_object_path "$contents_oid")" |
| 121 | popd |
| 122 | |
| 123 | GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log |
| 124 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 125 | |
| 126 | grep "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log |
| 127 | grep "Failed to fetch some objects" pull.log |
| 128 | |
| 129 | refute_local_object "$contents_oid" |
| 130 | refute_local_object "$inverted_contents_oid" |
| 131 | |
| 132 | expected="${contents_oid:0:10} - a.dat" |
| 133 | [ "$expected" = "$(git lfs ls-files)" ] |
| 134 | |
| 135 | git lfs fsck --objects 2>&1 | tee fsck.log |
| 136 | [ 1 -eq "${PIPESTATUS[0]}" ] |
| 137 | |
| 138 | grep "objects: openError: a.dat ($contents_oid) could not be checked: .*" fsck.log |
| 139 | |
| 140 | # Test again using "git pull", which should not advance HEAD after the |
| 141 | # smudge filter reports an error. |
| 142 | git reset --hard HEAD^ |
| 143 | |
| 144 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git pull origin main 2>&1 | tee pull.log |
| 145 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 146 | |
| 147 | grep "expected OID $contents_oid, got $inverted_contents_oid after ${#contents} bytes written" pull.log |
| 148 | grep "Smudge error: Error downloading a.dat ($contents_oid)" pull.log |
| 149 | |
| 150 | refute_local_object "$contents_oid" |
| 151 | refute_local_object "$inverted_contents_oid" |
| 152 | |
| 153 | [ "$initial_sha" = "$(git rev-parse HEAD)" ] |
| 154 | |
| 155 | [ -z "$(git lfs ls-files)" ] |
| 156 | |
| 157 | git lfs fsck --objects 2>&1 | tee fsck.log |
| 158 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 159 | |
| 160 | grep "Git LFS fsck OK" fsck.log |
| 161 | ) |
| 162 | end_test |
| 163 | |
| 164 | begin_test "batch storage custom adapter download of corrupt object" |
| 165 | ( |
| 166 | set -e |
| 167 | |
| 168 | # The "custom-transfer-" prefix indicates to the server to advertise |
| 169 | # support for custom transfers. |
| 170 | reponame="custom-transfer-batch-storage-download-corrupt" |
| 171 | setup_remote_repo "$reponame" |
| 172 | clone_repo "$reponame" "$reponame" |
| 173 | |
| 174 | git lfs track "*.dat" |
| 175 | git add .gitattributes |
| 176 | git commit -m "initial commit" |
| 177 | |
| 178 | initial_sha="$(git rev-parse HEAD)" |
| 179 | |
| 180 | # This content announces to the server that it should corrupt the |
| 181 | # contents of the object before returning it. |
| 182 | contents="storage-download-corrupt" |
| 183 | contents_oid="$(calc_oid "$contents")" |
| 184 | printf "%s" "$contents" > a.dat |
| 185 | |
| 186 | git add a.dat |
| 187 | git commit -m "add a.dat" |
| 188 | |
| 189 | git config lfs.customTransfer.testcustom.path lfstest-customadapter |
| 190 | |
| 191 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin main 2>&1 | tee push.log |
| 192 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 193 | |
| 194 | grep "tq: starting transfer adapter" push.log |
| 195 | grep "xfer: started custom adapter process" push.log |
| 196 | |
| 197 | assert_server_object "$reponame" "$contents_oid" |
| 198 | |
| 199 | rm -f a.dat |
| 200 | rm -rf .git/lfs/objects |
| 201 | |
| 202 | # We expect the server to corrupt the object's contents by inverting |
| 203 | # the case of each character. |
| 204 | inverted_contents_oid="$(calc_oid "$(invert_case "$contents")")" |
| 205 | |
| 206 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git lfs pull 2>&1 | tee pull.log |
| 207 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 208 | |
| 209 | grep "tq: starting transfer adapter" pull.log |
| 210 | grep "xfer: started custom adapter process" pull.log |
| 211 | |
| 212 | grep "downloaded file failed checks" pull.log |
| 213 | grep "has an invalid hash $inverted_contents_oid, expected $contents_oid" pull.log |
| 214 | grep "Failed to fetch some objects" pull.log |
| 215 | |
| 216 | refute_local_object "$contents_oid" |
| 217 | refute_local_object "$inverted_contents_oid" |
| 218 | |
| 219 | expected="${contents_oid:0:10} - a.dat" |
| 220 | [ "$expected" = "$(git lfs ls-files)" ] |
| 221 | |
| 222 | git lfs fsck --objects 2>&1 | tee fsck.log |
| 223 | [ 1 -eq "${PIPESTATUS[0]}" ] |
| 224 | |
| 225 | grep "objects: openError: a.dat ($contents_oid) could not be checked: .*" fsck.log |
| 226 | |
| 227 | # Test again using "git pull", which should not advance HEAD after the |
| 228 | # smudge filter reports an error. |
| 229 | git reset --hard HEAD^ |
| 230 | |
| 231 | GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git pull origin main 2>&1 | tee pull.log |
| 232 | [ 0 -ne "${PIPESTATUS[0]}" ] |
| 233 | |
| 234 | grep "tq: starting transfer adapter" pull.log |
| 235 | grep "xfer: started custom adapter process" pull.log |
| 236 | |
| 237 | grep "downloaded file failed checks" pull.log |
| 238 | grep "has an invalid hash $inverted_contents_oid, expected $contents_oid" pull.log |
| 239 | grep "Smudge error: Error downloading a.dat ($contents_oid)" pull.log |
| 240 | |
| 241 | refute_local_object "$contents_oid" |
| 242 | refute_local_object "$inverted_contents_oid" |
| 243 | |
| 244 | [ "$initial_sha" = "$(git rev-parse HEAD)" ] |
| 245 | |
| 246 | [ -z "$(git lfs ls-files)" ] |
| 247 | |
| 248 | git lfs fsck --objects 2>&1 | tee fsck.log |
| 249 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 250 | |
| 251 | grep "Git LFS fsck OK" fsck.log |
| 252 | ) |
| 253 | end_test |