t / t5560-http-backend-noserver.shon commit bash: simple reimplementation of _get_comp_words_by_ref (dbda3b1)
   1#!/bin/sh
   2
   3test_description='test git-http-backend-noserver'
   4. ./test-lib.sh
   5
   6HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"
   7
   8run_backend() {
   9        echo "$2" |
  10        QUERY_STRING="${1#*\?}" \
  11        GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
  12        PATH_INFO="${1%%\?*}" \
  13        git http-backend >act.out 2>act.err
  14}
  15
  16GET() {
  17        export REQUEST_METHOD="GET" &&
  18        run_backend "/repo.git/$1" &&
  19        unset REQUEST_METHOD &&
  20        if ! grep "Status" act.out >act
  21        then
  22                printf "Status: 200 OK\r\n" >act
  23        fi
  24        printf "Status: $2\r\n" >exp &&
  25        test_cmp exp act
  26}
  27
  28POST() {
  29        export REQUEST_METHOD="POST" &&
  30        export CONTENT_TYPE="application/x-$1-request" &&
  31        run_backend "/repo.git/$1" "$2" &&
  32        unset REQUEST_METHOD &&
  33        unset CONTENT_TYPE &&
  34        if ! grep "Status" act.out >act
  35        then
  36                printf "Status: 200 OK\r\n" >act
  37        fi
  38        printf "Status: $3\r\n" >exp &&
  39        test_cmp exp act
  40}
  41
  42log_div() {
  43        return 0
  44}
  45
  46. "$TEST_DIRECTORY"/t556x_common
  47
  48expect_aliased() {
  49        export REQUEST_METHOD="GET" &&
  50        if test $1 = 0; then
  51                run_backend "$2"
  52        else
  53                run_backend "$2" &&
  54                echo "fatal: '$2': aliased" >exp.err &&
  55                test_cmp exp.err act.err
  56        fi
  57        unset REQUEST_METHOD
  58}
  59
  60test_expect_success 'http-backend blocks bad PATH_INFO' '
  61        config http.getanyfile true &&
  62
  63        expect_aliased 0 /repo.git/HEAD &&
  64
  65        expect_aliased 1 /repo.git/../HEAD &&
  66        expect_aliased 1 /../etc/passwd &&
  67        expect_aliased 1 ../etc/passwd &&
  68        expect_aliased 1 /etc//passwd &&
  69        expect_aliased 1 /etc/./passwd &&
  70        expect_aliased 1 //domain/data.txt
  71'
  72
  73test_done