From ae76a4b7f5a2cc57abd7c971a8d41a94a04f594f Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 29 Jan 2025 14:45:03 -0600 Subject: [PATCH] Add test case for multiple indexes on the same realm (#11080) A test case for https://github.com/astral-sh/uv/pull/11074 (and related issues) --- crates/uv/tests/it/lock.rs | 50 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/crates/uv/tests/it/lock.rs b/crates/uv/tests/it/lock.rs index fa4e29ff9..6674ad0e7 100644 --- a/crates/uv/tests/it/lock.rs +++ b/crates/uv/tests/it/lock.rs @@ -8305,6 +8305,56 @@ fn lock_env_credentials() -> Result<()> { Ok(()) } +/// Test solving for packages that are pinned to separate indexes in the same realm. +/// This requires the credentials to be cached at the URL-level instead of the realm-level, or +/// credentials for one index will be used for both indexes and the request will fail. +#[test] +fn lock_multiple_indexes_same_realm_different_credentials() -> Result<()> { + let context = TestContext::new("3.12"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" + [project] + name = "foo" + version = "0.1.0" + requires-python = ">=3.12" + dependencies = ["iniconfig", "anyio"] + + [tool.uv.sources] + iniconfig = { index = "internal-proxy-heron" } + anyio = { index = "internal-proxy-eagle" } + + [[tool.uv.index]] + name = "internal-proxy-heron" + url = "https://pypi-proxy.fly.dev/basic-auth-heron/simple" + + [[tool.uv.index]] + name = "internal-proxy-eagle" + url = "https://pypi-proxy.fly.dev/basic-auth-eagle/simple" + "#, + )?; + + // Provide credentials via environment variables. + uv_snapshot!(context.filters(), context.lock() + .env(EnvVars::index_username("INTERNAL_PROXY_HERON"), "public") + .env(EnvVars::index_password("INTERNAL_PROXY_HERON"), "heron") + .env(EnvVars::index_username("INTERNAL_PROXY_EAGLE"), "public") + .env(EnvVars::index_password("INTERNAL_PROXY_EAGLE"), "eagle"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + warning: Missing version constraint (e.g., a lower bound) for `iniconfig` + warning: Missing version constraint (e.g., a lower bound) for `anyio` + error: Failed to fetch: `https://pypi-proxy.fly.dev/basic-auth-heron/files/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl.metadata` + Caused by: HTTP status client error (401 Unauthorized) for url (https://pypi-proxy.fly.dev/basic-auth-heron/files/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl.metadata) + "###); + + Ok(()) +} + /// Resolve against an index that uses relative links. #[test] fn lock_relative_index() -> Result<()> {