Skip to content

Commit 5b2406f

Browse files
committed
Added a test case for parsing garbage mime-types in the Content-Type header
1 parent 77a9788 commit 5b2406f

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

UnitTests/ExperimentalMimeParserTests.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -819,8 +819,9 @@ public async Task TestEmptyMessageAsync ()
819819
}
820820
}
821821

822-
[Test]
823-
public void TestInvalidContentType ()
822+
[TestCase ("garbage")]
823+
[TestCase ("!%^#&^!\\t ")]
824+
public void TestInvalidContentType (string mimeType)
824825
{
825826
string text = @"From: [email protected]
826827
@@ -829,10 +830,10 @@ public void TestInvalidContentType ()
829830
MIME-Version: 1.0
830831
Message-ID: <[email protected]>
831832
X-Mailer: Microsoft Office Outlook 12.0
832-
Content-Type: garbage; charset=utf-8
833+
Content-Type: ${mimeType}; charset=utf-8
833834
834835
This is the message body.
835-
".Replace ("\r\n", "\n");
836+
".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n");
836837

837838
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
838839
var parser = new ExperimentalMimeParser (stream, MimeFormat.Entity);
@@ -867,8 +868,9 @@ This is the message body.
867868
}
868869
}
869870

870-
[Test]
871-
public async Task TestInvalidContentTypeAsync ()
871+
[TestCase ("garbage")]
872+
[TestCase ("!%^#&^!\\t ")]
873+
public async Task TestInvalidContentTypeAsync (string mimeType)
872874
{
873875
string text = @"From: [email protected]
874876
@@ -877,10 +879,10 @@ public async Task TestInvalidContentTypeAsync ()
877879
MIME-Version: 1.0
878880
Message-ID: <[email protected]>
879881
X-Mailer: Microsoft Office Outlook 12.0
880-
Content-Type: garbage; charset=utf-8
882+
Content-Type: ${mimeType}; charset=utf-8
881883
882884
This is the message body.
883-
".Replace ("\r\n", "\n");
885+
".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n");
884886

885887
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
886888
var parser = new ExperimentalMimeParser (stream, MimeFormat.Entity);

UnitTests/MimeParserTests.cs

+10-8
Original file line numberDiff line numberDiff line change
@@ -833,8 +833,9 @@ public async Task TestEmptyMessageAsync ()
833833
}
834834
}
835835

836-
[Test]
837-
public void TestInvalidContentType ()
836+
[TestCase ("garbage")]
837+
[TestCase ("!%^#&^!\\t ")]
838+
public void TestInvalidContentType (string mimeType)
838839
{
839840
string text = @"From: [email protected]
840841
@@ -843,10 +844,10 @@ public void TestInvalidContentType ()
843844
MIME-Version: 1.0
844845
Message-ID: <[email protected]>
845846
X-Mailer: Microsoft Office Outlook 12.0
846-
Content-Type: garbage; charset=utf-8
847+
Content-Type: ${mimeType}; charset=utf-8
847848
848849
This is the message body.
849-
".Replace ("\r\n", "\n");
850+
".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n");
850851

851852
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
852853
var parser = new MimeParser (stream, MimeFormat.Entity);
@@ -881,8 +882,9 @@ This is the message body.
881882
}
882883
}
883884

884-
[Test]
885-
public async Task TestInvalidContentTypeAsync ()
885+
[TestCase ("garbage")]
886+
[TestCase ("!%^#&^!\\t ")]
887+
public async Task TestInvalidContentTypeAsync (string mimeType)
886888
{
887889
string text = @"From: [email protected]
888890
@@ -891,10 +893,10 @@ public async Task TestInvalidContentTypeAsync ()
891893
MIME-Version: 1.0
892894
Message-ID: <[email protected]>
893895
X-Mailer: Microsoft Office Outlook 12.0
894-
Content-Type: garbage; charset=utf-8
896+
Content-Type: ${mimeType}; charset=utf-8
895897
896898
This is the message body.
897-
".Replace ("\r\n", "\n");
899+
".Replace ("${mimeType}", mimeType).Replace ("\r\n", "\n");
898900

899901
using (var stream = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
900902
var parser = new MimeParser (stream, MimeFormat.Entity);

0 commit comments

Comments
 (0)