]> git.ipfire.org Git - thirdparty/git.git/blame - t/t7416-submodule-dash-url.sh
The second batch
[thirdparty/git.git] / t / t7416-submodule-dash-url.sh
CommitLineData
f6adec4e
JK
1#!/bin/sh
2
07259e74 3test_description='check handling of disallowed .gitmodule urls'
c65d18cb
ÆAB
4
5TEST_PASSES_SANITIZE_LEAK=true
f6adec4e
JK
6. ./test-lib.sh
7
0d3beb71
TB
8test_expect_success 'setup' '
9 git config --global protocol.file.allow always
10'
11
f6adec4e
JK
12test_expect_success 'create submodule with protected dash in url' '
13 git init upstream &&
14 git -C upstream commit --allow-empty -m base &&
15 mv upstream ./-upstream &&
16 git submodule add ./-upstream sub &&
17 git add sub .gitmodules &&
18 git commit -m submodule
19'
20
21test_expect_success 'clone can recurse submodule' '
22 test_when_finished "rm -rf dst" &&
23 git clone --recurse-submodules . dst &&
24 echo base >expect &&
25 git -C dst/sub log -1 --format=%s >actual &&
26 test_cmp expect actual
27'
28
a124133e
JK
29test_expect_success 'fsck accepts protected dash' '
30 test_when_finished "rm -rf dst" &&
31 git init --bare dst &&
32 git -C dst config transfer.fsckObjects true &&
33 git push dst HEAD
34'
35
f6adec4e
JK
36test_expect_success 'remove ./ protection from .gitmodules url' '
37 perl -i -pe "s{\./}{}" .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 &&
6789275d 44 test_grep ignoring err
f6adec4e
JK
45'
46
a124133e
JK
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
6d868416
JS
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 &&
6789275d 66 test_grep ! "unknown option" err
6d868416
JS
67'
68
c44088ec
JN
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
e7fab62b
JN
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
1a3609e4
JN
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
a2b26ffb
JN
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
07259e74
JK
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
a2b26ffb
JN
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
6aed5673
JK
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
f6adec4e 225test_done