From 5b2406f647cc4c9a29518eeafe90d4548545f5f3 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Sat, 21 Dec 2024 22:03:31 -0500 Subject: [PATCH] Added a test case for parsing garbage mime-types in the Content-Type header --- UnitTests/ExperimentalMimeParserTests.cs | 18 ++++++++++-------- UnitTests/MimeParserTests.cs | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/UnitTests/ExperimentalMimeParserTests.cs b/UnitTests/ExperimentalMimeParserTests.cs index 6df5c0acc3..f78d33c912 100644 --- a/UnitTests/ExperimentalMimeParserTests.cs +++ b/UnitTests/ExperimentalMimeParserTests.cs @@ -819,8 +819,9 @@ public async Task TestEmptyMessageAsync () } } - [Test] - public void TestInvalidContentType () + [TestCase ("garbage")] + [TestCase ("!%^#&^!\\t ")] + public void TestInvalidContentType (string mimeType) { string text = @"From: mimekit@example.com To: mimekit@example.com @@ -829,10 +830,10 @@ public void TestInvalidContentType () MIME-Version: 1.0 Message-ID: <54AD68C9E3B0184CAC6041320424FD1B5B81E74D@localhost.localdomain> X-Mailer: Microsoft Office Outlook 12.0 -Content-Type: garbage; charset=utf-8 +Content-Type: ${mimeType}; charset=utf-8 This is the message body. -".Replace ("\r\n", "\n"); +".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n"); using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { var parser = new ExperimentalMimeParser (stream, MimeFormat.Entity); @@ -867,8 +868,9 @@ This is the message body. } } - [Test] - public async Task TestInvalidContentTypeAsync () + [TestCase ("garbage")] + [TestCase ("!%^#&^!\\t ")] + public async Task TestInvalidContentTypeAsync (string mimeType) { string text = @"From: mimekit@example.com To: mimekit@example.com @@ -877,10 +879,10 @@ public async Task TestInvalidContentTypeAsync () MIME-Version: 1.0 Message-ID: <54AD68C9E3B0184CAC6041320424FD1B5B81E74D@localhost.localdomain> X-Mailer: Microsoft Office Outlook 12.0 -Content-Type: garbage; charset=utf-8 +Content-Type: ${mimeType}; charset=utf-8 This is the message body. -".Replace ("\r\n", "\n"); +".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n"); using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { var parser = new ExperimentalMimeParser (stream, MimeFormat.Entity); diff --git a/UnitTests/MimeParserTests.cs b/UnitTests/MimeParserTests.cs index 09bd544636..4b002af3f3 100644 --- a/UnitTests/MimeParserTests.cs +++ b/UnitTests/MimeParserTests.cs @@ -833,8 +833,9 @@ public async Task TestEmptyMessageAsync () } } - [Test] - public void TestInvalidContentType () + [TestCase ("garbage")] + [TestCase ("!%^#&^!\\t ")] + public void TestInvalidContentType (string mimeType) { string text = @"From: mimekit@example.com To: mimekit@example.com @@ -843,10 +844,10 @@ public void TestInvalidContentType () MIME-Version: 1.0 Message-ID: <54AD68C9E3B0184CAC6041320424FD1B5B81E74D@localhost.localdomain> X-Mailer: Microsoft Office Outlook 12.0 -Content-Type: garbage; charset=utf-8 +Content-Type: ${mimeType}; charset=utf-8 This is the message body. -".Replace ("\r\n", "\n"); +".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n"); using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { var parser = new MimeParser (stream, MimeFormat.Entity); @@ -881,8 +882,9 @@ This is the message body. } } - [Test] - public async Task TestInvalidContentTypeAsync () + [TestCase ("garbage")] + [TestCase ("!%^#&^!\\t ")] + public async Task TestInvalidContentTypeAsync (string mimeType) { string text = @"From: mimekit@example.com To: mimekit@example.com @@ -891,10 +893,10 @@ public async Task TestInvalidContentTypeAsync () MIME-Version: 1.0 Message-ID: <54AD68C9E3B0184CAC6041320424FD1B5B81E74D@localhost.localdomain> X-Mailer: Microsoft Office Outlook 12.0 -Content-Type: garbage; charset=utf-8 +Content-Type: ${mimeType}; charset=utf-8 This is the message body. -".Replace ("\r\n", "\n"); +".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n"); using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) { var parser = new MimeParser (stream, MimeFormat.Entity);