|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <bautils.h> |
|
20 #include <s32file.h> |
|
21 #include <test/testexecutelog.h> |
|
22 |
|
23 #include "authserver/authmgrclient.h" |
|
24 #include "authserver/identity.h" |
|
25 #include "tauthcliservstep.h" |
|
26 |
|
27 using namespace AuthServer; |
|
28 |
|
29 class CRegActive : public CActive |
|
30 { |
|
31 public: |
|
32 CRegActive(RAuthMgrClient& aClient, CIdentity*& aResult, TBool aStop = ETrue) : |
|
33 CActive(EPriorityNormal), |
|
34 iFirstTime(true), |
|
35 iClient(aClient), |
|
36 iResult(aResult), |
|
37 iStop(aStop) |
|
38 { |
|
39 CActiveScheduler::Add(this); |
|
40 } |
|
41 void doReg() |
|
42 { |
|
43 SetActive(); |
|
44 TRequestStatus* status = &iStatus; |
|
45 User::RequestComplete(status, KErrNone); |
|
46 iFirstTime = ETrue; |
|
47 } |
|
48 void DoCancel() |
|
49 { |
|
50 } |
|
51 void RunL() |
|
52 { |
|
53 if (iFirstTime) |
|
54 { |
|
55 SetActive(); |
|
56 iStatus = KRequestPending; |
|
57 iClient.RegisterIdentityL(iResult, _L("SOMENAME"), iStatus); |
|
58 iFirstTime = false; |
|
59 } |
|
60 else |
|
61 { |
|
62 if (iStop) |
|
63 { |
|
64 CActiveScheduler::Stop(); |
|
65 } |
|
66 iErr = iStatus.Int(); |
|
67 } |
|
68 } |
|
69 TBool iFirstTime; |
|
70 RAuthMgrClient& iClient; |
|
71 CIdentity*& iResult; |
|
72 TBool iStop; |
|
73 TInt iErr; |
|
74 }; |
|
75 |
|
76 class CTrainActive : public CActive |
|
77 { |
|
78 public: |
|
79 CTrainActive(RAuthMgrClient& aClient, TBool aStop = ETrue) : |
|
80 CActive(EPriorityNormal), |
|
81 iClient(aClient), |
|
82 iResult(EFail), |
|
83 iRunCount(0), |
|
84 iStop(aStop) |
|
85 { |
|
86 CActiveScheduler::Add(this); |
|
87 } |
|
88 void doTrain() |
|
89 { |
|
90 |
|
91 SetActive(); |
|
92 TRequestStatus* status = &iStatus; |
|
93 User::RequestComplete(status, KErrNone); |
|
94 iRunCount = 0; |
|
95 } |
|
96 void DoCancel() |
|
97 { |
|
98 } |
|
99 void RunL() |
|
100 { |
|
101 iErr = iStatus.Int(); |
|
102 if (iStatus.Int() != KErrNone) |
|
103 { |
|
104 } |
|
105 switch (iRunCount) |
|
106 { |
|
107 case 0: |
|
108 iStatus = KRequestPending; |
|
109 iAe = AuthExpr(0x10274104); |
|
110 iId = 0; |
|
111 |
|
112 iClient.AuthenticateL(*iAe, 10, EFalse, EFalse, iId, iStatus); |
|
113 SetActive(); |
|
114 |
|
115 break; |
|
116 case 1: |
|
117 delete iAe; |
|
118 delete iId; |
|
119 iStatus = KRequestPending; |
|
120 iClient.TrainPlugin(22, 0x10274104, iStatus); |
|
121 SetActive(); |
|
122 |
|
123 break; |
|
124 case 2: |
|
125 iResult = iStatus.Int() == KErrNone ? EPass : EFail; |
|
126 iErr = iStatus.Int(); |
|
127 if (iStop) |
|
128 { |
|
129 CActiveScheduler::Stop(); |
|
130 } |
|
131 |
|
132 break; |
|
133 default: |
|
134 iResult = EFail; |
|
135 |
|
136 if (iStop) |
|
137 { |
|
138 CActiveScheduler::Stop(); |
|
139 } |
|
140 } |
|
141 ++iRunCount; |
|
142 } |
|
143 RAuthMgrClient& iClient; |
|
144 TVerdict iResult; |
|
145 TInt iRunCount; |
|
146 CAuthExpression* iAe; |
|
147 CIdentity* iId; |
|
148 TBool iStop; |
|
149 TInt iErr; |
|
150 }; |
|
151 |
|
152 class CTrainActive2 : public CActive |
|
153 { |
|
154 public: |
|
155 CTrainActive2(RAuthMgrClient& aClient, TBool aStop = ETrue) : |
|
156 CActive(EPriorityNormal), |
|
157 iClient(aClient), |
|
158 iRunCount(0), |
|
159 iStop(aStop) |
|
160 { |
|
161 CActiveScheduler::Add(this); |
|
162 } |
|
163 void doTrain() |
|
164 { |
|
165 SetActive(); |
|
166 iClient.TrainPlugin(22, 0x10274105, iStatus); |
|
167 } |
|
168 void DoCancel() |
|
169 { |
|
170 } |
|
171 void RunL() |
|
172 { |
|
173 iErr = iStatus.Int(); |
|
174 if (iStop) |
|
175 { |
|
176 CActiveScheduler::Stop(); |
|
177 } |
|
178 } |
|
179 |
|
180 RAuthMgrClient& iClient; |
|
181 TInt iRunCount; |
|
182 CAuthExpression* iAe; |
|
183 CIdentity* iId; |
|
184 TBool iStop; |
|
185 TInt iErr; |
|
186 }; |
|
187 |
|
188 class CCancelActive : public CActive |
|
189 { |
|
190 public: |
|
191 CCancelActive(RAuthMgrClient& aClient) : |
|
192 CActive(EPriorityNormal), |
|
193 iClient(aClient), |
|
194 iResult(EFail), |
|
195 iRunCount(0) |
|
196 { |
|
197 CActiveScheduler::Add(this); |
|
198 } |
|
199 void doIdCancel() |
|
200 { |
|
201 SetActive(); |
|
202 TRequestStatus* status = &iStatus; |
|
203 User::RequestComplete(status, KErrNone); |
|
204 iMode = 1; |
|
205 iRunCount = 0; |
|
206 } |
|
207 void doRegCancel() |
|
208 { |
|
209 SetActive(); |
|
210 TRequestStatus* status = &iStatus; |
|
211 User::RequestComplete(status, KErrNone); |
|
212 iMode = 2; |
|
213 iRunCount = 0; |
|
214 } |
|
215 void doTrainCancel() |
|
216 { |
|
217 SetActive(); |
|
218 TRequestStatus* status = &iStatus; |
|
219 User::RequestComplete(status, KErrNone); |
|
220 iMode = 0; |
|
221 iRunCount = 0; |
|
222 } |
|
223 void DoCancel() |
|
224 { |
|
225 } |
|
226 void RunL() |
|
227 { |
|
228 if (iStatus.Int() != KErrNone) |
|
229 { |
|
230 //RDebug::Printf("CCancelActive error: %d", iStatus.Int()); |
|
231 } |
|
232 switch (iRunCount) |
|
233 { |
|
234 case 0: |
|
235 iStatus = KRequestPending; |
|
236 iAe = AuthExpr(0x10274105); |
|
237 iId = 0; |
|
238 switch (iMode) |
|
239 { |
|
240 case 2: |
|
241 iClient.RegisterIdentityL(iId, _L("RegCancelID"), iStatus); |
|
242 break; |
|
243 case 1: |
|
244 iClient.AuthenticateL(*iAe, 0, EFalse, ETrue, iId, iStatus); |
|
245 break; |
|
246 case 0: |
|
247 iClient.TrainPlugin(22, 0x10274105, iStatus); |
|
248 break; |
|
249 } |
|
250 SetActive(); |
|
251 User::After(1000000); |
|
252 iClient.Cancel(); |
|
253 |
|
254 break; |
|
255 case 1: |
|
256 //iStatus = KRequestPending; |
|
257 |
|
258 delete iAe; |
|
259 delete iId; |
|
260 //SetActive(); |
|
261 |
|
262 //break; |
|
263 case 2: |
|
264 iResult = iStatus.Int() == KErrCancel ? EPass : EFail; |
|
265 CActiveScheduler::Stop(); |
|
266 |
|
267 break; |
|
268 default: |
|
269 iResult = EFail; |
|
270 CActiveScheduler::Stop(); |
|
271 } |
|
272 ++iRunCount; |
|
273 } |
|
274 RAuthMgrClient& iClient; |
|
275 TVerdict iResult; |
|
276 TInt iRunCount; |
|
277 CAuthExpression* iAe; |
|
278 CIdentity* iId; |
|
279 TInt iMode; |
|
280 }; |
|
281 |
|
282 |
|
283 CTStepMgrClient::CTStepMgrClient() |
|
284 { |
|
285 SetTestStepName(KTStepMgrClient); |
|
286 } |
|
287 |
|
288 |
|
289 TBool CTStepMgrClient::TestMultiRegisterL(RAuthMgrClient& client) |
|
290 { |
|
291 CIdentity* result = 0; |
|
292 CRegActive active(client, result); |
|
293 |
|
294 CIdentity* result2 = 0; |
|
295 RAuthMgrClient client2; |
|
296 User::LeaveIfError(client2.Connect()); |
|
297 CleanupClosePushL(client2); |
|
298 |
|
299 CRegActive active2(client2, result2, EFalse); |
|
300 |
|
301 active.doReg(); |
|
302 active2.doReg(); |
|
303 |
|
304 CActiveScheduler::Start(); |
|
305 |
|
306 TEST(active.iErr == KErrNone); |
|
307 TEST(active2.iErr == KErrServerBusy); |
|
308 |
|
309 delete result; |
|
310 delete result2; |
|
311 CleanupStack::PopAndDestroy(&client2); |
|
312 return ETrue; |
|
313 |
|
314 } |
|
315 |
|
316 TBool CTStepMgrClient::TestRegister(RAuthMgrClient& client) |
|
317 { |
|
318 CIdentity* result = 0; |
|
319 CRegActive active(client, result); |
|
320 |
|
321 active.doReg(); |
|
322 |
|
323 CActiveScheduler::Start(); |
|
324 if (result == 0) |
|
325 { |
|
326 return EFalse; |
|
327 } |
|
328 |
|
329 INFO_PRINTF3(_L("Id = %d , KeyLength = %d\n"), result->Id(), result->Key().KeyData().Size()); |
|
330 delete result; |
|
331 result = 0; |
|
332 return ETrue; |
|
333 } |
|
334 |
|
335 TBool CTStepMgrClient::TestMultiTrainL(RAuthMgrClient& client) |
|
336 { |
|
337 CTrainActive2 active(client); |
|
338 active.doTrain(); |
|
339 |
|
340 RAuthMgrClient client2; |
|
341 User::LeaveIfError(client2.Connect()); |
|
342 CleanupClosePushL(client2); |
|
343 |
|
344 CTrainActive2 active2(client2, EFalse); |
|
345 active2.doTrain(); |
|
346 |
|
347 CActiveScheduler::Start(); |
|
348 |
|
349 TEST(active.iErr == KErrAuthServPluginCancelled); // blocking plugin returns |
|
350 // cancelled if left to |
|
351 // complete |
|
352 TEST(active2.iErr == KErrServerBusy); |
|
353 |
|
354 CleanupStack::PopAndDestroy(&client2); |
|
355 INFO_PRINTF3(_L("Training Result (%d,%d)\n"), |
|
356 active.iErr, |
|
357 active2.iErr); |
|
358 |
|
359 return true; |
|
360 } |
|
361 |
|
362 |
|
363 TBool CTStepMgrClient::TestTrain(RAuthMgrClient& client) |
|
364 { |
|
365 CTrainActive active(client); |
|
366 active.doTrain(); |
|
367 CActiveScheduler::Start(); |
|
368 INFO_PRINTF2(_L("Training Result = %d\n"), active.iResult == EPass); |
|
369 return active.iResult == EPass; |
|
370 } |
|
371 |
|
372 TBool CTStepMgrClient::TestCancellation(RAuthMgrClient& client) |
|
373 { |
|
374 CCancelActive active(client); |
|
375 |
|
376 active.doTrainCancel(); |
|
377 CActiveScheduler::Start(); |
|
378 TEST(active.iResult == EPass); |
|
379 INFO_PRINTF2(_L("Training Cancel Result = %d\n"), active.iResult == EPass); |
|
380 |
|
381 active.doTrainCancel(); |
|
382 CActiveScheduler::Start(); |
|
383 TEST(active.iResult == EPass); |
|
384 INFO_PRINTF2(_L("Training Cancel Result = %d\n"), active.iResult == EPass); |
|
385 |
|
386 active.doTrainCancel(); |
|
387 CActiveScheduler::Start(); |
|
388 TEST(active.iResult == EPass); |
|
389 INFO_PRINTF2(_L("Training Cancel Result = %d\n"), active.iResult == EPass); |
|
390 |
|
391 //User::After(5000000); |
|
392 active.doIdCancel(); |
|
393 CActiveScheduler::Start(); |
|
394 TEST(active.iResult == EPass); |
|
395 INFO_PRINTF2(_L("Id Cancel Result = %d\n"), active.iResult == EPass); |
|
396 |
|
397 active.doIdCancel(); |
|
398 CActiveScheduler::Start(); |
|
399 TEST(active.iResult == EPass); |
|
400 INFO_PRINTF2(_L("Id Cancel Result = %d\n"), active.iResult == EPass); |
|
401 |
|
402 active.doRegCancel(); |
|
403 CActiveScheduler::Start(); |
|
404 TEST(active.iResult == EPass); |
|
405 INFO_PRINTF2(_L("Registration Cancel Result = %d\n"), active.iResult == EPass); |
|
406 |
|
407 return active.iResult == EPass; |
|
408 } |
|
409 |
|
410 TVerdict CTStepMgrClient::doTestStepL() |
|
411 { |
|
412 TInt r = 0; |
|
413 |
|
414 if (TestStepResult() != EPass) |
|
415 { |
|
416 INFO_PRINTF1(_L("Previous step failed")); |
|
417 |
|
418 return TestStepResult(); |
|
419 } |
|
420 |
|
421 |
|
422 WaitForServerToReleaseDb(); |
|
423 |
|
424 |
|
425 TDriveUnit sysDrive (RFs::GetSystemDrive()); |
|
426 TDriveName sysDriveName (sysDrive.Name()); |
|
427 |
|
428 _LIT(KDbSrcFile ,"\\authdb0.db"); |
|
429 TBuf<64> dbSrcFileName (sysDriveName); |
|
430 dbSrcFileName.Append(KDbSrcFile); |
|
431 |
|
432 TBuf<128> dbName(KDbName); |
|
433 dbName[0] = 'A' + sysDrive; |
|
434 |
|
435 r = BaflUtils::CopyFile(iFs, dbSrcFileName, dbName); |
|
436 |
|
437 INFO_PRINTF2(_L("File copy returned %d"), r); |
|
438 |
|
439 User::LeaveIfError(r); |
|
440 |
|
441 |
|
442 |
|
443 __UHEAP_MARK; |
|
444 SetTestStepResult(EPass); |
|
445 |
|
446 CActiveScheduler::Install(iActSchd); |
|
447 |
|
448 |
|
449 RAuthMgrClient mgrclient; |
|
450 User::LeaveIfError(mgrclient.Connect()); |
|
451 CleanupClosePushL(mgrclient); |
|
452 |
|
453 mgrclient.RemoveIdentityL(2); |
|
454 |
|
455 |
|
456 RIdentityIdArray ids; |
|
457 mgrclient.IdentitiesL(ids); |
|
458 CleanupClosePushL(ids); |
|
459 |
|
460 TESTL(ids.Count() == 3); |
|
461 |
|
462 // ensure each expected identity occurs once. |
|
463 // (This technique is simple but doesn't generalise.) |
|
464 TInt sum = 0; |
|
465 for (TInt i = 0; i < 3; ++i) |
|
466 { |
|
467 TIdentityId id = ids[i]; |
|
468 TESTL(id == 1 || id == 3 || id == 22); |
|
469 sum += id; |
|
470 } |
|
471 TESTL(sum == 1 + 3 + 22); |
|
472 |
|
473 CleanupStack::PopAndDestroy(&ids); |
|
474 |
|
475 TEST(TestRegister(mgrclient)); |
|
476 |
|
477 mgrclient.IdentitiesL(ids); |
|
478 CleanupClosePushL(ids); |
|
479 TEST(ids.Count() == 4); |
|
480 CleanupStack::PopAndDestroy(&ids); |
|
481 |
|
482 TEST(TestTrain(mgrclient)); |
|
483 |
|
484 INFO_PRINTF1(_L("Testing cancellation")); |
|
485 TEST(TestCancellation(mgrclient)); |
|
486 |
|
487 INFO_PRINTF1(_L("Testing simultaneous registrations are blocked")); |
|
488 TEST(TestMultiRegisterL(mgrclient)); |
|
489 |
|
490 INFO_PRINTF1(_L("Testing simultaneous trainings are blocked")); |
|
491 TestMultiTrainL(mgrclient); |
|
492 |
|
493 // Last plugin can't be removed |
|
494 TRAPD(err, mgrclient.ForgetPluginL(22,0x10274104)); |
|
495 TEST(err == KErrAuthServCanNotRemoveLastPlugin); |
|
496 |
|
497 CleanupStack::PopAndDestroy(1, &mgrclient); |
|
498 |
|
499 __UHEAP_MARKEND; |
|
500 return EPass; |
|
501 } |