send-email: improve RFC2047 quote parsing
[git/jrn.git] / t / t0300-credentials.sh
blobc1c8108148351ab3ec3db3f2615ff88f29d38974
1 #!/bin/sh
3 test_description='basic credential helper tests'
4 . ./test-lib.sh
5 . "$TEST_DIRECTORY"/lib-credential.sh
7 test_expect_success 'setup helper scripts' '
8 cat >dump <<-\EOF &&
9 whoami=`echo $0 | sed s/.*git-credential-//`
10 echo >&2 "$whoami: $*"
11 OIFS=$IFS
12 IFS==
13 while read key value; do
14 echo >&2 "$whoami: $key=$value"
15 eval "$key=$value"
16 done
17 IFS=$OIFS
18 EOF
20 cat >git-credential-useless <<-\EOF &&
21 #!/bin/sh
22 . ./dump
23 exit 0
24 EOF
25 chmod +x git-credential-useless &&
27 cat >git-credential-verbatim <<-\EOF &&
28 #!/bin/sh
29 user=$1; shift
30 pass=$1; shift
31 . ./dump
32 test -z "$user" || echo username=$user
33 test -z "$pass" || echo password=$pass
34 EOF
35 chmod +x git-credential-verbatim &&
37 PATH="$PWD:$PATH"
40 test_expect_success 'credential_fill invokes helper' '
41 check fill "verbatim foo bar" <<-\EOF
43 username=foo
44 password=bar
46 verbatim: get
47 EOF
50 test_expect_success 'credential_fill invokes multiple helpers' '
51 check fill useless "verbatim foo bar" <<-\EOF
53 username=foo
54 password=bar
56 useless: get
57 verbatim: get
58 EOF
61 test_expect_success 'credential_fill stops when we get a full response' '
62 check fill "verbatim one two" "verbatim three four" <<-\EOF
64 username=one
65 password=two
67 verbatim: get
68 EOF
71 test_expect_success 'credential_fill continues through partial response' '
72 check fill "verbatim one \"\"" "verbatim two three" <<-\EOF
74 username=two
75 password=three
77 verbatim: get
78 verbatim: get
79 verbatim: username=one
80 EOF
83 test_expect_success 'credential_fill passes along metadata' '
84 check fill "verbatim one two" <<-\EOF
85 protocol=ftp
86 host=example.com
87 path=foo.git
89 username=one
90 password=two
92 verbatim: get
93 verbatim: protocol=ftp
94 verbatim: host=example.com
95 verbatim: path=foo.git
96 EOF
99 test_expect_success 'credential_approve calls all helpers' '
100 check approve useless "verbatim one two" <<-\EOF
101 username=foo
102 password=bar
105 useless: store
106 useless: username=foo
107 useless: password=bar
108 verbatim: store
109 verbatim: username=foo
110 verbatim: password=bar
114 test_expect_success 'do not bother storing password-less credential' '
115 check approve useless <<-\EOF
116 username=foo
123 test_expect_success 'credential_reject calls all helpers' '
124 check reject useless "verbatim one two" <<-\EOF
125 username=foo
126 password=bar
129 useless: erase
130 useless: username=foo
131 useless: password=bar
132 verbatim: erase
133 verbatim: username=foo
134 verbatim: password=bar
138 test_expect_success 'usernames can be preserved' '
139 check fill "verbatim \"\" three" <<-\EOF
140 username=one
142 username=one
143 password=three
145 verbatim: get
146 verbatim: username=one
150 test_expect_success 'usernames can be overridden' '
151 check fill "verbatim two three" <<-\EOF
152 username=one
154 username=two
155 password=three
157 verbatim: get
158 verbatim: username=one
162 test_expect_success 'do not bother completing already-full credential' '
163 check fill "verbatim three four" <<-\EOF
164 username=one
165 password=two
167 username=one
168 password=two
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' '
177 check fill <<-\EOF
179 username=askpass-username
180 password=askpass-password
182 askpass: Username:
183 askpass: Password:
187 test_expect_success 'internal getpass does not ask for known username' '
188 check fill <<-\EOF
189 username=foo
191 username=foo
192 password=askpass-password
194 askpass: Password:
198 HELPER="!f() {
199 cat >/dev/null
200 echo username=foo
201 echo password=bar
202 }; f"
203 test_expect_success 'respect configured credentials' '
204 test_config credential.helper "$HELPER" &&
205 check fill <<-\EOF
207 username=foo
208 password=bar
213 test_expect_success 'match configured credential' '
214 test_config credential.https://example.com.helper "$HELPER" &&
215 check fill <<-\EOF
216 protocol=https
217 host=example.com
218 path=repo.git
220 username=foo
221 password=bar
226 test_expect_success 'do not match configured credential' '
227 test_config credential.https://foo.helper "$HELPER" &&
228 check fill <<-\EOF
229 protocol=https
230 host=bar
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 &&
242 check fill <<-\EOF
243 protocol=https
244 host=example.com
246 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 &&
255 protocol=https
256 host=example.com
257 path=foo.git
259 username=foo
260 password=bar
262 verbatim: get
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
268 protocol=https
269 host=example.com
270 path=foo.git
272 username=foo
273 password=bar
275 verbatim: get
276 verbatim: protocol=https
277 verbatim: host=example.com
278 verbatim: path=foo.git
282 test_done