comparison 3rdparty/vmime/tests/net/imap/IMAPParserTest.cpp @ 0:a4671277546c tip

created the repository for the thymian project
author ferencd
date Tue, 17 Aug 2021 11:19:54 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:a4671277546c
1 //
2 // VMime library (http://www.vmime.org)
3 // Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 3 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // Linking this library statically or dynamically with other modules is making
20 // a combined work based on this library. Thus, the terms and conditions of
21 // the GNU General Public License cover the whole combination.
22 //
23
24 #include "tests/testUtils.hpp"
25
26 #include "vmime/net/imap/IMAPTag.hpp"
27 #include "vmime/net/imap/IMAPParser.hpp"
28
29
30 VMIME_TEST_SUITE_BEGIN(IMAPParserTest)
31
32 VMIME_TEST_LIST_BEGIN
33 VMIME_TEST(testExtraSpaceInCapaResponse)
34 VMIME_TEST(testContinueReqWithoutSpace)
35 VMIME_TEST(testNILValueInBodyFldEnc)
36 VMIME_TEST_LIST_END
37
38
39 // For Apple iCloud IMAP server
40 void testExtraSpaceInCapaResponse()
41 {
42 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
43 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
44
45 vmime::shared_ptr <vmime::net::imap::IMAPTag> tag =
46 vmime::make_shared <vmime::net::imap::IMAPTag>();
47
48 socket->localSend(
49 "* CAPABILITY IMAP4rev1 AUTH=ATOKEN AUTH=PLAIN \r\n" // extra space at end
50 "a001 OK Capability completed.\r\n");
51
52 vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
53 vmime::make_shared <vmime::net::imap::IMAPParser>();
54
55 parser->setTag(tag);
56 parser->setSocket(socket);
57 parser->setTimeoutHandler(toh);
58
59 parser->setStrict(false);
60 VASSERT_NO_THROW("non-strict mode", parser->readResponse(/* literalHandler */ NULL));
61
62 ++(*tag);
63
64 socket->localSend(
65 "* CAPABILITY IMAP4rev1 AUTH=ATOKEN AUTH=PLAIN \r\n" // extra space at end
66 "a002 OK Capability completed.\r\n");
67
68 parser->setStrict(true);
69 VASSERT_THROW("strict mode", parser->readResponse(/* literalHandler */ NULL), vmime::exceptions::invalid_response);
70 }
71
72 // For Apple iCloud/Exchange IMAP server
73 void testContinueReqWithoutSpace()
74 {
75 // continue_req ::= "+" SPACE (resp_text / base64)
76 //
77 // Some servers do not send SPACE when response text is empty.
78 // IMAP parser should allow this in non-strict mode.
79 //
80 // Eg:
81 //
82 // C: a002 AUTHENTICATE xxx[CR][LF]
83 // S: +[CR][LF]
84
85 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
86 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
87
88 vmime::shared_ptr <vmime::net::imap::IMAPTag> tag =
89 vmime::make_shared <vmime::net::imap::IMAPTag>();
90
91 socket->localSend("+\r\n");
92
93 vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
94 vmime::make_shared <vmime::net::imap::IMAPParser>();
95
96 parser->setTag(tag);
97 parser->setSocket(socket);
98 parser->setTimeoutHandler(toh);
99
100 parser->setStrict(false);
101 VASSERT_NO_THROW("non-strict mode", parser->readResponse());
102
103 ++(*tag);
104
105 socket->localSend("+\r\n");
106
107 parser->setStrict(true);
108 VASSERT_THROW("strict mode", parser->readResponse(), vmime::exceptions::invalid_response);
109 }
110
111 // When an IMAP4 client sends a FETCH (bodystructure) request to a server
112 // that is running the Exchange Server 2007 IMAP4 service, a corrupted
113 // response is sent as a reply
114 // --> http://support.microsoft.com/kb/975918/en-us
115 void testNILValueInBodyFldEnc()
116 {
117 vmime::shared_ptr <testSocket> socket = vmime::make_shared <testSocket>();
118 vmime::shared_ptr <vmime::net::timeoutHandler> toh = vmime::make_shared <testTimeoutHandler>();
119
120 vmime::shared_ptr <vmime::net::imap::IMAPTag> tag =
121 vmime::make_shared <vmime::net::imap::IMAPTag>();
122
123 const char* resp = "* 7970 FETCH (UID 8036 FLAGS () BODYSTRUCTURE (\"text\" \"html\" (\"charset\" \"utf-8\") NIL NIL NIL 175501 1651 NIL NIL NIL NIL) RFC822.HEADER {3}\r\nx\r\n)\r\na001 OK FETCH complete\r\n";
124
125 socket->localSend(resp);
126
127 vmime::shared_ptr <vmime::net::imap::IMAPParser> parser =
128 vmime::make_shared <vmime::net::imap::IMAPParser>();
129
130 parser->setTag(tag);
131 parser->setSocket(socket);
132 parser->setTimeoutHandler(toh);
133
134 parser->setStrict(false);
135 VASSERT_NO_THROW("non-strict mode", parser->readResponse());
136
137 ++(*tag);
138
139 socket->localSend(resp);
140
141 parser->setStrict(true);
142 VASSERT_THROW("strict mode", parser->readResponse(), vmime::exceptions::invalid_response);
143 }
144
145 VMIME_TEST_SUITE_END