t / t5551-http-fetch-smart.shon commit checkout.h: wrap the arguments to unique_tracking_name() (17b44ae)
   1#!/bin/sh
   2
   3test_description='test smart fetching over http via http-backend'
   4. ./test-lib.sh
   5. "$TEST_DIRECTORY"/lib-httpd.sh
   6start_httpd
   7
   8test_expect_success 'setup repository' '
   9        git config push.default matching &&
  10        echo content >file &&
  11        git add file &&
  12        git commit -m one
  13'
  14
  15test_expect_success 'create http-accessible bare repository' '
  16        mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  17        (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  18         git --bare init
  19        ) &&
  20        git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  21        git push public master:master
  22'
  23
  24setup_askpass_helper
  25
  26cat >exp <<EOF
  27> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
  28> Accept: */*
  29> Accept-Encoding: ENCODINGS
  30> Pragma: no-cache
  31< HTTP/1.1 200 OK
  32< Pragma: no-cache
  33< Cache-Control: no-cache, max-age=0, must-revalidate
  34< Content-Type: application/x-git-upload-pack-advertisement
  35> POST /smart/repo.git/git-upload-pack HTTP/1.1
  36> Accept-Encoding: ENCODINGS
  37> Content-Type: application/x-git-upload-pack-request
  38> Accept: application/x-git-upload-pack-result
  39> Content-Length: xxx
  40< HTTP/1.1 200 OK
  41< Pragma: no-cache
  42< Cache-Control: no-cache, max-age=0, must-revalidate
  43< Content-Type: application/x-git-upload-pack-result
  44EOF
  45test_expect_success 'clone http repository' '
  46        GIT_TRACE_CURL=true git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
  47        test_cmp file clone/file &&
  48        tr '\''\015'\'' Q <err |
  49        sed -e "
  50                s/Q\$//
  51                /^[*] /d
  52                /^== Info:/d
  53                /^=> Send header, /d
  54                /^=> Send header:$/d
  55                /^<= Recv header, /d
  56                /^<= Recv header:$/d
  57                s/=> Send header: //
  58                s/= Recv header://
  59                /^<= Recv data/d
  60                /^=> Send data/d
  61                /^$/d
  62                /^< $/d
  63
  64                /^[^><]/{
  65                        s/^/> /
  66                }
  67
  68                /^> User-Agent: /d
  69                /^> Host: /d
  70                /^> POST /,$ {
  71                        /^> Accept: [*]\\/[*]/d
  72                }
  73                s/^> Content-Length: .*/> Content-Length: xxx/
  74                /^> 00..want /d
  75                /^> 00.*done/d
  76
  77                /^< Server: /d
  78                /^< Expires: /d
  79                /^< Date: /d
  80                /^< Content-Length: /d
  81                /^< Transfer-Encoding: /d
  82        " >actual &&
  83        sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
  84                        actual >actual.smudged &&
  85        test_cmp exp actual.smudged &&
  86
  87        grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
  88        test_line_count = 2 actual.gzip
  89'
  90
  91test_expect_success 'fetch changes via http' '
  92        echo content >>file &&
  93        git commit -a -m two &&
  94        git push public &&
  95        (cd clone && git pull) &&
  96        test_cmp file clone/file
  97'
  98
  99cat >exp <<EOF
 100GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
 101POST /smart/repo.git/git-upload-pack HTTP/1.1 200
 102GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
 103POST /smart/repo.git/git-upload-pack HTTP/1.1 200
 104EOF
 105test_expect_success 'used upload-pack service' '
 106        sed -e "
 107                s/^.* \"//
 108                s/\"//
 109                s/ [1-9][0-9]*\$//
 110                s/^GET /GET  /
 111        " >act <"$HTTPD_ROOT_PATH"/access.log &&
 112        test_cmp exp act
 113'
 114
 115test_expect_success 'follow redirects (301)' '
 116        git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
 117'
 118
 119test_expect_success 'follow redirects (302)' '
 120        git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
 121'
 122
 123test_expect_success 'redirects re-root further requests' '
 124        git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited
 125'
 126
 127test_expect_success 're-rooting dies on insane schemes' '
 128        test_must_fail git clone $HTTPD_URL/insane-redir/repo.git insane
 129'
 130
 131test_expect_success 'clone from password-protected repository' '
 132        echo two >expect &&
 133        set_askpass user@host pass@host &&
 134        git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
 135        expect_askpass both user@host &&
 136        git --git-dir=smart-auth log -1 --format=%s >actual &&
 137        test_cmp expect actual
 138'
 139
 140test_expect_success 'clone from auth-only-for-push repository' '
 141        echo two >expect &&
 142        set_askpass wrong &&
 143        git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
 144        expect_askpass none &&
 145        git --git-dir=smart-noauth log -1 --format=%s >actual &&
 146        test_cmp expect actual
 147'
 148
 149test_expect_success 'clone from auth-only-for-objects repository' '
 150        echo two >expect &&
 151        set_askpass user@host pass@host &&
 152        git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
 153        expect_askpass both user@host &&
 154        git --git-dir=half-auth log -1 --format=%s >actual &&
 155        test_cmp expect actual
 156'
 157
 158test_expect_success 'no-op half-auth fetch does not require a password' '
 159        set_askpass wrong &&
 160        git --git-dir=half-auth fetch &&
 161        expect_askpass none
 162'
 163
 164test_expect_success 'redirects send auth to new location' '
 165        set_askpass user@host pass@host &&
 166        git -c credential.useHttpPath=true \
 167          clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth &&
 168        expect_askpass both user@host auth/smart/repo.git
 169'
 170
 171test_expect_success 'disable dumb http on server' '
 172        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 173                config http.getanyfile false
 174'
 175
 176test_expect_success 'GIT_SMART_HTTP can disable smart http' '
 177        (GIT_SMART_HTTP=0 &&
 178         export GIT_SMART_HTTP &&
 179         cd clone &&
 180         test_must_fail git fetch)
 181'
 182
 183test_expect_success 'invalid Content-Type rejected' '
 184        test_must_fail git clone $HTTPD_URL/broken_smart/repo.git 2>actual &&
 185        grep "not valid:" actual
 186'
 187
 188test_expect_success 'create namespaced refs' '
 189        test_commit namespaced &&
 190        git push public HEAD:refs/namespaces/ns/refs/heads/master &&
 191        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 192                symbolic-ref refs/namespaces/ns/HEAD refs/namespaces/ns/refs/heads/master
 193'
 194
 195test_expect_success 'smart clone respects namespace' '
 196        git clone "$HTTPD_URL/smart_namespace/repo.git" ns-smart &&
 197        echo namespaced >expect &&
 198        git --git-dir=ns-smart/.git log -1 --format=%s >actual &&
 199        test_cmp expect actual
 200'
 201
 202test_expect_success 'dumb clone via http-backend respects namespace' '
 203        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 204                config http.getanyfile true &&
 205        GIT_SMART_HTTP=0 git clone \
 206                "$HTTPD_URL/smart_namespace/repo.git" ns-dumb &&
 207        echo namespaced >expect &&
 208        git --git-dir=ns-dumb/.git log -1 --format=%s >actual &&
 209        test_cmp expect actual
 210'
 211
 212cat >cookies.txt <<EOF
 213127.0.0.1       FALSE   /smart_cookies/ FALSE   0       othername       othervalue
 214EOF
 215cat >expect_cookies.txt <<EOF
 216
 217127.0.0.1       FALSE   /smart_cookies/ FALSE   0       othername       othervalue
 218127.0.0.1       FALSE   /smart_cookies/repo.git/info/   FALSE   0       name    value
 219EOF
 220test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' '
 221        git config http.cookiefile cookies.txt &&
 222        git config http.savecookies true &&
 223        git ls-remote $HTTPD_URL/smart_cookies/repo.git master &&
 224        tail -3 cookies.txt >cookies_tail.txt &&
 225        test_cmp expect_cookies.txt cookies_tail.txt
 226'
 227
 228test_expect_success 'transfer.hiderefs works over smart-http' '
 229        test_commit hidden &&
 230        test_commit visible &&
 231        git push public HEAD^:refs/heads/a HEAD:refs/heads/b &&
 232        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 233                config transfer.hiderefs refs/heads/a &&
 234        git clone --bare "$HTTPD_URL/smart/repo.git" hidden.git &&
 235        test_must_fail git -C hidden.git rev-parse --verify a &&
 236        git -C hidden.git rev-parse --verify b
 237'
 238
 239# create an arbitrary number of tags, numbered from tag-$1 to tag-$2
 240create_tags () {
 241        rm -f marks &&
 242        for i in $(test_seq "$1" "$2")
 243        do
 244                # don't use here-doc, because it requires a process
 245                # per loop iteration
 246                echo "commit refs/heads/too-many-refs-$1" &&
 247                echo "mark :$i" &&
 248                echo "committer git <git@example.com> $i +0000" &&
 249                echo "data 0" &&
 250                echo "M 644 inline bla.txt" &&
 251                echo "data 4" &&
 252                echo "bla" &&
 253                # make every commit dangling by always
 254                # rewinding the branch after each commit
 255                echo "reset refs/heads/too-many-refs-$1" &&
 256                echo "from :$1"
 257        done | git fast-import --export-marks=marks &&
 258
 259        # now assign tags to all the dangling commits we created above
 260        tag=$(perl -e "print \"bla\" x 30") &&
 261        sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs
 262}
 263
 264test_expect_success 'create 2,000 tags in the repo' '
 265        (
 266                cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 267                create_tags 1 2000
 268        )
 269'
 270
 271test_expect_success CMDLINE_LIMIT \
 272        'clone the 2,000 tag repo to check OS command line overflow' '
 273        run_with_limited_cmdline git clone $HTTPD_URL/smart/repo.git too-many-refs &&
 274        (
 275                cd too-many-refs &&
 276                git for-each-ref refs/tags >actual &&
 277                test_line_count = 2000 actual
 278        )
 279'
 280
 281test_expect_success 'large fetch-pack requests can be split across POSTs' '
 282        GIT_TRACE_CURL=true git -c http.postbuffer=65536 \
 283                clone --bare "$HTTPD_URL/smart/repo.git" split.git 2>err &&
 284        grep "^=> Send header: POST" err >posts &&
 285        test_line_count = 2 posts
 286'
 287
 288test_expect_success 'test allowreachablesha1inwant' '
 289        test_when_finished "rm -rf test_reachable.git" &&
 290        server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 291        master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
 292        git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
 293
 294        git init --bare test_reachable.git &&
 295        git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
 296        git -C test_reachable.git fetch origin "$master_sha"
 297'
 298
 299test_expect_success 'test allowreachablesha1inwant with unreachable' '
 300        test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
 301
 302        #create unreachable sha
 303        echo content >file2 &&
 304        git add file2 &&
 305        git commit -m two &&
 306        git push public HEAD:refs/heads/doomed &&
 307        git push public :refs/heads/doomed &&
 308
 309        server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 310        master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
 311        git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
 312
 313        git init --bare test_reachable.git &&
 314        git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
 315        test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
 316'
 317
 318test_expect_success 'test allowanysha1inwant with unreachable' '
 319        test_when_finished "rm -rf test_reachable.git; git reset --hard $(git rev-parse HEAD)" &&
 320
 321        #create unreachable sha
 322        echo content >file2 &&
 323        git add file2 &&
 324        git commit -m two &&
 325        git push public HEAD:refs/heads/doomed &&
 326        git push public :refs/heads/doomed &&
 327
 328        server="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 329        master_sha=$(git -C "$server" rev-parse refs/heads/master) &&
 330        git -C "$server" config uploadpack.allowreachablesha1inwant 1 &&
 331
 332        git init --bare test_reachable.git &&
 333        git -C test_reachable.git remote add origin "$HTTPD_URL/smart/repo.git" &&
 334        test_must_fail git -C test_reachable.git fetch origin "$(git rev-parse HEAD)" &&
 335
 336        git -C "$server" config uploadpack.allowanysha1inwant 1 &&
 337        git -C test_reachable.git fetch origin "$(git rev-parse HEAD)"
 338'
 339
 340test_expect_success EXPENSIVE 'http can handle enormous ref negotiation' '
 341        (
 342                cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 343                create_tags 2001 50000
 344        ) &&
 345        git -C too-many-refs fetch -q --tags &&
 346        (
 347                cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 348                create_tags 50001 100000
 349        ) &&
 350        git -C too-many-refs fetch -q --tags &&
 351        git -C too-many-refs for-each-ref refs/tags >tags &&
 352        test_line_count = 100000 tags
 353'
 354
 355test_expect_success 'custom http headers' '
 356        test_must_fail git -c http.extraheader="x-magic-two: cadabra" \
 357                fetch "$HTTPD_URL/smart_headers/repo.git" &&
 358        git -c http.extraheader="x-magic-one: abra" \
 359            -c http.extraheader="x-magic-two: cadabra" \
 360            fetch "$HTTPD_URL/smart_headers/repo.git" &&
 361        git update-index --add --cacheinfo 160000,$(git rev-parse HEAD),sub &&
 362        git config -f .gitmodules submodule.sub.path sub &&
 363        git config -f .gitmodules submodule.sub.url \
 364                "$HTTPD_URL/smart_headers/repo.git" &&
 365        git submodule init sub &&
 366        test_must_fail git submodule update sub &&
 367        git -c http.extraheader="x-magic-one: abra" \
 368            -c http.extraheader="x-magic-two: cadabra" \
 369                submodule update sub
 370'
 371
 372test_expect_success 'GIT_REDACT_COOKIES redacts cookies' '
 373        rm -rf clone &&
 374        echo "Set-Cookie: Foo=1" >cookies &&
 375        echo "Set-Cookie: Bar=2" >>cookies &&
 376        GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Bar,Baz \
 377                git -c "http.cookieFile=$(pwd)/cookies" clone \
 378                $HTTPD_URL/smart/repo.git clone 2>err &&
 379        grep "Cookie:.*Foo=1" err &&
 380        grep "Cookie:.*Bar=<redacted>" err &&
 381        ! grep "Cookie:.*Bar=2" err
 382'
 383
 384test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
 385        rm -rf clone &&
 386        echo "Set-Cookie: Foo=" >cookies &&
 387        GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Foo \
 388                git -c "http.cookieFile=$(pwd)/cookies" clone \
 389                $HTTPD_URL/smart/repo.git clone 2>err &&
 390        grep "Cookie:.*Foo=<redacted>" err
 391'
 392
 393test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
 394        rm -rf clone &&
 395        GIT_TRACE_CURL=true \
 396                git clone $HTTPD_URL/smart/repo.git clone 2>err &&
 397        grep "=> Send data" err &&
 398
 399        rm -rf clone &&
 400        GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
 401                git clone $HTTPD_URL/smart/repo.git clone 2>err &&
 402        ! grep "=> Send data" err
 403'
 404
 405stop_httpd
 406test_done