mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
fix: improve error for token & provider
This commit is contained in:
parent
d14c85f4e6
commit
3f004c613c
@ -108,21 +108,26 @@ fn credential_provider(config: &Config, sid: &SourceId) -> CargoResult<Vec<Vec<S
|
|||||||
secret_key,
|
secret_key,
|
||||||
..
|
..
|
||||||
}) if config.cli_unstable().credential_process => {
|
}) if config.cli_unstable().credential_process => {
|
||||||
|
let provider = resolve_credential_alias(config, provider);
|
||||||
if let Some(token) = token {
|
if let Some(token) = token {
|
||||||
config.shell().warn(format!(
|
if provider[0] != "cargo:token" {
|
||||||
"{sid} has a token configured in {} that will be ignored \
|
config.shell().warn(format!(
|
||||||
because a credential-provider is configured for this registry`",
|
"{sid} has a token configured in {} that will be ignored \
|
||||||
token.definition
|
because this registry is configured to use credential-provider `{}`",
|
||||||
))?;
|
token.definition, provider[0],
|
||||||
|
))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if let Some(secret_key) = secret_key {
|
if let Some(secret_key) = secret_key {
|
||||||
config.shell().warn(format!(
|
if provider[0] != "cargo:paseto" {
|
||||||
"{sid} has a secret-key configured in {} that will be ignored \
|
config.shell().warn(format!(
|
||||||
because a credential-provider is configured for this registry`",
|
"{sid} has a secret-key configured in {} that will be ignored \
|
||||||
secret_key.definition
|
because this registry is configured to use credential-provider `{}`",
|
||||||
))?;
|
secret_key.definition, provider[0],
|
||||||
|
))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
vec![resolve_credential_alias(config, provider)]
|
vec![provider]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warning for both `token` and `secret-key`, stating which will be ignored
|
// Warning for both `token` and `secret-key`, stating which will be ignored
|
||||||
|
@ -447,13 +447,31 @@ fn multiple_providers() {
|
|||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test]
|
||||||
fn both_token_and_provider() {
|
fn both_token_and_provider() {
|
||||||
|
let server = registry::RegistryBuilder::new()
|
||||||
|
.credential_provider(&["cargo:paseto"])
|
||||||
|
.build();
|
||||||
|
|
||||||
|
cargo_process("login -Z credential-process -Z asymmetric-token")
|
||||||
|
.masquerade_as_nightly_cargo(&["credential-process", "asymmetric-token"])
|
||||||
|
.replace_crates_io(server.index_url())
|
||||||
|
.with_stderr(
|
||||||
|
r#"[UPDATING] [..]
|
||||||
|
[WARNING] registry `crates-io` has a token configured in [..] that will be ignored because this registry is configured to use credential-provider `cargo:paseto`
|
||||||
|
k3.public[..]
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cargo_test]
|
||||||
|
fn registry_provider_overrides_global() {
|
||||||
let server = registry::RegistryBuilder::new().build();
|
let server = registry::RegistryBuilder::new().build();
|
||||||
cargo_util::paths::append(
|
cargo_util::paths::append(
|
||||||
&paths::home().join(".cargo/config"),
|
&paths::home().join(".cargo/config"),
|
||||||
format!(
|
format!(
|
||||||
r#"
|
r#"
|
||||||
[registry]
|
[registry]
|
||||||
credential-provider = ["cargo:token"]
|
global-credential-providers = ["should-not-be-called"]
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
@ -462,10 +480,10 @@ fn both_token_and_provider() {
|
|||||||
|
|
||||||
cargo_process("login -Z credential-process -v abcdefg")
|
cargo_process("login -Z credential-process -v abcdefg")
|
||||||
.masquerade_as_nightly_cargo(&["credential-process"])
|
.masquerade_as_nightly_cargo(&["credential-process"])
|
||||||
|
.env("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token")
|
||||||
.replace_crates_io(server.index_url())
|
.replace_crates_io(server.index_url())
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
r#"[UPDATING] [..]
|
r#"[UPDATING] [..]
|
||||||
[WARNING] registry `crates-io` has a token configured in [..]credentials.toml that will be ignored because a credential-provider is configured for this registry`
|
|
||||||
[CREDENTIAL] cargo:token login crates-io
|
[CREDENTIAL] cargo:token login crates-io
|
||||||
[LOGIN] token for `crates-io` saved
|
[LOGIN] token for `crates-io` saved
|
||||||
"#,
|
"#,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user