Skip to content

Commit

Permalink
Added a test case for parsing garbage mime-types in the Content-Type …
Browse files Browse the repository at this point in the history
…header
  • Loading branch information
jstedfast committed Dec 22, 2024
1 parent 77a9788 commit 5b2406f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
18 changes: 10 additions & 8 deletions UnitTests/ExperimentalMimeParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down
18 changes: 10 additions & 8 deletions UnitTests/MimeParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down

0 comments on commit 5b2406f

Please sign in to comment.