From c25977685303669b3fe709c8bdc5e40421c0b918 Mon Sep 17 00:00:00 2001 From: eth3lbert Date: Wed, 26 Jun 2024 04:19:30 +0800 Subject: [PATCH] test: migrate registry_auth to snapbox --- tests/testsuite/registry_auth.rs | 143 +++++++++++++++++++------------ 1 file changed, 86 insertions(+), 57 deletions(-) diff --git a/tests/testsuite/registry_auth.rs b/tests/testsuite/registry_auth.rs index 6c9ad9902794..91c9cf68050b 100644 --- a/tests/testsuite/registry_auth.rs +++ b/tests/testsuite/registry_auth.rs @@ -1,7 +1,5 @@ //! Tests for registry authentication. -#![allow(deprecated)] - use cargo_test_support::compare::assert_e2e; use cargo_test_support::registry::{Package, RegistryBuilder, Token}; use cargo_test_support::str; @@ -46,8 +44,8 @@ static SUCCESS_OUTPUT: &'static str = "\ [DOWNLOADING] crates ... [DOWNLOADED] bar v0.0.1 (registry `alternative`) [COMPILING] bar v0.0.1 (registry `alternative`) -[COMPILING] foo v0.0.1 ([CWD]) -[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]s +[COMPILING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "; #[cargo_test] @@ -61,18 +59,19 @@ fn requires_credential_provider() { let p = make_project(); p.cargo("check") .with_status(101) - .with_stderr( - r#"[UPDATING] `alternative` index + .with_stderr_data(str![[r#" +[UPDATING] `alternative` index [LOCKING] 2 packages to latest compatible versions -error: failed to download `bar v0.0.1 (registry `alternative`)` +[ERROR] failed to download `bar v0.0.1 (registry `alternative`)` Caused by: unable to get packages from source Caused by: authenticated registries require a credential-provider to be configured - see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details"#, - ) + see https://doc.rust-lang.org/cargo/reference/registry-authentication.html for details + +"#]]) .run(); } @@ -85,7 +84,7 @@ fn simple() { .build(); let p = make_project(); - cargo(&p, "build").with_stderr(SUCCESS_OUTPUT).run(); + cargo(&p, "build").with_stderr_data(SUCCESS_OUTPUT).run(); } #[cargo_test] @@ -98,7 +97,7 @@ fn simple_with_asymmetric() { .build(); let p = make_project(); - cargo(&p, "build").with_stderr(SUCCESS_OUTPUT).run(); + cargo(&p, "build").with_stderr_data(SUCCESS_OUTPUT).run(); } #[cargo_test] @@ -117,7 +116,7 @@ fn environment_config() { registry.index_url().as_str(), ) .env("CARGO_REGISTRIES_ALTERNATIVE_TOKEN", registry.token()) - .with_stderr(SUCCESS_OUTPUT) + .with_stderr_data(SUCCESS_OUTPUT) .run(); } @@ -133,7 +132,7 @@ fn environment_token() { let p = make_project(); cargo(&p, "build") .env("CARGO_REGISTRIES_ALTERNATIVE_TOKEN", registry.token()) - .with_stderr(SUCCESS_OUTPUT) + .with_stderr_data(SUCCESS_OUTPUT) .run(); } @@ -154,7 +153,7 @@ fn environment_token_with_asymmetric() { let p = make_project(); cargo(&p, "build") .env("CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY", registry.key()) - .with_stderr(SUCCESS_OUTPUT) + .with_stderr_data(SUCCESS_OUTPUT) .run(); } @@ -179,9 +178,20 @@ fn bad_environment_token_with_asymmetric_subject() { "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT", "incorrect", ) - .with_stderr_contains( - " token rejected for `alternative`, please run `cargo login --registry alternative`", - ) + .with_stderr_data(str![[r#" +[UPDATING] `alternative` index +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` + +Caused by: + token rejected for `alternative`, please run `cargo login --registry alternative` + or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN + +Caused by: + failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401 + body: + Unauthorized message from server. + +"#]]) .with_status(101) .run(); } @@ -203,9 +213,20 @@ fn bad_environment_token_with_asymmetric_incorrect_subject() { "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY_SUBJECT", "incorrect", ) - .with_stderr_contains( - " token rejected for `alternative`, please run `cargo login --registry alternative`", - ) + .with_stderr_data(str![[r#" +[UPDATING] `alternative` index +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` + +Caused by: + token rejected for `alternative`, please run `cargo login --registry alternative` + or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN + +Caused by: + failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401 + body: + Unauthorized message from server. + +"#]]) .with_status(101) .run(); } @@ -230,9 +251,20 @@ fn bad_environment_token_with_incorrect_asymmetric() { "CARGO_REGISTRIES_ALTERNATIVE_SECRET_KEY", "k3.secret.9Vxr5hVlI_g_orBZN54vPz20bmB4O76wB_MVqUSuJJJqHFLwP8kdn_RY5g6J6pQG", ) - .with_stderr_contains( - " token rejected for `alternative`, please run `cargo login --registry alternative`", - ) + .with_stderr_data(str![[r#" +[UPDATING] `alternative` index +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` + +Caused by: + token rejected for `alternative`, please run `cargo login --registry alternative` + or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN + +Caused by: + failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401 + body: + Unauthorized message from server. + +"#]]) .with_status(101) .run(); } @@ -249,15 +281,15 @@ fn missing_token() { let p = make_project(); cargo(&p, "build") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index -[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])` +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` Caused by: no token found for `alternative`, please run `cargo login --registry alternative` - or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN", - ) + or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN + +"#]]) .run(); } @@ -272,8 +304,7 @@ fn missing_token_git() { let p = make_project(); cargo(&p, "build") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index [LOCKING] 2 packages to latest compatible versions [ERROR] failed to download `bar v0.0.1 (registry `alternative`)` @@ -283,8 +314,9 @@ Caused by: Caused by: no token found for `alternative`, please run `cargo login --registry alternative` - or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN", - ) + or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN + +"#]]) .run(); } @@ -301,20 +333,20 @@ fn incorrect_token() { cargo(&p, "build") .env("CARGO_REGISTRIES_ALTERNATIVE_TOKEN", "incorrect") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index -[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([..])` +[ERROR] failed to get `bar` as a dependency of package `foo v0.0.1 ([ROOT]/foo)` Caused by: token rejected for `alternative`, please run `cargo login --registry alternative` or use environment variable CARGO_REGISTRIES_ALTERNATIVE_TOKEN Caused by: - failed to get successful HTTP response from `http://[..]/index/config.json`, got 401 + failed to get successful HTTP response from `http://127.0.0.1:[..]/index/config.json`, got 401 body: - Unauthorized message from server.", - ) + Unauthorized message from server. + +"#]]) .run(); } @@ -331,18 +363,18 @@ fn incorrect_token_git() { cargo(&p, "build") .env("CARGO_REGISTRIES_ALTERNATIVE_TOKEN", "incorrect") .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index [LOCKING] 2 packages to latest compatible versions [DOWNLOADING] crates ... -[ERROR] failed to download from `http://[..]/dl/bar/0.0.1/download` +[ERROR] failed to download from `http://127.0.0.1:[..]/dl/bar/0.0.1/download` Caused by: - failed to get successful HTTP response from `http://[..]/dl/bar/0.0.1/download` (127.0.0.1), got 401 + failed to get successful HTTP response from `http://127.0.0.1:[..]/dl/bar/0.0.1/download` (127.0.0.1), got 401 body: - Unauthorized message from server.", - ) + Unauthorized message from server. + +"#]]) .run(); } @@ -360,18 +392,17 @@ fn anonymous_alt_registry() { let p = make_project(); cargo(&p, &format!("install --index {} bar", registry.index_url())) .with_status(101) - .with_stderr( - "\ -[UPDATING] `[..]` index -[ERROR] no token found for `[..]` + .with_stderr_data(str![[r#" +[UPDATING] `sparse+http://127.0.0.1:[..]/index/` index +[ERROR] no token found for `sparse+http://127.0.0.1:[..]/index/` consider setting up an alternate registry in Cargo's configuration as described by https://doc.rust-lang.org/cargo/reference/registries.html [registries] -my-registry = { index = \"[..]\" } +my-registry = { index = "sparse+http://127.0.0.1:[..]/index/" } -", - ) + +"#]]) .run(); } @@ -424,8 +455,7 @@ fn duplicate_index() { server.index_url().as_str(), ) .with_status(101) - .with_stderr( - "\ + .with_stderr_data(str![[r#" [UPDATING] `alternative` index [LOCKING] 2 packages to latest compatible versions [ERROR] failed to download `bar v0.0.1 (registry `alternative`)` @@ -434,10 +464,9 @@ Caused by: unable to get packages from source Caused by: - multiple registries are configured with the same index url \ - 'registry+file://[..]/alternative-registry': alternative1, alternative2 -", - ) + multiple registries are configured with the same index url 'registry+[ROOTURL]/alternative-registry': alternative1, alternative2 + +"#]]) .run(); }