diff options
Diffstat (limited to 'tests/shims.rs')
| -rw-r--r-- | tests/shims.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/shims.rs b/tests/shims.rs index 3422500..b21efab 100644 --- a/tests/shims.rs +++ b/tests/shims.rs @@ -175,6 +175,54 @@ fn repo_add_writes_a_pacman_database() { } #[test] +fn pacman_u_verifies_digests_and_q_reports_the_world() { + // The provisioning step's fail-closed world check runs against this fake: + // `-U` must refuse bytes that do not hash to the digest their name claims, + // and `-Q` must report exactly what landed. + let tmp = tempfile::tempdir().unwrap(); + let log = tmp.path().join("shimlog"); + std::fs::create_dir_all(&log).unwrap(); + let build = tmp.path().join("build"); + std::fs::create_dir_all(&build).unwrap(); + std::fs::write(build.join("PKGBUILD"), common::pkgbuild("plain-make", "1.0", "1", "")).unwrap(); + shim( + "makepkg", + &build, + &[("AUR_SHIM_MANIFEST", &fixture_manifest("plain-make")), ("AUR_SHIM_DIR", &log)], + &["-c", "-f"], + ); + let pkg = build.join("plain-make-1.0-1-x86_64.pkg.tar.zst"); + let bytes = std::fs::read(&pkg).unwrap(); + let blob = tmp.path().join(aur_build::hash::hex(&bytes)); + std::fs::write(&blob, &bytes).unwrap(); + + let (code, _, err) = shim( + "pacman", + tmp.path(), + &[("AUR_SHIM_DIR", &log)], + &["-U", "--noconfirm", &blob.display().to_string()], + ); + assert_eq!(code, 0, "{err}"); + + let (code, out, _) = shim("pacman", tmp.path(), &[("AUR_SHIM_DIR", &log)], &["-Q"]); + assert_eq!(code, 0); + assert!(out.contains("plain-make 1.0-1"), "the world check reads -Q: {out}"); + + // A blob whose bytes do not match the digest its name claims is refused + // like a bad signature: name it with some other digest's hex. + let bad = tmp.path().join(aur_build::hash::hex(b"some other artifact")); + std::fs::write(&bad, b"tampered").unwrap(); + let (code, _, err) = shim( + "pacman", + tmp.path(), + &[("AUR_SHIM_DIR", &log)], + &["-U", &bad.display().to_string()], + ); + assert_ne!(code, 0, "a digest mismatch must fail closed"); + assert!(err.contains("hash"), "{err}"); +} + +#[test] fn gpg_writes_a_detached_signature() { let tmp = tempfile::tempdir().unwrap(); let f = tmp.path().join("thing.pkg.tar.zst"); |
