1
1
//! Tests for the `cargo login` command.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: cargo_process;
6
4
use cargo_test_support:: paths:: { self , CargoPathExt } ;
7
5
use cargo_test_support:: registry:: { self , RegistryBuilder } ;
6
+ use cargo_test_support:: str;
8
7
use cargo_test_support:: t;
9
8
use std:: fs;
10
9
use std:: path:: PathBuf ;
@@ -112,30 +111,28 @@ fn empty_login_token() {
112
111
cargo_process ( "login" )
113
112
. replace_crates_io ( registry. index_url ( ) )
114
113
. with_stdin ( "\t \n " )
115
- . with_stderr (
116
- "\
114
+ . with_stderr_data ( str![ [ r#"
117
115
[UPDATING] crates.io index
118
- please paste the token found on [..] below
116
+ please paste the token found on [ROOTURL]/api/me below
119
117
[ERROR] credential provider `cargo:token` failed action `login`
120
118
121
119
Caused by:
122
120
please provide a non-empty token
123
- " ,
124
- )
121
+
122
+ "# ] ] )
125
123
. with_status ( 101 )
126
124
. run ( ) ;
127
125
128
126
cargo_process ( "login" )
129
127
. replace_crates_io ( registry. index_url ( ) )
130
128
. arg ( "" )
131
- . with_stderr (
132
- "\
129
+ . with_stderr_data ( str![ [ r#"
133
130
[ERROR] credential provider `cargo:token` failed action `login`
134
131
135
132
Caused by:
136
133
please provide a non-empty token
137
- " ,
138
- )
134
+
135
+ "# ] ] )
139
136
. with_status ( 101 )
140
137
. run ( ) ;
141
138
}
@@ -152,7 +149,7 @@ fn invalid_login_token() {
152
149
cargo_process ( "login" )
153
150
. replace_crates_io ( registry. index_url ( ) )
154
151
. with_stdin ( stdin)
155
- . with_stderr ( stderr)
152
+ . with_stderr_data ( stderr)
156
153
. with_status ( status)
157
154
. run ( ) ;
158
155
} ;
@@ -164,11 +161,20 @@ fn invalid_login_token() {
164
161
165
162
Caused by:
166
163
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
+ " ,
168
166
101 ,
169
167
)
170
168
} ;
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
+ } ;
172
178
173
179
// Update config.json so that the rest of the tests don't need to care
174
180
// whether or not `Updating` is printed.
@@ -203,9 +209,16 @@ fn bad_asymmetric_token_args() {
203
209
cargo_process ( "login -Zasymmetric-token -- --key-subject" )
204
210
. masquerade_as_nightly_cargo ( & [ "asymmetric-token" ] )
205
211
. 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
+ "# ] ] )
209
222
. with_status ( 101 )
210
223
. run ( ) ;
211
224
}
@@ -234,10 +247,12 @@ fn login_with_asymmetric_token_and_subject_on_stdin() {
234
247
cargo_process ( "login -v -Z asymmetric-token -- --key-subject=foo" )
235
248
. masquerade_as_nightly_cargo ( & [ "asymmetric-token" ] )
236
249
. 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
+ "# ] ] )
241
256
. with_stdin ( "k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36" )
242
257
. run ( ) ;
243
258
let credentials = fs:: read_to_string ( & credentials) . unwrap ( ) ;
@@ -291,12 +306,12 @@ fn login_with_asymmetric_token_on_stdin() {
291
306
let credentials = credentials_toml ( ) ;
292
307
cargo_process ( "login -v -Z asymmetric-token --registry alternative" )
293
308
. masquerade_as_nightly_cargo ( & [ "asymmetric-token" ] )
294
- . with_stderr (
295
- "\
296
- [UPDATING] [..]
309
+ . with_stderr_data ( str![ [ r#"
310
+ [UPDATING] `alternative` index
297
311
[CREDENTIAL] cargo:paseto login alternative
298
- k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ" ,
299
- )
312
+ k3.public.AmDwjlyf8jAV3gm5Z7Kz9xAOcsKslt_Vwp5v-emjFzBHLCtcANzTaVEghTNEMj9PkQ
313
+
314
+ "# ] ] )
300
315
. with_stdin ( "k3.secret.fNYVuMvBgOlljt9TDohnaYLblghqaHoQquVZwgR6X12cBFHZLFsaU3q7X3k1Zn36" )
301
316
. run ( ) ;
302
317
let credentials = fs:: read_to_string ( & credentials) . unwrap ( ) ;
@@ -313,7 +328,11 @@ fn login_with_generate_asymmetric_token() {
313
328
let credentials = credentials_toml ( ) ;
314
329
cargo_process ( "login -Z asymmetric-token --registry alternative" )
315
330
. masquerade_as_nightly_cargo ( & [ "asymmetric-token" ] )
316
- . with_stderr ( "[UPDATING] `alternative` index\n k3.public.[..]" )
331
+ . with_stderr_data ( str![ [ r#"
332
+ [UPDATING] `alternative` index
333
+ k3.public.[..]
334
+
335
+ "# ] ] )
317
336
. run ( ) ;
318
337
let credentials = fs:: read_to_string ( & credentials) . unwrap ( ) ;
319
338
assert ! ( credentials. contains( "secret-key = \" k3.secret." ) ) ;
@@ -336,12 +355,11 @@ fn default_registry_configured() {
336
355
337
356
cargo_process ( "login" )
338
357
. arg ( "a-new-token" )
339
- . with_stderr (
340
- "\
358
+ . with_stderr_data ( str![ [ r#"
341
359
[UPDATING] `alternative` index
342
360
[LOGIN] token for `alternative` saved
343
- " ,
344
- )
361
+
362
+ "# ] ] )
345
363
. run ( ) ;
346
364
347
365
check_token ( None , None ) ;
0 commit comments