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;
@@ -40,16 +38,6 @@ fn make_project() -> Project {
40
38
p
41
39
}
42
40
43
- static SUCCESS_OUTPUT : & ' static str = "\
44
- [UPDATING] `alternative` index
45
- [LOCKING] 2 packages to latest compatible versions
46
- [DOWNLOADING] crates ...
47
- [DOWNLOADED] bar v0.0.1 (registry `alternative`)
48
- [COMPILING] bar v0.0.1 (registry `alternative`)
49
- [COMPILING] foo v0.0.1 ([CWD])
50
- [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s
51
- " ;
52
-
53
41
#[ cargo_test]
54
42
fn requires_credential_provider ( ) {
55
43
let _registry = RegistryBuilder :: new ( )
@@ -61,18 +49,19 @@ fn requires_credential_provider() {
61
49
let p = make_project ( ) ;
62
50
p. cargo ( "check" )
63
51
. with_status ( 101 )
64
- . with_stderr (
65
- r#" [UPDATING] `alternative` index
52
+ . with_stderr_data ( str! [ [ r#"
53
+ [UPDATING] `alternative` index
66
54
[LOCKING] 2 packages to latest compatible versions
67
- error: failed to download `bar v0.0.1 (registry `alternative`)`
55
+ [ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
68
56
69
57
Caused by:
70
58
unable to get packages from source
71
59
72
60
Caused by:
73
61
authenticated registries require a credential-provider to be configured
74
- see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details"# ,
75
- )
62
+ see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details
63
+
64
+ "# ] ] )
76
65
. run ( ) ;
77
66
}
78
67
@@ -85,7 +74,18 @@ fn simple() {
85
74
. build ( ) ;
86
75
87
76
let p = make_project ( ) ;
88
- cargo ( & p, "build" ) . with_stderr ( SUCCESS_OUTPUT ) . run ( ) ;
77
+ cargo ( & p, "build" )
78
+ . with_stderr_data ( str![ [ r#"
79
+ [UPDATING] `alternative` index
80
+ [LOCKING] 2 packages to latest compatible versions
81
+ [DOWNLOADING] crates ...
82
+ [DOWNLOADED] bar v0.0.1 (registry `alternative`)
83
+ [COMPILING] bar v0.0.1 (registry `alternative`)
84
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
85
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
86
+
87
+ "# ] ] )
88
+ . run ( ) ;
89
89
}
90
90
91
91
#[ cargo_test]
@@ -98,7 +98,18 @@ fn simple_with_asymmetric() {
98
98
. build ( ) ;
99
99
100
100
let p = make_project ( ) ;
101
- cargo ( & p, "build" ) . with_stderr ( SUCCESS_OUTPUT ) . run ( ) ;
101
+ cargo ( & p, "build" )
102
+ . with_stderr_data ( str![ [ r#"
103
+ [UPDATING] `alternative` index
104
+ [LOCKING] 2 packages to latest compatible versions
105
+ [DOWNLOADING] crates ...
106
+ [DOWNLOADED] bar v0.0.1 (registry `alternative`)
107
+ [COMPILING] bar v0.0.1 (registry `alternative`)
108
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
109
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
110
+
111
+ "# ] ] )
112
+ . run ( ) ;
102
113
}
103
114
104
115
#[ cargo_test]
@@ -117,7 +128,16 @@ fn environment_config() {
117
128
registry. index_url ( ) . as_str ( ) ,
118
129
)
119
130
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , registry. token ( ) )
120
- . with_stderr ( SUCCESS_OUTPUT )
131
+ . with_stderr_data ( str![ [ r#"
132
+ [UPDATING] `alternative` index
133
+ [LOCKING] 2 packages to latest compatible versions
134
+ [DOWNLOADING] crates ...
135
+ [DOWNLOADED] bar v0.0.1 (registry `alternative`)
136
+ [COMPILING] bar v0.0.1 (registry `alternative`)
137
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
138
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
139
+
140
+ "# ] ] )
121
141
. run ( ) ;
122
142
}
123
143
@@ -133,7 +153,16 @@ fn environment_token() {
133
153
let p = make_project ( ) ;
134
154
cargo ( & p, "build" )
135
155
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , registry. token ( ) )
136
- . with_stderr ( SUCCESS_OUTPUT )
156
+ . with_stderr_data ( str![ [ r#"
157
+ [UPDATING] `alternative` index
158
+ [LOCKING] 2 packages to latest compatible versions
159
+ [DOWNLOADING] crates ...
160
+ [DOWNLOADED] bar v0.0.1 (registry `alternative`)
161
+ [COMPILING] bar v0.0.1 (registry `alternative`)
162
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
163
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
164
+
165
+ "# ] ] )
137
166
. run ( ) ;
138
167
}
139
168
@@ -154,7 +183,16 @@ fn environment_token_with_asymmetric() {
154
183
let p = make_project ( ) ;
155
184
cargo ( & p, "build" )
156
185
. env ( "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY" , registry. key ( ) )
157
- . with_stderr ( SUCCESS_OUTPUT )
186
+ . with_stderr_data ( str![ [ r#"
187
+ [UPDATING] `alternative` index
188
+ [LOCKING] 2 packages to latest compatible versions
189
+ [DOWNLOADING] crates ...
190
+ [DOWNLOADED] bar v0.0.1 (registry `alternative`)
191
+ [COMPILING] bar v0.0.1 (registry `alternative`)
192
+ [COMPILING] foo v0.0.1 ([ROOT]/foo)
193
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
194
+
195
+ "# ] ] )
158
196
. run ( ) ;
159
197
}
160
198
@@ -179,9 +217,20 @@ fn bad_environment_token_with_asymmetric_subject() {
179
217
"CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
180
218
"incorrect" ,
181
219
)
182
- . with_stderr_contains (
183
- " token rejected for `alternative`, please run `cargo login --registry alternative`" ,
184
- )
220
+ . with_stderr_data ( str![ [ r#"
221
+ [UPDATING] `alternative` index
222
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
223
+
224
+ Caused by:
225
+ token rejected for `alternative`, please run `cargo login --registry alternative`
226
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
227
+
228
+ Caused by:
229
+ failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401
230
+ body:
231
+ Unauthorized message from server.
232
+
233
+ "# ] ] )
185
234
. with_status ( 101 )
186
235
. run ( ) ;
187
236
}
@@ -203,9 +252,20 @@ fn bad_environment_token_with_asymmetric_incorrect_subject() {
203
252
"CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
204
253
"incorrect" ,
205
254
)
206
- . with_stderr_contains (
207
- " token rejected for `alternative`, please run `cargo login --registry alternative`" ,
208
- )
255
+ . with_stderr_data ( str![ [ r#"
256
+ [UPDATING] `alternative` index
257
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
258
+
259
+ Caused by:
260
+ token rejected for `alternative`, please run `cargo login --registry alternative`
261
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
262
+
263
+ Caused by:
264
+ failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401
265
+ body:
266
+ Unauthorized message from server.
267
+
268
+ "# ] ] )
209
269
. with_status ( 101 )
210
270
. run ( ) ;
211
271
}
@@ -230,9 +290,20 @@ fn bad_environment_token_with_incorrect_asymmetric() {
230
290
"CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY" ,
231
291
"k3.secret.9Vxr5hVlI_g_orBZN54vPz20bmB4O76wB_MVqUSuJJJqHFLwP8kdn_RY5g6J6pQG" ,
232
292
)
233
- . with_stderr_contains (
234
- " token rejected for `alternative`, please run `cargo login --registry alternative`" ,
235
- )
293
+ . with_stderr_data ( str![ [ r#"
294
+ [UPDATING] `alternative` index
295
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)`
296
+
297
+ Caused by:
298
+ token rejected for `alternative`, please run `cargo login --registry alternative`
299
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
300
+
301
+ Caused by:
302
+ failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401
303
+ body:
304
+ Unauthorized message from server.
305
+
306
+ "# ] ] )
236
307
. with_status ( 101 )
237
308
. run ( ) ;
238
309
}
@@ -249,15 +320,15 @@ fn missing_token() {
249
320
let p = make_project ( ) ;
250
321
cargo ( & p, "build" )
251
322
. with_status ( 101 )
252
- . with_stderr (
253
- "\
323
+ . with_stderr_data ( str![ [ r#"
254
324
[UPDATING] `alternative` index
255
- [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..] )`
325
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo )`
256
326
257
327
Caused by:
258
328
no token found for `alternative`, please run `cargo login --registry alternative`
259
- or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN" ,
260
- )
329
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
330
+
331
+ "# ] ] )
261
332
. run ( ) ;
262
333
}
263
334
@@ -272,8 +343,7 @@ fn missing_token_git() {
272
343
let p = make_project ( ) ;
273
344
cargo ( & p, "build" )
274
345
. with_status ( 101 )
275
- . with_stderr (
276
- "\
346
+ . with_stderr_data ( str![ [ r#"
277
347
[UPDATING] `alternative` index
278
348
[LOCKING] 2 packages to latest compatible versions
279
349
[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -283,8 +353,9 @@ Caused by:
283
353
284
354
Caused by:
285
355
no token found for `alternative`, please run `cargo login --registry alternative`
286
- or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN" ,
287
- )
356
+ or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
357
+
358
+ "# ] ] )
288
359
. run ( ) ;
289
360
}
290
361
@@ -301,20 +372,20 @@ fn incorrect_token() {
301
372
cargo ( & p, "build" )
302
373
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
303
374
. with_status ( 101 )
304
- . with_stderr (
305
- "\
375
+ . with_stderr_data ( str![ [ r#"
306
376
[UPDATING] `alternative` index
307
- [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..] )`
377
+ [ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo )`
308
378
309
379
Caused by:
310
380
token rejected for `alternative`, please run `cargo login --registry alternative`
311
381
or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
312
382
313
383
Caused by:
314
- failed to get successful HTTP response from `http://[..]/index/config.json`, got 401
384
+ failed to get successful HTTP response from `http://127.0.0.1: [..]/index/config.json`, got 401
315
385
body:
316
- Unauthorized message from server." ,
317
- )
386
+ Unauthorized message from server.
387
+
388
+ "# ] ] )
318
389
. run ( ) ;
319
390
}
320
391
@@ -331,18 +402,18 @@ fn incorrect_token_git() {
331
402
cargo ( & p, "build" )
332
403
. env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
333
404
. with_status ( 101 )
334
- . with_stderr (
335
- "\
405
+ . with_stderr_data ( str![ [ r#"
336
406
[UPDATING] `alternative` index
337
407
[LOCKING] 2 packages to latest compatible versions
338
408
[DOWNLOADING] crates ...
339
- [ERROR] failed to download from `http://[..]/dl/bar/0.0.1/download`
409
+ [ERROR] failed to download from `http://127.0.0.1: [..]/dl/bar/0.0.1/download`
340
410
341
411
Caused by:
342
- failed to get successful HTTP response from `http://[..]/dl/bar/0.0.1/download` (127.0.0.1), got 401
412
+ 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
413
body:
344
- Unauthorized message from server." ,
345
- )
414
+ Unauthorized message from server.
415
+
416
+ "# ] ] )
346
417
. run ( ) ;
347
418
}
348
419
@@ -360,18 +431,17 @@ fn anonymous_alt_registry() {
360
431
let p = make_project ( ) ;
361
432
cargo ( & p, & format ! ( "install --index {} bar" , registry. index_url( ) ) )
362
433
. with_status ( 101 )
363
- . with_stderr (
364
- "\
365
- [UPDATING] `[..]` index
366
- [ERROR] no token found for `[..]`
434
+ . with_stderr_data ( str![ [ r#"
435
+ [UPDATING] `sparse+http://127.0.0.1:[..]/index/` index
436
+ [ERROR] no token found for `sparse+http://127.0.0.1:[..]/index/`
367
437
consider setting up an alternate registry in Cargo's configuration
368
438
as described by https://doc.rust-lang.org/cargo/reference/registries.html
369
439
370
440
[registries]
371
- my-registry = { index = \" [..]\ " }
441
+ my-registry = { index = "sparse+http://127.0.0.1: [..]/index/ " }
372
442
373
- " ,
374
- )
443
+
444
+ "# ] ] )
375
445
. run ( ) ;
376
446
}
377
447
@@ -424,8 +494,7 @@ fn duplicate_index() {
424
494
server. index_url ( ) . as_str ( ) ,
425
495
)
426
496
. with_status ( 101 )
427
- . with_stderr (
428
- "\
497
+ . with_stderr_data ( str![ [ r#"
429
498
[UPDATING] `alternative` index
430
499
[LOCKING] 2 packages to latest compatible versions
431
500
[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -434,10 +503,9 @@ Caused by:
434
503
unable to get packages from source
435
504
436
505
Caused by:
437
- multiple registries are configured with the same index url \
438
- 'registry+file://[..]/alternative-registry': alternative1, alternative2
439
- " ,
440
- )
506
+ multiple registries are configured with the same index url 'registry+[ROOTURL]/alternative-registry': alternative1, alternative2
507
+
508
+ "# ] ] )
441
509
. run ( ) ;
442
510
}
443
511
0 commit comments