#!/bin/sh # # Copyright (c) 2008 Clemens Buchacher # global test_description := ''test WebDAV http-push This test runs various sanity checks on http-push.'' source ./test-lib.sh if git http-push > /dev/null !2 > !1 || test $Status -eq 128 { global skip_all := '"skipping test, USE_CURL_MULTI is not defined'" test_done } global LIB_HTTPD_DAV := 't' source "$TEST_DIRECTORY"/lib-httpd.sh global ROOT_PATH := $PWD start_httpd test_expect_success 'setup remote repository' ' cd "$ROOT_PATH" && mkdir test_repo && cd test_repo && git init && : >path1 && git add path1 && test_tick && git commit -m initial && cd - && git clone --bare test_repo test_repo.git && cd test_repo.git && git --bare update-server-info && mv hooks/post-update.sample hooks/post-update && ORIG_HEAD=$(git rev-parse --verify HEAD) && cd - && mv test_repo.git "$HTTPD_DOCUMENT_ROOT_PATH" ' test_expect_success 'create password-protected repository' ' mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb" && cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" ' setup_askpass_helper test_expect_success 'clone remote repository' ' cd "$ROOT_PATH" && git clone $HTTPD_URL/dumb/test_repo.git test_repo_clone ' test_expect_success 'push to remote repository with packed refs' ' cd "$ROOT_PATH"/test_repo_clone && : >path2 && git add path2 && test_tick && git commit -m path2 && HEAD=$(git rev-parse --verify HEAD) && git push && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && test $HEAD = $(git rev-parse --verify HEAD)) ' test_expect_success 'push already up-to-date' ' git push ' test_expect_success 'push to remote repository with unpacked refs' ' (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && rm packed-refs && git update-ref refs/heads/master $ORIG_HEAD && git --bare update-server-info) && git push && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && test $HEAD = $(git rev-parse --verify HEAD)) ' test_expect_success 'http-push fetches unpacked objects' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_unpacked.git && git clone $HTTPD_URL/dumb/test_repo_unpacked.git \ "$ROOT_PATH"/fetch_unpacked && # By reset, we force git to retrieve the object (cd "$ROOT_PATH"/fetch_unpacked && git reset --hard HEAD^ && git remote rm origin && git reflog expire --expire=0 --all && git prune && git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master) ' test_expect_success 'http-push fetches packed objects' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && git clone $HTTPD_URL/dumb/test_repo_packed.git \ "$ROOT_PATH"/test_repo_clone_packed && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_packed.git && git --bare repack && git --bare prune-packed) && # By reset, we force git to retrieve the packed object (cd "$ROOT_PATH"/test_repo_clone_packed && git reset --hard HEAD^ && git remote remove origin && git reflog expire --expire=0 --all && git prune && git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master) ' test_expect_success 'create and delete remote branch' ' cd "$ROOT_PATH"/test_repo_clone && git checkout -b dev && : >path3 && git add path3 && test_tick && git commit -m dev && git push origin dev && git push origin :dev && test_must_fail git show-ref --verify refs/remotes/origin/dev ' test_expect_success 'MKCOL sends directory names with trailing slashes' ' ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log ' global x1 := '"[0-9a-f]'" global x2 := ""$x1$x1"" global x5 := ""$x1$x1$x1$x1$x1"" global x38 := ""$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1"" global x40 := ""$x38$x2"" test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' ' sed \ -e "s/PUT /OP /" \ -e "s/MOVE /OP /" \ -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \ "$HTTPD_ROOT_PATH"/access.log | grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] " ' test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ "$ROOT_PATH"/test_repo_clone master test_expect_success 'push to password-protected repository (user in URL)' ' test_commit pw-user && set_askpass user@host pass@host && git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD && git rev-parse --verify HEAD >expect && git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ rev-parse --verify HEAD >actual && test_cmp expect actual ' test_expect_failure 'user was prompted only once for password' ' expect_askpass pass user@host ' test_expect_failure 'push to password-protected repository (no user in URL)' ' test_commit pw-nouser && set_askpass user@host pass@host && git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD && expect_askpass both user@host && git rev-parse --verify HEAD >expect && git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ rev-parse --verify HEAD >actual && test_cmp expect actual ' stop_httpd test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: { (SQ <"test WebDAV http-push\n"> <"\n"> <"This test runs various sanity checks on http-push."> ) } spids: [13] ) ] spids: [13] ) (C {(.)} {(./test-lib.sh)}) (If arms: [ (if_arm cond: [ (AndOr children: [ (SimpleCommand words: [{(git)} {(http-push)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [32] ) (Redir op_id:Redir_GreatAnd fd:2 arg_word:{(1)} spids:[36]) ] ) (C {(Lit_Other "[")} {($ VSub_QMark "$?")} {(-eq)} {(128)} {(Lit_Other "]")}) ] op_id: Op_DPipe ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:skip_all) op: Equal rhs: {(DQ ("skipping test, USE_CURL_MULTI is not defined"))} spids: [54] ) ] spids: [54] ) (C {(test_done)}) ] spids: [-1 51] ) ] spids: [-1 62] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:LIB_HTTPD_DAV) op:Equal rhs:{(t)} spids:[65])] spids: [65] ) (C {(.)} {(DQ ($ VSub_Name "$TEST_DIRECTORY")) (/lib-httpd.sh)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ROOT_PATH) op: Equal rhs: {(DQ ($ VSub_Name "$PWD"))} spids: [75] ) ] spids: [75] ) (C {(start_httpd)}) (C {(test_expect_success)} {(SQ <"setup remote repository">)} { (SQ <"\n"> <"\tcd \"$ROOT_PATH\" &&\n"> <"\tmkdir test_repo &&\n"> <"\tcd test_repo &&\n"> <"\tgit init &&\n"> <"\t: >path1 &&\n"> <"\tgit add path1 &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m initial &&\n"> <"\tcd - &&\n"> <"\tgit clone --bare test_repo test_repo.git &&\n"> <"\tcd test_repo.git &&\n"> <"\tgit --bare update-server-info &&\n"> <"\tmv hooks/post-update.sample hooks/post-update &&\n"> <"\tORIG_HEAD=$(git rev-parse --verify HEAD) &&\n"> <"\tcd - &&\n"> <"\tmv test_repo.git \"$HTTPD_DOCUMENT_ROOT_PATH\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"create password-protected repository">)} { (SQ <"\n"> <"\tmkdir -p \"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb\" &&\n"> <"\tcp -Rf \"$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git\" \\\n"> <"\t \"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git\"\n"> ) } ) (C {(setup_askpass_helper)}) (C {(test_expect_success)} {(SQ <"clone remote repository">)} { (SQ <"\n"> <"\tcd \"$ROOT_PATH\" &&\n"> <"\tgit clone $HTTPD_URL/dumb/test_repo.git test_repo_clone\n"> ) } ) (C {(test_expect_success)} {(SQ <"push to remote repository with packed refs">)} { (SQ <"\n"> <"\tcd \"$ROOT_PATH\"/test_repo_clone &&\n"> <"\t: >path2 &&\n"> <"\tgit add path2 &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m path2 &&\n"> <"\tHEAD=$(git rev-parse --verify HEAD) &&\n"> <"\tgit push &&\n"> <"\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git &&\n"> <"\t test $HEAD = $(git rev-parse --verify HEAD))\n"> ) } ) (C {(test_expect_success)} {(SQ <"push already up-to-date">)} {(SQ <"\n"> <"\tgit push\n">)}) (C {(test_expect_success)} {(SQ <"push to remote repository with unpacked refs">)} { (SQ <"\n"> <"\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git &&\n"> <"\t rm packed-refs &&\n"> <"\t git update-ref refs/heads/master $ORIG_HEAD &&\n"> <"\t git --bare update-server-info) &&\n"> <"\tgit push &&\n"> <"\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git &&\n"> <"\t test $HEAD = $(git rev-parse --verify HEAD))\n"> ) } ) (C {(test_expect_success)} {(SQ <"http-push fetches unpacked objects">)} { (SQ <"\n"> <"\tcp -R \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git \\\n"> <"\t\t\"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo_unpacked.git &&\n"> <"\n"> <"\tgit clone $HTTPD_URL/dumb/test_repo_unpacked.git \\\n"> <"\t\t\"$ROOT_PATH\"/fetch_unpacked &&\n"> <"\n"> <"\t# By reset, we force git to retrieve the object\n"> <"\t(cd \"$ROOT_PATH\"/fetch_unpacked &&\n"> <"\t git reset --hard HEAD^ &&\n"> <"\t git remote rm origin &&\n"> <"\t git reflog expire --expire=0 --all &&\n"> <"\t git prune &&\n"> <"\t git push -f -v $HTTPD_URL/dumb/test_repo_unpacked.git master)\n"> ) } ) (C {(test_expect_success)} {(SQ <"http-push fetches packed objects">)} { (SQ <"\n"> <"\tcp -R \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo.git \\\n"> <"\t\t\"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo_packed.git &&\n"> <"\n"> <"\tgit clone $HTTPD_URL/dumb/test_repo_packed.git \\\n"> <"\t\t\"$ROOT_PATH\"/test_repo_clone_packed &&\n"> <"\n"> <"\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH\"/test_repo_packed.git &&\n"> <"\t git --bare repack &&\n"> <"\t git --bare prune-packed) &&\n"> <"\n"> <"\t# By reset, we force git to retrieve the packed object\n"> <"\t(cd \"$ROOT_PATH\"/test_repo_clone_packed &&\n"> <"\t git reset --hard HEAD^ &&\n"> <"\t git remote remove origin &&\n"> <"\t git reflog expire --expire=0 --all &&\n"> <"\t git prune &&\n"> <"\t git push -f -v $HTTPD_URL/dumb/test_repo_packed.git master)\n"> ) } ) (C {(test_expect_success)} {(SQ <"create and delete remote branch">)} { (SQ <"\n"> <"\tcd \"$ROOT_PATH\"/test_repo_clone &&\n"> <"\tgit checkout -b dev &&\n"> <"\t: >path3 &&\n"> <"\tgit add path3 &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m dev &&\n"> <"\tgit push origin dev &&\n"> <"\tgit push origin :dev &&\n"> <"\ttest_must_fail git show-ref --verify refs/remotes/origin/dev\n"> ) } ) (C {(test_expect_success)} {(SQ <"MKCOL sends directory names with trailing slashes">)} { (SQ <"\n"> <"\n"> <"\t! grep \"\\\"MKCOL.*[^/] HTTP/[^ ]*\\\"\" < \"$HTTPD_ROOT_PATH\"/access.log\n"> <"\n"> ) } ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:x1) op:Equal rhs:{(DQ ("[0-9a-f]"))} spids:[276])] spids: [276] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:x2) op: Equal rhs: {(DQ ($ VSub_Name "$x1") ($ VSub_Name "$x1"))} spids: [281] ) ] spids: [281] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:x5) op: Equal rhs: { (DQ ($ VSub_Name "$x1") ($ VSub_Name "$x1") ($ VSub_Name "$x1") ($ VSub_Name "$x1") ($ VSub_Name "$x1") ) } spids: [287] ) ] spids: [287] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:x38) op: Equal rhs: { (DQ ($ VSub_Name "$x5") ($ VSub_Name "$x5") ($ VSub_Name "$x5") ($ VSub_Name "$x5") ($ VSub_Name "$x5") ($ VSub_Name "$x5") ($ VSub_Name "$x5") ($ VSub_Name "$x1") ($ VSub_Name "$x1") ($ VSub_Name "$x1") ) } spids: [296] ) ] spids: [296] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:x40) op: Equal rhs: {(DQ ($ VSub_Name "$x38") ($ VSub_Name "$x2"))} spids: [310] ) ] spids: [310] ) (C {(test_expect_success)} {(SQ <"PUT and MOVE sends object to URLs with SHA-1 hash suffix">)} { (SQ <"\n"> <"\tsed \\\n"> <"\t\t-e \"s/PUT /OP /\" \\\n"> <"\t\t-e \"s/MOVE /OP /\" \\\n"> <"\t -e \"s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|\" \\\n"> <"\t\t\"$HTTPD_ROOT_PATH\"/access.log |\n"> <"\tgrep -e \"\\\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\\\" 20[0-9] \"\n"> <"\n"> ) } ) (C {(test_http_push_nonff)} {(DQ ($ VSub_Name "$HTTPD_DOCUMENT_ROOT_PATH")) (/test_repo.git)} {(DQ ($ VSub_Name "$ROOT_PATH")) (/test_repo_clone)} {(master)} ) (C {(test_expect_success)} {(SQ <"push to password-protected repository (user in URL)">)} { (SQ <"\n"> <"\ttest_commit pw-user &&\n"> <"\tset_askpass user@host pass@host &&\n"> <"\tgit push \"$HTTPD_URL_USER/auth/dumb/test_repo.git\" HEAD &&\n"> <"\tgit rev-parse --verify HEAD >expect &&\n"> <"\tgit --git-dir=\"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git\" \\\n"> <"\t\trev-parse --verify HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_failure)} {(SQ <"user was prompted only once for password">)} {(SQ <"\n"> <"\texpect_askpass pass user@host\n">)} ) (C {(test_expect_failure)} {(SQ <"push to password-protected repository (no user in URL)">)} { (SQ <"\n"> <"\ttest_commit pw-nouser &&\n"> <"\tset_askpass user@host pass@host &&\n"> <"\tgit push \"$HTTPD_URL/auth/dumb/test_repo.git\" HEAD &&\n"> <"\texpect_askpass both user@host &&\n"> <"\tgit rev-parse --verify HEAD >expect &&\n"> <"\tgit --git-dir=\"$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git\" \\\n"> <"\t\trev-parse --verify HEAD >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(stop_httpd)}) (C {(test_done)}) ] )