From 54601c6d3450f7d31f8ce331b87cefbcde7e67b4 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 11:50:22 -0600 Subject: [PATCH 1/9] introduce calc_oid() helper for integration tests --- test/test-batch-error-handling.sh | 2 +- test/test-batch-transfer-unsupported.sh | 2 +- test/test-batch-transfer.sh | 2 +- test/test-checkout.sh | 2 +- .../test-chunked-transfer-encoding-batched.sh | 2 +- test/test-chunked-transfer-encoding.sh | 2 +- test/test-commit-delete-push.sh | 4 ++-- test/test-credentials.sh | 6 ++--- test/test-fetch.sh | 18 +++++++-------- test/test-happy-path.sh | 2 +- test/test-pre-push.sh | 6 ++--- test/test-pull.sh | 2 +- test/test-push.sh | 22 +++++++++---------- test/testhelpers.sh | 4 ++++ 14 files changed, 40 insertions(+), 36 deletions(-) diff --git a/test/test-batch-error-handling.sh b/test/test-batch-error-handling.sh index 2a80689d..54c7c46a 100755 --- a/test/test-batch-error-handling.sh +++ b/test/test-batch-error-handling.sh @@ -27,7 +27,7 @@ begin_test "batch error handling" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat diff --git a/test/test-batch-transfer-unsupported.sh b/test/test-batch-transfer-unsupported.sh index 13a389aa..c835fd81 100755 --- a/test/test-batch-transfer-unsupported.sh +++ b/test/test-batch-transfer-unsupported.sh @@ -21,7 +21,7 @@ begin_test "batch transfer unsupported on server" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat diff --git a/test/test-batch-transfer.sh b/test/test-batch-transfer.sh index d311dc1c..5430e7b7 100755 --- a/test/test-batch-transfer.sh +++ b/test/test-batch-transfer.sh @@ -27,7 +27,7 @@ begin_test "batch transfer" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat diff --git a/test/test-checkout.sh b/test/test-checkout.sh index 332c7fcb..b2c54126 100755 --- a/test/test-checkout.sh +++ b/test/test-checkout.sh @@ -16,7 +16,7 @@ begin_test "checkout" contents="something something" contentsize=19 - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") # Same content everywhere is ok, just one object in lfs db printf "$contents" > file1.dat diff --git a/test/test-chunked-transfer-encoding-batched.sh b/test/test-chunked-transfer-encoding-batched.sh index 280fe0c3..154ce9ca 100755 --- a/test/test-chunked-transfer-encoding-batched.sh +++ b/test/test-chunked-transfer-encoding-batched.sh @@ -27,7 +27,7 @@ begin_test "chunked transfer encoding batched" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat diff --git a/test/test-chunked-transfer-encoding.sh b/test/test-chunked-transfer-encoding.sh index 4632c162..147d1ead 100755 --- a/test/test-chunked-transfer-encoding.sh +++ b/test/test-chunked-transfer-encoding.sh @@ -27,7 +27,7 @@ begin_test "chunked transfer encoding" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") # Regular Git commands can be used. printf "$contents" > a.dat diff --git a/test/test-commit-delete-push.sh b/test/test-commit-delete-push.sh index 2d78aea4..6e9537c2 100755 --- a/test/test-commit-delete-push.sh +++ b/test/test-commit-delete-push.sh @@ -12,7 +12,7 @@ begin_test "commit, delete, then push" git lfs track "*.dat" - deleted_oid=$(echo "deleted" | shasum -a 256 | cut -f 1 -d " ") + deleted_oid=$(calc_oid "deleted\n") echo "deleted" > deleted.dat git add deleted.dat .gitattributes git commit -m "add deleted file" @@ -21,7 +21,7 @@ begin_test "commit, delete, then push" assert_pointer "master" "deleted.dat" "$deleted_oid" 8 - added_oid=$(echo "added" | shasum -a 256 | cut -f 1 -d " ") + added_oid=$(calc_oid "added\n") echo "added" > added.dat git add added.dat git commit -m "add file" diff --git a/test/test-credentials.sh b/test/test-credentials.sh index 4a968e77..713a129d 100755 --- a/test/test-credentials.sh +++ b/test/test-credentials.sh @@ -18,7 +18,7 @@ begin_test "credentials without useHttpPath, with bad path password" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat @@ -47,7 +47,7 @@ begin_test "credentials with useHttpPath, with wrong password" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat @@ -78,7 +78,7 @@ begin_test "credentials with useHttpPath, with correct password" # creating new branch does not re-sent any objects existing on other # remote branches anymore, generate new object, different from prev tests contents="b" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > b.dat git add b.dat diff --git a/test/test-fetch.sh b/test/test-fetch.sh index 43957e99..50ebe227 100755 --- a/test/test-fetch.sh +++ b/test/test-fetch.sh @@ -17,7 +17,7 @@ begin_test "fetch" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat @@ -43,7 +43,7 @@ begin_test "fetch" # Add a file in a different branch git checkout -b newbranch b="b" - b_oid=$(printf "$b" | shasum -a 256 | cut -f 1 -d " ") + b_oid=$(calc_oid "$b") printf "$b" > b.dat git add b.dat git commit -m "add b.dat" @@ -152,12 +152,12 @@ begin_test "fetch-recent" content3="filecontent3" content4="filecontent4" content5="filecontent5" - oid0=$(printf "$content0" | shasum -a 256 | cut -f 1 -d " ") - oid1=$(printf "$content1" | shasum -a 256 | cut -f 1 -d " ") - oid2=$(printf "$content2" | shasum -a 256 | cut -f 1 -d " ") - oid3=$(printf "$content3" | shasum -a 256 | cut -f 1 -d " ") - oid4=$(printf "$content4" | shasum -a 256 | cut -f 1 -d " ") - oid5=$(printf "$content5" | shasum -a 256 | cut -f 1 -d " ") + oid0=$(calc_oid "$content0") + oid1=$(calc_oid "$content1") + oid2=$(calc_oid "$content2") + oid3=$(calc_oid "$content3") + oid4=$(calc_oid "$content4") + oid5=$(calc_oid "$content5") echo "[ { @@ -293,7 +293,7 @@ begin_test "fetch-all" for ((a=0; a < NUMFILES ; a++)) do content[$a]="filecontent$a" - oid[$a]=$(printf "${content[$a]}" | shasum -a 256 | cut -f 1 -d " ") + oid[$a]=$(calc_oid "${content[$a]}") done echo "[ diff --git a/test/test-happy-path.sh b/test/test-happy-path.sh index 80456ae6..bab6378b 100755 --- a/test/test-happy-path.sh +++ b/test/test-happy-path.sh @@ -27,7 +27,7 @@ begin_test "happy path" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") # Regular Git commands can be used. printf "$contents" > a.dat diff --git a/test/test-pre-push.sh b/test/test-pre-push.sh index 239b5768..3ebbd689 100755 --- a/test/test-pre-push.sh +++ b/test/test-pre-push.sh @@ -204,7 +204,7 @@ begin_test "pre-push with missing pointer which is on server" clone_repo "$reponame" missing-but-on-server contents="common data" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") git lfs track "*.dat" printf "$contents" > common1.dat git add common1.dat @@ -269,7 +269,7 @@ begin_test "pre-push with missing pointer which is on server (BATCH)" clone_repo "$reponame" missing-but-on-server-batch contents="common data" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") git lfs track "*.dat" printf "$contents" > common1.dat git add common1.dat @@ -319,7 +319,7 @@ begin_test "pre-push multiple branches" for ((a=0; a < NUMFILES ; a++)) do content[$a]="filecontent$a" - oid[$a]=$(printf "${content[$a]}" | shasum -a 256 | cut -f 1 -d " ") + oid[$a]=$(calc_oid "${content[$a]}") done echo "[ diff --git a/test/test-pull.sh b/test/test-pull.sh index c7b42942..66ae31f9 100755 --- a/test/test-pull.sh +++ b/test/test-pull.sh @@ -17,7 +17,7 @@ begin_test "pull" grep "Tracking \*.dat" track.log contents="a" - contents_oid=$(printf "$contents" | shasum -a 256 | cut -f 1 -d " ") + contents_oid=$(calc_oid "$contents") printf "$contents" > a.dat git add a.dat diff --git a/test/test-push.sh b/test/test-push.sh index 55626da8..ef54c3de 100755 --- a/test/test-push.sh +++ b/test/test-push.sh @@ -56,12 +56,12 @@ push_all_setup() { content4="tagged" content5="master" extracontent="extra" - oid1=$(printf "$content1" | shasum -a 256 | cut -f 1 -d " ") - oid2=$(printf "$content2" | shasum -a 256 | cut -f 1 -d " ") - oid3=$(printf "$content3" | shasum -a 256 | cut -f 1 -d " ") - oid4=$(printf "$content4" | shasum -a 256 | cut -f 1 -d " ") - oid5=$(printf "$content5" | shasum -a 256 | cut -f 1 -d " ") - extraoid=$(printf "$extracontent" | shasum -a 256 | cut -f 1 -d " ") + oid1=$(calc_oid "$content1") + oid2=$(calc_oid "$content2") + oid3=$(calc_oid "$content3") + oid4=$(calc_oid "$content4") + oid5=$(calc_oid "$content5") + extraoid=$(calc_oid "$extracontent") # if the local repo exists, it has already been bootstrapped [ -d "push-all" ] && exit 0 @@ -369,11 +369,11 @@ begin_test "push modified files" content3="filecontent3" content4="filecontent4" content5="filecontent5" - oid1=$(printf "$content1" | shasum -a 256 | cut -f 1 -d " ") - oid2=$(printf "$content2" | shasum -a 256 | cut -f 1 -d " ") - oid3=$(printf "$content3" | shasum -a 256 | cut -f 1 -d " ") - oid4=$(printf "$content4" | shasum -a 256 | cut -f 1 -d " ") - oid5=$(printf "$content5" | shasum -a 256 | cut -f 1 -d " ") + oid1=$(calc_oid "$content1") + oid2=$(calc_oid "$content2") + oid3=$(calc_oid "$content3") + oid4=$(calc_oid "$content4") + oid5=$(calc_oid "$content5") echo "[ { diff --git a/test/testhelpers.sh b/test/testhelpers.sh index 833c4297..35e79a78 100644 --- a/test/testhelpers.sh +++ b/test/testhelpers.sh @@ -323,6 +323,10 @@ comparison_to_operator() { fi } +calc_oid() { + printf "$1" | shasum -a 256 | cut -f 1 -d " " +} + # Get a date string with an offset # Args: One or more date offsets of the form (regex) "[+-]\d+[dmyHM]" # e.g. +1d = 1 day forward from today From 2c585894d94c4672eddafca48cc7611e58a5b888 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 12:17:58 -0600 Subject: [PATCH 2/9] initial storage server tests --- test/cmd/lfstest-gitserver.go | 48 +++++++++++++++++++++++- test/test-push-failures.sh | 70 +++++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100755 test/test-push-failures.sh diff --git a/test/cmd/lfstest-gitserver.go b/test/cmd/lfstest-gitserver.go index 7b51f4eb..f25081e6 100644 --- a/test/cmd/lfstest-gitserver.go +++ b/test/cmd/lfstest-gitserver.go @@ -25,6 +25,22 @@ var ( repoDir string largeObjects = newLfsStorage() server *httptest.Server + + // maps OIDs to content strings. Both the LFS and Storage test servers below + // see OIDs. + oidHandlers map[string]string + + // These magic strings tell the test lfs server change their behavior so the + // integration tests can check those use cases. Tests will create objects with + // the magic strings as the contents. + // + // printf "status:lfs:404" > 404.dat + // + contentHandlers = []string{ + "status-batch-404", "status-batch-410", "status-batch-422", "status-batch-500", + "status-storage-404", "status-storage-410", "status-storage-422", "status-storage-500", + "status-legacy-404", "status-legacy-410", "status-legacy-422", "status-legacy-403", "status-legacy-500", + } ) func main() { @@ -263,9 +279,30 @@ func lfsBatchHandler(w http.ResponseWriter, r *http.Request, repo string) { // handles any /storage/{oid} requests func storageHandler(w http.ResponseWriter, r *http.Request) { repo := r.URL.Query().Get("r") - log.Printf("storage %s %s repo: %s\n", r.Method, r.URL, repo) + parts := strings.Split(r.URL.Path, "/") + oid := parts[len(parts)-1] + + log.Printf("storage %s %s repo: %s\n", r.Method, oid, repo) switch r.Method { case "PUT": + switch oidHandlers[oid] { + case "status-storage-403": + w.WriteHeader(403) + return + case "status-storage-404": + w.WriteHeader(404) + return + case "status-storage-410": + w.WriteHeader(410) + return + case "status-storage-422": + w.WriteHeader(422) + return + case "status-storage-500": + w.WriteHeader(500) + return + } + if testingChunkedTransferEncoding(r) { valid := false for _, value := range r.TransferEncoding { @@ -461,3 +498,12 @@ func skipIfBadAuth(w http.ResponseWriter, r *http.Request) bool { log.Printf("Bad auth: %q\n", auth) return true } + +func init() { + oidHandlers = make(map[string]string) + for _, content := range contentHandlers { + h := sha256.New() + h.Write([]byte(content)) + oidHandlers[hex.EncodeToString(h.Sum(nil))] = content + } +} diff --git a/test/test-push-failures.sh b/test/test-push-failures.sh new file mode 100755 index 00000000..3c1d3c78 --- /dev/null +++ b/test/test-push-failures.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env bash + +. "test/testlib.sh" + +push_fail_test() { + local contents="$1" + + set -e + + reponame="$(basename "$0" ".sh")-error" + setup_remote_repo "$reponame" + clone_repo "$reponame" "$reponame-$contents" + + git lfs track "*.dat" + printf "hi" > good.dat + printf "$contents" > bad.dat + git add .gitattributes good.dat bad.dat + git commit -m "welp" + + set +e + git push origin master + if [ "$?" = "0" ]; then + echo "push successful?" + exit 1 + fi + + refute_server_object "$reponame" "$(calc_oid "$contents")" + + exit 0 +} + +begin_test "push: upload file with storage 403" +( + set -e + + push_fail_test "status-storage-403" +) +end_test + +begin_test "push: upload file with storage 404" +( + set -e + + push_fail_test "status-storage-404" +) +end_test + +begin_test "push: upload file with storage 410" +( + set -e + + push_fail_test "status-storage-410" +) +end_test + +begin_test "push: upload file with storage 422" +( + set -e + + push_fail_test "status-storage-422" +) +end_test + +begin_test "push: upload file with storage 500" +( + set -e + + push_fail_test "status-storage-500" +) +end_test From 8be2dc4f107ca693fa4cc1802d0064c6b7daa51f Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 12:23:25 -0600 Subject: [PATCH 3/9] forgot to add a content handler for storage 403 responses --- test/cmd/lfstest-gitserver.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/cmd/lfstest-gitserver.go b/test/cmd/lfstest-gitserver.go index f25081e6..35818d17 100644 --- a/test/cmd/lfstest-gitserver.go +++ b/test/cmd/lfstest-gitserver.go @@ -38,7 +38,7 @@ var ( // contentHandlers = []string{ "status-batch-404", "status-batch-410", "status-batch-422", "status-batch-500", - "status-storage-404", "status-storage-410", "status-storage-422", "status-storage-500", + "status-storage-403", "status-storage-404", "status-storage-410", "status-storage-422", "status-storage-500", "status-legacy-404", "status-legacy-410", "status-legacy-422", "status-legacy-403", "status-legacy-500", } ) From a8aa41fef8351d23b402e2cdc202a8d68e05cecc Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 13:04:11 -0600 Subject: [PATCH 4/9] add more push tests for the batch and legacy APIs --- test/cmd/lfstest-gitserver.go | 45 ++++++++++-- test/test-push-failures.sh | 42 ++++++++++- test/test-push-legacy-failures.sh | 111 ++++++++++++++++++++++++++++++ 3 files changed, 192 insertions(+), 6 deletions(-) create mode 100755 test/test-push-legacy-failures.sh diff --git a/test/cmd/lfstest-gitserver.go b/test/cmd/lfstest-gitserver.go index 35818d17..c9bad0f2 100644 --- a/test/cmd/lfstest-gitserver.go +++ b/test/cmd/lfstest-gitserver.go @@ -37,7 +37,7 @@ var ( // printf "status:lfs:404" > 404.dat // contentHandlers = []string{ - "status-batch-404", "status-batch-410", "status-batch-422", "status-batch-500", + "status-batch-403", "status-batch-404", "status-batch-410", "status-batch-422", "status-batch-500", "status-storage-403", "status-storage-404", "status-storage-410", "status-storage-422", "status-storage-500", "status-legacy-404", "status-legacy-410", "status-legacy-422", "status-legacy-403", "status-legacy-500", } @@ -95,6 +95,7 @@ type lfsObject struct { Oid string `json:"oid,omitempty"` Size int64 `json:"size,omitempty"` Actions map[string]lfsLink `json:"actions,omitempty"` + Err *lfsError `json:"error,omitempty"` } type lfsLink struct { @@ -102,6 +103,11 @@ type lfsLink struct { Header map[string]string `json:"header,omitempty"` } +type lfsError struct { + Code int + Message string +} + // handles any requests with "{name}.server.git/info/lfs" in the path func lfsHandler(w http.ResponseWriter, r *http.Request) { repo, err := repoFromLfsUrl(r.URL.Path) @@ -151,12 +157,26 @@ func lfsPostHandler(w http.ResponseWriter, r *http.Request, repo string) { res := &lfsObject{ Oid: obj.Oid, Size: obj.Size, - Actions: map[string]lfsLink{ + } + + switch oidHandlers[obj.Oid] { + case "status-legacy-403": + res.Err = &lfsError{Code: 403, Message: "welp"} + case "status-legacy-404": + res.Err = &lfsError{Code: 404, Message: "welp"} + case "status-legacy-410": + res.Err = &lfsError{Code: 410, Message: "welp"} + case "status-legacy-422": + res.Err = &lfsError{Code: 422, Message: "welp"} + case "status-legacy-500": + res.Err = &lfsError{Code: 500, Message: "welp"} + default: // regular 200 response + res.Actions = map[string]lfsLink{ "upload": lfsLink{ Href: lfsUrl(repo, obj.Oid), Header: map[string]string{}, }, - }, + } } if testingChunkedTransferEncoding(r) { @@ -248,13 +268,28 @@ func lfsBatchHandler(w http.ResponseWriter, r *http.Request, repo string) { o := lfsObject{ Oid: obj.Oid, Size: obj.Size, - Actions: map[string]lfsLink{ + } + + switch oidHandlers[obj.Oid] { + case "status-batch-403": + o.Err = &lfsError{Code: 403, Message: "welp"} + case "status-batch-404": + o.Err = &lfsError{Code: 404, Message: "welp"} + case "status-batch-410": + o.Err = &lfsError{Code: 410, Message: "welp"} + case "status-batch-422": + o.Err = &lfsError{Code: 422, Message: "welp"} + case "status-batch-500": + o.Err = &lfsError{Code: 500, Message: "welp"} + default: // regular 200 response + o.Actions = map[string]lfsLink{ action: lfsLink{ Href: lfsUrl(repo, obj.Oid), Header: map[string]string{}, }, - }, + } } + if testingChunked { o.Actions[action].Header["Transfer-Encoding"] = "chunked" } diff --git a/test/test-push-failures.sh b/test/test-push-failures.sh index 3c1d3c78..2804205f 100755 --- a/test/test-push-failures.sh +++ b/test/test-push-failures.sh @@ -7,7 +7,7 @@ push_fail_test() { set -e - reponame="$(basename "$0" ".sh")-error" + local reponame="$(basename "$0" ".sh")" setup_remote_repo "$reponame" clone_repo "$reponame" "$reponame-$contents" @@ -68,3 +68,43 @@ begin_test "push: upload file with storage 500" push_fail_test "status-storage-500" ) end_test + +begin_test "push: upload file with api 403" +( + set -e + + push_fail_test "status-batch-403" +) +end_test + +begin_test "push: upload file with api 404" +( + set -e + + push_fail_test "status-batch-404" +) +end_test + +begin_test "push: upload file with api 410" +( + set -e + + push_fail_test "status-batch-410" +) +end_test + +begin_test "push: upload file with api 422" +( + set -e + + push_fail_test "status-batch-422" +) +end_test + +begin_test "push: upload file with api 500" +( + set -e + + push_fail_test "status-batch-500" +) +end_test diff --git a/test/test-push-legacy-failures.sh b/test/test-push-legacy-failures.sh new file mode 100755 index 00000000..902eb5c4 --- /dev/null +++ b/test/test-push-legacy-failures.sh @@ -0,0 +1,111 @@ +#!/usr/bin/env bash + +. "test/testlib.sh" + +push_legacy_fail_test() { + local contents="$1" + + set -e + + local reponame="$(basename "$0" ".sh")" + setup_remote_repo "$reponame" + clone_repo "$reponame" "$reponame-$contents" + git config lfs.batch false + + git lfs track "*.dat" + printf "hi" > good.dat + printf "$contents" > bad.dat + git add .gitattributes good.dat bad.dat + git commit -m "welp" + + set +e + git push origin master + if [ "$?" = "0" ]; then + echo "push successful?" + exit 1 + fi + + refute_server_object "$reponame" "$(calc_oid "$contents")" + + exit 0 +} + +begin_test "push (legacy): upload file with storage 403" +( + set -e + + push_legacy_fail_test "status-storage-403" +) +end_test + +begin_test "push (legacy): upload file with storage 404" +( + set -e + + push_legacy_fail_test "status-storage-404" +) +end_test + +begin_test "push (legacy): upload file with storage 410" +( + set -e + + push_legacy_fail_test "status-storage-410" +) +end_test + +begin_test "push (legacy): upload file with storage 422" +( + set -e + + push_legacy_fail_test "status-storage-422" +) +end_test + +begin_test "push (legacy): upload file with storage 500" +( + set -e + + push_legacy_fail_test "status-storage-500" +) +end_test + +begin_test "push (legacy): upload file with api 403" +( + set -e + + push_legacy_fail_test "status-legacy-403" +) +end_test + +begin_test "push (legacy): upload file with api 404" +( + set -e + + push_legacy_fail_test "status-legacy-404" +) +end_test + +begin_test "push (legacy): upload file with api 410" +( + set -e + + push_legacy_fail_test "status-legacy-410" +) +end_test + +begin_test "push (legacy): upload file with api 422" +( + set -e + + push_legacy_fail_test "status-legacy-422" +) +end_test + +begin_test "push (legacy): upload file with api 500" +( + set -e + + push_legacy_fail_test "status-legacy-500" +) +end_test From 0aceedf0c2b453991b9c3f32bc252eeac3b60819 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 13:22:58 -0600 Subject: [PATCH 5/9] dont share a remote repo --- test/test-push-failures.sh | 4 ++-- test/test-push-legacy-failures.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test-push-failures.sh b/test/test-push-failures.sh index 2804205f..3e666d97 100755 --- a/test/test-push-failures.sh +++ b/test/test-push-failures.sh @@ -7,9 +7,9 @@ push_fail_test() { set -e - local reponame="$(basename "$0" ".sh")" + local reponame="$(basename "$0" ".sh")-$contents" setup_remote_repo "$reponame" - clone_repo "$reponame" "$reponame-$contents" + clone_repo "$reponame" "$reponame" git lfs track "*.dat" printf "hi" > good.dat diff --git a/test/test-push-legacy-failures.sh b/test/test-push-legacy-failures.sh index 902eb5c4..0be44ad5 100755 --- a/test/test-push-legacy-failures.sh +++ b/test/test-push-legacy-failures.sh @@ -7,9 +7,9 @@ push_legacy_fail_test() { set -e - local reponame="$(basename "$0" ".sh")" + local reponame="$(basename "$0" ".sh")-$contents" setup_remote_repo "$reponame" - clone_repo "$reponame" "$reponame-$contents" + clone_repo "$reponame" "$reponame" git config lfs.batch false git lfs track "*.dat" From b3a8eabab7e4ea9fcb933e171ddb96fac3527ad6 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 13:31:05 -0600 Subject: [PATCH 6/9] update legacy test server to return http error responses instead old api doesnt have the error object on the json responses --- test/cmd/lfstest-gitserver.go | 36 +++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/test/cmd/lfstest-gitserver.go b/test/cmd/lfstest-gitserver.go index c9bad0f2..9bfca684 100644 --- a/test/cmd/lfstest-gitserver.go +++ b/test/cmd/lfstest-gitserver.go @@ -154,29 +154,33 @@ func lfsPostHandler(w http.ResponseWriter, r *http.Request, repo string) { log.Fatal(err) } + switch oidHandlers[obj.Oid] { + case "status-legacy-403": + w.WriteHeader(403) + return + case "status-legacy-404": + w.WriteHeader(404) + return + case "status-legacy-410": + w.WriteHeader(410) + return + case "status-legacy-422": + w.WriteHeader(422) + return + case "status-legacy-500": + w.WriteHeader(500) + return + } + res := &lfsObject{ Oid: obj.Oid, Size: obj.Size, - } - - switch oidHandlers[obj.Oid] { - case "status-legacy-403": - res.Err = &lfsError{Code: 403, Message: "welp"} - case "status-legacy-404": - res.Err = &lfsError{Code: 404, Message: "welp"} - case "status-legacy-410": - res.Err = &lfsError{Code: 410, Message: "welp"} - case "status-legacy-422": - res.Err = &lfsError{Code: 422, Message: "welp"} - case "status-legacy-500": - res.Err = &lfsError{Code: 500, Message: "welp"} - default: // regular 200 response - res.Actions = map[string]lfsLink{ + Actions: map[string]lfsLink{ "upload": lfsLink{ Href: lfsUrl(repo, obj.Oid), Header: map[string]string{}, }, - } + }, } if testingChunkedTransferEncoding(r) { From b85954d511855a8c2911108601e91697215e1882 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 13:40:06 -0600 Subject: [PATCH 7/9] use bash instead of shell seems to help keep the output of the parallel scripts consistent --- script/integration | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/integration b/script/integration index 0e434c53..96153a9d 100755 --- a/script/integration +++ b/script/integration @@ -58,4 +58,4 @@ fi for file in "${testfiles[@]}"; do echo "0$(cat .$(basename $file).time 2>/dev/null || true) $file" -done | sort -rnk1 | awk '{ print $2 }' | xargs -I % -P $parallel -n 1 /bin/sh -c % --batch +done | sort -rnk1 | awk '{ print $2 }' | xargs -I % -P $parallel -n 1 /bin/bash % --batch From 3671cc7f27130ecd468a04bc27c7554382d6f3fa Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 14:19:50 -0600 Subject: [PATCH 8/9] check for errors before checking for a link action --- lfs/transfer_queue.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lfs/transfer_queue.go b/lfs/transfer_queue.go index 082189c8..991f1363 100644 --- a/lfs/transfer_queue.go +++ b/lfs/transfer_queue.go @@ -224,15 +224,14 @@ func (q *TransferQueue) batchApiRoutine() { startProgress.Do(q.meter.Start) for _, o := range objects { - if _, ok := o.Rel(q.transferKind); ok { - // This object has an error - if o.Error != nil { - q.errorc <- Error(o.Error) - q.meter.Skip(o.Size) - q.wait.Done() - continue - } + if o.Error != nil { + q.errorc <- Error(o.Error) + q.meter.Skip(o.Size) + q.wait.Done() + continue + } + if _, ok := o.Rel(q.transferKind); ok { // This object needs to be transferred if transfer, ok := q.transferables[o.Oid]; ok { transfer.SetObject(o) From 9e6a5d3d6ed992a380bd6cb9c1fe8ffec4ec4035 Mon Sep 17 00:00:00 2001 From: rick Date: Mon, 21 Sep 2015 14:55:05 -0600 Subject: [PATCH 9/9] add tests for bad dns name in lfs endpoint --- test/test-push-failures.sh | 39 ++++++++++++++++++++++++++---- test/test-push-legacy-failures.sh | 40 +++++++++++++++++++++++++++---- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/test/test-push-failures.sh b/test/test-push-failures.sh index 3e666d97..e15f0083 100755 --- a/test/test-push-failures.sh +++ b/test/test-push-failures.sh @@ -2,6 +2,35 @@ . "test/testlib.sh" +begin_test "push: upload to bad dns" +( + set -e + + reponame="$(basename "$0" ".sh")-bad-dns" + setup_remote_repo "$reponame" + clone_repo "$reponame" "$reponame" + + git lfs track "*.dat" + printf "hi" > good.dat + git add .gitattributes good.dat + git commit -m "welp" + + port="$(echo "http://127.0.0.1:63378" | cut -f 3 -d ":")" + git config lfs.url "http://git-lfs-bad-dns:$port" + + set +e + GIT_TERMINAL_PROMPT=0 git push origin master + res="$?" + set -e + + refute_server_object "$reponame" "$(calc_oid "hi")" + if [ "$res" = "0" ]; then + echo "push successful?" + exit 1 + fi +) +end_test + push_fail_test() { local contents="$1" @@ -19,14 +48,14 @@ push_fail_test() { set +e git push origin master - if [ "$?" = "0" ]; then + res="$?" + set -e + + refute_server_object "$reponame" "$(calc_oid "$contents")" + if [ "$res" = "0" ]; then echo "push successful?" exit 1 fi - - refute_server_object "$reponame" "$(calc_oid "$contents")" - - exit 0 } begin_test "push: upload file with storage 403" diff --git a/test/test-push-legacy-failures.sh b/test/test-push-legacy-failures.sh index 0be44ad5..847b92f4 100755 --- a/test/test-push-legacy-failures.sh +++ b/test/test-push-legacy-failures.sh @@ -2,6 +2,36 @@ . "test/testlib.sh" +begin_test "push (legacy): upload to bad dns" +( + set -e + + reponame="$(basename "$0" ".sh")-bad-dns" + setup_remote_repo "$reponame" + clone_repo "$reponame" "$reponame" + + git lfs track "*.dat" + printf "hi" > good.dat + git add .gitattributes good.dat + git commit -m "welp" + + port="$(echo "http://127.0.0.1:63378" | cut -f 3 -d ":")" + git config lfs.batch false + git config lfs.url "http://git-lfs-bad-dns:$port" + + set +e + GIT_TERMINAL_PROMPT=0 git push origin master + res="$?" + set -e + + refute_server_object "$reponame" "$(calc_oid "hi")" + if [ "$res" = "0" ]; then + echo "push successful?" + exit 1 + fi +) +end_test + push_legacy_fail_test() { local contents="$1" @@ -20,14 +50,14 @@ push_legacy_fail_test() { set +e git push origin master - if [ "$?" = "0" ]; then + res="$?" + set -e + + refute_server_object "$reponame" "$(calc_oid "$contents")" + if [ "$res" = "0" ]; then echo "push successful?" exit 1 fi - - refute_server_object "$reponame" "$(calc_oid "$contents")" - - exit 0 } begin_test "push (legacy): upload file with storage 403"