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
92 verbatim: protocol=ftp
93 verbatim: host=example.com
94 verbatim: path=foo.git
98 test_expect_success 'credential_approve calls all helpers' '
99 check approve useless "verbatim one two" <<-\EOF
105 useless: username=foo
106 useless: password=bar
108 verbatim: username=foo
109 verbatim: password=bar
113 test_expect_success 'do not bother storing password-less credential' '
114 check approve useless <<-\EOF
122 test_expect_success 'credential_reject calls all helpers' '
123 check reject useless "verbatim one two" <<-\EOF
129 useless: username=foo
130 useless: password=bar
132 verbatim: username=foo
133 verbatim: password=bar
137 test_expect_success 'usernames can be preserved' '
138 check fill "verbatim \"\" three" <<-\EOF
145 verbatim: username=one
149 test_expect_success 'usernames can be overridden' '
150 check fill "verbatim two three" <<-\EOF
157 verbatim: username=one
161 test_expect_success 'do not bother completing already-full credential' '
162 check fill "verbatim three four" <<-\EOF
172 # We can't test the basic terminal password prompt here because
173 # getpass() tries too hard to find the real terminal. But if our
174 # askpass helper is run, we know the internal getpass is working.
175 test_expect_success 'empty helper list falls back to internal getpass' '
178 username=askpass-username
179 password=askpass-password
186 test_expect_success 'internal getpass does not ask for known username' '
191 password=askpass-password
202 test_expect_success 'respect configured credentials' '
203 test_config credential.helper "$HELPER" &&
212 test_expect_success 'match configured credential' '
213 test_config credential.https://example.com.helper "$HELPER" &&
227 test_expect_success 'do not match configured credential' '
228 test_config credential.https://foo.helper "$HELPER" &&
235 username=askpass-username
236 password=askpass-password
238 askpass: Username for '\''https://bar'\'':
239 askpass: Password for '\''https://askpass-username@bar'\'':
243 test_expect_success 'match multiple configured helpers' '
244 test_config credential.helper "verbatim \"\" \"\"" &&
245 test_config credential.https://example.com.helper "$HELPER" &&
257 verbatim: protocol=https
258 verbatim: host=example.com
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" &&
276 verbatim: protocol=https
277 verbatim: host=example.com
281 test_expect_success 'match percent-encoded values' '
282 test_config credential.https://example.com/%2566.git.helper "$HELPER" &&
284 url=https://example.com/%2566.git
294 test_expect_success 'pull username from config' '
295 test_config credential.https://example.com.username foo &&
303 password=askpass-password
305 askpass: Password for '\''https://foo@example.com'\'':
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" &&
313 url=https://alice@example.com
321 verbatim: protocol=https
322 verbatim: host=example.com
323 verbatim: username=alice
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" &&
341 verbatim: protocol=https
342 verbatim: host=example.com
343 verbatim: username=alice
347 test_expect_success '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" &&
352 url=https://example.com/path.git
360 verbatim: protocol=https
361 verbatim: host=example.com
362 verbatim: username=alice
366 test_expect_success 'http paths can be part of context' '
367 check fill "verbatim foo bar" <<-\EOF &&
378 verbatim: protocol=https
379 verbatim: host=example.com
381 test_config credential.https://example.com.useHttpPath true &&
382 check fill "verbatim foo bar" <<-\EOF
394 verbatim: protocol=https
395 verbatim: host=example.com
396 verbatim: path=foo.git
400 test_expect_success 'context uses urlmatch' '
401 test_config "credential.https://*.org.useHttpPath" true &&
402 check fill "verbatim foo bar" <<-\EOF
414 verbatim: protocol=https
415 verbatim: host=example.org
416 verbatim: path=foo.git
420 test_expect_success 'helpers can abort the process' '
422 -c credential.helper="!f() { echo quit=1; }; f" \
423 -c credential.helper="verbatim foo bar" \
424 credential fill >stdout &&
425 test_must_be_empty stdout
428 test_expect_success 'empty helper spec resets helper list' '
429 test_config credential.helper "verbatim file file" &&
430 check fill "" "verbatim cmdline cmdline" <<-\EOF