Skip to content

Commit

Permalink
Merge branch 'tc/smart-http-restrict'
Browse files Browse the repository at this point in the history
* tc/smart-http-restrict:
  Test t5560: Fix test when run with dash
  Smart-http tests: Test http-backend without curl or a webserver
  Smart-http tests: Break test t5560-http-backend into pieces
  Smart-http tests: Improve coverage in test t5560
  Smart-http: check if repository is OK to export before serving it
  • Loading branch information
Junio C Hamano committed Jan 17, 2010
2 parents 4fa0882 + e8189ee commit d060507
Show file tree
Hide file tree
Showing 7 changed files with 362 additions and 260 deletions.
10 changes: 10 additions & 0 deletions Documentation/git-http-backend.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ The program supports clients fetching using both the smart HTTP protcol
and the backwards-compatible dumb HTTP protocol, as well as clients
pushing using the smart HTTP protocol.

It verifies that the directory has the magic file
"git-daemon-export-ok", and it will refuse to export any git directory
that hasn't explicitly been marked for export this way (unless the
GIT_HTTP_EXPORT_ALL environmental variable is set).

By default, only the `upload-pack` service is enabled, which serves
'git-fetch-pack' and 'git-ls-remote' clients, which are invoked from
'git-fetch', 'git-pull', and 'git-clone'. If the client is authenticated,
Expand Down Expand Up @@ -70,6 +75,7 @@ Apache 2.x::
+
----------------------------------------------------------------
SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
----------------------------------------------------------------
+
Expand Down Expand Up @@ -157,6 +163,10 @@ by the invoking web server, including:
* QUERY_STRING
* REQUEST_METHOD

The GIT_HTTP_EXPORT_ALL environmental variable may be passed to
'git-http-backend' to bypass the check for the "git-daemon-export-ok"
file in each repository before allowing export of that repository.

The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and
GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
ensuring that any reflogs created by 'git-receive-pack' contain some
Expand Down
3 changes: 3 additions & 0 deletions http-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ int main(int argc, char **argv)
setup_path();
if (!enter_repo(dir, 0))
not_found("Not a git repository: '%s'", dir);
if (!getenv("GIT_HTTP_EXPORT_ALL") &&
access("git-daemon-export-ok", F_OK) )
not_found("Repository not exported: '%s'", dir);

git_config(http_config, NULL);
cmd->imp(cmd_arg);
Expand Down
5 changes: 5 additions & 0 deletions t/lib-httpd/apache.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ Alias /dumb/ www/

<Location /smart/>
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
SetEnv GIT_HTTP_EXPORT_ALL
</Location>
<Location /smart_noexport/>
SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH}
</Location>
ScriptAlias /smart/ ${GIT_EXEC_PATH}/git-http-backend/
ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/
<Directory ${GIT_EXEC_PATH}>
Options None
</Directory>
Expand Down
73 changes: 73 additions & 0 deletions t/t5560-http-backend-noserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/sh

test_description='test git-http-backend-noserver'
. ./test-lib.sh

HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY"

run_backend() {
echo "$2" |
QUERY_STRING="${1#*\?}" \
GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \
PATH_INFO="${1%%\?*}" \
git http-backend >act.out 2>act.err
}

GET() {
export REQUEST_METHOD="GET" &&
run_backend "/repo.git/$1" &&
unset REQUEST_METHOD &&
if ! grep "Status" act.out >act
then
printf "Status: 200 OK\r\n" >act
fi
printf "Status: $2\r\n" >exp &&
test_cmp exp act
}

POST() {
export REQUEST_METHOD="POST" &&
export CONTENT_TYPE="application/x-$1-request" &&
run_backend "/repo.git/$1" "$2" &&
unset REQUEST_METHOD &&
unset CONTENT_TYPE &&
if ! grep "Status" act.out >act
then
printf "Status: 200 OK\r\n" >act
fi
printf "Status: $3\r\n" >exp &&
test_cmp exp act
}

log_div() {
return 0
}

. "$TEST_DIRECTORY"/t556x_common

expect_aliased() {
export REQUEST_METHOD="GET" &&
if test $1 = 0; then
run_backend "$2"
else
run_backend "$2" &&
echo "fatal: '$2': aliased" >exp.err &&
test_cmp exp.err act.err
fi
unset REQUEST_METHOD
}

test_expect_success 'http-backend blocks bad PATH_INFO' '
config http.getanyfile true &&
expect_aliased 0 /repo.git/HEAD &&
expect_aliased 1 /repo.git/../HEAD &&
expect_aliased 1 /../etc/passwd &&
expect_aliased 1 ../etc/passwd &&
expect_aliased 1 /etc//passwd &&
expect_aliased 1 /etc/./passwd &&
expect_aliased 1 //domain/data.txt
'

test_done
260 changes: 0 additions & 260 deletions t/t5560-http-backend.sh

This file was deleted.

Loading

0 comments on commit d060507

Please sign in to comment.