Merge branch 'jc/diff-format-doc' into maint
[git] / t / t5561-http-backend.sh
1 #!/bin/sh
2
3 test_description='test git-http-backend'
4 . ./test-lib.sh
5
6 if test -n "$NO_CURL"; then
7         skip_all='skipping test, git built without http support'
8         test_done
9 fi
10
11 . "$TEST_DIRECTORY"/lib-httpd.sh
12 start_httpd
13
14 GET() {
15         curl --include "$HTTPD_URL/$SMART/repo.git/$1" >out 2>/dev/null &&
16         tr '\015' Q <out |
17         sed '
18                 s/Q$//
19                 1q
20         ' >act &&
21         echo "HTTP/1.1 $2" >exp &&
22         test_cmp exp act
23 }
24
25 POST() {
26         curl --include --data "$2" \
27         --header "Content-Type: application/x-$1-request" \
28         "$HTTPD_URL/smart/repo.git/$1" >out 2>/dev/null &&
29         tr '\015' Q <out |
30         sed '
31                 s/Q$//
32                 1q
33         ' >act &&
34         echo "HTTP/1.1 $3" >exp &&
35         test_cmp exp act
36 }
37
38 log_div() {
39         echo >>"$HTTPD_ROOT_PATH"/access.log
40         echo "###  $1" >>"$HTTPD_ROOT_PATH"/access.log
41         echo "###" >>"$HTTPD_ROOT_PATH"/access.log
42 }
43
44 . "$TEST_DIRECTORY"/t556x_common
45
46 cat >exp <<EOF
47
48 ###  refs/heads/master
49 ###
50 GET  /smart/repo.git/refs/heads/master HTTP/1.1 404 -
51
52 ###  getanyfile default
53 ###
54 GET  /smart/repo.git/HEAD HTTP/1.1 200
55 GET  /smart/repo.git/info/refs HTTP/1.1 200
56 GET  /smart/repo.git/objects/info/packs HTTP/1.1 200
57 GET  /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
58 GET  /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
59 GET  /smart/repo.git/$LOOSE_URL HTTP/1.1 200
60 GET  /smart/repo.git/$PACK_URL HTTP/1.1 200
61 GET  /smart/repo.git/$IDX_URL HTTP/1.1 200
62
63 ###  no git-daemon-export-ok
64 ###
65 GET  /smart_noexport/repo.git/HEAD HTTP/1.1 404 -
66 GET  /smart_noexport/repo.git/info/refs HTTP/1.1 404 -
67 GET  /smart_noexport/repo.git/objects/info/packs HTTP/1.1 404 -
68 GET  /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 404 -
69 GET  /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 404 -
70 GET  /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 404 -
71 GET  /smart_noexport/repo.git/$PACK_URL HTTP/1.1 404 -
72 GET  /smart_noexport/repo.git/$IDX_URL HTTP/1.1 404 -
73
74 ###  git-daemon-export-ok
75 ###
76 GET  /smart_noexport/repo.git/HEAD HTTP/1.1 200
77 GET  /smart_noexport/repo.git/info/refs HTTP/1.1 200
78 GET  /smart_noexport/repo.git/objects/info/packs HTTP/1.1 200
79 GET  /smart_noexport/repo.git/objects/info/alternates HTTP/1.1 200 -
80 GET  /smart_noexport/repo.git/objects/info/http-alternates HTTP/1.1 200 -
81 GET  /smart_noexport/repo.git/$LOOSE_URL HTTP/1.1 200
82 GET  /smart_noexport/repo.git/$PACK_URL HTTP/1.1 200
83 GET  /smart_noexport/repo.git/$IDX_URL HTTP/1.1 200
84
85 ###  getanyfile true
86 ###
87 GET  /smart/repo.git/HEAD HTTP/1.1 200
88 GET  /smart/repo.git/info/refs HTTP/1.1 200
89 GET  /smart/repo.git/objects/info/packs HTTP/1.1 200
90 GET  /smart/repo.git/objects/info/alternates HTTP/1.1 200 -
91 GET  /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -
92 GET  /smart/repo.git/$LOOSE_URL HTTP/1.1 200
93 GET  /smart/repo.git/$PACK_URL HTTP/1.1 200
94 GET  /smart/repo.git/$IDX_URL HTTP/1.1 200
95
96 ###  getanyfile false
97 ###
98 GET  /smart/repo.git/HEAD HTTP/1.1 403 -
99 GET  /smart/repo.git/info/refs HTTP/1.1 403 -
100 GET  /smart/repo.git/objects/info/packs HTTP/1.1 403 -
101 GET  /smart/repo.git/objects/info/alternates HTTP/1.1 403 -
102 GET  /smart/repo.git/objects/info/http-alternates HTTP/1.1 403 -
103 GET  /smart/repo.git/$LOOSE_URL HTTP/1.1 403 -
104 GET  /smart/repo.git/$PACK_URL HTTP/1.1 403 -
105 GET  /smart/repo.git/$IDX_URL HTTP/1.1 403 -
106
107 ###  uploadpack default
108 ###
109 GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
110 POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
111
112 ###  uploadpack true
113 ###
114 GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
115 POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -
116
117 ###  uploadpack false
118 ###
119 GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 403 -
120 POST /smart/repo.git/git-upload-pack HTTP/1.1 403 -
121
122 ###  receivepack default
123 ###
124 GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
125 POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
126
127 ###  receivepack true
128 ###
129 GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 200
130 POST /smart/repo.git/git-receive-pack HTTP/1.1 200 -
131
132 ###  receivepack false
133 ###
134 GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -
135 POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -
136 EOF
137 test_expect_success 'server request log matches test results' '
138         sed -e "
139                 s/^.* \"//
140                 s/\"//
141                 s/ [1-9][0-9]*\$//
142                 s/^GET /GET  /
143         " >act <"$HTTPD_ROOT_PATH"/access.log &&
144         test_cmp exp act
145 '
146
147 stop_httpd
148 test_done