diff options
author | Nora Widdecke <nora@sequoia-pgp.org> | 2022-06-29 19:11:00 +0200 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2022-06-29 19:19:28 +0200 |
commit | fbfb792c0a6d41397daf5475d25db7785f689b03 (patch) | |
tree | de02aa4fbf0ef82e2f30625e10f354fb0f84537d /sq/tests | |
parent | 56ad63f1b12f41ec38eddf2a2e8131a66a2e22fa (diff) |
sq: Add packet decrypt --session-key.
- Allow giving multiple session keys, try them all until one decrypts
the packet.
Diffstat (limited to 'sq/tests')
-rw-r--r-- | sq/tests/sq-packet-decrypt.rs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/sq/tests/sq-packet-decrypt.rs b/sq/tests/sq-packet-decrypt.rs new file mode 100644 index 00000000..5a466ac7 --- /dev/null +++ b/sq/tests/sq-packet-decrypt.rs @@ -0,0 +1,75 @@ +#[cfg(test)] +mod sq_packet_decrypt { + use assert_cmd::Command; + use predicates::prelude::*; + + use openpgp::Result; + use sequoia_openpgp as openpgp; + + fn artifact(filename: &str) -> String { + format!("tests/data/{}", filename) + } + + // Integration tests should be done with subplot. + // However, at this time, subplot does not support static binary files in tests. + // Generating the test files would mean encrypting some static text symmetrically + // and then extracting the session key, which means parsing of human readabe cli output. + // So, for now, the tests go here. + #[test] + fn session_key() -> Result<()> { + Command::cargo_bin("sq") + .unwrap() + .arg("packet") + .arg("decrypt") + .args(["--session-key", "1FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) + .arg(artifact("messages/rsa.msg.pgp")) + .assert() + .success() + .stderr(predicate::str::contains("Encrypted with Session Key")); + Ok(()) + } + + #[test] + fn session_key_with_prefix() -> Result<()> { + Command::cargo_bin("sq") + .unwrap() + .arg("packet") + .arg("decrypt") + .args(["--session-key", "9:1FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) + .arg(artifact("messages/rsa.msg.pgp")) + .assert() + .success() + .stderr(predicate::str::contains("Decryption failed").not()); + Ok(()) + } + + #[test] + fn session_key_multiple() -> Result<()> { + Command::cargo_bin("sq") + .unwrap() + .arg("packet") + .arg("decrypt") + .args(["--session-key", "2FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) + .args(["--session-key", "9:1FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) + .args(["--session-key", "3FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) + .arg(artifact("messages/rsa.msg.pgp")) + .assert() + .success() + .stderr(predicate::str::contains("Decryption failed").not()); + Ok(()) + } + + #[test] + fn session_key_wrong_key() -> Result<()> { + Command::cargo_bin("sq") + .unwrap() + .arg("packet") + .arg("decrypt") + .args(["--session-key", "BB9CCB8EDE22DC222C83BD1C63AEB97335DDC7B696DB171BD16EAA5784CC0478"]) + .arg(artifact("messages/rsa.msg.pgp")) + .assert() + .failure() + .stderr(predicate::str::contains("No key to decrypt message")); + Ok(()) + } +} |