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

create-reload-action
James Houlahan 6 years ago
parent 35ae2011b6
commit 10e384f4df
  1. 38
      pkg/message/parser_test.go
  2. 14
      pkg/message/testdata/text_plain_octet_attachment_bad_2231_filename.eml
  3. 18
      pkg/message/testdata/text_plain_octet_attachment_bad_2231_filename.mime
  4. 14
      pkg/message/testdata/text_plain_octet_attachment_good_2231_filename.eml
  5. 18
      pkg/message/testdata/text_plain_octet_attachment_good_2231_filename.mime

@ -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() }()

@ -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--

@ -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--
.

@ -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--

@ -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--
.
Loading…
Cancel
Save