1
1
//! Tests for registry authentication.
2
2
3
- #![ allow( deprecated) ]
4
-
5
3
use cargo_test_support:: compare:: assert_e2e;
6
4
use cargo_test_support:: registry:: { Package , RegistryBuilder , Token } ;
7
5
use cargo_test_support:: str;
@@ -46,8 +44,8 @@ static SUCCESS_OUTPUT: &'static str = "\
46
44
[DOWNLOADING] crates ...
47
45
[DOWNLOADED] bar v0.0.1 (registry `alternative`)
48
46
[COMPILING] bar v0.0.1 (registry `alternative`)
49
- [COMPILING] foo v0.0.1 ([CWD] )
50
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [.. ]s
47
+ [COMPILING] foo v0.0.1 ([ROOT]/foo )
48
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED ]s
51
49
" ;
52
50
53
51
#[ cargo_test]
@@ -61,18 +59,19 @@ fn requires_credential_provider() {
61
59
let p = make_project ( ) ;
62
60
p. cargo ( "check" )
63
61
. with_status ( 101 )
64
- . with_stderr (
65
- r#" [UPDATING] `alternative` index
62
+ . with_stderr_data ( str! [ [ r#"
63
+ [UPDATING] `alternative` index
66
64
[LOCKING] 2 packages to latest compatible versions
67
- error: failed to download `bar v0.0.1 (registry `alternative`)`
65
+ [ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
68
66
69
67
Caused by:
70
68
unable to get packages from source
71
69
72
70
Caused by:
73
71
authenticated registries require a credential-provider to be configured
74
- see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details"# ,
75
- )
72
+ see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details
73
+
74
+ "# ] ] )
76
75
. run ( ) ;
77
76
}
78
77
@@ -85,7 +84,7 @@ fn simple() {
85
84
. build ( ) ;
86
85
87
86
let p = make_project ( ) ;
88
- cargo ( & p, "build" ) . with_stderr ( SUCCESS_OUTPUT ) . run ( ) ;
87
+ cargo ( & p, "build" ) . with_stderr_data ( SUCCESS_OUTPUT ) . run ( ) ;
89
88
}
90
89
91
90
#[ cargo_test]
@@ -98,7 +97,7 @@ fn simple_with_asymmetric() {
98
97
. build ( ) ;
99
98
100
99
let p = make_project ( ) ;
101
- cargo ( & p, "build" ) . with_stderr ( SUCCESS_OUTPUT ) . run ( ) ;
100
+ cargo ( & p, "build" ) . with_stderr_data ( SUCCESS_OUTPUT ) . run ( ) ;
102
101
}
103
102
104
103
#[ cargo_test]
@@ -117,7 +116,7 @@ fn environment_config() {
117
116
registry. index_url ( ) . as_str ( ) ,
118
117
)
119
118
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , registry. token ( ) )
120
- . with_stderr ( SUCCESS_OUTPUT )
119
+ . with_stderr_data ( SUCCESS_OUTPUT )
121
120
. run ( ) ;
122
121
}
123
122
@@ -133,7 +132,7 @@ fn environment_token() {
133
132
let p = make_project ( ) ;
134
133
cargo ( & p, "build" )
135
134
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , registry. token ( ) )
136
- . with_stderr ( SUCCESS_OUTPUT )
135
+ . with_stderr_data ( SUCCESS_OUTPUT )
137
136
. run ( ) ;
138
137
}
139
138
@@ -154,7 +153,7 @@ fn environment_token_with_asymmetric() {
154
153
let p = make_project ( ) ;
155
154
cargo ( & p, "build" )
156
155
. env ( "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY" , registry. key ( ) )
157
- . with_stderr ( SUCCESS_OUTPUT )
156
+ . with_stderr_data ( SUCCESS_OUTPUT )
158
157
. run ( ) ;
159
158
}
160
159
@@ -179,9 +178,20 @@ fn bad_environment_token_with_asymmetric_subject() {
179
178
"CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
180
179
"incorrect" ,
181
180
)
182
- . with_stderr_contains (
183
- " token rejected for `alternative`, please run `cargo login --registry alternative`" ,
184
- )
181
+ . with_stderr_data ( str![ [ r#"
182
+ [UPDATING] `alternative` index
183
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
184
+
185
+ Caused by:
186
+ token rejected for `alternative`, please run `cargo login --registry alternative`
187
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
188
+
189
+ Caused by:
190
+ failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401
191
+ body:
192
+ Unauthorized message from server.
193
+
194
+ "# ] ] )
185
195
. with_status ( 101 )
186
196
. run ( ) ;
187
197
}
@@ -203,9 +213,20 @@ fn bad_environment_token_with_asymmetric_incorrect_subject() {
203
213
"CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
204
214
"incorrect" ,
205
215
)
206
- . with_stderr_contains (
207
- " token rejected for `alternative`, please run `cargo login --registry alternative`" ,
208
- )
216
+ . with_stderr_data ( str![ [ r#"
217
+ [UPDATING] `alternative` index
218
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
219
+
220
+ Caused by:
221
+ token rejected for `alternative`, please run `cargo login --registry alternative`
222
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
223
+
224
+ Caused by:
225
+ failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401
226
+ body:
227
+ Unauthorized message from server.
228
+
229
+ "# ] ] )
209
230
. with_status ( 101 )
210
231
. run ( ) ;
211
232
}
@@ -230,9 +251,20 @@ fn bad_environment_token_with_incorrect_asymmetric() {
230
251
"CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY" ,
231
252
"k3.secret.9Vxr5hVlI_g_orBZN54vPz20bmB4O76wB_MVqUSuJJJqHFLwP8kdn_RY5g6J6pQG" ,
232
253
)
233
- . with_stderr_contains (
234
- " token rejected for `alternative`, please run `cargo login --registry alternative`" ,
235
- )
254
+ . with_stderr_data ( str![ [ r#"
255
+ [UPDATING] `alternative` index
256
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
257
+
258
+ Caused by:
259
+ token rejected for `alternative`, please run `cargo login --registry alternative`
260
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
261
+
262
+ Caused by:
263
+ failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401
264
+ body:
265
+ Unauthorized message from server.
266
+
267
+ "# ] ] )
236
268
. with_status ( 101 )
237
269
. run ( ) ;
238
270
}
@@ -249,15 +281,15 @@ fn missing_token() {
249
281
let p = make_project ( ) ;
250
282
cargo ( & p, "build" )
251
283
. with_status ( 101 )
252
- . with_stderr (
253
- "\
284
+ . with_stderr_data ( str![ [ r#"
254
285
[UPDATING] `alternative` index
255
- [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..] )`
286
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo )`
256
287
257
288
Caused by:
258
289
no token found for `alternative`, please run `cargo login --registry alternative`
259
- or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN" ,
260
- )
290
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
291
+
292
+ "# ] ] )
261
293
. run ( ) ;
262
294
}
263
295
@@ -272,8 +304,7 @@ fn missing_token_git() {
272
304
let p = make_project ( ) ;
273
305
cargo ( & p, "build" )
274
306
. with_status ( 101 )
275
- . with_stderr (
276
- "\
307
+ . with_stderr_data ( str![ [ r#"
277
308
[UPDATING] `alternative` index
278
309
[LOCKING] 2 packages to latest compatible versions
279
310
[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -283,8 +314,9 @@ Caused by:
283
314
284
315
Caused by:
285
316
no token found for `alternative`, please run `cargo login --registry alternative`
286
- or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN" ,
287
- )
317
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
318
+
319
+ "# ] ] )
288
320
. run ( ) ;
289
321
}
290
322
@@ -301,20 +333,20 @@ fn incorrect_token() {
301
333
cargo ( & p, "build" )
302
334
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
303
335
. with_status ( 101 )
304
- . with_stderr (
305
- "\
336
+ . with_stderr_data ( str![ [ r#"
306
337
[UPDATING] `alternative` index
307
- [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..] )`
338
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo )`
308
339
309
340
Caused by:
310
341
token rejected for `alternative`, please run `cargo login --registry alternative`
311
342
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
312
343
313
344
Caused by:
314
- failed to get successful HTTP response from `http://[..]/index/config.json`, got 401
345
+ failed to get successful HTTP response from `http://127.0.0.1: [..]/index/config.json`, got 401
315
346
body:
316
- Unauthorized message from server." ,
317
- )
347
+ Unauthorized message from server.
348
+
349
+ "# ] ] )
318
350
. run ( ) ;
319
351
}
320
352
@@ -331,18 +363,18 @@ fn incorrect_token_git() {
331
363
cargo ( & p, "build" )
332
364
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
333
365
. with_status ( 101 )
334
- . with_stderr (
335
- "\
366
+ . with_stderr_data ( str![ [ r#"
336
367
[UPDATING] `alternative` index
337
368
[LOCKING] 2 packages to latest compatible versions
338
369
[DOWNLOADING] crates ...
339
- [ERROR] failed to download from `http://[..]/dl/bar/0.0.1/download`
370
+ [ERROR] failed to download from `http://127.0.0.1: [..]/dl/bar/0.0.1/download`
340
371
341
372
Caused by:
342
- failed to get successful HTTP response from `http://[..]/dl/bar/0.0.1/download` (127.0.0.1), got 401
373
+ failed to get successful HTTP response from `http://127.0.0.1: [..]/dl/bar/0.0.1/download` (127.0.0.1), got 401
343
374
body:
344
- Unauthorized message from server." ,
345
- )
375
+ Unauthorized message from server.
376
+
377
+ "# ] ] )
346
378
. run ( ) ;
347
379
}
348
380
@@ -360,18 +392,17 @@ fn anonymous_alt_registry() {
360
392
let p = make_project ( ) ;
361
393
cargo ( & p, & format ! ( "install --index {} bar" , registry. index_url( ) ) )
362
394
. with_status ( 101 )
363
- . with_stderr (
364
- "\
365
- [UPDATING] `[..]` index
366
- [ERROR] no token found for `[..]`
395
+ . with_stderr_data ( str![ [ r#"
396
+ [UPDATING] `sparse+http://127.0.0.1:[..]/index/` index
397
+ [ERROR] no token found for `sparse+http://127.0.0.1:[..]/index/`
367
398
consider setting up an alternate registry in Cargo's configuration
368
399
as described by https://doc.rust-lang.org/cargo/reference/registries.html
369
400
370
401
[registries]
371
- my-registry = { index = \" [..]\ " }
402
+ my-registry = { index = "sparse+http://127.0.0.1: [..]/index/ " }
372
403
373
- " ,
374
- )
404
+
405
+ "# ] ] )
375
406
. run ( ) ;
376
407
}
377
408
@@ -424,8 +455,7 @@ fn duplicate_index() {
424
455
server. index_url ( ) . as_str ( ) ,
425
456
)
426
457
. with_status ( 101 )
427
- . with_stderr (
428
- "\
458
+ . with_stderr_data ( str![ [ r#"
429
459
[UPDATING] `alternative` index
430
460
[LOCKING] 2 packages to latest compatible versions
431
461
[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -434,10 +464,9 @@ Caused by:
434
464
unable to get packages from source
435
465
436
466
Caused by:
437
- multiple registries are configured with the same index url \
438
- 'registry+file://[..]/alternative-registry': alternative1, alternative2
439
- " ,
440
- )
467
+ multiple registries are configured with the same index url 'registry+[ROOTURL]/alternative-registry': alternative1, alternative2
468
+
469
+ "# ] ] )
441
470
. run ( ) ;
442
471
}
443
472
0 commit comments