Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 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 | |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 13 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 14 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 15 | |
Ævar Arnfjörð Bjarmason | 7a98d9a | 2022-04-13 22:01:47 +0200 | [diff] [blame] | 16 | TEST_PASSES_SANITIZE_LEAK=true |
Ævar Arnfjörð Bjarmason | 3fca1fc | 2021-02-09 22:41:53 +0100 | [diff] [blame] | 17 | . ./lib-gitweb.sh |
Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 18 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 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 | |
Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 26 | # ---------------------------------------------------------------------- |
| 27 | # snapshot settings |
| 28 | |
Brian Gernhardt | 4a45f7d | 2010-03-20 04:29:11 -0400 | [diff] [blame] | 29 | test_expect_success 'setup' " |
Ramsay Jones | 1b3187b | 2010-12-14 18:26:38 +0000 | [diff] [blame] | 30 | test_commit 'SnapshotTests' 'i can has snapshot' |
Brian Gernhardt | 4a45f7d | 2010-03-20 04:29:11 -0400 | [diff] [blame] | 31 | " |
| 32 | |
Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 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' |
Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 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' |
Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 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' |
Jakub Narebski | 745a2db | 2010-01-30 23:30:38 +0100 | [diff] [blame] | 85 | test_debug 'cat gitweb.headers' |
Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 86 | |
| 87 | |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 88 | # ---------------------------------------------------------------------- |
| 89 | # snapshot hash ids |
| 90 | |
| 91 | test_expect_success 'snapshots: good tree-ish id' ' |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 92 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 93 | grep "Status: 200 OK" gitweb.output |
| 94 | ' |
Jakub Narebski | 745a2db | 2010-01-30 23:30:38 +0100 | [diff] [blame] | 95 | test_debug 'cat gitweb.headers' |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 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 && |
W. Trevor King | b7d565e | 2012-03-29 08:45:48 -0400 | [diff] [blame] | 106 | test_tick && git commit -m "Object to be tagged" && |
Elia Pinto | 9c10377 | 2016-01-12 11:49:37 +0000 | [diff] [blame] | 107 | git tag tagged-object $(git hash-object tag-object) && |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 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' ' |
Elia Pinto | 9c10377 | 2016-01-12 11:49:37 +0000 | [diff] [blame] | 114 | ID=$(git rev-parse --verify HEAD) && |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 115 | gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" && |
| 116 | grep "Status: 200 OK" gitweb.output |
| 117 | ' |
Jakub Narebski | 745a2db | 2010-01-30 23:30:38 +0100 | [diff] [blame] | 118 | test_debug 'cat gitweb.headers' |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 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 | |
W. Trevor King | b7d565e | 2012-03-29 08:45:48 -0400 | [diff] [blame] | 126 | # ---------------------------------------------------------------------- |
| 127 | # modification times (Last-Modified and If-Modified-Since) |
| 128 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 129 | test_expect_success DATE_PARSER 'modification: feed last-modified' ' |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 130 | gitweb_run "p=.git;a=atom;h=main" && |
W. Trevor King | b7d565e | 2012-03-29 08:45:48 -0400 | [diff] [blame] | 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 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 136 | test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' ' |
Torsten Bögershausen | d87ec81 | 2013-04-26 11:18:07 +0200 | [diff] [blame] | 137 | HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && |
| 138 | export HTTP_IF_MODIFIED_SINCE && |
W. Trevor King | b7d565e | 2012-03-29 08:45:48 -0400 | [diff] [blame] | 139 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 140 | gitweb_run "p=.git;a=atom;h=main" && |
W. Trevor King | b7d565e | 2012-03-29 08:45:48 -0400 | [diff] [blame] | 141 | grep "Status: 200 OK" gitweb.headers |
| 142 | ' |
| 143 | test_debug 'cat gitweb.headers' |
| 144 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 145 | test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' ' |
Torsten Bögershausen | d87ec81 | 2013-04-26 11:18:07 +0200 | [diff] [blame] | 146 | HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && |
| 147 | export HTTP_IF_MODIFIED_SINCE && |
W. Trevor King | b7d565e | 2012-03-29 08:45:48 -0400 | [diff] [blame] | 148 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 149 | gitweb_run "p=.git;a=atom;h=main" && |
W. Trevor King | b7d565e | 2012-03-29 08:45:48 -0400 | [diff] [blame] | 150 | grep "Status: 304 Not Modified" gitweb.headers |
| 151 | ' |
| 152 | test_debug 'cat gitweb.headers' |
Mark Rada | fdb0c36 | 2009-09-26 13:46:08 -0400 | [diff] [blame] | 153 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 154 | test_expect_success DATE_PARSER 'modification: snapshot last-modified' ' |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 155 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
W. Trevor King | 8745db6 | 2012-03-29 08:45:49 -0400 | [diff] [blame] | 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 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 161 | test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' ' |
Torsten Bögershausen | d87ec81 | 2013-04-26 11:18:07 +0200 | [diff] [blame] | 162 | HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && |
| 163 | export HTTP_IF_MODIFIED_SINCE && |
W. Trevor King | 8745db6 | 2012-03-29 08:45:49 -0400 | [diff] [blame] | 164 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 165 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
W. Trevor King | 8745db6 | 2012-03-29 08:45:49 -0400 | [diff] [blame] | 166 | grep "Status: 200 OK" gitweb.headers |
| 167 | ' |
| 168 | test_debug 'cat gitweb.headers' |
| 169 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 170 | test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' ' |
Torsten Bögershausen | d87ec81 | 2013-04-26 11:18:07 +0200 | [diff] [blame] | 171 | HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" && |
| 172 | export HTTP_IF_MODIFIED_SINCE && |
W. Trevor King | 8745db6 | 2012-03-29 08:45:49 -0400 | [diff] [blame] | 173 | test_when_finished "unset HTTP_IF_MODIFIED_SINCE" && |
Johannes Schindelin | 765577b | 2020-11-18 23:44:43 +0000 | [diff] [blame] | 174 | gitweb_run "p=.git;a=snapshot;h=main;sf=tgz" && |
W. Trevor King | 8745db6 | 2012-03-29 08:45:49 -0400 | [diff] [blame] | 175 | grep "Status: 304 Not Modified" gitweb.headers |
| 176 | ' |
| 177 | test_debug 'cat gitweb.headers' |
| 178 | |
Ramsay Jones | 2a8a449 | 2012-06-12 19:09:38 +0100 | [diff] [blame] | 179 | test_expect_success DATE_PARSER 'modification: tree snapshot' ' |
Elia Pinto | 9c10377 | 2016-01-12 11:49:37 +0000 | [diff] [blame] | 180 | ID=$(git rev-parse --verify HEAD^{tree}) && |
Torsten Bögershausen | d87ec81 | 2013-04-26 11:18:07 +0200 | [diff] [blame] | 181 | HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" && |
| 182 | export HTTP_IF_MODIFIED_SINCE && |
W. Trevor King | 8745db6 | 2012-03-29 08:45:49 -0400 | [diff] [blame] | 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 | |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 190 | # ---------------------------------------------------------------------- |
| 191 | # load checking |
| 192 | |
| 193 | # always hit the load limit |
| 194 | cat >>gitweb_config.perl <<\EOF |
Brian Gernhardt | ab35469 | 2010-02-06 09:50:03 -0500 | [diff] [blame] | 195 | our $maxload = -1; |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 196 | EOF |
| 197 | |
Brian Gernhardt | ab35469 | 2010-02-06 09:50:03 -0500 | [diff] [blame] | 198 | test_expect_success 'load checking: load too high (default action)' ' |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 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 | ' |
John 'Warthog9' Hawley | b62a1a9 | 2010-01-30 23:30:39 +0100 | [diff] [blame] | 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 | |
Jakub Narebski | 36612e4 | 2012-02-28 19:41:47 +0100 | [diff] [blame] | 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 | |
Mark Rada | e39e0d3 | 2009-08-25 01:03:48 -0400 | [diff] [blame] | 221 | test_done |