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)
This commit is contained in:
Zanie Blue 2025-01-29 14:45:03 -06:00 committed by GitHub
parent a3049ecf69
commit ae76a4b7f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 50 additions and 0 deletions

View File

@ -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<()> {