Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='test git-http-backend respects CONTENT_LENGTH' |
| 4 | . ./test-lib.sh |
| 5 | |
| 6 | test_lazy_prereq GZIP 'gzip --version' |
| 7 | |
| 8 | verify_http_result() { |
| 9 | # some fatal errors still produce status 200 |
| 10 | # so check if there is the error message |
Max Kirillov | 0539071 | 2018-11-24 11:37:19 +0200 | [diff] [blame] | 11 | if grep 'fatal:' act.err.$test_count |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 12 | then |
| 13 | return 1 |
| 14 | fi |
| 15 | |
Max Kirillov | 0539071 | 2018-11-24 11:37:19 +0200 | [diff] [blame] | 16 | if ! grep "Status" act.out.$test_count >act |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 17 | then |
| 18 | printf "Status: 200 OK\r\n" >act |
| 19 | fi |
| 20 | printf "Status: $1\r\n" >exp && |
| 21 | test_cmp exp act |
| 22 | } |
| 23 | |
| 24 | test_http_env() { |
| 25 | handler_type="$1" |
| 26 | request_body="$2" |
| 27 | shift |
| 28 | env \ |
| 29 | CONTENT_TYPE="application/x-git-$handler_type-pack-request" \ |
| 30 | QUERY_STRING="/repo.git/git-$handler_type-pack" \ |
| 31 | PATH_TRANSLATED="$PWD/.git/git-$handler_type-pack" \ |
| 32 | GIT_HTTP_EXPORT_ALL=TRUE \ |
| 33 | REQUEST_METHOD=POST \ |
Jeff King | 8c8fad9 | 2018-11-23 01:38:21 +0200 | [diff] [blame] | 34 | "$PERL_PATH" \ |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 35 | "$TEST_DIRECTORY"/t5562/invoke-with-content-length.pl \ |
Max Kirillov | 0539071 | 2018-11-24 11:37:19 +0200 | [diff] [blame] | 36 | "$request_body" git http-backend >act.out.$test_count 2>act.err.$test_count |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | ssize_b100dots() { |
| 40 | # hardcoded ((size_t) SSIZE_MAX) + 1 |
| 41 | case "$(build_option sizeof-size_t)" in |
| 42 | 8) echo 9223372036854775808;; |
| 43 | 4) echo 2147483648;; |
| 44 | *) die "Unexpected ssize_t size: $(build_option sizeof-size_t)";; |
| 45 | esac |
| 46 | } |
| 47 | |
| 48 | test_expect_success 'setup' ' |
Ramsay Jones | eebfe40 | 2018-07-28 23:51:28 +0100 | [diff] [blame] | 49 | HTTP_CONTENT_ENCODING="identity" && |
| 50 | export HTTP_CONTENT_ENCODING && |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 51 | git config http.receivepack true && |
| 52 | test_commit c0 && |
| 53 | test_commit c1 && |
| 54 | hash_head=$(git rev-parse HEAD) && |
| 55 | hash_prev=$(git rev-parse HEAD~1) && |
Jeff King | 88124ab | 2020-03-27 04:03:00 -0400 | [diff] [blame] | 56 | { |
| 57 | packetize "want $hash_head" && |
| 58 | printf 0000 && |
| 59 | packetize "have $hash_prev" && |
| 60 | packetize "done" |
| 61 | } >fetch_body && |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 62 | test_copy_bytes 10 <fetch_body >fetch_body.trunc && |
| 63 | hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) && |
Jeff King | 88124ab | 2020-03-27 04:03:00 -0400 | [diff] [blame] | 64 | { |
brian m. carlson | 9dc78c2 | 2020-05-25 19:59:06 +0000 | [diff] [blame] | 65 | printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \ |
Eric Sunshine | 7abcbcb | 2021-12-09 00:11:08 -0500 | [diff] [blame] | 66 | "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw && |
Jeff King | 88124ab | 2020-03-27 04:03:00 -0400 | [diff] [blame] | 67 | printf 0000 && |
| 68 | echo "$hash_next" | git pack-objects --stdout |
| 69 | } >push_body && |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 70 | test_copy_bytes 10 <push_body >push_body.trunc && |
| 71 | : >empty_body |
| 72 | ' |
| 73 | |
| 74 | test_expect_success GZIP 'setup, compression related' ' |
| 75 | gzip -c fetch_body >fetch_body.gz && |
| 76 | test_copy_bytes 10 <fetch_body.gz >fetch_body.gz.trunc && |
| 77 | gzip -c push_body >push_body.gz && |
| 78 | test_copy_bytes 10 <push_body.gz >push_body.gz.trunc |
| 79 | ' |
| 80 | |
| 81 | test_expect_success 'fetch plain' ' |
| 82 | test_http_env upload fetch_body && |
| 83 | verify_http_result "200 OK" |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'fetch plain truncated' ' |
| 87 | test_http_env upload fetch_body.trunc && |
| 88 | ! verify_http_result "200 OK" |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'fetch plain empty' ' |
| 92 | test_http_env upload empty_body && |
| 93 | ! verify_http_result "200 OK" |
| 94 | ' |
| 95 | |
| 96 | test_expect_success GZIP 'fetch gzipped' ' |
| 97 | test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz && |
| 98 | verify_http_result "200 OK" |
| 99 | ' |
| 100 | |
| 101 | test_expect_success GZIP 'fetch gzipped truncated' ' |
| 102 | test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload fetch_body.gz.trunc && |
| 103 | ! verify_http_result "200 OK" |
| 104 | ' |
| 105 | |
| 106 | test_expect_success GZIP 'fetch gzipped empty' ' |
| 107 | test_env HTTP_CONTENT_ENCODING="gzip" test_http_env upload empty_body && |
| 108 | ! verify_http_result "200 OK" |
| 109 | ' |
| 110 | |
| 111 | test_expect_success GZIP 'push plain' ' |
| 112 | test_when_finished "git branch -D newbranch" && |
| 113 | test_http_env receive push_body && |
| 114 | verify_http_result "200 OK" && |
| 115 | git rev-parse newbranch >act.head && |
| 116 | echo "$hash_next" >exp.head && |
| 117 | test_cmp act.head exp.head |
| 118 | ' |
| 119 | |
| 120 | test_expect_success 'push plain truncated' ' |
| 121 | test_http_env receive push_body.trunc && |
| 122 | ! verify_http_result "200 OK" |
| 123 | ' |
| 124 | |
| 125 | test_expect_success 'push plain empty' ' |
| 126 | test_http_env receive empty_body && |
| 127 | ! verify_http_result "200 OK" |
| 128 | ' |
| 129 | |
| 130 | test_expect_success GZIP 'push gzipped' ' |
| 131 | test_when_finished "git branch -D newbranch" && |
| 132 | test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz && |
| 133 | verify_http_result "200 OK" && |
| 134 | git rev-parse newbranch >act.head && |
| 135 | echo "$hash_next" >exp.head && |
| 136 | test_cmp act.head exp.head |
| 137 | ' |
| 138 | |
| 139 | test_expect_success GZIP 'push gzipped truncated' ' |
| 140 | test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive push_body.gz.trunc && |
| 141 | ! verify_http_result "200 OK" |
| 142 | ' |
| 143 | |
| 144 | test_expect_success GZIP 'push gzipped empty' ' |
| 145 | test_env HTTP_CONTENT_ENCODING="gzip" test_http_env receive empty_body && |
| 146 | ! verify_http_result "200 OK" |
| 147 | ' |
| 148 | |
| 149 | test_expect_success 'CONTENT_LENGTH overflow ssite_t' ' |
| 150 | NOT_FIT_IN_SSIZE=$(ssize_b100dots) && |
Junio C Hamano | d991948 | 2019-02-19 10:18:15 -0800 | [diff] [blame] | 151 | env \ |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 152 | CONTENT_TYPE=application/x-git-upload-pack-request \ |
| 153 | QUERY_STRING=/repo.git/git-upload-pack \ |
| 154 | PATH_TRANSLATED="$PWD"/.git/git-upload-pack \ |
| 155 | GIT_HTTP_EXPORT_ALL=TRUE \ |
| 156 | REQUEST_METHOD=POST \ |
| 157 | CONTENT_LENGTH="$NOT_FIT_IN_SSIZE" \ |
Max Kirillov | 7094175 | 2019-02-15 18:42:37 +0200 | [diff] [blame] | 158 | git http-backend </dev/null >/dev/null 2>err && |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 159 | grep "fatal:.*CONTENT_LENGTH" err |
| 160 | ' |
| 161 | |
Max Kirillov | 574c513 | 2018-09-07 06:36:07 +0300 | [diff] [blame] | 162 | test_expect_success 'empty CONTENT_LENGTH' ' |
| 163 | env \ |
Max Kirillov | 806b168 | 2018-09-11 23:33:36 +0300 | [diff] [blame] | 164 | QUERY_STRING="service=git-receive-pack" \ |
| 165 | PATH_TRANSLATED="$PWD"/.git/info/refs \ |
Max Kirillov | 574c513 | 2018-09-07 06:36:07 +0300 | [diff] [blame] | 166 | GIT_HTTP_EXPORT_ALL=TRUE \ |
| 167 | REQUEST_METHOD=GET \ |
| 168 | CONTENT_LENGTH="" \ |
Max Kirillov | 0539071 | 2018-11-24 11:37:19 +0200 | [diff] [blame] | 169 | git http-backend <empty_body >act.out.$test_count 2>act.err.$test_count && |
Max Kirillov | 574c513 | 2018-09-07 06:36:07 +0300 | [diff] [blame] | 170 | verify_http_result "200 OK" |
| 171 | ' |
| 172 | |
Max Kirillov | 6c213e8 | 2018-07-27 06:48:59 +0300 | [diff] [blame] | 173 | test_done |