Skip to content

Commit 588c70e

Browse files
bk2204gitster
authored andcommitted
t0300: add tests for some additional cases
There are some tricky cases in our credential helpers that we don't have test cases for. To help prevent regressions, let's add some for these cases: * If there are multiple configured credential helpers, one without a path and one with a path, we want to invoke both of them. * If there are percent-encoded values in the URL, we handle them properly. * And finally, if there is a username in the remote URL, we want to honor that over what the configuration tells us. Finally, there's an additional case that we'd like to test for as well, but that currently fails. In all other situations in our configuration, we pick the last configuration setting that's provided. However, we fail to do that for credential.username, where we pick the first setting instead. Let's add a failing test that we have the consistent behavior here, since that's the documented, expected behavior. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 732f934 commit 588c70e

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

t/t0300-credentials.sh

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,57 @@ test_expect_success 'do not match configured credential' '
240240
EOF
241241
'
242242

243+
test_expect_success 'match multiple configured helpers' '
244+
test_config credential.helper "verbatim \"\" \"\"" &&
245+
test_config credential.https://example.com.helper "$HELPER" &&
246+
check fill <<-\EOF
247+
protocol=https
248+
host=example.com
249+
path=repo.git
250+
--
251+
protocol=https
252+
host=example.com
253+
username=foo
254+
password=bar
255+
--
256+
verbatim: get
257+
verbatim: protocol=https
258+
verbatim: host=example.com
259+
EOF
260+
'
261+
262+
test_expect_success 'match multiple configured helpers with URLs' '
263+
test_config credential.https://example.com/repo.git.helper "verbatim \"\" \"\"" &&
264+
test_config credential.https://example.com.helper "$HELPER" &&
265+
check fill <<-\EOF
266+
protocol=https
267+
host=example.com
268+
path=repo.git
269+
--
270+
protocol=https
271+
host=example.com
272+
username=foo
273+
password=bar
274+
--
275+
verbatim: get
276+
verbatim: protocol=https
277+
verbatim: host=example.com
278+
EOF
279+
'
280+
281+
test_expect_success 'match percent-encoded values' '
282+
test_config credential.https://example.com/%2566.git.helper "$HELPER" &&
283+
check fill <<-\EOF
284+
url=https://example.com/%2566.git
285+
--
286+
protocol=https
287+
host=example.com
288+
username=foo
289+
password=bar
290+
--
291+
EOF
292+
'
293+
243294
test_expect_success 'pull username from config' '
244295
test_config credential.https://example.com.username foo &&
245296
check fill <<-\EOF
@@ -255,6 +306,63 @@ test_expect_success 'pull username from config' '
255306
EOF
256307
'
257308

309+
test_expect_success 'honors username from URL over helper (URL)' '
310+
test_config credential.https://example.com.username bob &&
311+
test_config credential.https://example.com.helper "verbatim \"\" bar" &&
312+
check fill <<-\EOF
313+
url=https://[email protected]
314+
--
315+
protocol=https
316+
host=example.com
317+
username=alice
318+
password=bar
319+
--
320+
verbatim: get
321+
verbatim: protocol=https
322+
verbatim: host=example.com
323+
verbatim: username=alice
324+
EOF
325+
'
326+
327+
test_expect_success 'honors username from URL over helper (components)' '
328+
test_config credential.https://example.com.username bob &&
329+
test_config credential.https://example.com.helper "verbatim \"\" bar" &&
330+
check fill <<-\EOF
331+
protocol=https
332+
host=example.com
333+
username=alice
334+
--
335+
protocol=https
336+
host=example.com
337+
username=alice
338+
password=bar
339+
--
340+
verbatim: get
341+
verbatim: protocol=https
342+
verbatim: host=example.com
343+
verbatim: username=alice
344+
EOF
345+
'
346+
347+
test_expect_failure 'last matching username wins' '
348+
test_config credential.https://example.com/path.git.username bob &&
349+
test_config credential.https://example.com.username alice &&
350+
test_config credential.https://example.com.helper "verbatim \"\" bar" &&
351+
check fill <<-\EOF
352+
url=https://example.com/path.git
353+
--
354+
protocol=https
355+
host=example.com
356+
username=alice
357+
password=bar
358+
--
359+
verbatim: get
360+
verbatim: protocol=https
361+
verbatim: host=example.com
362+
verbatim: username=alice
363+
EOF
364+
'
365+
258366
test_expect_success 'http paths can be part of context' '
259367
check fill "verbatim foo bar" <<-\EOF &&
260368
protocol=https

0 commit comments

Comments
 (0)