]>
Commit | Line | Data |
---|---|---|
e39e0d37 MR |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2009 Mark Rada | |
4 | # | |
5 | ||
6 | test_description='gitweb as standalone script (http status tests). | |
7 | ||
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.' | |
11 | ||
12 | ||
765577b5 | 13 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
14 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
15 | ||
3fca1fc6 | 16 | . ./lib-gitweb.sh |
e39e0d37 | 17 | |
2a8a4490 RJ |
18 | # |
19 | # Gitweb only provides the functionality tested by the 'modification times' | |
20 | # tests if it can access a date parser from one of these modules: | |
21 | # | |
22 | perl -MHTTP::Date -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER | |
23 | perl -MTime::ParseDate -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER | |
24 | ||
e39e0d37 MR |
25 | # ---------------------------------------------------------------------- |
26 | # snapshot settings | |
27 | ||
4a45f7dd | 28 | test_expect_success 'setup' " |
1b3187ba | 29 | test_commit 'SnapshotTests' 'i can has snapshot' |
4a45f7dd BG |
30 | " |
31 | ||
e39e0d37 MR |
32 | |
33 | cat >>gitweb_config.perl <<\EOF | |
34 | $feature{'snapshot'}{'override'} = 0; | |
35 | EOF | |
36 | ||
37 | test_expect_success \ | |
38 | 'snapshots: tgz only default format enabled' \ | |
39 | 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" && | |
40 | grep "Status: 200 OK" gitweb.output && | |
41 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" && | |
42 | grep "403 - Unsupported snapshot format" gitweb.output && | |
43 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" && | |
44 | grep "403 - Snapshot format not allowed" gitweb.output && | |
45 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" && | |
46 | grep "403 - Unsupported snapshot format" gitweb.output' | |
e39e0d37 MR |
47 | |
48 | ||
49 | cat >>gitweb_config.perl <<\EOF | |
50 | $feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip']; | |
51 | EOF | |
52 | ||
53 | test_expect_success \ | |
54 | 'snapshots: all enabled in default, use default disabled value' \ | |
55 | 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" && | |
56 | grep "Status: 200 OK" gitweb.output && | |
57 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" && | |
58 | grep "Status: 200 OK" gitweb.output && | |
59 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" && | |
60 | grep "403 - Snapshot format not allowed" gitweb.output && | |
61 | gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" && | |
62 | grep "Status: 200 OK" gitweb.output' | |
e39e0d37 MR |
63 | |
64 | ||
65 | cat >>gitweb_config.perl <<\EOF | |
66 | $known_snapshot_formats{'zip'}{'disabled'} = 1; | |
67 | EOF | |
68 | ||
69 | test_expect_success \ | |
70 | 'snapshots: zip explicitly disabled' \ | |
71 | 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" && | |
72 | grep "403 - Snapshot format not allowed" gitweb.output' | |
73 | test_debug 'cat gitweb.output' | |
74 | ||
75 | ||
76 | cat >>gitweb_config.perl <<\EOF | |
77 | $known_snapshot_formats{'tgz'}{'disabled'} = 0; | |
78 | EOF | |
79 | ||
80 | test_expect_success \ | |
81 | 'snapshots: tgz explicitly enabled' \ | |
82 | 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" && | |
83 | grep "Status: 200 OK" gitweb.output' | |
745a2db4 | 84 | test_debug 'cat gitweb.headers' |
e39e0d37 MR |
85 | |
86 | ||
fdb0c36e MR |
87 | # ---------------------------------------------------------------------- |
88 | # snapshot hash ids | |
89 | ||
90 | test_expect_success 'snapshots: good tree-ish id' ' | |
765577b5 | 91 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
fdb0c36e MR |
92 | grep "Status: 200 OK" gitweb.output |
93 | ' | |
745a2db4 | 94 | test_debug 'cat gitweb.headers' |
fdb0c36e MR |
95 | |
96 | test_expect_success 'snapshots: bad tree-ish id' ' | |
97 | gitweb_run "p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz" && | |
98 | grep "404 - Object does not exist" gitweb.output | |
99 | ' | |
100 | test_debug 'cat gitweb.output' | |
101 | ||
102 | test_expect_success 'snapshots: bad tree-ish id (tagged object)' ' | |
103 | echo object > tag-object && | |
104 | git add tag-object && | |
b7d565ea | 105 | test_tick && git commit -m "Object to be tagged" && |
9c103775 | 106 | git tag tagged-object $(git hash-object tag-object) && |
fdb0c36e MR |
107 | gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" && |
108 | grep "400 - Object is not a tree-ish" gitweb.output | |
109 | ' | |
110 | test_debug 'cat gitweb.output' | |
111 | ||
112 | test_expect_success 'snapshots: good object id' ' | |
9c103775 | 113 | ID=$(git rev-parse --verify HEAD) && |
fdb0c36e MR |
114 | gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" && |
115 | grep "Status: 200 OK" gitweb.output | |
116 | ' | |
745a2db4 | 117 | test_debug 'cat gitweb.headers' |
fdb0c36e MR |
118 | |
119 | test_expect_success 'snapshots: bad object id' ' | |
120 | gitweb_run "p=.git;a=snapshot;h=abcdef01234;sf=tgz" && | |
121 | grep "404 - Object does not exist" gitweb.output | |
122 | ' | |
123 | test_debug 'cat gitweb.output' | |
124 | ||
b7d565ea TK |
125 | # ---------------------------------------------------------------------- |
126 | # modification times (Last-Modified and If-Modified-Since) | |
127 | ||
2a8a4490 | 128 | test_expect_success DATE_PARSER 'modification: feed last-modified' ' |
765577b5 | 129 | gitweb_run "p=.git;a=atom;h=main" && |
b7d565ea TK |
130 | grep "Status: 200 OK" gitweb.headers && |
131 | grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers | |
132 | ' | |
133 | test_debug 'cat gitweb.headers' | |
134 | ||
2a8a4490 | 135 | test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' ' |
d87ec816 TB |
136 | HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && |
137 | export HTTP_IF_MODIFIED_SINCE && | |
b7d565ea | 138 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
765577b5 | 139 | gitweb_run "p=.git;a=atom;h=main" && |
b7d565ea TK |
140 | grep "Status: 200 OK" gitweb.headers |
141 | ' | |
142 | test_debug 'cat gitweb.headers' | |
143 | ||
2a8a4490 | 144 | test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' ' |
d87ec816 TB |
145 | HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && |
146 | export HTTP_IF_MODIFIED_SINCE && | |
b7d565ea | 147 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
765577b5 | 148 | gitweb_run "p=.git;a=atom;h=main" && |
b7d565ea TK |
149 | grep "Status: 304 Not Modified" gitweb.headers |
150 | ' | |
151 | test_debug 'cat gitweb.headers' | |
fdb0c36e | 152 | |
2a8a4490 | 153 | test_expect_success DATE_PARSER 'modification: snapshot last-modified' ' |
765577b5 | 154 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
8745db63 TK |
155 | grep "Status: 200 OK" gitweb.headers && |
156 | grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers | |
157 | ' | |
158 | test_debug 'cat gitweb.headers' | |
159 | ||
2a8a4490 | 160 | test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' ' |
d87ec816 TB |
161 | HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && |
162 | export HTTP_IF_MODIFIED_SINCE && | |
8745db63 | 163 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
765577b5 | 164 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
8745db63 TK |
165 | grep "Status: 200 OK" gitweb.headers |
166 | ' | |
167 | test_debug 'cat gitweb.headers' | |
168 | ||
2a8a4490 | 169 | test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' ' |
d87ec816 TB |
170 | HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && |
171 | export HTTP_IF_MODIFIED_SINCE && | |
8745db63 | 172 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
765577b5 | 173 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
8745db63 TK |
174 | grep "Status: 304 Not Modified" gitweb.headers |
175 | ' | |
176 | test_debug 'cat gitweb.headers' | |
177 | ||
2a8a4490 | 178 | test_expect_success DATE_PARSER 'modification: tree snapshot' ' |
9c103775 | 179 | ID=$(git rev-parse --verify HEAD^{tree}) && |
d87ec816 TB |
180 | HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && |
181 | export HTTP_IF_MODIFIED_SINCE && | |
8745db63 TK |
182 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
183 | gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" && | |
184 | grep "Status: 200 OK" gitweb.headers && | |
185 | ! grep -i "last-modified" gitweb.headers | |
186 | ' | |
187 | test_debug 'cat gitweb.headers' | |
188 | ||
b62a1a98 JWH |
189 | # ---------------------------------------------------------------------- |
190 | # load checking | |
191 | ||
192 | # always hit the load limit | |
193 | cat >>gitweb_config.perl <<\EOF | |
ab35469d | 194 | our $maxload = -1; |
b62a1a98 JWH |
195 | EOF |
196 | ||
ab35469d | 197 | test_expect_success 'load checking: load too high (default action)' ' |
b62a1a98 JWH |
198 | gitweb_run "p=.git" && |
199 | grep "Status: 503 Service Unavailable" gitweb.headers && | |
200 | grep "503 - The load average on the server is too high" gitweb.body | |
201 | ' | |
b62a1a98 JWH |
202 | test_debug 'cat gitweb.headers' |
203 | ||
204 | # turn off load checking | |
205 | cat >>gitweb_config.perl <<\EOF | |
206 | our $maxload = undef; | |
207 | EOF | |
208 | ||
209 | ||
36612e4d JN |
210 | # ---------------------------------------------------------------------- |
211 | # invalid arguments | |
212 | ||
213 | test_expect_success 'invalid arguments: invalid regexp (in project search)' ' | |
214 | gitweb_run "a=project_list;s=*\.git;sr=1" && | |
215 | grep "Status: 400" gitweb.headers && | |
216 | grep "400 - Invalid.*regexp" gitweb.body | |
217 | ' | |
218 | test_debug 'cat gitweb.headers' | |
219 | ||
e39e0d37 | 220 | test_done |