1
1
//! Tests for git authentication.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use std:: collections:: HashSet ;
6
4
use std:: io:: prelude:: * ;
7
5
use std:: io:: BufReader ;
@@ -12,7 +10,7 @@ use std::thread::{self, JoinHandle};
12
10
13
11
use cargo_test_support:: git:: cargo_uses_gitoxide;
14
12
use cargo_test_support:: paths;
15
- use cargo_test_support:: { basic_manifest, project} ;
13
+ use cargo_test_support:: { basic_manifest, project, str } ;
16
14
17
15
fn setup_failed_auth_test ( ) -> ( SocketAddr , JoinHandle < ( ) > , Arc < AtomicUsize > ) {
18
16
let server = TcpListener :: bind ( "127.0.0.1:0" ) . unwrap ( ) ;
@@ -138,10 +136,10 @@ fn http_auth_offered() {
138
136
// may span multiple lines, and isn't relevant to this test.
139
137
p. cargo ( "check" )
140
138
. with_status ( 101 )
141
- . with_stderr_contains ( & format ! (
139
+ . with_stderr_data ( & format ! (
142
140
"\
143
141
[UPDATING] git repository `http://{addr}/foo/bar`
144
- [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 [..] `
142
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo) `
145
143
146
144
Caused by:
147
145
failed to load source for dependency `bar`
@@ -150,21 +148,29 @@ Caused by:
150
148
Unable to update http://{addr}/foo/bar
151
149
152
150
Caused by:
153
- failed to clone into: [.. ]
151
+ failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH ]
154
152
155
153
Caused by:
156
154
failed to authenticate when downloading repository
157
155
158
- * attempted to find username/password via `credential.helper`, but [..]
156
+ * attempted to find username/password via `credential.helper`, but maybe the found credentials were incorrect
159
157
160
158
if the git CLI succeeds then `net.git-fetch-with-cli` may help here
161
- https://[..]
159
+ https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
162
160
163
161
Caused by:
164
- "
162
+ {trailer}
163
+ " ,
164
+ trailer = if cargo_uses_gitoxide( ) {
165
+ format!( r#"[CREDENTIAL]s provided for "http://{addr}/foo/bar" were not accepted by the remote
166
+
167
+ Caused by:
168
+ Received HTTP status 401"# )
169
+ } else {
170
+ " no authentication methods succeeded" . to_string( )
171
+ }
165
172
) )
166
173
. run ( ) ;
167
-
168
174
assert_eq ! ( connections. load( SeqCst ) , 2 ) ;
169
175
t. join ( ) . ok ( ) . unwrap ( ) ;
170
176
}
@@ -209,16 +215,33 @@ fn https_something_happens() {
209
215
210
216
p. cargo ( "check -v" )
211
217
. with_status ( 101 )
212
- . with_stderr_contains ( & format ! (
213
- "[UPDATING] git repository `https://{addr}/foo/bar`"
214
- ) )
215
- . with_stderr_contains ( & format ! (
218
+ . with_stderr_data ( & format ! (
216
219
"\
220
+ [UPDATING] git repository `https://{addr}/foo/bar`
221
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
222
+
223
+ Caused by:
224
+ failed to load source for dependency `bar`
225
+
226
+ Caused by:
227
+ Unable to update https://{addr}/foo/bar
228
+
229
+ Caused by:
230
+ failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
231
+
217
232
Caused by:
218
- {errmsg}
233
+ {errmsg}
219
234
" ,
220
235
errmsg = if cargo_uses_gitoxide( ) {
221
- "[..]SSL connect error [..]"
236
+ r" network failure seems to have happened
237
+ if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
238
+ https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
239
+
240
+ Caused by:
241
+ An IO error occurred when talking to the server
242
+
243
+ Caused by:
244
+ [35] SSL connect error (schannel: failed to receive handshake, SSL/TLS connection failed)"
222
245
} else if cfg!( windows) {
223
246
"[..]failed to send request: [..]"
224
247
} else if cfg!( target_os = "macos" ) {
@@ -227,7 +250,7 @@ Caused by:
227
250
// message here.
228
251
"[..]"
229
252
} else {
230
- "[..]SSL error: [..]"
253
+ "[..]SSL [ERROR] [..]"
231
254
}
232
255
) )
233
256
. run ( ) ;
@@ -264,7 +287,7 @@ fn ssh_something_happens() {
264
287
. file ( "src/main.rs" , "" )
265
288
. build ( ) ;
266
289
267
- let ( expected_ssh_message , expected_update ) = if cargo_uses_gitoxide ( ) {
290
+ let expected = if cargo_uses_gitoxide ( ) {
268
291
// Due to the usage of `ssh` and `ssh.exe` respectively, the messages change.
269
292
// This will be adjusted to use `ssh2` to get rid of this dependency and have uniform messaging.
270
293
let message = if cfg ! ( windows) {
@@ -277,31 +300,73 @@ fn ssh_something_happens() {
277
300
// "[..]banner exchange: Connection to 127.0.0.1 [..]"
278
301
// banner exchange: Connection to 127.0.0.1 port 62250: Software caused connection abort
279
302
// But since there is no common meaningful sequence or word, we can only match a small telling sequence of characters.
280
- "[..] onnect[..]"
303
+ "onnect" . to_string ( )
281
304
} else {
282
- "[..]Connection [..] by [..]"
305
+ format ! (
306
+ r"
307
+ Caused by:
308
+ failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
309
+
310
+ Caused by:
311
+ network failure seems to have happened
312
+ if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
313
+ https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
314
+
315
+ Caused by:
316
+ An IO error occurred when talking to the server
317
+
318
+ Caused by:
319
+ Connection closed by {} port {}
320
+ " ,
321
+ addr. ip( ) ,
322
+ addr. port( )
323
+ )
283
324
} ;
284
- (
285
- message,
286
- format ! ( "[..]Unable to update ssh://{addr}/foo/bar" ) ,
325
+ format ! (
326
+ "\
327
+ [UPDATING] git repository `ssh://{addr}/foo/bar`
328
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
329
+
330
+ Caused by:
331
+ failed to load source for dependency `bar`
332
+
333
+ Caused by:
334
+ Unable to update ssh://{addr}/foo/bar
335
+ {message}"
287
336
)
288
337
} else {
289
- (
338
+ format ! (
290
339
"\
340
+ [UPDATING] git repository `ssh://{addr}/foo/bar`
341
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
342
+
291
343
Caused by:
292
- [..]failed to start SSH session: Failed getting banner[..]
293
- " ,
294
- format ! ( "[UPDATING] git repository `ssh://{addr}/foo/bar`" ) ,
344
+ failed to load source for dependency `bar`
345
+
346
+ Caused by:
347
+ Unable to update ssh://{addr}/foo/bar
348
+
349
+ Caused by:
350
+ failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
351
+
352
+ Caused by:
353
+ network failure seems to have happened
354
+ if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
355
+ https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
356
+
357
+ Caused by:
358
+ failed to start SSH session: Failed getting banner; class=Ssh (23)
359
+ "
295
360
)
296
361
} ;
297
362
p. cargo ( "check -v" )
298
363
. with_status ( 101 )
299
- . with_stderr_contains ( & expected_update)
300
- . with_stderr_contains ( expected_ssh_message)
364
+ . with_stderr_data ( expected)
301
365
. run ( ) ;
302
366
t. join ( ) . ok ( ) . unwrap ( ) ;
303
367
}
304
368
369
+ #[ allow( deprecated) ]
305
370
#[ cargo_test]
306
371
fn net_err_suggests_fetch_with_cli ( ) {
307
372
let p = project ( )
@@ -323,13 +388,13 @@ fn net_err_suggests_fetch_with_cli() {
323
388
324
389
p. cargo ( "check -v" )
325
390
. with_status ( 101 )
326
- . with_stderr ( format ! (
391
+ . with_stderr_data ( format ! (
327
392
"\
328
393
[UPDATING] git repository `ssh://needs-proxy.invalid/git`
329
- warning: spurious network error[..]
330
- warning: spurious network error[..]
331
- warning: spurious network error[..]
332
- [ERROR] failed to get `foo` as a dependency of package `foo v0.0.0 [..] `
394
+ [WARNING] spurious network error (3 tries remaining): failed to resolve address for needs-proxy.invalid: Name or service not known; class=Net (12)
395
+ [WARNING] spurious network error (2 tries remaining): failed to resolve address for needs-proxy.invalid: Name or service not known; class=Net (12)
396
+ [WARNING] spurious network error (1 tries remaining): failed to resolve address for needs-proxy.invalid: Name or service not known; class=Net (12)
397
+ [ERROR] failed to get `foo` as a dependency of package `foo v0.0.0 ([ROOT]/foo) `
333
398
334
399
Caused by:
335
400
failed to load source for dependency `foo`
@@ -338,20 +403,23 @@ Caused by:
338
403
Unable to update ssh://needs-proxy.invalid/git
339
404
340
405
Caused by:
341
- failed to clone into: [.. ]
406
+ failed to clone into: [ROOT]/home/.cargo/git/db/git-[HASH ]
342
407
343
408
Caused by:
344
409
network failure seems to have happened
345
410
if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
346
- https://[..]
411
+ https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
347
412
348
413
Caused by:
349
- {trailer}
414
+ {trailer}
350
415
" ,
351
416
trailer = if cargo_uses_gitoxide( ) {
352
- "An IO error occurred when talking to the server\n \n Caused by:\n ssh: Could not resolve hostname needs-proxy.invalid[..]"
417
+ r" An IO error occurred when talking to the server
418
+
419
+ Caused by:
420
+ ssh: Could not resolve hostname needs-proxy.invalid"
353
421
} else {
354
- "failed to resolve address for needs-proxy.invalid[..] "
422
+ " failed to resolve address for needs-proxy.invalid: Name or service not known; class=Net (12) "
355
423
}
356
424
) )
357
425
. run ( ) ;
@@ -366,7 +434,29 @@ Caused by:
366
434
367
435
p. cargo ( "check -v" )
368
436
. with_status ( 101 )
369
- . with_stderr_contains ( "[..]Unable to update[..]" )
437
+ . with_stderr_data ( str![ [ r#"
438
+ [UPDATING] git repository `ssh://needs-proxy.invalid/git`
439
+ [RUNNING] `git fetch --verbose --force --update-head-ok 'ssh://needs-proxy.invalid/git' '+HEAD:refs/remotes/origin/HEAD'`
440
+ ssh: Could not resolve hostname needs-proxy.invalid: Name or service not known
441
+ fatal: Could not read from remote repository.
442
+
443
+ Please make sure you have the correct access rights
444
+ and the repository exists.
445
+ [ERROR] failed to get `foo` as a dependency of package `foo v0.0.0 ([ROOT]/foo)`
446
+
447
+ Caused by:
448
+ failed to load source for dependency `foo`
449
+
450
+ Caused by:
451
+ Unable to update ssh://needs-proxy.invalid/git
452
+
453
+ Caused by:
454
+ failed to fetch into: [ROOT]/home/.cargo/git/db/git-[HASH]
455
+
456
+ Caused by:
457
+ process didn't exit successfully: `git fetch --verbose --force --update-head-ok 'ssh://needs-proxy.invalid/git' '+HEAD:refs/remotes/origin/HEAD'` ([EXIT_STATUS]: 128)
458
+
459
+ "# ] ] )
370
460
. with_stderr_does_not_contain ( "[..]try enabling `git-fetch-with-cli`[..]" )
371
461
. run ( ) ;
372
462
}
@@ -401,10 +491,10 @@ fn instead_of_url_printed() {
401
491
402
492
p. cargo ( "check" )
403
493
. with_status ( 101 )
404
- . with_stderr ( & format ! (
494
+ . with_stderr_data ( & format ! (
405
495
"\
406
496
[UPDATING] git repository `https://foo.bar/foo/bar`
407
- [ERROR] failed to get `bar` as a dependency of package `foo [..] `
497
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo) `
408
498
409
499
Caused by:
410
500
failed to load source for dependency `bar`
@@ -413,20 +503,19 @@ Caused by:
413
503
Unable to update https://foo.bar/foo/bar
414
504
415
505
Caused by:
416
- failed to clone into: [.. ]
506
+ failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH ]
417
507
418
508
Caused by:
419
509
failed to authenticate when downloading repository: http://{addr}/foo/bar
420
510
421
511
* attempted to find username/password via `credential.helper`, but maybe the found credentials were incorrect
422
512
423
513
if the git CLI succeeds then `net.git-fetch-with-cli` may help here
424
- https://[..]
514
+ https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
425
515
426
516
Caused by:
427
- [..]
428
- {trailer}" ,
429
- trailer = if cargo_uses_gitoxide( ) { "\n Caused by:\n [..]" } else { "" }
517
+ ...
518
+ "
430
519
) )
431
520
. run ( ) ;
432
521
0 commit comments