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 write_script git-credential-useless <<-\EOF &&
22 write_script git-credential-verbatim <<-\EOF &&
26 test -z "$user" || echo username=$user
27 test -z "$pass" || echo password=$pass
33 test_expect_success
'credential_fill invokes helper' '
34 check fill "verbatim foo bar" <<-\EOF
43 test_expect_success
'credential_fill invokes multiple helpers' '
44 check fill useless "verbatim foo bar" <<-\EOF
54 test_expect_success
'credential_fill stops when we get a full response' '
55 check fill "verbatim one two" "verbatim three four" <<-\EOF
64 test_expect_success
'credential_fill continues through partial response' '
65 check fill "verbatim one \"\"" "verbatim two three" <<-\EOF
72 verbatim: username=one
76 test_expect_success
'credential_fill passes along metadata' '
77 check fill "verbatim one two" <<-\EOF
86 verbatim: protocol=ftp
87 verbatim: host=example.com
88 verbatim: path=foo.git
92 test_expect_success
'credential_approve calls all helpers' '
93 check approve useless "verbatim one two" <<-\EOF
100 useless: password=bar
102 verbatim: username=foo
103 verbatim: password=bar
107 test_expect_success
'do not bother storing password-less credential' '
108 check approve useless <<-\EOF
116 test_expect_success
'credential_reject calls all helpers' '
117 check reject useless "verbatim one two" <<-\EOF
123 useless: username=foo
124 useless: password=bar
126 verbatim: username=foo
127 verbatim: password=bar
131 test_expect_success
'usernames can be preserved' '
132 check fill "verbatim \"\" three" <<-\EOF
139 verbatim: username=one
143 test_expect_success
'usernames can be overridden' '
144 check fill "verbatim two three" <<-\EOF
151 verbatim: username=one
155 test_expect_success
'do not bother completing already-full credential' '
156 check fill "verbatim three four" <<-\EOF
166 # We can't test the basic terminal password prompt here because
167 # getpass() tries too hard to find the real terminal. But if our
168 # askpass helper is run, we know the internal getpass is working.
169 test_expect_success
'empty helper list falls back to internal getpass' '
172 username=askpass-username
173 password=askpass-password
180 test_expect_success
'internal getpass does not ask for known username' '
185 password=askpass-password
196 test_expect_success
'respect configured credentials' '
197 test_config credential.helper "$HELPER" &&
206 test_expect_success
'match configured credential' '
207 test_config credential.https://example.com.helper "$HELPER" &&
219 test_expect_success
'do not match configured credential' '
220 test_config credential.https://foo.helper "$HELPER" &&
225 username=askpass-username
226 password=askpass-password
228 askpass: Username for '\''https://bar'\'':
229 askpass: Password for '\''https://askpass-username@bar'\'':
233 test_expect_success
'pull username from config' '
234 test_config credential.https://example.com.username foo &&
240 password=askpass-password
242 askpass: Password for '\''https://foo@example.com'\'':
246 test_expect_success
'http paths can be part of context' '
247 check fill "verbatim foo bar" <<-\EOF &&
256 verbatim: protocol=https
257 verbatim: host=example.com
259 test_config credential.https://example.com.useHttpPath true &&
260 check fill "verbatim foo bar" <<-\EOF
269 verbatim: protocol=https
270 verbatim: host=example.com
271 verbatim: path=foo.git