use super::tests::EnvVarGuard;
use super::*;
use tempfile::tempdir;
#[test]
#[serial_test::serial]
fn register_project_index_never_bypasses_sensitive_path_denylist() {
let data_dir = tempdir().unwrap();
let _env = EnvVarGuard::set(
trusty_common::data_dir::DATA_DIR_OVERRIDE_ENV,
data_dir.path(),
);
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();
let (tx, rx) = std::sync::mpsc::channel();
let server = std::thread::spawn(move || {
use std::io::{Read, Write};
let (mut stream, _) = listener.accept().unwrap();
drop(listener);
let mut buf = [0u8; 4096];
let n = stream.read(&mut buf).unwrap();
let request = String::from_utf8_lossy(&buf[..n]).to_string();
let _ =
stream.write_all(b"HTTP/1.1 200 OK\r\ncontent-length: 0\r\nconnection: close\r\n\r\n");
let _ = stream.flush();
let body = request.split("\r\n\r\n").nth(1).unwrap_or("").to_string();
let _ = tx.send(body);
});
let search_data_dir = data_dir.path().join("trusty-search");
std::fs::create_dir_all(&search_data_dir).unwrap();
std::fs::write(search_data_dir.join("http_addr"), addr.to_string()).unwrap();
let project = tempdir().unwrap();
std::fs::create_dir_all(project.path().join(".git")).unwrap();
let _ = register_project_index(project.path());
let body_json: serde_json::Value = serde_json::from_str(
&rx.recv_timeout(std::time::Duration::from_secs(5))
.expect("fake daemon must have received the create-index POST"),
)
.expect("captured body must be valid JSON");
let _ = server.join();
assert_eq!(
body_json.get("allow_sensitive_path"),
Some(&serde_json::Value::Bool(false)),
"register_project_index must never set allow_sensitive_path: true; got {body_json:?}"
);
}