589aaf82149916c43d42fad488567e34b26aebaa
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
   4#
   5
   6if test -z "$GIT_TEST_HTTPD"
   7then
   8        say "skipping test, network testing disabled by default"
   9        say "(define GIT_TEST_HTTPD to enable)"
  10        test_done
  11        exit
  12fi
  13
  14HTTPD_PARA=""
  15
  16case $(uname) in
  17        Darwin)
  18                DEFAULT_HTTPD_PATH='/usr/sbin/httpd'
  19                DEFAULT_HTTPD_MODULE_PATH='/usr/libexec/apache2'
  20                HTTPD_PARA="$HTTPD_PARA -DDarwin"
  21        ;;
  22        *)
  23                DEFAULT_HTTPD_PATH='/usr/sbin/apache2'
  24                DEFAULT_HTTPD_MODULE_PATH='/usr/lib/apache2/modules'
  25        ;;
  26esac
  27
  28LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"}
  29LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
  30
  31TEST_PATH="$TEST_DIRECTORY"/lib-httpd
  32HTTPD_ROOT_PATH="$PWD"/httpd
  33HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
  34
  35if ! test -x "$LIB_HTTPD_PATH"
  36then
  37        say "skipping test, no web server found at '$LIB_HTTPD_PATH'"
  38        test_done
  39        exit
  40fi
  41
  42HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
  43        sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
  44
  45if test -n "$HTTPD_VERSION"
  46then
  47        if test -z "$LIB_HTTPD_MODULE_PATH"
  48        then
  49                if ! test $HTTPD_VERSION -ge 2
  50                then
  51                        say "skipping test, at least Apache version 2 is required"
  52                        test_done
  53                        exit
  54                fi
  55
  56                LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
  57        fi
  58else
  59        error "Could not identify web server at '$LIB_HTTPD_PATH'"
  60fi
  61
  62prepare_httpd() {
  63        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
  64
  65        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
  66
  67        if test -n "$LIB_HTTPD_SSL"
  68        then
  69                HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT
  70
  71                RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
  72                        -config "$TEST_PATH/ssl.cnf" \
  73                        -new -x509 -nodes \
  74                        -out "$HTTPD_ROOT_PATH/httpd.pem" \
  75                        -keyout "$HTTPD_ROOT_PATH/httpd.pem"
  76                GIT_SSL_NO_VERIFY=t
  77                export GIT_SSL_NO_VERIFY
  78                HTTPD_PARA="$HTTPD_PARA -DSSL"
  79        else
  80                HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT
  81        fi
  82
  83        if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
  84        then
  85                HTTPD_PARA="$HTTPD_PARA -DDAV"
  86
  87                if test -n "$LIB_HTTPD_SVN"
  88                then
  89                        HTTPD_PARA="$HTTPD_PARA -DSVN"
  90                        rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
  91                        svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
  92                fi
  93        fi
  94}
  95
  96start_httpd() {
  97        prepare_httpd >&3 2>&4
  98
  99        trap 'stop_httpd; die' EXIT
 100
 101        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
 102                -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
 103                -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
 104                >&3 2>&4
 105        if ! test $? = 0; then
 106                say "skipping test, web server setup failed"
 107                test_done
 108        fi
 109}
 110
 111stop_httpd() {
 112        trap 'die' EXIT
 113
 114        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
 115                -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
 116}