Skip to content

Commit 73aafe9

Browse files
peffjrn
authored andcommitted
t0300: use more realistic inputs
Many of the tests in t0300 give partial inputs to git-credential, omitting a protocol or hostname. We're checking only high-level things like whether and how helpers are invoked at all, and we don't care about specific hosts. However, in preparation for tightening up the rules about when we're willing to run a helper, let's start using input that's a bit more realistic: pretend as if http://example.com is being examined. This shouldn't change the point of any of the tests, but do note we have to adjust the expected output to accommodate this (filling a credential will repeat back the protocol/host fields to stdout, and the helper debug messages and askpass prompt will change on stderr). Signed-off-by: Jeff King <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Jonathan Nieder <[email protected]>
1 parent a88dbd2 commit 73aafe9

File tree

1 file changed

+85
-4
lines changed

1 file changed

+85
-4
lines changed

t/t0300-credentials.sh

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,43 +40,71 @@ test_expect_success 'setup helper scripts' '
4040

4141
test_expect_success 'credential_fill invokes helper' '
4242
check fill "verbatim foo bar" <<-\EOF
43+
protocol=http
44+
host=example.com
4345
--
46+
protocol=http
47+
host=example.com
4448
username=foo
4549
password=bar
4650
--
4751
verbatim: get
52+
verbatim: protocol=http
53+
verbatim: host=example.com
4854
EOF
4955
'
5056

5157
test_expect_success 'credential_fill invokes multiple helpers' '
5258
check fill useless "verbatim foo bar" <<-\EOF
59+
protocol=http
60+
host=example.com
5361
--
62+
protocol=http
63+
host=example.com
5464
username=foo
5565
password=bar
5666
--
5767
useless: get
68+
useless: protocol=http
69+
useless: host=example.com
5870
verbatim: get
71+
verbatim: protocol=http
72+
verbatim: host=example.com
5973
EOF
6074
'
6175

6276
test_expect_success 'credential_fill stops when we get a full response' '
6377
check fill "verbatim one two" "verbatim three four" <<-\EOF
78+
protocol=http
79+
host=example.com
6480
--
81+
protocol=http
82+
host=example.com
6583
username=one
6684
password=two
6785
--
6886
verbatim: get
87+
verbatim: protocol=http
88+
verbatim: host=example.com
6989
EOF
7090
'
7191

7292
test_expect_success 'credential_fill continues through partial response' '
7393
check fill "verbatim one \"\"" "verbatim two three" <<-\EOF
94+
protocol=http
95+
host=example.com
7496
--
97+
protocol=http
98+
host=example.com
7599
username=two
76100
password=three
77101
--
78102
verbatim: get
103+
verbatim: protocol=http
104+
verbatim: host=example.com
79105
verbatim: get
106+
verbatim: protocol=http
107+
verbatim: host=example.com
80108
verbatim: username=one
81109
EOF
82110
'
@@ -102,21 +130,29 @@ test_expect_success 'credential_fill passes along metadata' '
102130

103131
test_expect_success 'credential_approve calls all helpers' '
104132
check approve useless "verbatim one two" <<-\EOF
133+
protocol=http
134+
host=example.com
105135
username=foo
106136
password=bar
107137
--
108138
--
109139
useless: store
140+
useless: protocol=http
141+
useless: host=example.com
110142
useless: username=foo
111143
useless: password=bar
112144
verbatim: store
145+
verbatim: protocol=http
146+
verbatim: host=example.com
113147
verbatim: username=foo
114148
verbatim: password=bar
115149
EOF
116150
'
117151

118152
test_expect_success 'do not bother storing password-less credential' '
119153
check approve useless <<-\EOF
154+
protocol=http
155+
host=example.com
120156
username=foo
121157
--
122158
--
@@ -126,48 +162,70 @@ test_expect_success 'do not bother storing password-less credential' '
126162

127163
test_expect_success 'credential_reject calls all helpers' '
128164
check reject useless "verbatim one two" <<-\EOF
165+
protocol=http
166+
host=example.com
129167
username=foo
130168
password=bar
131169
--
132170
--
133171
useless: erase
172+
useless: protocol=http
173+
useless: host=example.com
134174
useless: username=foo
135175
useless: password=bar
136176
verbatim: erase
177+
verbatim: protocol=http
178+
verbatim: host=example.com
137179
verbatim: username=foo
138180
verbatim: password=bar
139181
EOF
140182
'
141183

