tizen 2.3 release
[framework/web/wearable/wrt-security.git] / tests / ace / TestSuite06.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /*
17  * @file    TestSuite06.cpp
18  * @author  unknown
19  * @version 1.0
20  * @brief   Test cases for AceDAO implementation.
21  */
22 #include <iostream>
23 #include <string>
24 #include <memory>
25
26 #include <dpl/foreach.h>
27 #include <dpl/test/test_runner.h>
28
29 #include <ace-dao-rw/AceDAO.h>
30 #include <ace/Attribute.h>
31 #include <ace/Preference.h>
32 #include <ace/SettingsLogic.h>
33
34 #define TEST_WIDGET_HANDLE  23
35
36 #define TESTSUITE06(n) \
37 RUNNER_TEST(ts06_ace_dao_ ## n)
38
39 #define CLEANENV \
40     do{                                              \
41         AceDB::AceDAO::clearWidgetDevCapSettings();  \
42         AceDB::AceDAO::clearDevCapSettings();        \
43     }while(0)
44
45 using namespace AceDB;
46
47 int operator==(const Attribute& left, const Attribute& right)
48 {
49    return ( (*left.getName() == *right.getName()));
50 }
51
52 bool UserSettingsAgreed(std::list<PermissionTriple>* expected,
53                         std::list<PermissionTriple>* allRules)
54 {
55     if (allRules->empty() && expected->empty())
56     {
57         return true;
58     }
59
60     std::list<PermissionTriple>::iterator itA;
61     FOREACH(itE, *expected)
62     {
63         if (itE->devCap.empty()){
64             return false;  //some error occur
65         }
66
67         for (itA = allRules->begin(); itA !=  allRules->end(); ++itA){
68             if (itA->appId == itE->appId &&
69                 itA->devCap == itE->devCap)
70             {
71                 if (itA->access == itE->access){
72                     break;
73                 }
74                 else{
75                     return false; //optimization
76                 }
77             }
78         }
79
80         if (itA == allRules->end())
81         {
82             if (itE->access == Preference::PREFERENCE_DEFAULT)
83             {  // this value is not set in DB
84                 continue;
85             }
86             //if we are here -it means that expected values doesnt exist in DB
87             return false;
88         }
89         else
90         {
91             continue;   //go to next expected attr
92         }
93     }
94
95     //it means that all required values exist in DB
96     return true;
97 }
98
99
100 bool UserSettingNotStored(std::list<PermissionTriple>* userSettings,
101                           std::string res,
102                           WidgetHandle handler,
103                           Preference pref)
104 {
105     if (userSettings->empty())
106     {
107         return true;
108     }
109
110     FOREACH(iter, *userSettings)
111     {
112         if (iter->appId == handler && iter->devCap == res){
113             if (iter->access == pref){
114                 return false;  //this value has been saved
115             }
116             else{
117                 continue;  //value has been saved
118             }
119         }
120     }
121
122     return true;
123 }
124
125
126
127 bool ResourceSettingsAgreed(
128         std::list< std::pair<const std::string*,Preference> > *expected,
129         std::map<std::string, Preference>* allRules)
130 {
131     std::list< std::pair<const std::string*,Preference> >::iterator itE;
132     std::map<std::string, Preference>::iterator itA;
133
134     FOREACH(itE, *expected)
135     {
136         itA = allRules->find(*(itE->first));
137         if (itA != allRules->end() && itA->second == itE->second)
138         {
139             continue;
140         }
141         else
142         {
143             return false;
144         }
145     }
146
147     return true;
148 }
149
150 bool ResourceSettingsEqual(
151         std::list< std::pair<const std::string*,Preference> > * actual,
152         std::map<std::string, Preference>* expected)
153 {
154     bool flag = false;
155     FOREACH(iterA, *actual)
156     {
157         FOREACH(iterE, *expected)
158         {
159             if (*(iterA->first) == iterE->first &&
160                 iterA->second == iterE->second)
161             {
162                 flag = true;
163             }
164         }
165         if (!flag)
166         {
167             return false;
168         }
169         flag = false;
170     }
171
172     return true;
173 }
174
175 //bool VSPAssertEqual(Verdict actual, Verdict expected){
176 //    return (actual == expected);
177 //}
178
179
180 bool AttributeEqual(AttributeSet  actual, AttributeSet expected){
181     return (actual == expected);
182 }
183
184 bool ResourceSettingEqual(std::map<std::string, Preference>*  rSettings,
185                           std::string res,
186                           Preference pref)
187 {
188     std::map<std::string, Preference>::iterator iter = rSettings->find(res);
189
190     if (iter != rSettings->end() && iter->second ==pref)
191     {
192         return true;
193     }
194
195     return false;
196 }
197
198
199 bool  UserSettingEqual(std::list<PermissionTriple>* userSettings,
200                        std::string res,
201                        WidgetHandle handler,
202                        Preference pref)
203 {
204         if (userSettings->empty() && pref == Preference::PREFERENCE_DEFAULT)
205         {
206             return true;
207         }
208         FOREACH(iter, *userSettings)
209         {
210             if (iter->devCap.empty())
211             {
212                 return false; //some error occurred
213             }
214             if (iter->appId == handler && iter->devCap == res){
215                 if (iter->access == pref)
216                 {
217                     return true;
218                 }
219                 else
220                 {
221                     return false;
222                 }
223             }
224         }
225
226     return false;
227 }
228
229 RUNNER_TEST_GROUP_INIT(ACE_TEST_SUITE_06)
230
231 //Test does  verdict PERMIT is saved when validity is once
232 TESTSUITE06(01){
233     CLEANENV;
234     AttributeSet attributeSet;
235     std::string tmp("atrS");
236     std::string tmpValue("Buu");
237     BaseAttributePtr atr(new Attribute(&tmp,
238                                        Attribute::Match::Equal,
239                                        Attribute::Type::Subject));
240     DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
241     attributeSet.insert(atr);
242
243     AceDAO::setPolicyResult(attributeSet,
244                             ExtendedPolicyResult(PolicyEffect::PERMIT));
245     OptionalExtendedPolicyResult opt =
246         AceDAO::getPolicyResult(attributeSet);
247
248     PolicyResult effect(PolicyEffect::DENY);
249     if (!opt.IsNull()) {
250         effect = opt->policyResult;
251     }
252
253     RUNNER_ASSERT(effect == PolicyEffect::PERMIT);
254 }
255
256 TESTSUITE06(02){
257     CLEANENV;
258     AttributeSet attributeSet;
259     std::string tmp("atrS");
260     std::string tmpValue("Buu");
261     BaseAttributePtr atr(new Attribute(&tmp,
262                                        Attribute::Match::Equal,
263                                        Attribute::Type::Subject));
264     DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
265     attributeSet.insert(atr);
266
267     AceDAO::setPolicyResult(attributeSet,
268                             ExtendedPolicyResult(PolicyEffect::DENY));
269     OptionalExtendedPolicyResult opt = AceDAO::getPolicyResult(attributeSet);
270
271     PolicyResult effect(PolicyEffect::PERMIT);
272     if (!opt.IsNull()) {
273         effect = opt->policyResult;
274     }
275
276     RUNNER_ASSERT(effect == PolicyEffect::DENY);
277 }
278
279 TESTSUITE06(03){
280     CLEANENV;
281     AttributeSet attributeSet;
282     std::string tmp("atrS");
283     std::string tmpValue("Buu");
284     BaseAttributePtr atr(new Attribute(&tmp,
285                                        Attribute::Match::Equal,
286                                        Attribute::Type::Subject));
287     DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
288     attributeSet.insert(atr);
289
290     AceDAO::setPolicyResult(attributeSet,
291                             ExtendedPolicyResult(PolicyEffect::PROMPT_ONESHOT));
292     OptionalExtendedPolicyResult opt = AceDAO::getPolicyResult(attributeSet);
293
294     PolicyResult effect(PolicyEffect::DENY);
295     if (!opt.IsNull()) {
296         effect = opt->policyResult;
297     }
298
299     RUNNER_ASSERT(effect == PolicyEffect::PROMPT_ONESHOT);
300 }
301
302 TESTSUITE06(04){
303     CLEANENV;
304     AttributeSet attributeSet;
305     std::string tmp("atrS");
306     std::string tmpValue("Buu");
307     BaseAttributePtr atr(new Attribute(&tmp,
308                                        Attribute::Match::Equal,
309                                        Attribute::Type::Subject));
310     DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
311     attributeSet.insert(atr);
312
313     AceDAO::setPolicyResult(attributeSet,
314                             ExtendedPolicyResult(PolicyEffect::PROMPT_SESSION));
315     OptionalExtendedPolicyResult opt = AceDAO::getPolicyResult(attributeSet);
316
317     PolicyResult effect(PolicyEffect::DENY);
318     if (!opt.IsNull()) {
319         effect = opt->policyResult;
320     }
321
322     RUNNER_ASSERT(effect == PolicyEffect::PROMPT_SESSION);
323 }
324
325 TESTSUITE06(05){
326     CLEANENV;
327     AttributeSet attributeSet;
328     std::string tmp("atrS");
329     std::string tmpValue("Buu");
330     BaseAttributePtr atr(new Attribute(&tmp,
331                                        Attribute::Match::Equal,
332                                        Attribute::Type::Subject));
333     DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
334     attributeSet.insert(atr);
335
336     AceDAO::setPolicyResult(attributeSet,
337                             ExtendedPolicyResult(PolicyEffect::PROMPT_BLANKET));
338     OptionalExtendedPolicyResult opt = AceDAO::getPolicyResult(attributeSet);
339
340     PolicyResult effect(PolicyEffect::DENY);
341     if (!opt.IsNull()) {
342         effect = opt->policyResult;
343     }
344
345     RUNNER_ASSERT(effect == PolicyEffect::PROMPT_BLANKET);
346 }
347
348 TESTSUITE06(06){
349     CLEANENV;
350     AttributeSet attributeSet;
351     std::string tmp("atrS");
352     std::string tmpValue("Buu");
353     BaseAttributePtr atr(new Attribute(&tmp,
354                                        Attribute::Match::Equal,
355                                        Attribute::Type::Subject));
356     DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
357     attributeSet.insert(atr);
358
359     AceDAO::setPolicyResult(attributeSet,
360                             ExtendedPolicyResult(PolicyDecision::NOT_APPLICABLE));
361     OptionalExtendedPolicyResult opt = AceDAO::getPolicyResult(attributeSet);
362
363     PolicyResult effect(PolicyEffect::DENY);
364     if (!opt.IsNull()) {
365         effect = opt->policyResult;
366     }
367
368     RUNNER_ASSERT(effect == PolicyDecision::NOT_APPLICABLE);
369 }
370
371 TESTSUITE06(07){
372     CLEANENV;
373     AttributeSet attributeSet;
374     std::string tmp("atrS");
375     std::string tmpValue("Buu");
376     BaseAttributePtr atr(new Attribute(&tmp,
377                                        Attribute::Match::Equal,
378                                        Attribute::Type::Subject));
379     DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
380     attributeSet.insert(atr);
381
382     AceDAO::setPolicyResult(attributeSet,
383                             ExtendedPolicyResult(PolicyResult::UNDETERMINED));
384     OptionalExtendedPolicyResult opt = AceDAO::getPolicyResult(attributeSet);
385
386     PolicyResult effect(PolicyEffect::DENY);
387     if (!opt.IsNull()) {
388         effect = opt->policyResult;
389     }
390
391     RUNNER_ASSERT(effect == PolicyResult::UNDETERMINED);
392 }
393
394 TESTSUITE06(08){
395     CLEANENV;
396     int ruleId = 4;
397     std::string tmp("atrS2");
398     std::string tmpValue("Buu2");
399     std::string session = "jlakjhqrwebn234324987";
400
401     AceDAO::setPromptDecision(TEST_WIDGET_HANDLE,
402                               ruleId,
403                               DPL::FromUTF8String(session),
404                               PromptDecision::ALLOW_ALWAYS);
405
406     OptionalCachedPromptDecision decision =
407         AceDAO::getPromptDecision(TEST_WIDGET_HANDLE,
408                                   ruleId);
409
410     DPL::String session1;
411     PromptDecision dec = PromptDecision::DENY_FOR_SESSION;
412     if (!decision.IsNull()){
413         dec = (*decision).decision;
414         if (!decision.IsNull()) {
415             session1 = *((*decision).session);
416         }
417     }
418     RUNNER_ASSERT(dec == PromptDecision::ALLOW_ALWAYS);
419     RUNNER_ASSERT(DPL::ToUTF8String(session1) == session);
420 }
421
422 TESTSUITE06(09){
423     CLEANENV;
424     int ruleId = 5;
425     std::string tmp("atrS2");
426     std::string tmpValue("Buu2");
427
428     AceDAO::setPromptDecision(TEST_WIDGET_HANDLE,
429                                   ruleId,
430                                   DPL::OptionalString(),
431                                   PromptDecision::ALLOW_FOR_SESSION);
432
433     OptionalCachedPromptDecision decision =
434         AceDAO::getPromptDecision(TEST_WIDGET_HANDLE, ruleId);
435
436     PromptDecision dec = PromptDecision::DENY_FOR_SESSION;
437     if (!decision.IsNull()){
438         dec = (*decision).decision;
439         RUNNER_ASSERT((*decision).session.IsNull());
440     }
441     RUNNER_ASSERT(dec == PromptDecision::ALLOW_FOR_SESSION);
442 }
443
444 ///*findVerdict*/
445 //
446 //void AceDAOTester::test3()
447 //{
448 //// Tests does verdict is stored for validity always
449 //    Request  request("subject", "resource");
450 //    AttributeSet attributeSet;
451 //    std::string tmp("atrS3");
452 //    std::string tmpValue("Buu3");
453 //    BaseAttributePtr atr(
454 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
455 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
456 //    attributeSet.insert(atr);
457 //    Verdict ver = Verdict::VERDICT_PERMIT;
458 //    Validity val = Validity::ALWAYS;
459 //    std::string session = getSession();
460 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
461 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
462 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_PERMIT);
463 //    handleResult(result, "find Verdict test 3");
464 //}
465 ///*findVerdict*/
466 //
467 //void AceDAOTester::test4()
468 //{
469 ////tests does verdict is propertly stored (NOT saved)when session is Validity::ONCE
470 ////and verdict is DENY
471 //    Request  request("subject", "resource");
472 //    AttributeSet attributeSet;
473 //    std::string tmp("atrS4");
474 //    std::string tmpValue("Buu4");
475 //    BaseAttributePtr atr(
476 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
477 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
478 //    attributeSet.insert(atr);
479 //    Verdict ver = Verdict::VERDICT_DENY;
480 //    Validity val = Validity::ONCE;
481 //    std::string session = getSession();
482 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
483 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
484 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
485 //    handleResult(result, "find Verdict test 4");
486 //}
487 ///*findVerdict*/
488 //
489 //void AceDAOTester::test5()
490 //{
491 ////tests does verdict is properly set when validity is session
492 ////and verdict is deny
493 //    Request  request("subject", "resource");
494 //    AttributeSet attributeSet;
495 //    std::string tmp("atrS5");
496 //    std::string tmpValue("Buu5");
497 //    BaseAttributePtr atr(
498 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
499 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
500 //    attributeSet.insert(atr);
501 //    Verdict ver = Verdict::VERDICT_DENY;
502 //    Validity val = Validity::SESSION;
503 //    pip.setSessionId("5");
504 //    std::string session = getSession();
505 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
506 //    pip.setSessionId("5");
507 //    session = getSession();
508 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
509 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_DENY);
510 //    handleResult(result, "find Verdict test 5");
511 //}
512 ///*findVerdict*/
513 //
514 //void AceDAOTester::test6()
515 //{
516 ////tests does verdict is properly stored for DENY Validity::ALWAYS
517 //    Request  request("subject", "resource");
518 //    AttributeSet attributeSet;
519 //    std::string tmp("atrS6");
520 //    std::string tmpValue("Buu6");
521 //    BaseAttributePtr atr(
522 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
523 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
524 //    attributeSet.insert(atr);
525 //    Verdict ver = Verdict::VERDICT_DENY;
526 //    Validity val = Validity::ALWAYS;
527 //    std::string session = getSession();
528 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
529 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
530 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_DENY);
531 //    handleResult(result, "find Verdict test 6");
532 //}
533 //
534 //
535 //void AceDAOTester::test7()
536 //{
537 ////tests stored version fo INAPPLICABLE Validity::ONCE
538 //
539 //    Request  request("subject", "resource");
540 //    AttributeSet attributeSet;
541 //    attributeSet.insert(constructAttribute("atrS7","Buu7"));
542 //    Verdict ver = Verdict::VERDICT_INAPPLICABLE;
543 //    Validity val = Validity::ONCE;
544 //    std::string session = getSession();
545 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
546 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
547 //    //Verdict with 'Once' validity should not be stored, therefore
548 //    //the outcome should be UNKNOWN
549 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
550 //    handleResult(result, "find Verdict test 7");
551 //}
552 //
553 //
554 //void AceDAOTester::test8()
555 //{
556 ////tests storing data for verdict INAPLICABLE and Validity::SESSION
557 //
558 //    Request  request("subject", "resource");
559 //    AttributeSet attributeSet;
560 //    attributeSet.insert(constructAttribute("atrS8","Buuu8"));
561 //    Verdict ver = Verdict::VERDICT_INAPPLICABLE;
562 //    Validity val = Validity::SESSION;
563 //    pip.setSessionId("8");
564 //    std::string session = getSession();
565 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
566 //    pip.setSessionId("9");
567 //    session = getSession();
568 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
569 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
570 //    handleResult(result, "find Verdict test 8");
571 //}
572 ///*findVerdict*/
573 //
574 //void AceDAOTester::test9()
575 //{
576 //    Request  request("subject", "resource");
577 //    AttributeSet attributeSet;
578 //    std::string tmp("atrS9");
579 //    std::string tmpValue("Buu9");
580 //    BaseAttributePtr atr(
581 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
582 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
583 //    attributeSet.insert(atr);
584 //    Verdict ver = Verdict::VERDICT_INAPPLICABLE;
585 //    Validity val = Validity::ALWAYS;
586 //    std::string session = getSession();
587 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
588 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
589 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_INAPPLICABLE);
590 //    handleResult(result, "find Verdict test 9");
591 //}
592 ///*findVerdict*/
593 //
594 //void AceDAOTester::test10()
595 //{
596 ////tests does verdict is properly stored for verdict undetermined
597 ////and validity Validity::ONCE - thats why verdict is UNKNOWN
598 //    Request  request("subject", "resource");
599 //    AttributeSet attributeSet;
600 //    std::string tmp("atrS10");
601 //    std::string tmpValue("Buu10");
602 //    BaseAttributePtr atr(
603 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
604 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
605 //    attributeSet.insert(atr);
606 //    Verdict ver = Verdict::VERDICT_UNDETERMINED;
607 //    Validity val = Validity::ONCE;
608 //    std::string session = getSession();
609 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
610 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
611 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
612 //    handleResult(result, "find Verdict test 10");
613 //}
614 ///*findVerdict*/
615 //
616 //void AceDAOTester::test11()
617 //{
618 ////tests does verdict is properly stored for verdict undetermined
619 ////and validity Validity::SESSION - TODO Verdicts for undetermined are not stored??
620 //    Request  request("subject", "resource");
621 //    AttributeSet attributeSet;
622 //    std::string tmp("atrS11");
623 //    std::string tmpValue("Buu11");
624 //    BaseAttributePtr atr(
625 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
626 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
627 //    attributeSet.insert(atr);
628 //    Verdict ver = Verdict::VERDICT_UNDETERMINED;
629 //    pip.setSessionId("8");
630 //    Validity val = Validity::SESSION;
631 //    pip.setSessionId("8");
632 //    std::string session = getSession();
633 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
634 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
635 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
636 //    handleResult(result, "find Verdict test 11");
637 //}
638 ///*findVerdict*/
639 //
640 //void AceDAOTester::test12()
641 //{
642 ////tests does verdict is properly stored for verdict undetermined
643 ////and validity Validity::ALWAYS - TODO Verdicts for undetermined are not stored??
644 //    Request  request("subject", "resource");
645 //    AttributeSet attributeSet;
646 //    std::string tmp("atrS12");
647 //    std::string tmpValue("Buu12");
648 //    BaseAttributePtr atr(
649 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
650 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
651 //    attributeSet.insert(atr);
652 //    Verdict ver = Verdict::VERDICT_UNDETERMINED;
653 //    Validity val = Validity::ALWAYS;
654 //    std::string session = getSession();
655 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
656 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
657 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
658 //    handleResult(result, "find Verdict test 12");
659 //}
660 ///*findVerdict*/
661 //
662 //void AceDAOTester::test13()
663 //{
664 ////tests does verdict is properly stored for verdict unknown
665 ////and validity Validity::ONCE-thats why  verdict is not stored
666 //    Request  request("subject", "resource");
667 //    AttributeSet attributeSet;
668 //    std::string tmp("atrS13");
669 //    std::string tmpValue("Buu13");
670 //    BaseAttributePtr atr(
671 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
672 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
673 //    attributeSet.insert(atr);
674 //    Verdict ver = Verdict::VERDICT_UNKNOWN;
675 //    Validity val = Validity::ONCE;
676 //    std::string session = getSession();
677 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
678 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
679 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
680 //    handleResult(result, "find Verdict test 13");
681 //}
682 ///*findVerdict*/
683 //
684 //void AceDAOTester::test14()
685 //{
686 ////tests does verdict is properly stored for verdict unknown
687 ////and validity session- TODO why is the verdict not stored?
688 //    Request  request("subject", "resource");
689 //    AttributeSet attributeSet;
690 //    std::string tmp("atrS14");
691 //    std::string tmpValue("Buu14");
692 //    BaseAttributePtr atr(
693 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
694 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
695 //    attributeSet.insert(atr);
696 //    Verdict ver = Verdict::VERDICT_UNKNOWN;
697 //    Validity val = Validity::SESSION;
698 //    pip.setSessionId("8");
699 //    std::string session = getSession();
700 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
701 //    pip.setSessionId("8");
702 //    session = getSession();
703 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
704 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
705 //    handleResult(result, "find Verdict test 14");
706 //}
707 ///*findVerdict*/
708 //
709 //void AceDAOTester::test15()
710 //{
711 ////tests does verdict is properly stored for verdict unknown and
712 ////validity Validity::ALWAYS - TODO should we save Unknown verdict?
713 //    Request  request("subject", "resource");
714 //    AttributeSet attributeSet;
715 //    std::string tmp("atrS15");
716 //    std::string tmpValue("Buu15");
717 //    BaseAttributePtr atr(
718 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
719 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
720 //    attributeSet.insert(atr);
721 //    Verdict ver = Verdict::VERDICT_UNKNOWN;
722 //    Validity val = Validity::ALWAYS;
723 //    std::string session = getSession();
724 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
725 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
726 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
727 //    handleResult(result, "find Verdict test 15");
728 //}
729 //
730 ///*removeVerdict*/         //tests does verdict is properly removed
731 //void AceDAOTester::test16()
732 //{
733 //    Request  request("subject", "resource");
734 //    AttributeSet attributeSet;
735 //    std::string tmp("atrS15");
736 //    std::string tmpValue("Buu15");
737 //    BaseAttributePtr atr(
738 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
739 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
740 //    attributeSet.insert(atr);
741 //
742 //    Verdict ver = Verdict::VERDICT_PERMIT;
743 //    Validity val = Validity::ALWAYS;
744 //    //add verdict
745 //    std::string session = getSession();
746 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
747 //    //check has verdict been stored?
748 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
749 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_PERMIT);
750 //    handleResult(result, "find Verdict test 16: partA");
751 //
752 //    //remove verdict
753 //    VerdictLogic::removeVerdict(request, attributeSet);
754 //    //verified removed
755 //    verdict = VerdictLogic::findVerdict(request, session, attributeSet);
756 //    result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
757 //    handleResult(result, "find Verdict test 16: partB");
758 //}
759 //
760 ///*findVerdict*/
761 //void AceDAOTester::test18()
762 //{
763 ////verdict for 3 elements on the set of attributes
764 //    Request  request("subject18","resource");
765 //    AttributeSet attributeSet;
766 //    std::string tmp("atrS60");
767 //    std::string tmpValue("Buu60");
768 //    BaseAttributePtr atr(
769 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
770 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
771 //    attributeSet.insert(atr);
772 //
773 //    std::string tmp1("atrS61");
774 //    std::string tmpValue1("Buu61");
775 //    BaseAttributePtr atr1(
776 //        new Attribute(&tmp1,Attribute::Match::Equal, Attribute::Type::Subject));
777 //    DPL::StaticPointerCast<Attribute>(atr1)->addValue(&tmpValue1);
778 //    attributeSet.insert(atr1);
779 //
780 //    std::string tmp2("atrS62");
781 //    std::string tmpValue2("Buu62");
782 //    BaseAttributePtr atr2(
783 //        new Attribute(&tmp2,Attribute::Match::Equal, Attribute::Type::Subject));
784 //    DPL::StaticPointerCast<Attribute>(atr2)->addValue(&tmpValue2);
785 //    attributeSet.insert(atr2);
786 //
787 //    Verdict ver = Verdict::VERDICT_DENY;
788 //    Validity val = Validity::ALWAYS;
789 //    std::string session = getSession();
790 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
791 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
792 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_DENY);
793 //    handleResult(result, "find Verdict test 18");
794 //}
795 //
796 ///*resetDatabase*/
797 //void AceDAOTester::test19()
798 //{
799 //    //tests reset DB
800 //    Request  request("subject", "resource");
801 //    AttributeSet attributeSet;
802 //    std::string tmp("atrS15");
803 //    std::string tmpValue("Buu15");
804 //    BaseAttributePtr atr(
805 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
806 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
807 //    attributeSet.insert(atr);
808 //
809 //    Verdict ver = Verdict::VERDICT_PERMIT;
810 //    Validity val = Validity::ALWAYS;
811 //    //add verdict
812 //    std::string session = getSession();
813 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
814 //    //check has verdict been stored?
815 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
816 //    bool result = VSPAssertEqual(verdict, Verdict::VERDICT_PERMIT);
817 //    handleResult(result, "reset database test 19: partA");
818 //
819 //    AceDAO::resetDatabase();
820 //
821 //    verdict = VerdictLogic::findVerdict(request, session, attributeSet);
822 //    result = VSPAssertEqual(verdict, Verdict::VERDICT_UNKNOWN);
823 //    handleResult(result, "reset database test 19: partB");
824 //}
825
826
827 /*setWidgetDevCapSetting*/
828
829 TESTSUITE06(26){
830     CLEANENV;
831     std::string res("res20");
832     WidgetHandle sub = 20;
833
834     SettingsLogic::setWidgetDevCapSetting(res, sub, Preference::PREFERENCE_PERMIT);
835     std::list<PermissionTriple> userSettings;
836     SettingsLogic::getWidgetDevCapSettings(&userSettings);
837     RUNNER_ASSERT(
838         UserSettingEqual(
839             &userSettings, res, sub, Preference::PREFERENCE_PERMIT));
840 }
841
842 /*setWidgetDevCapSetting*/
843
844 TESTSUITE06(27){
845     CLEANENV;
846     std::string res("res21");
847     WidgetHandle sub = 21;
848
849     SettingsLogic::setWidgetDevCapSetting(res, sub, Preference::PREFERENCE_DENY);
850     std::list<PermissionTriple> userSettings;
851     SettingsLogic::getWidgetDevCapSettings(&userSettings);
852     RUNNER_ASSERT(
853         UserSettingEqual(
854             &userSettings, res, sub, Preference::PREFERENCE_DENY));
855 }
856
857 /*setWidgetDevCapSetting*/
858
859 TESTSUITE06(28){
860     CLEANENV;
861     std::string res("res22");
862     WidgetHandle sub = 22;
863     AceDAO::clearAllSettings();
864     SettingsLogic::setWidgetDevCapSetting(res, sub, Preference::PREFERENCE_DEFAULT);
865     std::list<PermissionTriple> userSettings;
866     SettingsLogic::getWidgetDevCapSettings(&userSettings);
867     RUNNER_ASSERT(
868         UserSettingEqual(
869             &userSettings, res, sub, Preference::PREFERENCE_DEFAULT));
870 }
871
872 TESTSUITE06(29){
873     CLEANENV;
874     std::string res("res23");
875     WidgetHandle sub = 23;
876
877     SettingsLogic::setWidgetDevCapSetting(res, sub, Preference::PREFERENCE_DEFAULT);
878     SettingsLogic::setWidgetDevCapSetting(res, sub, Preference::PREFERENCE_DENY);
879     std::list<PermissionTriple> userSettings;
880     SettingsLogic::getWidgetDevCapSettings(&userSettings);
881     RUNNER_ASSERT(
882         UserSettingEqual(
883             &userSettings, res, sub, Preference::PREFERENCE_DENY));
884 }
885
886 /*setWidgetDevCapSettings*/
887
888 TESTSUITE06(30){
889     CLEANENV;
890     std::string resa("res24a");
891     WidgetHandle suba = 241;
892     std::string resb("res24b");
893     WidgetHandle subb = 242;
894
895     std::list<PermissionTriple> permissionsL;
896
897     permissionsL.push_back(
898         PermissionTriple(suba, resa, Preference::PREFERENCE_DENY));
899     permissionsL.push_back(
900         PermissionTriple(subb, resb, Preference::PREFERENCE_PERMIT));
901
902     SettingsLogic::setWidgetDevCapSettings(permissionsL);
903
904     std::list<PermissionTriple> userSettings;
905     SettingsLogic::getWidgetDevCapSettings(&userSettings);
906     RUNNER_ASSERT(
907         UserSettingsAgreed(&permissionsL, &userSettings));
908 }
909
910
911
912 TESTSUITE06(31){
913     CLEANENV;
914 //multi set - if value is not set in DB or has DEFAUL value it is not
915 //send by getWidgetDevCapSettings - optimization
916
917     std::string resa("res25a");
918     WidgetHandle suba = 251;
919     std::string resb("res25b");
920     WidgetHandle subb = 252;
921     std::string resc("res25c");
922     WidgetHandle subc = 253;
923
924     std::list<PermissionTriple> permissionsL;
925
926     permissionsL.push_back(
927         PermissionTriple(suba, resa, Preference::PREFERENCE_DENY));
928     permissionsL.push_back(
929         PermissionTriple(subb, resb, Preference::PREFERENCE_PERMIT));
930     permissionsL.push_back(
931         PermissionTriple(subc, resc, Preference::PREFERENCE_DEFAULT));
932
933
934     SettingsLogic::setWidgetDevCapSettings(permissionsL);
935
936     std::list<PermissionTriple> userSettings;
937     SettingsLogic::getWidgetDevCapSettings(&userSettings);
938     RUNNER_ASSERT(UserSettingsAgreed(&permissionsL, &userSettings));
939 }
940
941 TESTSUITE06(32){
942     CLEANENV;
943     //empty list  -- TODO what is it testing?
944     std::list<PermissionTriple> permissionsL;
945
946     std::list<PermissionTriple> userSettings;
947     SettingsLogic::getWidgetDevCapSettings(&userSettings);
948     RUNNER_ASSERT(UserSettingsAgreed(&permissionsL, &userSettings));
949 }
950
951 TESTSUITE06(33){
952     CLEANENV;
953     //test resource setting PERMIT
954     std::string res("res27");
955     SettingsLogic::setDevCapSetting(res, Preference::PREFERENCE_PERMIT);
956     std::map<std::string, Preference> resourceSettings;
957     SettingsLogic::getDevCapSettings(&resourceSettings);
958
959     RUNNER_ASSERT(
960          ResourceSettingEqual(&resourceSettings,
961                               res,
962                               Preference::PREFERENCE_PERMIT));
963 }
964
965 TESTSUITE06(34){
966     CLEANENV;
967     //test resource setting DENY
968     std::string res("res28");
969     SettingsLogic::setDevCapSetting(res, Preference::PREFERENCE_DENY);
970     std::map<std::string, Preference> resourceSettings;
971     SettingsLogic::getDevCapSettings(&resourceSettings);
972
973     RUNNER_ASSERT(
974         ResourceSettingEqual(&resourceSettings,
975                              res,
976                              Preference::PREFERENCE_DENY));
977 }
978
979 TESTSUITE06(35){
980     CLEANENV;
981     //test resource setting Preference::PREFERENCE_DEFAULT
982
983     std::string res("res29");
984     SettingsLogic::setDevCapSetting(res, Preference::PREFERENCE_DEFAULT);
985     std::map<std::string, Preference> resourceSettings;
986     SettingsLogic::getDevCapSettings(&resourceSettings);
987
988     RUNNER_ASSERT(
989         ResourceSettingEqual(
990             &resourceSettings,
991             res,
992             Preference::PREFERENCE_DEFAULT));
993 }
994
995 TESTSUITE06(36){
996     CLEANENV;
997     //multi set for Resource settings
998
999     std::string resa("res30a");
1000     std::string resb("res30b");
1001
1002     std::list<std::pair<const std::string*, Preference> > resourcesL;
1003     resourcesL.push_back(make_pair(&resa, Preference::PREFERENCE_DENY));
1004     resourcesL.push_back(make_pair(&resb, Preference::PREFERENCE_PERMIT));
1005
1006     SettingsLogic::setAllDevCapSettings (resourcesL);
1007
1008     std::map<std::string, Preference> resourceSettings;
1009     SettingsLogic::getDevCapSettings(&resourceSettings);
1010     RUNNER_ASSERT(ResourceSettingsAgreed(&resourcesL, &resourceSettings));
1011
1012 }
1013
1014 //void AceDAOTester::test31()
1015 //{
1016 //    // session has changed (PERMIT).
1017 //    //What is the verdict now?
1018 //
1019 //    Request  request("subject", "resource");
1020 //    AttributeSet attributeSet;
1021 //    std::string tmp("atrS31");
1022 //    std::string tmpValue("Buu31");
1023 //    BaseAttributePtr atr(
1024 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1025 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1026 //    attributeSet.insert(atr);
1027 //    Verdict ver = Verdict::VERDICT_PERMIT;
1028 //    Validity val = Validity::SESSION;
1029 //    pip.setSessionId("aaa");
1030 //
1031 //    std::string session = getSession();
1032 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1033 //
1034 //    Verdict verdictA =
1035 //        VerdictLogic::findVerdict(request, session, attributeSet);
1036 //    bool resultA = VSPAssertEqual(verdictA, Verdict::VERDICT_PERMIT);
1037 //    handleResult(resultA, "Verdict session test 31 session a");
1038 //
1039 //    pip.setSessionId("bbb");
1040 //    session = getSession();
1041 //    Verdict verdictB =
1042 //        VerdictLogic::findVerdict(request, session, attributeSet);
1043 //    bool resultB = VSPAssertEqual(verdictB, Verdict::VERDICT_UNKNOWN);
1044 //    handleResult(resultB, "Verdict session test 31 session b");
1045 //}
1046
1047
1048 //void AceDAOTester::test32()
1049 //{
1050 //    //session has changed (DENY).
1051 //    //what is the verdict?
1052 //
1053 //    Request  request("subject", "resource");
1054 //    AttributeSet attributeSet;
1055 //    std::string tmp("atrS32");
1056 //    std::string tmpValue("Buu32");
1057 //    BaseAttributePtr atr(
1058 //        new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1059 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1060 //    attributeSet.insert(atr);
1061 //    Verdict ver = Verdict::VERDICT_DENY;
1062 //    Validity val = Validity::SESSION;
1063 //    pip.setSessionId("aaa");
1064 //    std::string session = getSession();
1065 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1066 //
1067 //    Verdict verdictA =
1068 //        VerdictLogic::findVerdict(request, session, attributeSet);
1069 //    bool resultA = VSPAssertEqual(verdictA, Verdict::VERDICT_DENY);
1070 //    handleResult(resultA, "Verdict session test 32 session a");
1071 //
1072 //    pip.setSessionId("ccc");
1073 //
1074 //    session = getSession();
1075 //    Verdict verdictB =
1076 //        VerdictLogic::findVerdict(request, session, attributeSet);
1077 //    bool resultB = VSPAssertEqual(verdictB, Verdict::VERDICT_UNKNOWN);
1078 //    handleResult(resultB, "Verdict session test 32 session b");
1079 //}
1080
1081 //void AceDAOTester::test33(){
1082 //
1083 //    Request  request("subject", "resource");
1084 //    AttributeSet attributeSet;
1085 //    std::string tmp("atrS33");
1086 //    std::string tmpValue("Buu33");
1087 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1088 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1089 //    attributeSet.insert(atr);
1090 //    Verdict ver =  Verdict::VERDICT_INAPPLICABLE;
1091 //    Validity val = Validity::SESSION;
1092 //    pip.setSessionId("aaa");
1093 //    std::string session = getSession();
1094 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1095 //
1096 //    Verdict verdictA = VerdictLogic::findVerdict(request, session, attributeSet);
1097 //    bool resultA = VSPAssertEqual(verdictA, Verdict::VERDICT_INAPPLICABLE);
1098 //    handleResult(resultA, "Verdict session test 33 session a");
1099 //
1100 //    pip.setSessionId("bbb");
1101 //
1102 //    session = getSession();
1103 //    Verdict verdictB = VerdictLogic::findVerdict(request, session, attributeSet);
1104 //    bool resultB = VSPAssertEqual(verdictB, Verdict::VERDICT_UNKNOWN);
1105 //    handleResult(resultB, "Verdict session test 33 session b");
1106 //}
1107
1108 //void AceDAOTester::test34(){ //session has changed (UNDETERMINED).
1109 ////what is the verdict?
1110 //
1111 //    Request  request("subject", "resource");
1112 //    AttributeSet attributeSet;
1113 //    std::string tmp("atrS34");
1114 //    std::string tmpValue("Buu34");
1115 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1116 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1117 //    attributeSet.insert(atr);
1118 //    Verdict ver =  Verdict::VERDICT_UNDETERMINED;
1119 //    Validity val = Validity::SESSION;
1120 //    pip.setSessionId("aaa");
1121 //    std::string session  = getSession();
1122 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1123 //
1124 //    Verdict verdictA = VerdictLogic::findVerdict(request, session, attributeSet);
1125 //    bool resultA = VSPAssertEqual(verdictA, Verdict::VERDICT_UNKNOWN);
1126 //    handleResult(resultA, "Verdict session test 34 session a");
1127 //
1128 //    pip.setSessionId("bbb");
1129 //
1130 //    session = getSession();
1131 //    Verdict verdictB = VerdictLogic::findVerdict(request, session, attributeSet);
1132 //    bool resultB = VSPAssertEqual(verdictB, Verdict::VERDICT_UNKNOWN);
1133 //    handleResult(resultB, "Verdict session test 34 session b");
1134 //}
1135
1136 //void AceDAOTester::test35(){  //session has changed(UNKNOWN),
1137 ////what is the verdict?
1138 //
1139 //    Request  request("subject", "resource");
1140 //    AttributeSet attributeSet;
1141 //    std::string tmp("atrS35");
1142 //    std::string tmpValue("Buu35");
1143 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1144 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1145 //    attributeSet.insert(atr);
1146 //    Verdict ver =  Verdict::VERDICT_UNKNOWN;
1147 //    Validity val = Validity::SESSION;
1148 //    pip.setSessionId("aaa");
1149 //    std::string session = getSession();
1150 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1151 //
1152 //    Verdict verdictA = VerdictLogic::findVerdict(request, session, attributeSet);
1153 //    bool resultA = VSPAssertEqual(verdictA, Verdict::VERDICT_UNKNOWN);
1154 //    handleResult(resultA, "Verdict session test 35 session a");
1155 //    pip.setSessionId("bbb");
1156 //
1157 //    session = getSession();
1158 //    Verdict verdictB = VerdictLogic::findVerdict(request, session,attributeSet);
1159 //    bool resultB = VSPAssertEqual(verdictB, Verdict::VERDICT_UNKNOWN);
1160 //    handleResult(resultB, "Verdict session test 35 session b");
1161 //}
1162
1163 //void AceDAOTester::test36(){ //changed verdict in the same session
1164 //
1165 //    Request  request("subject", "resource");
1166 //    AttributeSet attributeSet;
1167 //    std::string tmp("atrS36");
1168 //    std::string tmpValue("Buu36");
1169 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1170 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1171 //    attributeSet.insert(atr);
1172 //    Verdict ver =  Verdict::VERDICT_DENY;
1173 //    Validity val = Validity::SESSION;
1174 //    pip.setSessionId("aaa");
1175 //    std::string session = getSession();
1176 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1177 //
1178 //    Verdict verdictA = VerdictLogic::findVerdict(request, session, attributeSet);
1179 //    bool resultA = VSPAssertEqual(verdictA ,Verdict::VERDICT_DENY);
1180 //    handleResult(resultA, "Verdict session test 36 session a");
1181 //
1182 //    ver =  Verdict::VERDICT_PERMIT;
1183 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1184 //
1185 //    Verdict verdictB = VerdictLogic::findVerdict(request, session, attributeSet);
1186 //    bool resultB = VSPAssertEqual(verdictB ,Verdict::VERDICT_PERMIT);
1187 //    handleResult(resultB, "Verdict session test 36 session b");
1188 //}
1189 //
1190 ///* User settings crash tests */
1191 //
1192 //
1193 //void AceDAOTester::test37(){ //empty attribute and verdict permit always
1194 //    Request  request("subject", "resource");
1195 //    AttributeSet attributeSet;
1196 //
1197 //    Verdict ver = Verdict::VERDICT_PERMIT;
1198 //    Validity val = Validity::ALWAYS;
1199 //
1200 //    std::string session = getSession();
1201 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1202 //
1203 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1204 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_PERMIT);
1205 //    handleResult(result, "find Verdict empty attribute set test 37 ");
1206 //}
1207 //
1208 //void AceDAOTester::test38(){ //empty attribute and verdict deny always
1209 //    Request  request("subject", "resource");
1210 //    AttributeSet attributeSet;
1211 //
1212 //    Verdict ver = Verdict::VERDICT_DENY;
1213 //    Validity val = Validity::ALWAYS;
1214 //
1215 //    std::string session = getSession();
1216 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1217 //
1218 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1219 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_DENY);
1220 //    handleResult(result, "find Verdict empty attribute set test 38 ");
1221 //}
1222 //
1223 //void AceDAOTester::test39(){
1224 //
1225 //    Request  request("subject", "resource");
1226 //    AttributeSet attributeSet;
1227 //
1228 //    Verdict ver = Verdict::VERDICT_INAPPLICABLE;
1229 //    Validity val = Validity::ALWAYS;
1230 //
1231 //    std::string session = getSession();
1232 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1233 //
1234 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1235 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_INAPPLICABLE);
1236 //    handleResult(result, "find Verdict empty attribute set test 39 ");
1237 //}
1238 //
1239 //void AceDAOTester::test40(){ //empty attribute and verdict unknown
1240 //    Request  request("subject", "resource");
1241 //    AttributeSet attributeSet;
1242 //
1243 //    Verdict ver = Verdict::VERDICT_UNKNOWN;
1244 //    Validity val = Validity::ALWAYS;
1245 //
1246 //    std::string session = getSession();
1247 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1248 //
1249 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1250 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_UNKNOWN);
1251 //    handleResult(result, "find Verdict empty attribute set test 40 ");
1252 //}
1253 //
1254 //void AceDAOTester::test41()
1255 //{
1256 //    //empty string as subject and resource,
1257 //    //without attributes and verdit DENY Validity::ALWAYS
1258 //    Request  request("", "");
1259 //    //TODO is it OK to store Verdict::VERDICT for empty request?
1260 //    AttributeSet attributeSet;
1261 //
1262 //    Verdict ver = Verdict::VERDICT_DENY;
1263 //    Validity val = Validity::ALWAYS;
1264 //
1265 //    std::string session = getSession();
1266 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1267 //
1268 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1269 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_DENY);
1270 //    //bool result = VSPAssertEqual(verdict,Verdict::VERDICT_UNKNOWN);
1271 //    handleResult(result, "find Verdict empty request empty "
1272 //                         "attribute set test 41 ");
1273 //}
1274 //
1275 //void AceDAOTester::test42(){
1276 //    //empty string as subject and resource, without attributes
1277 //    //and verdict is PERMIT Validity::ALWAYS
1278 //    Request  request("", "");
1279 //
1280 //    AttributeSet attributeSet;
1281 //    std::string tmp("atrS42");
1282 //    std::string tmpValue("Buu342");
1283 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1284 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1285 //    attributeSet.insert(atr);
1286 //
1287 //    Verdict ver = Verdict::VERDICT_PERMIT;
1288 //    Validity val = Validity::ALWAYS;
1289 //
1290 //    std::string session = getSession();
1291 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1292 //
1293 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1294 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_PERMIT);
1295 //    handleResult(result, "find Verdict empty request test 42 ");
1296 //}
1297 //
1298 //void AceDAOTester::test43(){
1299 //    //TODO I have changed it! verdict
1300 //    //has changed and stored in DB. does current verdict is the last one?
1301 //
1302 //    Request  request("ac", "ca");
1303 //    AttributeSet attributeSet;
1304 //
1305 //    Verdict ver = Verdict::VERDICT_DENY;
1306 //    Verdict verp = Verdict::VERDICT_PERMIT;
1307 //    Validity val = Validity::ALWAYS;
1308 //
1309 //    std::string session = getSession();
1310 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1311 //    VerdictLogic::addVerdict(request, session, attributeSet, verp, val);
1312 //
1313 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1314 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_PERMIT);
1315 //    handleResult(result, "find Verdict empty request empty "
1316 //                         "attribute set test 43 ");
1317 //}
1318 //
1319 //void AceDAOTester::test44(){
1320 //    //empty subject and resource name - get Atributes list
1321 //    Request  request("","");
1322 //
1323 //    AttributeSet attributeSet;
1324 //    std::string tmp("atrS44");
1325 //    std::string tmpValue("Buu44");
1326 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1327 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1328 //    attributeSet.insert(atr);
1329 //
1330 //    Verdict ver = Verdict::VERDICT_PERMIT;
1331 //    Validity val = Validity::ALWAYS;
1332 //    std::string session = getSession();
1333 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1334 //
1335 //    AttributeSet attributeS;
1336 //    AceDAO::getAttributes(&attributeS);
1337 //
1338 //    bool result = false;
1339 //
1340 //    result = AttributeEqual(attributeSet,attributeS);
1341 //
1342 //    handleResult(!result,"find Attributes empty request  test 44");
1343 //}
1344 //
1345 //void AceDAOTester::test45(){
1346 //    //empty subject and resource name - what is the verdict? - is it OK??
1347 //    Request  request("", "");
1348 //    AttributeSet attributeSet;
1349 //    std::string tmp("atrS15");
1350 //    std::string tmpValue("Buu15");
1351 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1352 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1353 //    attributeSet.insert(atr);
1354 //
1355 //    Verdict ver = Verdict::VERDICT_PERMIT;
1356 //    Validity val = Validity::ALWAYS;
1357 //    std::string session = getSession();
1358 //    VerdictLogic::addVerdict(request, session, attributeSet, ver, val);
1359 //
1360 //    VerdictLogic::removeVerdict(request, attributeSet);
1361 //
1362 //    Verdict verdict = VerdictLogic::findVerdict(request, session, attributeSet);
1363 //    bool result = VSPAssertEqual(verdict,Verdict::VERDICT_UNKNOWN);
1364 //    handleResult(result, "find Verdict test 45");
1365 //}
1366 //
1367 //void AceDAOTester::test46(){
1368 //    // TODO is it ok that for empty subject and resource name
1369 //    // the verdict is not stored
1370 //    Request  requestemp("", "");
1371 //    Request  request("aa","bb");
1372 //
1373 //    AttributeSet attributeSet;
1374 //    std::string tmp("atrS46");
1375 //    std::string tmpValue("Buu146");
1376 //    BaseAttributePtr atr(new Attribute(&tmp, Attribute::Match::Equal, Attribute::Type::Subject));
1377 //    DPL::StaticPointerCast<Attribute>(atr)->addValue(&tmpValue);
1378 //    attributeSet.insert(atr);
1379 //
1380 //    Verdict verAdd = Verdict::VERDICT_PERMIT;
1381 //    Validity val = Validity::ALWAYS;
1382 //    std::string session = getSession();
1383 //    VerdictLogic::addVerdict(requestemp, session, attributeSet, verAdd, val);
1384 //    VerdictLogic::addVerdict(request, session, attributeSet, verAdd, val);
1385 //
1386 //    VerdictLogic::removeVerdict(requestemp, attributeSet);
1387 //
1388 //    Verdict verdictA = VerdictLogic::findVerdict(requestemp, session, attributeSet);
1389 //    bool resultA = VSPAssertEqual(verdictA,Verdict::VERDICT_UNKNOWN);
1390 //    handleResult(resultA,"find Verdict test 46 A ");
1391 //
1392 //    Verdict verdictB = VerdictLogic::findVerdict(request, session, attributeSet);
1393 //    bool resultB = VSPAssertEqual(verdictB, Verdict::VERDICT_PERMIT);
1394 //    handleResult(resultB,"find Verdict test 46 B ");
1395 //
1396 //}
1397
1398 TESTSUITE06(53){
1399     CLEANENV;
1400     //Empty resource name
1401     std::string res("");
1402     SettingsLogic::setDevCapSetting(res, Preference::PREFERENCE_PERMIT);
1403     std::map<std::string, Preference> resourceSettings;
1404     SettingsLogic::getDevCapSettings(&resourceSettings);
1405
1406     RUNNER_ASSERT(
1407         ResourceSettingEqual(
1408             &resourceSettings,
1409             res,
1410             Preference::PREFERENCE_PERMIT));
1411 }
1412
1413 //void AceDAOTester::test48(){
1414 //    SettingsLogic::setResourceSetting(NULL, PERMIT);
1415 //    std::map<std::string, Preference>*  resourceSettings =
1416 //        SettingsLogic::getResourceSettings();
1417 //
1418 //    bool result = ResourceSettingEqual(resourceSettings, NULL,PERMIT );
1419 //    handleResult(result, "get Resource Settings empty resource test 48");
1420 //    printf("get Resource Settings empty resource test 48 -----> "
1421 //           "Segmentation fault\n");
1422 //}
1423
1424 TESTSUITE06(55){
1425     CLEANENV;
1426     //resource settings list with empty elemen
1427
1428     std::string resb("");
1429
1430     std::list<std::pair<const std::string*, Preference> > resourcesL;
1431     resourcesL.push_back(make_pair(&resb, Preference::PREFERENCE_PERMIT));
1432
1433     SettingsLogic::setAllDevCapSettings (resourcesL);
1434
1435     std::map<std::string, Preference> resourceSettings;
1436     SettingsLogic::getDevCapSettings(&resourceSettings);
1437     RUNNER_ASSERT(ResourceSettingsEqual(&resourcesL, &resourceSettings));
1438 }
1439
1440 TESTSUITE06(56){
1441     CLEANENV;
1442     //user settings with empty subject and resource
1443     //if resource or subject name is empty, values are not saved in DB
1444     std::string resb("fake-resource");
1445     WidgetHandle subb = 0;
1446
1447     std::list<PermissionTriple> permissionsL;
1448
1449     permissionsL.push_back(PermissionTriple(subb, resb, Preference::PREFERENCE_PERMIT));
1450
1451     SettingsLogic::setWidgetDevCapSettings(permissionsL);
1452
1453     std::list<PermissionTriple> userSettings;
1454     SettingsLogic::getWidgetDevCapSettings(&userSettings);
1455     RUNNER_ASSERT(UserSettingsAgreed(&permissionsL, &userSettings));
1456 }
1457
1458 TESTSUITE06(57){
1459     CLEANENV;
1460     //user setting equal
1461     // settings with at least one empty value is not set
1462     std::string res("");
1463     WidgetHandle sub = 0;
1464
1465     SettingsLogic::setWidgetDevCapSetting(res, sub, Preference::PREFERENCE_PERMIT);
1466     std::list<PermissionTriple> userSettings;
1467     SettingsLogic::getWidgetDevCapSettings(&userSettings);
1468     RUNNER_ASSERT(
1469         UserSettingNotStored(
1470             &userSettings,
1471             res,
1472             sub,
1473             Preference::PREFERENCE_PERMIT));
1474 }
1475
1476 TESTSUITE06(58){
1477     CLEANENV;
1478     //user settings empty values and Default access
1479
1480     std::string res("");
1481     WidgetHandle sub = 0;
1482
1483     SettingsLogic::setWidgetDevCapSetting(res, sub, Preference::PREFERENCE_DEFAULT);
1484     std::list<PermissionTriple> userSettings;
1485     SettingsLogic::getWidgetDevCapSettings(&userSettings);
1486     RUNNER_ASSERT(
1487         UserSettingNotStored(
1488             &userSettings,
1489             res,
1490             sub,
1491             Preference::PREFERENCE_DEFAULT));
1492 }
1493
1494 TESTSUITE06(59){
1495     CLEANENV;
1496     DPL::OptionalString sessionId(DPL::FromUTF8String("fakesession"));
1497     AceDAO::setPromptDecision(59, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1498
1499     OptionalCachedPromptDecision dec = AceDAO::getPromptDecision(59, 4);
1500
1501     RUNNER_ASSERT(!dec.IsNull());
1502
1503     if (!dec.IsNull())
1504     {
1505         RUNNER_ASSERT(dec->decision == PromptDecision::ALLOW_FOR_SESSION);
1506         RUNNER_ASSERT(!(dec->session.IsNull()));
1507         if (!(dec->session.IsNull())) {
1508             RUNNER_ASSERT(*(dec->session) == *sessionId);
1509         }
1510     }
1511 }
1512
1513 TESTSUITE06(60){
1514     CLEANENV;
1515     DPL::OptionalString sessionId(DPL::FromUTF8String("fakesession44"));
1516     AceDAO::setPromptDecision(60, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1517     AceDAO::setPromptDecision(60, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1518
1519     OptionalCachedPromptDecision dec = AceDAO::getPromptDecision(60, 4);
1520
1521     RUNNER_ASSERT(!dec.IsNull());
1522
1523     if (!dec.IsNull())
1524     {
1525         RUNNER_ASSERT(dec->decision == PromptDecision::DENY_FOR_SESSION);
1526         RUNNER_ASSERT(!(dec->session.IsNull()));
1527         if (!(dec->session.IsNull())) {
1528             RUNNER_ASSERT(*(dec->session) == *sessionId);
1529         }
1530     }
1531 }
1532
1533 TESTSUITE06(61){
1534     CLEANENV;
1535     DPL::OptionalString sessionId(DPL::FromUTF8String("fakesessionxxx"));
1536     AceDAO::setPromptDecision(61, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1537     AceDAO::setPromptDecision(61, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1538     AceDAO::setPromptDecision(61, 5, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1539     AceDAO::setPromptDecision(61, 3, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1540     AceDAO::setPromptDecision(61, 5, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1541     AceDAO::setPromptDecision(61, 3, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1542
1543     OptionalCachedPromptDecision dec = AceDAO::getPromptDecision(61, 4);
1544
1545     RUNNER_ASSERT(!dec.IsNull());
1546
1547     if (!dec.IsNull())
1548     {
1549         RUNNER_ASSERT(dec->decision == PromptDecision::DENY_FOR_SESSION);
1550         RUNNER_ASSERT(!(dec->session.IsNull()));
1551         if (!(dec->session.IsNull())) {
1552             RUNNER_ASSERT(*(dec->session) == *sessionId);
1553         }
1554     }
1555 }
1556
1557 TESTSUITE06(62){
1558     CLEANENV;
1559     DPL::OptionalString sessionId(DPL::FromUTF8String("fakesession63"));
1560     AceDAO::setPromptDecision(61, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1561     AceDAO::setPromptDecision(61, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1562     AceDAO::setPromptDecision(60, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1563     AceDAO::setPromptDecision(60, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1564     AceDAO::setPromptDecision(62, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1565     AceDAO::setPromptDecision(62, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1566
1567     OptionalCachedPromptDecision dec = AceDAO::getPromptDecision(61, 4);
1568
1569     RUNNER_ASSERT(!dec.IsNull());
1570
1571     if (!dec.IsNull())
1572     {
1573         RUNNER_ASSERT(dec->decision == PromptDecision::DENY_FOR_SESSION);
1574         RUNNER_ASSERT(!(dec->session.IsNull()));
1575         if (!(dec->session.IsNull())) {
1576             RUNNER_ASSERT(*(dec->session) == *sessionId);
1577         }
1578     }
1579 }
1580
1581 TESTSUITE06(63){
1582     CLEANENV;
1583     DPL::OptionalString sessionId(DPL::FromUTF8String("fakesession64"));
1584     AceDAO::setPromptDecision(61, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1585     AceDAO::setPromptDecision(61, 4, sessionId, PromptDecision::ALLOW_FOR_SESSION);
1586     AceDAO::setPromptDecision(60, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1587     AceDAO::setPromptDecision(60, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1588     AceDAO::setPromptDecision(62, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1589     AceDAO::setPromptDecision(62, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1590
1591     OptionalCachedPromptDecision dec = AceDAO::getPromptDecision(61, 4);
1592
1593     RUNNER_ASSERT(!dec.IsNull());
1594
1595     if (!dec.IsNull())
1596     {
1597         RUNNER_ASSERT(dec->decision == PromptDecision::ALLOW_FOR_SESSION);
1598         RUNNER_ASSERT(!(dec->session.IsNull()));
1599         if (!(dec->session.IsNull())) {
1600             RUNNER_ASSERT(*(dec->session) == *sessionId);
1601         }
1602     }
1603 }
1604
1605 TESTSUITE06(64){
1606     CLEANENV;
1607     DPL::OptionalString sessionId;
1608     AceDAO::setPromptDecision(64, 5, sessionId, PromptDecision::DENY_ALWAYS);
1609     AceDAO::setPromptDecision(64, 5, sessionId, PromptDecision::ALLOW_ALWAYS);
1610     AceDAO::setPromptDecision(64, 4, sessionId, PromptDecision::DENY_FOR_SESSION);
1611     AceDAO::setPromptDecision(63, 5, sessionId, PromptDecision::DENY_FOR_SESSION);
1612
1613     OptionalCachedPromptDecision dec = AceDAO::getPromptDecision(64, 5);
1614
1615     RUNNER_ASSERT(!dec.IsNull());
1616
1617     if (!dec.IsNull())
1618     {
1619         RUNNER_ASSERT(dec->decision == PromptDecision::ALLOW_ALWAYS);
1620         RUNNER_ASSERT(dec->session.IsNull());
1621     }
1622 }
1623
1624 TESTSUITE06(65){
1625     CLEANENV;
1626     DPL::String f1(DPL::FromASCIIString("Feature1"));
1627     DPL::String f2(DPL::FromASCIIString("Feature2"));
1628     AceDB::FeatureNameVector fvector;
1629     fvector.push_back(f1);
1630     fvector.push_back(f2);
1631     AceDAO::setAcceptedFeature(65, fvector);
1632
1633     fvector.clear();
1634     AceDAO::getAcceptedFeature(65, &fvector);
1635
1636     RUNNER_ASSERT(fvector.size() == 2);
1637     RUNNER_ASSERT(fvector[0] != fvector[1]);
1638     RUNNER_ASSERT(fvector[0] == f1 || fvector[0] == f2);
1639     RUNNER_ASSERT(fvector[1] == f1 || fvector[1] == f2);
1640 }
1641
1642 TESTSUITE06(66){
1643     CLEANENV;
1644     AceDB::FeatureNameVector fvector;
1645     fvector.push_back(DPL::FromASCIIString("Feature1"));
1646     fvector.push_back(DPL::FromASCIIString("Feature2"));
1647     AceDAO::setAcceptedFeature(66, fvector);
1648
1649     fvector.clear();
1650     AceDAO::getAcceptedFeature(67, &fvector);
1651
1652     RUNNER_ASSERT(fvector.size() == 0);
1653 }