t / t9501-gitweb-standalone-http-status.shon commit Merge branch 'jn/makedepend' (a026d53)
   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# snapshot settings
  17
  18test_commit \
  19        'SnapshotTests' \
  20        'i can has snapshot?'
  21
  22cat >>gitweb_config.perl <<\EOF
  23$feature{'snapshot'}{'override'} = 0;
  24EOF
  25
  26test_expect_success \
  27    'snapshots: tgz only default format enabled' \
  28    'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
  29    grep "Status: 200 OK" gitweb.output &&
  30    gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
  31    grep "403 - Unsupported snapshot format" gitweb.output &&
  32    gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
  33    grep "403 - Snapshot format not allowed" gitweb.output &&
  34    gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
  35    grep "403 - Unsupported snapshot format" gitweb.output'
  36
  37
  38cat >>gitweb_config.perl <<\EOF
  39$feature{'snapshot'}{'default'} = ['tgz','tbz2','txz','zip'];
  40EOF
  41
  42test_expect_success \
  43    'snapshots: all enabled in default, use default disabled value' \
  44    'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
  45    grep "Status: 200 OK" gitweb.output &&
  46    gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tbz2" &&
  47    grep "Status: 200 OK" gitweb.output &&
  48    gitweb_run "p=.git;a=snapshot;h=HEAD;sf=txz" &&
  49    grep "403 - Snapshot format not allowed" gitweb.output &&
  50    gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
  51    grep "Status: 200 OK" gitweb.output'
  52
  53
  54cat >>gitweb_config.perl <<\EOF
  55$known_snapshot_formats{'zip'}{'disabled'} = 1;
  56EOF
  57
  58test_expect_success \
  59    'snapshots: zip explicitly disabled' \
  60    'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=zip" &&
  61    grep "403 - Snapshot format not allowed" gitweb.output'
  62test_debug 'cat gitweb.output'
  63
  64
  65cat >>gitweb_config.perl <<\EOF
  66$known_snapshot_formats{'tgz'}{'disabled'} = 0;
  67EOF
  68
  69test_expect_success \
  70    'snapshots: tgz explicitly enabled' \
  71    'gitweb_run "p=.git;a=snapshot;h=HEAD;sf=tgz" &&
  72    grep "Status: 200 OK" gitweb.output'
  73test_debug 'cat gitweb.headers'
  74
  75
  76# ----------------------------------------------------------------------
  77# snapshot hash ids
  78
  79test_expect_success 'snapshots: good tree-ish id' '
  80        gitweb_run "p=.git;a=snapshot;h=master;sf=tgz" &&
  81        grep "Status: 200 OK" gitweb.output
  82'
  83test_debug 'cat gitweb.headers'
  84
  85test_expect_success 'snapshots: bad tree-ish id' '
  86        gitweb_run "p=.git;a=snapshot;h=frizzumFrazzum;sf=tgz" &&
  87        grep "404 - Object does not exist" gitweb.output
  88'
  89test_debug 'cat gitweb.output'
  90
  91test_expect_success 'snapshots: bad tree-ish id (tagged object)' '
  92        echo object > tag-object &&
  93        git add tag-object &&
  94        git commit -m "Object to be tagged" &&
  95        git tag tagged-object `git hash-object tag-object` &&
  96        gitweb_run "p=.git;a=snapshot;h=tagged-object;sf=tgz" &&
  97        grep "400 - Object is not a tree-ish" gitweb.output
  98'
  99test_debug 'cat gitweb.output'
 100
 101test_expect_success 'snapshots: good object id' '
 102        ID=`git rev-parse --verify HEAD` &&
 103        gitweb_run "p=.git;a=snapshot;h=$ID;sf=tgz" &&
 104        grep "Status: 200 OK" gitweb.output
 105'
 106test_debug 'cat gitweb.headers'
 107
 108test_expect_success 'snapshots: bad object id' '
 109        gitweb_run "p=.git;a=snapshot;h=abcdef01234;sf=tgz" &&
 110        grep "404 - Object does not exist" gitweb.output
 111'
 112test_debug 'cat gitweb.output'
 113
 114
 115# ----------------------------------------------------------------------
 116# load checking
 117
 118# always hit the load limit
 119cat >>gitweb_config.perl <<\EOF
 120our $maxload = -1;
 121EOF
 122
 123test_expect_success 'load checking: load too high (default action)' '
 124        gitweb_run "p=.git" &&
 125        grep "Status: 503 Service Unavailable" gitweb.headers &&
 126        grep "503 - The load average on the server is too high" gitweb.body
 127'
 128test_debug 'cat gitweb.log' # just in case
 129test_debug 'cat gitweb.headers'
 130
 131# turn off load checking
 132cat >>gitweb_config.perl <<\EOF
 133our $maxload = undef;
 134EOF
 135
 136
 137test_done