Skip to content

Commit 3f004c6

Browse files
committed
fix: improve error for token & provider
1 parent d14c85f commit 3f004c6

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

src/cargo/util/auth/mod.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,26 @@ fn credential_provider(config: &Config, sid: &SourceId) -> CargoResult<Vec<Vec<S
108108
secret_key,
109109
..
110110
}) if config.cli_unstable().credential_process => {
111+
let provider = resolve_credential_alias(config, provider);
111112
if let Some(token) = token {
112-
config.shell().warn(format!(
113-
"{sid} has a token configured in {} that will be ignored \
114-
because a credential-provider is configured for this registry`",
115-
token.definition
116-
))?;
113+
if provider[0] != "cargo:token" {
114+
config.shell().warn(format!(
115+
"{sid} has a token configured in {} that will be ignored \
116+
because this registry is configured to use credential-provider `{}`",
117+
token.definition, provider[0],
118+
))?;
119+
}
117120
}
118121
if let Some(secret_key) = secret_key {
119-
config.shell().warn(format!(
120-
"{sid} has a secret-key configured in {} that will be ignored \
121-
because a credential-provider is configured for this registry`",
122-
secret_key.definition
123-
))?;
122+
if provider[0] != "cargo:paseto" {
123+
config.shell().warn(format!(
124+
"{sid} has a secret-key configured in {} that will be ignored \
125+
because this registry is configured to use credential-provider `{}`",
126+
secret_key.definition, provider[0],
127+
))?;
128+
}
124129
}
125-
vec![resolve_credential_alias(config, provider)]
130+
vec![provider]
126131
}
127132

128133
// Warning for both `token` and `secret-key`, stating which will be ignored

tests/testsuite/credential_process.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,31 @@ fn multiple_providers() {
447447

448448
#[cargo_test]
449449
fn both_token_and_provider() {
450+
let server = registry::RegistryBuilder::new()
451+
.credential_provider(&["cargo:paseto"])
452+
.build();
453+
454+
cargo_process("login -Z credential-process -Z asymmetric-token")
455+
.masquerade_as_nightly_cargo(&["credential-process", "asymmetric-token"])
456+
.replace_crates_io(server.index_url())
457+
.with_stderr(
458+
r#"[UPDATING] [..]
459+
[WARNING] registry `crates-io` has a token configured in [..] that will be ignored because this registry is configured to use credential-provider `cargo:paseto`
460+
k3.public[..]
461+
"#,
462+
)
463+
.run();
464+
}
465+
466+
#[cargo_test]
467+
fn registry_provider_overrides_global() {
450468
let server = registry::RegistryBuilder::new().build();
451469
cargo_util::paths::append(
452470
&paths::home().join(".cargo/config"),
453471
format!(
454472
r#"
455473
[registry]
456-
credential-provider = ["cargo:token"]
474+
global-credential-providers = ["should-not-be-called"]
457475
"#,
458476
)
459477
.as_bytes(),
@@ -462,10 +480,10 @@ fn both_token_and_provider() {
462480

463481
cargo_process("login -Z credential-process -v abcdefg")
464482
.masquerade_as_nightly_cargo(&["credential-process"])
483+
.env("CARGO_REGISTRY_CREDENTIAL_PROVIDER", "cargo:token")
465484
.replace_crates_io(server.index_url())
466485
.with_stderr(
467486
r#"[UPDATING] [..]
468-
[WARNING] registry `crates-io` has a token configured in [..]credentials.toml that will be ignored because a credential-provider is configured for this registry`
469487
[CREDENTIAL] cargo:token login crates-io
470488
[LOGIN] token for `crates-io` saved
471489
"#,

0 commit comments

Comments
 (0)