3 test_description
='check handling of disallowed .gitmodule urls'
6 test_expect_success
'setup' '
7 git config --global protocol.file.allow always
10 test_expect_success
'create submodule with protected dash in url' '
12 git -C upstream commit --allow-empty -m base &&
13 mv upstream ./-upstream &&
14 git submodule add ./-upstream sub &&
15 git add sub .gitmodules &&
16 git commit -m submodule
19 test_expect_success
'clone can recurse submodule' '
20 test_when_finished "rm -rf dst" &&
21 git clone --recurse-submodules . dst &&
23 git -C dst/sub log -1 --format=%s >actual &&
24 test_cmp expect actual
27 test_expect_success
'fsck accepts protected dash' '
28 test_when_finished "rm -rf dst" &&
29 git init --bare dst &&
30 git -C dst config transfer.fsckObjects true &&
34 test_expect_success
'remove ./ protection from .gitmodules url' '
35 perl -i -pe "s{\./}{}" .gitmodules &&
36 git commit -am "drop protection"
39 test_expect_success
'clone rejects unprotected dash' '
40 test_when_finished "rm -rf dst" &&
41 test_must_fail git clone --recurse-submodules . dst 2>err &&
42 test_i18ngrep ignoring err
45 test_expect_success
'fsck rejects unprotected dash' '
46 test_when_finished "rm -rf dst" &&
47 git init --bare dst &&
48 git -C dst config transfer.fsckObjects true &&
49 test_must_fail git push dst HEAD 2>err &&
50 grep gitmodulesUrl err
53 test_expect_success
'trailing backslash is handled correctly' '
54 git init testmodule &&
55 test_commit -C testmodule c &&
56 git submodule add ./testmodule &&
57 : ensure that the name ends in a double backslash &&
58 sed -e "s|\\(submodule \"testmodule\\)\"|\\1\\\\\\\\\"|" \
59 -e "s|url = .*|url = \" --should-not-be-an-option\"|" \
61 mv .new .gitmodules &&
62 git commit -am "Add testmodule" &&
63 test_must_fail git clone --verbose --recurse-submodules . dolly 2>err &&
64 test_i18ngrep ! "unknown option" err
67 test_expect_success
'fsck rejects missing URL scheme' '
68 git checkout --orphan missing-scheme &&
69 cat >.gitmodules <<-\EOF &&
71 url = http::one.example.com/foo.git
73 git add .gitmodules &&
75 git commit -m "gitmodules with missing URL scheme" &&
76 test_when_finished "rm -rf dst" &&
77 git init --bare dst &&
78 git -C dst config transfer.fsckObjects true &&
79 test_must_fail git push dst HEAD 2>err &&
80 grep gitmodulesUrl err
83 test_expect_success
'fsck rejects relative URL resolving to missing scheme' '
84 git checkout --orphan relative-missing-scheme &&
85 cat >.gitmodules <<-\EOF &&
87 url = "..\\../.\\../:one.example.com/foo.git"
89 git add .gitmodules &&
91 git commit -m "gitmodules with relative URL that strips off scheme" &&
92 test_when_finished "rm -rf dst" &&
93 git init --bare dst &&
94 git -C dst config transfer.fsckObjects true &&
95 test_must_fail git push dst HEAD 2>err &&
96 grep gitmodulesUrl err
99 test_expect_success
'fsck rejects empty URL scheme' '
100 git checkout --orphan empty-scheme &&
101 cat >.gitmodules <<-\EOF &&
103 url = http::://one.example.com/foo.git
105 git add .gitmodules &&
107 git commit -m "gitmodules with empty URL scheme" &&
108 test_when_finished "rm -rf dst" &&
109 git init --bare dst &&
110 git -C dst config transfer.fsckObjects true &&
111 test_must_fail git push dst HEAD 2>err &&
112 grep gitmodulesUrl err
115 test_expect_success
'fsck rejects relative URL resolving to empty scheme' '
116 git checkout --orphan relative-empty-scheme &&
117 cat >.gitmodules <<-\EOF &&
119 url = ../../../:://one.example.com/foo.git
121 git add .gitmodules &&
123 git commit -m "relative gitmodules URL resolving to empty scheme" &&
124 test_when_finished "rm -rf dst" &&
125 git init --bare dst &&
126 git -C dst config transfer.fsckObjects true &&
127 test_must_fail git push dst HEAD 2>err &&
128 grep gitmodulesUrl err
131 test_expect_success
'fsck rejects empty hostname' '
132 git checkout --orphan empty-host &&
133 cat >.gitmodules <<-\EOF &&
135 url = http:///one.example.com/foo.git
137 git add .gitmodules &&
139 git commit -m "gitmodules with extra slashes" &&
140 test_when_finished "rm -rf dst" &&
141 git init --bare dst &&
142 git -C dst config transfer.fsckObjects true &&
143 test_must_fail git push dst HEAD 2>err &&
144 grep gitmodulesUrl err
147 test_expect_success
'fsck rejects relative url that produced empty hostname' '
148 git checkout --orphan messy-relative &&
149 cat >.gitmodules <<-\EOF &&
151 url = ../../..//one.example.com/foo.git
153 git add .gitmodules &&
155 git commit -m "gitmodules abusing relative_path" &&
156 test_when_finished "rm -rf dst" &&
157 git init --bare dst &&
158 git -C dst config transfer.fsckObjects true &&
159 test_must_fail git push dst HEAD 2>err &&
160 grep gitmodulesUrl err
163 test_expect_success
'fsck permits embedded newline with unrecognized scheme' '
164 git checkout --orphan newscheme &&
165 cat >.gitmodules <<-\EOF &&
167 url = "data://acjbkd%0akajfdickajkd"
169 git add .gitmodules &&
170 git commit -m "gitmodules with unrecognized scheme" &&
171 test_when_finished "rm -rf dst" &&
172 git init --bare dst &&
173 git -C dst config transfer.fsckObjects true &&
177 test_expect_success
'fsck rejects embedded newline in url' '
178 # create an orphan branch to avoid existing .gitmodules objects
179 git checkout --orphan newline &&
180 cat >.gitmodules <<-\EOF &&
182 url = "https://one.example.com?%0ahost=two.example.com/foo.git"
184 git add .gitmodules &&
185 git commit -m "gitmodules with newline" &&
186 test_when_finished "rm -rf dst" &&
187 git init --bare dst &&
188 git -C dst config transfer.fsckObjects true &&
189 test_must_fail git push dst HEAD 2>err &&
190 grep gitmodulesUrl err
193 test_expect_success
'fsck rejects embedded newline in relative url' '
194 git checkout --orphan relative-newline &&
195 cat >.gitmodules <<-\EOF &&
197 url = "./%0ahost=two.example.com/foo.git"
199 git add .gitmodules &&
200 git commit -m "relative url with newline" &&
201 test_when_finished "rm -rf dst" &&
202 git init --bare dst &&
203 git -C dst config transfer.fsckObjects true &&
204 test_must_fail git push dst HEAD 2>err &&
205 grep gitmodulesUrl err
208 test_expect_success
'fsck rejects embedded newline in git url' '
209 git checkout --orphan git-newline &&
210 cat >.gitmodules <<-\EOF &&
212 url = "git://example.com:1234/repo%0a.git"
214 git add .gitmodules &&
215 git commit -m "git url with newline" &&
216 test_when_finished "rm -rf dst" &&
217 git init --bare dst &&
218 git -C dst config transfer.fsckObjects true &&
219 test_must_fail git push dst HEAD 2>err &&
220 grep gitmodulesUrl err