From 6c090d827ae470b0b0062d295899ee46f9f4ae36 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 1 Jun 2024 15:02:35 -0400 Subject: [PATCH 1/2] fixture: Add missing trailing NUL in security.selinux xattr Because we were only doing bare-user checkouts in the test suite (and not trying to physically materialize the xattrs) and because ostree today doesn't validate xattrs, this problem was silently ignored. But I was looking at changing the tests to do a checkout, and this caused confusing failures. Add the missing trailing `NUL`. Also while we're here, split the xattr function in two; one which returns the Rust-native value and a wrapper which converts to GVariant. This will be useful later. --- lib/src/fixture.rs | 8 ++++++-- lib/tests/it/main.rs | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/src/fixture.rs b/lib/src/fixture.rs index 8693f1b3..bae068c7 100644 --- a/lib/src/fixture.rs +++ b/lib/src/fixture.rs @@ -170,7 +170,7 @@ m 0 0 1755 d tmp "## }; pub const CONTENTS_CHECKSUM_V0: &str = - "f8c5c1ad93339fd6e928aec7819de79ecec4ec8a4d0cb3565bb1d127fd7f56db"; + "acc42fb5c796033f034941dc688643bf8beddfd9068d87165344d2b99906220a"; // 1 for ostree commit, 2 for max frequency packages, 3 as empty layer pub const LAYERS_V0_LEN: usize = 3usize; pub const PKGS_V0_LEN: usize = 7usize; @@ -229,8 +229,12 @@ impl SeLabel { } } + pub fn xattrs(&self) -> Vec<(&[u8], &[u8])> { + vec![(b"security.selinux\0", self.to_str().as_bytes())] + } + pub fn new_xattrs(&self) -> glib::Variant { - vec![("security.selinux".as_bytes(), self.to_str().as_bytes())].to_variant() + self.xattrs().to_variant() } } diff --git a/lib/tests/it/main.rs b/lib/tests/it/main.rs index d6a01791..0dacf39d 100644 --- a/lib/tests/it/main.rs +++ b/lib/tests/it/main.rs @@ -806,7 +806,7 @@ r usr/bin/bash bash-v0 assert!(second.0.commit.is_none()); assert_eq!( first.1, - "ostree export of commit cc1180f8431dc5bd69172d9a9ded36038dc9449f7c6c48e7686c894e483bfb8a" + "ostree export of commit fe4ba8bbd8f61a69ae53cde0dd53c637f26dfbc87717b2e71e061415d931361e" ); assert_eq!(second.1, "8 components"); From 1e023b22cedaec6ed8aaaa8832d0a07fa22de993 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Sat, 1 Jun 2024 15:14:07 -0400 Subject: [PATCH 2/2] tests: Add some error context This helped me debug a recent problem. --- lib/src/fixture.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/src/fixture.rs b/lib/src/fixture.rs index bae068c7..35f406d8 100644 --- a/lib/src/fixture.rs +++ b/lib/src/fixture.rs @@ -254,8 +254,10 @@ pub fn create_dirmeta(path: &Utf8Path, selinux: bool) -> glib::Variant { } /// Wraps [`create_dirmeta`] and commits it. +#[context("Init dirmeta for {path}")] pub fn require_dirmeta(repo: &ostree::Repo, path: &Utf8Path, selinux: bool) -> Result { let v = create_dirmeta(path, selinux); + ostree::validate_structureof_dirmeta(&v).context("Validating dirmeta")?; let r = repo.write_metadata( ostree::ObjectType::DirMeta, None, @@ -454,6 +456,7 @@ impl Fixture { Ok(()) } + #[context("Writing filedef {}", def.path.as_str())] pub fn write_filedef(&self, root: &ostree::MutableTree, def: &FileDef) -> Result<()> { let parent_path = def.path.parent(); let parent = if let Some(parent_path) = parent_path { @@ -472,15 +475,18 @@ impl Fixture { let xattrs = label.map(|v| v.new_xattrs()); let xattrs = xattrs.as_ref(); let checksum = match &def.ty { - FileDefType::Regular(contents) => self.srcrepo.write_regfile_inline( - None, - 0, - 0, - libc::S_IFREG | def.mode, - xattrs, - contents.as_bytes(), - gio::Cancellable::NONE, - )?, + FileDefType::Regular(contents) => self + .srcrepo + .write_regfile_inline( + None, + 0, + 0, + libc::S_IFREG | def.mode, + xattrs, + contents.as_bytes(), + gio::Cancellable::NONE, + ) + .context("Writing regfile inline")?, FileDefType::Symlink(target) => self.srcrepo.write_symlink( None, def.uid, @@ -496,7 +502,9 @@ impl Fixture { return Ok(()); } }; - parent.replace_file(name, checksum.as_str())?; + parent + .replace_file(name, checksum.as_str()) + .context("Setting file")?; Ok(()) }