3 test_description='basic credential helper tests'
6 # Try a set of credential helpers; the expected
7 # stdout and stderr should be provided on stdin,
15 done >expect-stdout &&
17 test-credential "$@" >stdout 2>stderr &&
18 test_cmp expect-stdout stdout &&
19 test_cmp expect-stderr stderr
22 test_expect_success 'setup helper scripts' '
26 echo >&2 "$whoami: <empty>"
29 echo >&2 "$whoami: $i"
35 cat >git-credential-useless <<-\EOF &&
40 chmod +x git-credential-useless &&
42 cat >git-credential-verbatim <<-\EOF &&
47 test -z "$user" || echo username=$user
48 test -z "$pass" || echo password=$pass
50 chmod +x git-credential-verbatim &&
52 cat >askpass <<-\EOF &&
58 GIT_ASKPASS=askpass &&
64 test_expect_success 'credential_fill invokes helper' '
65 check "verbatim foo bar" <<-\EOF
73 test_expect_success 'credential_fill invokes multiple helpers' '
74 check useless "verbatim foo bar" <<-\EOF
83 test_expect_success 'credential_fill stops when we get a full response' '
84 check "verbatim one two" "verbatim three four" <<-\EOF
92 test_expect_success 'credential_fill continues through partial response' '
93 check "verbatim one \"\"" "verbatim two three" <<-\EOF
98 verbatim: --username=one
102 test_expect_success 'credential_fill passes along metadata' '
103 check --description=foo --unique=bar "verbatim one two" <<-\EOF
107 verbatim: --description=foo
108 verbatim: --unique=bar
112 test_expect_success 'credential_reject calls all helpers' '
113 check --reject --username=foo useless "verbatim one two" <<-\EOF
116 useless: --username=foo
118 verbatim: --username=foo
122 test_expect_success 'do not bother rejecting empty credential' '
123 check --reject useless <<-\EOF
128 test_expect_success 'usernames can be preserved' '
129 check --username=one "verbatim \"\" three" <<-\EOF
133 verbatim: --username=one
136 test_expect_success 'usernames can be overridden' '
137 check --username=one "verbatim two three" <<-\EOF
141 verbatim: --username=one
145 test_expect_success 'do not bother completing already-full credential' '
146 check --username=one --password=two "verbatim three four" <<-\EOF
153 # We can't test the basic terminal password prompt here because
154 # getpass() tries too hard to find the real terminal. But if our
155 # askpass helper is run, we know the internal getpass is working.
156 test_expect_success 'empty methods falls back to internal getpass' '
158 username=askpass-result
159 password=askpass-result
166 test_expect_success 'internal getpass does not ask for known username' '
167 check --username=foo <<-\EOF
169 password=askpass-result
175 test_expect_success 'internal getpass can pull from config' '
176 git config credential.foo.username configured-username
177 check --unique=foo <<-\EOF
178 username=configured-username
179 password=askpass-result
185 test_expect_success 'credential-cache caches password' '
186 test_when_finished "git credential-cache --exit" &&
187 check --unique=host cache <<-\EOF &&
188 username=askpass-result
189 password=askpass-result
194 check --unique=host cache <<-\EOF
195 username=askpass-result
196 password=askpass-result
201 test_expect_success 'credential-cache requires matching unique token' '
202 test_when_finished "git credential-cache --exit" &&
203 check --unique=host cache <<-\EOF &&
204 username=askpass-result
205 password=askpass-result
210 check --unique=host2 cache <<-\EOF
211 username=askpass-result
212 password=askpass-result
219 test_expect_success 'credential-cache requires matching usernames' '
220 test_when_finished "git credential-cache --exit" &&
221 check --unique=host cache <<-\EOF &&
222 username=askpass-result
223 password=askpass-result
228 check --unique=host --username=other cache <<-\EOF
230 password=askpass-result
236 test_expect_success 'credential-cache times out' '
237 test_when_finished "git credential-cache --exit || true" &&
238 check --unique=host "cache --timeout=1" <<-\EOF &&
239 username=askpass-result
240 password=askpass-result
246 check --unique=host cache <<-\EOF
247 username=askpass-result
248 password=askpass-result
255 test_expect_success 'credential-cache removes rejected credentials' '
256 test_when_finished "git credential-cache --exit || true" &&
257 check --unique=host cache <<-\EOF &&
258 username=askpass-result
259 password=askpass-result
264 check --reject --unique=host --username=askpass-result cache <<-\EOF &&
267 check --unique=host cache <<-\EOF
268 username=askpass-result
269 password=askpass-result
276 test_expect_success 'credential-store stores password' '
277 test_when_finished "rm -f .git-credentials" &&
278 check --unique=host store <<-\EOF &&
279 username=askpass-result
280 password=askpass-result
285 check --unique=host store <<-\EOF
286 username=askpass-result
287 password=askpass-result
292 test_expect_success 'credential-store requires matching unique token' '
293 test_when_finished "rm -f .git-credentials" &&
294 check --unique=host store <<-\EOF &&
295 username=askpass-result
296 password=askpass-result
301 check --unique=host2 store <<-\EOF
302 username=askpass-result
303 password=askpass-result
310 test_expect_success 'credential-store removes rejected credentials' '
311 test_when_finished "rm -f .git-credentials" &&
312 check --unique=host store <<-\EOF &&
313 username=askpass-result
314 password=askpass-result
319 check --reject --unique=host --username=askpass-result store <<-\EOF &&
322 check --unique=host store <<-\EOF
323 username=askpass-result
324 password=askpass-result