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