blob: 32814e75df5b0d796b292c2ac39d370c636e5e67 [file] [log] [blame]
Mark Radae39e0d32009-08-25 01:03:48 -04001#!/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
Johannes Schindelin765577b2020-11-18 23:44:43 +000013GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +000014export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15
Ævar Arnfjörð Bjarmason3fca1fc2021-02-09 22:41:53 +010016. ./lib-gitweb.sh
Mark Radae39e0d32009-08-25 01:03:48 -040017
Ramsay Jones2a8a4492012-06-12 19:09:38 +010018#
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#
22perl -MHTTP::Date -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
23perl -MTime::ParseDate -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
24
Mark Radae39e0d32009-08-25 01:03:48 -040025# ----------------------------------------------------------------------
26# snapshot settings
27
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040028test_expect_success 'setup' "
Ramsay Jones1b3187b2010-12-14 18:26:38 +000029 test_commit 'SnapshotTests' 'i can has snapshot'
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040030"
31
Mark Radae39e0d32009-08-25 01:03:48 -040032
33cat >>gitweb_config.perl <<\EOF
34$feature{'snapshot'}{'override'} = 0;
35EOF
36
37test_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'
Mark Radae39e0d32009-08-25 01:03:48 -040047
48
49cat >>gitweb_config.perl <<\EOF
50$feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
51EOF
52
53test_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'
Mark Radae39e0d32009-08-25 01:03:48 -040063
64
65cat >>gitweb_config.perl <<\EOF
66$known_snapshot_formats{'zip'}{'disabled'} = 1;
67EOF
68
69test_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'
73test_debug 'cat gitweb.output'
74
75
76cat >>gitweb_config.perl <<\EOF
77$known_snapshot_formats{'tgz'}{'disabled'} = 0;
78EOF
79
80test_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'
Jakub Narebski745a2db2010-01-30 23:30:38 +010084test_debug 'cat gitweb.headers'
Mark Radae39e0d32009-08-25 01:03:48 -040085
86
Mark Radafdb0c362009-09-26 13:46:08 -040087# ----------------------------------------------------------------------
88# snapshot hash ids
89
90test_expect_success 'snapshots: good tree-ish id' '
Johannes Schindelin765577b2020-11-18 23:44:43 +000091 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
Mark Radafdb0c362009-09-26 13:46:08 -040092 grep "Status: 200 OK" gitweb.output
93'
Jakub Narebski745a2db2010-01-30 23:30:38 +010094test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -040095
96test_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'
100test_debug 'cat gitweb.output'
101
102test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
103 echo object > tag-object &&
104 git add tag-object &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400105 test_tick && git commit -m "Object to be tagged" &&
Elia Pinto9c103772016-01-12 11:49:37 +0000106 git tag tagged-object $(git hash-object tag-object) &&
Mark Radafdb0c362009-09-26 13:46:08 -0400107 gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
108 grep "400 - Object is not a tree-ish" gitweb.output
109'
110test_debug 'cat gitweb.output'
111
112test_expect_success 'snapshots: good object id' '
Elia Pinto9c103772016-01-12 11:49:37 +0000113 ID=$(git rev-parse --verify HEAD) &&
Mark Radafdb0c362009-09-26 13:46:08 -0400114 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
115 grep "Status: 200 OK" gitweb.output
116'
Jakub Narebski745a2db2010-01-30 23:30:38 +0100117test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -0400118
119test_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'
123test_debug 'cat gitweb.output'
124
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400125# ----------------------------------------------------------------------
126# modification times (Last-Modified and If-Modified-Since)
127
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100128test_expect_success DATE_PARSER 'modification: feed last-modified' '
Johannes Schindelin765577b2020-11-18 23:44:43 +0000129 gitweb_run "p=.git;a=atom;h=main" &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400130 grep "Status: 200 OK" gitweb.headers &&
131 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
132'
133test_debug 'cat gitweb.headers'
134
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100135test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200136 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
137 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400138 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000139 gitweb_run "p=.git;a=atom;h=main" &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400140 grep "Status: 200 OK" gitweb.headers
141'
142test_debug 'cat gitweb.headers'
143
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100144test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200145 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
146 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400147 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000148 gitweb_run "p=.git;a=atom;h=main" &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400149 grep "Status: 304 Not Modified" gitweb.headers
150'
151test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -0400152
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100153test_expect_success DATE_PARSER 'modification: snapshot last-modified' '
Johannes Schindelin765577b2020-11-18 23:44:43 +0000154 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
W. Trevor King8745db62012-03-29 08:45:49 -0400155 grep "Status: 200 OK" gitweb.headers &&
156 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
157'
158test_debug 'cat gitweb.headers'
159
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100160test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200161 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
162 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400163 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000164 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
W. Trevor King8745db62012-03-29 08:45:49 -0400165 grep "Status: 200 OK" gitweb.headers
166'
167test_debug 'cat gitweb.headers'
168
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100169test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200170 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
171 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400172 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000173 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
W. Trevor King8745db62012-03-29 08:45:49 -0400174 grep "Status: 304 Not Modified" gitweb.headers
175'
176test_debug 'cat gitweb.headers'
177
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100178test_expect_success DATE_PARSER 'modification: tree snapshot' '
Elia Pinto9c103772016-01-12 11:49:37 +0000179 ID=$(git rev-parse --verify HEAD^{tree}) &&
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200180 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
181 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400182 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'
187test_debug 'cat gitweb.headers'
188
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100189# ----------------------------------------------------------------------
190# load checking
191
192# always hit the load limit
193cat >>gitweb_config.perl <<\EOF
Brian Gernhardtab354692010-02-06 09:50:03 -0500194our $maxload = -1;
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100195EOF
196
Brian Gernhardtab354692010-02-06 09:50:03 -0500197test_expect_success 'load checking: load too high (default action)' '
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100198 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'
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100202test_debug 'cat gitweb.headers'
203
204# turn off load checking
205cat >>gitweb_config.perl <<\EOF
206our $maxload = undef;
207EOF
208
209
Jakub Narebski36612e42012-02-28 19:41:47 +0100210# ----------------------------------------------------------------------
211# invalid arguments
212
213test_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'
218test_debug 'cat gitweb.headers'
219
Mark Radae39e0d32009-08-25 01:03:48 -0400220test_done