Resolve portable run paths for web metadata

This commit is contained in:
salman committed 2026-11-19 21:29:43 +01:00
1 parent 4518553369
commit f672ded04c
2 files changed
+32 -1

No files matched your search

+8 -1
View File
@@ -2091,9 +2091,16 @@ if ($action eq "dump_header") {
if ($file_format !~ /^(?:MusrRoot|NeXus|ROOT|PSI-BIN|PSI-MDU|MUD|WKM)$/) {
respond_json({ ok => JSON::PP::false, code => 400, message => "Invalid data-file format" });
}
if (!path_is_under_data_root($data_file)) {
# Web RUN directives may use a portable path relative to a startup-XML
# <data_path>. Resolve it through the same bounded path resolver used by
# series inventory before invoking dump_header. This keeps metadata lookup
# consistent with musrfit without accepting arbitrary server paths.
my $resolved_data_file = path_is_under_data_root($data_file)
? $data_file : series_data_file_root($data_file);
if (!defined($resolved_data_file)) {
respond_json({ ok => JSON::PP::false, code => 400, message => "Invalid data-file path" });
}
$data_file = $resolved_data_file;
if (!-f $data_file) {
respond_json({ ok => JSON::PP::false, code => 404, message => "Data file not found" });
}
+24
View File
@@ -140,6 +140,30 @@ try {
assert.strictEqual(res.message, "Invalid data-file path");
}
// 4b. Portable RUN names resolve through administrator-owned startup XML
// data paths, matching abbreviated names used by browser Fit/Plot.
{
const portableRoot = path.join(testRoot, "portable-data");
const portableFile = path.join(portableRoot, "2026", "lem26_his_1200.root");
const startupXml = path.join(testRoot, "musrfit_startup.xml");
fs.mkdirSync(path.dirname(portableFile), { recursive: true });
fs.writeFileSync(portableFile, "dummy");
fs.writeFileSync(startupXml, [
"<musrfit_startup>",
" <data_path>" + portableRoot + "</data_path>",
"</musrfit_startup>",
""
].join("\n"));
const res = runCGI(new URLSearchParams({
action: "dump_header",
fn: "2026/lem26_his_1200.root",
file_format: "MusrRoot"
}).toString(), { MUSRFIT_STARTUP_XML: startupXml });
assert.strictEqual(res.ok, true);
assert.strictEqual(res.code, 0);
assert.match(res.header, /RUN 514/);
}
// 5. dump_header hangs are bounded by the watchdog. The fake records its
// pid and sleeps; the CGI must return a timeout well before the sleep
// finishes and must kill the child process.