t / t9501-gitweb-standalone-http-status.shon commit Merge branch 'mg/rebase-i-onto-reflog-in-full' (4514de7)
   1#!/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
  15#
  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
  22# ----------------------------------------------------------------------
  23# snapshot settings
  24
  25test_expect_success 'setup' "
  26        test_commit 'SnapshotTests' 'i can has snapshot'
  27"
  28
  29
  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'
  44
  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'
  60
  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'
  81test_debug 'cat gitweb.headers'
  82
  83
  84# ----------------------------------------------------------------------
  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'
  91test_debug 'cat gitweb.headers'
  92
  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 &&
 102        test_tick && git commit -m "Object to be tagged" &&
 103        git tag tagged-object `git hash-object tag-object` &&
 104        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' '
 110        ID=`git rev-parse --verify HEAD` &&
 111        gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
 112        grep "Status: 200 OK" gitweb.output
 113'
 114test_debug 'cat gitweb.headers'
 115
 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
 122# ----------------------------------------------------------------------
 123# modification times (Last-Modified and If-Modified-Since)
 124
 125test_expect_success DATE_PARSER 'modification: feed last-modified' '
 126        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
 132test_expect_success DATE_PARSER 'modification: feed if-modified-since (modified)' '
 133        export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
 134        test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
 135        gitweb_run "p=.git;a=atom;h=master" &&
 136        grep "Status: 200 OK" gitweb.headers
 137'
 138test_debug 'cat gitweb.headers'
 139
 140test_expect_success DATE_PARSER 'modification: feed if-modified-since (unmodified)' '
 141        export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
 142        test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
 143        gitweb_run "p=.git;a=atom;h=master" &&
 144        grep "Status: 304 Not Modified" gitweb.headers
 145'
 146test_debug 'cat gitweb.headers'
 147
 148test_expect_success DATE_PARSER 'modification: snapshot last-modified' '
 149        gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
 150        grep "Status: 200 OK" gitweb.headers &&
 151        grep "Last-modified: Thu, 7 Apr 2005 22:14:13 +0000" gitweb.headers
 152'
 153test_debug 'cat gitweb.headers'
 154
 155test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (modified)' '
 156        export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
 157        test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
 158        gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
 159        grep "Status: 200 OK" gitweb.headers
 160'
 161test_debug 'cat gitweb.headers'
 162
 163test_expect_success DATE_PARSER 'modification: snapshot if-modified-since (unmodified)' '
 164        export HTTP_IF_MODIFIED_SINCE="Thu, 7 Apr 2005 22:14:13 +0000" &&
 165        test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
 166        gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
 167        grep "Status: 304 Not Modified" gitweb.headers
 168'
 169test_debug 'cat gitweb.headers'
 170
 171test_expect_success DATE_PARSER 'modification: tree snapshot' '
 172        ID=`git rev-parse --verify HEAD^{tree}` &&
 173        export HTTP_IF_MODIFIED_SINCE="Wed, 6 Apr 2005 22:14:13 +0000" &&
 174        test_when_finished "unset HTTP_IF_MODIFIED_SINCE" &&
 175        gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
 176        grep "Status: 200 OK" gitweb.headers &&
 177        ! grep -i "last-modified" gitweb.headers
 178'
 179test_debug 'cat gitweb.headers'
 180
 181# ----------------------------------------------------------------------
 182# load checking
 183
 184# always hit the load limit
 185cat >>gitweb_config.perl <<\EOF
 186our $maxload = -1;
 187EOF
 188
 189test_expect_success 'load checking: load too high (default action)' '
 190        gitweb_run "p=.git" &&
 191        grep "Status: 503 Service Unavailable" gitweb.headers &&
 192        grep "503 - The load average on the server is too high" gitweb.body
 193'
 194test_debug 'cat gitweb.headers'
 195
 196# turn off load checking
 197cat >>gitweb_config.perl <<\EOF
 198our $maxload = undef;
 199EOF
 200
 201
 202# ----------------------------------------------------------------------
 203# invalid arguments
 204
 205test_expect_success 'invalid arguments: invalid regexp (in project search)' '
 206        gitweb_run "a=project_list;s=*\.git;sr=1" &&
 207        grep "Status: 400" gitweb.headers &&
 208        grep "400 - Invalid.*regexp" gitweb.body
 209'
 210test_debug 'cat gitweb.headers'
 211
 212test_done