]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t0300: add tests for some additional cases
authorbrian m. carlson <bk2204@github.com>
Thu, 20 Feb 2020 02:24:11 +0000 (02:24 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 20 Feb 2020 21:05:43 +0000 (13:05 -0800)
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>
t/t0300-credentials.sh

index 82eaaea0f4954d22861a4733b80aebcc361aca9a..4593a0cd3d5d5db13450eaac637bed9afb425006 100755 (executable)
@@ -240,6 +240,57 @@ test_expect_success 'do not match configured credential' '
        EOF
 '
 
+test_expect_success 'match multiple configured helpers' '
+       test_config credential.helper "verbatim \"\" \"\"" &&
+       test_config credential.https://example.com.helper "$HELPER" &&
+       check fill <<-\EOF
+       protocol=https
+       host=example.com
+       path=repo.git
+       --
+       protocol=https
+       host=example.com
+       username=foo
+       password=bar
+       --
+       verbatim: get
+       verbatim: protocol=https
+       verbatim: host=example.com
+       EOF
+'
+
+test_expect_success 'match multiple configured helpers with URLs' '
+       test_config credential.https://example.com/repo.git.helper "verbatim \"\" \"\"" &&
+       test_config credential.https://example.com.helper "$HELPER" &&
+       check fill <<-\EOF
+       protocol=https
+       host=example.com
+       path=repo.git
+       --
+       protocol=https
+       host=example.com
+       username=foo
+       password=bar
+       --
+       verbatim: get
+       verbatim: protocol=https
+       verbatim: host=example.com
+       EOF
+'
+
+test_expect_success 'match percent-encoded values' '
+       test_config credential.https://example.com/%2566.git.helper "$HELPER" &&
+       check fill <<-\EOF
+       url=https://example.com/%2566.git
+       --
+       protocol=https
+       host=example.com
+       username=foo
+       password=bar
+       --
+       EOF
+'
+
 test_expect_success 'pull username from config' '
        test_config credential.https://example.com.username foo &&
        check fill <<-\EOF
@@ -255,6 +306,63 @@ test_expect_success 'pull username from config' '
        EOF
 '
 
+test_expect_success 'honors username from URL over helper (URL)' '
+       test_config credential.https://example.com.username bob &&
+       test_config credential.https://example.com.helper "verbatim \"\" bar" &&
+       check fill <<-\EOF
+       url=https://alice@example.com
+       --
+       protocol=https
+       host=example.com
+       username=alice
+       password=bar
+       --
+       verbatim: get
+       verbatim: protocol=https
+       verbatim: host=example.com
+       verbatim: username=alice
+       EOF
+'
+
+test_expect_success 'honors username from URL over helper (components)' '
+       test_config credential.https://example.com.username bob &&
+       test_config credential.https://example.com.helper "verbatim \"\" bar" &&
+       check fill <<-\EOF
+       protocol=https
+       host=example.com
+       username=alice
+       --
+       protocol=https
+       host=example.com
+       username=alice
+       password=bar
+       --
+       verbatim: get
+       verbatim: protocol=https
+       verbatim: host=example.com
+       verbatim: username=alice
+       EOF
+'
+
+test_expect_failure 'last matching username wins' '
+       test_config credential.https://example.com/path.git.username bob &&
+       test_config credential.https://example.com.username alice &&
+       test_config credential.https://example.com.helper "verbatim \"\" bar" &&
+       check fill <<-\EOF
+       url=https://example.com/path.git
+       --
+       protocol=https
+       host=example.com
+       username=alice
+       password=bar
+       --
+       verbatim: get
+       verbatim: protocol=https
+       verbatim: host=example.com
+       verbatim: username=alice
+       EOF
+'
+
 test_expect_success 'http paths can be part of context' '
        check fill "verbatim foo bar" <<-\EOF &&
        protocol=https