diff --git a/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs b/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs index 27c9f7b81..1862147e8 100644 --- a/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs +++ b/crates/socket-patch-cli/tests/scan/quoted_url_credentials.rs @@ -3,14 +3,16 @@ //! entry must not copy that credential to the terminal, a CI log or the //! `--json` document (#2287). //! -//! Each case plants one token in a file-only project, runs the built -//! binary against a wiremock patch API, and reads both streams back. +//! Each case plants one token in a small project (the pip one has its +//! own venv, the others hold files alone), runs the built binary against +//! a wiremock patch API, and reads both streams back. use std::path::Path; use wiremock::MockServer; use crate::common; +use crate::common::hermetic::{self, Extra}; use crate::hosted_fixture::*; /// The planted credential. No message may carry it. @@ -72,6 +74,10 @@ fn cargo_git(root: &Path) { } /// pip, with `six` installed from a private mirror by direct reference. +/// The project has its own venv with `six` in it: a scan reads the +/// installed packages, and without one it reads those of the Python on +/// PATH, which holds `six` 1.16.0 on some machines (Ubuntu ships it) and +/// not on others. fn requirements_direct_reference(root: &Path) { std::fs::write( root.join("requirements.txt"), @@ -80,6 +86,20 @@ fn requirements_direct_reference(root: &Path) { ), ) .unwrap(); + // The layout the crawler looks for differs by platform. + let site_packages = if cfg!(windows) { + root.join(".venv").join("Lib").join("site-packages") + } else { + root.join(".venv/lib/python3.12/site-packages") + }; + let dist_info = site_packages.join("six-1.16.0.dist-info"); + std::fs::create_dir_all(&dist_info).unwrap(); + std::fs::write( + dist_info.join("METADATA"), + "Metadata-Version: 2.1\nName: six\nVersion: 1.16.0\n", + ) + .unwrap(); + std::fs::write(site_packages.join("six.py"), "").unwrap(); } const YARN: Case = Case { @@ -162,7 +182,16 @@ async fn run_quotes_without_the_token( "--api-token", "fake", ]); - let (code, stdout, stderr) = common::run_with_env(&root, &args, &[]); + // As `common::run` runs it, and without an activated virtualenv: the + // Python crawler reads one ahead of the project's own venv. + let mut cmd = common::hermetic_command(&common::binary()); + cmd.args(&args).current_dir(&root); + common::jvm_env::isolate_cli(&mut cmd); + hermetic::scrub_extra(&mut cmd, &[Extra::Go, Extra::Venv]); + let out = cmd.output().expect("failed to execute socket-patch binary"); + let code = out.status.code().unwrap_or(-1); + let stdout = String::from_utf8_lossy(&out.stdout).to_string(); + let stderr = String::from_utf8_lossy(&out.stderr).to_string(); let run = format!("{} --mode {mode} (exit {code})", command.join(" ")); let both = format!("{stdout}\n{stderr}"); if both.contains(SECRET) {