unit-tests: do not mistake `.pdb` files for being executable
[git.git] / t / t9501-gitweb-standalone-http-status.sh
blobc900231079cf750f0f1111ca74ddca7803becf6c
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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16 TEST_PASSES_SANITIZE_LEAK=true
17 . ./lib-gitweb.sh
20 # Gitweb only provides the functionality tested by the 'modification times'
21 # tests if it can access a date parser from one of these modules:
23 perl -MHTTP::Date -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
24 perl -MTime::ParseDate -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
26 # ----------------------------------------------------------------------
27 # snapshot settings
29 test_expect_success 'setup' "
30 test_commit 'SnapshotTests' 'i can has snapshot'
34 cat >>gitweb_config.perl <<\EOF
35 $feature{'snapshot'}{'override'} = 0;
36 EOF
38 test_expect_success \
39 'snapshots: tgz only default format enabled' \
40 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
41 grep "Status: 200 OK" gitweb.output &&
42 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
43 grep "403 - Unsupported snapshot format" gitweb.output &&
44 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
45 grep "403 - Snapshot format not allowed" gitweb.output &&
46 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
47 grep "403 - Unsupported snapshot format" gitweb.output'
50 cat >>gitweb_config.perl <<\EOF
51 $feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
52 EOF
54 test_expect_success \
55 'snapshots: all enabled in default, use default disabled value' \
56 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
57 grep "Status: 200 OK" gitweb.output &&
58 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
59 grep "Status: 200 OK" gitweb.output &&
60 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
61 grep "403 - Snapshot format not allowed" gitweb.output &&
62 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
63 grep "Status: 200 OK" gitweb.output'
66 cat >>gitweb_config.perl <<\EOF
67 $known_snapshot_formats{'zip'}{'disabled'} = 1;
68 EOF
70 test_expect_success \
71 'snapshots: zip explicitly disabled' \
72 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
73 grep "403 - Snapshot format not allowed" gitweb.output'
74 test_debug 'cat gitweb.output'
77 cat >>gitweb_config.perl <<\EOF
78 $known_snapshot_formats{'tgz'}{'disabled'} = 0;
79 EOF
81 test_expect_success \
82 'snapshots: tgz explicitly enabled' \
83 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
84 grep "Status: 200 OK" gitweb.output'
85 test_debug 'cat gitweb.headers'
88 # ----------------------------------------------------------------------
89 # snapshot hash ids
91 test_expect_success 'snapshots: good tree-ish id' '
92 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
93 grep "Status: 200 OK" gitweb.output
95 test_debug 'cat gitweb.headers'
97 test_expect_success 'snapshots: bad tree-ish id' '
98 gitweb_run "p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz" &&
99 grep "404 - Object does not exist" gitweb.output
101 test_debug 'cat gitweb.output'
103 test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
104 echo object > tag-object &&
105 git add tag-object &&
106 test_tick && git commit -m "Object to be tagged" &&
107 git tag tagged-object $(git hash-object tag-object) &&
108 gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
109 grep "400 - Object is not a tree-ish" gitweb.output
111 test_debug 'cat gitweb.output'
113 test_expect_success 'snapshots: good object id' '
114 ID=$(git rev-parse --verify HEAD) &&
115 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
116 grep "Status: 200 OK" gitweb.output
118 test_debug 'cat gitweb.headers'
120 test_expect_success 'snapshots: bad object id' '
121 gitweb_run "p=.git;a=snapshot;h=abcdef01234;sf=tgz" &&
122 grep "404 - Object does not exist" gitweb.output
124 test_debug 'cat gitweb.output'
126 # ----------------------------------------------------------------------
127 # modification times (Last-Modified and If-Modified-Since)
129 test_expect_success DATE_PARSER 'modification: feed last-modified' '
130 gitweb_run "p=.git;a=atom;h=main" &&
131 grep "Status: 200 OK" gitweb.headers &&
132 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
134 test_debug 'cat gitweb.headers'
136 test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' '
137 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
138 export HTTP_IF_MODIFIED_SINCE &&
139 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
140 gitweb_run "p=.git;a=atom;h=main" &&
141 grep "Status: 200 OK" gitweb.headers
143 test_debug 'cat gitweb.headers'
145 test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' '
146 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
147 export HTTP_IF_MODIFIED_SINCE &&
148 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
149 gitweb_run "p=.git;a=atom;h=main" &&
150 grep "Status: 304 Not Modified" gitweb.headers
152 test_debug 'cat gitweb.headers'
154 test_expect_success DATE_PARSER 'modification: snapshot last-modified' '
155 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
156 grep "Status: 200 OK" gitweb.headers &&
157 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
159 test_debug 'cat gitweb.headers'
161 test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' '
162 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
163 export HTTP_IF_MODIFIED_SINCE &&
164 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
165 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
166 grep "Status: 200 OK" gitweb.headers
168 test_debug 'cat gitweb.headers'
170 test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' '
171 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
172 export HTTP_IF_MODIFIED_SINCE &&
173 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
174 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
175 grep "Status: 304 Not Modified" gitweb.headers
177 test_debug 'cat gitweb.headers'
179 test_expect_success DATE_PARSER 'modification: tree snapshot' '
180 ID=$(git rev-parse --verify HEAD^{tree}) &&
181 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
182 export HTTP_IF_MODIFIED_SINCE &&
183 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
184 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
185 grep "Status: 200 OK" gitweb.headers &&
186 ! grep -i "last-modified" gitweb.headers
188 test_debug 'cat gitweb.headers'
190 # ----------------------------------------------------------------------
191 # load checking
193 # always hit the load limit
194 cat >>gitweb_config.perl <<\EOF
195 our $maxload = -1;
198 test_expect_success 'load checking: load too high (default action)' '
199 gitweb_run "p=.git" &&
200 grep "Status: 503 Service Unavailable" gitweb.headers &&
201 grep "503 - The load average on the server is too high" gitweb.body
203 test_debug 'cat gitweb.headers'
205 # turn off load checking
206 cat >>gitweb_config.perl <<\EOF
207 our $maxload = undef;
211 # ----------------------------------------------------------------------
212 # invalid arguments
214 test_expect_success 'invalid arguments: invalid regexp (in project search)' '
215 gitweb_run "a=project_list;s=*\.git;sr=1" &&
216 grep "Status: 400" gitweb.headers &&
217 grep "400 - Invalid.*regexp" gitweb.body
219 test_debug 'cat gitweb.headers'
221 test_done