9d971c94fefe11a3ce01471785fe14c8018839e6
[iotivity.git] / resource / csdk / security / provisioning / unittest / ocprovisioningmanager.cpp
1 /* *****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics 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 #include "gtest/gtest.h"
21 #include "ocprovisioningmanager.h"
22
23 static OicSecAcl_t acl1;
24 static OicSecAcl_t acl2;
25 static OCProvisionDev_t pDev1;
26 static OCProvisionDev_t pDev2;
27 static OicSecCredType_t credType = SYMMETRIC_PAIR_WISE_KEY;
28 static OicSecOxm_t oicSecDoxmJustWorks = OIC_JUST_WORKS;
29 static OicSecOxm_t oicSecDoxmRandomPin = OIC_RANDOM_DEVICE_PIN;
30 static OicSecDoxm_t defaultDoxm1 =
31 {
32     NULL,                   /* OicUrn_t *oxmType */
33     0,                      /* size_t oxmTypeLen */
34     &oicSecDoxmJustWorks,  /* uint16_t *oxm */
35     1,                      /* size_t oxmLen */
36     OIC_JUST_WORKS,         /* uint16_t oxmSel */
37     SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
38     false,                  /* bool owned */
39     {{0}},            /* OicUuid_t deviceID */
40     false,                  /* bool dpc */
41     {{0}},            /* OicUuid_t owner */
42 };
43
44 static OicSecDoxm_t defaultDoxm2 =
45 {
46     NULL,                   /* OicUrn_t *oxmType */
47     0,                      /* size_t oxmTypeLen */
48     &oicSecDoxmRandomPin,  /* uint16_t *oxm */
49     1,                      /* size_t oxmLen */
50     OIC_RANDOM_DEVICE_PIN,         /* uint16_t oxmSel */
51     SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
52     false,                  /* bool owned */
53     {{0}},            /* OicUuid_t deviceID */
54     false,                  /* bool dpc */
55     {{0}},            /* OicUuid_t owner */
56 };
57
58 static void provisioningCB (void* UNUSED1, int UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4)
59 {
60     //dummy callback
61     (void) UNUSED1;
62     (void) UNUSED2;
63     (void) UNUSED3;
64     (void) UNUSED4;
65 }
66
67 static OCStackResult OTMLoadSecretCallback(OTMContext_t* otmCtx)
68 {
69     //dummy callback
70     (void) otmCtx;
71     return OC_STACK_OK;
72 }
73
74 TEST(OCInitPMTest, NullPath)
75 {
76     EXPECT_EQ(OC_STACK_OK, OCInitPM(NULL));
77 }
78
79 TEST(OCProvisionPairwiseDevicesTest, NullDevice1)
80 {
81     pDev1.doxm = &defaultDoxm1;
82     uint8_t deviceId1[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64};
83     memcpy(pDev1.doxm->deviceID.id, deviceId1, sizeof(deviceId1));
84
85     pDev2.doxm = &defaultDoxm2;
86     uint8_t deviceId2[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x63};
87     memcpy(pDev2.doxm->deviceID.id, deviceId2, sizeof(deviceId2));
88
89     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
90                                                               OWNER_PSK_LENGTH_128, NULL, &acl1,
91                                                               &pDev2, &acl2, &provisioningCB));
92 }
93
94 TEST(OCProvisionPairwiseDevicesTest, NullDevice2)
95 {
96     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
97                                                               OWNER_PSK_LENGTH_128, &pDev1, &acl1,
98                                                               NULL, &acl2, &provisioningCB));
99 }
100
101 TEST(OCProvisionPairwiseDevicesTest, SamelDeviceId)
102 {
103     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
104                                                               OWNER_PSK_LENGTH_128, &pDev1, &acl1,
105                                                               &pDev1, &acl2, &provisioningCB));
106 }
107
108 TEST(OCProvisionPairwiseDevicesTest, NullCallback)
109 {
110     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCProvisionPairwiseDevices(NULL, credType,
111                                                               OWNER_PSK_LENGTH_128, &pDev1, &acl1,
112                                                               &pDev2, &acl2, NULL));
113 }
114
115 TEST(OCProvisionPairwiseDevicesTest, InvalidKeySize)
116 {
117     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
118                                                               0, &pDev1, &acl1,
119                                                               &pDev2, &acl2 ,&provisioningCB));
120 }
121
122 TEST(OCUnlinkDevicesTest, NullDevice1)
123 {
124     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, NULL, &pDev2, provisioningCB));
125 }
126
127 TEST(OCUnlinkDevicesTest, NullDevice2)
128 {
129     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, &pDev1, NULL, provisioningCB));
130 }
131
132 TEST(OCUnlinkDevicesTest, NullCallback)
133 {
134     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCUnlinkDevices(NULL, &pDev1, &pDev2, NULL));
135 }
136
137 TEST(OCUnlinkDevicesTest, SamelDeviceId)
138 {
139     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL,&pDev1, &pDev1, &provisioningCB));
140 }
141
142 TEST(OCRemoveDeviceTest, NullTargetDevice)
143 {
144     unsigned short waitTime = 10 ;
145     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, NULL, provisioningCB));
146 }
147
148 TEST(OCRemoveDeviceWithUuidTest, NullTargetDevice)
149 {
150     unsigned short waitTime = 10 ;
151     OicUuid_t uuid;
152     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDeviceWithUuid(NULL, waitTime, NULL, provisioningCB));
153
154     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDeviceWithUuid(NULL, waitTime, &uuid, NULL));
155 }
156
157 TEST(OCRemoveDeviceTest, NullResultCallback)
158 {
159     unsigned short waitTime = 10;
160     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDevice(NULL, waitTime, &pDev1, NULL));
161 }
162
163 TEST(OCRemoveDeviceTest, ZeroWaitTime)
164 {
165     unsigned short waitTime = 0;
166     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, &pDev1, provisioningCB));
167 }
168
169 TEST(OCGetDevInfoFromNetworkTest, NullUnOwnedDeviceInfo)
170 {
171     unsigned short waitTime = 10;
172     OCProvisionDev_t *ownedList = NULL;
173     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, NULL));
174 }
175
176 TEST(OCGetDevInfoFromNetworkTest, NullOwnedDeviceInfo)
177 {
178     unsigned short waitTime = 10;
179     OCProvisionDev_t *unownedList = NULL;
180     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, NULL, &unownedList));
181 }
182
183 TEST(OCGetDevInfoFromNetworkTest, ZeroWaitTime)
184 {
185     unsigned short waitTime = 0;
186     OCProvisionDev_t *ownedList = NULL;
187     OCProvisionDev_t *unownedList = NULL;
188     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, &unownedList));
189 }
190
191 TEST(OCGetLinkedStatusTest, NULLDeviceID)
192 {
193     OCUuidList_t *list = NULL;
194     size_t noOfDevices = 0;
195     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetLinkedStatus(NULL, &list, &noOfDevices));
196 }
197
198 TEST(OCDeleteUuidListTest, NullUuidList)
199 {
200     OCDeleteUuidList(NULL);
201     EXPECT_EQ(1, 1);
202 }
203
204 TEST(OCDeleteACLListTest, NullACLList)
205 {
206     OCDeleteACLList(NULL);
207     EXPECT_EQ(1, 1);
208 }
209
210 TEST(OCDeletePdAclListTest, NullPdACLList)
211 {
212     OCDeletePdAclList(NULL);
213     EXPECT_EQ(1, 1);
214 }
215
216 TEST(OCDeleteDiscoveredDevicesTest, NullProvisionDevList)
217 {
218     OCDeleteDiscoveredDevices(NULL);
219     EXPECT_EQ(1, 1);
220 }
221
222 TEST(OCSetOwnerTransferCallbackDataTest, NULLCallback)
223 {
224     OicSecOxm_t ownershipTransferMethod = OIC_JUST_WORKS;
225     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
226     NULL));
227 }
228
229 TEST(OCSetOwnerTransferCallbackDataTest, InvalidOXMType)
230 {
231     OicSecOxm_t ownershipTransferMethod = OIC_OXM_COUNT;
232     OTMCallbackData_t stOTMCallbackData = { &OTMLoadSecretCallback, NULL, NULL, NULL};
233     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
234     &stOTMCallbackData));
235 }