@matheusbsbs / matheus-bagliano / commits / 588c70e10f
Fork 0

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 <bk2204@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Feb 20, 2020 at 02:24 UTC 588c70e10f3511f85110512da97b188f3c581e53
1 file changed +108
t/t0300-credentials.sh
+108
@@ -240,6 +240,57 @@ test_expect_success 'do not match configured credential' '
240 EOF
241 '
242
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 +
294 test_expect_success 'pull username from config' '
295 test_config credential.https://example.com.username foo &&
296 check fill <<-\EOF
@@ -255,6 +306,63 @@ test_expect_success 'pull username from config' '
306 EOF
307 '
308
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://alice@example.com
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 +
366 test_expect_success 'http paths can be part of context' '
367 check fill "verbatim foo bar" <<-\EOF &&
368 protocol=https