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