mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 08:44:24 +00:00
Moved from MailCraft's crates/openpgp at a44a45013d1c. Built on rPGP 0.21.0 as there. The one code change: the Unicode format-character test the From address check used from mailcraft-names is now a private function here, with a test.
24 lines
1.1 KiB
Rust
24 lines
1.1 KiB
Rust
use crate::autocrypt::MAX_HEADER;
|
|
use crate::{Error, parse_autocrypt};
|
|
|
|
#[test]
|
|
fn a_header_without_addr_or_keydata_is_unreadable() {
|
|
assert_eq!(parse_autocrypt("keydata=AAAA").unwrap_err(), Error::Unreadable);
|
|
assert_eq!(parse_autocrypt("addr=a@example.org").unwrap_err(), Error::Unreadable);
|
|
assert_eq!(parse_autocrypt("").unwrap_err(), Error::Unreadable);
|
|
}
|
|
|
|
#[test]
|
|
fn an_unknown_critical_attribute_makes_the_header_unreadable() {
|
|
assert_eq!(parse_autocrypt("addr=a@example.org; colour=blue; keydata=AAAA").unwrap_err(), Error::Unreadable);
|
|
assert_eq!(parse_autocrypt("addr=a@example.org; novalue; keydata=AAAA").unwrap_err(), Error::Unreadable);
|
|
// One starting with `_` is skipped; the keydata here is no key, so it still doesn't read.
|
|
assert_eq!(parse_autocrypt("addr=a@example.org; _colour=blue; keydata=AAAA").unwrap_err(), Error::Unreadable);
|
|
}
|
|
|
|
#[test]
|
|
fn a_header_too_long_is_refused_before_it_is_read() {
|
|
let long = format!("addr=a@example.org; keydata={}", "A".repeat(MAX_HEADER));
|
|
assert_eq!(parse_autocrypt(&long).unwrap_err(), Error::TooLarge);
|
|
}
|