Merge branch 'js/spawn-via-shell-path-fix'
[git/debian.git] / t / t9501-gitweb-standalone-http-status.sh
blobfa2f65f6be44fb7d6c4c22b9642b33cd90d51646
1 #!/bin/sh
3 # Copyright (c) 2009 Mark Rada
6 test_description='gitweb as standalone script (http status tests).
8 This test runs gitweb (git web interface) as a CGI script from the
9 commandline, and checks that it returns the expected HTTP status
10 code and message.'
13 . ./gitweb-lib.sh
15 # ----------------------------------------------------------------------
16 # snapshot settings
18 test_expect_success 'setup' "
19 test_commit 'SnapshotTests' 'i can has snapshot'
23 cat >>gitweb_config.perl <<\EOF
24 $feature{'snapshot'}{'override'} = 0;
25 EOF
27 test_expect_success \
28 'snapshots: tgz only default format enabled' \
29 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
30 grep "Status: 200 OK" gitweb.output &&
31 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
32 grep "403 - Unsupported snapshot format" gitweb.output &&
33 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
34 grep "403 - Snapshot format not allowed" gitweb.output &&
35 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
36 grep "403 - Unsupported snapshot format" gitweb.output'
39 cat >>gitweb_config.perl <<\EOF
40 $feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
41 EOF
43 test_expect_success \
44 'snapshots: all enabled in default, use default disabled value' \
45 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
46 grep "Status: 200 OK" gitweb.output &&
47 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
48 grep "Status: 200 OK" gitweb.output &&
49 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
50 grep "403 - Snapshot format not allowed" gitweb.output &&
51 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
52 grep "Status: 200 OK" gitweb.output'
55 cat >>gitweb_config.perl <<\EOF
56 $known_snapshot_formats{'zip'}{'disabled'} = 1;
57 EOF
59 test_expect_success \
60 'snapshots: zip explicitly disabled' \
61 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
62 grep "403 - Snapshot format not allowed" gitweb.output'
63 test_debug 'cat gitweb.output'
66 cat >>gitweb_config.perl <<\EOF
67 $known_snapshot_formats{'tgz'}{'disabled'} = 0;
68 EOF
70 test_expect_success \
71 'snapshots: tgz explicitly enabled' \
72 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
73 grep "Status: 200 OK" gitweb.output'
74 test_debug 'cat gitweb.headers'
77 # ----------------------------------------------------------------------
78 # snapshot hash ids
80 test_expect_success 'snapshots: good tree-ish id' '
81 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
82 grep "Status: 200 OK" gitweb.output
84 test_debug 'cat gitweb.headers'
86 test_expect_success 'snapshots: bad tree-ish id' '
87 gitweb_run "p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz" &&
88 grep "404 - Object does not exist" gitweb.output
90 test_debug 'cat gitweb.output'
92 test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
93 echo object > tag-object &&
94 git add tag-object &&
95 test_tick && git commit -m "Object to be tagged" &&
96 git tag tagged-object `git hash-object tag-object` &&
97 gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
98 grep "400 - Object is not a tree-ish" gitweb.output
100 test_debug 'cat gitweb.output'
102 test_expect_success 'snapshots: good object id' '
103 ID=`git rev-parse --verify HEAD` &&
104 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
105 grep "Status: 200 OK" gitweb.output
107 test_debug 'cat gitweb.headers'
109 test_expect_success 'snapshots: bad object id' '
110 gitweb_run "p=.git;a=snapshot;h=abcdef01234;sf=tgz" &&
111 grep "404 - Object does not exist" gitweb.output
113 test_debug 'cat gitweb.output'
115 # ----------------------------------------------------------------------
116 # modification times (Last-Modified and If-Modified-Since)
118 test_expect_success 'modification: feed last-modified' '
119 gitweb_run "p=.git;a=atom;h=master" &&
120 grep "Status: 200 OK" gitweb.headers &&
121 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
123 test_debug 'cat gitweb.headers'
125 test_expect_success 'modification: feed if-modified-since (modified)' '
126 export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
127 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
128 gitweb_run "p=.git;a=atom;h=master" &&
129 grep "Status: 200 OK" gitweb.headers
131 test_debug 'cat gitweb.headers'
133 test_expect_success 'modification: feed if-modified-since (unmodified)' '
134 export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
135 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
136 gitweb_run "p=.git;a=atom;h=master" &&
137 grep "Status: 304 Not Modified" gitweb.headers
139 test_debug 'cat gitweb.headers'
141 test_expect_success 'modification: snapshot last-modified' '
142 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
143 grep "Status: 200 OK" gitweb.headers &&
144 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
146 test_debug 'cat gitweb.headers'
148 test_expect_success 'modification: snapshot if-modified-since (modified)' '
149 export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
150 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
151 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
152 grep "Status: 200 OK" gitweb.headers
154 test_debug 'cat gitweb.headers'
156 test_expect_success 'modification: snapshot if-modified-since (unmodified)' '
157 export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
158 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
159 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
160 grep "Status: 304 Not Modified" gitweb.headers
162 test_debug 'cat gitweb.headers'
164 test_expect_success 'modification: tree snapshot' '
165 ID=`git rev-parse --verify HEAD^{tree}` &&
166 export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
167 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
168 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
169 grep "Status: 200 OK" gitweb.headers &&
170 ! grep -i "last-modified" gitweb.headers
172 test_debug 'cat gitweb.headers'
174 # ----------------------------------------------------------------------
175 # load checking
177 # always hit the load limit
178 cat >>gitweb_config.perl <<\EOF
179 our $maxload = -1;
182 test_expect_success 'load checking: load too high (default action)' '
183 gitweb_run "p=.git" &&
184 grep "Status: 503 Service Unavailable" gitweb.headers &&
185 grep "503 - The load average on the server is too high" gitweb.body
187 test_debug 'cat gitweb.headers'
189 # turn off load checking
190 cat >>gitweb_config.perl <<\EOF
191 our $maxload = undef;
195 # ----------------------------------------------------------------------
196 # invalid arguments
198 test_expect_success 'invalid arguments: invalid regexp (in project search)' '
199 gitweb_run "a=project_list;s=*\.git;sr=1" &&
200 grep "Status: 400" gitweb.headers &&
201 grep "400 - Invalid.*regexp" gitweb.body
203 test_debug 'cat gitweb.headers'
205 test_done