t / lib-httpd.shon commit Merge branch 'as/test-name-alias-uniquely' (8d1b1a0)
   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
  46# hack to suppress apache PassEnv warnings
  47GIT_VALGRIND=$GIT_VALGRIND; export GIT_VALGRIND
  48GIT_VALGRIND_OPTIONS=$GIT_VALGRIND_OPTIONS; export GIT_VALGRIND_OPTIONS
  49
  50if ! test -x "$LIB_HTTPD_PATH"
  51then
  52        skip_all="skipping test, no web server found at '$LIB_HTTPD_PATH'"
  53        test_done
  54fi
  55
  56HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \
  57        sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'`
  58
  59if test -n "$HTTPD_VERSION"
  60then
  61        if test -z "$LIB_HTTPD_MODULE_PATH"
  62        then
  63                if ! test $HTTPD_VERSION -ge 2
  64                then
  65                        skip_all="skipping test, at least Apache version 2 is required"
  66                        test_done
  67                fi
  68                if ! test -d "$DEFAULT_HTTPD_MODULE_PATH"
  69                then
  70                        skip_all="Apache module directory not found.  Skipping tests."
  71                        test_done
  72                fi
  73
  74                LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH"
  75        fi
  76else
  77        error "Could not identify web server at '$LIB_HTTPD_PATH'"
  78fi
  79
  80prepare_httpd() {
  81        mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH"
  82        cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH"
  83
  84        ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules"
  85
  86        if test -n "$LIB_HTTPD_SSL"
  87        then
  88                HTTPD_PROTO=https
  89
  90                RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \
  91                        -config "$TEST_PATH/ssl.cnf" \
  92                        -new -x509 -nodes \
  93                        -out "$HTTPD_ROOT_PATH/httpd.pem" \
  94                        -keyout "$HTTPD_ROOT_PATH/httpd.pem"
  95                GIT_SSL_NO_VERIFY=t
  96                export GIT_SSL_NO_VERIFY
  97                HTTPD_PARA="$HTTPD_PARA -DSSL"
  98        else
  99                HTTPD_PROTO=http
 100        fi
 101        HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT
 102        HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST
 103        HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST
 104        HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:user%40host@$HTTPD_DEST
 105
 106        if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN"
 107        then
 108                HTTPD_PARA="$HTTPD_PARA -DDAV"
 109
 110                if test -n "$LIB_HTTPD_SVN"
 111                then
 112                        HTTPD_PARA="$HTTPD_PARA -DSVN"
 113                        rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo"
 114                        svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn"
 115                fi
 116        fi
 117}
 118
 119start_httpd() {
 120        prepare_httpd >&3 2>&4
 121
 122        trap 'code=$?; stop_httpd; (exit $code); die' EXIT
 123
 124        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
 125                -f "$TEST_PATH/apache.conf" $HTTPD_PARA \
 126                -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start \
 127                >&3 2>&4
 128        if test $? -ne 0
 129        then
 130                skip_all="skipping test, web server setup failed"
 131                trap 'die' EXIT
 132                test_done
 133        fi
 134}
 135
 136stop_httpd() {
 137        trap 'die' EXIT
 138
 139        "$LIB_HTTPD_PATH" -d "$HTTPD_ROOT_PATH" \
 140                -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop
 141}
 142
 143test_http_push_nonff() {
 144        REMOTE_REPO=$1
 145        LOCAL_REPO=$2
 146        BRANCH=$3
 147
 148        test_expect_success 'non-fast-forward push fails' '
 149                cd "$REMOTE_REPO" &&
 150                HEAD=$(git rev-parse --verify HEAD) &&
 151
 152                cd "$LOCAL_REPO" &&
 153                git checkout $BRANCH &&
 154                echo "changed" > path2 &&
 155                git commit -a -m path2 --amend &&
 156
 157                test_must_fail git push -v origin >output 2>&1 &&
 158                (cd "$REMOTE_REPO" &&
 159                 test $HEAD = $(git rev-parse --verify HEAD))
 160        '
 161
 162        test_expect_success 'non-fast-forward push show ref status' '
 163                grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output
 164        '
 165
 166        test_expect_success 'non-fast-forward push shows help message' '
 167                test_i18ngrep "Updates were rejected because" output
 168        '
 169}
 170
 171setup_askpass_helper() {
 172        test_expect_success 'setup askpass helper' '
 173                write_script "$TRASH_DIRECTORY/askpass" <<-\EOF &&
 174                echo >>"$TRASH_DIRECTORY/askpass-query" "askpass: $*" &&
 175                cat "$TRASH_DIRECTORY/askpass-response"
 176                EOF
 177                GIT_ASKPASS="$TRASH_DIRECTORY/askpass" &&
 178                export GIT_ASKPASS &&
 179                export TRASH_DIRECTORY
 180        '
 181}
 182
 183set_askpass() {
 184        >"$TRASH_DIRECTORY/askpass-query" &&
 185        echo "$*" >"$TRASH_DIRECTORY/askpass-response"
 186}
 187
 188expect_askpass() {
 189        dest=$HTTPD_DEST
 190        {
 191                case "$1" in
 192                none)
 193                        ;;
 194                pass)
 195                        echo "askpass: Password for 'http://$2@$dest': "
 196                        ;;
 197                both)
 198                        echo "askpass: Username for 'http://$dest': "
 199                        echo "askpass: Password for 'http://$2@$dest': "
 200                        ;;
 201                *)
 202                        false
 203                        ;;
 204                esac
 205        } >"$TRASH_DIRECTORY/askpass-expect" &&
 206        test_cmp "$TRASH_DIRECTORY/askpass-expect" \
 207                 "$TRASH_DIRECTORY/askpass-query"
 208}