summaryrefslogtreecommitdiff
path: root/tests/inst/src/sysroot.rs
blob: 818b4eb10a0c5ae3a7a07dc0b6bc0c192ab51bb3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Tests that mostly use the API and access the booted sysroot read-only.

use std::os::unix::prelude::PermissionsExt;
use std::path::Path;

use anyhow::Result;
use ostree_ext::prelude::*;
use ostree_ext::{gio, ostree};

use crate::test::*;

fn skip_non_ostree_host() -> bool {
    !std::path::Path::new("/run/ostree-booted").exists()
}

pub(crate) fn itest_sysroot_ro() -> Result<()> {
    // TODO add a skipped identifier
    if skip_non_ostree_host() {
        return Ok(());
    }
    let cancellable = Some(gio::Cancellable::new());
    let sysroot = ostree::Sysroot::new_default();
    sysroot.load(cancellable.as_ref())?;
    assert!(sysroot.is_booted());

    let booted = sysroot.booted_deployment().expect("booted deployment");
    assert!(!booted.is_staged());
    let repo = sysroot.repo().expect("repo");

    let csum = booted.csum().expect("booted csum");
    let csum = csum.as_str();

    let (root, rev) = repo.read_commit(csum, cancellable.as_ref())?;
    assert_eq!(rev, csum);
    let root = root.downcast::<ostree::RepoFile>().expect("downcast");
    root.ensure_resolved()?;

    Ok(())
}

pub(crate) fn itest_immutable_bit() -> Result<()> {
    if skip_non_ostree_host() {
        return Ok(());
    }
    // https://bugzilla.redhat.com/show_bug.cgi?id=1867601
    cmd_has_output(sh_inline::bash_command!("lsattr -d /").unwrap(), "-i-")?;
    Ok(())
}

pub(crate) fn itest_tmpfiles() -> Result<()> {
    if skip_non_ostree_host() {
        return Ok(());
    }
    let metadata = Path::new("/run/ostree").metadata()?;
    assert_eq!(metadata.permissions().mode() & !nix::libc::S_IFMT, 0o755);
    Ok(())
}