diff options
| author | Hermes Agent <hermes@localhost> | 2026-08-12 08:16:51 +0000 |
|---|---|---|
| committer | Hermes Agent <hermes@localhost> | 2026-08-12 08:16:51 +0000 |
| commit | 9e3259b6fd163903c406b250e18782370e63c517 (patch) | |
| tree | 068509ece2624bf6b71108866671c5d1d9b012da /tests | |
| parent | ffa26f89481aa2d6259137b27cbe34f8e8330154 (diff) | |
Verify initrd digest before native packaging
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/build.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/build.rs b/tests/build.rs index 2fcd1bf..c9cc59f 100644 --- a/tests/build.rs +++ b/tests/build.rs @@ -73,6 +73,20 @@ impl PackageInstaller for ArchiveFailingInstaller { } } +struct MutatingInitrdBuilder; + +impl InitramfsBuilder for MutatingInitrdBuilder { + fn build(&mut self, request: &InitramfsRequest) -> anyhow::Result<InitramfsResult> { + let initrd = request + .rootfs() + .join(format!("boot/initrd-{}.img", request.kernel().as_str())); + fs::write(&initrd, "primary initrd")?; + let result = InitramfsResult::from_rootfs(request.rootfs(), request.kernel())?; + fs::write(initrd, "mutated initrd")?; + Ok(result) + } +} + #[derive(Default)] struct FixtureInitramfsBuilder; @@ -355,3 +369,38 @@ fn removes_the_new_workspace_and_partial_artifact_when_packaging_fails() { "failed packaging must not leave a companion manifest" ); } + +#[test] +fn removes_the_new_workspace_and_artifact_when_manifest_collection_fails() { + let fixture = tempdir().expect("fixture directory"); + let spec = ImageSpec::load(std::path::Path::new("profiles/alt-controller.toml")) + .expect("load controller spec"); + let plan = BuildPlan::compile(spec).expect("compile build plan"); + let mut executor = BuildExecutor::new(FixtureInstaller::default(), MutatingInitrdBuilder); + let workspace = fixture.path().join("work"); + let artifact = fixture.path().join("out/image.tar"); + + let error = executor + .execute(&plan, &workspace, "profiles/apt.conf", &artifact) + .expect_err("mutated initrd must fail before packaging"); + + assert!( + error + .to_string() + .contains("generated initrd digest changed") + ); + assert!( + !workspace.exists(), + "failed build must not leave a workspace" + ); + assert!( + !artifact.exists(), + "failed manifest collection must not leave an artifact" + ); + assert!( + !ArtifactManifest::path_beside(&artifact) + .expect("manifest path") + .exists(), + "failed manifest collection must not leave a companion manifest" + ); +} |