3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 * This file implements a unit test suite for the Configuration Manager
31 #include <nlunit-test.h>
32 #include <support/CHIPMem.h>
33 #include <support/CodeUtils.h>
34 #include <support/UnitTestRegistration.h>
36 #include <platform/CHIPDeviceLayer.h>
39 using namespace chip::Logging;
40 using namespace chip::Inet;
41 using namespace chip::DeviceLayer;
43 // =================================
45 // =================================
47 static void TestPlatformMgr_Init(nlTestSuite * inSuite, void * inContext)
49 // ConfigurationManager is initialized from PlatformManager indirectly
50 CHIP_ERROR err = PlatformMgr().InitChipStack();
51 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
55 static void TestPlatformMgr_RunUnitTest(nlTestSuite * inSuite, void * inContext)
57 CHIP_ERROR err = CHIP_NO_ERROR;
59 err = ConfigurationMgr().RunUnitTests();
60 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
64 static void TestConfigurationMgr_SerialNumber(nlTestSuite * inSuite, void * inContext)
66 CHIP_ERROR err = CHIP_NO_ERROR;
69 size_t serialNumberLen = 0;
70 const char * serialNumber = "89051AAZZ236";
72 err = ConfigurationMgr().StoreSerialNumber(serialNumber, strlen(serialNumber));
73 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
75 err = ConfigurationMgr().GetSerialNumber(buf, 64, serialNumberLen);
76 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
78 NL_TEST_ASSERT(inSuite, serialNumberLen == strlen(serialNumber));
79 NL_TEST_ASSERT(inSuite, strcmp(buf, serialNumber) == 0);
81 err = ConfigurationMgr().StoreSerialNumber(serialNumber, 5);
82 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
84 err = ConfigurationMgr().GetSerialNumber(buf, 64, serialNumberLen);
85 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
87 NL_TEST_ASSERT(inSuite, serialNumberLen == 5);
88 NL_TEST_ASSERT(inSuite, strcmp(buf, "89051") == 0);
91 static void TestConfigurationMgr_ManufacturingDate(nlTestSuite * inSuite, void * inContext)
93 CHIP_ERROR err = CHIP_NO_ERROR;
95 const char * mfgDate = "2008/09/20";
100 err = ConfigurationMgr().StoreManufacturingDate(mfgDate, strlen(mfgDate));
101 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
103 err = ConfigurationMgr().GetManufacturingDate(year, month, dayOfMonth);
104 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
106 NL_TEST_ASSERT(inSuite, year == 2008);
107 NL_TEST_ASSERT(inSuite, month == 9);
108 NL_TEST_ASSERT(inSuite, dayOfMonth == 20);
111 static void TestConfigurationMgr_ProductRevision(nlTestSuite * inSuite, void * inContext)
113 CHIP_ERROR err = CHIP_NO_ERROR;
116 err = ConfigurationMgr().StoreProductRevision(1234);
117 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
119 err = ConfigurationMgr().GetProductRevision(productRev);
120 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
122 NL_TEST_ASSERT(inSuite, productRev == 1234);
125 static void TestConfigurationMgr_ManufacturerDeviceId(nlTestSuite * inSuite, void * inContext)
127 CHIP_ERROR err = CHIP_NO_ERROR;
130 err = ConfigurationMgr().StoreManufacturerDeviceId(7212064004600625234);
131 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
133 err = ConfigurationMgr().GetManufacturerDeviceId(deviceId);
134 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
136 NL_TEST_ASSERT(inSuite, deviceId == 7212064004600625234);
139 static void TestConfigurationMgr_ManufacturerDeviceCertificate(nlTestSuite * inSuite, void * inContext)
141 CHIP_ERROR err = CHIP_NO_ERROR;
142 const static uint8_t cert[] = {
143 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30, 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, 0x3D, 0x8F, 0x24,
144 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x41,
145 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4,
146 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5,
147 0xA4, 0x13, 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3,
148 0x48, 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65,
149 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, 0x35, 0x83, 0x29, 0x01, 0x18,
150 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18,
151 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02,
152 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54,
153 0xF5, 0xAE, 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8, 0x54,
154 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, 0x28, 0xAA, 0xC4, 0xF1,
155 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, 0x18,
160 err = ConfigurationMgr().StoreManufacturerDeviceCertificate(cert, sizeof(cert));
161 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
163 err = ConfigurationMgr().GetManufacturerDeviceCertificate(buf, sizeof(buf), certLen);
164 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
166 NL_TEST_ASSERT(inSuite, certLen == sizeof(cert));
167 NL_TEST_ASSERT(inSuite, memcmp(buf, cert, certLen) == 0);
170 static void TestConfigurationMgr_ManufacturerDeviceIntermediateCACerts(nlTestSuite * inSuite, void * inContext)
172 CHIP_ERROR err = CHIP_NO_ERROR;
173 const static uint8_t certs[] = {
174 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30, 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, 0x3D, 0x8F, 0x24,
175 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00, 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x41,
176 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4,
177 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5,
178 0xA4, 0x13, 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3,
179 0x48, 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65,
180 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, 0x35, 0x83, 0x29, 0x01, 0x18,
181 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18,
182 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02,
183 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54,
184 0xF5, 0xAE, 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8, 0x54,
185 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, 0x28, 0xAA, 0xC4, 0xF1,
186 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, 0x18,
191 err = ConfigurationMgr().StoreManufacturerDeviceCertificate(certs, sizeof(certs));
192 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
194 err = ConfigurationMgr().GetManufacturerDeviceCertificate(buf, sizeof(buf), certsLen);
195 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
197 NL_TEST_ASSERT(inSuite, certsLen == sizeof(certs));
198 NL_TEST_ASSERT(inSuite, memcmp(buf, certs, certsLen) == 0);
201 static void TestConfigurationMgr_ManufacturerDevicePrivateKey(nlTestSuite * inSuite, void * inContext)
203 CHIP_ERROR err = CHIP_NO_ERROR;
204 const static uint8_t key[] = {
205 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, 0x35, 0x83, 0x29, 0x01, 0x18,
206 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18,
207 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02,
212 err = ConfigurationMgr().StoreManufacturerDevicePrivateKey(key, sizeof(key));
213 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
215 err = ConfigurationMgr().GetManufacturerDevicePrivateKey(buf, sizeof(buf), keyLen);
216 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
218 NL_TEST_ASSERT(inSuite, keyLen == sizeof(key));
219 NL_TEST_ASSERT(inSuite, memcmp(buf, key, keyLen) == 0);
222 static void TestConfigurationMgr_FabricId(nlTestSuite * inSuite, void * inContext)
224 #if CHIP_CONFIG_ENABLE_FABRIC_STATE
225 CHIP_ERROR err = CHIP_NO_ERROR;
226 uint64_t fabricId = 0;
228 err = ConfigurationMgr().StoreFabricId(2006255910626445ULL);
229 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
231 err = ConfigurationMgr().GetFabricId(fabricId);
232 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
234 NL_TEST_ASSERT(inSuite, fabricId == 2006255910626445ULL);
238 static void TestConfigurationMgr_ServiceConfig(nlTestSuite * inSuite, void * inContext)
240 CHIP_ERROR err = CHIP_NO_ERROR;
243 size_t serviceConfigLen = 0;
244 const static uint8_t serviceConfig[] = {
245 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, 0x18,
246 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, 0xA4, 0x13,
247 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, 0x48, 0x53, 0x87,
248 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65, 0x80, 0x08, 0x17, 0x6B,
249 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, 0x35, 0x83, 0x29, 0x01, 0x18, 0x35, 0x82, 0x29, 0x01, 0x24,
250 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08,
251 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4,
252 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54, 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30,
253 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, 0x3D, 0x8F, 0x24, 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00,
254 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x41, 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06,
255 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23,
256 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, 0xA4, 0x13, 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E,
257 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, 0x48, 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3,
258 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65, 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86,
259 0x35, 0x83, 0x29, 0x01, 0x18, 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04,
260 0x02, 0x04, 0x01, 0x18, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35,
261 0x80, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6,
262 0x5D, 0x54, 0xF5, 0xAE, 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8,
263 0x54, 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, 0x28, 0xAA, 0xC4, 0xF1,
264 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, 0x18, 0x18, 0x02, 0x40
266 err = ConfigurationMgr().StoreServiceConfig(serviceConfig, sizeof(serviceConfig));
267 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
269 err = ConfigurationMgr().GetServiceConfig(buf, 1024, serviceConfigLen);
270 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
272 NL_TEST_ASSERT(inSuite, serviceConfigLen == sizeof(serviceConfig));
273 NL_TEST_ASSERT(inSuite, memcmp(buf, serviceConfig, serviceConfigLen) == 0);
276 static void TestConfigurationMgr_SetupPinCode(nlTestSuite * inSuite, void * inContext)
278 CHIP_ERROR err = CHIP_NO_ERROR;
280 const uint32_t setSetupPinCode = 34567890;
281 uint32_t getSetupPinCode = 0;
283 err = ConfigurationMgr().StoreSetupPinCode(setSetupPinCode);
284 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
286 err = ConfigurationMgr().GetSetupPinCode(getSetupPinCode);
287 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
289 NL_TEST_ASSERT(inSuite, getSetupPinCode == setSetupPinCode);
292 static void TestConfigurationMgr_SetupDiscriminator(nlTestSuite * inSuite, void * inContext)
294 CHIP_ERROR err = CHIP_NO_ERROR;
296 const uint16_t setSetupDiscriminator = 0xBA0;
297 uint16_t getSetupDiscriminator = 0;
299 err = ConfigurationMgr().StoreSetupDiscriminator(setSetupDiscriminator);
300 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
302 err = ConfigurationMgr().GetSetupDiscriminator(getSetupDiscriminator);
303 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
305 NL_TEST_ASSERT(inSuite, getSetupDiscriminator == setSetupDiscriminator);
308 static void TestConfigurationMgr_PairedAccountId(nlTestSuite * inSuite, void * inContext)
310 CHIP_ERROR err = CHIP_NO_ERROR;
313 size_t accountIdLen = 0;
314 const char * accountId = "USER_016CB664A86A888D";
316 err = ConfigurationMgr().StorePairedAccountId(accountId, strlen(accountId));
317 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
319 err = ConfigurationMgr().GetPairedAccountId(buf, 64, accountIdLen);
320 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
322 NL_TEST_ASSERT(inSuite, accountIdLen == strlen(accountId));
323 NL_TEST_ASSERT(inSuite, strcmp(buf, "USER_016CB664A86A888D") == 0);
326 static void TestConfigurationMgr_ServiceProvisioningData(nlTestSuite * inSuite, void * inContext)
328 CHIP_ERROR err = CHIP_NO_ERROR;
333 size_t accountIdLen = 0;
334 const char * accountId = "USER_016CB664A86A888D";
337 size_t serviceConfigLen = 0;
338 const static uint8_t serviceConfig[] = {
339 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06, 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, 0x18,
340 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23, 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, 0xA4, 0x13,
341 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E, 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, 0x48, 0x53, 0x87,
342 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3, 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65, 0x80, 0x08, 0x17, 0x6B,
343 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86, 0x35, 0x83, 0x29, 0x01, 0x18, 0x35, 0x82, 0x29, 0x01, 0x24,
344 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04, 0x02, 0x04, 0x01, 0x18, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08,
345 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35, 0x80, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4,
346 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6, 0x5D, 0x54, 0xD5, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x30,
347 0x01, 0x08, 0x79, 0x55, 0x9F, 0x15, 0x1F, 0x66, 0x3D, 0x8F, 0x24, 0x02, 0x05, 0x37, 0x03, 0x27, 0x13, 0x02, 0x00, 0x00,
348 0xEE, 0xEE, 0x30, 0xB4, 0x18, 0x18, 0x26, 0x04, 0x80, 0x41, 0x1B, 0x23, 0x26, 0x05, 0x7F, 0xFF, 0xFF, 0x52, 0x37, 0x06,
349 0x27, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x30, 0xB4, 0x18, 0x18, 0x24, 0x07, 0x02, 0x26, 0x08, 0x25, 0x00, 0x5A, 0x23,
350 0x30, 0x0A, 0x39, 0x04, 0x9E, 0xC7, 0x77, 0xC5, 0xA4, 0x13, 0x31, 0xF7, 0x72, 0x2E, 0x27, 0xC2, 0x86, 0x3D, 0xC5, 0x2E,
351 0xD5, 0xD2, 0x3C, 0xCF, 0x7E, 0x06, 0xE3, 0x48, 0x53, 0x87, 0xE8, 0x4D, 0xB0, 0x27, 0x07, 0x58, 0x4A, 0x38, 0xB4, 0xF3,
352 0xB2, 0x47, 0x94, 0x45, 0x58, 0x65, 0x80, 0x08, 0x17, 0x6B, 0x8E, 0x4F, 0x07, 0x41, 0xA3, 0x3D, 0x5D, 0xCE, 0x76, 0x86,
353 0x35, 0x83, 0x29, 0x01, 0x18, 0x35, 0x82, 0x29, 0x01, 0x24, 0x02, 0x05, 0x18, 0x35, 0x84, 0x29, 0x01, 0x36, 0x02, 0x04,
354 0x02, 0x04, 0x01, 0x18, 0x18, 0x35, 0x81, 0x30, 0x02, 0x08, 0x42, 0xBD, 0x2C, 0x6B, 0x5B, 0x3A, 0x18, 0x16, 0x18, 0x35,
355 0x80, 0x30, 0x02, 0x08, 0x44, 0xE3, 0x40, 0x38, 0xA9, 0xD4, 0xB5, 0xA7, 0x18, 0x35, 0x0C, 0x30, 0x01, 0x19, 0x00, 0xA6,
356 0x5D, 0x54, 0xF5, 0xAE, 0x5D, 0x63, 0xEB, 0x69, 0xD8, 0xDB, 0xCB, 0xE2, 0x20, 0x0C, 0xD5, 0x6F, 0x43, 0x5E, 0x96, 0xA8,
357 0x54, 0xB2, 0x74, 0x30, 0x02, 0x19, 0x00, 0xE0, 0x37, 0x02, 0x8B, 0xB3, 0x04, 0x06, 0xDD, 0xBD, 0x28, 0xAA, 0xC4, 0xF1,
358 0xFF, 0xFB, 0xB1, 0xD4, 0x1C, 0x78, 0x40, 0xDA, 0x2C, 0xD8, 0x40, 0x18, 0x18, 0x18, 0x02, 0x40
362 err = ConfigurationMgr().StoreServiceProvisioningData(7212064004600625234, serviceConfig, sizeof(serviceConfig), accountId,
364 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
366 err = ConfigurationMgr().ClearServiceProvisioningData();
367 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
369 err = ConfigurationMgr().GetServiceId(serviceId);
370 NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
372 err = ConfigurationMgr().GetPairedAccountId(account, 64, accountIdLen);
373 NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
375 err = ConfigurationMgr().GetServiceConfig(buf, 512, serviceConfigLen);
376 NL_TEST_ASSERT(inSuite, err != CHIP_NO_ERROR);
379 err = ConfigurationMgr().StoreServiceProvisioningData(7212064004600625234, serviceConfig, sizeof(serviceConfig), accountId,
381 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
383 err = ConfigurationMgr().GetServiceId(serviceId);
384 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
385 NL_TEST_ASSERT(inSuite, serviceId == 7212064004600625234);
387 err = ConfigurationMgr().GetPairedAccountId(account, 64, accountIdLen);
388 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
389 NL_TEST_ASSERT(inSuite, accountIdLen == strlen(accountId));
390 NL_TEST_ASSERT(inSuite, strcmp(account, "USER_016CB664A86A888D") == 0);
392 err = ConfigurationMgr().GetServiceConfig(buf, 512, serviceConfigLen);
393 NL_TEST_ASSERT(inSuite, err == CHIP_NO_ERROR);
394 NL_TEST_ASSERT(inSuite, serviceConfigLen == sizeof(serviceConfig));
395 NL_TEST_ASSERT(inSuite, memcmp(buf, serviceConfig, serviceConfigLen) == 0);
399 * Test Suite. It lists all the test functions.
401 static const nlTest sTests[] = {
403 NL_TEST_DEF("Test PlatformMgr::Init", TestPlatformMgr_Init),
405 NL_TEST_DEF("Test PlatformMgr::RunUnitTest", TestPlatformMgr_RunUnitTest),
407 NL_TEST_DEF("Test ConfigurationMgr::SerialNumber", TestConfigurationMgr_SerialNumber),
408 NL_TEST_DEF("Test ConfigurationMgr::ManufacturingDate", TestConfigurationMgr_ManufacturingDate),
409 NL_TEST_DEF("Test ConfigurationMgr::ProductRevision", TestConfigurationMgr_ProductRevision),
410 NL_TEST_DEF("Test ConfigurationMgr::ManufacturerDeviceId", TestConfigurationMgr_ManufacturerDeviceId),
411 NL_TEST_DEF("Test ConfigurationMgr::ManufacturerDeviceCertificate", TestConfigurationMgr_ManufacturerDeviceCertificate),
412 NL_TEST_DEF("Test ConfigurationMgr::ManufacturerDeviceIntermediateCACerts",
413 TestConfigurationMgr_ManufacturerDeviceIntermediateCACerts),
414 NL_TEST_DEF("Test ConfigurationMgr::ManufacturerDevicePrivateKey", TestConfigurationMgr_ManufacturerDevicePrivateKey),
415 NL_TEST_DEF("Test ConfigurationMgr::SetupPinCode", TestConfigurationMgr_SetupPinCode),
416 NL_TEST_DEF("Test ConfigurationMgr::SetupDiscriminator", TestConfigurationMgr_SetupDiscriminator),
417 NL_TEST_DEF("Test ConfigurationMgr::FabricId", TestConfigurationMgr_FabricId),
418 NL_TEST_DEF("Test ConfigurationMgr::ServiceConfig", TestConfigurationMgr_ServiceConfig),
419 NL_TEST_DEF("Test ConfigurationMgr::PairedAccountId", TestConfigurationMgr_PairedAccountId),
420 NL_TEST_DEF("Test ConfigurationMgr::ServiceProvisioningData", TestConfigurationMgr_ServiceProvisioningData),
425 * Set up the test suite.
427 int TestConfigurationMgr_Setup(void * inContext)
429 CHIP_ERROR error = chip::Platform::MemoryInit();
430 if (error != CHIP_NO_ERROR)
436 * Tear down the test suite.
438 int TestConfigurationMgr_Teardown(void * inContext)
440 chip::Platform::MemoryShutdown();
444 int TestConfigurationMgr()
446 nlTestSuite theSuite = { "ConfigurationMgr tests", &sTests[0], TestConfigurationMgr_Setup, TestConfigurationMgr_Teardown };
448 // Run test suit againt one context.
449 nlTestRunner(&theSuite, nullptr);
450 return nlTestRunnerStats(&theSuite);
453 CHIP_REGISTER_TEST_SUITE(TestConfigurationMgr)