use std::fs;
use sequoia_openpgp as openpgp;
use openpgp::serialize::Serialize;
mod common;
use common::Environment;
use common::Result;
fn create_environment() -> Result<(Environment, String)> {
Environment::scooby_gang_bootstrap(None)
}
#[test]
fn sign_commit() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
let p = e.git_state();
e.git(&["checkout", "-b", "test-base"])?;
e.git(&["checkout", "-b", "test-willow"])?;
fs::write(p.join("a"), "Aller Anfang ist schwer.")?;
e.git(&["add", "a"])?;
e.git(&[
"commit",
"-m", "First change.",
&format!("-S{}", e.willow.fingerprint),
])?;
e.sq_git(&["log", "--trust-root", &root])?;
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-willow-release"])?;
fs::write(p.join("a"), "Aller Anfang ist schwer. -- Schiller")?;
e.git(&["add", "a"])?;
e.git(&[
"commit",
"-m", "Someone is not quite correct on the internet.",
&format!("-S{}", e.willow_release.fingerprint),
])?;
e.sq_git(&["log", "--trust-root", &root])?;
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-buffy"])?;
fs::write(p.join("a"),
"Aller Anfang ist schwer, unless you are super strong!1")?;
e.git(&["add", "a"])?;
e.git(&[
"commit",
"-m", "Well, actually...",
&format!("-S{}", e.buffy.fingerprint),
])?;
let commit_2 = e.git_current_commit()?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
let commit_3 = e.git_commit(&[("workwork.txt", Some(b"Hiho, hiho"))],
"Off to work we go...",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &commit_2]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..{}", commit_2, commit_3)]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..{}", commit_2, commit_2)]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &commit_2,
&format!("{}..{}", commit_3, commit_3)]).is_ok());
Ok(())
}
#[test]
fn add_user() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.git(&["checkout", "-b", "test-base"])?;
e.git(&["checkout", "-b", "test-willow"])?;
e.sq_git(&[
"policy",
"authorize",
e.buffy.petname,
&e.buffy.fingerprint.to_string(),
"--sign-commit"
])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Add Buffy.",
&format!("-S{}", e.willow.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-willow-release"])?;
e.sq_git(&[
"policy",
"authorize",
e.buffy.petname,
&e.buffy.fingerprint.to_string(),
"--sign-commit"
])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Add Buffy.",
&format!("-S{}", e.willow_release.fingerprint),
])?;
e.sq_git(&["log", "--trust-root", &root])?;
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-xander"])?;
e.sq_git(&[
"policy",
"authorize",
e.buffy.petname,
&e.buffy.fingerprint.to_string(),
"--sign-commit"
])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Add Buffy.",
&format!("-S{}", e.xander.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
Ok(())
}
#[test]
fn retire_user() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.sq_git(&[
"policy",
"authorize",
e.buffy.petname,
&e.buffy.fingerprint.to_string(),
"--sign-commit"
])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Add Buffy.",
&format!("-S{}", e.willow_release.fingerprint),
])?;
e.sq_git(&["log", "--trust-root", &root])?;
e.git(&["checkout", "-b", "test-base"])?;
e.git(&["checkout", "-b", "test-willow"])?;
e.sq_git(&[
"policy",
"authorize",
e.buffy.petname,
&e.buffy.fingerprint.to_string(),
"--no-sign-commit",
])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Add Buffy.",
&format!("-S{}", e.willow.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-willow-release"])?;
e.sq_git(&[
"policy",
"authorize",
e.buffy.petname,
&e.buffy.fingerprint.to_string(),
"--no-sign-commit",
])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Add Buffy.",
&format!("-S{}", e.willow_release.fingerprint),
])?;
e.sq_git(&["log", "--trust-root", &root])?;
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-xander"])?;
e.sq_git(&[
"policy",
"authorize",
e.buffy.petname,
&e.buffy.fingerprint.to_string(),
"--no-sign-commit",
])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Add Buffy.",
&format!("-S{}", e.xander.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
Ok(())
}
#[test]
fn audit() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
let p = e.git_state();
fs::write(p.join("superpowers"), "Willow can break encryption.")?;
e.git(&["add", "superpowers"])?;
e.git(&[
"commit",
"-m", "Willow data commit.",
&format!("-S{}", e.willow.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_ok());
fs::write(p.join("a"),
"Aller Anfang ist schwer, I'll go fetch the hammer!")?;
e.git(&["add", "a"])?;
e.git(&[
"commit",
"-m", "No problem, we'll get you up and running in no time.",
&format!("-S{}", e.xander.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
"--policy-file", "openpgp-policy.toml"]).is_err());
let bad_commit = e.git_current_commit()?;
e.git(&["checkout", "-b", "test-base"])?;
e.git(&["checkout", "-b", "test-willow"])?;
e.sq_git(&["policy", "goodlist", &bad_commit])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Goodlist the bad commit.",
&format!("-S{}", e.willow.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
"--policy-file", "openpgp-policy.toml"]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
"--policy-file", "openpgp-policy.toml",
&format!("{}..", root)]).is_ok());
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-willow-release"])?;
e.sq_git(&["policy", "goodlist", &bad_commit])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Goodlist the bad commit.",
&format!("-S{}", e.willow_release.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
"--policy-file", "openpgp-policy.toml"]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.sq_git(&["log", "--trust-root", &root,
"--policy-file", "openpgp-policy.toml",
&format!("{}..", root)])?;
e.git(&["checkout", "test-base"])?;
e.git(&["clean", "-fdx"])?;
e.git(&["checkout", "-b", "test-xander"])?;
e.sq_git(&["policy", "goodlist", &bad_commit])?;
e.git(&["add", "openpgp-policy.toml"])?;
e.git(&[
"commit",
"-m", "Goodlist the bad commit.",
&format!("-S{}", e.xander.fingerprint),
])?;
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
"--policy-file", "openpgp-policy.toml"]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
"--policy-file", "openpgp-policy.toml",
&format!("{}..", root)]).is_err());
Ok(())
}
#[test]
#[allow(unused_variables)]
fn goodlist_1() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.sq_git(&[
"policy",
"authorize",
e.riley.petname,
&e.riley.fingerprint.to_string(),
"--sign-commit",
])?;
let commit_a = e.git_commit(&[("openpgp-policy.toml", None)],
"A: willow authorizes riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_b = e.git_commit(&[("riley.txt", Some(b"riley was here"))],
"B: riley signs a commit",
Some(&e.riley)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_c = e.git_commit(&[("workwork.txt", Some(b"1"))],
"C: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let riley_revocation_pgp = e.scratch_state().join("riley-revocation.pgp");
let mut f = std::fs::File::create(&riley_revocation_pgp).unwrap();
e.riley.hard_revoke().serialize(&mut f).unwrap();
drop(f);
e.sq_git(&[
"policy",
"authorize",
"--cert-file", &riley_revocation_pgp.to_str().unwrap(),
e.riley.petname,
])?;
let commit_d = e.git_commit(&[("openpgp-policy.toml", None)],
"D: willow imports hard revocation for riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
let commit_e = e.git_commit(&[("workwork.txt", Some(b"e"))],
"E: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.sq_git(&[
"policy",
"goodlist",
&commit_b,
])?;
let commit_f = e.git_commit(&[("openpgp-policy.toml", None)],
"F: willow good lists riley's commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_g = e.git_commit(&[("workwork.txt", Some(b"g"))],
"G: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
Ok(())
}
#[test]
#[allow(unused_variables)]
fn goodlist_2() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.sq_git(&[
"policy",
"authorize",
e.riley.petname,
&e.riley.fingerprint.to_string(),
"--sign-commit",
])?;
let commit_a = e.git_commit(&[("openpgp-policy.toml", None)],
"A: willow authorizes riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_b = e.git_commit(&[("riley.txt", Some(b"riley was here"))],
"B: riley signs a commit",
Some(&e.riley)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_c = e.git_commit(&[("workwork.txt", Some(b"1"))],
"C: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let riley_revocation_pgp = e.scratch_state().join("riley-revocation.pgp");
let mut f = std::fs::File::create(&riley_revocation_pgp).unwrap();
e.riley.hard_revoke().serialize(&mut f).unwrap();
drop(f);
e.sq_git(&[
"policy",
"authorize",
"--cert-file", &riley_revocation_pgp.to_str().unwrap(),
e.riley.petname,
])?;
let commit_d = e.git_commit(&[("openpgp-policy.toml", None)],
"D: willow imports hard revocation for riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
let commit_e = e.git_commit(&[("workwork.txt", Some(b"e"))],
"E: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
let commit_f = e.git_commit(&[("workwork.txt", Some(b"f"))],
"F: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
let commit_g = e.git_commit(&[("workwork.txt", Some(b"g"))],
"G: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
let commit_h = e.git_commit(&[("workwork.txt", Some(b"h"))],
"H: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.sq_git(&[
"policy",
"goodlist",
&commit_b,
])?;
let commit_i = e.git_commit(&[("openpgp-policy.toml", None)],
"I: willow good lists riley's commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
e.git(&["checkout", &commit_d])?;
e.git(&["clean", "-fdx"])?;
let commit_j = e.git_commit(&[("workwork.md", Some(b"1"))],
"J: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.git(&[ "merge",
"-m", "K: Merge I and J",
&format!("-S{}", e.willow_release.fingerprint),
&commit_j, &commit_i])?;
let commit_k = e.git_current_commit()?;
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
Ok(())
}
#[test]
#[allow(unused_variables)]
fn goodlist_3() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.sq_git(&[
"policy",
"authorize",
e.riley.petname,
&e.riley.fingerprint.to_string(),
"--sign-commit",
])?;
let commit_a = e.git_commit(&[("openpgp-policy.toml", None)],
"A: willow authorizes riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_b = e.git_commit(&[("riley.txt", Some(b"riley was here"))],
"B: riley signs a commit",
Some(&e.riley)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_c = e.git_commit(&[("workwork.txt", Some(b"c"))],
"C: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_d = e.git_commit(&[("workwork.txt", Some(b"d"))],
"D: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
e.git(&["checkout", &commit_b])?;
e.git(&["clean", "-fdx"])?;
let riley_revocation_pgp = e.scratch_state().join("riley-revocation.pgp");
let mut f = std::fs::File::create(&riley_revocation_pgp).unwrap();
e.riley.hard_revoke().serialize(&mut f).unwrap();
drop(f);
e.sq_git(&[
"policy",
"authorize",
"--cert-file", &riley_revocation_pgp.to_str().unwrap(),
e.riley.petname,
])?;
let commit_e = e.git_commit(&[("openpgp-policy.toml", None)],
"E: willow imports hard revocation for riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..{}", root, commit_d)]).is_ok());
e.git(&[ "merge",
"-m", "F: Merge D and E",
&format!("-S{}", e.willow_release.fingerprint),
&commit_d, &commit_e])?;
let commit_k = e.git_current_commit()?;
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
Ok(())
}
#[test]
#[allow(unused_variables)]
fn goodlist_4() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.sq_git(&[
"policy",
"authorize",
e.riley.petname,
&e.riley.fingerprint.to_string(),
"--sign-commit",
])?;
let commit_a = e.git_commit(&[("openpgp-policy.toml", None)],
"A: willow authorizes riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_b = e.git_commit(&[("riley.txt", Some(b"riley was here"))],
"B: riley signs a commit",
Some(&e.riley)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_c = e.git_commit(&[("riley.txt", Some(b"riley was here, again"))],
"C: riley signs a commit",
Some(&e.riley)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let riley_revocation_pgp = e.scratch_state().join("riley-revocation.pgp");
let mut f = std::fs::File::create(&riley_revocation_pgp).unwrap();
e.riley.hard_revoke().serialize(&mut f).unwrap();
drop(f);
e.sq_git(&[
"policy",
"authorize",
"--cert-file", &riley_revocation_pgp.to_str().unwrap(),
e.riley.petname,
])?;
let commit_d = e.git_commit(&[("openpgp-policy.toml", None)],
"D: willow imports hard revocation for riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.sq_git(&[
"policy",
"goodlist",
&commit_b,
])?;
let commit_e = e.git_commit(&[("openpgp-policy.toml", None)],
"E: willow good lists riley's commit (B)",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.git(&["checkout", &commit_d])?;
e.git(&["clean", "-fdx"])?;
e.sq_git(&[
"policy",
"goodlist",
&commit_c,
])?;
let commit_f = e.git_commit(&[("openpgp-policy.toml", None)],
"F: willow good lists riley's commit (C)",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.git(&[ "merge",
"-m", "G: Merge E and F",
"-s", "ours", "--no-commit",
&commit_e, &commit_f])?;
e.sq_git(&[
"policy",
"goodlist",
&commit_b,
])?;
let commit_f = e.git_commit(&[("openpgp-policy.toml", None)],
"G: Merge E and F",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
Ok(())
}
#[test]
#[allow(unused_variables)]
fn goodlist_5() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.sq_git(&[
"policy",
"authorize",
e.riley.petname,
&e.riley.fingerprint.to_string(),
"--sign-commit",
])?;
let commit_a = e.git_commit(&[("openpgp-policy.toml", None)],
"A: willow authorizes riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_b = e.git_commit(&[("riley.txt", Some(b"riley was here"))],
"B: riley signs a commit",
Some(&e.riley)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_c = e.git_commit(&[("workwork.txt", Some(b"1"))],
"C: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let riley_revocation_pgp = e.scratch_state().join("riley-revocation.pgp");
let mut f = std::fs::File::create(&riley_revocation_pgp).unwrap();
e.riley.hard_revoke().serialize(&mut f).unwrap();
drop(f);
e.sq_git(&[
"policy",
"authorize",
"--cert-file", &riley_revocation_pgp.to_str().unwrap(),
e.riley.petname,
])?;
let commit_d = e.git_commit(&[("openpgp-policy.toml", None)],
"D: willow imports hard revocation for riley",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
let commit_e = e.git_commit(&[("workwork.txt", Some(b"e"))],
"E: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.sq_git(&[
"policy",
"goodlist",
&commit_b,
])?;
let commit_f = e.git_commit(&[("openpgp-policy.toml", None)],
"F: xander good lists riley's commit",
Some(&e.xander)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
let commit_g = e.git_commit(&[("workwork.txt", Some(b"g"))],
"G: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
Ok(())
}
#[test]
#[allow(unused_variables)]
fn via() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
let commit_a = e.git_commit(&[("workwork.txt", Some(b"1"))],
"A: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_b = e.git_commit(&[("workwork.txt", Some(b"2"))],
"B: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_c = e.git_commit(&[("workwork.txt", Some(b"3"))],
"C: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
let commit_d = e.git_commit(&[("workwork.txt", Some(b"4"))],
"D: willow signs a commit",
Some(&e.willow_release)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
e.git(&["checkout", &commit_b])?;
e.git(&["clean", "-fdx"])?;
let commit_e = e.git_commit(&[("busybusy.txt", Some(b"1"))],
"E: xander signs a commit",
Some(&e.xander)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_err());
e.git(&[ "merge",
"-m", "F: Merge D and E",
&format!("-S{}", e.willow_release.fingerprint),
&commit_d, &commit_e])?;
let commit_f = e.git_current_commit()?;
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..", root)]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..{}", commit_d, commit_f)]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..{}", commit_e, commit_f)]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &root,
&format!("{}..{}", commit_f, commit_e)]).is_err());
Ok(())
}
#[test]
fn external_policy_authenticates_trust_root() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
let commit_a = e.git_commit(&[("workwork.txt", Some(b"1"))],
"A: xander signs a commit",
Some(&e.xander)).unwrap();
let _commit_b = e.git_commit(&[("workwork.txt", Some(b"2"))],
"B: willow signs a commit",
Some(&e.willow)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root]).is_err());
assert!(e.sq_git(&["log", "--trust-root", &commit_a]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", &commit_a,
"--policy-file", "openpgp-policy.toml"]).is_err());
e.sq_git(&[
"policy",
"authorize",
e.xander.petname,
&e.xander.fingerprint.to_string(),
"--sign-commit",
])?;
assert!(e.sq_git(&["log", "--trust-root", &commit_a,
"--policy-file", "openpgp-policy.toml"]).is_ok());
Ok(())
}
#[test]
fn symbolic_names() -> anyhow::Result<()> {
let (e, root) = create_environment()?;
e.git(&["checkout", "-b", "commit-a"])?;
let commit_a = e.git_commit(&[("workwork.txt", Some(b"1"))],
"A: willow signs a commit",
Some(&e.willow)).unwrap();
e.git(&["checkout", "-b", "commit-b"])?;
let commit_b = e.git_commit(&[("workwork.txt", Some(b"2"))],
"B: willow signs a commit",
Some(&e.willow)).unwrap();
e.git(&["checkout", "-b", "commit-c"])?;
let commit_c = e.git_commit(&[("workwork.txt", Some(b"3"))],
"C: willow signs a commit",
Some(&e.willow)).unwrap();
assert!(e.sq_git(&["log", "--trust-root", &root]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", &commit_a]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", "commit-a"]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", "commit_a"]).is_err());
assert!(e.sq_git(&["log", "--trust-root", "commit-a",
&commit_b]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", "commit-a",
&format!("{}..{}", commit_b, commit_c)]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", "commit-a",
&format!("commit-b..{}", commit_c)]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", "commit-a",
&format!("{}..commit-c", commit_b)]).is_ok());
assert!(e.sq_git(&["log", "--trust-root", "commit-a",
"commit-b..commit-c"]).is_ok());
Ok(())
}