| 1 |
use predicates::prelude::*; |
| 2 |
|
| 3 |
use openpgp::Result; |
| 4 |
use sequoia_openpgp as openpgp; |
| 5 |
|
| 6 |
use super::common::{Sq, artifact}; |
| 7 |
|
| 8 |
// Integration tests should be done with subplot. |
| 9 |
// However, at this time, subplot does not support static binary files in tests. |
| 10 |
// Generating the test files would mean encrypting some static text symmetrically |
| 11 |
// and then extracting the session key, which means parsing of human readabe cli output. |
| 12 |
// So, for now, the tests go here. |
| 13 |
#[test] |
| 14 |
fn session_key() -> Result<()> { |
| 15 |
let sq = Sq::new(); |
| 16 |
sq.command() |
| 17 |
.arg("packet") |
| 18 |
.arg("decrypt") |
| 19 |
.args(["--session-key", "1FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) |
| 20 |
.arg(artifact("messages/rsa.msg.pgp")) |
| 21 |
.assert() |
| 22 |
.success() |
| 23 |
.stderr(predicate::str::contains("Encrypted with Session Key")); |
| 24 |
Ok(()) |
| 25 |
} |
| 26 |
|
| 27 |
#[test] |
| 28 |
fn session_key_with_prefix() -> Result<()> { |
| 29 |
let sq = Sq::new(); |
| 30 |
sq.command() |
| 31 |
.arg("packet") |
| 32 |
.arg("decrypt") |
| 33 |
.args(["--session-key", "9:1FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) |
| 34 |
.arg(artifact("messages/rsa.msg.pgp")) |
| 35 |
.assert() |
| 36 |
.success() |
| 37 |
.stderr(predicate::str::contains("Decryption failed").not()); |
| 38 |
Ok(()) |
| 39 |
} |
| 40 |
|
| 41 |
#[test] |
| 42 |
fn session_key_multiple() -> Result<()> { |
| 43 |
let sq = Sq::new(); |
| 44 |
sq.command() |
| 45 |
.arg("packet") |
| 46 |
.arg("decrypt") |
| 47 |
.args(["--session-key", "2FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) |
| 48 |
.args(["--session-key", "9:1FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) |
| 49 |
.args(["--session-key", "3FE820EC21FB5D7E33D83367106D1D3747DCD48E6320C1AEC57EE7D18FC437D4"]) |
| 50 |
.arg(artifact("messages/rsa.msg.pgp")) |
| 51 |
.assert() |
| 52 |
.success() |
| 53 |
.stderr(predicate::str::contains("Decryption failed").not()); |
| 54 |
Ok(()) |
| 55 |
} |
| 56 |
|
| 57 |
#[test] |
| 58 |
fn session_key_wrong_key() -> Result<()> { |
| 59 |
let sq = Sq::new(); |
| 60 |
sq.command() |
| 61 |
.arg("packet") |
| 62 |
.arg("decrypt") |
| 63 |
.args(["--session-key", "BB9CCB8EDE22DC222C83BD1C63AEB97335DDC7B696DB171BD16EAA5784CC0478"]) |
| 64 |
.arg(artifact("messages/rsa.msg.pgp")) |
| 65 |
.assert() |
| 66 |
.failure() |
| 67 |
.stderr(predicate::str::contains("No key to decrypt message")); |
| 68 |
Ok(()) |
| 69 |
} |