|
1 /* |
|
2 * Copyright (c) 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 "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 #include <stdio.h> |
|
19 #include <string> |
|
20 #include <x509certchain.h> |
|
21 #include <memory> |
|
22 |
|
23 #include "TestHarness.h" |
|
24 |
|
25 #include "javastorage.h" |
|
26 #include "javastorageexception.h" |
|
27 #include "javastoragenames.h" |
|
28 #include "javauid.h" |
|
29 #include "javaprocessconstants.h" |
|
30 #include "javasymbianoslayer.h" |
|
31 #include "javaregistry.h" |
|
32 #include "javaregistryentry.h" |
|
33 #include "logger.h" |
|
34 #include "mjavaattribute.h" |
|
35 #include "storagetestutils.h" |
|
36 |
|
37 #include "javacommonutils.h" |
|
38 |
|
39 using namespace std; |
|
40 using namespace Java; |
|
41 using namespace java::storage; |
|
42 using namespace java::util; |
|
43 |
|
44 const JavaStorageApplicationEntry_t createEntry(const wstring& aUid, |
|
45 const wstring& aName, |
|
46 const wstring& aValue); |
|
47 |
|
48 const JavaStorageApplicationEntry_t createValidCertsEntry( |
|
49 const wstring& aUid, |
|
50 const wstring& aCerts); |
|
51 |
|
52 TEST_GROUP(TestRegistryEntry) |
|
53 { |
|
54 JavaStorage* js; |
|
55 JavaStorageTestUtils* jtu; |
|
56 CActiveScheduler* newScheduler; |
|
57 |
|
58 TEST_SETUP() |
|
59 { |
|
60 newScheduler = new CActiveScheduler(); |
|
61 CActiveScheduler::Install(newScheduler); |
|
62 |
|
63 js = JavaStorage::createInstance(); |
|
64 jtu = new JavaStorageTestUtils(); |
|
65 } |
|
66 TEST_TEARDOWN() |
|
67 { |
|
68 try |
|
69 { |
|
70 js->rollbackTransaction(); |
|
71 js->close(); |
|
72 delete js; |
|
73 js = NULL; |
|
74 } |
|
75 catch (...) |
|
76 { |
|
77 // No can do |
|
78 } |
|
79 |
|
80 delete js; |
|
81 js = 0; |
|
82 delete jtu; |
|
83 jtu = 0; |
|
84 |
|
85 delete newScheduler; |
|
86 newScheduler = NULL; |
|
87 } |
|
88 }; |
|
89 |
|
90 /** |
|
91 * Test CJavaRegistryEntry::Uid() method. |
|
92 * 1. Application uid. |
|
93 * 2. Application suite uid. |
|
94 * NOTE: Invalid Uid cannot be tested as it cannot be queried. |
|
95 */ |
|
96 TEST(TestRegistryEntry, TestUid) |
|
97 { |
|
98 LOG(EJavaStorage, EInfo, "+TestUid"); |
|
99 |
|
100 JavaStorageApplicationEntry_t midlet1; |
|
101 JavaStorageEntry attr; |
|
102 |
|
103 Uid suite1Uid(L"[e22a4577]"); |
|
104 |
|
105 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
106 midlet1.insert(attr); |
|
107 |
|
108 Uid midlet1Uid(L"[e22a4588]"); |
|
109 |
|
110 attr.setEntry(ID, midlet1Uid.toString()); |
|
111 midlet1.insert(attr); |
|
112 |
|
113 js->open(); |
|
114 js->startTransaction(); |
|
115 |
|
116 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
117 |
|
118 JavaStorageApplicationEntry_t suite1; |
|
119 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
120 suite1.insert(attr); |
|
121 |
|
122 attr.setEntry(ID, suite1Uid.toString()); |
|
123 suite1.insert(attr); |
|
124 |
|
125 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
126 suite1.insert(attr); |
|
127 |
|
128 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
129 |
|
130 // Session must be committed before next use of Registry otherwise |
|
131 // it is locked. |
|
132 js->commitTransaction(); |
|
133 |
|
134 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
135 |
|
136 // 1. Application uid. |
|
137 TUid midletUid; |
|
138 uidToTUid(midlet1Uid, midletUid); |
|
139 |
|
140 CJavaRegistryEntry* entry = registry->RegistryEntryL(midletUid); |
|
141 CHECK(entry != NULL); |
|
142 CHECK(entry->Uid().iUid == midletUid.iUid); |
|
143 |
|
144 delete entry; |
|
145 entry = NULL; |
|
146 |
|
147 // 2. Application suite uid. |
|
148 TUid suiteUid; |
|
149 uidToTUid(suite1Uid, suiteUid); |
|
150 |
|
151 entry = registry->RegistryEntryL(suiteUid); |
|
152 CHECK(entry != NULL); |
|
153 CHECK(entry->Uid().iUid == suiteUid.iUid); |
|
154 |
|
155 delete entry; |
|
156 entry = NULL; |
|
157 |
|
158 // Clean |
|
159 js->startTransaction(); |
|
160 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
161 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
162 js->commitTransaction(); |
|
163 js->close(); |
|
164 LOG(EJavaStorage, EInfo, "-TestUid"); |
|
165 } |
|
166 |
|
167 /** |
|
168 * Test CJavaRegistryEntry::Name() method. |
|
169 * 1. Application no name defined |
|
170 * 2. Application suite no name defined |
|
171 * 3. Application name. |
|
172 * 4. Application suite name. |
|
173 */ |
|
174 TEST(TestRegistryEntry, TestName) |
|
175 { |
|
176 LOG(EJavaStorage, EInfo, "+TestName"); |
|
177 JavaStorageApplicationEntry_t midlet1; |
|
178 JavaStorageEntry attr; |
|
179 |
|
180 Uid suite1Uid(L"[e2234577]"); |
|
181 |
|
182 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
183 midlet1.insert(attr); |
|
184 |
|
185 Uid midlet1Uid(L"[e2234588]"); |
|
186 |
|
187 attr.setEntry(ID, midlet1Uid.toString()); |
|
188 midlet1.insert(attr); |
|
189 |
|
190 js->open(); |
|
191 js->startTransaction(); |
|
192 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
193 |
|
194 JavaStorageApplicationEntry_t suite1; |
|
195 attr.setEntry(ID, suite1Uid.toString()); |
|
196 suite1.insert(attr); |
|
197 |
|
198 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
199 suite1.insert(attr); |
|
200 |
|
201 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
202 js->commitTransaction(); |
|
203 |
|
204 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
205 |
|
206 // 1. Application uid. |
|
207 TUid midletUid; |
|
208 uidToTUid(midlet1Uid, midletUid); |
|
209 |
|
210 CJavaRegistryEntry* entry = registry->RegistryEntryL(midletUid); |
|
211 CHECK(entry != NULL); |
|
212 |
|
213 // 1. Application no name defined |
|
214 CHECK(entry->Name() == KNullDesC); |
|
215 |
|
216 // 2. Application suite no name defined |
|
217 TUid suiteUid; |
|
218 uidToTUid(suite1Uid, suiteUid); |
|
219 |
|
220 delete entry; |
|
221 entry = NULL; |
|
222 |
|
223 entry = registry->RegistryEntryL(suiteUid); |
|
224 CHECK(entry != NULL); |
|
225 CHECK(entry->Name() == KNullDesC); |
|
226 |
|
227 delete entry; |
|
228 entry = NULL; |
|
229 |
|
230 JavaStorageApplicationEntry_t midlet2; |
|
231 |
|
232 Uid suite2Uid(L"[e2224577]"); |
|
233 |
|
234 attr.setEntry(PACKAGE_ID, suite2Uid.toString()); |
|
235 midlet2.insert(attr); |
|
236 |
|
237 Uid midlet2Uid(L"[e2224588]"); |
|
238 |
|
239 attr.setEntry(ID, midlet2Uid.toString()); |
|
240 midlet2.insert(attr); |
|
241 |
|
242 wstring midlet2Name = L"MIDlet2"; |
|
243 attr.setEntry(NAME, midlet2Name); |
|
244 midlet2.insert(attr); |
|
245 |
|
246 js->open(); |
|
247 js->startTransaction(); |
|
248 |
|
249 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet2)); |
|
250 |
|
251 wstring suite2Name = L"MySuite2"; |
|
252 JavaStorageApplicationEntry_t suite2; |
|
253 attr.setEntry(PACKAGE_NAME, suite2Name); |
|
254 suite2.insert(attr); |
|
255 |
|
256 attr.setEntry(ID, suite2Uid.toString()); |
|
257 suite2.insert(attr); |
|
258 |
|
259 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
260 suite2.insert(attr); |
|
261 |
|
262 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
263 |
|
264 // Session must be committed before next use of Registry otherwise |
|
265 // it is locked. |
|
266 js->commitTransaction(); |
|
267 |
|
268 // 3. Application name. |
|
269 uidToTUid(midlet2Uid, midletUid); |
|
270 |
|
271 entry = registry->RegistryEntryL(midletUid); |
|
272 CHECK(entry != NULL); |
|
273 |
|
274 const TDesC16& name = entry->Name(); |
|
275 HBufC16* refName = wstringToBuf(midlet2Name); |
|
276 CHECK(name.Compare(refName->Des()) == 0); |
|
277 |
|
278 delete refName; |
|
279 refName = NULL; |
|
280 delete entry; |
|
281 entry = NULL; |
|
282 |
|
283 // 4. Application suite name. |
|
284 uidToTUid(suite2Uid, suiteUid); |
|
285 |
|
286 entry = registry->RegistryEntryL(suiteUid); |
|
287 CHECK(entry != NULL); |
|
288 |
|
289 const TDesC16& name2 = entry->Name(); |
|
290 refName = wstringToBuf(suite2Name); |
|
291 CHECK(name2.Compare(refName->Des()) == 0); |
|
292 |
|
293 delete refName; |
|
294 refName = NULL; |
|
295 delete entry; |
|
296 entry = NULL; |
|
297 |
|
298 registry.reset(0); |
|
299 |
|
300 js->startTransaction(); |
|
301 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
302 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
303 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet2)); |
|
304 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite2)); |
|
305 js->commitTransaction(); |
|
306 js->close(); |
|
307 |
|
308 LOG(EJavaStorage, EInfo, "-TestName"); |
|
309 } |
|
310 |
|
311 /** |
|
312 * Test CJavaRegistryEntry::Type() method. |
|
313 * 1. Application type. |
|
314 * 2. Application suite type. |
|
315 */ |
|
316 TEST(TestRegistryEntry, TestType) |
|
317 { |
|
318 LOG(EJavaStorage, EInfo, "+TestType"); |
|
319 JavaStorageApplicationEntry_t midlet1; |
|
320 JavaStorageEntry attr; |
|
321 |
|
322 Uid suite1Uid(L"[ea234577]"); |
|
323 |
|
324 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
325 midlet1.insert(attr); |
|
326 |
|
327 Uid midlet1Uid(L"[ea234588]"); |
|
328 |
|
329 attr.setEntry(ID, midlet1Uid.toString()); |
|
330 midlet1.insert(attr); |
|
331 |
|
332 js->open(); |
|
333 js->startTransaction(); |
|
334 |
|
335 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
336 |
|
337 JavaStorageApplicationEntry_t suite1; |
|
338 attr.setEntry(ID, suite1Uid.toString()); |
|
339 suite1.insert(attr); |
|
340 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
341 suite1.insert(attr); |
|
342 |
|
343 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
344 |
|
345 // Session must be committed before next use of Registry otherwise |
|
346 // it is locked. |
|
347 js->commitTransaction(); |
|
348 |
|
349 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
350 |
|
351 // 1. Application uid. |
|
352 TUid midletUid; |
|
353 uidToTUid(midlet1Uid, midletUid); |
|
354 |
|
355 CJavaRegistryEntry* entry = registry->RegistryEntryL(midletUid); |
|
356 CHECK(entry != NULL); |
|
357 CHECK(entry->Type() == EMidp2Midlet); |
|
358 |
|
359 delete entry; |
|
360 entry = NULL; |
|
361 |
|
362 TUid suiteUid; |
|
363 uidToTUid(suite1Uid, suiteUid); |
|
364 |
|
365 entry = registry->RegistryEntryL(suiteUid); |
|
366 CHECK(entry != NULL); |
|
367 CHECK(entry->Type() == EMidp2MidletSuite); |
|
368 |
|
369 delete entry; |
|
370 entry = NULL; |
|
371 |
|
372 js->startTransaction(); |
|
373 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
374 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
375 js->commitTransaction(); |
|
376 js->close(); |
|
377 registry.reset(0); |
|
378 |
|
379 LOG(EJavaStorage, EInfo, "-TestType"); |
|
380 } |
|
381 |
|
382 /** |
|
383 * Test CJavaRegistryEntry::Drive() method. |
|
384 * 1. Get application suite drive. |
|
385 * 2. Get application drive. |
|
386 */ |
|
387 TEST(TestRegistryEntry, TestDrive) |
|
388 { |
|
389 LOG(EJavaStorage, EInfo, "+TestDrive"); |
|
390 JavaStorageApplicationEntry_t midlet1; |
|
391 JavaStorageEntry attr; |
|
392 |
|
393 Uid suite1Uid(L"[e01a4577]"); |
|
394 |
|
395 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
396 midlet1.insert(attr); |
|
397 |
|
398 Uid midlet1Uid(L"[e01a4588]"); |
|
399 |
|
400 attr.setEntry(ID, midlet1Uid.toString()); |
|
401 midlet1.insert(attr); |
|
402 |
|
403 js->open(); |
|
404 js->startTransaction(); |
|
405 |
|
406 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
407 |
|
408 JavaStorageApplicationEntry_t suite1; |
|
409 attr.setEntry(ID, suite1Uid.toString()); |
|
410 suite1.insert(attr); |
|
411 |
|
412 attr.setEntry(ROOT_PATH, L"e:\\private\\MIDlets\\[e01a4577]"); |
|
413 suite1.insert(attr); |
|
414 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
415 suite1.insert(attr); |
|
416 |
|
417 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
418 |
|
419 // Session must be committed before next use of Registry otherwise |
|
420 // it is locked. |
|
421 js->commitTransaction(); |
|
422 |
|
423 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
424 |
|
425 // 1. Application uid. |
|
426 TUid midletUid; |
|
427 uidToTUid(midlet1Uid, midletUid); |
|
428 |
|
429 CJavaRegistryEntry* entry = registry->RegistryEntryL(midletUid); |
|
430 CHECK(entry != NULL); |
|
431 CHECK(entry->Drive() == 4); // 4 represents e: |
|
432 |
|
433 delete entry; |
|
434 entry = NULL; |
|
435 |
|
436 TUid suiteUid; |
|
437 uidToTUid(suite1Uid, suiteUid); |
|
438 |
|
439 entry = registry->RegistryEntryL(suiteUid); |
|
440 CHECK(entry != NULL); |
|
441 CHECK(entry->Drive() == 4); // 4 represents c: |
|
442 |
|
443 delete entry; |
|
444 entry = NULL; |
|
445 |
|
446 js->startTransaction(); |
|
447 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
448 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
449 js->commitTransaction(); |
|
450 js->close(); |
|
451 registry.reset(0); |
|
452 |
|
453 LOG(EJavaStorage, EInfo, "-TestDrive"); |
|
454 } |
|
455 |
|
456 /** |
|
457 * Test CJavaRegistryEntry::AddributeL() method. |
|
458 * 1. Test no attributes in DB. NULL is returned. |
|
459 * 2. Test empty name. Leaves with KErrArgument. |
|
460 * 3. Test non-existing attribute. NULL is returned. |
|
461 * 4. Test existing application attribute. |
|
462 * 5. Test existing application suite attribute. |
|
463 * 6. Test trusted attribute. |
|
464 * 7. Test attribute VALUE not set i.e. empty. |
|
465 * NULL is returned. |
|
466 */ |
|
467 TEST(TestRegistryEntry, TestAttribute) |
|
468 { |
|
469 LOG(EJavaStorage, EInfo, "+TestAttribute"); |
|
470 JavaStorageApplicationEntry_t midlet1; |
|
471 JavaStorageEntry attr; |
|
472 |
|
473 Uid suite1Uid(L"[ebbb4577]"); |
|
474 |
|
475 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
476 midlet1.insert(attr); |
|
477 |
|
478 Uid midlet1Uid(L"[ebbb4588]"); |
|
479 |
|
480 attr.setEntry(ID, midlet1Uid.toString()); |
|
481 midlet1.insert(attr); |
|
482 |
|
483 js->open(); |
|
484 js->startTransaction(); |
|
485 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
486 |
|
487 JavaStorageApplicationEntry_t suite1; |
|
488 attr.setEntry(ID, suite1Uid.toString()); |
|
489 suite1.insert(attr); |
|
490 |
|
491 attr.setEntry(ROOT_PATH, L"e:\\private\\MIDlets\\[ebbb4577]"); |
|
492 suite1.insert(attr); |
|
493 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
494 suite1.insert(attr); |
|
495 |
|
496 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
497 js->commitTransaction(); |
|
498 |
|
499 // 1. Test no attributes in DB. |
|
500 TUid midletUid; |
|
501 uidToTUid(midlet1Uid, midletUid); |
|
502 |
|
503 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
504 |
|
505 CJavaRegistryEntry* entry = registry->RegistryEntryL(midletUid); |
|
506 CHECK(entry != NULL); |
|
507 |
|
508 // 1. non-existing attribute |
|
509 _LIT(KAttrName, "TestClass"); |
|
510 const MJavaAttribute* regAttr = entry->AttributeL(KAttrName); |
|
511 |
|
512 CHECK(regAttr == NULL); |
|
513 |
|
514 delete entry; |
|
515 entry = NULL; |
|
516 |
|
517 // Populate attributes |
|
518 JavaStorageApplicationEntry_t suiteAttribute; |
|
519 attr.setEntry(ID, suite1Uid.toString()); |
|
520 suiteAttribute.insert(attr); |
|
521 |
|
522 attr.setEntry(NAME, L"MIDlet-1"); |
|
523 suiteAttribute.insert(attr); |
|
524 |
|
525 attr.setEntry(VALUE, L""); |
|
526 suiteAttribute.insert(attr); |
|
527 |
|
528 attr.setEntry(TRUSTED, L"0", JavaStorageEntry::INT); |
|
529 suiteAttribute.insert(attr); |
|
530 |
|
531 js->startTransaction(); |
|
532 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
533 suiteAttribute.clear(); |
|
534 |
|
535 attr.setEntry(ID, suite1Uid.toString()); |
|
536 suiteAttribute.insert(attr); |
|
537 |
|
538 attr.setEntry(NAME, L"Jar-Size"); |
|
539 suiteAttribute.insert(attr); |
|
540 |
|
541 attr.setEntry(VALUE, L"2342"); |
|
542 suiteAttribute.insert(attr); |
|
543 |
|
544 attr.setEntry(TRUSTED, L"1", JavaStorageEntry::INT); |
|
545 suiteAttribute.insert(attr); |
|
546 |
|
547 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
548 suiteAttribute.clear(); |
|
549 |
|
550 attr.setEntry(ID, suite1Uid.toString()); |
|
551 suiteAttribute.insert(attr); |
|
552 |
|
553 attr.setEntry(NAME, L"TestClass"); |
|
554 suiteAttribute.insert(attr); |
|
555 |
|
556 attr.setEntry(VALUE, L"com.platform.test.app"); |
|
557 suiteAttribute.insert(attr); |
|
558 |
|
559 attr.setEntry(TRUSTED, L"0", JavaStorageEntry::INT); |
|
560 suiteAttribute.insert(attr); |
|
561 |
|
562 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
563 suiteAttribute.clear(); |
|
564 js->commitTransaction(); |
|
565 |
|
566 // 2. Test empty name. |
|
567 uidToTUid(midlet1Uid, midletUid); |
|
568 |
|
569 entry = registry->RegistryEntryL(midletUid); |
|
570 CHECK(entry != NULL); |
|
571 |
|
572 // 1. non-existing attribute |
|
573 _LIT(KAttrName2, ""); |
|
574 |
|
575 TRAPD(err, regAttr = entry->AttributeL(KAttrName2)); |
|
576 CHECK(KErrArgument == err); |
|
577 |
|
578 TRAP(err, regAttr = entry->AttributeL(KNullDesC)); |
|
579 CHECK(KErrArgument == err); |
|
580 |
|
581 // 3. Test non-existing attribute. |
|
582 _LIT(KAttrName3, "FOO_BAR"); |
|
583 regAttr = entry->AttributeL(KAttrName3); |
|
584 CHECK(regAttr == NULL); |
|
585 |
|
586 // 4. Test existing application attribute. |
|
587 _LIT(KAttrName4, "TestClass"); |
|
588 regAttr = entry->AttributeL(KAttrName4); |
|
589 CHECK(regAttr != NULL); |
|
590 |
|
591 _LIT(KAttrValue, "com.platform.test.app"); |
|
592 |
|
593 CHECK(regAttr->Name() == KAttrName4); |
|
594 CHECK(regAttr->Value() == KAttrValue); |
|
595 CHECK(regAttr->Trusted() == EFalse); |
|
596 |
|
597 delete regAttr; |
|
598 regAttr = NULL; |
|
599 |
|
600 delete entry; |
|
601 entry = NULL; |
|
602 |
|
603 // 5. Test existing application suite attribute. |
|
604 TUid suiteUid; |
|
605 uidToTUid(suite1Uid, suiteUid); |
|
606 |
|
607 entry = registry->RegistryEntryL(suiteUid); |
|
608 CHECK(entry != NULL); |
|
609 |
|
610 regAttr = entry->AttributeL(KAttrName4); |
|
611 CHECK(regAttr != NULL); |
|
612 |
|
613 CHECK(regAttr->Name() == KAttrName4); |
|
614 CHECK(regAttr->Value() == KAttrValue); |
|
615 CHECK(regAttr->Trusted() == EFalse); |
|
616 |
|
617 delete regAttr; |
|
618 regAttr = NULL; |
|
619 |
|
620 // 6. Test trusted attribute. |
|
621 _LIT(KAttrName5, "Jar-Size"); |
|
622 |
|
623 regAttr = entry->AttributeL(KAttrName5); |
|
624 CHECK(regAttr != NULL); |
|
625 |
|
626 _LIT(KAttrValue2, "2342"); |
|
627 |
|
628 CHECK(regAttr->Name() == KAttrName5); |
|
629 CHECK(regAttr->Value() == KAttrValue2); |
|
630 CHECK(regAttr->Trusted() == true); |
|
631 |
|
632 delete regAttr; |
|
633 regAttr = NULL; |
|
634 |
|
635 // 7. Test attribute VALUE not set i.e. empty. |
|
636 _LIT(KAttrName6, "MIDlet-1"); |
|
637 |
|
638 regAttr = entry->AttributeL(KAttrName6); |
|
639 CHECK(regAttr == NULL); |
|
640 |
|
641 delete entry; |
|
642 entry = NULL; |
|
643 |
|
644 js->startTransaction(); |
|
645 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
646 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
647 |
|
648 suiteAttribute.clear(); |
|
649 attr.setEntry(ID, suite1Uid.toString()); |
|
650 suiteAttribute.insert(attr); |
|
651 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
652 |
|
653 js->commitTransaction(); |
|
654 js->close(); |
|
655 registry.reset(0); |
|
656 |
|
657 LOG(EJavaStorage, EInfo, "-TestAttribute"); |
|
658 } |
|
659 |
|
660 /** |
|
661 * Test CJavaRegistryEntry::AddributesL() method. |
|
662 * 1. Test no attributes in DB. Emtry array returned. |
|
663 * 2. Test existing application attribute. |
|
664 * 3. Test existing application suite attribute. |
|
665 * 4. Test query twice i.e. Caching. |
|
666 */ |
|
667 TEST(TestRegistryEntry, TestAttributes) |
|
668 { |
|
669 LOG(EJavaStorage, EInfo, "+TestAttributes"); |
|
670 JavaStorageApplicationEntry_t midlet1; |
|
671 JavaStorageEntry attr; |
|
672 |
|
673 Uid suite1Uid(L"[eaaaa577]"); |
|
674 |
|
675 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
676 midlet1.insert(attr); |
|
677 |
|
678 Uid midlet1Uid(L"[eaaaa588]"); |
|
679 |
|
680 attr.setEntry(ID, midlet1Uid.toString()); |
|
681 midlet1.insert(attr); |
|
682 |
|
683 js->open(); |
|
684 js->startTransaction(); |
|
685 |
|
686 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
687 |
|
688 JavaStorageApplicationEntry_t suite1; |
|
689 attr.setEntry(ID, suite1Uid.toString()); |
|
690 suite1.insert(attr); |
|
691 |
|
692 attr.setEntry(ROOT_PATH, L"e:\\private\\MIDlets\\[eaaaa577]"); |
|
693 suite1.insert(attr); |
|
694 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
695 suite1.insert(attr); |
|
696 |
|
697 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
698 |
|
699 // Session must be committed before next use of Registry otherwise |
|
700 // it is locked. |
|
701 js->commitTransaction(); |
|
702 |
|
703 TUid midletUid; |
|
704 uidToTUid(midlet1Uid, midletUid); |
|
705 |
|
706 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
707 CJavaRegistryEntry* entry = registry->RegistryEntryL(midletUid); |
|
708 CHECK(entry != NULL); |
|
709 |
|
710 // 1. Test no attributes in DB. |
|
711 const RPointerArray<MJavaAttribute>& attrs = entry->AttributesL(); |
|
712 CHECK(attrs.Count() == 0); |
|
713 |
|
714 delete entry; |
|
715 entry = NULL; |
|
716 |
|
717 // Populate attributes |
|
718 JavaStorageApplicationEntry_t suiteAttribute; |
|
719 attr.setEntry(ID, suite1Uid.toString()); |
|
720 suiteAttribute.insert(attr); |
|
721 |
|
722 attr.setEntry(NAME, L"MIDlet-1"); |
|
723 suiteAttribute.insert(attr); |
|
724 |
|
725 attr.setEntry(VALUE, L"Greaat MIDlet"); |
|
726 suiteAttribute.insert(attr); |
|
727 |
|
728 attr.setEntry(TRUSTED, L"0", JavaStorageEntry::INT); |
|
729 suiteAttribute.insert(attr); |
|
730 |
|
731 js->startTransaction(); |
|
732 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
733 suiteAttribute.clear(); |
|
734 |
|
735 attr.setEntry(ID, suite1Uid.toString()); |
|
736 suiteAttribute.insert(attr); |
|
737 |
|
738 attr.setEntry(NAME, L"Jar-Size"); |
|
739 suiteAttribute.insert(attr); |
|
740 |
|
741 attr.setEntry(VALUE, L"2342"); |
|
742 suiteAttribute.insert(attr); |
|
743 |
|
744 attr.setEntry(TRUSTED, L"1", JavaStorageEntry::INT); |
|
745 suiteAttribute.insert(attr); |
|
746 |
|
747 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
748 suiteAttribute.clear(); |
|
749 |
|
750 attr.setEntry(ID, suite1Uid.toString()); |
|
751 suiteAttribute.insert(attr); |
|
752 |
|
753 attr.setEntry(NAME, L"TestClass"); |
|
754 suiteAttribute.insert(attr); |
|
755 |
|
756 attr.setEntry(VALUE, L"com.platform.test.app"); |
|
757 suiteAttribute.insert(attr); |
|
758 |
|
759 attr.setEntry(TRUSTED, L"0", JavaStorageEntry::INT); |
|
760 suiteAttribute.insert(attr); |
|
761 |
|
762 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
763 suiteAttribute.clear(); |
|
764 |
|
765 // Session must be committed before next use of Registry otherwise |
|
766 // it is locked. |
|
767 js->commitTransaction(); |
|
768 |
|
769 // 2. Test existing application attributes. |
|
770 entry = registry->RegistryEntryL(midletUid); |
|
771 CHECK(entry != NULL); |
|
772 |
|
773 const RPointerArray<MJavaAttribute>& attrs2 = entry->AttributesL(); |
|
774 CHECK(attrs2.Count() == 3); |
|
775 |
|
776 // Cannot quarantee order so size check should be OK. |
|
777 |
|
778 delete entry; |
|
779 entry = NULL; |
|
780 |
|
781 // 3. Test existing application suite attribute. |
|
782 TUid suiteUid; |
|
783 uidToTUid(suite1Uid, suiteUid); |
|
784 |
|
785 entry = registry->RegistryEntryL(suiteUid); |
|
786 CHECK(entry != NULL); |
|
787 |
|
788 const RPointerArray<MJavaAttribute>& attrs3 = entry->AttributesL(); |
|
789 CHECK(attrs3.Count() == 3); |
|
790 |
|
791 // Cannot quarantee order so size check should be OK. |
|
792 |
|
793 // 4. Test query twice i.e. Caching. |
|
794 const RPointerArray<MJavaAttribute>& attrs4 = entry->AttributesL(); |
|
795 CHECK(attrs4.Count() == 3); |
|
796 |
|
797 delete entry; |
|
798 entry = NULL; |
|
799 |
|
800 js->startTransaction(); |
|
801 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
802 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
803 |
|
804 suiteAttribute.clear(); |
|
805 attr.setEntry(ID, suite1Uid.toString()); |
|
806 suiteAttribute.insert(attr); |
|
807 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, suiteAttribute)); |
|
808 |
|
809 js->commitTransaction(); |
|
810 js->close(); |
|
811 registry.reset(0); |
|
812 LOG(EJavaStorage, EInfo, "-TestAttributes"); |
|
813 } |
|
814 |
|
815 /** |
|
816 * Test CJavaRegistryEntry::NumberOfCertificateChains() method. |
|
817 * 1. Test when suite no cert chains. Size is 0. |
|
818 * 2. Test when suite one cert chains. Size is 1. |
|
819 * 3. Test when suite three cert chains. size is 3. |
|
820 */ |
|
821 TEST(TestRegistryEntry, TestNumberOfCertificateChains) |
|
822 { |
|
823 LOG(EJavaStorage, EInfo, "+TestNumberOfCertificateChains"); |
|
824 |
|
825 JavaStorageApplicationEntry_t midlet1; |
|
826 JavaStorageEntry attr; |
|
827 |
|
828 Uid suite1Uid(L"[e22bf577]"); |
|
829 |
|
830 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
831 midlet1.insert(attr); |
|
832 |
|
833 Uid midlet1Uid(L"[e22bf588]"); |
|
834 |
|
835 attr.setEntry(ID, midlet1Uid.toString()); |
|
836 midlet1.insert(attr); |
|
837 |
|
838 js->open(); |
|
839 js->startTransaction(); |
|
840 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
841 |
|
842 JavaStorageApplicationEntry_t suite1; |
|
843 attr.setEntry(PACKAGE_NAME, L"TestCertChains"); |
|
844 suite1.insert(attr); |
|
845 |
|
846 attr.setEntry(ID, suite1Uid.toString()); |
|
847 suite1.insert(attr); |
|
848 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
849 suite1.insert(attr); |
|
850 |
|
851 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
852 js->commitTransaction(); |
|
853 js->close(); |
|
854 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
855 |
|
856 TUid suiteUid; |
|
857 uidToTUid(suite1Uid, suiteUid); |
|
858 |
|
859 // 1. Test when no cert chains. Size is 0. |
|
860 CJavaRegistryEntry* entry = registry->RegistryEntryL(suiteUid); |
|
861 CHECK(entry != NULL); |
|
862 CHECK(entry->NumberOfCertificateChains() == 0); |
|
863 |
|
864 delete entry; |
|
865 entry = NULL; |
|
866 |
|
867 TUid midletUid; |
|
868 uidToTUid(midlet1Uid, midletUid); |
|
869 |
|
870 // 1.2 Test no certs via app. |
|
871 entry = registry->RegistryEntryL(midletUid); |
|
872 CHECK(entry != NULL); |
|
873 CHECK(entry->NumberOfCertificateChains() == 0); |
|
874 |
|
875 delete entry; |
|
876 entry = NULL; |
|
877 |
|
878 // 2. Test when one cert chains. Size is 1. |
|
879 |
|
880 JavaStorageApplicationEntry_t certEntry; |
|
881 JavaStorageApplicationEntry_t validcertsEntry; |
|
882 |
|
883 js->open(); |
|
884 validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1"); |
|
885 js->write(MIDP_PACKAGE_TABLE, validcertsEntry); |
|
886 |
|
887 certEntry = createEntry(suite1Uid.toString(), |
|
888 L"MIDlet-Certificate-1-1", |
|
889 L"abc123"); |
|
890 |
|
891 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
892 js->close(); |
|
893 |
|
894 entry = registry->RegistryEntryL(suiteUid); |
|
895 CHECK(entry != NULL); |
|
896 CHECK(entry->NumberOfCertificateChains() == 1); |
|
897 |
|
898 delete entry; |
|
899 entry = NULL; |
|
900 |
|
901 // 2.2 Test no certs via app. |
|
902 entry = registry->RegistryEntryL(midletUid); |
|
903 CHECK(entry != NULL); |
|
904 CHECK(entry->NumberOfCertificateChains() == 1); |
|
905 |
|
906 delete entry; |
|
907 entry = NULL; |
|
908 |
|
909 js->open(); |
|
910 js->startTransaction(); |
|
911 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry)); |
|
912 CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry)); |
|
913 js->commitTransaction(); |
|
914 js->close(); |
|
915 |
|
916 |
|
917 // 3. Test when three cert chains. size is 3. |
|
918 certEntry.clear(); |
|
919 validcertsEntry.clear(); |
|
920 |
|
921 validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1,2,3"); |
|
922 |
|
923 js->open(); |
|
924 js->write(MIDP_PACKAGE_TABLE, validcertsEntry); |
|
925 |
|
926 certEntry = createEntry(suite1Uid.toString(), |
|
927 L"MIDlet-Certificate-1-1", |
|
928 L"abc123"); |
|
929 |
|
930 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
931 |
|
932 JavaStorageApplicationEntry_t certEntry2; |
|
933 certEntry2 = createEntry(suite1Uid.toString(), |
|
934 L"MIDlet-Certificate-2-1", |
|
935 L"def456"); |
|
936 |
|
937 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
938 |
|
939 JavaStorageApplicationEntry_t certEntry3; |
|
940 certEntry3 = createEntry(suite1Uid.toString(), |
|
941 L"MIDlet-Certificate-3-1", |
|
942 L"fooBar"); |
|
943 |
|
944 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
945 js->close(); |
|
946 |
|
947 entry = registry->RegistryEntryL(suiteUid); |
|
948 CHECK(entry != NULL); |
|
949 CHECK(entry->NumberOfCertificateChains() == 3); |
|
950 |
|
951 delete entry; |
|
952 entry = NULL; |
|
953 |
|
954 // 2.2 Test no certs via app. |
|
955 entry = registry->RegistryEntryL(midletUid); |
|
956 CHECK(entry != NULL); |
|
957 CHECK(entry->NumberOfCertificateChains() == 3); |
|
958 |
|
959 delete entry; |
|
960 entry = NULL; |
|
961 |
|
962 js->open(); |
|
963 js->startTransaction(); |
|
964 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry)); |
|
965 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2)); |
|
966 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3)); |
|
967 CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry)); |
|
968 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
969 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
970 js->commitTransaction(); |
|
971 js->close(); |
|
972 LOG(EJavaStorage, EInfo, "-TestNumberOfCertificateChains"); |
|
973 } |
|
974 |
|
975 /** |
|
976 * Test CJavaRegistryEntry::CertificateChain() method. |
|
977 * 1. Test when suite no cert chains. |
|
978 * 2. Test when suite one cert chains. |
|
979 * 3. Test when suite three cert chains. |
|
980 * 4. Test index greater than. |
|
981 * 5. Test index less than i.e. -1. |
|
982 * 6. Test install application suite and do CX509CertChain::DecodeCertsL(). |
|
983 */ |
|
984 TEST(TestRegistryEntry, TestCertificateChain) |
|
985 { |
|
986 LOG(EJavaStorage, EInfo, "+TestCertificateChain"); |
|
987 |
|
988 JavaStorageApplicationEntry_t midlet1; |
|
989 JavaStorageEntry attr; |
|
990 |
|
991 Uid suite1Uid(L"[e22bf577]"); |
|
992 |
|
993 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
994 midlet1.insert(attr); |
|
995 |
|
996 Uid midlet1Uid(L"[e22bf588]"); |
|
997 |
|
998 attr.setEntry(ID, midlet1Uid.toString()); |
|
999 midlet1.insert(attr); |
|
1000 |
|
1001 js->open(); |
|
1002 js->startTransaction(); |
|
1003 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
1004 |
|
1005 JavaStorageApplicationEntry_t suite1; |
|
1006 attr.setEntry(PACKAGE_NAME, L"TestCertChains"); |
|
1007 suite1.insert(attr); |
|
1008 |
|
1009 attr.setEntry(ID, suite1Uid.toString()); |
|
1010 suite1.insert(attr); |
|
1011 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
1012 suite1.insert(attr); |
|
1013 |
|
1014 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
1015 js->commitTransaction(); |
|
1016 js->close(); |
|
1017 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
1018 |
|
1019 TUid suiteUid; |
|
1020 uidToTUid(suite1Uid, suiteUid); |
|
1021 |
|
1022 // 1. Test when no cert chains. Size is 0. |
|
1023 CJavaRegistryEntry* entry = registry->RegistryEntryL(suiteUid); |
|
1024 CHECK(entry != NULL); |
|
1025 CHECK(entry->NumberOfCertificateChains() == 0); |
|
1026 CHECK(entry->CertificateChain(0) == KNullDesC8); |
|
1027 |
|
1028 delete entry; |
|
1029 entry = NULL; |
|
1030 |
|
1031 TUid midletUid; |
|
1032 uidToTUid(midlet1Uid, midletUid); |
|
1033 |
|
1034 // 1.2 Test no certs via app. |
|
1035 entry = registry->RegistryEntryL(midletUid); |
|
1036 CHECK(entry != NULL); |
|
1037 CHECK(entry->NumberOfCertificateChains() == 0); |
|
1038 CHECK(entry->CertificateChain(0) == KNullDesC8); |
|
1039 |
|
1040 delete entry; |
|
1041 entry = NULL; |
|
1042 |
|
1043 // 2. Test when one cert chains. Size is 1. |
|
1044 JavaStorageApplicationEntry_t certEntry; |
|
1045 JavaStorageApplicationEntry_t validcertsEntry; |
|
1046 |
|
1047 js->open(); |
|
1048 validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1"); |
|
1049 js->write(MIDP_PACKAGE_TABLE, validcertsEntry); |
|
1050 |
|
1051 certEntry = createEntry(suite1Uid.toString(), |
|
1052 L"MIDlet-Certificate-1-1", |
|
1053 L"YWJjMTIz"); // abc123 as base64 encoded. |
|
1054 |
|
1055 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
1056 js->close(); |
|
1057 |
|
1058 _LIT8(KCertChain1, "abc123"); |
|
1059 |
|
1060 entry = registry->RegistryEntryL(suiteUid); |
|
1061 CHECK(entry != NULL); |
|
1062 CHECK(entry->NumberOfCertificateChains() == 1); |
|
1063 CHECK(entry->CertificateChain(0).Compare(KCertChain1) == 0); |
|
1064 |
|
1065 delete entry; |
|
1066 entry = NULL; |
|
1067 |
|
1068 // 2.2 Test no certs via app. |
|
1069 entry = registry->RegistryEntryL(midletUid); |
|
1070 CHECK(entry != NULL); |
|
1071 CHECK(entry->NumberOfCertificateChains() == 1); |
|
1072 CHECK(entry->CertificateChain(0).Compare(KCertChain1) == 0); |
|
1073 |
|
1074 delete entry; |
|
1075 entry = NULL; |
|
1076 |
|
1077 js->open(); |
|
1078 js->startTransaction(); |
|
1079 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry)); |
|
1080 CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry)); |
|
1081 js->commitTransaction(); |
|
1082 js->close(); |
|
1083 |
|
1084 |
|
1085 // 3. Test when three cert chains. size is 3. |
|
1086 certEntry.clear(); |
|
1087 validcertsEntry.clear(); |
|
1088 |
|
1089 validcertsEntry = createValidCertsEntry(suite1Uid.toString(), L"1,2,3"); |
|
1090 |
|
1091 js->open(); |
|
1092 js->write(MIDP_PACKAGE_TABLE, validcertsEntry); |
|
1093 |
|
1094 certEntry = createEntry(suite1Uid.toString(), |
|
1095 L"MIDlet-Certificate-1-1", |
|
1096 L"YWJjMTIz"); // abc123 |
|
1097 |
|
1098 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry); |
|
1099 |
|
1100 JavaStorageApplicationEntry_t certEntry2; |
|
1101 certEntry2 = createEntry(suite1Uid.toString(), |
|
1102 L"MIDlet-Certificate-2-1", |
|
1103 L"ZGVmNDU2"); // def456 as base 64 encoded. |
|
1104 |
|
1105 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2); |
|
1106 |
|
1107 JavaStorageApplicationEntry_t certEntry3; |
|
1108 certEntry3 = createEntry(suite1Uid.toString(), |
|
1109 L"MIDlet-Certificate-3-1", |
|
1110 L"Zm9vQmFy"); // fooBar |
|
1111 |
|
1112 js->write(APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3); |
|
1113 js->close(); |
|
1114 |
|
1115 entry = registry->RegistryEntryL(suiteUid); |
|
1116 CHECK(entry != NULL); |
|
1117 CHECK(entry->NumberOfCertificateChains() == 3); |
|
1118 CHECK(entry->CertificateChain(0).Compare(KCertChain1) == 0); |
|
1119 _LIT8(KCertChain2, "def456"); |
|
1120 CHECK(entry->CertificateChain(1).Compare(KCertChain2) == 0); |
|
1121 _LIT8(KCertChain3, "fooBar"); |
|
1122 CHECK(entry->CertificateChain(2).Compare(KCertChain3) == 0); |
|
1123 |
|
1124 delete entry; |
|
1125 entry = NULL; |
|
1126 |
|
1127 // 2.2 Test no certs via app. |
|
1128 entry = registry->RegistryEntryL(midletUid); |
|
1129 CHECK(entry != NULL); |
|
1130 CHECK(entry->NumberOfCertificateChains() == 3); |
|
1131 CHECK(entry->CertificateChain(0).Compare(KCertChain1) == 0); |
|
1132 CHECK(entry->CertificateChain(1).Compare(KCertChain2) == 0); |
|
1133 CHECK(entry->CertificateChain(2).Compare(KCertChain3) == 0); |
|
1134 |
|
1135 // 4. Test index greater than. |
|
1136 CHECK(entry->CertificateChain(3) == KNullDesC8); |
|
1137 |
|
1138 // 5. Test index less than i.e. -1. |
|
1139 CHECK(entry->CertificateChain(-1) == KNullDesC8); |
|
1140 |
|
1141 delete entry; |
|
1142 entry = NULL; |
|
1143 |
|
1144 js->open(); |
|
1145 js->startTransaction(); |
|
1146 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry)); |
|
1147 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry2)); |
|
1148 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_ATTRIBUTES_TABLE, certEntry3)); |
|
1149 CHECK(jtu->remove(*js, MIDP_PACKAGE_TABLE, validcertsEntry)); |
|
1150 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
1151 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
1152 js->commitTransaction(); |
|
1153 js->close(); |
|
1154 |
|
1155 // 6. Test install application suite and do CX509CertChain::DecodeCertsL() |
|
1156 RProcess rJavaInstaller; |
|
1157 TFileName fileName; |
|
1158 TBuf<400> commandLine; |
|
1159 |
|
1160 // Build command line used to pass all necessary info to Java Installer |
|
1161 std::auto_ptr<HBufC> installerStarterDll( |
|
1162 stringToDes(java::runtime::JAVA_INSTALLER_STARTER_DLL)); |
|
1163 commandLine = installerStarterDll->Des(); |
|
1164 commandLine.Append(_L(" install -jad=c:\\Signed.jad")); |
|
1165 commandLine.Append(_L(" -silent -upgrade=yes -ocsp=no")); |
|
1166 commandLine.Append(_L(" -download=no -upgrade_data=yes")); |
|
1167 |
|
1168 // start JavaInstaller |
|
1169 std::auto_ptr<HBufC> installerProcess( |
|
1170 stringToDes(java::runtime::JAVA_PROCESS)); |
|
1171 TInt err = rJavaInstaller.Create(installerProcess->Des(), commandLine); |
|
1172 |
|
1173 TRequestStatus status; |
|
1174 |
|
1175 if (KErrNone == err) |
|
1176 { |
|
1177 LOG(EJavaStorage, EInfo, "Calling Logon"); |
|
1178 // This call will wait until Java Installer exits (or panics) |
|
1179 rJavaInstaller.Logon(status); |
|
1180 |
|
1181 LOG(EJavaStorage, EInfo, "Calling Resume"); |
|
1182 rJavaInstaller.Resume(); |
|
1183 } |
|
1184 else |
|
1185 { |
|
1186 ELOG1(EJavaStorage, "Cannot start Installer, error %d", err); |
|
1187 User::Leave(err); |
|
1188 } |
|
1189 |
|
1190 LOG(EJavaStorage, EInfo, "Calling RProcess::Close"); |
|
1191 // free resources before returning |
|
1192 rJavaInstaller.Close(); |
|
1193 |
|
1194 // now wait until Java Installer exits |
|
1195 User::WaitForRequest(status); |
|
1196 |
|
1197 registry.reset(CJavaRegistry::NewL()); |
|
1198 RArray<TUid> uids; |
|
1199 registry->GetRegistryEntryUidsL(EGeneralPackage, uids); |
|
1200 |
|
1201 CHECK(uids.Count() == 1); // One app installed |
|
1202 |
|
1203 CJavaRegistryEntry* regEntry = registry->RegistryEntryL(uids[0]); |
|
1204 CHECK(regEntry != NULL); |
|
1205 CHECK(regEntry->NumberOfCertificateChains() > 0); |
|
1206 |
|
1207 const TDesC8& chain = regEntry->CertificateChain(0); |
|
1208 |
|
1209 auto_ptr<CX509CertChain> theChain(new(ELeave)CX509CertChain()); |
|
1210 |
|
1211 CArrayPtrFlat<CX509Certificate>* certsArray = |
|
1212 theChain->DecodeCertsL(chain); |
|
1213 CHECK(certsArray->Count() > 0); // This verifies X509 decode succeeded. |
|
1214 |
|
1215 certsArray->ResetAndDestroy(); |
|
1216 delete regEntry; |
|
1217 regEntry = NULL; |
|
1218 registry.reset(0); |
|
1219 |
|
1220 // UNINSTALL |
|
1221 // Build command line used to pass all necessary info to Java Installer |
|
1222 commandLine = installerStarterDll->Des(); |
|
1223 commandLine.Append(_L(" uninstall -uid=")); |
|
1224 TUidName uidName = (uids[0]).Name(); |
|
1225 commandLine.Append(uidName); |
|
1226 uids.Reset(); |
|
1227 uids.Close(); |
|
1228 commandLine.Append(_L(" -silent")); |
|
1229 |
|
1230 // start JavaInstaller |
|
1231 err = rJavaInstaller.Create(installerProcess->Des(), commandLine); |
|
1232 |
|
1233 status = KRequestPending; |
|
1234 |
|
1235 if (KErrNone == err) |
|
1236 { |
|
1237 LOG(EJavaStorage, EInfo, "Calling Logon"); |
|
1238 // This call will wait until Java Installer exits (or panics) |
|
1239 rJavaInstaller.Logon(status); |
|
1240 |
|
1241 LOG(EJavaStorage, EInfo, "Calling Resume"); |
|
1242 rJavaInstaller.Resume(); |
|
1243 } |
|
1244 else |
|
1245 { |
|
1246 ELOG1(EJavaStorage, "Cannot start Installer, error %d", err); |
|
1247 User::Leave(err); |
|
1248 } |
|
1249 |
|
1250 LOG(EJavaStorage, EInfo, "Calling RProcess::Close"); |
|
1251 // free resources before returning |
|
1252 rJavaInstaller.Close(); |
|
1253 |
|
1254 // now wait until Java Installer exits |
|
1255 User::WaitForRequest(status); |
|
1256 |
|
1257 LOG(EJavaStorage, EInfo, "-TestCertificateChain"); |
|
1258 } |
|
1259 |
|
1260 /** |
|
1261 * Test CJavaRegistryEntry::DrmContentId() method. |
|
1262 * 1. Test DrmContentId no ContentId. |
|
1263 * 2. Test DrmContentId DRM protected file SuiteEntry. |
|
1264 * 3. Test DrmContentId DRM protected file AppEntry. |
|
1265 */ |
|
1266 TEST(TestRegistryEntry, TestDrmContentId) |
|
1267 { |
|
1268 LOG(EJavaStorage, EInfo, "+TestDrmContentId"); |
|
1269 |
|
1270 JavaStorageApplicationEntry_t midlet1; |
|
1271 JavaStorageEntry attr; |
|
1272 |
|
1273 Uid suite1Uid(L"[e22ba577]"); |
|
1274 |
|
1275 attr.setEntry(PACKAGE_ID, suite1Uid.toString()); |
|
1276 midlet1.insert(attr); |
|
1277 |
|
1278 Uid midlet1Uid(L"[e22ba588]"); |
|
1279 |
|
1280 attr.setEntry(ID, midlet1Uid.toString()); |
|
1281 midlet1.insert(attr); |
|
1282 |
|
1283 js->open(); |
|
1284 js->startTransaction(); |
|
1285 CHECK(jtu->populate(*js, APPLICATION_TABLE, midlet1)); |
|
1286 |
|
1287 JavaStorageApplicationEntry_t suite1; |
|
1288 attr.setEntry(PACKAGE_NAME, L"MySuite"); |
|
1289 suite1.insert(attr); |
|
1290 |
|
1291 attr.setEntry(JAR_PATH, L"c:\\HelloWorld1.jar"); |
|
1292 |
|
1293 suite1.insert(attr); |
|
1294 |
|
1295 attr.setEntry(ID, suite1Uid.toString()); |
|
1296 suite1.insert(attr); |
|
1297 attr.setEntry(MEDIA_ID, L"-124614446"); |
|
1298 suite1.insert(attr); |
|
1299 |
|
1300 CHECK(jtu->populate(*js, APPLICATION_PACKAGE_TABLE, suite1)); |
|
1301 js->commitTransaction(); |
|
1302 |
|
1303 auto_ptr<CJavaRegistry> registry(CJavaRegistry::NewL()); |
|
1304 |
|
1305 // 1. Test DrmContentId no DRM protected file. |
|
1306 TUid suiteUid; |
|
1307 uidToTUid(suite1Uid, suiteUid); |
|
1308 |
|
1309 CJavaRegistryEntry* entry = registry->RegistryEntryL(suiteUid); |
|
1310 CHECK(entry != NULL); |
|
1311 CHECK(entry->DrmContentId() == KNullDesC); |
|
1312 |
|
1313 delete entry; |
|
1314 entry = NULL; |
|
1315 |
|
1316 JavaStorageApplicationEntry_t updateEntry; |
|
1317 attr.setEntry(JAR_PATH, L"c:\\HelloWorld2.jar"); |
|
1318 updateEntry.insert(attr); |
|
1319 attr.setEntry(CONTENT_ID, L"MyGreatContentId"); |
|
1320 updateEntry.insert(attr); |
|
1321 |
|
1322 // 2. Test DrmContentId DRM protected file SuiteEntry. |
|
1323 js->startTransaction(); |
|
1324 CHECK(jtu->update(*js, APPLICATION_PACKAGE_TABLE, updateEntry, suite1)); |
|
1325 js->commitTransaction(); |
|
1326 |
|
1327 entry = registry->RegistryEntryL(suiteUid); |
|
1328 CHECK(entry != NULL); |
|
1329 _LIT(KContentId, "MyGreatContentId"); |
|
1330 CHECK(entry->DrmContentId().Compare(KContentId) == 0); |
|
1331 |
|
1332 delete entry; |
|
1333 entry = NULL; |
|
1334 |
|
1335 // 3. Test DrmContentId DRM protected file AppEntry. |
|
1336 TUid midletUid; |
|
1337 uidToTUid(midlet1Uid, midletUid); |
|
1338 |
|
1339 entry = registry->RegistryEntryL(midletUid); |
|
1340 CHECK(entry != NULL); |
|
1341 CHECK(entry->DrmContentId().Compare(KContentId) == 0); |
|
1342 |
|
1343 delete entry; |
|
1344 entry = NULL; |
|
1345 |
|
1346 js->startTransaction(); |
|
1347 CHECK(jtu->remove(*js, APPLICATION_TABLE, midlet1)); |
|
1348 CHECK(jtu->remove(*js, APPLICATION_PACKAGE_TABLE, updateEntry)); |
|
1349 js->commitTransaction(); |
|
1350 js->close(); |
|
1351 LOG(EJavaStorage, EInfo, "-TestDrmContentId"); |
|
1352 } |
|
1353 |
|
1354 const JavaStorageApplicationEntry_t createEntry(const wstring& aUid, |
|
1355 const wstring& aName, |
|
1356 const wstring& aValue) |
|
1357 { |
|
1358 JavaStorageApplicationEntry_t entry; |
|
1359 JavaStorageEntry attr; |
|
1360 |
|
1361 attr.setEntry(ID, aUid); |
|
1362 entry.insert(attr); |
|
1363 |
|
1364 attr.setEntry(NAME, aName); |
|
1365 entry.insert(attr); |
|
1366 |
|
1367 attr.setEntry(VALUE, aValue); |
|
1368 entry.insert(attr); |
|
1369 |
|
1370 return entry; |
|
1371 } |
|
1372 |
|
1373 const JavaStorageApplicationEntry_t createValidCertsEntry(const wstring& aUid, |
|
1374 const wstring& aCerts) |
|
1375 { |
|
1376 JavaStorageApplicationEntry_t entry; |
|
1377 JavaStorageEntry attr; |
|
1378 |
|
1379 attr.setEntry(ID, aUid); |
|
1380 entry.insert(attr); |
|
1381 |
|
1382 attr.setEntry(VALID_CERTS, aCerts); |
|
1383 entry.insert(attr); |
|
1384 |
|
1385 return entry; |
|
1386 } |
|
1387 |