fix and cleanup tests

This commit is contained in:
dignifiedquire
2019-10-08 22:19:25 +02:00
committed by holger krekel
parent 03979fdc51
commit fd69ebfd1f
3 changed files with 9 additions and 186 deletions

View File

@@ -40,7 +40,7 @@ pub fn split_armored_data(
let headers = dearmor
.headers
.into_iter()
.map(|(key, value)| (key.to_lowercase(), value))
.map(|(key, value)| (key.trim().to_lowercase(), value.trim().to_string()))
.collect();
Ok((typ, headers, bytes))
@@ -218,7 +218,7 @@ mod tests {
use super::*;
#[test]
fn test_split_armored_data() {
fn test_split_armored_data_1() {
let (typ, _headers, base64) = split_armored_data(
b"-----BEGIN PGP MESSAGE-----\nNoVal:\n\naGVsbG8gd29ybGQ=\n-----END PGP MESSAGE----",
)
@@ -230,36 +230,12 @@ mod tests {
std::string::String::from_utf8(base64).unwrap(),
"hello world"
);
}
let (typ, _headers, base64) =
split_armored_data(b"-----BEGIN PGP MESSAGE-----\n\ndat1\n-----END PGP MESSAGE-----\n-----BEGIN PGP MESSAGE-----\n\ndat2\n-----END PGP MESSAGE-----")
.unwrap();
assert_eq!(typ, BlockType::Message);
assert!(!base64.is_empty());
let (typ, _headers, base64) = split_armored_data(
b"foo \n -----BEGIN PGP MESSAGE----- \n base64-123 \n -----END PGP MESSAGE-----",
)
.unwrap();
assert_eq!(typ, BlockType::Message);
assert!(!base64.is_empty());
assert!(split_armored_data(b"foo-----BEGIN PGP MESSAGE-----",).is_err());
#[test]
fn test_split_armored_data_2() {
let (typ, headers, base64) = split_armored_data(
b"foo \n -----BEGIN PGP MESSAGE-----\n Passphrase-BeGIN : 23 \n \n base64-567 \r\n abc \n -----END PGP MESSAGE-----\n\n\n",
)
.unwrap();
assert_eq!(typ, BlockType::Message);
assert!(!base64.is_empty());
assert_eq!(headers.get(HEADER_SETUPCODE), Some(&"23".to_string()));
let (typ, headers, base64) = split_armored_data(
b"-----BEGIN PGP PRIVATE KEY BLOCK-----\n Autocrypt-Prefer-Encrypt : mutual \n\nbase64\n-----END PGP PRIVATE KEY BLOCK-----"
b"-----BEGIN PGP PRIVATE KEY BLOCK-----\nAutocrypt-Prefer-Encrypt: mutual \n\nbase64\n-----END PGP PRIVATE KEY BLOCK-----"
)
.unwrap();