test: add tests for parsing mime message with bad 2231 filename

This commit is contained in:
James Houlahan
2020-07-03 09:19:18 +02:00
parent 35ae2011b6
commit 10e384f4df
5 changed files with 102 additions and 0 deletions

View File

@ -271,6 +271,44 @@ func TestParseMessageTextPlainWithOctetAttachment(t *testing.T) {
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
}
func TestParseMessageTextPlainWithOctetAttachmentGoodFilename(t *testing.T) {
f := f("text_plain_octet_attachment_good_2231_filename.eml")
defer func() { _ = f.Close() }()
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_octet_attachment_good_2231_filename.mime"), mimeBody)
assert.Equal(t, "body", plainContents)
assert.Len(t, atts, 1)
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
assert.Equal(t, "😁😂.txt", m.Attachments[0].Name)
}
func TestParseMessageTextPlainWithOctetAttachmentBadFilename(t *testing.T) {
f := f("text_plain_octet_attachment_bad_2231_filename.eml")
defer func() { _ = f.Close() }()
m, mimeBody, plainContents, atts, err := Parse(f, "", "")
assert.NoError(t, err)
assert.Equal(t, `"Sender" <sender@pm.me>`, m.Sender.String())
assert.Equal(t, `"Receiver" <receiver@pm.me>`, m.ToList[0].String())
assert.Equal(t, "body", m.Body)
assert.Equal(t, s("text_plain_octet_attachment_bad_2231_filename.mime"), mimeBody)
assert.Equal(t, "body", plainContents)
assert.Len(t, atts, 1)
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
assert.Equal(t, "attachment.bin", m.Attachments[0].Name)
}
func TestParseMessageTextPlainWithPlainAttachment(t *testing.T) {
f := f("text_plain_plain_attachment.eml")
defer func() { _ = f.Close() }()

View File

@ -0,0 +1,14 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
--longrandomstring
body
--longrandomstring
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename*=utf-8'%F0%9F%98%81%F0%9F%98%82.txt
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--

View File

@ -0,0 +1,18 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Transfer-Encoding: quoted-printable
body
--longrandomstring
Content-Disposition: attachment; filename*=utf-8'%F0%9F%98%81%F0%9F%98%82.txt
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--
.

View File

@ -0,0 +1,14 @@
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
Content-Type: multipart/mixed; boundary=longrandomstring
--longrandomstring
body
--longrandomstring
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename*=utf-8''%F0%9F%98%81%F0%9F%98%82.txt
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--

View File

@ -0,0 +1,18 @@
Content-Type: multipart/mixed; boundary=longrandomstring
From: Sender <sender@pm.me>
To: Receiver <receiver@pm.me>
This is a multi-part message in MIME format.
--longrandomstring
Content-Transfer-Encoding: quoted-printable
body
--longrandomstring
Content-Disposition: attachment; filename*=utf-8''%F0%9F%98%81%F0%9F%98%82.txt
Content-Transfer-Encoding: base64
Content-Type: application/octet-stream
aWYgeW91IGFyZSByZWFkaW5nIHRoaXMsIGhpIQ==
--longrandomstring--
.