|
1 // Copyright (c) 2001-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 // Brief description of test harness: |
|
15 // Tests SMTP AUTH functionality in SMTS |
|
16 // Input files required to run test harness: |
|
17 // The following files should be copied to <drive>:\msgtest\smts\scripts |
|
18 // imsk25_tls_no_smtp_auth_on_server.scr |
|
19 // imsk25_tls_no_smtp_auth.scr |
|
20 // imsk25_tls_login.scr |
|
21 // imsk25_no_tls_wrong_username.scr |
|
22 // imsk25_no_tls_wrong_password.scr |
|
23 // imsk25_no_tls_plain.scr |
|
24 // imsk25_no_tls_login.scr |
|
25 // imsk25_no_tls_cram_md5.scr |
|
26 // imsk25_no_tls_no_smtp_auth_on_server.scr |
|
27 // Output files produced by running test harness: |
|
28 // <DRIVE>:\msglogs\T_SMTSSMTPAUTH.<PLATFORM>.<VARIANT>.LOG.txt |
|
29 // Description of how to build test harness: |
|
30 // cd \messaging\msg\smts\ |
|
31 // bldmake bldfiles |
|
32 // abld test build t_SMTSSMTPAUTH |
|
33 // Description of how to run test harness: |
|
34 // The following instructions are the same for all platforms: |
|
35 // 2. Build the test utilities: |
|
36 // cd \messaging\msg\testutils\group\ |
|
37 // bldmake bldfiles |
|
38 // abld build |
|
39 // WINS running instructions: |
|
40 // 1. \epoc32\release\wins\<VARIANT>\t_SMTSSMTPAUTH.exe can be used at the command prompt |
|
41 // or executable can be run from Windows Explorer. |
|
42 // All other platform running instructions: |
|
43 // 1. Copy \epoc32\release\<PLATFORM>\<VARIANT>\t_SMTSSMTPAUTH.exe onto the other platform |
|
44 // 2. Copy \epoc32\release\<PLATFORM>\<VARIANT>\MSVTESTUTILS.DLL into |
|
45 // <DRIVE>:\system\libs on the other platform |
|
46 // 3. Copy \epoc32\release\<PLATFORM>\<VARIANT>\EMAILTESTUTILS.DLL into |
|
47 // <DRIVE>:\system\libs on the other platform |
|
48 // 4. Copy \epoc32\wins\c\msgtest\smts\scripts\*.scr to |
|
49 // <DRIVE>:\msgtest\smts\scripts\ |
|
50 // Note that this drive should be a CF card as the test files are large |
|
51 // 5. Run t_SMTSSMTPAUTH.exe on the other platform with the CF card |
|
52 // Once the test is run, run logtoscr from the command prompt. This will generate a number of .out |
|
53 // files in the c:\logs\email directory of the environment you are using. To check the test have |
|
54 // completed correctly compare these files with the files of the same name in the |
|
55 // c:\msgtest\smts\checkagainst directory. |
|
56 // // Note : For dial up tests do the following: |
|
57 // 1) The server names used in function ResetSettingsL() are dummy |
|
58 // Need to use right server names for testing for dial up testing. |
|
59 // However,they have been tested by giving the right server names. |
|
60 // 2) Uncomment the line "testUtils->DeleteScriptFilesFromLogsDirL()" |
|
61 // in function RunTestL(). |
|
62 // |
|
63 // |
|
64 |
|
65 #include "emailtestutils.h" |
|
66 #include "scripttestutils.h" |
|
67 #include <cemailaccounts.h> |
|
68 |
|
69 // For loading the serial comms device drivers |
|
70 #if defined (__WINS__) |
|
71 #define PDD_NAME _L("ECDRV") |
|
72 #define LDD_NAME _L("ECOMM") |
|
73 #else |
|
74 #define PDD_NAME _L("EUART1") |
|
75 #define LDD_NAME _L("ECOMM") |
|
76 #endif |
|
77 |
|
78 _LIT(KSmtsTest, "Testing SMTS smtp authentication with script files"); |
|
79 _LIT(KSmtsComponent,"SMTS"); |
|
80 |
|
81 // Script Files for the Tests |
|
82 |
|
83 _LIT(KTest3ScriptFile, "scripts\\imsk25_tls_login.scr"); |
|
84 _LIT(KTest3Desc, "Tls should handshake, Authentication takes place using Login Mechanism."); |
|
85 _LIT(KTest3Result, "Mail is sent."); |
|
86 |
|
87 _LIT(KTest4ScriptFile, "scripts\\imsk25_no_tls_wrong_username.scr"); |
|
88 _LIT(KTest4Desc, "No Tls, Wrong username used "); |
|
89 _LIT(KTest4Result, "Mail is sent."); |
|
90 |
|
91 _LIT(KTest5ScriptFile, "scripts\\imsk25_no_tls_wrong_password.scr"); |
|
92 _LIT(KTest5Desc, "No Tls, Wrong password used"); |
|
93 _LIT(KTest5Result, "Mail is sent."); |
|
94 |
|
95 _LIT(KTest6ScriptFile, "scripts\\imsk25_no_tls_plain.scr"); |
|
96 _LIT(KTest6Desc, "No Tls, authenticates using Plain Mechanism."); |
|
97 _LIT(KTest6Result, "Mail is sent."); |
|
98 |
|
99 _LIT(KTest7ScriptFile, "scripts\\imsk25_no_tls_login.scr"); |
|
100 _LIT(KTest7Desc, "No Tls, authenticates using Login Mechanism"); |
|
101 _LIT(KTest7Result, "Mail is sent."); |
|
102 |
|
103 _LIT(KTest8ScriptFile, "scripts\\imsk25_no_tls_cram_md5.scr"); |
|
104 _LIT(KTest8Desc, "No Tls, authenticates using CRAM-MD5 Mechanism."); |
|
105 _LIT(KTest8Result, "Mail is sent."); |
|
106 |
|
107 _LIT(KTest9ScriptFile, "scripts\\imsk25_no_tls_no_smtp_auth_on_server.scr"); |
|
108 _LIT(KTest9Desc, "No Tls, No AUTH command sent from Server."); |
|
109 _LIT(KTest9Result, "Mail is sent."); |
|
110 |
|
111 _LIT(KTest10ScriptFile, "scripts\\imsk25_ehlo_fail_conitnue_with_helo.scr"); |
|
112 _LIT(KTest10Desc, "Smtp Auth with EHLO fail, Tls Off, Continue with HELO Command"); |
|
113 _LIT(KTest10Result, "Mail is sent."); |
|
114 |
|
115 _LIT(KTest11ScriptFile, "scripts\\imsk25_ehlo_fail_quit_if_tls_on.scr"); |
|
116 _LIT(KTest11Desc, "Smtp Auth with EHLO fail, Quit if TLS on"); |
|
117 _LIT(KTest11Result, "Mail is not sent."); |
|
118 |
|
119 _LIT(KTest12ScriptFile, "scripts\\imsk25_tls_cram.scr"); |
|
120 _LIT(KTest12Desc, "Tls should handshake, Authentication takes place using CRAM-MD5 Mechanism."); |
|
121 _LIT(KTest12Result, "Mail is sent."); |
|
122 |
|
123 _LIT(KTest13ScriptFile, "scripts\\imsk25_ehlo_fail_conitnue_with_hostname.scr"); |
|
124 _LIT(KTest13Desc, "Smtp Auth with EHLO fail, Tls Off, Continue with hostname and then HELO"); |
|
125 _LIT(KTest13Result, "Mail is sent."); |
|
126 |
|
127 #ifdef _DEBUG |
|
128 _LIT(KLogFilePath, "c:\\logs\\email\\ImLog25.txt"); |
|
129 #endif |
|
130 |
|
131 _LIT(KScriptFilePath, "c:\\logs\\email\\imsk25.scr\\"); |
|
132 |
|
133 // Class to hold the data required for a Test |
|
134 class TTestData |
|
135 { |
|
136 public: |
|
137 TInt iTestNumber; |
|
138 TBuf<100> iTestFile; |
|
139 TBuf<200> iTestDescription; |
|
140 TBuf<200> iTestResult; |
|
141 }; |
|
142 |
|
143 enum TImStripLogType |
|
144 { |
|
145 EImMakeInFile, |
|
146 EImMakeOutFile, |
|
147 EImEndMakeFile |
|
148 }; |
|
149 |
|
150 RTest test(KSmtsTest); |
|
151 |
|
152 LOCAL_D CTrapCleanup* theCleanup; |
|
153 LOCAL_D CEmailTestUtils* testUtils; |
|
154 LOCAL_D TMsvId smtpService; |
|
155 LOCAL_D CBaseServerMtm* serverMtm; |
|
156 LOCAL_D TInt testError; |
|
157 LOCAL_D TTestData testData; |
|
158 |
|
159 LOCAL_C void ClearOutboxL() |
|
160 { |
|
161 testUtils->iServerEntry->SetEntry(KMsvGlobalOutBoxIndexEntryId); |
|
162 CMsvEntrySelection* sel = new(ELeave) CMsvEntrySelection(); |
|
163 CleanupStack::PushL(sel); |
|
164 testUtils->iServerEntry->GetChildrenWithMtm(KUidMsgTypeSMTP, *sel); |
|
165 |
|
166 TInt count = sel->Count(); |
|
167 |
|
168 while (count--) |
|
169 { |
|
170 testUtils->iServerEntry->DeleteEntry(sel->At(count)); |
|
171 } |
|
172 |
|
173 CleanupStack::PopAndDestroy(sel); |
|
174 } |
|
175 |
|
176 #ifdef _DEBUG |
|
177 |
|
178 LOCAL_C TBool CompareFilesL(TFileName aLogFile) |
|
179 { |
|
180 RFs& fs = testUtils->FileSession(); |
|
181 |
|
182 // Need to create the create filename |
|
183 TFileName name = _L("imsk"); |
|
184 TInt pos = 5; // set to skip passed the "imlog" part |
|
185 |
|
186 while( aLogFile[pos] != '.' ) |
|
187 { |
|
188 name.Append(aLogFile[pos]); |
|
189 ++pos; |
|
190 } |
|
191 name.Append(_L(".out")); |
|
192 |
|
193 // Load up the two files to compare. |
|
194 fs.SetSessionPath(_L("c:\\logs\\email\\")); |
|
195 |
|
196 RFile newFile; |
|
197 if( newFile.Open(fs, name, KEntryAttReadOnly) != KErrNone ) |
|
198 { |
|
199 return EFalse; |
|
200 } |
|
201 CleanupClosePushL(newFile); |
|
202 |
|
203 fs.SetSessionPath(_L("c:\\msgtest\\smts\\checkagainst\\")); |
|
204 RFile oldFile; |
|
205 if( oldFile.Open(fs, name, KEntryAttReadOnly) != KErrNone ) |
|
206 { |
|
207 CleanupStack::PopAndDestroy(&newFile); |
|
208 return EFalse; |
|
209 } |
|
210 CleanupClosePushL(oldFile); |
|
211 |
|
212 // Compare the files... |
|
213 HBufC8* line1Buffer = HBufC8::NewLC(1024); |
|
214 TPtr8 line1 = line1Buffer->Des(); |
|
215 TBuf8<1> aChar1; |
|
216 |
|
217 HBufC8* line2Buffer = HBufC8::NewLC(1024); |
|
218 TPtr8 line2 = line2Buffer->Des(); |
|
219 TBuf8<1> aChar2; |
|
220 TBool finished1 = EFalse; |
|
221 TBool finished2 = EFalse; |
|
222 TBool done = EFalse; |
|
223 |
|
224 do { |
|
225 line1.FillZ(); |
|
226 line1.SetLength(0); |
|
227 // compile the lines one char at a time |
|
228 do { |
|
229 User::LeaveIfError(newFile.Read(aChar1, 1)); |
|
230 if( aChar1.Length() > 0 ) |
|
231 line1.Append(aChar1); |
|
232 else |
|
233 { |
|
234 finished1 = ETrue; |
|
235 break; |
|
236 } |
|
237 // stop at the end of line or no more data |
|
238 } |
|
239 while( (aChar1[0]!=0x0A)&&(line1.Length()<1024) ); |
|
240 |
|
241 line2.FillZ(); |
|
242 line2.SetLength(0); |
|
243 do { |
|
244 User::LeaveIfError(oldFile.Read(aChar2, 1)); |
|
245 if( aChar2.Length() > 0 ) |
|
246 line2.Append(aChar2); |
|
247 else |
|
248 { |
|
249 finished2 = ETrue; |
|
250 break; |
|
251 } |
|
252 // stop at the end of line or no more data |
|
253 } |
|
254 while( (aChar2[0]!=0x0A)&&(line2.Length()<1024) ); |
|
255 |
|
256 if( finished1 || finished2 ) |
|
257 { |
|
258 // Check that both files have been completely read. |
|
259 if( finished1 && finished2 ) |
|
260 { |
|
261 // Yep - done. |
|
262 done = ETrue; |
|
263 } |
|
264 else |
|
265 { |
|
266 // Files are of different length - failed! |
|
267 CleanupStack::PopAndDestroy(4, &newFile); |
|
268 return EFalse; |
|
269 } |
|
270 } |
|
271 else |
|
272 { |
|
273 // get rid of white space |
|
274 line1.TrimRight(); |
|
275 line2.TrimRight(); |
|
276 |
|
277 if( line1.Compare(line2) != 0 ) |
|
278 { |
|
279 CleanupStack::PopAndDestroy(4, &newFile); |
|
280 return EFalse; |
|
281 } |
|
282 } |
|
283 } |
|
284 while(!done); |
|
285 |
|
286 CleanupStack::PopAndDestroy(4, &newFile); |
|
287 |
|
288 return ETrue; |
|
289 } |
|
290 |
|
291 LOCAL_C void ParseLogFileL(TFileName aLogFile) |
|
292 { |
|
293 RFs& fs = testUtils->FileSession(); |
|
294 fs.SetSessionPath(_L("c:\\logs\\email\\")); |
|
295 |
|
296 CScriptTestUtils* scriptTestUtils = CScriptTestUtils::NewLC(*testUtils); |
|
297 |
|
298 TInt portStringCounter; |
|
299 TBufC<KMaxFileName> logFileName; |
|
300 TBuf<KMaxFileName> scriptFileName; |
|
301 |
|
302 // First create the script file, then create the output test file. |
|
303 |
|
304 TImStripLogType lineType = EImMakeInFile; |
|
305 while ((lineType == EImMakeInFile) |
|
306 || (lineType == EImMakeOutFile)) |
|
307 { |
|
308 logFileName = aLogFile; |
|
309 |
|
310 // Get the name of the destination script file. |
|
311 scriptFileName = _L("imsk"); |
|
312 portStringCounter = 5; |
|
313 |
|
314 while (logFileName[portStringCounter] != L'.') |
|
315 { |
|
316 scriptFileName.Append(logFileName[portStringCounter]); |
|
317 portStringCounter++; |
|
318 } |
|
319 |
|
320 if (EImMakeInFile == lineType) |
|
321 { |
|
322 scriptFileName.Append(_L(".scr")); |
|
323 } |
|
324 else if (EImMakeOutFile == lineType) |
|
325 { |
|
326 scriptFileName.Append(_L(".out")); |
|
327 } |
|
328 |
|
329 if (lineType == EImMakeInFile) |
|
330 scriptTestUtils->LogToInputFileL(logFileName, scriptFileName, EFalse); |
|
331 else |
|
332 scriptTestUtils->LogToOutputFileL(logFileName, scriptFileName, ETrue); |
|
333 |
|
334 // If we have just created the script file the create the output test file. |
|
335 if (EImMakeInFile == lineType) |
|
336 { |
|
337 lineType = EImMakeOutFile; |
|
338 } |
|
339 else |
|
340 { |
|
341 lineType = EImEndMakeFile; |
|
342 } |
|
343 } |
|
344 |
|
345 CleanupStack::PopAndDestroy(); // scriptTestUtils |
|
346 } |
|
347 |
|
348 LOCAL_C void renameLogL(TTestData& aTestData, TFileName& aLogFile) |
|
349 { |
|
350 TFileName destPath = aTestData.iTestFile; |
|
351 |
|
352 // Make the destination file name. |
|
353 destPath.Delete(0,15); |
|
354 destPath.Delete(destPath.Length()-4,4); |
|
355 TFileName destPath1 = (_L("c:\\logs\\email\\Imlog25_")); |
|
356 destPath1.Append(destPath); |
|
357 destPath1.Append(_L(".txt")); |
|
358 |
|
359 aLogFile.Zero(); |
|
360 aLogFile.Append(_L("Imlog25_")); |
|
361 aLogFile.Append(destPath); |
|
362 aLogFile.Append(_L(".txt")); |
|
363 |
|
364 RFs aFs; |
|
365 User::LeaveIfError(aFs.Connect()); |
|
366 |
|
367 TInt err = aFs.Delete(destPath1); |
|
368 |
|
369 __ASSERT_ALWAYS((err == KErrNone) || (err == KErrNotFound), User::Panic(_L("smts_auth_test"),KErrGeneral)); |
|
370 |
|
371 // Copy the file. |
|
372 CFileMan* fileMan = CFileMan::NewL(aFs); |
|
373 CleanupStack::PushL(fileMan); |
|
374 fileMan->Rename(KLogFilePath, destPath1); |
|
375 aFs.Close(); |
|
376 CleanupStack::PopAndDestroy(fileMan); |
|
377 } |
|
378 |
|
379 #endif |
|
380 |
|
381 LOCAL_C TInt TestSendingMessagesL() |
|
382 { |
|
383 testError = 0; |
|
384 |
|
385 CTestActive* testActive = new (ELeave) CTestActive(); |
|
386 CleanupStack::PushL(testActive); |
|
387 |
|
388 CMsvEntrySelection* sendSel = new(ELeave) CMsvEntrySelection(); |
|
389 CleanupStack::PushL(sendSel); |
|
390 |
|
391 testUtils->iServerEntry->SetEntry(KMsvGlobalOutBoxIndexEntryId); |
|
392 User::LeaveIfError(testUtils->iServerEntry->GetChildren(*sendSel)); |
|
393 TInt count=sendSel->Count(); |
|
394 if (!count) |
|
395 { |
|
396 testUtils->WriteComment(_L("\t No messages to send in the outbox")); |
|
397 CleanupStack::PopAndDestroy(2); //testActive, sendsel |
|
398 testError = KErrNotFound; |
|
399 } |
|
400 else |
|
401 { |
|
402 serverMtm->CopyFromLocalL(*sendSel,smtpService, testActive->iStatus); |
|
403 |
|
404 testActive->StartL(); |
|
405 CActiveScheduler::Start(); |
|
406 TImSmtpProgress temp; |
|
407 TPckgC<TImSmtpProgress> paramPack(temp); |
|
408 |
|
409 const TDesC8& progBuf =serverMtm->Progress(); |
|
410 paramPack.Set(progBuf); |
|
411 TImSmtpProgress progress=paramPack(); |
|
412 CleanupStack::PopAndDestroy(2); //testActive, sendsel |
|
413 testError = progress.Error(); |
|
414 } |
|
415 |
|
416 return testError; |
|
417 } |
|
418 |
|
419 LOCAL_C void ClosedownL() |
|
420 { |
|
421 testUtils->TestHarnessCompleted(); |
|
422 CleanupStack::PopAndDestroy(2); //testUtils, ischeduler |
|
423 } |
|
424 |
|
425 LOCAL_C void InitL() |
|
426 { |
|
427 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
428 CleanupStack::PushL(scheduler); |
|
429 CActiveScheduler::Install( scheduler ); |
|
430 |
|
431 testUtils = CEmailTestUtils::NewLC(test); |
|
432 testUtils->WriteComment(KSmtsTest); |
|
433 |
|
434 testUtils->CleanMessageFolderL(); |
|
435 testUtils->ClearEmailAccountsL(); |
|
436 |
|
437 testUtils->GoClientSideL(); |
|
438 smtpService = testUtils->CreateSmtpServiceL(); |
|
439 CleanupStack::PopAndDestroy(testUtils); |
|
440 |
|
441 //explicitly close the message server so that a new instance of CEmailTestUtils can be created (waits for the server to close) |
|
442 TMsvDummyObserver* dummyObserver = new (ELeave) TMsvDummyObserver; |
|
443 CMsvSession* msvSession = CMsvSession::OpenSyncL(*dummyObserver); |
|
444 msvSession->CloseMessageServer(); |
|
445 delete msvSession; |
|
446 delete dummyObserver; |
|
447 |
|
448 testUtils = CEmailTestUtils::NewLC(test, ETuGoServerSide); |
|
449 testUtils->InstantiateSmtpServerMtmL(); |
|
450 serverMtm=testUtils->iSmtpServerMtm; |
|
451 |
|
452 testUtils->WriteComment(_L("Smtp server created")); |
|
453 } |
|
454 |
|
455 LOCAL_C void ResetSettingsL(TBool aSecureSocket, TBool aSmtpAuth) |
|
456 { |
|
457 _LIT(KSmtpEmailAlias, "SMTP AUTH"); |
|
458 _LIT(KSmtpServer, "lon-msgtest06.intra"); |
|
459 _LIT(KSmtpEmailAddress, "<smtp@lon-msgtest06.intra>"); |
|
460 _LIT8(KSmtpUserName, "smtp-bad"); |
|
461 _LIT8(KSmtpPassword, "password-bad"); |
|
462 |
|
463 TPtrC8 userName(KSmtpUserName); |
|
464 TPtrC8 password(KSmtpPassword); |
|
465 |
|
466 CleanupStack::PopAndDestroy(testUtils); |
|
467 |
|
468 // Overwrite the setings with test code one. Don't want the default settings. |
|
469 CImSmtpSettings* settings = new(ELeave) CImSmtpSettings(); |
|
470 CleanupStack::PushL(settings); |
|
471 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
472 TSmtpAccount smtpAccountId; |
|
473 accounts->GetSmtpAccountL(smtpService,smtpAccountId); |
|
474 accounts->LoadSmtpSettingsL(smtpAccountId, *settings); |
|
475 settings->SetServerAddressL(KSmtpServer); |
|
476 settings->SetEmailAliasL(KSmtpEmailAlias); |
|
477 settings->SetEmailAddressL(KSmtpEmailAddress); |
|
478 settings->SetReplyToAddressL(KSmtpEmailAddress); |
|
479 settings->SetBodyEncoding(EMsgOutboxMIME); |
|
480 settings->SetReceiptAddressL(KSmtpEmailAddress); |
|
481 settings->SetSecureSockets(aSecureSocket); |
|
482 settings->SetSMTPAuth(aSmtpAuth); |
|
483 settings->SetLoginNameL(userName); |
|
484 settings->SetPasswordL(password); |
|
485 |
|
486 settings->SetPort(25); |
|
487 accounts->SaveSmtpSettingsL(smtpAccountId, *settings); |
|
488 |
|
489 CleanupStack::PopAndDestroy(2, settings); //settings, store/accounts |
|
490 |
|
491 //explicitly close the message server so that a new instance of CEmailTestUtils can be created (waits for the server to close) |
|
492 TMsvDummyObserver* dummyObserver = new (ELeave) TMsvDummyObserver; |
|
493 CMsvSession* msvSession = CMsvSession::OpenSyncL(*dummyObserver); |
|
494 msvSession->CloseMessageServer(); |
|
495 delete msvSession; |
|
496 delete dummyObserver; |
|
497 |
|
498 testUtils = CEmailTestUtils::NewLC(test, ETuGoServerSide); |
|
499 testUtils->InstantiateSmtpServerMtmL(); |
|
500 serverMtm=testUtils->iSmtpServerMtm; |
|
501 } |
|
502 |
|
503 LOCAL_C void CreateMsgToSendL() |
|
504 // Create a message to send & place it in the outbox |
|
505 { |
|
506 TParse scriptFile; |
|
507 _LIT(KSmtsRfcFile, "RFC822\\rfc82201.txt"); |
|
508 testUtils->ResolveFile(KSmtsComponent, KSmtsRfcFile, scriptFile); |
|
509 testUtils->CreateMessageL(scriptFile.FullName(), smtpService, KMsvGlobalOutBoxIndexEntryId); |
|
510 testUtils->WriteComment(_L(" Message created in the outbox")); |
|
511 testUtils->WriteComment(_L("\nPerforming Tests\n")); |
|
512 } |
|
513 |
|
514 LOCAL_C void RunTestL(TTestData& aTestData) |
|
515 { |
|
516 testUtils->FileSession().RmDir(KScriptFilePath); |
|
517 // Add a blank line to the Log file before the new Test |
|
518 _LIT(KBlankLine, ""); |
|
519 testUtils->WriteComment(KBlankLine); |
|
520 |
|
521 TParse scriptFile; |
|
522 testUtils->ResolveFile(KSmtsComponent, aTestData.iTestFile, scriptFile); |
|
523 testUtils->CopyScriptFileL(scriptFile.FullName(), _L("25")); |
|
524 |
|
525 // For dial up tests, ucomment the below line |
|
526 // testUtils->DeleteScriptFilesFromLogsDirL(); |
|
527 |
|
528 testUtils->TestStart(aTestData.iTestNumber); |
|
529 testUtils->WriteComment(aTestData.iTestDescription); |
|
530 testUtils->WriteComment(aTestData.iTestResult); |
|
531 |
|
532 // Run the Test & check the error |
|
533 if( TestSendingMessagesL() == KErrNone ) |
|
534 { |
|
535 #ifdef _DEBUG |
|
536 // Test was executed ok - check to see if result was correct |
|
537 TFileName logFile; |
|
538 renameLogL(testData, logFile); |
|
539 ParseLogFileL(logFile); |
|
540 |
|
541 if( !CompareFilesL(logFile) ) |
|
542 testError = KErrNotFound; |
|
543 #else |
|
544 // Cannot compare logs on REL builds, since the log file is not generated |
|
545 testUtils->WriteComment(_L("!!!! Logs comparison skipped on REL builds !!!!")); |
|
546 testUtils->WriteComment(_L("!!!! Run on DEB build for complete test !!!!")); |
|
547 #endif |
|
548 } |
|
549 } |
|
550 |
|
551 LOCAL_C void RunAllTestsL() |
|
552 { |
|
553 |
|
554 /* //--------------------------------------------------- |
|
555 // Test 1 - TLS On, Smtp Auth On, No Smtp on Server |
|
556 //--------------------------------------------------- |
|
557 ResetSettingsL(ETrue, ETrue); |
|
558 testData.iTestNumber = 1; |
|
559 testData.iTestFile = KTest1ScriptFile; |
|
560 testData.iTestDescription = KTest1Desc; |
|
561 testData.iTestResult = KTest1Result; |
|
562 RunTestL(testData); |
|
563 testError=(testError==-1)? 0 : testError; |
|
564 testUtils->TestFinish(testData.iTestNumber, testError); |
|
565 |
|
566 //CreateMsgToSendL(); |
|
567 renameLogL(testData); |
|
568 |
|
569 //----------------------------------------------------------------- |
|
570 // Test 2 - TLS on, SMTP Auth Off, Smtp on Server |
|
571 //----------------------------------------------------------------- |
|
572 ResetSettingsL(ETrue, EFalse); |
|
573 testData.iTestNumber = 2; |
|
574 testData.iTestFile = KTest2ScriptFile; |
|
575 testData.iTestDescription = KTest2Desc; |
|
576 testData.iTestResult = KTest2Result; |
|
577 RunTestL(testData); |
|
578 testError=(testError==-1)? 0 : testError; |
|
579 testUtils->TestFinish(testData.iTestNumber, testError); |
|
580 //CreateMsgToSendL(); |
|
581 renameLogL(testData); |
|
582 */ |
|
583 |
|
584 //------------------------------------------------------ |
|
585 // Test 3 - TLS on, SMTP Auth On, Login Mechanism used |
|
586 //------------------------------------------------------ |
|
587 ResetSettingsL(ETrue, ETrue); |
|
588 CreateMsgToSendL(); |
|
589 testData.iTestNumber = 3; |
|
590 testData.iTestFile = KTest3ScriptFile; |
|
591 testData.iTestDescription = KTest3Desc; |
|
592 testData.iTestResult = KTest3Result; |
|
593 RunTestL(testData); |
|
594 testUtils->TestFinish(testData.iTestNumber, testError); |
|
595 |
|
596 |
|
597 //--------------------------------------------- |
|
598 // Test 4 - TLS off, SMTP Auth On, Wrong UserName |
|
599 //--------------------------------------------- |
|
600 ResetSettingsL(EFalse, ETrue); |
|
601 CreateMsgToSendL(); |
|
602 testData.iTestNumber = 4; |
|
603 testData.iTestFile = KTest4ScriptFile; |
|
604 testData.iTestDescription = KTest4Desc; |
|
605 testData.iTestResult = KTest4Result; |
|
606 RunTestL(testData); |
|
607 testUtils->TestFinish(testData.iTestNumber, testError); |
|
608 |
|
609 |
|
610 //-------------------------------------------------------------------------------------- |
|
611 // Test 5 - TLS off, SMTP Auth On, Wrong Password |
|
612 //-------------------------------------------------------------------------------------- |
|
613 ResetSettingsL(EFalse, ETrue); |
|
614 CreateMsgToSendL(); |
|
615 testData.iTestNumber = 5; |
|
616 testData.iTestFile = KTest5ScriptFile; |
|
617 testData.iTestDescription = KTest5Desc; |
|
618 testData.iTestResult = KTest5Result; |
|
619 RunTestL(testData); |
|
620 testUtils->TestFinish(testData.iTestNumber, testError); |
|
621 |
|
622 |
|
623 //---------------------------------------- |
|
624 // Test 6 - TLS off, SMTP Auth On, Plain Mechanism used |
|
625 //---------------------------------------- |
|
626 ResetSettingsL(EFalse, ETrue); |
|
627 CreateMsgToSendL(); |
|
628 testData.iTestNumber = 6; |
|
629 testData.iTestFile = KTest6ScriptFile; |
|
630 testData.iTestDescription = KTest6Desc; |
|
631 testData.iTestResult = KTest6Result; |
|
632 RunTestL(testData); |
|
633 testUtils->TestFinish(testData.iTestNumber, testError); |
|
634 |
|
635 //-------------------------------------------------------------------------- |
|
636 // Test 7 - TLS off, SMTP Auth On, Login Mechanism used |
|
637 //-------------------------------------------------------------------------- |
|
638 ResetSettingsL(EFalse, ETrue); |
|
639 CreateMsgToSendL(); |
|
640 testData.iTestNumber = 7; |
|
641 testData.iTestFile = KTest7ScriptFile; |
|
642 testData.iTestDescription = KTest7Desc; |
|
643 testData.iTestResult = KTest7Result; |
|
644 RunTestL(testData); |
|
645 testUtils->TestFinish(testData.iTestNumber, testError); |
|
646 |
|
647 |
|
648 //-------------------------------------------------------------------------- |
|
649 // Test 8 - TLS off, SMTP Auth On, CRAM-MD5 Mechanism used |
|
650 //-------------------------------------------------------------------------- |
|
651 ResetSettingsL(EFalse, ETrue); |
|
652 CreateMsgToSendL(); |
|
653 testData.iTestNumber = 8; |
|
654 testData.iTestFile = KTest8ScriptFile; |
|
655 testData.iTestDescription = KTest8Desc; |
|
656 testData.iTestResult = KTest8Result; |
|
657 RunTestL(testData); |
|
658 testUtils->TestFinish(testData.iTestNumber, testError); |
|
659 |
|
660 //---------------------------------------- |
|
661 // Test 9 - TLS off, SMTP Auth On, No SMTP on Server |
|
662 //---------------------------------------- |
|
663 ResetSettingsL(EFalse, ETrue); |
|
664 CreateMsgToSendL(); |
|
665 testData.iTestNumber = 9; |
|
666 testData.iTestFile = KTest9ScriptFile; |
|
667 testData.iTestDescription = KTest9Desc; |
|
668 testData.iTestResult = KTest9Result; |
|
669 RunTestL(testData); |
|
670 testUtils->TestFinish(testData.iTestNumber, testError); |
|
671 |
|
672 //--------------------------------------------------------------------- |
|
673 // Test 10 - SMTP Auth with Ehlo is not supported, Conitnue using Helo Command |
|
674 //--------------------------------------------------------------------- |
|
675 |
|
676 ResetSettingsL(EFalse, ETrue); |
|
677 CreateMsgToSendL(); |
|
678 |
|
679 testData.iTestNumber = 10; |
|
680 testData.iTestFile = KTest10ScriptFile; |
|
681 testData.iTestDescription = KTest10Desc; |
|
682 testData.iTestResult = KTest10Result; |
|
683 RunTestL(testData); |
|
684 testUtils->TestFinish(testData.iTestNumber, testError); |
|
685 |
|
686 //--------------------------------------------------------------------- |
|
687 // Test 11 - SMTP Auth with Ehlo is not supported, Quit if Tls On |
|
688 //--------------------------------------------------------------------- |
|
689 |
|
690 ResetSettingsL(ETrue, ETrue); |
|
691 CreateMsgToSendL(); |
|
692 |
|
693 testData.iTestNumber = 11; |
|
694 testData.iTestFile = KTest11ScriptFile; |
|
695 testData.iTestDescription = KTest11Desc; |
|
696 testData.iTestResult = KTest11Result; |
|
697 RunTestL(testData); |
|
698 // This test is slightly different - an error code is expected. |
|
699 if( testError == KErrSmtpTLSNegotiateFailed ) |
|
700 { |
|
701 #ifdef _DEBUG |
|
702 testError = KErrNone; |
|
703 // Test was executed ok - check to see if result was correct |
|
704 TFileName logFile; |
|
705 renameLogL(testData, logFile); |
|
706 ParseLogFileL(logFile); |
|
707 |
|
708 if( !CompareFilesL(logFile) ) |
|
709 testError = KErrNotFound; |
|
710 #else |
|
711 // Cannot compare logs on REL builds, since the log file is not generated |
|
712 testUtils->WriteComment(_L("!!!! Logs comparison skipped on REL builds !!!!")); |
|
713 testUtils->WriteComment(_L("!!!! Run on DEB build for complete test !!!!")); |
|
714 #endif |
|
715 } |
|
716 else |
|
717 { |
|
718 if( testError == KErrNone ) |
|
719 testError = KErrNotFound; // it should have been an error! (Although unlikely to get here as log comparison will fail!) |
|
720 } |
|
721 testUtils->TestFinish(testData.iTestNumber, testError); |
|
722 |
|
723 ClearOutboxL(); |
|
724 |
|
725 //------------------------------------------------------ |
|
726 // Test 12 - TLS on, SMTP Auth On, CRAM-MD5 Mechanism used |
|
727 //------------------------------------------------------ |
|
728 ResetSettingsL(ETrue, ETrue); |
|
729 CreateMsgToSendL(); |
|
730 testData.iTestNumber = 12; |
|
731 testData.iTestFile = KTest12ScriptFile; |
|
732 testData.iTestDescription = KTest12Desc; |
|
733 testData.iTestResult = KTest12Result; |
|
734 RunTestL(testData); |
|
735 testUtils->TestFinish(testData.iTestNumber, testError); |
|
736 |
|
737 //--------------------------------------------------------------------- |
|
738 // Test 13 - SMTP Auth with Ehlo is not supported, Conitnue with hostname and then HELO |
|
739 //--------------------------------------------------------------------- |
|
740 |
|
741 ResetSettingsL(EFalse, ETrue); |
|
742 CreateMsgToSendL(); |
|
743 |
|
744 testData.iTestNumber = 13; |
|
745 testData.iTestFile = KTest13ScriptFile; |
|
746 testData.iTestDescription = KTest13Desc; |
|
747 testData.iTestResult = KTest13Result; |
|
748 RunTestL(testData); |
|
749 testUtils->TestFinish(testData.iTestNumber, testError); |
|
750 |
|
751 // Delete the script file generated in C:\logs\email directory |
|
752 testUtils->DeleteScriptFilesFromLogsDirL(); |
|
753 } |
|
754 |
|
755 LOCAL_C void doMainL() |
|
756 { |
|
757 InitL(); |
|
758 |
|
759 TInt driverErr; |
|
760 driverErr=User::LoadPhysicalDevice(PDD_NAME); |
|
761 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
762 User::Leave(driverErr); |
|
763 driverErr=User::LoadLogicalDevice(LDD_NAME); |
|
764 if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists) |
|
765 User::Leave(driverErr); |
|
766 |
|
767 testUtils->iServerEntry->SetEntry(smtpService); |
|
768 |
|
769 ResetSettingsL(ETrue,ETrue); |
|
770 testUtils->DeleteScriptFilesFromLogsDirL(); |
|
771 RunAllTestsL(); |
|
772 |
|
773 // End of the Tests |
|
774 ClosedownL(); |
|
775 } |
|
776 |
|
777 GLDEF_C TInt E32Main() |
|
778 { |
|
779 __UHEAP_MARK; |
|
780 test.Start(_L("T_SMTSSMTPAUTH Test SMTP server MTM - SMTP AUTH")); |
|
781 theCleanup=CTrapCleanup::New(); |
|
782 TRAPD(ret,doMainL()); |
|
783 test(ret==KErrNone); |
|
784 delete theCleanup; |
|
785 test.End(); |
|
786 test.Close(); |
|
787 __UHEAP_MARKEND; |
|
788 User::Heap().Check(); |
|
789 return(KErrNone); |
|
790 } |