blob: c900231079cf750f0f1111ca74ddca7803becf6c [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ð Bjarmason7a98d9a2022-04-13 22:01:47 +020016TEST_PASSES_SANITIZE_LEAK=true
Ævar Arnfjörð Bjarmason3fca1fc2021-02-09 22:41:53 +010017. ./lib-gitweb.sh
Mark Radae39e0d32009-08-25 01:03:48 -040018
Ramsay Jones2a8a4492012-06-12 19:09:38 +010019#
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
Mark Radae39e0d32009-08-25 01:03:48 -040026# ----------------------------------------------------------------------
27# snapshot settings
28
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040029test_expect_success 'setup' "
Ramsay Jones1b3187b2010-12-14 18:26:38 +000030 test_commit 'SnapshotTests' 'i can has snapshot'
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040031"
32
Mark Radae39e0d32009-08-25 01:03:48 -040033
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'
Mark Radae39e0d32009-08-25 01:03:48 -040048
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'
Mark Radae39e0d32009-08-25 01:03:48 -040064
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'
Jakub Narebski745a2db2010-01-30 23:30:38 +010085test_debug 'cat gitweb.headers'
Mark Radae39e0d32009-08-25 01:03:48 -040086
87
Mark Radafdb0c362009-09-26 13:46:08 -040088# ----------------------------------------------------------------------
89# snapshot hash ids
90
91test_expect_success 'snapshots: good tree-ish id' '
Johannes Schindelin765577b2020-11-18 23:44:43 +000092 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
Mark Radafdb0c362009-09-26 13:46:08 -040093 grep "Status: 200 OK" gitweb.output
94'
Jakub Narebski745a2db2010-01-30 23:30:38 +010095test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -040096
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 &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400106 test_tick && git commit -m "Object to be tagged" &&
Elia Pinto9c103772016-01-12 11:49:37 +0000107 git tag tagged-object $(git hash-object tag-object) &&
Mark Radafdb0c362009-09-26 13:46:08 -0400108 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' '
Elia Pinto9c103772016-01-12 11:49:37 +0000114 ID=$(git rev-parse --verify HEAD) &&
Mark Radafdb0c362009-09-26 13:46:08 -0400115 gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
116 grep "Status: 200 OK" gitweb.output
117'
Jakub Narebski745a2db2010-01-30 23:30:38 +0100118test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -0400119
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
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400126# ----------------------------------------------------------------------
127# modification times (Last-Modified and If-Modified-Since)
128
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100129test_expect_success DATE_PARSER 'modification: feed last-modified' '
Johannes Schindelin765577b2020-11-18 23:44:43 +0000130 gitweb_run "p=.git;a=atom;h=main" &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400131 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
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100136test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200137 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
138 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400139 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000140 gitweb_run "p=.git;a=atom;h=main" &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400141 grep "Status: 200 OK" gitweb.headers
142'
143test_debug 'cat gitweb.headers'
144
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100145test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200146 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
147 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400148 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000149 gitweb_run "p=.git;a=atom;h=main" &&
W. Trevor Kingb7d565e2012-03-29 08:45:48 -0400150 grep "Status: 304 Not Modified" gitweb.headers
151'
152test_debug 'cat gitweb.headers'
Mark Radafdb0c362009-09-26 13:46:08 -0400153
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100154test_expect_success DATE_PARSER 'modification: snapshot last-modified' '
Johannes Schindelin765577b2020-11-18 23:44:43 +0000155 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
W. Trevor King8745db62012-03-29 08:45:49 -0400156 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
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100161test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200162 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
163 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400164 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000165 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
W. Trevor King8745db62012-03-29 08:45:49 -0400166 grep "Status: 200 OK" gitweb.headers
167'
168test_debug 'cat gitweb.headers'
169
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100170test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' '
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200171 HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
172 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400173 test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
Johannes Schindelin765577b2020-11-18 23:44:43 +0000174 gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" &&
W. Trevor King8745db62012-03-29 08:45:49 -0400175 grep "Status: 304 Not Modified" gitweb.headers
176'
177test_debug 'cat gitweb.headers'
178
Ramsay Jones2a8a4492012-06-12 19:09:38 +0100179test_expect_success DATE_PARSER 'modification: tree snapshot' '
Elia Pinto9c103772016-01-12 11:49:37 +0000180 ID=$(git rev-parse --verify HEAD^{tree}) &&
Torsten Bögershausend87ec812013-04-26 11:18:07 +0200181 HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
182 export HTTP_IF_MODIFIED_SINCE &&
W. Trevor King8745db62012-03-29 08:45:49 -0400183 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
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100190# ----------------------------------------------------------------------
191# load checking
192
193# always hit the load limit
194cat >>gitweb_config.perl <<\EOF
Brian Gernhardtab354692010-02-06 09:50:03 -0500195our $maxload = -1;
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100196EOF
197
Brian Gernhardtab354692010-02-06 09:50:03 -0500198test_expect_success 'load checking: load too high (default action)' '
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100199 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'
John 'Warthog9' Hawleyb62a1a92010-01-30 23:30:39 +0100203test_debug 'cat gitweb.headers'
204
205# turn off load checking
206cat >>gitweb_config.perl <<\EOF
207our $maxload = undef;
208EOF
209
210
Jakub Narebski36612e42012-02-28 19:41:47 +0100211# ----------------------------------------------------------------------
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
Mark Radae39e0d32009-08-25 01:03:48 -0400221test_done