Skip to content

Commit ab82f97

Browse files
committed
test: migrate ssh to snapbox
1 parent d1b5f07 commit ab82f97

File tree

1 file changed

+101
-89
lines changed

1 file changed

+101
-89
lines changed

tests/testsuite/ssh.rs

Lines changed: 101 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
//!
66
//! NOTE: The container tests almost certainly won't work on Windows.
77
8-
#![allow(deprecated)]
9-
108
use cargo_test_support::containers::{Container, ContainerHandle, MkFile};
119
use cargo_test_support::git::cargo_uses_gitoxide;
12-
use cargo_test_support::{paths, process, project, Project};
10+
use cargo_test_support::{paths, process, project, str, Project};
1311
use std::fs;
1412
use std::io::Write;
1513
use std::path::PathBuf;
@@ -131,10 +129,9 @@ fn no_known_host() {
131129
let p = foo_bar_project(&url);
132130
p.cargo("fetch")
133131
.with_status(101)
134-
.with_stderr(
135-
"\
132+
.with_stderr_data(str![[r#"
136133
[UPDATING] git repository `ssh://testuser@127.0.0.1:[..]/repos/bar.git`
137-
error: failed to get `bar` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
134+
[ERROR] failed to get `bar` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
138135
139136
Caused by:
140137
failed to load source for dependency `bar`
@@ -143,15 +140,13 @@ Caused by:
143140
Unable to update ssh://testuser@127.0.0.1:[..]/repos/bar.git
144141
145142
Caused by:
146-
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[..]
143+
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
147144
148145
Caused by:
149-
error: unknown SSH host key
146+
[ERROR] unknown SSH host key
150147
The SSH host key for `[127.0.0.1]:[..]` is not known and cannot be validated.
151148
152-
To resolve this issue, add the host key to the `net.ssh.known-hosts` array in \
153-
your Cargo configuration (such as [ROOT]/home/.cargo/config.toml) or in your \
154-
OpenSSH known_hosts file at [ROOT]/home/.ssh/known_hosts
149+
To resolve this issue, add the host key to the `net.ssh.known-hosts` array in your Cargo configuration (such as [ROOT]/home/.cargo/config.toml) or in your OpenSSH known_hosts file at [ROOT]/home/.ssh/known_hosts
155150
156151
The key to add is:
157152
@@ -160,10 +155,9 @@ Caused by:
160155
The ECDSA key fingerprint is: SHA256:[..]
161156
This fingerprint should be validated with the server administrator that it is correct.
162157
163-
See https://doc.rust-lang.org/stable/cargo/appendix/git-authentication.html#ssh-known-hosts \
164-
for more information.
165-
",
166-
)
158+
See https://doc.rust-lang.org/stable/cargo/appendix/git-authentication.html#ssh-known-hosts for more information.
159+
160+
"#]])
167161
.run();
168162
}
169163

@@ -205,12 +199,11 @@ fn known_host_works() {
205199
fs::write(agent.ssh_dir.join("known_hosts"), key).unwrap();
206200
p.cargo("fetch")
207201
.env("SSH_AUTH_SOCK", &agent.sock)
208-
.with_stderr(
209-
"\
202+
.with_stderr_data(str![[r#"
210203
[UPDATING] git repository `ssh://testuser@127.0.0.1:[..]/repos/bar.git`
211204
[LOCKING] 2 packages to latest compatible versions
212-
",
213-
)
205+
206+
"#]])
214207
.run();
215208
}
216209

@@ -228,10 +221,9 @@ fn same_key_different_hostname() {
228221
let p = foo_bar_project(&url);
229222
p.cargo("fetch")
230223
.with_status(101)
231-
.with_stderr(
232-
"\
224+
.with_stderr_data(str![[r#"
233225
[UPDATING] git repository `ssh://testuser@127.0.0.1:[..]/repos/bar.git`
234-
error: failed to get `bar` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
226+
[ERROR] failed to get `bar` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
235227
236228
Caused by:
237229
failed to load source for dependency `bar`
@@ -240,15 +232,13 @@ Caused by:
240232
Unable to update ssh://testuser@127.0.0.1:[..]/repos/bar.git
241233
242234
Caused by:
243-
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[..]
235+
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
244236
245237
Caused by:
246-
error: unknown SSH host key
238+
[ERROR] unknown SSH host key
247239
The SSH host key for `[127.0.0.1]:[..]` is not known and cannot be validated.
248240
249-
To resolve this issue, add the host key to the `net.ssh.known-hosts` array in \
250-
your Cargo configuration (such as [ROOT]/home/.cargo/config.toml) or in your \
251-
OpenSSH known_hosts file at [ROOT]/home/.ssh/known_hosts
241+
To resolve this issue, add the host key to the `net.ssh.known-hosts` array in your Cargo configuration (such as [ROOT]/home/.cargo/config.toml) or in your OpenSSH known_hosts file at [ROOT]/home/.ssh/known_hosts
252242
253243
The key to add is:
254244
@@ -259,10 +249,9 @@ Caused by:
259249
Note: This host key was found, but is associated with a different host:
260250
[ROOT]/home/.ssh/known_hosts line 1: example.com
261251
262-
See https://doc.rust-lang.org/stable/cargo/appendix/git-authentication.html#ssh-known-hosts \
263-
for more information.
264-
",
265-
)
252+
See https://doc.rust-lang.org/stable/cargo/appendix/git-authentication.html#ssh-known-hosts for more information.
253+
254+
"#]])
266255
.run();
267256
}
268257

@@ -282,12 +271,11 @@ fn known_host_without_port() {
282271
let p = foo_bar_project(&url);
283272
p.cargo("fetch")
284273
.env("SSH_AUTH_SOCK", &agent.sock)
285-
.with_stderr(
286-
"\
274+
.with_stderr_data(str![[r#"
287275
[UPDATING] git repository `ssh://testuser@127.0.0.1:[..]/repos/bar.git`
288276
[LOCKING] 2 packages to latest compatible versions
289-
",
290-
)
277+
278+
"#]])
291279
.run();
292280
}
293281

@@ -319,7 +307,7 @@ fn hostname_case_insensitive() {
319307
let p = foo_bar_project(&url);
320308
p.cargo("fetch")
321309
.env("SSH_AUTH_SOCK", &agent.sock)
322-
.with_stderr(&format!(
310+
.with_stderr_data(&format!(
323311
"\
324312
[UPDATING] git repository `ssh://testuser@{hostname}:{port}/repos/bar.git`
325313
[LOCKING] 2 packages to latest compatible versions
@@ -346,9 +334,9 @@ fn invalid_key_error() {
346334
p.cargo("fetch")
347335
.env("SSH_AUTH_SOCK", &agent.sock)
348336
.with_status(101)
349-
.with_stderr(&format!("\
337+
.with_stderr_data(&format!("\
350338
[UPDATING] git repository `ssh://testuser@127.0.0.1:{port}/repos/bar.git`
351-
error: failed to get `bar` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
339+
[ERROR] failed to get `bar` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
352340
353341
Caused by:
354342
failed to load source for dependency `bar`
@@ -357,10 +345,10 @@ Caused by:
357345
Unable to update ssh://testuser@127.0.0.1:{port}/repos/bar.git
358346
359347
Caused by:
360-
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[..]
348+
failed to clone into: [ROOT]/home/.cargo/git/db/bar-[HASH]
361349
362350
Caused by:
363-
error: SSH host key has changed for `[127.0.0.1]:{port}`
351+
[ERROR] SSH host key has changed for `[127.0.0.1]:{port}`
364352
*********************************
365353
* WARNING: HOST KEY HAS CHANGED *
366354
*********************************
@@ -369,15 +357,9 @@ Caused by:
369357
The ECDSA fingerprint for the key from the remote host is:
370358
SHA256:[..]
371359
372-
You are strongly encouraged to contact the server administrator for `[127.0.0.1]:{port}` \
373-
to verify that this new key is correct.
360+
You are strongly encouraged to contact the server administrator for `[127.0.0.1]:{port}` to verify that this new key is correct.
374361
375-
If you can verify that the server has a new key, you can resolve this error by \
376-
removing the old ecdsa-sha2-nistp256 key for `[127.0.0.1]:{port}` located at \
377-
[ROOT]/home/.ssh/known_hosts line 1, and adding the new key to the \
378-
`net.ssh.known-hosts` array in your Cargo configuration (such as \
379-
[ROOT]/home/.cargo/config.toml) or in your OpenSSH known_hosts file at \
380-
[ROOT]/home/.ssh/known_hosts
362+
If you can verify that the server has a new key, you can resolve this error by removing the old ecdsa-sha2-nistp256 key for `[127.0.0.1]:{port}` located at [ROOT]/home/.ssh/known_hosts line 1, and adding the new key to the `net.ssh.known-hosts` array in your Cargo configuration (such as [ROOT]/home/.cargo/config.toml) or in your OpenSSH known_hosts file at [ROOT]/home/.ssh/known_hosts
381363
382364
The key provided by the remote host is:
383365
@@ -397,12 +379,11 @@ Caused by:
397379
drop(f);
398380
p.cargo("fetch")
399381
.env("SSH_AUTH_SOCK", &agent.sock)
400-
.with_stderr(
401-
"\
382+
.with_stderr_data(str![[r#"
402383
[UPDATING] git repository `ssh://testuser@127.0.0.1:[..]/repos/bar.git`
403384
[LOCKING] 2 packages to latest compatible versions
404-
",
405-
)
385+
386+
"#]])
406387
.run();
407388
}
408389

@@ -437,10 +418,18 @@ fn invalid_github_key() {
437418
.build();
438419
p.cargo("fetch")
439420
.with_status(101)
440-
.with_stderr_contains(if cargo_uses_gitoxide() {
441-
" git@github.com: Permission denied (publickey)."
421+
.with_stderr_data(if cargo_uses_gitoxide() {
422+
str![[r#"
423+
...
424+
git@github.com: Permission denied (publickey).
425+
...
426+
"#]]
442427
} else {
443-
" error: SSH host key has changed for `github.com`"
428+
str![[r#"
429+
...
430+
[ERROR] SSH host key has changed for `github.com`
431+
...
432+
"#]]
444433
})
445434
.run();
446435
}
@@ -474,9 +463,10 @@ fn bundled_github_works() {
474463
)
475464
.file("src/lib.rs", "")
476465
.build();
477-
let shared_stderr = "\
466+
let expected = if cargo_uses_gitoxide() {
467+
str![[r#"
478468
[UPDATING] git repository `ssh://git@github.com/rust-lang/bitflags.git`
479-
error: failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
469+
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
480470
481471
Caused by:
482472
failed to load source for dependency `bitflags`
@@ -485,45 +475,58 @@ Caused by:
485475
Unable to update ssh://git@github.com/rust-lang/bitflags.git?tag=1.3.2
486476
487477
Caused by:
488-
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[..]
478+
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
489479
490480
Caused by:
491481
failed to authenticate when downloading repository
492482
493-
*";
494-
let expected = if cargo_uses_gitoxide() {
495-
format!(
496-
"{shared_stderr} attempted to find username/password via `credential.helper`, but maybe the found credentials were incorrect
483+
* attempted to find username/password via `credential.helper`, but maybe the found credentials were incorrect
497484
498485
if the git CLI succeeds then `net.git-fetch-with-cli` may help here
499486
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
500487
501488
Caused by:
502-
Credentials provided for \"ssh://git@github.com/rust-lang/bitflags.git\" were not accepted by the remote
489+
[CREDENTIAL]s provided for "ssh://git@github.com/rust-lang/bitflags.git" were not accepted by the remote
503490
504491
Caused by:
505492
git@github.com: Permission denied (publickey).
506-
"
507-
)
493+
494+
"#]]
508495
} else {
509-
format!(
510-
"{shared_stderr} attempted ssh-agent authentication, but no usernames succeeded: `git`
496+
str![[r#"
497+
[UPDATING] git repository `ssh://git@github.com/rust-lang/bitflags.git`
498+
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
499+
500+
Caused by:
501+
failed to load source for dependency `bitflags`
502+
503+
Caused by:
504+
Unable to update ssh://git@github.com/rust-lang/bitflags.git?tag=1.3.2
505+
506+
Caused by:
507+
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
508+
509+
Caused by:
510+
failed to authenticate when downloading repository
511+
512+
* attempted ssh-agent authentication, but no usernames succeeded: `git`
511513
512514
if the git CLI succeeds then `net.git-fetch-with-cli` may help here
513515
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
514516
515517
Caused by:
516518
no authentication methods succeeded
517-
"
518-
)
519+
520+
"#]]
519521
};
520522
p.cargo("fetch")
521523
.env("SSH_AUTH_SOCK", &bogus_auth_sock)
522524
.with_status(101)
523-
.with_stderr(&expected)
525+
.with_stderr_data(expected)
524526
.run();
525527

526-
let shared_stderr = "\
528+
let expected = if cargo_uses_gitoxide() {
529+
str![[r#"
527530
[UPDATING] git repository `ssh://git@github.com:22/rust-lang/bitflags.git`
528531
error: failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
529532
@@ -534,38 +537,48 @@ Caused by:
534537
Unable to update ssh://git@github.com:22/rust-lang/bitflags.git?tag=1.3.2
535538
536539
Caused by:
537-
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[..]
540+
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
538541
539542
Caused by:
540543
failed to authenticate when downloading repository
541544
542-
*";
543-
544-
let expected = if cargo_uses_gitoxide() {
545-
format!(
546-
"{shared_stderr} attempted to find username/password via `credential.helper`, but maybe the found credentials were incorrect
545+
* attempted to find username/password via `credential.helper`, but maybe the found credentials were incorrect
547546
548547
if the git CLI succeeds then `net.git-fetch-with-cli` may help here
549548
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
550549
551550
Caused by:
552-
Credentials provided for \"ssh://git@github.com:22/rust-lang/bitflags.git\" were not accepted by the remote
551+
[CREDENTIAL]s provided for \"ssh://git@github.com:22/rust-lang/bitflags.git\" were not accepted by the remote
553552
554553
Caused by:
555554
git@github.com: Permission denied (publickey).
556-
"
557-
)
555+
"#]]
558556
} else {
559-
format!(
560-
"{shared_stderr} attempted ssh-agent authentication, but no usernames succeeded: `git`
557+
str![[r#"
558+
[UPDATING] git repository `ssh://git@github.com:22/rust-lang/bitflags.git`
559+
[ERROR] failed to get `bitflags` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
560+
561+
Caused by:
562+
failed to load source for dependency `bitflags`
563+
564+
Caused by:
565+
Unable to update ssh://git@github.com:22/rust-lang/bitflags.git?tag=1.3.2
566+
567+
Caused by:
568+
failed to clone into: [ROOT]/home/.cargo/git/db/bitflags-[HASH]
569+
570+
Caused by:
571+
failed to authenticate when downloading repository
572+
573+
* attempted ssh-agent authentication, but no usernames succeeded: `git`
561574
562575
if the git CLI succeeds then `net.git-fetch-with-cli` may help here
563576
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
564577
565578
Caused by:
566579
no authentication methods succeeded
567-
"
568-
)
580+
581+
"#]]
569582
};
570583

571584
// Explicit :22 should also work with bundled.
@@ -584,7 +597,7 @@ Caused by:
584597
p.cargo("fetch")
585598
.env("SSH_AUTH_SOCK", &bogus_auth_sock)
586599
.with_status(101)
587-
.with_stderr(&expected)
600+
.with_stderr_data(expected)
588601
.run();
589602
}
590603

@@ -610,11 +623,10 @@ fn ssh_key_in_config() {
610623
);
611624
p.cargo("fetch")
612625
.env("SSH_AUTH_SOCK", &agent.sock)
613-
.with_stderr(
614-
"\
626+
.with_stderr_data(str![[r#"
615627
[UPDATING] git repository `ssh://testuser@127.0.0.1:[..]/repos/bar.git`
616628
[LOCKING] 2 packages to latest compatible versions
617-
",
618-
)
629+
630+
"#]])
619631
.run();
620632
}

0 commit comments

Comments
 (0)