forked from Silverfish/proton-bridge
test: add tests for parsing mime message with bad 2231 filename
This commit is contained in:
@ -271,6 +271,44 @@ func TestParseMessageTextPlainWithOctetAttachment(t *testing.T) {
|
|||||||
assert.Equal(t, readerToString(atts[0]), "if you are reading this, hi!")
|
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) {
|
func TestParseMessageTextPlainWithPlainAttachment(t *testing.T) {
|
||||||
f := f("text_plain_plain_attachment.eml")
|
f := f("text_plain_plain_attachment.eml")
|
||||||
defer func() { _ = f.Close() }()
|
defer func() { _ = f.Close() }()
|
||||||
|
|||||||
14
pkg/message/testdata/text_plain_octet_attachment_bad_2231_filename.eml
vendored
Normal file
14
pkg/message/testdata/text_plain_octet_attachment_bad_2231_filename.eml
vendored
Normal 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--
|
||||||
18
pkg/message/testdata/text_plain_octet_attachment_bad_2231_filename.mime
vendored
Normal file
18
pkg/message/testdata/text_plain_octet_attachment_bad_2231_filename.mime
vendored
Normal 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--
|
||||||
|
.
|
||||||
14
pkg/message/testdata/text_plain_octet_attachment_good_2231_filename.eml
vendored
Normal file
14
pkg/message/testdata/text_plain_octet_attachment_good_2231_filename.eml
vendored
Normal 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--
|
||||||
18
pkg/message/testdata/text_plain_octet_attachment_good_2231_filename.mime
vendored
Normal file
18
pkg/message/testdata/text_plain_octet_attachment_good_2231_filename.mime
vendored
Normal 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--
|
||||||
|
.
|
||||||
Reference in New Issue
Block a user