t7503: does pre-commit-hook learn authorship?
[gitweb.git] / t / t0300-credentials.sh
index 81a455f4c32e7d6541747b98d930fdffc9623f6f..c1c8108148351ab3ec3db3f2615ff88f29d38974 100755 (executable)
@@ -8,10 +8,13 @@ test_expect_success 'setup helper scripts' '
        cat >dump <<-\EOF &&
        whoami=`echo $0 | sed s/.*git-credential-//`
        echo >&2 "$whoami: $*"
-       while IFS== read key value; do
+       OIFS=$IFS
+       IFS==
+       while read key value; do
                echo >&2 "$whoami: $key=$value"
                eval "$key=$value"
        done
+       IFS=$OIFS
        EOF
 
        cat >git-credential-useless <<-\EOF &&
@@ -192,4 +195,88 @@ test_expect_success 'internal getpass does not ask for known username' '
        EOF
 '
 
+HELPER="!f() {
+               cat >/dev/null
+               echo username=foo
+               echo password=bar
+       }; f"
+test_expect_success 'respect configured credentials' '
+       test_config credential.helper "$HELPER" &&
+       check fill <<-\EOF
+       --
+       username=foo
+       password=bar
+       --
+       EOF
+'
+
+test_expect_success 'match configured credential' '
+       test_config credential.https://example.com.helper "$HELPER" &&
+       check fill <<-\EOF
+       protocol=https
+       host=example.com
+       path=repo.git
+       --
+       username=foo
+       password=bar
+       --
+       EOF
+'
+
+test_expect_success 'do not match configured credential' '
+       test_config credential.https://foo.helper "$HELPER" &&
+       check fill <<-\EOF
+       protocol=https
+       host=bar
+       --
+       username=askpass-username
+       password=askpass-password
+       --
+       askpass: Username for '\''https://bar'\'':
+       askpass: Password for '\''https://askpass-username@bar'\'':
+       EOF
+'
+
+test_expect_success 'pull username from config' '
+       test_config credential.https://example.com.username foo &&
+       check fill <<-\EOF
+       protocol=https
+       host=example.com
+       --
+       username=foo
+       password=askpass-password
+       --
+       askpass: Password for '\''https://foo@example.com'\'':
+       EOF
+'
+
+test_expect_success 'http paths can be part of context' '
+       check fill "verbatim foo bar" <<-\EOF &&
+       protocol=https
+       host=example.com
+       path=foo.git
+       --
+       username=foo
+       password=bar
+       --
+       verbatim: get
+       verbatim: protocol=https
+       verbatim: host=example.com
+       EOF
+       test_config credential.https://example.com.useHttpPath true &&
+       check fill "verbatim foo bar" <<-\EOF
+       protocol=https
+       host=example.com
+       path=foo.git
+       --
+       username=foo
+       password=bar
+       --
+       verbatim: get
+       verbatim: protocol=https
+       verbatim: host=example.com
+       verbatim: path=foo.git
+       EOF
+'
+
 test_done