1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "gtest/gtest.h"
24 #include <linux/limits.h>
26 #include "cainterface.h"
27 #include "srmresourcestrings.h"
28 #include "securevirtualresourcetypes.h"
32 #define PE_UT_TAG "\tPE-UT-message: "
38 #include "policyengine.h"
39 #include "doxmresource.h"
42 PEContext_t g_peContext;
48 OicUuid_t g_subjectIdA = {"SubjectA"};
49 OicUuid_t g_subjectIdB = {"SubjectB"};
51 char g_resource1[] = "Resource1";
52 char g_resource2[] = "Resource2";
54 extern OicSecDoxm_t *gDoxm;
56 //Policy Engine Core Tests
57 TEST(PolicyEngineCore, InitPolicyEngine)
59 EXPECT_EQ(OC_STACK_OK, InitPolicyEngine(&g_peContext));
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)
66 if(OC_STACK_OK == InitDoxmResource())
68 EXPECT_EQ(ACCESS_DENIED_SUBJECT_NOT_FOUND,
69 CheckPermission(&g_peContext,
76 printf("%s WARNING: InitDoxmResource() returned ERROR!\n", \
81 // TODO - in order to unittest this we need InitDoxmResource() to put doxm
82 // into Owned state with a known owner. This will have to be done post v1.1.
83 TEST(PolicyEngineCore, CheckDevOwnerRequest)
85 if(OC_STACK_OK == InitDoxmResource())
87 if(OC_STACK_OK == GetDoxmDevOwnerId(&g_devOwner))
89 printf("%s", PE_UT_TAG);
90 for(int i = 0; i < UUID_LENGTH; i++)
92 printf("%d", g_devOwner.id[i]);
95 EXPECT_EQ(ACCESS_GRANTED,
96 CheckPermission(&g_peContext,
99 PERMISSION_FULL_CONTROL));
103 printf("%s WARNING: GetDoxmDevOwnerId() returned ERROR!\n", \
109 printf("%s WARNING: InitDoxmResource() returned ERROR!\n", \
114 TEST(PolicyEngineCore, DeInitPolicyEngine)
116 DeInitPolicyEngine(&g_peContext);
117 EXPECT_EQ(STOPPED, g_peContext.state);
118 EXPECT_EQ((uint16_t)0, g_peContext.permission);
119 EXPECT_FALSE(g_peContext.matchingAclFound);
120 EXPECT_EQ(ACCESS_DENIED_POLICY_ENGINE_ERROR, g_peContext.retVal);