security: publish securevirtualresourcetypes.h
[iotivity.git] / resource / csdk / security / unittest / policyengine.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include <gtest/gtest.h>
22 #include "ocstack.h"
23 #include "cainterface.h"
24 #include "srmresourcestrings.h"
25
26 using namespace std;
27
28 #define PE_UT_TAG "\tPE-UT-message: "
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include "policyengine.h"
35 #include "doxmresource.h"
36
37 // test parameters
38 // PEContext_t g_peContext;
39
40 #ifdef __cplusplus
41 }
42 #endif
43
44 OicUuid_t g_subjectIdA = {"SubjectA"};
45 OicUuid_t g_subjectIdB = {"SubjectB"};
46 OicUuid_t g_devOwner;
47 char g_resource1[] = "Resource1";
48 char g_resource2[] = "Resource2";
49
50 extern OicSecDoxm_t *gDoxm;
51
52 // These tests need to be rewritten; they do not cover internal ACE/request
53 // logic.
54 // See JIRA 1787 (https://jira.iotivity.org/browse/IOT-1787)
55
56 //Policy Engine Core Tests
57 // TEST(PolicyEngineCore, InitPolicyEngine)
58 // {
59 //     EXPECT_EQ(OC_STACK_OK, InitPolicyEngine(&g_peContext));
60 // }
61
62 // TODO - in order to unittest this we need InitDoxmResource() to put doxm
63 // into Owned state with a known owner.  This will have to be done post v1.1.
64 // TEST(PolicyEngineCore, CheckPermissionNoAcls)
65 // {
66 //     if(OC_STACK_OK == InitDoxmResource())
67 //     {
68 //         EXPECT_EQ(ACCESS_DENIED_SUBJECT_NOT_FOUND,
69 //             CheckPermission(&g_peContext,
70 //                             &g_subjectIdA,
71 //                             g_resource1,
72 //                             PERMISSION_READ));
73 //     }
74 //     else
75 //     {
76 //         printf("%s WARNING: InitDoxmResource() returned ERROR!\n", PE_UT_TAG);
77 //     }
78 // }
79
80 // // TODO - in order to unittest this we need InitDoxmResource() to put doxm
81 // // into Owned state with a known owner.  This will have to be done post v1.1.
82 // TEST(PolicyEngineCore, CheckDevOwnerRequest)
83 // {
84 //     if(OC_STACK_OK == InitDoxmResource())
85 //     {
86 //         if(OC_STACK_OK == GetDoxmDevOwnerId(&g_devOwner))
87 //         {
88 //             printf("%s", PE_UT_TAG);
89 //             for(int i = 0; i < UUID_LENGTH; i++)
90 //             {
91 //                 printf("%d", g_devOwner.id[i]);
92 //             }
93 //             printf("\n");
94 //                 EXPECT_EQ(ACCESS_GRANTED,
95 //                     CheckPermission(&g_peContext,
96 //                         &g_devOwner,
97 //                         g_resource1,
98 //                         PERMISSION_FULL_CONTROL));
99 //         }
100 //         else
101 //         {
102 //             printf("%s WARNING: GetDoxmDevOwnerId() returned ERROR!\n", PE_UT_TAG);
103 //         }
104 //     }
105 //     else
106 //     {
107 //         printf("%s WARNING: InitDoxmResource() returned ERROR!\n", PE_UT_TAG);
108 //     }
109 // }
110
111 // TEST(PolicyEngineCore, DeInitPolicyEngine)
112 // {
113 //     DeInitPolicyEngine(&g_peContext);
114 //     EXPECT_EQ(STOPPED, g_peContext.state);
115 //     EXPECT_EQ((uint16_t)0, g_peContext.permission);
116 //     EXPECT_EQ(ACCESS_DENIED_POLICY_ENGINE_ERROR, g_peContext.retVal);
117 // }