|
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 // Brief description of test harness: |
|
15 // Tests SSL/TLS functionality in POPS |
|
16 // |
|
17 // |
|
18 |
|
19 |
|
20 #include "CTestPOPSecureSocketTest.h" |
|
21 #include <iapprefs.h> |
|
22 #include <f32file.h> |
|
23 |
|
24 //Literals used |
|
25 _LIT(KFileName,"C:\\msgtest\\pops\\scripts\\MachineIP.txt"); |
|
26 |
|
27 #define KMaxIpvalue 100 |
|
28 |
|
29 #if defined (__WINS__) |
|
30 #define PDD_NAME _L("ECDRV") |
|
31 #define LDD_NAME _L("ECOMM") |
|
32 #else |
|
33 #define PDD_NAME _L("EUART1") |
|
34 #define LDD_NAME _L("ECOMM") |
|
35 #endif |
|
36 |
|
37 _LIT(KPopsComponent,"T_POPSECURESOCKETS"); |
|
38 _LIT(KPopTeststart, "T_POPSECURESOCKETS - START POPS SecureSockets Functionality Testing"); |
|
39 _LIT(KPopTestend, "T_POPSECURESOCKETS - END POPS SecureSockets Functionality Testing"); |
|
40 |
|
41 _LIT8(KPOPtestUserPass, "poptest"); |
|
42 _LIT8(KPOPInValidUserPass, "InvaliedUserPass"); |
|
43 _LIT8(KServerDomainname, "stalker.com"); |
|
44 |
|
45 |
|
46 RTest test(KPopsComponent); |
|
47 |
|
48 |
|
49 CTestPOPSecureSocketTest::CTestPOPSecureSocketTest() |
|
50 { |
|
51 } |
|
52 |
|
53 CTestPOPSecureSocketTest ::~CTestPOPSecureSocketTest() |
|
54 { |
|
55 } |
|
56 /* |
|
57 // Read the Ip from the MachineIP.txt config file. |
|
58 // And connect the server . |
|
59 */ |
|
60 TPtr16 CTestPOPSecureSocketTest::ReadServerIp() |
|
61 { |
|
62 RFs fs; |
|
63 User::LeaveIfError(fs.Connect()); |
|
64 CleanupClosePushL(fs); |
|
65 RFile file; |
|
66 User::LeaveIfError(file.Open(fs, KFileName, EFileRead)); |
|
67 CleanupClosePushL(file); |
|
68 TInt fileSize; |
|
69 User::LeaveIfError(file.Size(fileSize)); |
|
70 HBufC8* iServerIp = HBufC8::NewL(fileSize); |
|
71 TPtr8 ibufferPtr = iServerIp->Des();; |
|
72 User::LeaveIfError(file.Read(ibufferPtr)); |
|
73 HBufC16* a16Value = HBufC16::NewL(KMaxIpvalue); |
|
74 TPtr16 i16bufferPtr = a16Value->Des(); |
|
75 i16bufferPtr.Copy(ibufferPtr); |
|
76 CleanupStack::PopAndDestroy(2); |
|
77 file.Close(); |
|
78 return i16bufferPtr; |
|
79 } |
|
80 |
|
81 void CTestPOPSecureSocketTest::SetupL() |
|
82 { |
|
83 _LIT(KFunction, "SetupL"); |
|
84 INFO_PRINTF1(KFunction); |
|
85 INFO_PRINTF1(KPopTeststart); |
|
86 TInt err; |
|
87 err=User::LoadPhysicalDevice(PDD_NAME); |
|
88 if (err!=KErrNone && err!=KErrAlreadyExists) |
|
89 User::Leave(err); |
|
90 err=User::LoadLogicalDevice(LDD_NAME); |
|
91 if (err!=KErrNone && err!=KErrAlreadyExists) |
|
92 User::Leave(err); |
|
93 |
|
94 iActiveWaiter = new(ELeave)CActiveWaiter(); |
|
95 iTestUtils = CEmailTestUtils::NewL(test); |
|
96 iTestUtils->FileSession().SetSessionPath( _L( "C:\\" ) ); |
|
97 iTestUtils->ClearEmailAccountsL(); |
|
98 iTestUtils->CreateAllTestDirectories(); |
|
99 iTestUtils->CleanMessageFolderL(); |
|
100 } |
|
101 |
|
102 void CTestPOPSecureSocketTest::TearDownL() |
|
103 { |
|
104 _LIT(KFunction, "TearDownL"); |
|
105 INFO_PRINTF1(KFunction); |
|
106 |
|
107 delete iActiveWaiter; |
|
108 iActiveWaiter = NULL; |
|
109 delete iTestUtils; |
|
110 iTestUtils = NULL; |
|
111 INFO_PRINTF1(KPopTestend); |
|
112 } |
|
113 |
|
114 void CTestPOPSecureSocketTest::TestRunPopSSLTLSTestsL() |
|
115 { |
|
116 _LIT(KFunction1, "TestRunNonApopTestsL"); |
|
117 INFO_PRINTF1(KFunction1); |
|
118 |
|
119 TPtr16 i16testbufferPtr = ReadServerIp(); |
|
120 //------------------------------- |
|
121 // Test 1 (Support SSl-TLS) |
|
122 //------------------------------- |
|
123 TypeOfTest aType1(EpopApopTLSok); |
|
124 SetSettingsL(aType1,i16testbufferPtr); |
|
125 ConnectToRemoteServerL(aType1); |
|
126 DisconnectL(); |
|
127 |
|
128 //------------------------------- |
|
129 // Test 2 (Invalid User) |
|
130 //------------------------------- |
|
131 |
|
132 TypeOfTest aType2(EpopTlsInvalidUser); |
|
133 SetSettingsL(aType2,i16testbufferPtr); |
|
134 ConnectToRemoteServerL(aType2); |
|
135 DisconnectL(); |
|
136 |
|
137 } |
|
138 |
|
139 // Setting up the POP3 Setting in SSL |
|
140 void CTestPOPSecureSocketTest::SetSettingsL(TypeOfTest aType,TPtr16 aServerIp) |
|
141 { |
|
142 iTestUtils->GoClientSideL(); |
|
143 |
|
144 if(!ipop3Service) |
|
145 ipop3Service = iTestUtils->CreatePopServiceL(); |
|
146 |
|
147 |
|
148 CEmailAccounts* account = CEmailAccounts::NewLC(); |
|
149 isettings = new(ELeave) CImPop3Settings(); |
|
150 |
|
151 |
|
152 CImIAPPreferences* imapIAP = CImIAPPreferences::NewLC(); |
|
153 iSel = new (ELeave) CMsvEntrySelection; |
|
154 |
|
155 TPopAccount pop3AccountId; |
|
156 account->GetPopAccountL(ipop3Service, pop3AccountId); |
|
157 account->LoadPopSettingsL(pop3AccountId, *isettings); |
|
158 |
|
159 switch(aType) |
|
160 { |
|
161 case EpopApopTLSok : |
|
162 isettings->SetServerAddressL(aServerIp ); |
|
163 isettings->SetLoginNameL(KPOPtestUserPass); |
|
164 isettings->SetPasswordL(KPOPtestUserPass ); |
|
165 isettings->SetSecureSockets(ETrue); |
|
166 isettings->SetSSLWrapper(ETrue); |
|
167 isettings->SetPort(995);//SSL/TLS POP3 port 995 . by default it is 110. |
|
168 isettings->SetTlsSslDomainL(KServerDomainname()); |
|
169 |
|
170 break; |
|
171 |
|
172 case EpopTlsInvalidUser : |
|
173 isettings->SetServerAddressL(aServerIp); |
|
174 isettings->SetLoginNameL(KPOPInValidUserPass); |
|
175 isettings->SetPasswordL(KPOPInValidUserPass); |
|
176 isettings->SetSecureSockets(ETrue); |
|
177 isettings->SetSSLWrapper(ETrue); |
|
178 isettings->SetPort(995);//SSL/TLS POP3 port 995 . by default it is 110. |
|
179 isettings->SetTlsSslDomainL(KServerDomainname()); |
|
180 break; |
|
181 }; |
|
182 |
|
183 account->SavePopSettingsL(pop3AccountId, *isettings); |
|
184 CleanupStack::PopAndDestroy(2, account); |
|
185 |
|
186 iTestUtils->GoServerSideL(); |
|
187 iTestUtils->InstantiatePopServerMtmL(); |
|
188 iPopServerMtm=iTestUtils->iPopServerMtm; |
|
189 } |
|
190 |
|
191 //Connect to tyhe Server |
|
192 void CTestPOPSecureSocketTest::ConnectToRemoteServerL(TypeOfTest aType) |
|
193 { |
|
194 TBuf8<128> parameter; |
|
195 iSel->AppendL(ipop3Service); |
|
196 TPop3Progress temp; |
|
197 TPckgC<TPop3Progress> paramPack(temp); |
|
198 iPopServerMtm->StartCommandL(*iSel, KPOP3MTMConnect, parameter, iActiveWaiter->iStatus); |
|
199 iActiveWaiter->WaitActive(); |
|
200 const TDesC8& progBuf = iTestUtils->iPopServerMtm->Progress(); |
|
201 paramPack.Set(progBuf); |
|
202 TPop3Progress progress=paramPack(); |
|
203 switch(aType) |
|
204 { |
|
205 case EpopApopTLSok : |
|
206 ASSERT_EQUALS( progress.iErrorCode, KErrNone|KErrAbort ); |
|
207 break; |
|
208 |
|
209 case EpopTlsInvalidUser : |
|
210 { |
|
211 if(progress.iErrorCode == KErrAbort ) |
|
212 { |
|
213 ASSERT_EQUALS( progress.iErrorCode, KErrAbort ); |
|
214 } |
|
215 else |
|
216 { |
|
217 ASSERT_EQUALS( progress.iErrorCode, -172 ); |
|
218 } |
|
219 } |
|
220 break; |
|
221 }; |
|
222 } |
|
223 |
|
224 //Disconnecting the Connection |
|
225 void CTestPOPSecureSocketTest::DisconnectL() |
|
226 { |
|
227 TBuf8<128> parameter; |
|
228 iSel->AppendL(ipop3Service); |
|
229 iPopServerMtm->StartCommandL(*iSel,KPOP3MTMDisconnect , parameter, iActiveWaiter->iStatus); |
|
230 iActiveWaiter->WaitActive(); |
|
231 ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone ); |
|
232 } |
|
233 |
|
234 |
|
235 CTestSuite* CTestPOPSecureSocketTest::CreateSuiteL(const TDesC& aName) |
|
236 { |
|
237 SUB_SUITE; |
|
238 ADD_ASYNC_TEST_STEP(TestRunPopSSLTLSTestsL); |
|
239 END_SUITE; |
|
240 } |
|
241 |