From cc18aa39c15ffffdd622cb61c3c147c2bc1903aa Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Thu, 24 Jan 2019 13:14:50 +0100 Subject: tests: add more malformation tests to mailboxTest --- tests/parser/mailboxTest.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/parser/mailboxTest.cpp b/tests/parser/mailboxTest.cpp index 127bb422..a0d1b694 100644 --- a/tests/parser/mailboxTest.cpp +++ b/tests/parser/mailboxTest.cpp @@ -30,7 +30,7 @@ VMIME_TEST_SUITE_BEGIN(mailboxTest) VMIME_TEST(testParse) VMIME_TEST(testEmptyEmailAddress) VMIME_TEST(testSeparatorInComment) - VMIME_TEST(testAddressInName) + VMIME_TEST(testMalformations) VMIME_TEST_LIST_END @@ -146,13 +146,28 @@ VMIME_TEST_SUITE_BEGIN(mailboxTest) VASSERT_EQ("email2", "bbb@vmime.org", mbox2->getEmail()); } - void testAddressInName() { - + void testMalformations() { vmime::mailbox mbox; - mbox.parse("a@b.c "); + mbox.parse("a@b.c "); VASSERT_EQ("name", vmime::text("a@b.c"), mbox.getName()); VASSERT_EQ("email", "e@f.g", mbox.getEmail()); + + mbox.parse("a@b.c e@f.g "); + VASSERT_EQ("name", vmime::text("e@f.g"), mbox.getName()); + VASSERT_EQ("email", "h@i.j", mbox.getEmail()); + + mbox.parse("Foo "); + VASSERT_EQ("name", vmime::text("Foobar"), mbox.getName()); + VASSERT_EQ("email", "baz@quux.com", mbox.getEmail()); + + mbox.parse("Foo "); + VASSERT_EQ("name", vmime::text("Foo"), mbox.getName()); + VASSERT_EQ("email", "foo@x.com", mbox.getEmail()); + + mbox.parse("Foo Bar "); + VASSERT_EQ("name", vmime::text("Foo"), mbox.getName()); + VASSERT_EQ("email", "foo@x.com", mbox.getEmail()); } VMIME_TEST_SUITE_END -- cgit v1.2.3 From d1190b496faa754a757aba79f88dcd7e31d6d500 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Thu, 29 Nov 2018 21:25:47 +0100 Subject: Improve address parser for malformed mailbox specifications Spammers use "Name " to trick some parsers. My expectations as to what the outcome should be is presented in the updated mailboxTest.cpp. The DFA in mailbox::parseImpl is hereby redone so as to pick the rightmost address-looking portion as the address, rather than something in between. While doing so, it will also no longer mangle the name part anymore (it does this by keeping a "as_if_name" variable around until the end). --- tests/parser/mailboxTest.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/parser/mailboxTest.cpp b/tests/parser/mailboxTest.cpp index a0d1b694..23d1b4ac 100644 --- a/tests/parser/mailboxTest.cpp +++ b/tests/parser/mailboxTest.cpp @@ -154,20 +154,20 @@ VMIME_TEST_SUITE_BEGIN(mailboxTest) VASSERT_EQ("email", "e@f.g", mbox.getEmail()); mbox.parse("a@b.c e@f.g "); - VASSERT_EQ("name", vmime::text("e@f.g"), mbox.getName()); + VASSERT_EQ("name", vmime::text("a@b.c e@f.g"), mbox.getName()); VASSERT_EQ("email", "h@i.j", mbox.getEmail()); mbox.parse("Foo "); - VASSERT_EQ("name", vmime::text("Foobar"), mbox.getName()); + VASSERT_EQ("name", vmime::text("Foo "); - VASSERT_EQ("name", vmime::text("Foo"), mbox.getName()); - VASSERT_EQ("email", "foo@x.com", mbox.getEmail()); + VASSERT_EQ("name", vmime::text("Foo "), mbox.getName()); + VASSERT_EQ("email", "bar@x.com", mbox.getEmail()); mbox.parse("Foo Bar "); - VASSERT_EQ("name", vmime::text("Foo"), mbox.getName()); - VASSERT_EQ("email", "foo@x.com", mbox.getEmail()); + VASSERT_EQ("name", vmime::text("Foo Bar"), mbox.getName()); + VASSERT_EQ("email", "bar@y.com", mbox.getEmail()); } VMIME_TEST_SUITE_END -- cgit v1.2.3