3 test_description='basic credential helper tests'
5 . "$TEST_DIRECTORY"/lib-credential.sh
7 test_expect_success 'setup helper scripts' '
9 whoami=`echo $0 | sed s/.*git-credential-//`
10 echo >&2 "$whoami: $*"
13 while read key value; do
14 echo >&2 "$whoami: $key=$value"
20 write_script git-credential-useless <<-\EOF &&
25 write_script git-credential-verbatim <<-\EOF &&
29 test -z "$user" || echo username=$user
30 test -z "$pass" || echo password=$pass
36 test_expect_success 'credential_fill invokes helper' '
37 check fill "verbatim foo bar" <<-\EOF
46 test_expect_success 'credential_fill invokes multiple helpers' '
47 check fill useless "verbatim foo bar" <<-\EOF
57 test_expect_success 'credential_fill stops when we get a full response' '
58 check fill "verbatim one two" "verbatim three four" <<-\EOF
67 test_expect_success 'credential_fill continues through partial response' '
68 check fill "verbatim one \"\"" "verbatim two three" <<-\EOF
75 verbatim: username=one
79 test_expect_success 'credential_fill passes along metadata' '
80 check fill "verbatim one two" <<-\EOF
89 verbatim: protocol=ftp
90 verbatim: host=example.com
91 verbatim: path=foo.git
95 test_expect_success 'credential_approve calls all helpers' '
96 check approve useless "verbatim one two" <<-\EOF
102 useless: username=foo
103 useless: password=bar
105 verbatim: username=foo
106 verbatim: password=bar
110 test_expect_success 'do not bother storing password-less credential' '
111 check approve useless <<-\EOF
119 test_expect_success 'credential_reject calls all helpers' '
120 check reject useless "verbatim one two" <<-\EOF
126 useless: username=foo
127 useless: password=bar
129 verbatim: username=foo
130 verbatim: password=bar
134 test_expect_success 'usernames can be preserved' '
135 check fill "verbatim \"\" three" <<-\EOF
142 verbatim: username=one
146 test_expect_success 'usernames can be overridden' '
147 check fill "verbatim two three" <<-\EOF
154 verbatim: username=one
158 test_expect_success 'do not bother completing already-full credential' '
159 check fill "verbatim three four" <<-\EOF
169 # We can't test the basic terminal password prompt here because
170 # getpass() tries too hard to find the real terminal. But if our
171 # askpass helper is run, we know the internal getpass is working.
172 test_expect_success 'empty helper list falls back to internal getpass' '
175 username=askpass-username
176 password=askpass-password
183 test_expect_success 'internal getpass does not ask for known username' '
188 password=askpass-password
199 test_expect_success 'respect configured credentials' '
200 test_config credential.helper "$HELPER" &&
209 test_expect_success 'match configured credential' '
210 test_config credential.https://example.com.helper "$HELPER" &&
222 test_expect_success 'do not match configured credential' '
223 test_config credential.https://foo.helper "$HELPER" &&
228 username=askpass-username
229 password=askpass-password
231 askpass: Username for '\''https://bar'\'':
232 askpass: Password for '\''https://askpass-username@bar'\'':
236 test_expect_success 'pull username from config' '
237 test_config credential.https://example.com.username foo &&
243 password=askpass-password
245 askpass: Password for '\''https://foo@example.com'\'':
249 test_expect_success 'http paths can be part of context' '
250 check fill "verbatim foo bar" <<-\EOF &&
259 verbatim: protocol=https
260 verbatim: host=example.com
262 test_config credential.https://example.com.useHttpPath true &&
263 check fill "verbatim foo bar" <<-\EOF
272 verbatim: protocol=https
273 verbatim: host=example.com
274 verbatim: path=foo.git