diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2021-02-16 10:03:43 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2021-02-17 11:25:24 +0100 |
commit | 025e5a480794be7846ec0918211b5b6d45224474 (patch) | |
tree | f875dc4cdc1cad15be621663aff0ef87d7c40268 | |
parent | 57ef9e4dc1f5a918766eaa5440b36d7132652ab5 (diff) |
openpgp: Generalize test.
-rw-r--r-- | openpgp/src/parse/stream.rs | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/openpgp/src/parse/stream.rs b/openpgp/src/parse/stream.rs index b99e6f2d..bca36ac9 100644 --- a/openpgp/src/parse/stream.rs +++ b/openpgp/src/parse/stream.rs @@ -2935,22 +2935,38 @@ mod test { .map(|f| Cert::from_bytes(crate::tests::key(f)).unwrap()) .collect::<Vec<_>>(); let tests = &[ - ("messages/signed-1.gpg", VHelper::new(1, 0, 0, 0, keys.clone())), - ("messages/signed-1-sha256-testy.gpg", VHelper::new(0, 1, 0, 0, keys.clone())), - ("messages/signed-1-notarized-by-ed25519.pgp", VHelper::new(2, 0, 0, 0, keys.clone())), - ("keys/neal.pgp", VHelper::new(0, 0, 0, 1, keys.clone())), + // Signed messages. + ("messages/signed-1.gpg", + crate::tests::manifesto(), + true, + Some(crate::frozen_time()), + VHelper::new(1, 0, 0, 0, keys.clone())), + ("messages/signed-1-sha256-testy.gpg", + crate::tests::manifesto(), + true, + Some(crate::frozen_time()), + VHelper::new(0, 1, 0, 0, keys.clone())), + ("messages/signed-1-notarized-by-ed25519.pgp", + crate::tests::manifesto(), + true, + Some(crate::frozen_time()), + VHelper::new(2, 0, 0, 0, keys.clone())), + // A key as example of an invalid message. + ("keys/neal.pgp", + crate::tests::manifesto(), + true, + Some(crate::frozen_time()), + VHelper::new(0, 0, 0, 1, keys.clone())), ]; - let reference = crate::tests::manifesto(); - - for (f, r) in tests { + for (f, reference, test_decryptor, time, r) in tests { eprintln!("{}...", f); // Test Verifier. let h = VHelper::new(0, 0, 0, 0, keys.clone()); let mut v = match VerifierBuilder::from_bytes(crate::tests::file(f))? - .with_policy(&p, crate::frozen_time(), h) { + .with_policy(&p, *time, h) { Ok(v) => v, Err(e) => if r.error > 0 || r.unknown > 0 { // Expected error. No point in trying to read @@ -2972,12 +2988,16 @@ mod test { let mut content = Vec::new(); v.read_to_end(&mut content).unwrap(); assert_eq!(reference.len(), content.len()); - assert_eq!(reference, &content[..]); + assert_eq!(&reference[..], &content[..]); + + if ! test_decryptor { + continue; + } // Test Decryptor. let h = VHelper::new(0, 0, 0, 0, keys.clone()); let mut v = match DecryptorBuilder::from_bytes(crate::tests::file(f))? - .with_policy(&p, crate::frozen_time(), h) { + .with_policy(&p, *time, h) { Ok(v) => v, Err(e) => if r.error > 0 || r.unknown > 0 { // Expected error. No point in trying to read @@ -2999,7 +3019,7 @@ mod test { let mut content = Vec::new(); v.read_to_end(&mut content).unwrap(); assert_eq!(reference.len(), content.len()); - assert_eq!(reference, &content[..]); + assert_eq!(&reference[..], &content[..]); } Ok(()) } |