Improve some integration tests to use more of the test framework.

This commit is contained in:
Justus Winter 2024-10-11 16:53:54 +02:00
parent 8f337bbd1e
commit aaae90ce6e
No known key found for this signature in database
GPG Key ID: 686F55B4AB2B3386
3 changed files with 23 additions and 63 deletions

View File

@ -1,8 +1,6 @@
use std::borrow::Cow;
use std::ops::Deref;
use tempfile::TempDir;
use sequoia_openpgp as openpgp;
use openpgp::KeyHandle;
use openpgp::Result;
@ -15,11 +13,9 @@ use super::common::Sq;
fn sq_cert_export() -> Result<()>
{
let sq = Sq::new();
let dir = TempDir::new()?;
struct Data {
userids: &'static [&'static str],
filename: String,
cert: Option<Cert>,
}
@ -32,12 +28,10 @@ fn sq_cert_export() -> Result<()>
let data: &mut [Data] = &mut [
Data {
userids: &[ "<alice@example.org>" ][..],
filename: dir.path().join("alice.pgp").display().to_string(),
cert: None,
},
Data {
userids: &[ "<bob@example.org>" ][..],
filename: dir.path().join("bob.pgp").display().to_string(),
cert: None,
},
Data {
@ -45,7 +39,6 @@ fn sq_cert_export() -> Result<()>
"<carol@sub.example.org>",
"<carol@other.org>",
][..],
filename: dir.path().join("carol.pgp").display().to_string(),
cert: None,
},
][..];
@ -54,16 +47,9 @@ fn sq_cert_export() -> Result<()>
for data in data.iter_mut() {
eprintln!("Generating key for {}",
data.userids.join(", "));
let mut cmd = sq.command();
cmd.args(["key", "generate", "--without-password",
"--expiration", "never",
"--output", &data.filename]);
for userid in data.userids.iter() {
cmd.args(["--userid", userid]);
}
cmd.assert().success();
let (cert, key_file, _rev) =
sq.key_generate(&["--expiration", "never"], &data.userids);
let cert = Cert::from_file(&data.filename)?;
eprintln!("Importing {}", cert.fingerprint());
for ka in cert.keys().subkeys() {
eprintln!(" - {}", ka.fingerprint());
@ -71,10 +57,7 @@ fn sq_cert_export() -> Result<()>
data.cert = Some(cert);
let mut cmd = sq.command();
cmd.args(["cert", "import",
&data.filename]);
cmd.assert().success();
sq.cert_import(key_file);
}
assert_eq!(data.len(), 3);

View File

@ -1,5 +1,3 @@
use tempfile::TempDir;
use sequoia_openpgp as openpgp;
use openpgp::Result;
use openpgp::cert::prelude::*;
@ -11,38 +9,25 @@ use super::common::Sq;
fn sq_cert_import() -> Result<()>
{
let sq = Sq::new();
let dir = TempDir::new()?;
let alice_pgp = dir.path().join("alice.pgp").display().to_string();
let alice_pgp = &alice_pgp[..];
let bob_pgp = dir.path().join("bob.pgp").display().to_string();
let bob_pgp = &bob_pgp[..];
let carol_pgp = dir.path().join("carol.pgp").display().to_string();
let carol_pgp = &carol_pgp[..];
// Generate keys.
let mut cmd = sq.command();
cmd.args(["key", "generate", "--without-password",
"--expiration", "never",
"--userid", "<alice@example.org>",
"--output", &alice_pgp]);
cmd.assert().success();
let (_cert, alice_pgp, _rev) =
sq.key_generate(&["--expiration", "never"], &["<alice@example.org>"]);
let alice_bytes = std::fs::read(&alice_pgp)?;
let mut cmd = sq.command();
cmd.args(["key", "generate", "--without-password",
"--expiration", "never",
"--userid", "<bob@example.org>",
"--output", bob_pgp]);
cmd.assert().success();
let (_cert, bob_pgp, _rev) =
sq.key_generate(&["--expiration", "never"], &["<bob@example.org>"]);
let mut cmd = sq.command();
cmd.args(["key", "generate", "--without-password",
"--expiration", "never",
"--userid", "<carol@example.org>",
"--output", carol_pgp]);
cmd.assert().success();
let (_cert, carol_pgp, _rev) =
sq.key_generate(&["--expiration", "never"], &["<carol@example.org>"]);
let alice_pgp = alice_pgp.display().to_string();
let alice_pgp = &alice_pgp[..];
let bob_pgp = bob_pgp.display().to_string();
let bob_pgp = &bob_pgp[..];
let carol_pgp = carol_pgp.display().to_string();
let carol_pgp = &carol_pgp[..];
let files = &[ alice_pgp, bob_pgp, carol_pgp ];

View File

@ -875,31 +875,23 @@ fn sq_sign_using_cert_store() -> Result<()> {
let certd = dir.path().join("cert.d").display().to_string();
std::fs::create_dir(&certd).expect("mkdir works");
let alice_pgp = dir.path().join("alice.pgp").display().to_string();
let msg_pgp = dir.path().join("msg.pgp").display().to_string();
// Generate a key.
let mut cmd = sq.command();
cmd.args(["--cert-store", &certd,
"key", "generate", "--without-password",
"--expiration", "never",
"--userid", "<alice@example.org>",
"--output", &alice_pgp]);
cmd.assert().success();
let alice = Cert::from_file(&alice_pgp)?;
let (alice, alice_pgp, _rev) =
sq.key_generate(&["--expiration", "never"], &["<alice@example.org>"]);
// Import it.
let mut cmd = sq.command();
cmd.args(["--cert-store", &certd,
"cert", "import", &alice_pgp]);
cmd.assert().success();
"cert", "import"]);
cmd.arg(&alice_pgp);
sq.run(cmd, true);
// Sign a message.
sq.command()
.arg("sign")
.args(["--signer-file", &alice_pgp])
.arg("--signer-file").arg(&alice_pgp)
.args(["--output", &msg_pgp])
.arg(&artifact("messages/a-cypherpunks-manifesto.txt"))
.assert()
@ -938,7 +930,7 @@ fn sq_sign_using_cert_store() -> Result<()> {
// explicitly.
sq.command()
.arg("verify")
.args(["--signer-file", &alice_pgp])
.arg("--signer-file").arg(&alice_pgp)
.arg(&msg_pgp)
.assert()
.success();