t / t5551-http-fetch-smart.shon commit Merge branch 'sg/complete-decorate-full-not-long' (465868a)
   1#!/bin/sh
   2
   3test_description='test smart fetching over http via http-backend'
   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
  11. "$TEST_DIRECTORY"/lib-httpd.sh
  12start_httpd
  13
  14test_expect_success 'setup repository' '
  15        git config push.default matching &&
  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        ) &&
  26        git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  27        git push public master:master
  28'
  29
  30setup_askpass_helper
  31
  32cat >exp <<EOF
  33> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
  34> Accept: */*
  35> Accept-Encoding: gzip
  36> Pragma: no-cache
  37< HTTP/1.1 200 OK
  38< Pragma: no-cache
  39< Cache-Control: no-cache, max-age=0, must-revalidate
  40< Content-Type: application/x-git-upload-pack-advertisement
  41> POST /smart/repo.git/git-upload-pack HTTP/1.1
  42> Accept-Encoding: gzip
  43> Content-Type: application/x-git-upload-pack-request
  44> Accept: application/x-git-upload-pack-result
  45> Content-Length: xxx
  46< HTTP/1.1 200 OK
  47< Pragma: no-cache
  48< Cache-Control: no-cache, max-age=0, must-revalidate
  49< Content-Type: application/x-git-upload-pack-result
  50EOF
  51test_expect_success 'clone http repository' '
  52        GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
  53        test_cmp file clone/file &&
  54        tr '\''\015'\'' Q <err |
  55        sed -e "
  56                s/Q\$//
  57                /^[*] /d
  58                /^$/d
  59                /^< $/d
  60
  61                /^[^><]/{
  62                        s/^/> /
  63                }
  64
  65                /^> User-Agent: /d
  66                /^> Host: /d
  67                /^> POST /,$ {
  68                        /^> Accept: [*]\\/[*]/d
  69                }
  70                s/^> Content-Length: .*/> Content-Length: xxx/
  71                /^> 00..want /d
  72                /^> 00.*done/d
  73
  74                /^< Server: /d
  75                /^< Expires: /d
  76                /^< Date: /d
  77                /^< Content-Length: /d
  78                /^< Transfer-Encoding: /d
  79        " >act &&
  80        test_cmp exp act
  81'
  82
  83test_expect_success 'fetch changes via http' '
  84        echo content >>file &&
  85        git commit -a -m two &&
  86        git push public &&
  87        (cd clone && git pull) &&
  88        test_cmp file clone/file
  89'
  90
  91cat >exp <<EOF
  92GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  93POST /smart/repo.git/git-upload-pack HTTP/1.1 200
  94GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  95POST /smart/repo.git/git-upload-pack HTTP/1.1 200
  96EOF
  97test_expect_success 'used upload-pack service' '
  98        sed -e "
  99                s/^.* \"//
 100                s/\"//
 101                s/ [1-9][0-9]*\$//
 102                s/^GET /GET  /
 103        " >act <"$HTTPD_ROOT_PATH"/access.log &&
 104        test_cmp exp act
 105'
 106
 107test_expect_success 'follow redirects (301)' '
 108        git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
 109'
 110
 111test_expect_success 'follow redirects (302)' '
 112        git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
 113'
 114
 115test_expect_success 'redirects re-root further requests' '
 116        git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
 117'
 118
 119test_expect_success 'clone from password-protected repository' '
 120        echo two >expect &&
 121        set_askpass user@host pass@host &&
 122        git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
 123        expect_askpass both user@host &&
 124        git --git-dir=smart-auth log -1 --format=%s >actual &&
 125        test_cmp expect actual
 126'
 127
 128test_expect_success 'clone from auth-only-for-push repository' '
 129        echo two >expect &&
 130        set_askpass wrong &&
 131        git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
 132        expect_askpass none &&
 133        git --git-dir=smart-noauth log -1 --format=%s >actual &&
 134        test_cmp expect actual
 135'
 136
 137test_expect_success 'clone from auth-only-for-objects repository' '
 138        echo two >expect &&
 139        set_askpass user@host pass@host &&
 140        git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
 141        expect_askpass both user@host &&
 142        git --git-dir=half-auth log -1 --format=%s >actual &&
 143        test_cmp expect actual
 144'
 145
 146test_expect_success 'no-op half-auth fetch does not require a password' '
 147        set_askpass wrong &&
 148        git --git-dir=half-auth fetch &&
 149        expect_askpass none
 150'
 151
 152test_expect_success 'redirects send auth to new location' '
 153        set_askpass user@host pass@host &&
 154        git -c credential.useHttpPath=true \
 155          clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
 156        expect_askpass both user@host auth/smart/repo.git
 157'
 158
 159test_expect_success 'disable dumb http on server' '
 160        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 161                config http.getanyfile false
 162'
 163
 164test_expect_success 'GIT_SMART_HTTP can disable smart http' '
 165        (GIT_SMART_HTTP=0 &&
 166         export GIT_SMART_HTTP &&
 167         cd clone &&
 168         test_must_fail git fetch)
 169'
 170
 171test_expect_success 'invalid Content-Type rejected' '
 172        test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
 173        grep "not valid:" actual
 174'
 175
 176test_expect_success 'create namespaced refs' '
 177        test_commit namespaced &&
 178        git push public HEAD:refs/namespaces/ns/refs/heads/master &&
 179        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 180                symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
 181'
 182
 183test_expect_success 'smart clone respects namespace' '
 184        git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
 185        echo namespaced >expect &&
 186        git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
 187        test_cmp expect actual
 188'
 189
 190test_expect_success 'dumb clone via http-backend respects namespace' '
 191        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 192                config http.getanyfile true &&
 193        GIT_SMART_HTTP=0 git clone \
 194                "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
 195        echo namespaced >expect &&
 196        git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
 197        test_cmp expect actual
 198'
 199
 200cat >cookies.txt <<EOF
 201127.0.0.1       FALSE   /smart_cookies/ FALSE   0       othername       othervalue
 202EOF
 203cat >expect_cookies.txt <<EOF
 204
 205127.0.0.1       FALSE   /smart_cookies/ FALSE   0       othername       othervalue
 206127.0.0.1       FALSE   /smart_cookies/repo.git/info/   FALSE   0       name    value
 207EOF
 208test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
 209        git config http.cookiefile cookies.txt &&
 210        git config http.savecookies true &&
 211        git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
 212        tail -3 cookies.txt >cookies_tail.txt &&
 213        test_cmp expect_cookies.txt cookies_tail.txt
 214'
 215
 216test_expect_success 'transfer.hiderefs works over smart-http' '
 217        test_commit hidden &&
 218        test_commit visible &&
 219        git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
 220        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 221                config transfer.hiderefs refs/heads/a &&
 222        git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
 223        test_must_fail git -C hidden.git rev-parse --verify a &&
 224        git -C hidden.git rev-parse --verify b
 225'
 226
 227test_expect_success 'create 2,000 tags in the repo' '
 228        (
 229        cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 230        for i in $(test_seq 2000)
 231        do
 232                echo "commit refs/heads/too-many-refs"
 233                echo "mark :$i"
 234                echo "committer git <git@example.com> $i +0000"
 235                echo "data 0"
 236                echo "M 644 inline bla.txt"
 237                echo "data 4"
 238                echo "bla"
 239                # make every commit dangling by always
 240                # rewinding the branch after each commit
 241                echo "reset refs/heads/too-many-refs"
 242                echo "from :1"
 243        done | git fast-import --export-marks=marks &&
 244
 245        # now assign tags to all the dangling commits we created above
 246        tag=$(perl -e "print \"bla\" x 30") &&
 247        sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
 248        )
 249'
 250
 251test_expect_success CMDLINE_LIMIT \
 252        'clone the 2,000 tag repo to check OS command line overflow' '
 253        run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
 254        (
 255                cd too-many-refs &&
 256                git for-each-ref refs/tags >actual &&
 257                test_line_count = 2000 actual
 258        )
 259'
 260
 261test_expect_success 'large fetch-pack requests can be split across POSTs' '
 262        GIT_CURL_VERBOSE=1 git -c http.postbuffer=65536 \
 263                clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
 264        grep "^> POST" err >posts &&
 265        test_line_count = 2 posts
 266'
 267
 268stop_httpd
 269test_done