Tests: script_io makes its temp folders by their real paths

On macOS the temp folder /var/... is a link to /private/var/.... Kept
script file grants hold real paths, and ScriptScope refuses a path by
its names alone when they don't start with a granted path, so the 11
grant tests that name their files under the temp folder were refused
and asked again. folder() now returns the real path of the folder it
makes.

ui_inspect_script_report_leaves_out_files_outside_the_read_root failed
on macOS for the same reason: the report names the included file by
its real path, and the test compared it with the /var spelling. It now
compares with the real path. No change outside the tests.

Fixes #8693
This commit is contained in:
HassanKhan
2026-11-19 16:50:28 +05:00
parent 644f5bc8e3
commit 24da5d2936
2 changed files with 7 additions and 3 deletions
+4 -2
View File
@@ -12,12 +12,14 @@ use crate::*;
const DENIED: &str = "Script file access denied";
/// A fresh folder for test `name`, with a `main` folder inside it for the script.
/// A fresh folder for test `name`, with a `main` folder inside it for the script, by its real
/// path: kept grants hold real paths, and a path named through a link (macOS's `/var` is
/// `/private/var`) is refused by its names alone.
fn folder(name: &str) -> PathBuf {
let base = std::env::temp_dir().join(format!("vc-script-io-{name}-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&base);
std::fs::create_dir_all(base.join("main")).unwrap();
base
std::fs::canonicalize(&base).unwrap()
}
fn write(path: &Path, bytes: &[u8]) {
+3 -1
View File
@@ -1310,7 +1310,9 @@ fn ui_inspect_script_report_leaves_out_files_outside_the_read_root() {
std::fs::write(base.join("outside/bad.jsxinc"), "\nthrow new Error('stopped here');\n").unwrap();
finish(&mut app, json!({"path": s(base.join("outside/run.jsx"))}));
let person = crate::control::inspect(&app, &ctx);
assert_eq!(person["scriptReport"]["file"], json!(s(base.join("outside/bad.jsxinc"))), "{person}");
// The report names the file by its real path (on macOS the temp folder is reached through a link).
let bad = std::fs::canonicalize(base.join("outside/bad.jsxinc")).unwrap();
assert_eq!(person["scriptReport"]["file"], json!(s(bad)), "{person}");
let r = request(&mut app, &tx, "ui.inspect", json!({}));
assert_eq!(r["result"]["scriptReport"]["file"], "bad.jsxinc", "{r}");
assert!(r["result"]["scriptReport"]["console"].to_string().contains("bad.jsxinc:2:"), "{r}");