Skip to content

Commit f74e430

Browse files
committed
test: Migrate git_auth to snapbox - linux
1 parent 814f918 commit f74e430

File tree

1 file changed

+136
-47
lines changed

1 file changed

+136
-47
lines changed

tests/testsuite/git_auth.rs

Lines changed: 136 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//! Tests for git authentication.
22
3-
#![allow(deprecated)]
4-
53
use std::collections::HashSet;
64
use std::io::prelude::*;
75
use std::io::BufReader;
@@ -12,7 +10,7 @@ use std::thread::{self, JoinHandle};
1210

1311
use cargo_test_support::git::cargo_uses_gitoxide;
1412
use cargo_test_support::paths;
15-
use cargo_test_support::{basic_manifest, project};
13+
use cargo_test_support::{basic_manifest, project, str};
1614

1715
fn setup_failed_auth_test() -> (SocketAddr, JoinHandle<()>, Arc<AtomicUsize>) {
1816
let server = TcpListener::bind("127.0.0.1:0").unwrap();
@@ -138,10 +136,10 @@ fn http_auth_offered() {
138136
// may span multiple lines, and isn't relevant to this test.
139137
p.cargo("check")
140138
.with_status(101)
141-
.with_stderr_contains(&format!(
139+
.with_stderr_data(&format!(
142140
"\
143141
[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)`
145143
146144
Caused by:
147145
failed to load source for dependency `bar`
@@ -150,21 +148,29 @@ Caused by:
150148
Unable to update http://{addr}/foo/bar
151149
152150
Caused by:
153-
failed to clone into: [..]
151+
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
154152
155153
Caused by:
156154
failed to authenticate when downloading repository
157155
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
159157
160158
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
162160
163161
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+
}
165172
))
166173
.run();
167-
168174
assert_eq!(connections.load(SeqCst), 2);
169175
t.join().ok().unwrap();
170176
}
@@ -209,16 +215,33 @@ fn https_something_happens() {
209215

210216
p.cargo("check -v")
211217
.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!(
216219
"\
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+
217232
Caused by:
218-
{errmsg}
233+
{errmsg}
219234
",
220235
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)"
222245
} else if cfg!(windows) {
223246
"[..]failed to send request: [..]"
224247
} else if cfg!(target_os = "macos") {
@@ -227,7 +250,7 @@ Caused by:
227250
// message here.
228251
"[..]"
229252
} else {
230-
"[..]SSL error: [..]"
253+
"[..]SSL [ERROR][..]"
231254
}
232255
))
233256
.run();
@@ -264,7 +287,7 @@ fn ssh_something_happens() {
264287
.file("src/main.rs", "")
265288
.build();
266289

267-
let (expected_ssh_message, expected_update) = if cargo_uses_gitoxide() {
290+
let expected = if cargo_uses_gitoxide() {
268291
// Due to the usage of `ssh` and `ssh.exe` respectively, the messages change.
269292
// This will be adjusted to use `ssh2` to get rid of this dependency and have uniform messaging.
270293
let message = if cfg!(windows) {
@@ -277,31 +300,73 @@ fn ssh_something_happens() {
277300
// "[..]banner exchange: Connection to 127.0.0.1 [..]"
278301
// banner exchange: Connection to 127.0.0.1 port 62250: Software caused connection abort
279302
// 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()
281304
} 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+
)
283324
};
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}"
287336
)
288337
} else {
289-
(
338+
format!(
290339
"\
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+
291343
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+
"
295360
)
296361
};
297362
p.cargo("check -v")
298363
.with_status(101)
299-
.with_stderr_contains(&expected_update)
300-
.with_stderr_contains(expected_ssh_message)
364+
.with_stderr_data(expected)
301365
.run();
302366
t.join().ok().unwrap();
303367
}
304368

369+
#[allow(deprecated)]
305370
#[cargo_test]
306371
fn net_err_suggests_fetch_with_cli() {
307372
let p = project()
@@ -323,13 +388,13 @@ fn net_err_suggests_fetch_with_cli() {
323388

324389
p.cargo("check -v")
325390
.with_status(101)
326-
.with_stderr(format!(
391+
.with_stderr_data(format!(
327392
"\
328393
[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)`
333398
334399
Caused by:
335400
failed to load source for dependency `foo`
@@ -338,20 +403,23 @@ Caused by:
338403
Unable to update ssh://needs-proxy.invalid/git
339404
340405
Caused by:
341-
failed to clone into: [..]
406+
failed to clone into: [ROOT]/home/.cargo/git/db/git-[HASH]
342407
343408
Caused by:
344409
network failure seems to have happened
345410
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
347412
348413
Caused by:
349-
{trailer}
414+
{trailer}
350415
",
351416
trailer = if cargo_uses_gitoxide() {
352-
"An IO error occurred when talking to the server\n\nCaused 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"
353421
} 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)"
355423
}
356424
))
357425
.run();
@@ -366,7 +434,29 @@ Caused by:
366434

367435
p.cargo("check -v")
368436
.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+
"#]])
370460
.with_stderr_does_not_contain("[..]try enabling `git-fetch-with-cli`[..]")
371461
.run();
372462
}
@@ -401,10 +491,10 @@ fn instead_of_url_printed() {
401491

402492
p.cargo("check")
403493
.with_status(101)
404-
.with_stderr(&format!(
494+
.with_stderr_data(&format!(
405495
"\
406496
[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)`
408498
409499
Caused by:
410500
failed to load source for dependency `bar`
@@ -413,20 +503,19 @@ Caused by:
413503
Unable to update https://foo.bar/foo/bar
414504
415505
Caused by:
416-
failed to clone into: [..]
506+
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
417507
418508
Caused by:
419509
failed to authenticate when downloading repository: http://{addr}/foo/bar
420510
421511
* attempted to find username/password via `credential.helper`, but maybe the found credentials were incorrect
422512
423513
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
425515
426516
Caused by:
427-
[..]
428-
{trailer}",
429-
trailer = if cargo_uses_gitoxide() { "\nCaused by:\n [..]" } else { "" }
517+
...
518+
"
430519
))
431520
.run();
432521

0 commit comments

Comments
 (0)