Skip to content

Commit

Permalink
test: migrate registry_auth to snapbox
Browse files Browse the repository at this point in the history
  • Loading branch information
eth3lbert committed Jun 25, 2024
1 parent 7cc62ad commit fdcd693
Showing 1 changed file with 86 additions and 57 deletions.
143 changes: 86 additions & 57 deletions tests/testsuite/registry_auth.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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]
Expand All @@ -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();
}

Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}

Expand All @@ -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`)`
Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand All @@ -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();
}

Expand Down Expand Up @@ -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`)`
Expand All @@ -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();
}

Expand Down

0 comments on commit fdcd693

Please sign in to comment.