{"thread":{"id":"21485","subject":"[PATCH v5.1 3/3] http-backend: Test configuration options","startedAt":"2009-11-05T01:16:36Z","lastAt":"2009-11-05T01:16:38Z","messageCount":3,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":5,"patchTotal":3},"messages":[{"id":"126863","messageId":"1257383798-29826-1-git-send-email-spearce@spearce.org","threadId":"21485","inReplyTo":null,"subject":"[PATCH v5.1 1/3] http-backend: Remove pointless objects/info/* service entry","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-11-05T01:16:36Z","receivedAt":"2009-11-05T01:16:36Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"In earlier versions of this patch series this rule was used to\nmatch and serve objects/info/alternates and http-alternates.\nLater versions of the patch series explicitly called out match\nrules for those files, making this wildcard rule unnecessary.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n\n This probably should be squashed into the commit that introduces\n this CGI script (\"Git-aware CGI to provide dumb HTTP transport\").\n\n http-backend.c |    1 -\n 1 files changed, 0 insertions(+), 1 deletions(-)\n\ndiff --git a/http-backend.c b/http-backend.c\nindex 8e5c0a2..7900cda 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -558,7 +558,6 @@ static struct service_cmd {\n \t{\"GET\", \"/objects/info/alternates$\", get_text_file},\n \t{\"GET\", \"/objects/info/http-alternates$\", get_text_file},\n \t{\"GET\", \"/objects/info/packs$\", get_info_packs},\n-\t{\"GET\", \"/objects/info/[^/]*$\", get_text_file},\n \t{\"GET\", \"/objects/[0-9a-f]{2}/[0-9a-f]{38}$\", get_loose_object},\n \t{\"GET\", \"/objects/pack/pack-[0-9a-f]{40}\\\\.pack$\", get_pack_file},\n \t{\"GET\", \"/objects/pack/pack-[0-9a-f]{40}\\\\.idx$\", get_idx_file},\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126862","messageId":"1257383798-29826-2-git-send-email-spearce@spearce.org","threadId":"21485","inReplyTo":"1257383798-29826-1-git-send-email-spearce@spearce.org","subject":"[PATCH v5.1 2/3] http-backend: Use http.getanyfile to disable dumb HTTP serving","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-11-05T01:16:37Z","receivedAt":"2009-11-05T01:16:37Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Some repository owners may wish to enable smart HTTP, but disallow\ndumb content serving.  Disallowing dumb serving might be because\nthe owners want to rely upon reachability to control which objects\nclients may access from the repository, or they just want to\nencourage clients to use the more bandwidth efficient transport.\n\nIf http.getanyfile is set to false the backend CGI will return with\n'403 Forbidden' when an object file is accessed by a dumb client.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n Documentation/git-http-backend.txt |    8 ++++++++\n http-backend.c                     |   34 ++++++++++++++++++++++++++++------\n 2 files changed, 36 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-http-backend.txt b/Documentation/git-http-backend.txt\nindex f17251a..67aec06 100644\n--- a/Documentation/git-http-backend.txt\n+++ b/Documentation/git-http-backend.txt\n@@ -29,6 +29,14 @@ SERVICES\n These services can be enabled/disabled using the per-repository\n configuration file:\n \n+http.getanyfile::\n+\tThis serves older Git clients which are unable to use the\n+\tupload pack service.  When enabled, clients are able to read\n+\tany file within the repository, including objects that are\n+\tno longer reachable from a branch but are still present.\n+\tIt is enabled by default, but a repository can disable it\n+\tby setting this configuration item to `false`.\n+\n http.uploadpack::\n \tThis serves 'git-fetch-pack' and 'git-ls-remote' clients.\n \tIt is enabled by default, but a repository can disable it\ndiff --git a/http-backend.c b/http-backend.c\nindex 7900cda..9021266 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -10,6 +10,7 @@\n static const char content_type[] = \"Content-Type\";\n static const char content_length[] = \"Content-Length\";\n static const char last_modified[] = \"Last-Modified\";\n+static int getanyfile = 1;\n \n static struct string_list *query_params;\n \n@@ -194,6 +195,12 @@ static NORETURN void forbidden(const char *err, ...)\n \texit(0);\n }\n \n+static void select_getanyfile(void)\n+{\n+\tif (!getanyfile)\n+\t\tforbidden(\"Unsupported service: getanyfile\");\n+}\n+\n static void send_strbuf(const char *type, struct strbuf *buf)\n {\n \thdr_int(content_length, buf->len);\n@@ -238,38 +245,51 @@ static void send_file(const char *the_type, const char *name)\n \n static void get_text_file(char *name)\n {\n+\tselect_getanyfile();\n \thdr_nocache();\n \tsend_file(\"text/plain\", name);\n }\n \n static void get_loose_object(char *name)\n {\n+\tselect_getanyfile();\n \thdr_cache_forever();\n \tsend_file(\"application/x-git-loose-object\", name);\n }\n \n static void get_pack_file(char *name)\n {\n+\tselect_getanyfile();\n \thdr_cache_forever();\n \tsend_file(\"application/x-git-packed-objects\", name);\n }\n \n static void get_idx_file(char *name)\n {\n+\tselect_getanyfile();\n \thdr_cache_forever();\n \tsend_file(\"application/x-git-packed-objects-toc\", name);\n }\n \n static int http_config(const char *var, const char *value, void *cb)\n {\n-\tstruct rpc_service *svc = cb;\n-\n-\tif (!prefixcmp(var, \"http.\") &&\n-\t    !strcmp(var + 5, svc->config_name)) {\n-\t\tsvc->enabled = git_config_bool(var, value);\n+\tif (!strcmp(var, \"http.getanyfile\")) {\n+\t\tgetanyfile = git_config_bool(var, value);\n \t\treturn 0;\n \t}\n \n+\tif (!prefixcmp(var, \"http.\")) {\n+\t\tint i;\n+\n+\t\tfor (i = 0; i < ARRAY_SIZE(rpc_service); i++) {\n+\t\t\tstruct rpc_service *svc = &rpc_service[i];\n+\t\t\tif (!strcmp(var + 5, svc->config_name)) {\n+\t\t\t\tsvc->enabled = git_config_bool(var, value);\n+\t\t\t\treturn 0;\n+\t\t\t}\n+\t\t}\n+\t}\n+\n \t/* we are not interested in parsing any other configuration here */\n \treturn 0;\n }\n@@ -293,7 +313,6 @@ static struct rpc_service *select_service(const char *name)\n \tif (!svc)\n \t\tforbidden(\"Unsupported service: '%s'\", name);\n \n-\tgit_config(http_config, svc);\n \tif (svc->enabled < 0) {\n \t\tconst char *user = getenv(\"REMOTE_USER\");\n \t\tsvc->enabled = (user && *user) ? 1 : 0;\n@@ -442,6 +461,7 @@ static void get_info_refs(char *arg)\n \t\trun_service(argv);\n \n \t} else {\n+\t\tselect_getanyfile();\n \t\tfor_each_ref(show_text_ref, &buf);\n \t\tsend_strbuf(\"text/plain\", &buf);\n \t}\n@@ -455,6 +475,7 @@ static void get_info_packs(char *arg)\n \tstruct packed_git *p;\n \tsize_t cnt = 0;\n \n+\tselect_getanyfile();\n \tprepare_packed_git();\n \tfor (p = packed_git; p; p = p->next) {\n \t\tif (p->pack_local)\n@@ -621,6 +642,7 @@ int main(int argc, char **argv)\n \tif (!enter_repo(dir, 0))\n \t\tnot_found(\"Not a git repository: '%s'\", dir);\n \n+\tgit_config(http_config, NULL);\n \tcmd->imp(cmd_arg);\n \treturn 0;\n }\n-- \n1.6.5.2.295.g0d105\n"},{"id":"126861","messageId":"1257383798-29826-3-git-send-email-spearce@spearce.org","threadId":"21485","inReplyTo":"1257383798-29826-1-git-send-email-spearce@spearce.org","subject":"[PATCH v5.1 3/3] http-backend: Test configuration options","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-11-05T01:16:38Z","receivedAt":"2009-11-05T01:16:38Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Test the major configuration settings which control access to\nthe repository:\n\n  http.getanyfile\n  http.uploadpack\n  http.receivepack\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n t/t5560-http-backend.sh |  229 +++++++++++++++++++++++++++++++++++++++++++++++\n 1 files changed, 229 insertions(+), 0 deletions(-)\n create mode 100755 t/t5560-http-backend.sh\n\ndiff --git a/t/t5560-http-backend.sh b/t/t5560-http-backend.sh\nnew file mode 100755\nindex 0000000..908ba07\n--- /dev/null\n+++ b/t/t5560-http-backend.sh\n@@ -0,0 +1,229 @@\n+#!/bin/sh\n+\n+test_description='test git-http-backend'\n+. ./test-lib.sh\n+\n+if test -n \"$NO_CURL\"; then\n+\tsay 'skipping test, git built without http support'\n+\ttest_done\n+fi\n+\n+LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5560'}\n+. \"$TEST_DIRECTORY\"/lib-httpd.sh\n+start_httpd\n+\n+find_file() {\n+\tcd \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" &&\n+\tfind $1 -type f |\n+\tsed -e 1q\n+}\n+\n+config() {\n+\tgit --git-dir=\"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" config $1 $2\n+}\n+\n+GET() {\n+\tcurl --include \"$HTTPD_URL/smart/repo.git/$1\" >out 2>/dev/null &&\n+\ttr '\\015' Q <out |\n+\tsed '\n+\t\ts/Q$//\n+\t\t1q\n+\t' >act &&\n+\techo \"HTTP/1.1 $2\" >exp &&\n+\ttest_cmp exp act\n+}\n+\n+POST() {\n+\tcurl --include --data \"$2\" \\\n+\t--header \"Content-Type: application/x-$1-request\" \\\n+\t\"$HTTPD_URL/smart/repo.git/$1\" >out 2>/dev/null &&\n+\ttr '\\015' Q <out |\n+\tsed '\n+\t\ts/Q$//\n+\t\t1q\n+\t' >act &&\n+\techo \"HTTP/1.1 $3\" >exp &&\n+\ttest_cmp exp act\n+}\n+\n+log_div() {\n+\techo >>\"$HTTPD_ROOT_PATH\"/access.log\n+\techo \"###  $1\" >>\"$HTTPD_ROOT_PATH\"/access.log\n+\techo \"###\" >>\"$HTTPD_ROOT_PATH\"/access.log\n+}\n+\n+test_expect_success 'setup repository' '\n+\techo content >file &&\n+\tgit add file &&\n+\tgit commit -m one &&\n+\n+\tmkdir \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" &&\n+\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" &&\n+\t git --bare init &&\n+\t : >objects/info/alternates &&\n+\t : >objects/info/http-alternates\n+\t) &&\n+\tgit remote add public \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" &&\n+\tgit push public master:master &&\n+\n+\t(cd \"$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" &&\n+\t git repack -a -d\n+\t) &&\n+\n+\techo other >file &&\n+\tgit add file &&\n+\tgit commit -m two &&\n+\tgit push public master:master &&\n+\n+\tLOOSE_URL=$(find_file objects/??) &&\n+\tPACK_URL=$(find_file objects/pack/*.pack) &&\n+\tIDX_URL=$(find_file objects/pack/*.idx)\n+'\n+\n+get_static_files() {\n+\tGET HEAD \"$1\" &&\n+\tGET info/refs \"$1\" &&\n+\tGET objects/info/packs \"$1\" &&\n+\tGET objects/info/alternates \"$1\" &&\n+\tGET objects/info/http-alternates \"$1\" &&\n+\tGET $LOOSE_URL \"$1\" &&\n+\tGET $PACK_URL \"$1\" &&\n+\tGET $IDX_URL \"$1\"\n+}\n+\n+test_expect_success 'direct refs/heads/master not found' '\n+\tlog_div \"refs/heads/master\"\n+\tGET refs/heads/master \"404 Not Found\"\n+'\n+test_expect_success 'static file is ok' '\n+\tlog_div \"getanyfile default\"\n+\tget_static_files \"200 OK\"\n+'\n+test_expect_success 'static file if http.getanyfile true is ok' '\n+\tlog_div \"getanyfile true\"\n+\tconfig http.getanyfile true &&\n+\tget_static_files \"200 OK\"\n+'\n+test_expect_success 'static file if http.getanyfile false fails' '\n+\tlog_div \"getanyfile false\"\n+\tconfig http.getanyfile false &&\n+\tget_static_files \"403 Forbidden\"\n+'\n+\n+test_expect_success 'http.uploadpack default enabled' '\n+\tlog_div \"uploadpack default\"\n+\tGET info/refs?service=git-upload-pack \"200 OK\"  &&\n+\tPOST git-upload-pack 0000 \"200 OK\"\n+'\n+test_expect_success 'http.uploadpack true' '\n+\tlog_div \"uploadpack true\"\n+\tconfig http.uploadpack true &&\n+\tGET info/refs?service=git-upload-pack \"200 OK\" &&\n+\tPOST git-upload-pack 0000 \"200 OK\"\n+'\n+test_expect_success 'http.uploadpack false' '\n+\tlog_div \"uploadpack false\"\n+\tconfig http.uploadpack false &&\n+\tGET info/refs?service=git-upload-pack \"403 Forbidden\" &&\n+\tPOST git-upload-pack 0000 \"403 Forbidden\"\n+'\n+\n+test_expect_success 'http.receivepack default disabled' '\n+\tlog_div \"receivepack default\"\n+\tGET info/refs?service=git-receive-pack \"403 Forbidden\"  &&\n+\tPOST git-receive-pack 0000 \"403 Forbidden\"\n+'\n+test_expect_success 'http.receivepack true' '\n+\tlog_div \"receivepack true\"\n+\tconfig http.receivepack true &&\n+\tGET info/refs?service=git-receive-pack \"200 OK\" &&\n+\tPOST git-receive-pack 0000 \"200 OK\"\n+'\n+test_expect_success 'http.receivepack false' '\n+\tlog_div \"receivepack false\"\n+\tconfig http.receivepack false &&\n+\tGET info/refs?service=git-receive-pack \"403 Forbidden\" &&\n+\tPOST git-receive-pack 0000 \"403 Forbidden\"\n+'\n+\n+cat >exp <<EOF\n+\n+###  refs/heads/master\n+###\n+GET  /smart/repo.git/refs/heads/master HTTP/1.1 404 -\n+\n+###  getanyfile default\n+###\n+GET  /smart/repo.git/HEAD HTTP/1.1 200\n+GET  /smart/repo.git/info/refs HTTP/1.1 200\n+GET  /smart/repo.git/objects/info/packs HTTP/1.1 200\n+GET  /smart/repo.git/objects/info/alternates HTTP/1.1 200 -\n+GET  /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -\n+GET  /smart/repo.git/$LOOSE_URL HTTP/1.1 200\n+GET  /smart/repo.git/$PACK_URL HTTP/1.1 200\n+GET  /smart/repo.git/$IDX_URL HTTP/1.1 200\n+\n+###  getanyfile true\n+###\n+GET  /smart/repo.git/HEAD HTTP/1.1 200\n+GET  /smart/repo.git/info/refs HTTP/1.1 200\n+GET  /smart/repo.git/objects/info/packs HTTP/1.1 200\n+GET  /smart/repo.git/objects/info/alternates HTTP/1.1 200 -\n+GET  /smart/repo.git/objects/info/http-alternates HTTP/1.1 200 -\n+GET  /smart/repo.git/$LOOSE_URL HTTP/1.1 200\n+GET  /smart/repo.git/$PACK_URL HTTP/1.1 200\n+GET  /smart/repo.git/$IDX_URL HTTP/1.1 200\n+\n+###  getanyfile false\n+###\n+GET  /smart/repo.git/HEAD HTTP/1.1 403 -\n+GET  /smart/repo.git/info/refs HTTP/1.1 403 -\n+GET  /smart/repo.git/objects/info/packs HTTP/1.1 403 -\n+GET  /smart/repo.git/objects/info/alternates HTTP/1.1 403 -\n+GET  /smart/repo.git/objects/info/http-alternates HTTP/1.1 403 -\n+GET  /smart/repo.git/$LOOSE_URL HTTP/1.1 403 -\n+GET  /smart/repo.git/$PACK_URL HTTP/1.1 403 -\n+GET  /smart/repo.git/$IDX_URL HTTP/1.1 403 -\n+\n+###  uploadpack default\n+###\n+GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200\n+POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -\n+\n+###  uploadpack true\n+###\n+GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200\n+POST /smart/repo.git/git-upload-pack HTTP/1.1 200 -\n+\n+###  uploadpack false\n+###\n+GET  /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 403 -\n+POST /smart/repo.git/git-upload-pack HTTP/1.1 403 -\n+\n+###  receivepack default\n+###\n+GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -\n+POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -\n+\n+###  receivepack true\n+###\n+GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 200\n+POST /smart/repo.git/git-receive-pack HTTP/1.1 200 -\n+\n+###  receivepack false\n+###\n+GET  /smart/repo.git/info/refs?service=git-receive-pack HTTP/1.1 403 -\n+POST /smart/repo.git/git-receive-pack HTTP/1.1 403 -\n+EOF\n+test_expect_success 'server request log matches test results' '\n+\tsed -e \"\n+\t\ts/^.* \\\"//\n+\t\ts/\\\"//\n+\t\ts/ [1-9][0-9]*\\$//\n+\t\ts/^GET /GET  /\n+\t\" >act <\"$HTTPD_ROOT_PATH\"/access.log &&\n+\ttest_cmp exp act\n+'\n+\n+stop_httpd\n+test_done\n-- \n1.6.5.2.295.g0d105\n"}]}