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