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;
@@ -46,8 +44,8 @@ static SUCCESS_OUTPUT: &'static str = "\
4644[DOWNLOADING] crates ...
4745[DOWNLOADED] bar v0.0.1 (registry `alternative`)
4846[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
5149" ;
5250
5351#[ cargo_test]
@@ -61,18 +59,19 @@ fn requires_credential_provider() {
6159 let p = make_project ( ) ;
6260 p. cargo ( "check" )
6361 . with_status ( 101 )
64- . with_stderr (
65- r#" [UPDATING] `alternative` index
62+ . with_stderr_data ( str! [ [ r#"
63+ [UPDATING] `alternative` index
6664[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`)`
6866
6967Caused by:
7068 unable to get packages from source
7169
7270Caused by:
7371 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+ "# ] ] )
7675 . run ( ) ;
7776}
7877
@@ -85,7 +84,7 @@ fn simple() {
8584 . build ( ) ;
8685
8786 let p = make_project ( ) ;
88- cargo ( & p, "build" ) . with_stderr ( SUCCESS_OUTPUT ) . run ( ) ;
87+ cargo ( & p, "build" ) . with_stderr_data ( SUCCESS_OUTPUT ) . run ( ) ;
8988}
9089
9190#[ cargo_test]
@@ -98,7 +97,7 @@ fn simple_with_asymmetric() {
9897 . build ( ) ;
9998
10099 let p = make_project ( ) ;
101- cargo ( & p, "build" ) . with_stderr ( SUCCESS_OUTPUT ) . run ( ) ;
100+ cargo ( & p, "build" ) . with_stderr_data ( SUCCESS_OUTPUT ) . run ( ) ;
102101}
103102
104103#[ cargo_test]
@@ -117,7 +116,7 @@ fn environment_config() {
117116 registry. index_url ( ) . as_str ( ) ,
118117 )
119118 . env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , registry. token ( ) )
120- . with_stderr ( SUCCESS_OUTPUT )
119+ . with_stderr_data ( SUCCESS_OUTPUT )
121120 . run ( ) ;
122121}
123122
@@ -133,7 +132,7 @@ fn environment_token() {
133132 let p = make_project ( ) ;
134133 cargo ( & p, "build" )
135134 . env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , registry. token ( ) )
136- . with_stderr ( SUCCESS_OUTPUT )
135+ . with_stderr_data ( SUCCESS_OUTPUT )
137136 . run ( ) ;
138137}
139138
@@ -154,7 +153,7 @@ fn environment_token_with_asymmetric() {
154153 let p = make_project ( ) ;
155154 cargo ( & p, "build" )
156155 . env ( "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY" , registry. key ( ) )
157- . with_stderr ( SUCCESS_OUTPUT )
156+ . with_stderr_data ( SUCCESS_OUTPUT )
158157 . run ( ) ;
159158}
160159
@@ -179,9 +178,20 @@ fn bad_environment_token_with_asymmetric_subject() {
179178 "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
180179 "incorrect" ,
181180 )
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+ "# ] ] )
185195 . with_status ( 101 )
186196 . run ( ) ;
187197}
@@ -203,9 +213,20 @@ fn bad_environment_token_with_asymmetric_incorrect_subject() {
203213 "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT" ,
204214 "incorrect" ,
205215 )
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+ "# ] ] )
209230 . with_status ( 101 )
210231 . run ( ) ;
211232}
@@ -230,9 +251,20 @@ fn bad_environment_token_with_incorrect_asymmetric() {
230251 "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY" ,
231252 "k3.secret.9Vxr5hVlI_g_orBZN54vPz20bmB4O76wB_MVqUSuJJJqHFLwP8kdn_RY5g6J6pQG" ,
232253 )
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+ "# ] ] )
236268 . with_status ( 101 )
237269 . run ( ) ;
238270}
@@ -249,15 +281,15 @@ fn missing_token() {
249281 let p = make_project ( ) ;
250282 cargo ( & p, "build" )
251283 . with_status ( 101 )
252- . with_stderr (
253- "\
284+ . with_stderr_data ( str![ [ r#"
254285[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 )`
256287
257288Caused by:
258289 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+ "# ] ] )
261293 . run ( ) ;
262294}
263295
@@ -272,8 +304,7 @@ fn missing_token_git() {
272304 let p = make_project ( ) ;
273305 cargo ( & p, "build" )
274306 . with_status ( 101 )
275- . with_stderr (
276- "\
307+ . with_stderr_data ( str![ [ r#"
277308[UPDATING] `alternative` index
278309[LOCKING] 2 packages to latest compatible versions
279310[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -283,8 +314,9 @@ Caused by:
283314
284315Caused by:
285316 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+ "# ] ] )
288320 . run ( ) ;
289321}
290322
@@ -301,20 +333,20 @@ fn incorrect_token() {
301333 cargo ( & p, "build" )
302334 . env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
303335 . with_status ( 101 )
304- . with_stderr (
305- "\
336+ . with_stderr_data ( str![ [ r#"
306337[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 )`
308339
309340Caused by:
310341 token rejected for `alternative`, please run `cargo login --registry alternative`
311342 or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN
312343
313344Caused 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
315346 body:
316- Unauthorized message from server." ,
317- )
347+ Unauthorized message from server.
348+
349+ "# ] ] )
318350 . run ( ) ;
319351}
320352
@@ -331,18 +363,18 @@ fn incorrect_token_git() {
331363 cargo ( & p, "build" )
332364 . env ( "CARGO_REGISTRIES_ALTERNATIVE_TOKEN" , "incorrect" )
333365 . with_status ( 101 )
334- . with_stderr (
335- "\
366+ . with_stderr_data ( str![ [ r#"
336367[UPDATING] `alternative` index
337368[LOCKING] 2 packages to latest compatible versions
338369[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`
340371
341372Caused 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
343374 body:
344- Unauthorized message from server." ,
345- )
375+ Unauthorized message from server.
376+
377+ "# ] ] )
346378 . run ( ) ;
347379}
348380
@@ -360,18 +392,17 @@ fn anonymous_alt_registry() {
360392 let p = make_project ( ) ;
361393 cargo ( & p, & format ! ( "install --index {} bar" , registry. index_url( ) ) )
362394 . 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/`
367398consider setting up an alternate registry in Cargo's configuration
368399as described by https://doc.rust-lang.org/cargo/reference/registries.html
369400
370401[registries]
371- my-registry = { index = \" [..]\ " }
402+ my-registry = { index = "sparse+http://127.0.0.1: [..]/index/ " }
372403
373- " ,
374- )
404+
405+ "# ] ] )
375406 . run ( ) ;
376407}
377408
@@ -424,8 +455,7 @@ fn duplicate_index() {
424455 server. index_url ( ) . as_str ( ) ,
425456 )
426457 . with_status ( 101 )
427- . with_stderr (
428- "\
458+ . with_stderr_data ( str![ [ r#"
429459[UPDATING] `alternative` index
430460[LOCKING] 2 packages to latest compatible versions
431461[ERROR] failed to download `bar v0.0.1 (registry `alternative`)`
@@ -434,10 +464,9 @@ Caused by:
434464 unable to get packages from source
435465
436466Caused 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+ "# ] ] )
441470 . run ( ) ;
442471}
443472
0 commit comments