Skip to content

Commit b694b92

Browse files
committed
..
1 parent fa75458 commit b694b92

File tree

6 files changed

+139
-15
lines changed

6 files changed

+139
-15
lines changed

crates/uv-auth/src/index.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ impl Display for AuthPolicy {
5353
// could potentially make sense for a future refactor.
5454
#[derive(Debug, Clone, Hash, Eq, PartialEq)]
5555
pub struct Index {
56+
pub url: Url,
5657
/// The root endpoint where authentication is applied.
5758
/// For PEP 503 endpoints, this excludes `/simple`.
5859
pub root_url: Url,
@@ -84,7 +85,7 @@ impl Indexes {
8485
self.0
8586
.iter()
8687
.find(|index| is_url_prefix(&index.root_url, url))
87-
.map(|index| &index.root_url)
88+
.map(|index| &index.url)
8889
}
8990

9091
/// Get the [`AuthPolicy`] for a URL.

crates/uv-auth/src/middleware.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,10 +1744,12 @@ mod tests {
17441744
let base_url_2 = base_url.join("prefix_2")?;
17451745
let indexes = Indexes::from_indexes(vec![
17461746
Index {
1747+
url: base_url_1.clone(),
17471748
root_url: base_url_1.clone(),
17481749
auth_policy: AuthPolicy::Auto,
17491750
},
17501751
Index {
1752+
url: base_url_2.clone(),
17511753
root_url: base_url_2.clone(),
17521754
auth_policy: AuthPolicy::Auto,
17531755
},
@@ -1850,6 +1852,7 @@ mod tests {
18501852
let base_url = Url::parse(&server.uri())?;
18511853
let index_url = base_url.join("prefix_1")?;
18521854
let indexes = Indexes::from_indexes(vec![Index {
1855+
url: index_url.clone(),
18531856
root_url: index_url.clone(),
18541857
auth_policy: AuthPolicy::Auto,
18551858
}]);
@@ -1908,6 +1911,7 @@ mod tests {
19081911
url.set_password(None).ok();
19091912
url.set_username("").ok();
19101913
Indexes::from_indexes(vec![Index {
1914+
url: url.clone(),
19111915
root_url: url.clone(),
19121916
auth_policy: policy,
19131917
}])

crates/uv-distribution-types/src/index_url.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,15 @@ impl<'a> IndexLocations {
413413
impl From<&IndexLocations> for uv_auth::Indexes {
414414
fn from(index_locations: &IndexLocations) -> uv_auth::Indexes {
415415
uv_auth::Indexes::from_indexes(index_locations.allowed_indexes().into_iter().map(|index| {
416-
let mut url = index
417-
.url()
418-
.root()
419-
.unwrap_or_else(|| index.url().url().clone());
416+
let mut url = index.url().url().clone();
420417
url.set_username("").ok();
421418
url.set_password(None).ok();
419+
let mut root_url = index.url().root().unwrap_or_else(|| url.clone());
420+
root_url.set_username("").ok();
421+
root_url.set_password(None).ok();
422422
uv_auth::Index {
423-
root_url: url,
423+
url,
424+
root_url,
424425
auth_policy: index.authenticate,
425426
}
426427
}))

crates/uv/tests/it/edit.rs

Lines changed: 120 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
#[cfg(feature = "git")]
44
mod conditional_imports {
55
pub(crate) use crate::common::{decode_token, READ_ONLY_GITHUB_TOKEN};
6-
pub(crate) use assert_cmd::assert::OutputAssertExt;
76
}
87

98
#[cfg(feature = "git")]
109
use conditional_imports::*;
1110

1211
use anyhow::Result;
12+
use assert_cmd::assert::OutputAssertExt;
1313
use assert_fs::prelude::*;
1414
use indoc::{formatdoc, indoc};
1515
use insta::assert_snapshot;
@@ -18,7 +18,7 @@ use uv_fs::Simplified;
1818

1919
use uv_static::EnvVars;
2020

21-
use crate::common::{packse_index_url, uv_snapshot, TestContext};
21+
use crate::common::{packse_index_url, uv_snapshot, venv_bin_path, TestContext};
2222

2323
/// Add a PyPI requirement.
2424
#[test]
@@ -10206,6 +10206,124 @@ fn add_unsupported_git_scheme() {
1020610206
"###);
1020710207
}
1020810208

10209+
#[test]
10210+
fn add_index_url_in_keyring() -> Result<()> {
10211+
let keyring_context = TestContext::new("3.12");
10212+
10213+
// Install our keyring plugin
10214+
keyring_context
10215+
.pip_install()
10216+
.arg(
10217+
keyring_context
10218+
.workspace_root
10219+
.join("scripts")
10220+
.join("packages")
10221+
.join("keyring_test_plugin"),
10222+
)
10223+
.assert()
10224+
.success();
10225+
10226+
let context = TestContext::new("3.12");
10227+
10228+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
10229+
pyproject_toml.write_str(indoc! { r#"
10230+
[project]
10231+
name = "foo"
10232+
version = "1.0.0"
10233+
requires-python = ">=3.11, <4"
10234+
dependencies = []
10235+
10236+
[tool.uv]
10237+
keyring-provider = "subprocess"
10238+
10239+
[[tool.uv.index]]
10240+
name = "proxy"
10241+
url = "https://pypi-proxy.fly.dev/basic-auth/simple"
10242+
default = true
10243+
"#
10244+
})?;
10245+
10246+
uv_snapshot!(context.add().arg("anyio")
10247+
.env(EnvVars::index_username("PROXY"), "public")
10248+
.env(EnvVars::KEYRING_TEST_CREDENTIALS, r#"{"https://pypi-proxy.fly.dev/basic-auth/simple": {"public": "heron"}}"#)
10249+
.env(EnvVars::PATH, venv_bin_path(&keyring_context.venv)), @r"
10250+
success: true
10251+
exit_code: 0
10252+
----- stdout -----
10253+
10254+
----- stderr -----
10255+
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth/simple
10256+
Resolved 4 packages in [TIME]
10257+
Prepared 3 packages in [TIME]
10258+
Installed 3 packages in [TIME]
10259+
+ anyio==4.3.0
10260+
+ idna==3.6
10261+
+ sniffio==1.3.1
10262+
"
10263+
);
10264+
10265+
context.assert_command("import anyio").success();
10266+
Ok(())
10267+
}
10268+
10269+
#[test]
10270+
fn add_full_url_in_keyring() -> Result<()> {
10271+
let keyring_context = TestContext::new("3.12");
10272+
10273+
// Install our keyring plugin
10274+
keyring_context
10275+
.pip_install()
10276+
.arg(
10277+
keyring_context
10278+
.workspace_root
10279+
.join("scripts")
10280+
.join("packages")
10281+
.join("keyring_test_plugin"),
10282+
)
10283+
.assert()
10284+
.success();
10285+
10286+
let context = TestContext::new("3.12");
10287+
10288+
let pyproject_toml = context.temp_dir.child("pyproject.toml");
10289+
pyproject_toml.write_str(indoc! { r#"
10290+
[project]
10291+
name = "foo"
10292+
version = "1.0.0"
10293+
requires-python = ">=3.11, <4"
10294+
dependencies = []
10295+
10296+
[tool.uv]
10297+
keyring-provider = "subprocess"
10298+
10299+
[[tool.uv.index]]
10300+
name = "proxy"
10301+
url = "https://pypi-proxy.fly.dev/basic-auth/simple"
10302+
default = true
10303+
"#
10304+
})?;
10305+
10306+
uv_snapshot!(context.add().arg("anyio")
10307+
.env(EnvVars::index_username("PROXY"), "public")
10308+
.env(EnvVars::KEYRING_TEST_CREDENTIALS, r#"{"https://pypi-proxy.fly.dev/basic-auth/simple/anyio": {"public": "heron"}}"#)
10309+
.env(EnvVars::PATH, venv_bin_path(&keyring_context.venv)), @r"
10310+
success: false
10311+
exit_code: 1
10312+
----- stdout -----
10313+
10314+
----- stderr -----
10315+
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth/simple
10316+
Keyring request for [email protected]
10317+
× No solution found when resolving dependencies:
10318+
╰─▶ Because anyio was not found in the package registry and your project depends on anyio, we can conclude that your project's requirements are unsatisfiable.
10319+
10320+
hint: An index URL (https://pypi-proxy.fly.dev/basic-auth/simple) could not be queried due to a lack of valid authentication credentials (401 Unauthorized).
10321+
help: If you want to add the package regardless of the failed resolution, provide the `--frozen` flag to skip locking and syncing.
10322+
"
10323+
);
10324+
Ok(())
10325+
}
10326+
1020910327
/// In authentication "always", the normal authentication flow should still work.
1021010328
#[test]
1021110329
fn add_auth_policy_always_with_credentials() -> Result<()> {

crates/uv/tests/it/lock.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18808,7 +18808,7 @@ fn lock_keyring_credentials() -> Result<()> {
1880818808
----- stdout -----
1880918809

1881018810
----- stderr -----
18811-
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth
18811+
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth/simple
1881218812
Keyring request for [email protected]
1881318813
Resolved 2 packages in [TIME]
1881418814
");
@@ -18913,7 +18913,7 @@ fn lock_keyring_explicit_always() -> Result<()> {
1891318913
----- stdout -----
1891418914

1891518915
----- stderr -----
18916-
Keyring request for https://pypi-proxy.fly.dev/basic-auth
18916+
Keyring request for https://pypi-proxy.fly.dev/basic-auth/simple
1891718917
Keyring request for pypi-proxy.fly.dev
1891818918
× No solution found when resolving dependencies:
1891918919
╰─▶ Because iniconfig was not found in the package registry and your project depends on iniconfig, we can conclude that your project's requirements are unsatisfiable.
@@ -18930,7 +18930,7 @@ fn lock_keyring_explicit_always() -> Result<()> {
1893018930
----- stdout -----
1893118931

1893218932
----- stderr -----
18933-
Keyring request for https://pypi-proxy.fly.dev/basic-auth
18933+
Keyring request for https://pypi-proxy.fly.dev/basic-auth/simple
1893418934
Keyring request for pypi-proxy.fly.dev
1893518935
Resolved 2 packages in [TIME]
1893618936
");
@@ -18996,7 +18996,7 @@ fn lock_keyring_credentials_always_authenticate_fetches_username() -> Result<()>
1899618996
----- stdout -----
1899718997

1899818998
----- stderr -----
18999-
Keyring request for https://pypi-proxy.fly.dev/basic-auth
18999+
Keyring request for https://pypi-proxy.fly.dev/basic-auth/simple
1900019000
Keyring request for pypi-proxy.fly.dev
1900119001
Resolved 2 packages in [TIME]
1900219002
");

crates/uv/tests/it/pip_install.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5341,7 +5341,7 @@ fn install_package_basic_auth_from_keyring() {
53415341
----- stdout -----
53425342
53435343
----- stderr -----
5344-
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth
5344+
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth/simple
53455345
Keyring request for [email protected]
53465346
Resolved 3 packages in [TIME]
53475347
Prepared 3 packages in [TIME]
@@ -5388,7 +5388,7 @@ fn install_package_basic_auth_from_keyring_wrong_password() {
53885388
----- stdout -----
53895389
53905390
----- stderr -----
5391-
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth
5391+
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth/simple
53925392
Keyring request for [email protected]
53935393
× No solution found when resolving dependencies:
53945394
╰─▶ Because anyio was not found in the package registry and you require anyio, we can conclude that your requirements are unsatisfiable.
@@ -5431,7 +5431,7 @@ fn install_package_basic_auth_from_keyring_wrong_username() {
54315431
----- stdout -----
54325432
54335433
----- stderr -----
5434-
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth
5434+
Keyring request for public@https://pypi-proxy.fly.dev/basic-auth/simple
54355435
Keyring request for [email protected]
54365436
× No solution found when resolving dependencies:
54375437
╰─▶ Because anyio was not found in the package registry and you require anyio, we can conclude that your requirements are unsatisfiable.

0 commit comments

Comments
 (0)