Git fork
at reftables-rust 225 lines 6.7 kB view raw
1#!/bin/sh 2 3test_description='check handling of disallowed .gitmodule urls' 4 5. ./test-lib.sh 6 7test_expect_success 'setup' ' 8 git config --global protocol.file.allow always 9' 10 11test_expect_success 'create submodule with protected dash in url' ' 12 git init upstream && 13 git -C upstream commit --allow-empty -m base && 14 mv upstream ./-upstream && 15 git submodule add ./-upstream sub && 16 git add sub .gitmodules && 17 git commit -m submodule 18' 19 20test_expect_success 'clone can recurse submodule' ' 21 test_when_finished "rm -rf dst" && 22 git clone --recurse-submodules . dst && 23 echo base >expect && 24 git -C dst/sub log -1 --format=%s >actual && 25 test_cmp expect actual 26' 27 28test_expect_success 'fsck accepts protected dash' ' 29 test_when_finished "rm -rf dst" && 30 git init --bare dst && 31 git -C dst config transfer.fsckObjects true && 32 git push dst HEAD 33' 34 35test_expect_success 'remove ./ protection from .gitmodules url' ' 36 sed "s|\./||" .gitmodules >.gitmodules.munged && 37 mv .gitmodules.munged .gitmodules && 38 git commit -am "drop protection" 39' 40 41test_expect_success 'clone rejects unprotected dash' ' 42 test_when_finished "rm -rf dst" && 43 test_must_fail git clone --recurse-submodules . dst 2>err && 44 test_grep ignoring err 45' 46 47test_expect_success 'fsck rejects unprotected dash' ' 48 test_when_finished "rm -rf dst" && 49 git init --bare dst && 50 git -C dst config transfer.fsckObjects true && 51 test_must_fail git push dst HEAD 2>err && 52 grep gitmodulesUrl err 53' 54 55test_expect_success 'trailing backslash is handled correctly' ' 56 git init testmodule && 57 test_commit -C testmodule c && 58 git submodule add ./testmodule && 59 : ensure that the name ends in a double backslash && 60 sed -e "s|\\(submodule \"testmodule\\)\"|\\1\\\\\\\\\"|" \ 61 -e "s|url = .*|url = \" --should-not-be-an-option\"|" \ 62 <.gitmodules >.new && 63 mv .new .gitmodules && 64 git commit -am "Add testmodule" && 65 test_must_fail git clone --verbose --recurse-submodules . dolly 2>err && 66 test_grep ! "unknown option" err 67' 68 69test_expect_success 'fsck rejects missing URL scheme' ' 70 git checkout --orphan missing-scheme && 71 cat >.gitmodules <<-\EOF && 72 [submodule "foo"] 73 url = http::one.example.com/foo.git 74 EOF 75 git add .gitmodules && 76 test_tick && 77 git commit -m "gitmodules with missing URL scheme" && 78 test_when_finished "rm -rf dst" && 79 git init --bare dst && 80 git -C dst config transfer.fsckObjects true && 81 test_must_fail git push dst HEAD 2>err && 82 grep gitmodulesUrl err 83' 84 85test_expect_success 'fsck rejects relative URL resolving to missing scheme' ' 86 git checkout --orphan relative-missing-scheme && 87 cat >.gitmodules <<-\EOF && 88 [submodule "foo"] 89 url = "..\\../.\\../:one.example.com/foo.git" 90 EOF 91 git add .gitmodules && 92 test_tick && 93 git commit -m "gitmodules with relative URL that strips off scheme" && 94 test_when_finished "rm -rf dst" && 95 git init --bare dst && 96 git -C dst config transfer.fsckObjects true && 97 test_must_fail git push dst HEAD 2>err && 98 grep gitmodulesUrl err 99' 100 101test_expect_success 'fsck rejects empty URL scheme' ' 102 git checkout --orphan empty-scheme && 103 cat >.gitmodules <<-\EOF && 104 [submodule "foo"] 105 url = http::://one.example.com/foo.git 106 EOF 107 git add .gitmodules && 108 test_tick && 109 git commit -m "gitmodules with empty URL scheme" && 110 test_when_finished "rm -rf dst" && 111 git init --bare dst && 112 git -C dst config transfer.fsckObjects true && 113 test_must_fail git push dst HEAD 2>err && 114 grep gitmodulesUrl err 115' 116 117test_expect_success 'fsck rejects relative URL resolving to empty scheme' ' 118 git checkout --orphan relative-empty-scheme && 119 cat >.gitmodules <<-\EOF && 120 [submodule "foo"] 121 url = ../../../:://one.example.com/foo.git 122 EOF 123 git add .gitmodules && 124 test_tick && 125 git commit -m "relative gitmodules URL resolving to empty scheme" && 126 test_when_finished "rm -rf dst" && 127 git init --bare dst && 128 git -C dst config transfer.fsckObjects true && 129 test_must_fail git push dst HEAD 2>err && 130 grep gitmodulesUrl err 131' 132 133test_expect_success 'fsck rejects empty hostname' ' 134 git checkout --orphan empty-host && 135 cat >.gitmodules <<-\EOF && 136 [submodule "foo"] 137 url = http:///one.example.com/foo.git 138 EOF 139 git add .gitmodules && 140 test_tick && 141 git commit -m "gitmodules with extra slashes" && 142 test_when_finished "rm -rf dst" && 143 git init --bare dst && 144 git -C dst config transfer.fsckObjects true && 145 test_must_fail git push dst HEAD 2>err && 146 grep gitmodulesUrl err 147' 148 149test_expect_success 'fsck rejects relative url that produced empty hostname' ' 150 git checkout --orphan messy-relative && 151 cat >.gitmodules <<-\EOF && 152 [submodule "foo"] 153 url = ../../..//one.example.com/foo.git 154 EOF 155 git add .gitmodules && 156 test_tick && 157 git commit -m "gitmodules abusing relative_path" && 158 test_when_finished "rm -rf dst" && 159 git init --bare dst && 160 git -C dst config transfer.fsckObjects true && 161 test_must_fail git push dst HEAD 2>err && 162 grep gitmodulesUrl err 163' 164 165test_expect_success 'fsck permits embedded newline with unrecognized scheme' ' 166 git checkout --orphan newscheme && 167 cat >.gitmodules <<-\EOF && 168 [submodule "foo"] 169 url = "data://acjbkd%0akajfdickajkd" 170 EOF 171 git add .gitmodules && 172 git commit -m "gitmodules with unrecognized scheme" && 173 test_when_finished "rm -rf dst" && 174 git init --bare dst && 175 git -C dst config transfer.fsckObjects true && 176 git push dst HEAD 177' 178 179test_expect_success 'fsck rejects embedded newline in url' ' 180 # create an orphan branch to avoid existing .gitmodules objects 181 git checkout --orphan newline && 182 cat >.gitmodules <<-\EOF && 183 [submodule "foo"] 184 url = "https://one.example.com?%0ahost=two.example.com/foo.git" 185 EOF 186 git add .gitmodules && 187 git commit -m "gitmodules with newline" && 188 test_when_finished "rm -rf dst" && 189 git init --bare dst && 190 git -C dst config transfer.fsckObjects true && 191 test_must_fail git push dst HEAD 2>err && 192 grep gitmodulesUrl err 193' 194 195test_expect_success 'fsck rejects embedded newline in relative url' ' 196 git checkout --orphan relative-newline && 197 cat >.gitmodules <<-\EOF && 198 [submodule "foo"] 199 url = "./%0ahost=two.example.com/foo.git" 200 EOF 201 git add .gitmodules && 202 git commit -m "relative url with newline" && 203 test_when_finished "rm -rf dst" && 204 git init --bare dst && 205 git -C dst config transfer.fsckObjects true && 206 test_must_fail git push dst HEAD 2>err && 207 grep gitmodulesUrl err 208' 209 210test_expect_success 'fsck rejects embedded newline in git url' ' 211 git checkout --orphan git-newline && 212 cat >.gitmodules <<-\EOF && 213 [submodule "foo"] 214 url = "git://example.com:1234/repo%0a.git" 215 EOF 216 git add .gitmodules && 217 git commit -m "git url with newline" && 218 test_when_finished "rm -rf dst" && 219 git init --bare dst && 220 git -C dst config transfer.fsckObjects true && 221 test_must_fail git push dst HEAD 2>err && 222 grep gitmodulesUrl err 223' 224 225test_done