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 cat >git-credential-useless <<-\EOF &&
25 chmod +x git-credential-useless &&
27 cat >git-credential-verbatim <<-\EOF &&
32 test -z "$user" || echo username=$user
33 test -z "$pass" || echo password=$pass
35 chmod +x git-credential-verbatim &&
40 test_expect_success
'credential_fill invokes helper' '
41 check fill "verbatim foo bar" <<-\EOF
50 test_expect_success
'credential_fill invokes multiple helpers' '
51 check fill useless "verbatim foo bar" <<-\EOF
61 test_expect_success
'credential_fill stops when we get a full response' '
62 check fill "verbatim one two" "verbatim three four" <<-\EOF
71 test_expect_success
'credential_fill continues through partial response' '
72 check fill "verbatim one \"\"" "verbatim two three" <<-\EOF
79 verbatim: username=one
83 test_expect_success
'credential_fill passes along metadata' '
84 check fill "verbatim one two" <<-\EOF
93 verbatim: protocol=ftp
94 verbatim: host=example.com
95 verbatim: path=foo.git
99 test_expect_success
'credential_approve calls all helpers' '
100 check approve useless "verbatim one two" <<-\EOF
106 useless: username=foo
107 useless: password=bar
109 verbatim: username=foo
110 verbatim: password=bar
114 test_expect_success
'do not bother storing password-less credential' '
115 check approve useless <<-\EOF
123 test_expect_success
'credential_reject calls all helpers' '
124 check reject useless "verbatim one two" <<-\EOF
130 useless: username=foo
131 useless: password=bar
133 verbatim: username=foo
134 verbatim: password=bar
138 test_expect_success
'usernames can be preserved' '
139 check fill "verbatim \"\" three" <<-\EOF
146 verbatim: username=one
150 test_expect_success
'usernames can be overridden' '
151 check fill "verbatim two three" <<-\EOF
158 verbatim: username=one
162 test_expect_success
'do not bother completing already-full credential' '
163 check fill "verbatim three four" <<-\EOF
173 # We can't test the basic terminal password prompt here because
174 # getpass() tries too hard to find the real terminal. But if our
175 # askpass helper is run, we know the internal getpass is working.
176 test_expect_success
'empty helper list falls back to internal getpass' '
179 username=askpass-username
180 password=askpass-password
187 test_expect_success
'internal getpass does not ask for known username' '
192 password=askpass-password
203 test_expect_success
'respect configured credentials' '
204 test_config credential.helper "$HELPER" &&
213 test_expect_success
'match configured credential' '
214 test_config credential.https://example.com.helper "$HELPER" &&
226 test_expect_success
'do not match configured credential' '
227 test_config credential.https://foo.helper "$HELPER" &&
232 username=askpass-username
233 password=askpass-password
235 askpass: Username for '\''https://bar'\'':
236 askpass: Password for '\''https://askpass-username@bar'\'':
240 test_expect_success
'pull username from config' '
241 test_config credential.https://example.com.username foo &&
247 password=askpass-password
249 askpass: Password for '\''https://foo@example.com'\'':
253 test_expect_success
'http paths can be part of context' '
254 check fill "verbatim foo bar" <<-\EOF &&
263 verbatim: protocol=https
264 verbatim: host=example.com
266 test_config credential.https://example.com.useHttpPath true &&
267 check fill "verbatim foo bar" <<-\EOF
276 verbatim: protocol=https
277 verbatim: host=example.com
278 verbatim: path=foo.git