]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9501-gitweb-standalone-http-status.sh
The third batch
[thirdparty/git.git] / t / t9501-gitweb-standalone-http-status.sh
CommitLineData
e39e0d37
MR
1#!/bin/sh
2#
3# Copyright (c) 2009 Mark Rada
4#
5
6test_description='gitweb as standalone script (http status tests).
7
8This test runs gitweb (git web interface) as a CGI script from the
9commandline, and checks that it returns the expected HTTP status
10code and message.'
11
12
765577b5 13GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
14export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15
7a98d9ab 16TEST_PASSES_SANITIZE_LEAK=true
3fca1fc6 17. ./lib-gitweb.sh
e39e0d37 18
2a8a4490
RJ
19#
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:
22#
23perl -MHTTP::Date -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
24perl -MTime::ParseDate -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
25
e39e0d37
MR
26# ----------------------------------------------------------------------
27# snapshot settings
28
4a45f7dd 29test_expect_success 'setup' "
1b3187ba 30 test_commit 'SnapshotTests' 'i can has snapshot'
4a45f7dd
BG
31"
32
e39e0d37
MR
33
34cat >>gitweb_config.perl <<\EOF
35$feature{'snapshot'}{'override'} = 0;
36EOF
37
38test_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'
e39e0d37
MR
48
49
50cat >>gitweb_config.perl <<\EOF
51$feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
52EOF
53
54test_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'
e39e0d37
MR
64
65
66cat >>gitweb_config.perl <<\EOF
67$known_snapshot_formats{'zip'}{'disabled'} = 1;
68EOF
69
70test_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'
74test_debug 'cat gitweb.output'
75
76
77cat >>gitweb_config.perl <<\EOF
78$known_snapshot_formats{'tgz'}{'disabled'} = 0;
79EOF
80
81test_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'
745a2db4 85test_debug 'cat gitweb.headers'
e39e0d37
MR
86
87
fdb0c36e
MR
88# ----------------------------------------------------------------------
89# snapshot hash ids
90
91test_expect_success 'snapshots: good tree-ish id' '
765577b5 92 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
fdb0c36e
MR
93 grep "Status: 200 OK" gitweb.output
94'
745a2db4 95test_debug 'cat gitweb.headers'
fdb0c36e
MR
96
97test_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
100'
101test_debug 'cat gitweb.output'
102
103test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
104 echo object > tag-object &&
105 git add tag-object &&
b7d565ea 106 test_tick && git commit -m "Object to be tagged" &&
9c103775 107 git tag tagged-object $(git hash-object tag-object) &&
fdb0c36e
MR
108 gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
109 grep "400 - Object is not a tree-ish" gitweb.output
110'
111test_debug 'cat gitweb.output'
112
113test_expect_success 'snapshots: good object id' '
9c103775 114 ID=$(git rev-parse --verify HEAD) &&
fdb0c36e
MR
115 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
116 grep "Status: 200 OK" gitweb.output
117'
745a2db4 118test_debug 'cat gitweb.headers'
fdb0c36e
MR
119
120test_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
123'
124test_debug 'cat gitweb.output'
125
b7d565ea
TK
126# ----------------------------------------------------------------------
127# modification times (Last-Modified and If-Modified-Since)
128
2a8a4490 129test_expect_success DATE_PARSER 'modification: feed last-modified' '
765577b5 130 gitweb_run "p=.git;a=atom;h=main" &&
b7d565ea
TK
131 grep "Status: 200 OK" gitweb.headers &&
132 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
133'
134test_debug 'cat gitweb.headers'
135
2a8a4490 136test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' '
d87ec816
TB
137 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
138 export HTTP_IF_MODIFIED_SINCE &&
b7d565ea 139 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
765577b5 140 gitweb_run "p=.git;a=atom;h=main" &&
b7d565ea
TK
141 grep "Status: 200 OK" gitweb.headers
142'
143test_debug 'cat gitweb.headers'
144
2a8a4490 145test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' '
d87ec816
TB
146 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
147 export HTTP_IF_MODIFIED_SINCE &&
b7d565ea 148 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
765577b5 149 gitweb_run "p=.git;a=atom;h=main" &&
b7d565ea
TK
150 grep "Status: 304 Not Modified" gitweb.headers
151'
152test_debug 'cat gitweb.headers'
fdb0c36e 153
2a8a4490 154test_expect_success DATE_PARSER 'modification: snapshot last-modified' '
765577b5 155 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
8745db63
TK
156 grep "Status: 200 OK" gitweb.headers &&
157 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
158'
159test_debug 'cat gitweb.headers'
160
2a8a4490 161test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' '
d87ec816
TB
162 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
163 export HTTP_IF_MODIFIED_SINCE &&
8745db63 164 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
765577b5 165 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
8745db63
TK
166 grep "Status: 200 OK" gitweb.headers
167'
168test_debug 'cat gitweb.headers'
169
2a8a4490 170test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' '
d87ec816
TB
171 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
172 export HTTP_IF_MODIFIED_SINCE &&
8745db63 173 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
765577b5 174 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
8745db63
TK
175 grep "Status: 304 Not Modified" gitweb.headers
176'
177test_debug 'cat gitweb.headers'
178
2a8a4490 179test_expect_success DATE_PARSER 'modification: tree snapshot' '
9c103775 180 ID=$(git rev-parse --verify HEAD^{tree}) &&
d87ec816
TB
181 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
182 export HTTP_IF_MODIFIED_SINCE &&
8745db63
TK
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
187'
188test_debug 'cat gitweb.headers'
189
b62a1a98
JWH
190# ----------------------------------------------------------------------
191# load checking
192
193# always hit the load limit
194cat >>gitweb_config.perl <<\EOF
ab35469d 195our $maxload = -1;
b62a1a98
JWH
196EOF
197
ab35469d 198test_expect_success 'load checking: load too high (default action)' '
b62a1a98
JWH
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
202'
b62a1a98
JWH
203test_debug 'cat gitweb.headers'
204
205# turn off load checking
206cat >>gitweb_config.perl <<\EOF
207our $maxload = undef;
208EOF
209
210
36612e4d
JN
211# ----------------------------------------------------------------------
212# invalid arguments
213
214test_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
218'
219test_debug 'cat gitweb.headers'
220
e39e0d37 221test_done