|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "ctestimapauthenticate.h" |
|
17 #include "msvtestutilsbase.h" |
|
18 |
|
19 #include "cfakeinputstream.h" |
|
20 #include "cfakeoutputstream.h" |
|
21 #include "cactivewaiter.h" |
|
22 #include "emailtestutils.h" |
|
23 #include <iapprefs.h> |
|
24 |
|
25 #include "moutputstream.h" |
|
26 #include "cimapsession.h" |
|
27 #include "cimaplistfolderinfo.h" |
|
28 #include "cimaputils.h" |
|
29 #include "cimapfolderinfo.h" |
|
30 #include "cimapmailstore.h" |
|
31 CMsvServer *server; |
|
32 |
|
33 _LIT( KLoopbackAddress, "127.0.0.1" ); |
|
34 _LIT(KCDrive,"c:\\"); |
|
35 _LIT(KImapauth,"t_ctestimapauthenticate"); |
|
36 |
|
37 RTest test1(KImapauth); |
|
38 CTestImapAuthenticate::CTestImapAuthenticate() |
|
39 : iInputStream(NULL) |
|
40 , iOutputStream(NULL) |
|
41 , iActiveWaiter(NULL) |
|
42 , iImapSession(NULL) |
|
43 ,iImapSettings(NULL) |
|
44 ,iEntry(NULL) |
|
45 ,iMsvServer(NULL) |
|
46 ,iAccounts(NULL) |
|
47 {} |
|
48 |
|
49 CTestImapAuthenticate::~CTestImapAuthenticate() |
|
50 { |
|
51 |
|
52 delete iAccounts; |
|
53 delete iImapSettings; |
|
54 delete iActiveWaiter; |
|
55 delete iImapSession; |
|
56 delete iOutputStream; |
|
57 delete iInputStream; |
|
58 CImapUtils::Delete(); |
|
59 } |
|
60 |
|
61 //DO the initial setup |
|
62 |
|
63 void CTestImapAuthenticate::SetupL() |
|
64 { |
|
65 ASSERT(iInputStream == NULL); |
|
66 ASSERT(iOutputStream == NULL); |
|
67 ASSERT(iActiveWaiter == NULL); |
|
68 ASSERT(iImapSession == NULL); |
|
69 ASSERT(iMsvServer == NULL); |
|
70 |
|
71 //clear the messaging folder |
|
72 CEmailTestUtils* testUtils; |
|
73 testUtils = CEmailTestUtils::NewL(test1); |
|
74 CleanupStack::PushL(testUtils); |
|
75 testUtils->FileSession().SetSessionPath(KCDrive); |
|
76 testUtils->ClearEmailAccountsL(); |
|
77 // TODO: How to clean the message folders or close the messaging server without a PANIC ???? |
|
78 |
|
79 // iTestUtils->CleanMessageFolderL( ); |
|
80 |
|
81 testUtils->CreateAllTestDirectories( ); |
|
82 testUtils->FileSession( ).SetSessionPath( _L( "C:\\" ) ); |
|
83 |
|
84 |
|
85 testUtils->GoServerSideL( ); |
|
86 testUtils->InstantiateImapServerMtmL( ); |
|
87 iImapServerMtm = testUtils->iImapServerMtm; |
|
88 |
|
89 // Create an account |
|
90 testUtils->GoClientSideL( ); |
|
91 iAccounts = CEmailAccounts::NewL( ); |
|
92 DoCreateImapAccountL( ); |
|
93 |
|
94 delete iAccounts; |
|
95 iAccounts = NULL; |
|
96 |
|
97 testUtils->GoServerSideL( ); |
|
98 |
|
99 iEntry = testUtils->iServerEntry; |
|
100 |
|
101 iServiceId = iImapAccount.iImapService; |
|
102 testUtils->InstantiateImapServerMtmL( ); |
|
103 iImapServerMtm = testUtils->iImapServerMtm; |
|
104 |
|
105 |
|
106 CImapUtils::CreateL(); |
|
107 iImapMailStore = CImapMailStore::NewL(*iEntry); |
|
108 iImapSettings = CImapSettings::NewL(*iEntry); |
|
109 |
|
110 iInputStream = CFakeInputStream::NewL(Logger()); |
|
111 iOutputStream = CFakeOutputStream::NewL(Logger()); |
|
112 iActiveWaiter = new(ELeave)CActiveWaiter(Logger()); |
|
113 iImapSession = CImapSession::NewL(*iImapSettings,*iImapMailStore,*iInputStream, *iOutputStream); |
|
114 |
|
115 iImapSettings->LoadSettingsL(iServiceId); |
|
116 |
|
117 |
|
118 |
|
119 INFO_PRINTF1(_L("Setup: ServerGreeting")); |
|
120 iInputStream->ResetInputStrings(); |
|
121 iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n")); |
|
122 |
|
123 ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState()); |
|
124 |
|
125 iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus); |
|
126 iActiveWaiter->WaitActive(); |
|
127 |
|
128 |
|
129 CleanupStack::PopAndDestroy(testUtils); |
|
130 } |
|
131 |
|
132 void CTestImapAuthenticate::TearDownL() |
|
133 { |
|
134 delete iImapSession; |
|
135 iImapSession = NULL; |
|
136 |
|
137 delete iActiveWaiter; |
|
138 iActiveWaiter = NULL; |
|
139 |
|
140 delete iOutputStream; |
|
141 iOutputStream = NULL; |
|
142 |
|
143 delete iInputStream; |
|
144 iInputStream = NULL; |
|
145 |
|
146 |
|
147 delete iImapMailStore; |
|
148 iImapMailStore = NULL; |
|
149 |
|
150 delete iAccounts; |
|
151 iAccounts = NULL; |
|
152 |
|
153 delete iImapSettings; |
|
154 iImapSettings = NULL; |
|
155 |
|
156 CImapUtils::Delete(); |
|
157 |
|
158 |
|
159 } |
|
160 |
|
161 // //Test authenticate CramMd5 |
|
162 |
|
163 void CTestImapAuthenticate::TestAuthwithCramMd5L() |
|
164 { |
|
165 INFO_PRINTF1(_L("TestAuthwithCramMd5")); |
|
166 |
|
167 iInputStream->AppendInputStringL(_L8("* CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR STARTTLS AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=GSSAPI AUTH=MSN AUTH=NTLM \r\n")); |
|
168 iInputStream->AppendInputStringL(_L8("1 OK CAPABILITY completed\r\n")); |
|
169 |
|
170 iImapSession->CapabilityL(iActiveWaiter->iStatus); |
|
171 iActiveWaiter->WaitActive(); |
|
172 iInputStream->AppendInputStringL(_L8("+ PDExLjEyMjcwMDgxNTBAZDA3MDA0MS5wcm9kLmFkLnN5bWJpYW4uaW50cmE\r\n")); |
|
173 iInputStream->AppendInputStringL(_L8("2 OK completed\r\n")); |
|
174 |
|
175 |
|
176 |
|
177 iImapSession->AuthenticateL(iActiveWaiter->iStatus,CImapAuthMechanismHelper::ECramMD5); |
|
178 |
|
179 iActiveWaiter->WaitActive(); |
|
180 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
181 |
|
182 INFO_PRINTF1(_L("Complete")); |
|
183 } |
|
184 |
|
185 //Test authenticate PLAIN |
|
186 void CTestImapAuthenticate::TestAuthwithPlainL() |
|
187 { |
|
188 INFO_PRINTF1(_L("TestAuthwithPlain")); |
|
189 |
|
190 iInputStream->AppendInputStringL(_L8("* CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR STARTTLS AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=GSSAPI AUTH=MSN AUTH=NTLM \r\n")); |
|
191 iInputStream->AppendInputStringL(_L8("1 OK CAPABILITY completed\r\n")); |
|
192 |
|
193 iImapSession->CapabilityL(iActiveWaiter->iStatus); |
|
194 iActiveWaiter->WaitActive(); |
|
195 |
|
196 iInputStream->AppendInputStringL(_L8("2 OK completed\r\n")); |
|
197 |
|
198 iImapSession->AuthenticateL(iActiveWaiter->iStatus,CImapAuthMechanismHelper::EPlain); |
|
199 iActiveWaiter->WaitActive(); |
|
200 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
201 |
|
202 INFO_PRINTF1(_L("Complete")); |
|
203 } |
|
204 |
|
205 |
|
206 // //Test authenticate Login |
|
207 |
|
208 void CTestImapAuthenticate::TestAuthwithLoginL() |
|
209 { |
|
210 INFO_PRINTF1(_L("TestAuthwithLogin")); |
|
211 |
|
212 iInputStream->AppendInputStringL(_L8("* CAPABILITY IMAP4 IMAP4REV1 ACL NAMESPACE UIDPLUS IDLE LITERAL+ QUOTA ID MULTIAPPEND LISTEXT CHILDREN BINARY ESEARCH LOGIN-REFERRALS UNSELECT SASL-IR STARTTLS AUTH=LOGIN AUTH=PLAIN AUTH=CRAM-MD5 AUTH=DIGEST-MD5 AUTH=GSSAPI AUTH=MSN AUTH=NTLM \r\n")); |
|
213 iInputStream->AppendInputStringL(_L8("1 OK CAPABILITY completed\r\n")); |
|
214 |
|
215 iImapSession->CapabilityL(iActiveWaiter->iStatus); |
|
216 iActiveWaiter->WaitActive(); |
|
217 |
|
218 |
|
219 iInputStream->AppendInputStringL(_L8("+ VXNlcm5hbWU6\r\n")); |
|
220 iInputStream->AppendInputStringL(_L8("+ UGFzc3dvcmQ6\r\n")); |
|
221 iInputStream->AppendInputStringL(_L8("2 OK completed\r\n")); |
|
222 |
|
223 |
|
224 iImapSession->AuthenticateL(iActiveWaiter->iStatus,CImapAuthMechanismHelper::ELogin); |
|
225 |
|
226 iActiveWaiter->WaitActive(); |
|
227 ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState()); |
|
228 |
|
229 INFO_PRINTF1(_L("Complete")); |
|
230 |
|
231 } |
|
232 //Create IMAP account |
|
233 void CTestImapAuthenticate::DoCreateImapAccountL( ) |
|
234 { |
|
235 INFO_PRINTF1( _L("Create IMAP account") ); |
|
236 |
|
237 //create objects and initialise with the defaults |
|
238 CImImap4Settings* imap4Settings = new ( ELeave ) CImImap4Settings; |
|
239 CleanupStack::PushL( imap4Settings ); |
|
240 |
|
241 CImSmtpSettings* smtpSettings = new ( ELeave ) CImSmtpSettings; |
|
242 CleanupStack::PushL( smtpSettings ); |
|
243 |
|
244 CImIAPPreferences* imapIap = CImIAPPreferences::NewLC( ); |
|
245 |
|
246 //override some of the defaults |
|
247 imap4Settings->SetPasswordL( _L8( "d70041" ) ); |
|
248 imap4Settings->SetLoginNameL( _L8( "d70041" ) ); |
|
249 imap4Settings->SetServerAddressL( KLoopbackAddress ); |
|
250 imap4Settings->SetFolderPathL( _L8( "" ) ); |
|
251 |
|
252 //create the account |
|
253 iImapAccount = iAccounts->CreateImapAccountL( _L( "TestAccount" ), *imap4Settings, *imapIap, EFalse ); |
|
254 //clean up |
|
255 CleanupStack::PopAndDestroy( 3,imap4Settings ); |
|
256 |
|
257 INFO_PRINTF1( _L("IMAP account created") ); |
|
258 } |
|
259 |
|
260 //Create Test suite |
|
261 CTestSuite* CTestImapAuthenticate::CreateSuiteL(const TDesC& aName) |
|
262 // static |
|
263 { |
|
264 SUB_SUITE; |
|
265 ADD_ASYNC_TEST_STEP(TestAuthwithCramMd5L); |
|
266 ADD_ASYNC_TEST_STEP(TestAuthwithPlainL); |
|
267 ADD_ASYNC_TEST_STEP(TestAuthwithLoginL); |
|
268 END_SUITE; |
|
269 } |