|
1 // Copyright (c) 2004-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 "3DigestAuthTransactions.h" |
|
17 #include <http.h> |
|
18 #include "csrvaddrval.h" |
|
19 |
|
20 // Literals used in the file |
|
21 _LIT8(KWapTestUrl, "http://WapTestName"); |
|
22 |
|
23 /** |
|
24 This function returns the name of the test. |
|
25 */ |
|
26 const TDesC& C3DigestAuthTransactions::TestName() |
|
27 { |
|
28 _LIT(KHeaderTestName, "Digest Authentication Test, sending three transactions"); |
|
29 return KHeaderTestName; |
|
30 } |
|
31 |
|
32 C3DigestAuthTransactions::C3DigestAuthTransactions(CScriptFile* aIniSettingsFile) |
|
33 : iIniSettingsFile(aIniSettingsFile) |
|
34 { |
|
35 iTransNum=0; |
|
36 iTransSucceeded=0; |
|
37 iExpectedStatusCode=200; |
|
38 } |
|
39 |
|
40 /** |
|
41 This function is opens a session for the test being executed. |
|
42 |
|
43 @leave Leaves with a standard error. |
|
44 */ |
|
45 void C3DigestAuthTransactions::OpenTestSessionL() |
|
46 { |
|
47 //open a default Session |
|
48 iSession.OpenL(); |
|
49 iSetCredentials=ETrue; |
|
50 InstallAuthenticationL(iSession); |
|
51 |
|
52 //Logs |
|
53 iEngine->Utils().LogIt(_L("Session Created(Iteration 2 Get Test 17)")); |
|
54 iEngine->Utils().LogIt(_L("Session parameters: Default")); |
|
55 |
|
56 //Get the iSession'string pool handle; |
|
57 iMyStrP = iSession.StringPool(); |
|
58 } |
|
59 |
|
60 /** |
|
61 This function closes all the transactions and sessions opened. |
|
62 */ |
|
63 void C3DigestAuthTransactions::CloseTestSession() |
|
64 { |
|
65 //Close all the 8 Transactions opened in the DoRunL() |
|
66 iTransaction1.Close(); |
|
67 iEngine->Utils().LogIt(_L("Transaction1 terminated\n")); |
|
68 iTransaction2.Close(); |
|
69 iEngine->Utils().LogIt(_L("Transaction2 terminated\n")); |
|
70 iTransaction3.Close(); |
|
71 iEngine->Utils().LogIt(_L("Transaction3 terminated\n")); |
|
72 //and close the session |
|
73 iSession.Close(); |
|
74 iEngine->Utils().LogIt(_L("Session terminated")); |
|
75 } |
|
76 |
|
77 /** |
|
78 3 Digest authentication transactions are executed from this function. |
|
79 |
|
80 @leave Leaves with a standard error. |
|
81 */ |
|
82 void C3DigestAuthTransactions::DoRunL() |
|
83 { |
|
84 OpenTestSessionL(); |
|
85 |
|
86 //Trans1 |
|
87 OpenTestTrans1L(); |
|
88 iTransaction1.SubmitL(); |
|
89 iTransNum++; |
|
90 //Trans2 |
|
91 OpenTestTrans2L(); |
|
92 iTransaction2.SubmitL(); |
|
93 iTransNum++; |
|
94 |
|
95 //Trans3 |
|
96 OpenTestTrans3L(); |
|
97 iTransaction3.SubmitL(); |
|
98 iTransNum++; |
|
99 |
|
100 CActiveScheduler::Start(); |
|
101 |
|
102 CloseTestSession(); |
|
103 if (iTestFail==1) |
|
104 { |
|
105 User::Leave(-1); |
|
106 } |
|
107 } |
|
108 |
|
109 void C3DigestAuthTransactions::OpenTestTrans1L() |
|
110 { |
|
111 // Literals used in the function |
|
112 _LIT8(KUrlPath, "/http_tests/digest/auth/"); |
|
113 |
|
114 // Replace the host name in the URL |
|
115 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
116 CleanupStack::PushL(newUrl8); |
|
117 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
118 newUrlPtr8.Append(KUrlPath()); |
|
119 |
|
120 TUriParser8 testURI1; |
|
121 testURI1.Parse(newUrlPtr8); |
|
122 |
|
123 //open a GET transaction and log it |
|
124 iTransaction1 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
125 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
126 |
|
127 // Log the Request parameters |
|
128 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
129 iEngine->Utils().LogIt(_L("Method:GET")); |
|
130 CleanupStack::PopAndDestroy(newUrl8); |
|
131 } |
|
132 |
|
133 void C3DigestAuthTransactions::OpenTestTrans2L() |
|
134 { |
|
135 // Literals used in the function |
|
136 _LIT8(KUrlPath, "/http_tests/digest/rfc2069/"); |
|
137 |
|
138 // Replace the host name in the URL |
|
139 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
140 CleanupStack::PushL(newUrl8); |
|
141 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
142 newUrlPtr8.Append(KUrlPath()); |
|
143 |
|
144 TUriParser8 testURI1; |
|
145 testURI1.Parse(newUrlPtr8); |
|
146 |
|
147 //open a GET transaction and log it |
|
148 iTransaction2 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
149 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
150 |
|
151 // Log the Request parameters |
|
152 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
153 iEngine->Utils().LogIt(_L("Method:GET")); |
|
154 CleanupStack::PopAndDestroy(newUrl8); |
|
155 } |
|
156 |
|
157 void C3DigestAuthTransactions::OpenTestTrans3L() |
|
158 { |
|
159 // Literals used in the function |
|
160 _LIT8(KUrlPath, "/http_tests/digest/rfc2069/"); |
|
161 |
|
162 // Replace the host name in the URL |
|
163 HBufC8* newUrl8 = TSrvAddrVal::ReplaceHostNameL(KWapTestUrl(), iIniSettingsFile); |
|
164 CleanupStack::PushL(newUrl8); |
|
165 TPtr8 newUrlPtr8 = newUrl8->Des(); |
|
166 newUrlPtr8.Append(KUrlPath()); |
|
167 |
|
168 TUriParser8 testURI1; |
|
169 testURI1.Parse(newUrlPtr8); |
|
170 |
|
171 //open a GET transaction and log it |
|
172 iTransaction3 = iSession.OpenTransactionL(testURI1, *this, iMyStrP.StringF(HTTP::EGET,RHTTPSession::GetTable())); |
|
173 iEngine->Utils().LogIt(_L("Transaction Created in Session")); |
|
174 |
|
175 // Log the Request parameters |
|
176 TSrvAddrVal::LogUsing8BitDesL(iEngine, newUrlPtr8); |
|
177 iEngine->Utils().LogIt(_L("Method:GET")); |
|
178 CleanupStack::PopAndDestroy(newUrl8); |
|
179 } |
|
180 |
|
181 |
|
182 TInt C3DigestAuthTransactions::MHFRunError(TInt aError, RHTTPTransaction /*aTransaction*/, |
|
183 const THTTPEvent& /*aEvent*/) |
|
184 { |
|
185 iEngine->Utils().LogIt(_L("\nTest failed with error code %d\n"), aError); |
|
186 return KErrNone; |
|
187 } |
|
188 |
|
189 void C3DigestAuthTransactions::MHFRunL(RHTTPTransaction aTransaction, |
|
190 const THTTPEvent& aEvent) |
|
191 { |
|
192 switch (aEvent.iStatus) |
|
193 { |
|
194 case THTTPEvent::EGotResponseHeaders: |
|
195 { |
|
196 // HTTP response headers have been received |
|
197 iEngine->Utils().LogIt(_L("<EGotResponseHeaders>\n")); |
|
198 TInt statusCode = aTransaction.Response().StatusCode(); |
|
199 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
200 DumpRespHeaders(aTransaction); |
|
201 iEngine->SetCurrentStatusCode(statusCode); |
|
202 if (iExpectedStatusCode != statusCode) |
|
203 { |
|
204 iTestFail=1; |
|
205 iEngine->Utils().LogIt(_L("<The Test will fail :The expected status code doesn't match the actual status code received>\n")); |
|
206 } |
|
207 } break; |
|
208 case THTTPEvent::EGotResponseBodyData: |
|
209 { |
|
210 // Some (more) body data has been received (in the HTTP response) |
|
211 iEngine->Utils().LogIt(_L("<EGotResponseBodyData received>\n")); |
|
212 // for each chunk of data received we have to empty the buffer |
|
213 // before to be able to receive |
|
214 MHTTPDataSupplier* body = aTransaction.Response().Body(); |
|
215 body->ReleaseData(); |
|
216 } break; |
|
217 case THTTPEvent::EResponseComplete: |
|
218 { |
|
219 // The transaction's response is complete |
|
220 iEngine->Utils().LogIt(_L("<EResponseComplete received >\n")); |
|
221 |
|
222 } break; |
|
223 case THTTPEvent::ESucceeded: |
|
224 { |
|
225 transCount++; |
|
226 iTransSucceeded++; |
|
227 iEngine->Utils().LogIt(_L("<ESucceeded received >\n")); |
|
228 if (transCount<=iTransNum) |
|
229 { |
|
230 if(iTransSucceeded==iTransNum) |
|
231 { |
|
232 iEngine->Utils().LogIt(_L("The test has PASSED")); |
|
233 CActiveScheduler::Stop(); |
|
234 } |
|
235 } |
|
236 else |
|
237 { |
|
238 iTestFail=1; |
|
239 iEngine->Utils().LogIt(_L("<The Test will fail:less than %d ESucceeded have been received>\n"),iTransNum); |
|
240 } |
|
241 } break; |
|
242 case THTTPEvent::EFailed: |
|
243 { |
|
244 TInt statusCode = aTransaction.Response().StatusCode(); |
|
245 iEngine->Utils().LogIt(_L("Status Code: %d \n"),statusCode); |
|
246 } break; |
|
247 default: |
|
248 { |
|
249 iEngine->Utils().LogIt(_L("<unrecognised event>\n %d"),aEvent.iStatus); |
|
250 iEngine->Utils().LogIt(_L("Test Failed\n")); |
|
251 iEngine->PressAnyKey(); |
|
252 CActiveScheduler::Stop(); |
|
253 } |
|
254 break; |
|
255 } |
|
256 } |
|
257 |
|
258 |
|
259 TBool C3DigestAuthTransactions::GetCredentialsL(const TUriC8& /*aURI*/, RString aRealm, RStringF /*aAuthenticationType*/, RString& aUsername, RString& aPassword) |
|
260 { |
|
261 if (!iSetCredentials) |
|
262 return EFalse; |
|
263 |
|
264 iSetCredentials =EFalse; //resetting |
|
265 |
|
266 _LIT8(KUsername, "scooby"); |
|
267 _LIT8(KPassword, "doo"); |
|
268 |
|
269 RStringPool stringPool = aRealm.Pool(); |
|
270 aUsername = stringPool.OpenStringL(KUsername); |
|
271 aPassword = stringPool.OpenStringL(KPassword); |
|
272 return ETrue; |
|
273 } |