summaryrefslogtreecommitdiffstats
path: root/tool/tests
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-09-19 14:03:09 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-09-19 17:58:42 +0200
commitb484cc6cae267d5ee05f9be709611cb583c272a7 (patch)
tree22411924e4aba5a1e8a38f293891324afef905b9 /tool/tests
parent7f14945102d365653973ff3643b155ca29dcd808 (diff)
tool: Add test for sq sign.
Diffstat (limited to 'tool/tests')
-rw-r--r--tool/tests/sq-sign.rs106
1 files changed, 106 insertions, 0 deletions
diff --git a/tool/tests/sq-sign.rs b/tool/tests/sq-sign.rs
new file mode 100644
index 00000000..e8788e8e
--- /dev/null
+++ b/tool/tests/sq-sign.rs
@@ -0,0 +1,106 @@
+use std::fs;
+
+extern crate assert_cli;
+use assert_cli::Assert;
+extern crate tempfile;
+use tempfile::TempDir;
+
+extern crate openpgp;
+use openpgp::{Packet, PacketPile, Reader};
+use openpgp::constants::SignatureType;
+
+fn p(filename: &str) -> String {
+ format!("../openpgp/tests/data/{}", filename)
+}
+
+#[test]
+fn sq_sign() {
+ let tmp_dir = TempDir::new().unwrap();
+ let sig = tmp_dir.path().join("sig0");
+
+ // Sign message.
+ Assert::cargo_binary("sq")
+ .with_args(
+ &["sign",
+ "--secret-key-file",
+ &p("keys/dennis-simon-anton-private.pgp"),
+ "--output",
+ &sig.to_string_lossy(),
+ &p("messages/a-cypherpunks-manifesto.txt")])
+ .unwrap();
+
+ // Check that the content is sane.
+ let packets: Vec<Packet> =
+ PacketPile::from_reader(Reader::from_file(&sig).unwrap())
+ .unwrap().into_children().collect();
+ assert_eq!(packets.len(), 3);
+ if let Packet::OnePassSig(ref ops) = packets[0] {
+ assert!(ops.last());
+ assert_eq!(ops.sigtype(), SignatureType::Binary);
+ } else {
+ panic!("expected one pass signature");
+ }
+ if let Packet::Literal(_) = packets[1] {
+ // Do nothing.
+ } else {
+ panic!("expected literal");
+ }
+ if let Packet::Signature(ref sig) = packets[2] {
+ assert_eq!(sig.sigtype(), SignatureType::Binary);
+ } else {
+ panic!("expected signature");
+ }
+
+ let content = fs::read(&sig).unwrap();
+ assert!(&content[..].starts_with(b"-----BEGIN PGP MESSAGE-----\n\n"));
+
+ // Verify signed message.
+ Assert::cargo_binary("sq")
+ .with_args(
+ &["verify",
+ "--public-key-file",
+ &p("keys/dennis-simon-anton.pgp"),
+ &sig.to_string_lossy()])
+ .unwrap();
+}
+
+#[test]
+fn sq_sign_detached() {
+ let tmp_dir = TempDir::new().unwrap();
+ let sig = tmp_dir.path().join("sig0");
+
+ // Sign detached.
+ Assert::cargo_binary("sq")
+ .with_args(
+ &["sign",
+ "--detached",
+ "--secret-key-file",
+ &p("keys/dennis-simon-anton-private.pgp"),
+ "--output",
+ &sig.to_string_lossy(),
+ &p("messages/a-cypherpunks-manifesto.txt")])
+ .unwrap();
+
+ // Check that the content is sane.
+ let packets: Vec<Packet> =
+ PacketPile::from_reader(Reader::from_file(&sig).unwrap())
+ .unwrap().into_children().collect();
+ assert_eq!(packets.len(), 1);
+ if let Packet::Signature(ref sig) = packets[0] {
+ assert_eq!(sig.sigtype(), SignatureType::Binary);
+ } else {
+ panic!("expected signature");
+ }
+
+ let content = fs::read(&sig).unwrap();
+ assert!(&content[..].starts_with(b"-----BEGIN PGP SIGNATURE-----\n\n"));
+
+ // Verify detached.
+ Assert::cargo_binary("sqv")
+ .with_args(
+ &["--keyring",
+ &p("keys/dennis-simon-anton.pgp"),
+ &sig.to_string_lossy(),
+ &p("messages/a-cypherpunks-manifesto.txt")])
+ .unwrap();
+}