t / lib-httpd.shon commit Merge branch 'jc/refactor-diff-stdin' (d7afe64)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at>
   4#
   5
   6if test -z "$GIT_TEST_HTTPD"
   7then
   8        skip_all="Network testing disabled (define GIT_TEST_HTTPD to enable)"
   9        test_done
  10fi
  11
  12HTTPD_PARA=""
  13
  14for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2'
  15do
  16        if test -x "$DEFAULT_HTTPD_PATH"
  17        then
  18                break
  19        fi
  20done
  21
  22for DEFAULT_HTTPD_MODULE_PATH in '/usr/libexec/apache2' \
  23                                 '/usr/lib/apache2/modules' \
  24                                 '/usr/lib64/httpd/modules' \
  25                                 '/usr/lib/httpd/modules'
  26do
  27        if test -d "$DEFAULT_HTTPD_MODULE_PATH"
  28        then
  29                break
  30        fi
  31done
  32
  33case $(uname) in
  34        Darwin)
  35                HTTPD_PARA="$HTTPD_PARA -DDarwin"
  36        ;;
  37esac
  38
  39LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"}
  40LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'}
  41
  42TEST_PATH="$TEST_DIRECTORY"/lib-httpd
  43HTTPD_ROOT_PATH="$PWD"/httpd
  44HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www
  45
  46if ! test -x "$LIB_HTTPD_PATH"
  47then
  48        skip_all="skipping test, no web server found at '$LIB_HTTPD_PATH'"
  49        test_done
  50fi
  51
  52HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
  53        sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
  54
  55if test -n "$HTTPD_VERSION"
  56then
  57        if test -z "$LIB_HTTPD_MODULE_PATH"
  58        then
  59                if ! test $HTTPD_VERSION -ge 2
  60                then
  61                        skip_all="skipping test, at least Apache version 2 is required"
  62                        test_done
  63                fi
  64                if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
  65                then
  66                        skip_all="Apache module directory not found.  Skipping tests."
  67                        test_done
  68                fi
  69
  70                LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
  71        fi
  72else
  73        error "Could not identify web server at '$LIB_HTTPD_PATH'"
  74fi
  75
  76prepare_httpd() {
  77        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
  78        cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
  79
  80        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
  81
  82        if test -n "$LIB_HTTPD_SSL"
  83        then
  84                HTTPD_PROTO=https
  85
  86                RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
  87                        -config "$TEST_PATH/ssl.cnf" \
  88                        -new -x509 -nodes \
  89                        -out "$HTTPD_ROOT_PATH/httpd.pem" \
  90                        -keyout "$HTTPD_ROOT_PATH/httpd.pem"
  91                GIT_SSL_NO_VERIFY=t
  92                export GIT_SSL_NO_VERIFY
  93                HTTPD_PARA="$HTTPD_PARA -DSSL"
  94        else
  95                HTTPD_PROTO=http
  96        fi
  97        HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT
  98        HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST
  99        HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST
 100        HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:user%40host@$HTTPD_DEST
 101
 102        if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
 103        then
 104                HTTPD_PARA="$HTTPD_PARA -DDAV"
 105
 106                if test -n "$LIB_HTTPD_SVN"
 107                then
 108                        HTTPD_PARA="$HTTPD_PARA -DSVN"
 109                        rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
 110                        svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
 111                fi
 112        fi
 113}
 114
 115start_httpd() {
 116        prepare_httpd >&3 2>&4
 117
 118        trap 'code=$?; stop_httpd; (exit $code); die' EXIT
 119
 120        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
 121                -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
 122                -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
 123                >&3 2>&4
 124        if test $? -ne 0
 125        then
 126                skip_all="skipping test, web server setup failed"
 127                trap 'die' EXIT
 128                test_done
 129        fi
 130}
 131
 132stop_httpd() {
 133        trap 'die' EXIT
 134
 135        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
 136                -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
 137}
 138
 139test_http_push_nonff() {
 140        REMOTE_REPO=$1
 141        LOCAL_REPO=$2
 142        BRANCH=$3
 143
 144        test_expect_success 'non-fast-forward push fails' '
 145                cd "$REMOTE_REPO" &&
 146                HEAD=$(git rev-parse --verify HEAD) &&
 147
 148                cd "$LOCAL_REPO" &&
 149                git checkout $BRANCH &&
 150                echo "changed" > path2 &&
 151                git commit -a -m path2 --amend &&
 152
 153                test_must_fail git push -v origin >output 2>&1 &&
 154                (cd "$REMOTE_REPO" &&
 155                 test $HEAD = $(git rev-parse --verify HEAD))
 156        '
 157
 158        test_expect_success 'non-fast-forward push show ref status' '
 159                grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
 160        '
 161
 162        test_expect_success 'non-fast-forward push shows help message' '
 163                test_i18ngrep "Updates were rejected because" output
 164        '
 165}