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