mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
test(appd): check that an unusable store entry does not hide a later store
The test also covers the refusal reported when no other store has the app. The new comment states that a package found and then refused is not replaced by another store's copy. The architecture doc says that a re-signed copy of the same content is visible at once.
This commit is contained in:
parent
a65fb89662
commit
d76d4c726d
2 changed files with 27 additions and 2 deletions
|
|
@ -98,7 +98,9 @@ fn resolve_in(app_id: &str, stores: &[PathBuf]) -> Result<LaunchPackage, Refusal
|
|||
}
|
||||
// The session runs from the revision itself, not the link, so an
|
||||
// update or rollback that switches the link while it runs leaves it
|
||||
// on the bytes it started with.
|
||||
// on the bytes it started with. From here on a refusal is final: a
|
||||
// package that is being changed, or that fails its checks, is not
|
||||
// silently replaced by another store's copy.
|
||||
let pin = weft_ipc_types::store::pin(&dir).map_err(|e| {
|
||||
Refusal::new(
|
||||
500,
|
||||
|
|
@ -433,6 +435,29 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn an_unusable_store_entry_does_not_hide_a_later_store() {
|
||||
let _env = crate::tests::env_lock().blocking_lock();
|
||||
let user = store("unusable_user", ID, "app.wasm");
|
||||
let system = std::env::temp_dir().join(format!(
|
||||
"weft_appd_launch_unusable_system_{}",
|
||||
std::process::id()
|
||||
));
|
||||
let _ = std::fs::remove_dir_all(&system);
|
||||
std::fs::create_dir_all(&system).unwrap();
|
||||
std::fs::rename(user.join(ID), system.join(ID)).unwrap();
|
||||
// A link to something other than one of the app's revisions.
|
||||
std::os::unix::fs::symlink("/tmp", user.join(ID)).unwrap();
|
||||
let found = resolve_in(ID, &[user.clone(), system.clone()]).map(|p| p.root);
|
||||
let alone = refusal(resolve_in(ID, std::slice::from_ref(&user)));
|
||||
finish(&user);
|
||||
let _ = std::fs::remove_dir_all(&system);
|
||||
assert_eq!(found.ok(), Some(system.join(ID)));
|
||||
// With no other store, its problem is reported, not "not installed".
|
||||
assert_eq!(alone.code, 403, "{}", alone.message);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_session_runs_from_its_revision_and_holds_it() {
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ A directory install can still be changed by its owner while a session runs; for
|
|||
|
||||
### Installing and updating
|
||||
|
||||
`weft-pack install` copies the package into a staging directory in the store and checks, verifies and admits that copy, so the bytes that are checked are the bytes that are installed. The copy is flushed to disk and renamed to an immutable revision named by its content digest, `<root>/.revisions/<id>/<digest>`; installing the same content again reuses it. One rename of the link `<root>/<id>` then makes it active. The rename of the link is the commit point. An installation that fails before it leaves the previously active revision active, or, for a first installation, nothing installed; a failed first installation also removes the owner record it created, while one interrupted by a crash leaves that record until `weft-pack uninstall <id>` releases it. After the commit point the update stands, and what an interruption leaves to tidy is collected later. A revision is reused only when it still holds the same content and signature file; otherwise the new copy replaces it in one exchange, unless a running session uses it. A package directory from before revisions is replaced in one exchange with the new link, only while no session runs from it and only after the app data an earlier weft-appd kept in its `data` directory has been moved to the app data directory, under the same rules as for uninstall; otherwise the update stops before replacing anything. Data moved this way stays in the app data directory even if the update is then refused.
|
||||
`weft-pack install` copies the package into a staging directory in the store and checks, verifies and admits that copy, so the bytes that are checked are the bytes that are installed. The copy is flushed to disk and renamed to an immutable revision named by its content digest, `<root>/.revisions/<id>/<digest>`; installing the same content again reuses it. One rename of the link `<root>/<id>` then makes it active. The rename of the link is the commit point. An installation that fails before it leaves the previously active revision active, or, for a first installation, nothing installed; a failed first installation also removes the owner record it created, while one interrupted by a crash leaves that record until `weft-pack uninstall <id>` releases it. After the commit point the update stands, and what an interruption leaves to tidy is collected later. A revision is reused only when it still holds the same content and signature file; otherwise the new copy replaces it in one exchange, unless a running session uses it. Such a replacement, for the same content with another signature file, is visible under the revision's name at once, even if the installation then fails. A package directory from before revisions is replaced in one exchange with the new link, only while no session runs from it and only after the app data an earlier weft-appd kept in its `data` directory has been moved to the app data directory, under the same rules as for uninstall; otherwise the update stops before replacing anything. Data moved this way stays in the app data directory even if the update is then refused.
|
||||
|
||||
The revision active before an update is kept for `weft-pack rollback <id>`, which makes it active again, keeping the revision it replaces in turn; it is checked against the owner record again, so a revision whose publisher key was withdrawn is not rolled back to. Other revisions are removed by each install, rollback or uninstall of the app, except those a session still runs from; those stay until a later operation on the app finds them unused. Temporary links of interrupted activations are removed then too, and staging, unpacking and removal directories once they are an hour old. `weft-pack uninstall` removes the link, so new launches no longer find the app, and the kept revision; running sessions continue on their revisions. Apart from that move of data from the earlier layout, app data is never touched by these operations. Package revisions and app data are independent: rolling back a package does not roll back its data.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue