-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug where username from authentication cache could be ignored (#8345
) Basically, if username-only authentication came from the _cache_ instead of being present on the _request URL_ to start, we'd end up ignoring it during password lookups which breaks keyring. Includes some cosmetic changes to the logging and commentary in the middleware, because I was confused when reading the code and logs.
- Loading branch information
Showing
3 changed files
with
152 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ use url::Url; | |
|
||
use crate::common::{ | ||
self, build_vendor_links_url, decode_token, download_to_disk, packse_index_url, uv_snapshot, | ||
TestContext, | ||
venv_bin_path, TestContext, | ||
}; | ||
use uv_fs::Simplified; | ||
use uv_static::EnvVars; | ||
|
@@ -14689,6 +14689,104 @@ fn lock_change_requires_python() -> Result<()> { | |
Ok(()) | ||
} | ||
|
||
/// Pass credentials for a named index via environment variables. | ||
#[test] | ||
fn lock_keyring_credentials() -> Result<()> { | ||
let keyring_context = TestContext::new("3.12"); | ||
|
||
// Install our keyring plugin | ||
keyring_context | ||
.pip_install() | ||
.arg( | ||
keyring_context | ||
.workspace_root | ||
.join("scripts") | ||
.join("packages") | ||
.join("keyring_test_plugin"), | ||
) | ||
.assert() | ||
.success(); | ||
|
||
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"] | ||
|
||
[build-system] | ||
requires = ["setuptools>=42"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.uv] | ||
keyring-provider = "subprocess" | ||
|
||
[[tool.uv.index]] | ||
name = "proxy" | ||
url = "https://pypi-proxy.fly.dev/basic-auth/simple" | ||
default = true | ||
"#, | ||
)?; | ||
|
||
// Provide credentials via environment variables. | ||
uv_snapshot!(context.filters(), context.lock() | ||
.env(EnvVars::index_username("PROXY"), "public") | ||
.env(EnvVars::KEYRING_TEST_CREDENTIALS, r#"{"pypi-proxy.fly.dev": {"public": "heron"}}"#) | ||
.env(EnvVars::PATH, venv_bin_path(&keyring_context.venv)), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
|
||
----- stderr ----- | ||
Request for public@https://pypi-proxy.fly.dev/basic-auth/simple/iniconfig/ | ||
Request for [email protected] | ||
Resolved 2 packages in [TIME] | ||
"###); | ||
|
||
let lock = fs_err::read_to_string(context.temp_dir.join("uv.lock")).unwrap(); | ||
|
||
// The lockfile shout omit the credentials. | ||
insta::with_settings!({ | ||
filters => context.filters(), | ||
}, { | ||
assert_snapshot!( | ||
lock, @r###" | ||
version = 1 | ||
requires-python = ">=3.12" | ||
|
||
[options] | ||
exclude-newer = "2024-03-25T00:00:00Z" | ||
|
||
[[package]] | ||
name = "foo" | ||
version = "0.1.0" | ||
source = { editable = "." } | ||
dependencies = [ | ||
{ name = "iniconfig" }, | ||
] | ||
|
||
[package.metadata] | ||
requires-dist = [{ name = "iniconfig" }] | ||
|
||
[[package]] | ||
name = "iniconfig" | ||
version = "2.0.0" | ||
source = { registry = "https://pypi-proxy.fly.dev/basic-auth/simple" } | ||
sdist = { url = "https://pypi-proxy.fly.dev/basic-auth/files/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3", size = 4646 } | ||
wheels = [ | ||
{ url = "https://pypi-proxy.fly.dev/basic-auth/files/packages/ef/a6/62565a6e1cf69e10f5727360368e451d4b7f58beeac6173dc9db836a5b46/iniconfig-2.0.0-py3-none-any.whl", hash = "sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374", size = 5892 }, | ||
] | ||
"### | ||
); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn lock_multiple_sources() -> Result<()> { | ||
let context = TestContext::new("3.12"); | ||
|