11//! Tests for registry authentication.
22
3- #![ allow( deprecated) ]
4-
53use cargo_test_support:: compare:: assert_e2e;
64use cargo_test_support:: registry:: { Package , RegistryBuilder , Token } ;
75use cargo_test_support:: str;
@@ -40,16 +38,6 @@ fn make_project() -> Project {
4038 p
4139}
4240
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-
5341#[ cargo_test]
5442fn requires_credential_provider ( ) {
5543 let _registry = RegistryBuilder :: new ( )
@@ -61,18 +49,19 @@ fn requires_credential_provider() {
6149 let p = make_project ( ) ;
6250 p. cargo ( "check" )
6351 . with_status ( 101 )
64- . with_stderr (
65- r#" [UPDATING] `alternative` index
52+ . with_stderr_data ( str! [ [ r#"
53+ [UPDATING] `alternative` index
6654[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`)`
6856
6957Caused by:
7058 unable to get packages from source
7159
7260Caused by:
7361 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+ "# ] ] )
7665 . run ( ) ;
7766}
7867
@@ -85,7 +74,18 @@ fn simple() {
8574 . build ( ) ;
8675
8776 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 ( ) ;
8989}
9090
9191#[ cargo_test]
@@ -98,7 +98,18 @@ fn simple_with_asymmetric() {
9898 . build ( ) ;
9999
100100 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 ( ) ;
102113}
103114
104115#[ cargo_test]
@@ -117,7 +128,16 @@ fn environment_config() {
117128 registry. index_url ( ) . as_str ( ) ,
118129 )
119130 . 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+ "# ] ] )
121141 . run ( ) ;
122142}
123143
@@ -133,7 +153,16 @@ fn environment_token() {
133153 let p = make_project ( ) ;
134154 cargo ( & p, "build" )
135155 . 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+ "# ] ] )
137166 . run ( ) ;
138167}
139168
@@ -154,7 +183,16 @@ fn environment_token_with_asymmetric() {
154183 let p = make_project ( ) ;
155184 cargo ( & p, "build" )
156185 . 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+ "# ] ] )
158196 . run ( ) ;
159197}
160198
@@ -179,9 +217,20 @@ fn bad_environment_token_with_asymmetric_subject() {
179217 "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
180218 "incorrect" ,
181219 )
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+ "# ] ] )
185234 . with_status ( 101 )
186235 . run ( ) ;
187236}
@@ -203,9 +252,20 @@ fn bad_environment_token_with_asymmetric_incorrect_subject() {
203252 "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
204253 "incorrect" ,
205254 )
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+ "# ] ] )
209269 . with_status ( 101 )
210270 . run ( ) ;
211271}
@@ -230,9 +290,20 @@ fn bad_environment_token_with_incorrect_asymmetric() {
230290 "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY" ,
231291 "k3.secret.9Vxr5hVlI_g_orBZN54vPz20bmB4O76wB_MVqUSuJJJqHFLwP8kdn_RY5g6J6pQG" ,
232292 )
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+ "# ] ] )
236307 . with_status ( 101 )
237308 . run ( ) ;
238309}
@@ -249,15 +320,15 @@ fn missing_token() {
249320 let p = make_project ( ) ;
250321 cargo ( & p, "build" )
251322 . with_status ( 101 )
252- . with_stderr (
253- "\
323+ . with_stderr_data ( str![ [ r#"
254324[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 )`
256326
257327Caused by:
258328 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+ "# ] ] )
261332 . run ( ) ;
262333}
263334
@@ -272,8 +343,7 @@ fn missing_token_git() {
272343 let p = make_project ( ) ;
273344 cargo ( & p, "build" )
274345 . with_status ( 101 )
275- . with_stderr (
276- "\
346+ . with_stderr_data ( str![ [ r#"
277347[UPDATING] `alternative` index
278348[LOCKING] 2 packages to latest compatible versions
279349[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -283,8 +353,9 @@ Caused by:
283353
284354Caused by:
285355 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+ "# ] ] )
288359 . run ( ) ;
289360}
290361
@@ -301,20 +372,20 @@ fn incorrect_token() {
301372 cargo ( & p, "build" )
302373 . env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
303374 . with_status ( 101 )
304- . with_stderr (
305- "\
375+ . with_stderr_data ( str![ [ r#"
306376[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 )`
308378
309379Caused by:
310380 token rejected for `alternative`, please run `cargo login --registry alternative`
311381 or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
312382
313383Caused 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
315385 body:
316- Unauthorized message from server." ,
317- )
386+ Unauthorized message from server.
387+
388+ "# ] ] )
318389 . run ( ) ;
319390}
320391
@@ -331,18 +402,18 @@ fn incorrect_token_git() {
331402 cargo ( & p, "build" )
332403 . env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
333404 . with_status ( 101 )
334- . with_stderr (
335- "\
405+ . with_stderr_data ( str![ [ r#"
336406[UPDATING] `alternative` index
337407[LOCKING] 2 packages to latest compatible versions
338408[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`
340410
341411Caused 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
343413 body:
344- Unauthorized message from server." ,
345- )
414+ Unauthorized message from server.
415+
416+ "# ] ] )
346417 . run ( ) ;
347418}
348419
@@ -360,18 +431,17 @@ fn anonymous_alt_registry() {
360431 let p = make_project ( ) ;
361432 cargo ( & p, & format ! ( "install --index {} bar" , registry. index_url( ) ) )
362433 . 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/`
367437consider setting up an alternate registry in Cargo's configuration
368438as described by https://doc.rust-lang.org/cargo/reference/registries.html
369439
370440[registries]
371- my-registry = { index = \" [..]\ " }
441+ my-registry = { index = "sparse+http://127.0.0.1: [..]/index/ " }
372442
373- " ,
374- )
443+
444+ "# ] ] )
375445 . run ( ) ;
376446}
377447
@@ -424,8 +494,7 @@ fn duplicate_index() {
424494 server. index_url ( ) . as_str ( ) ,
425495 )
426496 . with_status ( 101 )
427- . with_stderr (
428- "\
497+ . with_stderr_data ( str![ [ r#"
429498[UPDATING] `alternative` index
430499[LOCKING] 2 packages to latest compatible versions
431500[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -434,10 +503,9 @@ Caused by:
434503 unable to get packages from source
435504
436505Caused 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+ "# ] ] )
441509 . run ( ) ;
442510}
443511
0 commit comments