MSVC: require pton and ntop emulation
[git/dscho.git] / t / t0300-credentials.sh
blob8621ab036f91d0b7dcf96a1964611b8cafc3adbd
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 while IFS== read key value; do
12 echo >&2 "$whoami: $key=$value"
13 eval "$key=$value"
14 done
15 EOF
17 write_script git-credential-useless <<-\EOF &&
18 . ./dump
19 exit 0
20 EOF
22 write_script git-credential-verbatim <<-\EOF &&
23 user=$1; shift
24 pass=$1; shift
25 . ./dump
26 test -z "$user" || echo username=$user
27 test -z "$pass" || echo password=$pass
28 EOF
30 PATH="$PWD:$PATH"
33 test_expect_success 'credential_fill invokes helper' '
34 check fill "verbatim foo bar" <<-\EOF
36 username=foo
37 password=bar
39 verbatim: get
40 EOF
43 test_expect_success 'credential_fill invokes multiple helpers' '
44 check fill useless "verbatim foo bar" <<-\EOF
46 username=foo
47 password=bar
49 useless: get
50 verbatim: get
51 EOF
54 test_expect_success 'credential_fill stops when we get a full response' '
55 check fill "verbatim one two" "verbatim three four" <<-\EOF
57 username=one
58 password=two
60 verbatim: get
61 EOF
64 test_expect_success 'credential_fill continues through partial response' '
65 check fill "verbatim one \"\"" "verbatim two three" <<-\EOF
67 username=two
68 password=three
70 verbatim: get
71 verbatim: get
72 verbatim: username=one
73 EOF
76 test_expect_success 'credential_fill passes along metadata' '
77 check fill "verbatim one two" <<-\EOF
78 protocol=ftp
79 host=example.com
80 path=foo.git
82 username=one
83 password=two
85 verbatim: get
86 verbatim: protocol=ftp
87 verbatim: host=example.com
88 verbatim: path=foo.git
89 EOF
92 test_expect_success 'credential_approve calls all helpers' '
93 check approve useless "verbatim one two" <<-\EOF
94 username=foo
95 password=bar
98 useless: store
99 useless: username=foo
100 useless: password=bar
101 verbatim: store
102 verbatim: username=foo
103 verbatim: password=bar
107 test_expect_success 'do not bother storing password-less credential' '
108 check approve useless <<-\EOF
109 username=foo
116 test_expect_success 'credential_reject calls all helpers' '
117 check reject useless "verbatim one two" <<-\EOF
118 username=foo
119 password=bar
122 useless: erase
123 useless: username=foo
124 useless: password=bar
125 verbatim: erase
126 verbatim: username=foo
127 verbatim: password=bar
131 test_expect_success 'usernames can be preserved' '
132 check fill "verbatim \"\" three" <<-\EOF
133 username=one
135 username=one
136 password=three
138 verbatim: get
139 verbatim: username=one
143 test_expect_success 'usernames can be overridden' '
144 check fill "verbatim two three" <<-\EOF
145 username=one
147 username=two
148 password=three
150 verbatim: get
151 verbatim: username=one
155 test_expect_success 'do not bother completing already-full credential' '
156 check fill "verbatim three four" <<-\EOF
157 username=one
158 password=two
160 username=one
161 password=two
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' '
170 check fill <<-\EOF
172 username=askpass-username
173 password=askpass-password
175 askpass: Username:
176 askpass: Password:
180 test_expect_success 'internal getpass does not ask for known username' '
181 check fill <<-\EOF
182 username=foo
184 username=foo
185 password=askpass-password
187 askpass: Password:
191 HELPER="!f() {
192 cat >/dev/null
193 echo username=foo
194 echo password=bar
195 }; f"
196 test_expect_success 'respect configured credentials' '
197 test_config credential.helper "$HELPER" &&
198 check fill <<-\EOF
200 username=foo
201 password=bar
206 test_expect_success 'match configured credential' '
207 test_config credential.https://example.com.helper "$HELPER" &&
208 check fill <<-\EOF
209 protocol=https
210 host=example.com
211 path=repo.git
213 username=foo
214 password=bar
219 test_expect_success 'do not match configured credential' '
220 test_config credential.https://foo.helper "$HELPER" &&
221 check fill <<-\EOF
222 protocol=https
223 host=bar
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 &&
235 check fill <<-\EOF
236 protocol=https
237 host=example.com
239 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 &&
248 protocol=https
249 host=example.com
250 path=foo.git
252 username=foo
253 password=bar
255 verbatim: get
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
261 protocol=https
262 host=example.com
263 path=foo.git
265 username=foo
266 password=bar
268 verbatim: get
269 verbatim: protocol=https
270 verbatim: host=example.com
271 verbatim: path=foo.git
275 test_done