git-lfs/t/t-resume-tus.sh
brian m. carlson b2ddccd90d t: avoid using shell variables in printf's first argument
The printf(1) command, like it's C cousin, takes a format string as its
first argument.  If a shell variable is passed as the first argument, it
will be interpreted as a format string; this can lead to surprising
behavior and can cause the test suite to fail if we accidentally insert
a format string character into the variable.

Modify all the places in the individual tests that we use a plain quoted
variable as the format string by running the following Ruby one-liner:

  ruby -i -pe '$_.gsub!(/printf "\$/, %q(printf "%s" "$))' t/t-*.sh

Avoid modifying the test helpers, as there are places (such as calc_oid)
where we want to pass text containing escapes (such as "\n") and have
those be properly interpreted by printf(1).
2018-09-10 14:57:10 +00:00

76 lines
2.2 KiB
Bash
Executable File

#!/usr/bin/env bash
. "$(dirname "$0")/testlib.sh"
begin_test "tus-upload-uninterrupted"
(
set -e
# this repo name is the indicator to the server to use tus
reponame="test-tus-upload"
setup_remote_repo "$reponame"
clone_repo "$reponame" $reponame
git config lfs.tustransfers true
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
contents="send-verify-action"
contents_oid=$(calc_oid "$contents")
printf "%s" "$contents" > a.dat
git add a.dat
git add .gitattributes
git commit -m "add a.dat" 2>&1 | tee commit.log
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin master 2>&1 | tee pushtus.log
grep "xfer: tus.io uploading" pushtus.log
assert_server_object "$reponame" "$contents_oid"
)
end_test
begin_test "tus-upload-interrupted-resume"
(
set -e
# this repo name is the indicator to the server to use tus, AND to
# interrupt the upload part way
reponame="test-tus-upload-interrupt"
setup_remote_repo "$reponame"
clone_repo "$reponame" $reponame
git config lfs.tustransfers true
git lfs track "*.dat" 2>&1 | tee track.log
grep "Tracking \"\*.dat\"" track.log
contents_verify="send-verify-action"
contents_verify_oid="$(calc_oid "$contents_verify")"
# this string announces to server that we want it to abort the download part
# way, but reject the Range: header and fall back on re-downloading instead
contents="234587134187634598o634857619384765b747qcvtuedvoaicwtvseudtvcoqi7280r7qvow4i7r8c46pr9q6v9pri6ioq2r8"
contents_oid=$(calc_oid "$contents")
printf "%s" "$contents" > a.dat
printf "%s" "$contents_verify" > verify.dat
git add a.dat verify.dat
git add .gitattributes
git commit -m "add a.dat, verify.dat" 2>&1 | tee commit.log
GIT_TRACE=1 GIT_TRANSFER_TRACE=1 git push origin master 2>&1 | tee pushtus_resume.log
# first attempt will start from the beginning
grep "xfer: tus.io uploading" pushtus_resume.log
grep "HTTP: 500" pushtus_resume.log
# that will have failed but retry on 500 will resume it
grep "xfer: tus.io resuming" pushtus_resume.log
grep "HTTP: 204" pushtus_resume.log
# should have completed in the end
assert_server_object "$reponame" "$contents_oid"
assert_server_object "$reponame" "$contents_verify_oid"
)
end_test