t / t5550-http-fetch.shon commit Git 1.7.8.1 (2ce0edc)
   1#!/bin/sh
   2
   3test_description='test dumb fetching over http via static file'
   4. ./test-lib.sh
   5
   6if test -n "$NO_CURL"; then
   7        skip_all='skipping test, git built without http support'
   8        test_done
   9fi
  10
  11LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'}
  12. "$TEST_DIRECTORY"/lib-httpd.sh
  13start_httpd
  14
  15test_expect_success 'setup repository' '
  16        echo content >file &&
  17        git add file &&
  18        git commit -m one
  19'
  20
  21test_expect_success 'create http-accessible bare repository' '
  22        mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  23        (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  24         git --bare init &&
  25         echo "exec git update-server-info" >hooks/post-update &&
  26         chmod +x hooks/post-update
  27        ) &&
  28        git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  29        git push public master:master
  30'
  31
  32test_expect_success 'clone http repository' '
  33        git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
  34        cp -R clone-tmpl clone &&
  35        test_cmp file clone/file
  36'
  37
  38test_expect_success 'create password-protected repository' '
  39        mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" &&
  40        cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
  41               "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git"
  42'
  43
  44test_expect_success 'setup askpass helpers' '
  45        cat >askpass <<-EOF &&
  46        #!/bin/sh
  47        echo >>"$PWD/askpass-query" "askpass: \$*" &&
  48        cat "$PWD/askpass-response"
  49        EOF
  50        chmod +x askpass &&
  51        GIT_ASKPASS="$PWD/askpass" &&
  52        export GIT_ASKPASS &&
  53        >askpass-expect-none &&
  54        echo "askpass: Password for '\''$HTTPD_DEST'\'': " >askpass-expect-pass &&
  55        { echo "askpass: Username for '\''$HTTPD_DEST'\'': " &&
  56          cat askpass-expect-pass
  57        } >askpass-expect-both
  58'
  59
  60test_expect_success 'cloning password-protected repository can fail' '
  61        >askpass-query &&
  62        echo wrong >askpass-response &&
  63        test_must_fail git clone "$HTTPD_URL/auth/repo.git" clone-auth-fail &&
  64        test_cmp askpass-expect-both askpass-query
  65'
  66
  67test_expect_success 'http auth can use user/pass in URL' '
  68        >askpass-query &&
  69        echo wrong >askpass-reponse &&
  70        git clone "$HTTPD_URL_USER_PASS/auth/repo.git" clone-auth-none &&
  71        test_cmp askpass-expect-none askpass-query
  72'
  73
  74test_expect_success 'http auth can use just user in URL' '
  75        >askpass-query &&
  76        echo user@host >askpass-response &&
  77        git clone "$HTTPD_URL_USER/auth/repo.git" clone-auth-pass &&
  78        test_cmp askpass-expect-pass askpass-query
  79'
  80
  81test_expect_success 'http auth can request both user and pass' '
  82        >askpass-query &&
  83        echo user@host >askpass-response &&
  84        git clone "$HTTPD_URL/auth/repo.git" clone-auth-both &&
  85        test_cmp askpass-expect-both askpass-query
  86'
  87
  88test_expect_success 'fetch changes via http' '
  89        echo content >>file &&
  90        git commit -a -m two &&
  91        git push public &&
  92        (cd clone && git pull) &&
  93        test_cmp file clone/file
  94'
  95
  96test_expect_success 'fetch changes via manual http-fetch' '
  97        cp -R clone-tmpl clone2 &&
  98
  99        HEAD=$(git rev-parse --verify HEAD) &&
 100        (cd clone2 &&
 101         git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
 102         git checkout master-new &&
 103         test $HEAD = $(git rev-parse --verify HEAD)) &&
 104        test_cmp file clone2/file
 105'
 106
 107test_expect_success 'http remote detects correct HEAD' '
 108        git push public master:other &&
 109        (cd clone &&
 110         git remote set-head origin -d &&
 111         git remote set-head origin -a &&
 112         git symbolic-ref refs/remotes/origin/HEAD > output &&
 113         echo refs/remotes/origin/master > expect &&
 114         test_cmp expect output
 115        )
 116'
 117
 118test_expect_success 'fetch packed objects' '
 119        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
 120        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
 121         git --bare repack &&
 122         git --bare prune-packed
 123        ) &&
 124        git clone $HTTPD_URL/dumb/repo_pack.git
 125'
 126
 127test_expect_success 'fetch notices corrupt pack' '
 128        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
 129        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
 130         p=`ls objects/pack/pack-*.pack` &&
 131         chmod u+w $p &&
 132         printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
 133        ) &&
 134        mkdir repo_bad1.git &&
 135        (cd repo_bad1.git &&
 136         git --bare init &&
 137         test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
 138         test 0 = `ls objects/pack/pack-*.pack | wc -l`
 139        )
 140'
 141
 142test_expect_success 'fetch notices corrupt idx' '
 143        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
 144        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
 145         p=`ls objects/pack/pack-*.idx` &&
 146         chmod u+w $p &&
 147         printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
 148        ) &&
 149        mkdir repo_bad2.git &&
 150        (cd repo_bad2.git &&
 151         git --bare init &&
 152         test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
 153         test 0 = `ls objects/pack | wc -l`
 154        )
 155'
 156
 157test_expect_success 'did not use upload-pack service' '
 158        grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act
 159        : >exp
 160        test_cmp exp act
 161'
 162
 163stop_httpd
 164test_done