142184
test_expect_success 'usernames can be preserved' '
143185
check fill "verbatim \"\" three" <<-\EOF
186+
protocol=http
187+
host=example.com
144188
username=one
145189
--
190+
protocol=http
191+
host=example.com
146192
username=one
147193
password=three
148194
--
149195
verbatim: get
196+
verbatim: protocol=http
197+
verbatim: host=example.com
150198
verbatim: username=one
151199
EOF
152200
'
153201

154202
test_expect_success 'usernames can be overridden' '
155203
check fill "verbatim two three" <<-\EOF
204+
protocol=http
205+
host=example.com
156206
username=one
157207
--
208+
protocol=http
209+
host=example.com
158210
username=two
159211
password=three
160212
--
161213
verbatim: get
214+
verbatim: protocol=http
215+
verbatim: host=example.com
162216
verbatim: username=one
163217
EOF
164218
'
165219

166220
test_expect_success 'do not bother completing already-full credential' '
167221
check fill "verbatim three four" <<-\EOF
222+
protocol=http
223+
host=example.com
168224
username=one
169225
password=two
170226
--
227+
protocol=http
228+
host=example.com
171229
username=one
172230
password=two
173231
--
@@ -179,23 +237,31 @@ test_expect_success 'do not bother completing already-full credential' '
179237
# askpass helper is run, we know the internal getpass is working.
180238
test_expect_success 'empty helper list falls back to internal getpass' '
181239
check fill <<-\EOF
240+
protocol=http
241+
host=example.com
182242
--
243+
protocol=http
244+
host=example.com
183245
username=askpass-username
184246
password=askpass-password
185247
--
186-
askpass: Username:
187-
askpass: Password:
248+
askpass: Username for '\''http://example.com'\'':
249+
askpass: Password for '\''http://[email protected]'\'':
188250
EOF
189251
'
190252

191253
test_expect_success 'internal getpass does not ask for known username' '
192254
check fill <<-\EOF
255+
protocol=http
256+
host=example.com
193257
username=foo
194258
--
259+
protocol=http
260+
host=example.com
195261
username=foo
196262
password=askpass-password
197263
--
198-
askpass: Password:
264+
askpass: Password for '\''http://[email protected]'\'':
199265
EOF
200266
'
201267

@@ -207,7 +273,11 @@ HELPER="!f() {
207273
test_expect_success 'respect configured credentials' '
208274
test_config credential.helper "$HELPER" &&
209275
check fill <<-\EOF
276+
protocol=http
277+
host=example.com
210278
--
279+
protocol=http
280+
host=example.com
211281
username=foo
212282
password=bar
213283
--
@@ -298,11 +368,16 @@ test_expect_success 'helpers can abort the process' '
298368
test_must_fail git \
299369
-c credential.helper=quit \
300370
-c credential.helper="verbatim foo bar" \
301-
credential fill >stdout 2>stderr &&
371+
credential fill >stdout 2>stderr <<-\EOF &&
372+
protocol=http
373+
host=example.com
374+
EOF
302375
>expect &&
303376
test_cmp expect stdout &&
304377
cat >expect <<-\EOF &&
305378
quit: get
379+
quit: protocol=http
380+
quit: host=example.com
306381
fatal: credential helper '\''quit'\'' told us to quit
307382
EOF
308383
test_i18ncmp expect stderr
@@ -311,11 +386,17 @@ test_expect_success 'helpers can abort the process' '
311386
test_expect_success 'empty helper spec resets helper list' '
312387
test_config credential.helper "verbatim file file" &&
313388
check fill "" "verbatim cmdline cmdline" <<-\EOF
389+
protocol=http
390+
host=example.com
314391
--
392+
protocol=http
393+
host=example.com
315394
username=cmdline
316395
password=cmdline
317396
--
318397
verbatim: get
398+
verbatim: protocol=http
399+
verbatim: host=example.com
319400
EOF
320401
'
321402

0 commit comments

Comments
 (0)