Skip to content

Commit 0f6000f

Browse files
committed
Store native credentials for realms with the https scheme stripped
1 parent a519b79 commit 0f6000f

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

crates/uv-auth/src/keyring.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,26 @@ impl KeyringProvider {
8787
// Ensure we strip credentials from the URL before storing
8888
let url = url.without_credentials();
8989

90+
// If there's no path, we'll perform a host-level login
91+
let target = if let Some(host) = url.host_str().filter(|_| !url.path().is_empty()) {
92+
let mut target = String::new();
93+
if url.scheme() != "https" {
94+
target.push_str(url.scheme());
95+
target.push_str("://");
96+
}
97+
target.push_str(host);
98+
if let Some(port) = url.port() {
99+
target.push(':');
100+
target.push_str(&port.to_string());
101+
}
102+
target
103+
} else {
104+
url.to_string()
105+
};
106+
90107
match &self.backend {
91108
KeyringProviderBackend::Native => {
92-
self.store_native(url.as_str(), username, password).await?;
109+
self.store_native(&target, username, password).await?;
93110
Ok(true)
94111
}
95112
KeyringProviderBackend::Subprocess => {

crates/uv/tests/it/auth.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,12 @@ fn token_native_auth_realm() -> Result<()> {
462462
.arg("--username")
463463
.arg("public")
464464
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth"), @r"
465-
success: false
466-
exit_code: 2
465+
success: true
466+
exit_code: 0
467467
----- stdout -----
468+
heron
468469
469470
----- stderr -----
470-
error: Failed to fetch credentials for public@https://pypi-proxy.fly.dev/basic-auth/simple
471471
");
472472

473473
// Without the username
@@ -561,12 +561,12 @@ fn token_native_auth_realm() -> Result<()> {
561561
uv_snapshot!(context.auth_token()
562562
.arg("https://public@pypi-proxy.fly.dev/basic-auth/simple")
563563
.env(EnvVars::UV_PREVIEW_FEATURES, "native-auth"), @r"
564-
success: false
565-
exit_code: 2
564+
success: true
565+
exit_code: 0
566566
----- stdout -----
567+
heron
567568
568569
----- stderr -----
569-
error: Failed to fetch credentials for public@https://pypi-proxy.fly.dev/basic-auth/simple
570570
");
571571

572572
Ok(())

0 commit comments

Comments
 (0)