]>
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 | ||
7a98d9ab | 16 | TEST_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 | # | |
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 | |
25 | ||
e39e0d37 MR |
26 | # ---------------------------------------------------------------------- |
27 | # snapshot settings | |
28 | ||
4a45f7dd | 29 | test_expect_success 'setup' " |
1b3187ba | 30 | test_commit 'SnapshotTests' 'i can has snapshot' |
4a45f7dd BG |
31 | " |
32 | ||
e39e0d37 MR |
33 | |
34 | cat >>gitweb_config.perl <<\EOF | |
35 | $feature{'snapshot'}{'override'} = 0; | |
36 | EOF | |
37 | ||
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' | |
e39e0d37 MR |
48 | |
49 | ||
50 | cat >>gitweb_config.perl <<\EOF | |
51 | $feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip']; | |
52 | EOF | |
53 | ||
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' | |
e39e0d37 MR |
64 | |
65 | ||
66 | cat >>gitweb_config.perl <<\EOF | |
67 | $known_snapshot_formats{'zip'}{'disabled'} = 1; | |
68 | EOF | |
69 | ||
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' | |
75 | ||
76 | ||
77 | cat >>gitweb_config.perl <<\EOF | |
78 | $known_snapshot_formats{'tgz'}{'disabled'} = 0; | |
79 | EOF | |
80 | ||
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' | |
745a2db4 | 85 | test_debug 'cat gitweb.headers' |
e39e0d37 MR |
86 | |
87 | ||
fdb0c36e MR |
88 | # ---------------------------------------------------------------------- |
89 | # snapshot hash ids | |
90 | ||
91 | test_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 | 95 | test_debug 'cat gitweb.headers' |
fdb0c36e MR |
96 | |
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 | |
100 | ' | |
101 | test_debug 'cat gitweb.output' | |
102 | ||
103 | test_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 | ' | |
111 | test_debug 'cat gitweb.output' | |
112 | ||
113 | test_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 | 118 | test_debug 'cat gitweb.headers' |
fdb0c36e MR |
119 | |
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 | |
123 | ' | |
124 | test_debug 'cat gitweb.output' | |
125 | ||
b7d565ea TK |
126 | # ---------------------------------------------------------------------- |
127 | # modification times (Last-Modified and If-Modified-Since) | |
128 | ||
2a8a4490 | 129 | test_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 | ' | |
134 | test_debug 'cat gitweb.headers' | |
135 | ||
2a8a4490 | 136 | test_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 | ' | |
143 | test_debug 'cat gitweb.headers' | |
144 | ||
2a8a4490 | 145 | test_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 | ' | |
152 | test_debug 'cat gitweb.headers' | |
fdb0c36e | 153 | |
2a8a4490 | 154 | test_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 | ' | |
159 | test_debug 'cat gitweb.headers' | |
160 | ||
2a8a4490 | 161 | test_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 | ' | |
168 | test_debug 'cat gitweb.headers' | |
169 | ||
2a8a4490 | 170 | test_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 | ' | |
177 | test_debug 'cat gitweb.headers' | |
178 | ||
2a8a4490 | 179 | test_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 | ' | |
188 | test_debug 'cat gitweb.headers' | |
189 | ||
b62a1a98 JWH |
190 | # ---------------------------------------------------------------------- |
191 | # load checking | |
192 | ||
193 | # always hit the load limit | |
194 | cat >>gitweb_config.perl <<\EOF | |
ab35469d | 195 | our $maxload = -1; |
b62a1a98 JWH |
196 | EOF |
197 | ||
ab35469d | 198 | test_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 |
203 | test_debug 'cat gitweb.headers' |
204 | ||
205 | # turn off load checking | |
206 | cat >>gitweb_config.perl <<\EOF | |
207 | our $maxload = undef; | |
208 | EOF | |
209 | ||
210 | ||
36612e4d JN |
211 | # ---------------------------------------------------------------------- |
212 | # invalid arguments | |
213 | ||
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 | |
218 | ' | |
219 | test_debug 'cat gitweb.headers' | |
220 | ||
e39e0d37 | 221 | test_done |