mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
address review: packaging applies the source-read gate to the linked path
This commit is contained in:
1 parent
7a8cb8d60c
commit
e1125904be
2 files changed
+27
-2
No files matched your search
@@ -1498,8 +1498,11 @@ fn package(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
};
|
||||
// The path lives in the document, not in the params: a file the session's policy
|
||||
// refuses is packaged as missing, as smart-object renders refuse to read it. Both
|
||||
// spellings are gated, the stored link path as well as the resolved one.
|
||||
let refused = |p: &str| s.authorize.is_some_and(|gate| gate(cmd, &json!({"path": p})).is_err());
|
||||
// spellings are gated, the stored link path as well as the resolved one, and by the
|
||||
// command the renderer reads the file with too.
|
||||
let refused = |p: &str| {
|
||||
s.authorize.is_some_and(|gate| [cmd, "layer.smartObjects.updateModifiedContent"].iter().any(|c| gate(c, &json!({"path": p})).is_err()))
|
||||
};
|
||||
if refused(path.as_str()) || refused(&file.to_string_lossy()) {
|
||||
missing.push(path.clone());
|
||||
continue;
|
||||
|
||||
@@ -1585,3 +1585,25 @@ fn package_skips_links_the_session_refuses() {
|
||||
assert_eq!(r["missing"], json!([link]));
|
||||
assert!(!std::path::Path::new(&format!("{dir}/pkg/Print Me/Links/art.png")).exists());
|
||||
}
|
||||
|
||||
/// A gate that allows `file.package` but refuses the command the renderer reads linked files with
|
||||
/// still keeps the file out of the package.
|
||||
#[test]
|
||||
fn package_applies_the_source_read_gate() {
|
||||
fn deny_source_reads(id: &str, _: &Value) -> Result<()> {
|
||||
if id == "layer.smartObjects.updateModifiedContent" { Err(other("source reads are refused")) } else { Ok(()) }
|
||||
}
|
||||
let dir = tmp("package_read_gate");
|
||||
let link = format!("{dir}/art.png");
|
||||
let mut src = Session::new();
|
||||
src.execute("file.new", json!({"width": 20, "height": 20, "background": "#ff0000"})).unwrap();
|
||||
crate::file_cmds::save_doc(&src.active().unwrap().doc, &link, None).unwrap();
|
||||
let mut s = session("rgb", 8);
|
||||
s.execute("file.placeLinked", json!({"path": link})).unwrap();
|
||||
s.authorize = Some(deny_source_reads);
|
||||
let r = s.execute("file.package", json!({"dir": format!("{dir}/pkg")})).unwrap();
|
||||
assert_eq!(r["missing"], json!([link]));
|
||||
s.authorize = None;
|
||||
let r = s.execute("file.package", json!({"dir": format!("{dir}/pkg2")})).unwrap();
|
||||
assert_eq!(r["links"].as_array().map(Vec::len), Some(1), "an ungated package still copies the link");
|
||||
}
|
||||
Reference in new issue
Block a user