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: $*"
11 while IFS== read key value; do
12 echo >&2 "$whoami: $key=$value"
17 cat >git-credential-useless <<-\EOF &&
22 chmod +x git-credential-useless &&
24 cat >git-credential-verbatim <<-\EOF &&
29 test -z "$user" || echo username=$user
30 test -z "$pass" || echo password=$pass
32 chmod +x git-credential-verbatim &&
37 test_expect_success
'credential_fill invokes helper' '
38 check fill "verbatim foo bar" <<-\EOF
47 test_expect_success
'credential_fill invokes multiple helpers' '
48 check fill useless "verbatim foo bar" <<-\EOF
58 test_expect_success
'credential_fill stops when we get a full response' '
59 check fill "verbatim one two" "verbatim three four" <<-\EOF
68 test_expect_success
'credential_fill continues through partial response' '
69 check fill "verbatim one \"\"" "verbatim two three" <<-\EOF
76 verbatim: username=one
80 test_expect_success
'credential_fill passes along metadata' '
81 check fill "verbatim one two" <<-\EOF
90 verbatim: protocol=ftp
91 verbatim: host=example.com
92 verbatim: path=foo.git
96 test_expect_success
'credential_approve calls all helpers' '
97 check approve useless "verbatim one two" <<-\EOF
103 useless: username=foo
104 useless: password=bar
106 verbatim: username=foo
107 verbatim: password=bar
111 test_expect_success
'do not bother storing password-less credential' '
112 check approve useless <<-\EOF
120 test_expect_success
'credential_reject calls all helpers' '
121 check reject useless "verbatim one two" <<-\EOF
127 useless: username=foo
128 useless: password=bar
130 verbatim: username=foo
131 verbatim: password=bar
135 test_expect_success
'usernames can be preserved' '
136 check fill "verbatim \"\" three" <<-\EOF
143 verbatim: username=one
147 test_expect_success
'usernames can be overridden' '
148 check fill "verbatim two three" <<-\EOF
155 verbatim: username=one
159 test_expect_success
'do not bother completing already-full credential' '
160 check fill "verbatim three four" <<-\EOF
170 # We can't test the basic terminal password prompt here because
171 # getpass() tries too hard to find the real terminal. But if our
172 # askpass helper is run, we know the internal getpass is working.
173 test_expect_success
'empty helper list falls back to internal getpass' '
176 username=askpass-username
177 password=askpass-password
184 test_expect_success
'internal getpass does not ask for known username' '
189 password=askpass-password
200 test_expect_success
'respect configured credentials' '
201 test_config credential.helper "$HELPER" &&
210 test_expect_success
'match configured credential' '
211 test_config credential.https://example.com.helper "$HELPER" &&
223 test_expect_success
'do not match configured credential' '
224 test_config credential.https://foo.helper "$HELPER" &&
229 username=askpass-username
230 password=askpass-password
232 askpass: Username for '\''https://bar'\'':
233 askpass: Password for '\''https://askpass-username@bar'\'':
237 test_expect_success
'pull username from config' '
238 test_config credential.https://example.com.username foo &&
244 password=askpass-password
246 askpass: Password for '\''https://foo@example.com'\'':
250 test_expect_success
'http paths can be part of context' '
251 check fill "verbatim foo bar" <<-\EOF &&
260 verbatim: protocol=https
261 verbatim: host=example.com
263 test_config credential.https://example.com.useHttpPath true &&
264 check fill "verbatim foo bar" <<-\EOF
273 verbatim: protocol=https
274 verbatim: host=example.com
275 verbatim: path=foo.git