blob: 2a0ffed870dd8634466bccfd0e435b5a304f8818 [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
13. ./gitweb-lib.sh
14
Ramsay Jones2a8a4492012-06-12 19:09:38 +010015#
16# Gitweb only provides the functionality tested by the 'modification times'
17# tests if it can access a date parser from one of these modules:
18#
19perl -MHTTP::Date -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
20perl -MTime::ParseDate -e 0 >/dev/null 2>&1 && test_set_prereq DATE_PARSER
21
Mark Radae39e0d32009-08-25 01:03:48 -040022# ----------------------------------------------------------------------
23# snapshot settings
24
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040025test_expect_success 'setup' "
Ramsay Jones1b3187b2010-12-14 18:26:38 +000026 test_commit 'SnapshotTests' 'i can has snapshot'
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040027"
28
Mark Radae39e0d32009-08-25 01:03:48 -040029
30cat >>gitweb_config.perl <<\EOF
31$feature{'snapshot'}{'override'} = 0;
32EOF
33
34test_expect_success \
35 'snapshots: tgz only default format enabled' \
36 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
37 grep "Status: 200 OK" gitweb.output &&
38 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
39 grep "403 - Unsupported snapshot format" gitweb.output &&
40 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
41 grep "403 - Snapshot format not allowed" gitweb.output &&
42 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
43 grep "403 - Unsupported snapshot format" gitweb.output'
Mark Radae39e0d32009-08-25 01:03:48 -040044
45
46cat >>gitweb_config.perl <<\EOF
47$feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
48EOF
49
50test_expect_success \
51 'snapshots: all enabled in default, use default disabled value' \
52 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
53 grep "Status: 200 OK" gitweb.output &&
54 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
55 grep "Status: 200 OK" gitweb.output &&
56 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
57 grep "403 - Snapshot format not allowed" gitweb.output &&
58 gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
59 grep "Status: 200 OK" gitweb.output'
Mark Radae39e0d32009-08-25 01:03:48 -040060
61
62cat >>gitweb_config.perl <<\EOF
63$known_snapshot_formats{'zip'}{'disabled'} = 1;
64EOF
65
66test_expect_success \
67 'snapshots: zip explicitly disabled' \
68 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
69 grep "403 - Snapshot format not allowed" gitweb.output'
70test_debug 'cat gitweb.output'
71
72
73cat >>gitweb_config.perl <<\EOF
74$known_snapshot_formats{'tgz'}{'disabled'} = 0;
75EOF
76
77test_expect_success \
78 'snapshots: tgz explicitly enabled' \
79 'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
80 grep "Status: 200 OK" gitweb.output'
Jakub Narebski745a2db2010-01-30 23:30:38 +010081test_debug 'cat gitweb.headers'
Mark Radae39e0d32009-08-25 01:03:48 -040082
83
Mark Radafdb0c362009-09-26 13:46:08 -040084# ----------------------------------------------------------------------
85# snapshot hash ids
86
87test_expect_success 'snapshots: good tree-ish id' '
88 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
89 grep "Status: 200 OK" gitweb.output
90'
Jakub Narebski745a2db2010-01-30 23:30:38 +010091test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -040092
93test_expect_success 'snapshots: bad tree-ish id' '
94 gitweb_run "p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz" &&
95 grep "404 - Object does not exist" gitweb.output
96'
97test_debug 'cat gitweb.output'
98
99test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
100 echo object > tag-object &&
101 git add tag-object &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400102 test_tick && git commit -m "Object to be tagged" &&
Elia Pinto9c103772016-01-12 11:49:37 +0000103 git tag tagged-object $(git hash-object tag-object) &&
Mark Radafdb0c362009-09-26 13:46:08 -0400104 gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
105 grep "400 - Object is not a tree-ish" gitweb.output
106'
107test_debug 'cat gitweb.output'
108
109test_expect_success 'snapshots: good object id' '
Elia Pinto9c103772016-01-12 11:49:37 +0000110 ID=$(git rev-parse --verify HEAD) &&
Mark Radafdb0c362009-09-26 13:46:08 -0400111 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
112 grep "Status: 200 OK" gitweb.output
113'
Jakub Narebski745a2db2010-01-30 23:30:38 +0100114test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -0400115
116test_expect_success 'snapshots: bad object id' '
117 gitweb_run "p=.git;a=snapshot;h=abcdef01234;sf=tgz" &&
118 grep "404 - Object does not exist" gitweb.output
119'
120test_debug 'cat gitweb.output'
121
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400122# ----------------------------------------------------------------------
123# modification times (Last-Modified and If-Modified-Since)
124
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100125test_expect_success DATE_PARSER 'modification: feed last-modified' '
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400126 gitweb_run "p=.git;a=atom;h=master" &&
127 grep "Status: 200 OK" gitweb.headers &&
128 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
129'
130test_debug 'cat gitweb.headers'
131
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100132test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200133 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
134 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400135 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
136 gitweb_run "p=.git;a=atom;h=master" &&
137 grep "Status: 200 OK" gitweb.headers
138'
139test_debug 'cat gitweb.headers'
140
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100141test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200142 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
143 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400144 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
145 gitweb_run "p=.git;a=atom;h=master" &&
146 grep "Status: 304 Not Modified" gitweb.headers
147'
148test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -0400149
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100150test_expect_success DATE_PARSER 'modification: snapshot last-modified' '
W. Trevor King8745db62012-03-29 08:45:49 -0400151 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
152 grep "Status: 200 OK" gitweb.headers &&
153 grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
154'
155test_debug 'cat gitweb.headers'
156
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100157test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200158 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
159 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400160 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
161 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
162 grep "Status: 200 OK" gitweb.headers
163'
164test_debug 'cat gitweb.headers'
165
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100166test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200167 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
168 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400169 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
170 gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
171 grep "Status: 304 Not Modified" gitweb.headers
172'
173test_debug 'cat gitweb.headers'
174
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100175test_expect_success DATE_PARSER 'modification: tree snapshot' '
Elia Pinto9c103772016-01-12 11:49:37 +0000176 ID=$(git rev-parse --verify HEAD^{tree}) &&
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200177 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
178 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400179 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
180 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
181 grep "Status: 200 OK" gitweb.headers &&
182 ! grep -i "last-modified" gitweb.headers
183'
184test_debug 'cat gitweb.headers'
185
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100186# ----------------------------------------------------------------------
187# load checking
188
189# always hit the load limit
190cat >>gitweb_config.perl <<\EOF
Brian Gernhardtab354692010-02-06 09:50:03 -0500191our $maxload = -1;
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100192EOF
193
Brian Gernhardtab354692010-02-06 09:50:03 -0500194test_expect_success 'load checking: load too high (default action)' '
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100195 gitweb_run "p=.git" &&
196 grep "Status: 503 Service Unavailable" gitweb.headers &&
197 grep "503 - The load average on the server is too high" gitweb.body
198'
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100199test_debug 'cat gitweb.headers'
200
201# turn off load checking
202cat >>gitweb_config.perl <<\EOF
203our $maxload = undef;
204EOF
205
206
Jakub Narebski36612e42012-02-28 19:41:47 +0100207# ----------------------------------------------------------------------
208# invalid arguments
209
210test_expect_success 'invalid arguments: invalid regexp (in project search)' '
211 gitweb_run "a=project_list;s=*\.git;sr=1" &&
212 grep "Status: 400" gitweb.headers &&
213 grep "400 - Invalid.*regexp" gitweb.body
214'
215test_debug 'cat gitweb.headers'
216
Mark Radae39e0d32009-08-25 01:03:48 -0400217test_done