1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 * *****************************************************************/
22 #include <oic_malloc.h>
24 #include <OCPlatform_impl.h>
25 #include <oxmjustworks.h>
26 #include <oxmrandompin.h>
27 #include <OCProvisioningManager.h>
28 #include <gtest/gtest.h>
32 namespace OCProvisioningTest
36 void resultCallback(PMResultList_t *result, int hasError)
42 TEST(ProvisionInitTest, TestWithEmptyPath)
44 std::string dbPath("");
45 EXPECT_EQ(OC_STACK_OK, OCSecure::provisionInit(dbPath));
48 TEST(ProvisionInitTest, TestValidPath)
50 std::string dbPath("./dbPath");
51 EXPECT_EQ(OC_STACK_OK, OCSecure::provisionInit(dbPath));
54 TEST(DiscoveryTest, UnownedDevices)
57 EXPECT_EQ(OC_STACK_OK, OCSecure::discoverUnownedDevices(TIMEOUT, list));
60 TEST(DiscoveryTest, UnownedDevicesZeroTimeout)
63 EXPECT_EQ(OC_STACK_OK, OCSecure::discoverUnownedDevices(0, list));
66 TEST(DiscoveryTest, OwnedDevices)
69 EXPECT_EQ(OC_STACK_OK, OCSecure::discoverOwnedDevices(TIMEOUT, list));
72 TEST(DiscoveryTest, OwnedDevicesZeroTimeout)
75 EXPECT_EQ(OC_STACK_OK, OCSecure::discoverOwnedDevices(0, list));
78 TEST(OwnershipTest, SetOwnershipTransferCBDataNull)
80 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setOwnerTransferCallbackData(
81 OIC_JUST_WORKS, NULL, NULL));
84 TEST(OwnershipTest, SetOwnershipTransferCBData)
86 OTMCallbackData_t justWorksCBData;
87 justWorksCBData.loadSecretCB = LoadSecretJustWorksCallback;
88 justWorksCBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback;
89 justWorksCBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
90 justWorksCBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
91 EXPECT_EQ(OC_STACK_OK, OCSecure::setOwnerTransferCallbackData(OIC_JUST_WORKS,
92 &justWorksCBData, NULL));
95 TEST(OwnershipTest, SetOwnershipTransferCBDataInvalidType)
97 OTMCallbackData_t justWorksCBData;
98 justWorksCBData.loadSecretCB = LoadSecretJustWorksCallback;
99 justWorksCBData.createSecureSessionCB = CreateSecureSessionJustWorksCallback;
100 justWorksCBData.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
101 justWorksCBData.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
102 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setOwnerTransferCallbackData(OIC_OXM_COUNT,
103 &justWorksCBData, NULL));
106 TEST(OwnershipTest, SetOwnershipTransferCBDataNullInputPin)
108 OTMCallbackData_t pinBasedCBData;
109 pinBasedCBData.loadSecretCB = InputPinCodeCallback;
110 pinBasedCBData.createSecureSessionCB = CreateSecureSessionRandomPinCallback;
111 pinBasedCBData.createSelectOxmPayloadCB = CreatePinBasedSelectOxmPayload;
112 pinBasedCBData.createOwnerTransferPayloadCB = CreatePinBasedOwnerTransferPayload;
113 OTMSetOwnershipTransferCallbackData(OIC_RANDOM_DEVICE_PIN, &pinBasedCBData);
115 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setOwnerTransferCallbackData(
116 OIC_RANDOM_DEVICE_PIN, &pinBasedCBData, NULL));
119 TEST(OwnershipTest, OwnershipTransferNullCallback)
121 OCSecureResource device;
122 EXPECT_EQ(OC_STACK_INVALID_PARAM, device.doOwnershipTransfer(nullptr));
125 TEST(DeviceInfoTest, DevInfoFromNetwork)
127 DeviceList_t owned, unowned;
128 EXPECT_EQ(OC_STACK_OK, OCSecure::getDevInfoFromNetwork(TIMEOUT,
132 TEST(SetDisplayPinCBTest, SetDisplayPinCBTestNullCB)
134 EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSecure::setDisplayPinCB(nullptr));
137 TEST(ProvisionAclTest, ProvisionAclTestNullAcl)
139 OCSecureResource device;
140 EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionACL(nullptr, resultCallback));
143 TEST(ProvisionAclTest, ProvisionAclTestNullCallback)
145 OCSecureResource device;
146 OicSecAcl_t *acl = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
147 EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionACL(acl, nullptr));
151 TEST(ProvisionAclTest, ProvisionAclTestNullCallbackNUllAcl)
153 OCSecureResource device;
154 EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionACL(nullptr, nullptr));
157 TEST(ProvisionCredTest, ProvisionCredTestNullCallback)
159 OCSecureResource device, dev2;
161 EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionCredentials(cred, dev2, nullptr));
164 TEST(ProvisionPairwiseTest, ProvisionPairwiseTestNullCallback)
166 OCSecureResource device, dev2;
168 OicSecAcl_t *acl1 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
169 OicSecAcl_t *acl2 = (OicSecAcl_t *)OICCalloc(1,sizeof(OicSecAcl_t));
170 EXPECT_EQ(OC_STACK_INVALID_PARAM, device.provisionPairwiseDevices(cred, acl1,
171 dev2, acl2, nullptr));