summaryrefslogtreecommitdiff
path: root/tests/inst/src/repobin.rs
blob: b034326a3f115c2fc61975bbf7b33601224cc7aa (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//! Tests that mostly use the CLI and operate on temporary
//! repositories.

use std::path::Path;

use crate::test::*;
use anyhow::{Context, Result};
use sh_inline::{bash_command, bash};
use with_procspawn_tempdir::with_procspawn_tempdir;

#[itest]
fn test_basic() -> Result<()> {
    bash!(r"ostree --help >/dev/null")?;
    Ok(())
}

#[itest]
#[with_procspawn_tempdir]
fn test_nofifo() -> Result<()> {
    assert!(std::path::Path::new(".procspawn-tmpdir").exists());
    bash!(
        r"ostree --repo=repo init --mode=archive
    mkdir tmproot
    mkfifo tmproot/afile
"
    )?;
    cmd_fails_with(
        bash_command!(
            r#"ostree --repo=repo commit -b fifotest -s "commit fifo" --tree=dir=./tmproot"#
        )
        .unwrap(),
        "Not a regular file or symlink",
    )?;
    Ok(())
}

#[itest]
#[with_procspawn_tempdir]
fn test_mtime() -> Result<()> {
    bash!(
        r"ostree --repo=repo init --mode=archive
    mkdir tmproot
    echo afile > tmproot/afile
    ostree --repo=repo commit -b test --tree=dir=tmproot >/dev/null
"
    )?;
    let ts = Path::new("repo").metadata()?.modified().unwrap();
    bash!(
        r#"ostree --repo=repo commit -b test -s "bump mtime" --tree=dir=tmproot >/dev/null"#
    )?;
    assert_ne!(ts, Path::new("repo").metadata()?.modified().unwrap());
    Ok(())
}

#[itest]
#[with_procspawn_tempdir]
fn test_extensions() -> Result<()> {
    bash!(r"ostree --repo=repo init --mode=bare")?;
    assert!(Path::new("repo/extensions").exists());
    Ok(())
}

#[itest]
#[with_procspawn_tempdir]
fn test_pull_basicauth() -> Result<()> {
    let opts = TestHttpServerOpts {
        basicauth: true,
        ..Default::default()
    };
    let serverrepo = Path::new("server/repo");
    std::fs::create_dir_all(&serverrepo)?;
    with_webserver_in(&serverrepo, &opts, move |addr| {
        let baseuri = http::Uri::from_maybe_shared(format!("http://{}/", addr).into_bytes())?;
        let unauthuri =
            http::Uri::from_maybe_shared(format!("http://unknown:badpw@{}/", addr).into_bytes())?;
        let authuri = http::Uri::from_maybe_shared(
            format!("http://{}@{}/", TEST_HTTP_BASIC_AUTH, addr).into_bytes(),
        )?;
        let osroot = Path::new("osroot");
        crate::treegen::mkroot(&osroot)?;
        bash!(
            r#"ostree --repo={serverrepo} init --mode=archive
        ostree --repo={serverrepo} commit -b os --tree=dir={osroot} >/dev/null
        mkdir client
        cd client
        ostree --repo=repo init --mode=archive
        ostree --repo=repo remote add --set=gpg-verify=false origin-unauth {baseuri}
        ostree --repo=repo remote add --set=gpg-verify=false origin-badauth {unauthuri}
        ostree --repo=repo remote add --set=gpg-verify=false origin-goodauth {authuri}
        "#,
            osroot = osroot.to_str(),
            serverrepo = serverrepo.to_str(),
            baseuri = baseuri.to_string(),
            unauthuri = unauthuri.to_string(),
            authuri = authuri.to_string()
        )?;
        for rem in &["unauth", "badauth"] {
            cmd_fails_with(
                bash_command!(
                    r#"ostree --repo=client/repo pull origin-{rem} os >/dev/null"#,
                    rem = *rem
                )
                .unwrap(),
                "HTTP 403",
            )
            .context(rem)?;
        }
        bash!(r#"ostree --repo=client/repo pull origin-goodauth os >/dev/null"#,)?;
        Ok(())
    })?;
    Ok(())
}