summaryrefslogtreecommitdiffstats
path: root/sq/tests
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2021-01-15 12:23:07 +0100
committerJustus Winter <justus@sequoia-pgp.org>2021-01-15 15:03:04 +0100
commit41ce3881a1d3d17279528acdb20b806019ec7d48 (patch)
treecdfa82be86aff65060835e7ebf692cb15ec46b7a /sq/tests
parent83190eca2510cf0e139131d966dd448f9a6a80bc (diff)
sq: Rewrite tests to avoid additional dependencies.
- Neither assert_cmd nor predicates are in Debian.
Diffstat (limited to 'sq/tests')
-rw-r--r--sq/tests/sq-key-adopt.rs208
-rw-r--r--sq/tests/sq-sign.rs124
2 files changed, 134 insertions, 198 deletions
diff --git a/sq/tests/sq-key-adopt.rs b/sq/tests/sq-key-adopt.rs
index b3097f14..5bb40f32 100644
--- a/sq/tests/sq-key-adopt.rs
+++ b/sq/tests/sq-key-adopt.rs
@@ -2,8 +2,7 @@
mod integration {
use std::path;
- use assert_cmd::Command;
- use predicates::prelude::*;
+ use assert_cli::Assert;
use sequoia_openpgp as openpgp;
@@ -141,15 +140,15 @@ mod integration {
#[test]
fn adopt_encryption() -> Result<()> {
// Adopt an encryption subkey.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_encryption().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 2, (bob_primary(), &[alice_encryption()])).is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_encryption().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 2, (bob_primary(), &[alice_encryption()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -157,15 +156,15 @@ mod integration {
#[test]
fn adopt_signing() -> Result<()> {
// Adopt a signing subkey (subkey has secret key material).
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_signing().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 2, (bob_primary(), &[alice_signing()])).is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_signing().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 2, (bob_primary(), &[alice_signing()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -173,15 +172,15 @@ mod integration {
#[test]
fn adopt_certification() -> Result<()> {
// Adopt a certification subkey (subkey has secret key material).
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(carol())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_primary().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 4, (carol_primary(), &[alice_primary()])).is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ carol().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_primary().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 4, (carol_primary(), &[alice_primary()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -189,19 +188,18 @@ mod integration {
#[test]
fn adopt_encryption_and_signing() -> Result<()> {
// Adopt an encryption subkey and a signing subkey.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_signing().0.to_hex())
- .arg("--key").arg(alice_encryption().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 3,
- (bob_primary(),
- &[alice_signing(), alice_encryption()]))
- .is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_signing().0.to_hex(),
+ "--key", &alice_encryption().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 3,
+ (bob_primary(),
+ &[alice_signing(), alice_encryption()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -209,16 +207,16 @@ mod integration {
#[test]
fn adopt_twice() -> Result<()> {
// Adopt the same an encryption subkey twice.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_encryption().0.to_hex())
- .arg("--key").arg(alice_encryption().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 2, (bob_primary(), &[alice_encryption()])).is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_encryption().0.to_hex(),
+ "--key", &alice_encryption().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 2, (bob_primary(), &[alice_encryption()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -226,16 +224,16 @@ mod integration {
#[test]
fn adopt_key_appears_twice() -> Result<()> {
// Adopt the an encryption subkey that appears twice.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(alice())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_encryption().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 2, (bob_primary(), &[alice_encryption()])).is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_encryption().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 2, (bob_primary(), &[alice_encryption()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -243,15 +241,16 @@ mod integration {
#[test]
fn adopt_own_encryption() -> Result<()> {
// Adopt its own encryption subkey. This should be a noop.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(alice())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_encryption().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 3, (alice_primary(), &[alice_encryption()])).is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ alice().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_encryption().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 3, (alice_primary(),
+ &[alice_encryption()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -259,15 +258,15 @@ mod integration {
#[test]
fn adopt_own_primary() -> Result<()> {
// Adopt own primary key.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(bob())
- .arg("--key").arg(bob_primary().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 2, (bob_primary(), &[bob_primary()])).is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", bob().to_str().unwrap(),
+ "--key", &bob_primary().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 2, (bob_primary(), &[bob_primary()]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
@@ -275,12 +274,12 @@ mod integration {
#[test]
fn adopt_missing() -> Result<()> {
// Adopt a key that is not present.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(bob())
- .arg("--key").arg("1234 5678 90AB CDEF 1234 5678 90AB CDEF")
- .assert()
- .code(1);
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", bob().to_str().unwrap(),
+ "--key", "1234 5678 90AB CDEF 1234 5678 90AB CDEF"
+ ]).fails().unwrap();
Ok(())
}
@@ -288,25 +287,24 @@ mod integration {
#[test]
fn adopt_from_multiple() -> Result<()> {
// Adopt from multiple certificates simultaneously.
- Command::cargo_bin("sq").unwrap().arg("key").arg("adopt")
- .arg(bob())
- .arg("--keyring").arg(alice())
- .arg("--key").arg(alice_signing().0.to_hex())
- .arg("--key").arg(alice_encryption().0.to_hex())
- .arg("--keyring").arg(carol())
- .arg("--key").arg(carol_signing().0.to_hex())
- .arg("--key").arg(carol_encryption().0.to_hex())
- .assert()
- .code(0)
- .stdout(predicate::function(|output: &[u8]| -> bool {
- check(output, 5,
- (bob_primary(),
- &[
- alice_signing(), alice_encryption(),
- carol_signing(), carol_encryption()
- ]))
- .is_ok()
- }));
+ Assert::cargo_binary("sq").with_args(&[
+ "key", "adopt",
+ bob().to_str().unwrap(),
+ "--keyring", alice().to_str().unwrap(),
+ "--key", &alice_signing().0.to_hex(),
+ "--key", &alice_encryption().0.to_hex(),
+ "--keyring", carol().to_str().unwrap(),
+ "--key", &carol_signing().0.to_hex(),
+ "--key", &carol_encryption().0.to_hex(),
+ ]).stdout().satisfies(|output| {
+ check(output.as_bytes(), 5,
+ (bob_primary(),
+ &[
+ alice_signing(), alice_encryption(),
+ carol_signing(), carol_encryption()
+ ]))
+ .is_ok()
+ }, "check failed").unwrap();
Ok(())
}
diff --git a/sq/tests/sq-sign.rs b/sq/tests/sq-sign.rs
index f75d5b9e..2f40d137 100644
--- a/sq/tests/sq-sign.rs
+++ b/sq/tests/sq-sign.rs
@@ -26,9 +26,7 @@ fn sq_sign() {
// Sign message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--secret-key-file",
&artifact("keys/dennis-simon-anton-private.pgp"),
"--output",
@@ -63,9 +61,7 @@ fn sq_sign() {
// Verify signed message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
&sig.to_string_lossy()])
@@ -80,9 +76,7 @@ fn sq_sign_append() {
// Sign message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--secret-key-file",
&artifact("keys/dennis-simon-anton-private.pgp"),
"--output",
@@ -117,9 +111,7 @@ fn sq_sign_append() {
// Verify signed message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
&sig0.to_string_lossy()])
@@ -129,9 +121,7 @@ fn sq_sign_append() {
let sig1 = tmp_dir.path().join("sig1");
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--append",
"--secret-key-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp"),
@@ -180,18 +170,14 @@ fn sq_sign_append() {
// Verify both signatures of the signed message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
&sig1.to_string_lossy()])
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256.pgp"),
&sig1.to_string_lossy()])
@@ -255,9 +241,7 @@ fn sq_sign_append_on_compress_then_sign() {
// Verify signed message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
&sig0.to_string_lossy()])
@@ -267,9 +251,7 @@ fn sq_sign_append_on_compress_then_sign() {
let sig1 = tmp_dir.path().join("sig1");
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--append",
"--secret-key-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp"),
@@ -322,18 +304,14 @@ fn sq_sign_append_on_compress_then_sign() {
// Verify both signatures of the signed message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
&sig0.to_string_lossy()])
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256.pgp"),
&sig0.to_string_lossy()])
@@ -348,9 +326,7 @@ fn sq_sign_detached() {
// Sign detached.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--detached",
"--secret-key-file",
&artifact("keys/dennis-simon-anton-private.pgp"),
@@ -375,9 +351,7 @@ fn sq_sign_detached() {
// Verify detached.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
"--detached",
@@ -394,9 +368,7 @@ fn sq_sign_detached_append() {
// Sign detached.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--detached",
"--secret-key-file",
&artifact("keys/dennis-simon-anton-private.pgp"),
@@ -421,9 +393,7 @@ fn sq_sign_detached_append() {
// Verify detached.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
"--detached",
@@ -434,9 +404,7 @@ fn sq_sign_detached_append() {
// Check that we don't blindly overwrite signatures.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--detached",
"--secret-key-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp"),
@@ -449,9 +417,7 @@ fn sq_sign_detached_append() {
// Now add a second signature with --append.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--detached",
"--append",
"--secret-key-file",
@@ -482,9 +448,7 @@ fn sq_sign_detached_append() {
// Verify both detached signatures.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/dennis-simon-anton.pgp"),
"--detached",
@@ -493,9 +457,7 @@ fn sq_sign_detached_append() {
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256.pgp"),
"--detached",
@@ -507,9 +469,7 @@ fn sq_sign_detached_append() {
// goes wrong.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--detached",
"--append",
"--secret-key-file",
@@ -547,9 +507,7 @@ fn sq_sign_append_a_notarization() {
// Now add a third signature with --append to a notarized message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--append",
"--secret-key-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp"),
@@ -610,27 +568,21 @@ fn sq_sign_append_a_notarization() {
// Verify both notarizations and the signature.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/neal.pgp"),
&sig0.to_string_lossy()])
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp"),
&sig0.to_string_lossy()])
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256.pgp"),
&sig0.to_string_lossy()])
@@ -645,9 +597,7 @@ fn sq_sign_notarize() {
// Now add a third signature with --append to a notarized message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--notarize",
"--secret-key-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp"),
@@ -696,18 +646,14 @@ fn sq_sign_notarize() {
// Verify both notarizations and the signature.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/neal.pgp"),
&sig0.to_string_lossy()])
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256.pgp"),
&sig0.to_string_lossy()])
@@ -722,9 +668,7 @@ fn sq_sign_notarize_a_notarization() {
// Now add a third signature with --append to a notarized message.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "sign",
+ &["sign",
"--notarize",
"--secret-key-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256-private.pgp"),
@@ -785,27 +729,21 @@ fn sq_sign_notarize_a_notarization() {
// Verify both notarizations and the signature.
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/neal.pgp"),
&sig0.to_string_lossy()])
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/emmelie-dorothea-dina-samantha-awina-ed25519.pgp"),
&sig0.to_string_lossy()])
.unwrap();
Assert::cargo_binary("sq")
.with_args(
- &["--home",
- &tmp_dir.path().to_string_lossy(),
- "verify",
+ &["verify",
"--sender-cert-file",
&artifact("keys/erika-corinna-daniela-simone-antonia-nistp256.pgp"),
&sig0.to_string_lossy()])