Skip to content

Commit 56471ef

Browse files
committed
test: migrate login to snapbox
1 parent 6d0825d commit 56471ef

File tree

1 file changed

+49
-31
lines changed

1 file changed

+49
-31
lines changed

tests/testsuite/login.rs

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Tests for the `cargo login` command.
22
3-
#![allow(deprecated)]
4-
53
use cargo_test_support::cargo_process;
64
use cargo_test_support::paths::{self, CargoPathExt};
75
use cargo_test_support::registry::{self, RegistryBuilder};
6+
use cargo_test_support::str;
87
use cargo_test_support::t;
98
use std::fs;
109
use std::path::PathBuf;
@@ -112,30 +111,28 @@ fn empty_login_token() {
112111
cargo_process("login")
113112
.replace_crates_io(registry.index_url())
114113
.with_stdin("\t\n")
115-
.with_stderr(
116-
"\
114+
.with_stderr_data(str![[r#"
117115
[UPDATING] crates.io index
118-
please paste the token found on [..] below
116+
please paste the token found on [ROOTURL]/api/me below
119117
[ERROR] credential provider `cargo:token` failed action `login`
120118
121119
Caused by:
122120
please provide a non-empty token
123-
",
124-
)
121+
122+
"#]])
125123
.with_status(101)
126124
.run();
127125

128126
cargo_process("login")
129127
.replace_crates_io(registry.index_url())
130128
.arg("")
131-
.with_stderr(
132-
"\
129+
.with_stderr_data(str![[r#"
133130
[ERROR] credential provider `cargo:token` failed action `login`
134131
135132
Caused by:
136133
please provide a non-empty token
137-
",
138-
)
134+
135+
"#]])
139136
.with_status(101)
140137
.run();
141138
}
@@ -152,7 +149,7 @@ fn invalid_login_token() {
152149
cargo_process("login")
153150
.replace_crates_io(registry.index_url())
154151
.with_stdin(stdin)
155-
.with_stderr(stderr)
152+
.with_stderr_data(stderr)
156153
.with_status(status)
157154
.run();
158155
};
@@ -164,11 +161,20 @@ fn invalid_login_token() {
164161
165162
Caused by:
166163
token contains invalid characters.
167-
Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header.",
164+
Only printable ISO-8859-1 characters are allowed as it is sent in a HTTPS header.
165+
",
168166
101,
169167
)
170168
};
171-
let valid = |stdin: &str| check(stdin, "[LOGIN] token for `crates-io` saved", 0);
169+
let valid = |stdin: &str| {
170+
check(
171+
stdin,
172+
"\
173+
[LOGIN] token for `crates-io` saved
174+
",
175+
0,
176+
)
177+
};
172178

173179
// Update config.json so that the rest of the tests don't need to care
174180
// whether or not `Updating` is printed.
@@ -203,9 +209,16 @@ fn bad_asymmetric_token_args() {
203209
cargo_process("login -Zasymmetric-token -- --key-subject")
204210
.masquerade_as_nightly_cargo(&["asymmetric-token"])
205211
.replace_crates_io(registry.index_url())
206-
.with_stderr_contains(
207-
" error: a value is required for '--key-subject <SUBJECT>' but none was supplied",
208-
)
212+
.with_stderr_data(str![[r#"
213+
[UPDATING] crates.io index
214+
[ERROR] credential provider `cargo:paseto --key-subject` failed action `login`
215+
216+
Caused by:
217+
[ERROR] a value is required for '--key-subject <SUBJECT>' but none was supplied
218+
219+
For more information, try '--help'.
220+
221+
"#]])
209222
.with_status(101)
210223
.run();
211224
}
@@ -234,10 +247,12 @@ fn login_with_asymmetric_token_and_subject_on_stdin() {
234247
cargo_process("login -v -Z asymmetric-token -- --key-subject=foo")
235248
.masquerade_as_nightly_cargo(&["asymmetric-token"])
236249
.replace_crates_io(registry.index_url())
237-
.with_stderr_contains(
238-
"\
239-
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
240-
)
250+
.with_stderr_data(str![[r#"
251+
[UPDATING] crates.io index
252+
[CREDENTIAL] cargo:paseto --key-subject=foo login crates-io
253+
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ
254+
255+
"#]])
241256
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
242257
.run();
243258
let credentials = fs::read_to_string(&credentials).unwrap();
@@ -291,12 +306,12 @@ fn login_with_asymmetric_token_on_stdin() {
291306
let credentials = credentials_toml();
292307
cargo_process("login -v -Z asymmetric-token --registry alternative")
293308
.masquerade_as_nightly_cargo(&["asymmetric-token"])
294-
.with_stderr(
295-
"\
296-
[UPDATING] [..]
309+
.with_stderr_data(str![[r#"
310+
[UPDATING] `alternative` index
297311
[CREDENTIAL] cargo:paseto login alternative
298-
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ",
299-
)
312+
k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ
313+
314+
"#]])
300315
.with_stdin("k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36")
301316
.run();
302317
let credentials = fs::read_to_string(&credentials).unwrap();
@@ -313,7 +328,11 @@ fn login_with_generate_asymmetric_token() {
313328
let credentials = credentials_toml();
314329
cargo_process("login -Z asymmetric-token --registry alternative")
315330
.masquerade_as_nightly_cargo(&["asymmetric-token"])
316-
.with_stderr("[UPDATING] `alternative` index\nk3.public.[..]")
331+
.with_stderr_data(str![[r#"
332+
[UPDATING] `alternative` index
333+
k3.public.[..]
334+
335+
"#]])
317336
.run();
318337
let credentials = fs::read_to_string(&credentials).unwrap();
319338
assert!(credentials.contains("secret-key = \"k3.secret."));
@@ -336,12 +355,11 @@ fn default_registry_configured() {
336355

337356
cargo_process("login")
338357
.arg("a-new-token")
339-
.with_stderr(
340-
"\
358+
.with_stderr_data(str![[r#"
341359
[UPDATING] `alternative` index
342360
[LOGIN] token for `alternative` saved
343-
",
344-
)
361+
362+
"#]])
345363
.run();
346364

347365
check_token(None, None);

0 commit comments

Comments
 (0)