Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide password in the index printed via --emit-index-annotation #3112

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion crates/uv-resolver/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,12 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> {
// `# from https://pypi.org/simple`).
if self.include_index_annotation {
if let Some(index) = node.index() {
writeln!(f, "{}", format!(" # from {index}").green())?;
let mut url = index.url().clone();
if url.password().is_some() {
// Hide the password.
let _ = url.set_password(Some("****"));
}
writeln!(f, "{}", format!(" # from {url}").green())?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should just omit the username and password entirely -- what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, that is cleaner. making the changes -

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved it out to a method. Thanks!

}
}
}
Expand Down
40 changes: 40 additions & 0 deletions crates/uv/tests/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7640,6 +7640,46 @@ fn compile_index_url_fallback_prefer_primary() -> Result<()> {
Ok(())
}

/// Ensure that the password is hidden when index annotations are displayed via `--emit-index-annotation`.
#[test]
fn emit_index_annotation_hide_password() -> Result<()> {
let context = TestContext::new("3.12");

let requirements_in = context.temp_dir.child("requirements.in");
requirements_in.write_str("requests")?;

uv_snapshot!(context.compile()
.arg("requirements.in")
.arg("--emit-index-annotation")
.env("UV_INDEX_URL", "https://test-user:test-password@pypi.org/simple"), @r###"
success: true
exit_code: 0
----- stdout -----
# This file was autogenerated by uv via the following command:
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z requirements.in --emit-index-annotation
certifi==2024.2.2
# via requests
# from https://test-user:****@pypi.org/simple
charset-normalizer==3.3.2
# via requests
# from https://test-user:****@pypi.org/simple
idna==3.6
# via requests
# from https://test-user:****@pypi.org/simple
requests==2.31.0
# from https://test-user:****@pypi.org/simple
urllib3==2.2.1
# via requests
# from https://test-user:****@pypi.org/simple

----- stderr -----
Resolved 5 packages in [TIME]
"###
);

Ok(())
}

/// Ensure that `--emit-index-annotation` prints the index URL for each package.
#[test]
fn emit_index_annotation_pypi_org_simple() -> Result<()> {
Expand Down
Loading