From fd3aed5cf3fb1c75aa843c01b805eb6cd00d8360 Mon Sep 17 00:00:00 2001 From: Quentin Retourne <32574188+nitneuqr@users.noreply.github.com> Date: Tue, 17 Sep 2024 20:51:57 +0200 Subject: [PATCH] added tests for smime_decnonicalize --- src/rust/src/pkcs7.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/rust/src/pkcs7.rs b/src/rust/src/pkcs7.rs index de7d46e1ddd8..16e7d01642d3 100644 --- a/src/rust/src/pkcs7.rs +++ b/src/rust/src/pkcs7.rs @@ -662,7 +662,7 @@ mod tests { use std::borrow::Cow; use std::ops::Deref; - use super::smime_canonicalize; + use super::{smime_canonicalize, smime_decanonicalize}; #[test] fn test_smime_canonicalize() { @@ -722,4 +722,32 @@ mod tests { ); } } + + #[test] + fn test_smime_decanonicalize() { + for (input, text_mode, expected_output) in [ + // Values with text_mode=false + (b"" as &[u8], false, b"" as &[u8]), + (b"abc\r\n", false, b"abc\n"), + (b"\r\nabc\n", false, b"\nabc\n"), + (b"abc\r\ndef\r\n", false, b"abc\ndef\n"), + (b"abc\r\ndef\nabc", false, b"abc\ndef\nabc"), + // Values with text_mode=true + (b"Content-Type: text/plain\r\n\r\n", true, b""), + (b"Content-Type: text/plain\r\n\r\nabc", true, b"abc"), + ( + b"Content-Type: text/plain\r\n\r\nabc\r\ndef\r\n", + true, + b"abc\ndef\n", + ), + ( + b"Content-Type: text/plain\r\n\r\nabc\r\ndef\nabc", + true, + b"abc\ndef\nabc", + ), + ] { + let result = smime_decanonicalize(input, text_mode); + assert_eq!(result.deref(), expected_output); + } + } }