t / t5551-http-fetch.shon commit t5570: do not assume the "matching" push is the default (ac47a22)
   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
  11LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'}
  12. "$TEST_DIRECTORY"/lib-httpd.sh
  13start_httpd
  14
  15test_expect_success 'setup repository' '
  16        git config push.default matching &&
  17        echo content >file &&
  18        git add file &&
  19        git commit -m one
  20'
  21
  22test_expect_success 'create http-accessible bare repository' '
  23        mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  24        (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  25         git --bare init
  26        ) &&
  27        git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
  28        git push public master:master
  29'
  30
  31setup_askpass_helper
  32
  33cat >exp <<EOF
  34> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
  35> Accept: */*
  36> Accept-Encoding: gzip
  37> Pragma: no-cache
  38< HTTP/1.1 200 OK
  39< Pragma: no-cache
  40< Cache-Control: no-cache, max-age=0, must-revalidate
  41< Content-Type: application/x-git-upload-pack-advertisement
  42> POST /smart/repo.git/git-upload-pack HTTP/1.1
  43> Accept-Encoding: gzip
  44> Content-Type: application/x-git-upload-pack-request
  45> Accept: application/x-git-upload-pack-result
  46> Content-Length: xxx
  47< HTTP/1.1 200 OK
  48< Pragma: no-cache
  49< Cache-Control: no-cache, max-age=0, must-revalidate
  50< Content-Type: application/x-git-upload-pack-result
  51EOF
  52test_expect_success 'clone http repository' '
  53        GIT_CURL_VERBOSE=1 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
  54        test_cmp file clone/file &&
  55        tr '\''\015'\'' Q <err |
  56        sed -e "
  57                s/Q\$//
  58                /^[*] /d
  59                /^$/d
  60                /^< $/d
  61
  62                /^[^><]/{
  63                        s/^/> /
  64                }
  65
  66                /^> User-Agent: /d
  67                /^> Host: /d
  68                /^> POST /,$ {
  69                        /^> Accept: [*]\\/[*]/d
  70                }
  71                s/^> Content-Length: .*/> Content-Length: xxx/
  72                /^> 00..want /d
  73                /^> 00.*done/d
  74
  75                /^< Server: /d
  76                /^< Expires: /d
  77                /^< Date: /d
  78                /^< Content-Length: /d
  79                /^< Transfer-Encoding: /d
  80        " >act &&
  81        test_cmp exp act
  82'
  83
  84test_expect_success 'fetch changes via http' '
  85        echo content >>file &&
  86        git commit -a -m two &&
  87        git push public
  88        (cd clone && git pull) &&
  89        test_cmp file clone/file
  90'
  91
  92cat >exp <<EOF
  93GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  94POST /smart/repo.git/git-upload-pack HTTP/1.1 200
  95GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
  96POST /smart/repo.git/git-upload-pack HTTP/1.1 200
  97EOF
  98test_expect_success 'used upload-pack service' '
  99        sed -e "
 100                s/^.* \"//
 101                s/\"//
 102                s/ [1-9][0-9]*\$//
 103                s/^GET /GET  /
 104        " >act <"$HTTPD_ROOT_PATH"/access.log &&
 105        test_cmp exp act
 106'
 107
 108test_expect_success 'follow redirects (301)' '
 109        git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p
 110'
 111
 112test_expect_success 'follow redirects (302)' '
 113        git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t
 114'
 115
 116test_expect_success 'clone from password-protected repository' '
 117        echo two >expect &&
 118        set_askpass user@host &&
 119        git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth &&
 120        expect_askpass both user@host &&
 121        git --git-dir=smart-auth log -1 --format=%s >actual &&
 122        test_cmp expect actual
 123'
 124
 125test_expect_success 'clone from auth-only-for-push repository' '
 126        echo two >expect &&
 127        set_askpass wrong &&
 128        git clone --bare "$HTTPD_URL/auth-push/smart/repo.git" smart-noauth &&
 129        expect_askpass none &&
 130        git --git-dir=smart-noauth log -1 --format=%s >actual &&
 131        test_cmp expect actual
 132'
 133
 134test_expect_success 'clone from auth-only-for-objects repository' '
 135        echo two >expect &&
 136        set_askpass user@host &&
 137        git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth &&
 138        expect_askpass both user@host &&
 139        git --git-dir=half-auth log -1 --format=%s >actual &&
 140        test_cmp expect actual
 141'
 142
 143test_expect_success 'no-op half-auth fetch does not require a password' '
 144        set_askpass wrong &&
 145        git --git-dir=half-auth fetch &&
 146        expect_askpass none
 147'
 148
 149test_expect_success 'disable dumb http on server' '
 150        git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 151                config http.getanyfile false
 152'
 153
 154test_expect_success 'GIT_SMART_HTTP can disable smart http' '
 155        (GIT_SMART_HTTP=0 &&
 156         export GIT_SMART_HTTP &&
 157         cd clone &&
 158         test_must_fail git fetch)
 159'
 160
 161test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE
 162
 163test_expect_success EXPENSIVE 'create 50,000 tags in the repo' '
 164        (
 165        cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" &&
 166        for i in `test_seq 50000`
 167        do
 168                echo "commit refs/heads/too-many-refs"
 169                echo "mark :$i"
 170                echo "committer git <git@example.com> $i +0000"
 171                echo "data 0"
 172                echo "M 644 inline bla.txt"
 173                echo "data 4"
 174                echo "bla"
 175                # make every commit dangling by always
 176                # rewinding the branch after each commit
 177                echo "reset refs/heads/too-many-refs"
 178                echo "from :1"
 179        done | git fast-import --export-marks=marks &&
 180
 181        # now assign tags to all the dangling commits we created above
 182        tag=$("$PERL_PATH" -e "print \"bla\" x 30") &&
 183        sed -e "s/^:\(.\+\) \(.\+\)$/\2 refs\/tags\/$tag-\1/" <marks >>packed-refs
 184        )
 185'
 186
 187test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' '
 188        git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err &&
 189        test_line_count = 0 err
 190'
 191
 192stop_httpd
 193test_done