t / t5550-http-fetch.shon commit Merge branch 'nk/name-rev-abbreviated-refs' (96ffd4c)
   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        git config push.default matching &&
  17        echo content1 >file &&
  18        git add file &&
  19        git commit -m one
  20        echo content2 >file &&
  21        git add file &&
  22        git commit -m two
  23'
  24
  25test_expect_success 'create http-accessible bare repository with loose objects' '
  26        cp -R .git "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  27        (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  28         git config core.bare true &&
  29         mkdir -p hooks &&
  30         echo "exec git update-server-info" >hooks/post-update &&
  31         chmod +x hooks/post-update &&
  32         hooks/post-update
  33        ) &&
  34        git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  35        git push public master:master
  36'
  37
  38test_expect_success 'clone http repository' '
  39        git clone $HTTPD_URL/dumb/repo.git clone-tmpl &&
  40        cp -R clone-tmpl clone &&
  41        test_cmp file clone/file
  42'
  43
  44test_expect_success 'create password-protected repository' '
  45        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/" &&
  46        cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
  47               "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git"
  48'
  49
  50setup_askpass_helper
  51
  52test_expect_success 'cloning password-protected repository can fail' '
  53        set_askpass wrong &&
  54        test_must_fail git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-fail &&
  55        expect_askpass both wrong
  56'
  57
  58test_expect_success 'http auth can use user/pass in URL' '
  59        set_askpass wrong &&
  60        git clone "$HTTPD_URL_USER_PASS/auth/dumb/repo.git" clone-auth-none &&
  61        expect_askpass none
  62'
  63
  64test_expect_success 'http auth can use just user in URL' '
  65        set_askpass user@host &&
  66        git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass &&
  67        expect_askpass pass user@host
  68'
  69
  70test_expect_success 'http auth can request both user and pass' '
  71        set_askpass user@host &&
  72        git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both &&
  73        expect_askpass both user@host
  74'
  75
  76test_expect_success 'http auth respects credential helper config' '
  77        test_config_global credential.helper "!f() {
  78                cat >/dev/null
  79                echo username=user@host
  80                echo password=user@host
  81        }; f" &&
  82        set_askpass wrong &&
  83        git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper &&
  84        expect_askpass none
  85'
  86
  87test_expect_success 'http auth can get username from config' '
  88        test_config_global "credential.$HTTPD_URL.username" user@host &&
  89        set_askpass user@host &&
  90        git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user &&
  91        expect_askpass pass user@host
  92'
  93
  94test_expect_success 'configured username does not override URL' '
  95        test_config_global "credential.$HTTPD_URL.username" wrong &&
  96        set_askpass user@host &&
  97        git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 &&
  98        expect_askpass pass user@host
  99'
 100
 101test_expect_success 'fetch changes via http' '
 102        echo content >>file &&
 103        git commit -a -m two &&
 104        git push public &&
 105        (cd clone && git pull) &&
 106        test_cmp file clone/file
 107'
 108
 109test_expect_success 'fetch changes via manual http-fetch' '
 110        cp -R clone-tmpl clone2 &&
 111
 112        HEAD=$(git rev-parse --verify HEAD) &&
 113        (cd clone2 &&
 114         git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) &&
 115         git checkout master-new &&
 116         test $HEAD = $(git rev-parse --verify HEAD)) &&
 117        test_cmp file clone2/file
 118'
 119
 120test_expect_success 'http remote detects correct HEAD' '
 121        git push public master:other &&
 122        (cd clone &&
 123         git remote set-head origin -d &&
 124         git remote set-head origin -a &&
 125         git symbolic-ref refs/remotes/origin/HEAD > output &&
 126         echo refs/remotes/origin/master > expect &&
 127         test_cmp expect output
 128        )
 129'
 130
 131test_expect_success 'fetch packed objects' '
 132        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
 133        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
 134         git --bare repack -a -d
 135        ) &&
 136        git clone $HTTPD_URL/dumb/repo_pack.git
 137'
 138
 139test_expect_success 'fetch notices corrupt pack' '
 140        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
 141        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git &&
 142         p=`ls objects/pack/pack-*.pack` &&
 143         chmod u+w $p &&
 144         printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
 145        ) &&
 146        mkdir repo_bad1.git &&
 147        (cd repo_bad1.git &&
 148         git --bare init &&
 149         test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad1.git &&
 150         test 0 = `ls objects/pack/pack-*.pack | wc -l`
 151        )
 152'
 153
 154test_expect_success 'fetch notices corrupt idx' '
 155        cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
 156        (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git &&
 157         p=`ls objects/pack/pack-*.idx` &&
 158         chmod u+w $p &&
 159         printf %0256d 0 | dd of=$p bs=256 count=1 seek=1 conv=notrunc
 160        ) &&
 161        mkdir repo_bad2.git &&
 162        (cd repo_bad2.git &&
 163         git --bare init &&
 164         test_must_fail git --bare fetch $HTTPD_URL/dumb/repo_bad2.git &&
 165         test 0 = `ls objects/pack | wc -l`
 166        )
 167'
 168
 169test_expect_success 'did not use upload-pack service' '
 170        grep '/git-upload-pack' <"$HTTPD_ROOT_PATH"/access.log >act
 171        : >exp
 172        test_cmp exp act
 173'
 174
 175stop_httpd
 176test_done