credential: treat URL without scheme as invalid
[git/debian.git] / t / t7416-submodule-dash-url.sh
blob249dc3d1d462f3bdb938313bf6f1e2a20063b1b4
1 #!/bin/sh
3 test_description='check handling of disallowed .gitmodule urls'
4 . ./test-lib.sh
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
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
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
30 test_expect_success 'remove ./ protection from .gitmodules url' '
31 perl -i -pe "s{\./}{}" .gitmodules &&
32 git commit -am "drop protection"
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
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
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
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
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
95 test_expect_success 'fsck permits embedded newline with unrecognized scheme' '
96 git checkout --orphan newscheme &&
97 cat >.gitmodules <<-\EOF &&
98 [submodule "foo"]
99 url = "data://acjbkd%0akajfdickajkd"
101 git add .gitmodules &&
102 git commit -m "gitmodules with unrecognized scheme" &&
103 test_when_finished "rm -rf dst" &&
104 git init --bare dst &&
105 git -C dst config transfer.fsckObjects true &&
106 git push dst HEAD
109 test_expect_success 'fsck rejects embedded newline in url' '
110 # create an orphan branch to avoid existing .gitmodules objects
111 git checkout --orphan newline &&
112 cat >.gitmodules <<-\EOF &&
113 [submodule "foo"]
114 url = "https://one.example.com?%0ahost=two.example.com/foo.git"
116 git add .gitmodules &&
117 git commit -m "gitmodules with newline" &&
118 test_when_finished "rm -rf dst" &&
119 git init --bare dst &&
120 git -C dst config transfer.fsckObjects true &&
121 test_must_fail git push dst HEAD 2>err &&
122 grep gitmodulesUrl err
125 test_expect_success 'fsck rejects embedded newline in relative url' '
126 git checkout --orphan relative-newline &&
127 cat >.gitmodules <<-\EOF &&
128 [submodule "foo"]
129 url = "./%0ahost=two.example.com/foo.git"
131 git add .gitmodules &&
132 git commit -m "relative url with newline" &&
133 test_when_finished "rm -rf dst" &&
134 git init --bare dst &&
135 git -C dst config transfer.fsckObjects true &&
136 test_must_fail git push dst HEAD 2>err &&
137 grep gitmodulesUrl err
140 test_done