• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "cm_test_log.h"
18 #include "cm_test_common.h"
19 #include "cert_manager_api.h"
20 #include "cm_log.h"
21 #include "cm_mem.h"
22 #include "cm_cert_data_user.h"
23 
24 using namespace testing::ext;
25 using namespace CertmanagerTest;
26 namespace {
27 static uint32_t g_selfTokenId = 0;
28 static MockHapToken* g_MockHap = nullptr;
29 constexpr uint32_t MAX_URI_LEN = 256;
30 constexpr uint32_t ERROR_SCOPE = 3;
31 
32 struct CmBlob userCert[] = {
33     { sizeof(g_certData01), const_cast<uint8_t *>(g_certData01) },
34     { sizeof(g_certData02), const_cast<uint8_t *>(g_certData02) },
35     { sizeof(g_certData03), const_cast<uint8_t *>(g_certData03) },
36     { sizeof(g_certData05), const_cast<uint8_t *>(g_certData05) }
37 };
38 
39 static uint8_t certAliasBuf01[] = "40dc992e";
40 static uint8_t certAliasBuf02[] = "985c1f52";
41 static uint8_t certAliasBuf03[] = "1df5a75f";
42 static uint8_t certAliasBuf05[] = "2e0g9ue5";
43 
44 struct CmBlob certAlias[] = {
45     { sizeof(certAliasBuf01), certAliasBuf01 },
46     { sizeof(certAliasBuf02), certAliasBuf02 },
47     { sizeof(certAliasBuf03), certAliasBuf03 },
48     { sizeof(certAliasBuf05), certAliasBuf05 }
49 };
50 
51 class CmGetUserCertListTest : public testing::Test {
52 public:
53     static void SetUpTestCase(void);
54 
55     static void TearDownTestCase(void);
56 
57     void SetUp();
58 
59     void TearDown();
60 
61     struct CertList *lstCert;
62 };
63 
SetUpTestCase(void)64 void CmGetUserCertListTest::SetUpTestCase(void)
65 {
66     g_selfTokenId = GetSelfTokenID();
67     CmTestCommon::SetTestEnvironment(g_selfTokenId);
68 }
69 
TearDownTestCase(void)70 void CmGetUserCertListTest::TearDownTestCase(void)
71 {
72     CmTestCommon::ResetTestEnvironment();
73 }
74 
SetUp()75 void CmGetUserCertListTest::SetUp()
76 {
77     InitCertList(&lstCert);
78     g_MockHap = new (std::nothrow) MockHapToken();
79 }
80 
TearDown()81 void CmGetUserCertListTest::TearDown()
82 {
83     FreeCertList(lstCert);
84     if (g_MockHap != nullptr) {
85         delete g_MockHap;
86         g_MockHap = nullptr;
87     }
88 }
89 
90 /* installation in the directory with userid 0 */
CmInstallTestCert()91 static uint32_t CmInstallTestCert()
92 {
93     int32_t ret;
94     uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
95 
96     for (uint32_t i = 0; i < size; i++) {
97         uint8_t uriBuf[MAX_URI_LEN] = {0};
98         struct CmBlob certUri = { sizeof(uriBuf), uriBuf };
99         ret = CmInstallUserTrustedCert(&userCert[i], &certAlias[i], &certUri);
100         EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Install test failed, recode:" << ret;
101     }
102 
103     return ret;
104 }
105 
106 /* installation in any userid directory  */
CmInstallCATestCert(uint32_t userId)107 static uint32_t CmInstallCATestCert(uint32_t userId)
108 {
109     int32_t ret;
110     uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
111 
112     for (uint32_t i = 0; i < size; i++) {
113         uint8_t uriBuf[MAX_URI_LEN] = {0};
114         struct CmBlob certUri = { sizeof(uriBuf), uriBuf };
115         ret = CmInstallUserCACert(&userCert[i], &certAlias[i], userId, true, &certUri);
116         EXPECT_EQ(ret, CM_SUCCESS) << "Normal user CA cert Install test failed, recode:" << ret;
117     }
118 
119     return ret;
120 }
121 
122 /* install the maximum limit certs in userid 0 */
CmInstallBorderTestCert()123 static uint32_t CmInstallBorderTestCert()
124 {
125     int32_t ret;
126     struct CmBlob userCertTest = { sizeof(g_certData01), const_cast<uint8_t *>(g_certData01) };
127 
128     for (uint32_t i = 0; i < MAX_COUNT_CERTIFICATE; i++) { /* install 256 times user cert */
129         std::string alias = "alias_global_" + std::to_string(i);
130         char *aliasBuf = const_cast<char *>(alias.c_str());
131         struct CmBlob certAliasTest = { alias.length() + 1, reinterpret_cast<uint8_t *>(aliasBuf) };
132 
133         uint8_t uriBuf[MAX_URI_LEN] = {0};
134         struct CmBlob certUriTest = { sizeof(uriBuf), uriBuf };
135 
136         ret =  CmInstallUserTrustedCert(&userCertTest, &certAliasTest, &certUriTest);
137         EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Install test failed, recode:" << ret;
138     }
139     return ret;
140 }
141 
142 /* install the maximum limit certs in any directory */
CmInstallCABorderTestCert(uint32_t userId)143 static uint32_t CmInstallCABorderTestCert(uint32_t userId)
144 {
145     int32_t ret;
146     struct CmBlob userCertTest = { sizeof(g_certData01), const_cast<uint8_t *>(g_certData01) };
147 
148     for (uint32_t i = 0; i < MAX_COUNT_CERTIFICATE; i++) { /* install 256 times user cert */
149         std::string alias = "alias_user_" + std::to_string(i);
150         char *aliasBuf = const_cast<char *>(alias.c_str());
151         struct CmBlob certAliasTest = { alias.length() + 1, reinterpret_cast<uint8_t *>(aliasBuf) };
152 
153         uint8_t uriBuf[MAX_URI_LEN] = {0};
154         struct CmBlob certUriTest = { sizeof(uriBuf), uriBuf };
155 
156         ret = CmInstallUserCACert(&userCertTest, &certAliasTest, userId, true, &certUriTest);
157         EXPECT_EQ(ret, CM_SUCCESS) << "Normal user CA cert Install test failed, recode:" << ret;
158     }
159     return ret;
160 }
161 
162 /* uninstall the maximum limit certs in any directory */
CmUninstallCACertList(struct CertList * certList)163 static uint32_t CmUninstallCACertList(struct CertList *certList)
164 {
165     int32_t ret;
166 
167     for (uint32_t i = 0; i < certList->certsCount; i++) {
168         const struct CmBlob certUri = {
169             .size = strlen(certList->certAbstract[i].uri) + 1,
170             .data = reinterpret_cast<uint8_t *>(certList->certAbstract[i].uri)
171         };
172         ret = CmUninstallUserTrustedCert(&certUri);
173         EXPECT_EQ(ret, CM_SUCCESS) << "Normal Uninstall trusted cert test failed, recode:" << ret;
174     }
175     return ret;
176 }
177 
178 /* Initialize the minimum space */
InitSmallCertList(struct CertList ** cList)179 static int32_t InitSmallCertList(struct CertList **cList)
180 {
181     *cList = static_cast<struct CertList *>(CmMalloc(sizeof(struct CertList)));
182     if (*cList == nullptr) {
183         return CMR_ERROR_MALLOC_FAIL;
184     }
185 
186     uint32_t buffSize = sizeof(struct CertAbstract);
187     (*cList)->certAbstract = static_cast<struct CertAbstract *>(CmMalloc(buffSize));
188     if ((*cList)->certAbstract == NULL) {
189         return CMR_ERROR_MALLOC_FAIL;
190     }
191     (void)memset_s((*cList)->certAbstract, buffSize, 0, buffSize);
192     (*cList)->certsCount = 1;
193 
194     return CM_SUCCESS;
195 }
196 
197 /* If there is a failed use case, run the command to uninstall all certificates */
198 // /**
199 //  * @tc.name: CmUninstallAllUserCACert001
200 //  * @tc.desc: Test CertManager Get target user cert list interface performance
201 //  * @tc.type: FUNC
202 //  * @tc.require: AR000H0MJ8 /SR000H09N7
203 //  */
204 HWTEST_F(CmGetUserCertListTest, CmUninstallAllUserCACert001, TestSize.Level0)
205 {
206     int32_t ret;
207     struct CertList *certList001 = nullptr;
208     InitCertList(&certList001);
209     struct CertList *certList002 = nullptr;
210     InitCertList(&certList002);
211 
212     struct UserCAProperty prop = { TEST_USERID, CM_CURRENT_USER };
213     ret = CmGetUserCACertList(&prop, certList001);
214     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
215     prop = { SA_USERID, CM_CURRENT_USER };
216     ret = CmGetUserCACertList(&prop, certList002);
217     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
218 
219     ret = CmUninstallCACertList(certList001);
220     EXPECT_EQ(ret, CM_SUCCESS) << "Normal uninstall CA cert list failed, recode:" << ret;
221     ret = CmUninstallCACertList(certList002);
222     EXPECT_EQ(ret, CM_SUCCESS) << "Normal uninstall CA cert list failed, recode:" << ret;
223     FreeCertList(certList001);
224     FreeCertList(certList002);
225 }
226 
227 /**
228  * @tc.name: CmGetUserCACertList001
229  * @tc.desc: Test CertManager Get target user cert list interface performance
230  * @tc.type: FUNC
231  * @tc.require: AR000H0MJ8 /SR000H09N7
232  */
233 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList001, TestSize.Level0)
234 {
235     int32_t ret;
236     uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
237 
238     ret = CmInstallTestCert();
239     EXPECT_EQ(ret, CM_SUCCESS) << "Install test cert failed, recode:" << ret;
240 
241     struct CertList *certList001 = nullptr;
242     InitCertList(&certList001);
243     struct UserCAProperty prop = { SA_USERID, CM_ALL_USER };
244     ret = CmGetUserCACertList(&prop, certList001);
245     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert list test failed, recode:" << ret;
246 
247     uint32_t certsCount001 = certList001->certsCount;
248     EXPECT_EQ(certsCount001, size) << "Get certs count wrong, recode:" << ret;
249 
250     ret = CmUninstallAllUserTrustedCert();
251     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
252     FreeCertList(certList001);
253 }
254 
255 /**
256  * @tc.name: CmGetUserCACertList002
257  * @tc.desc: Test CertManager Get target user cert list interface performance
258  * @tc.type: FUNC
259  * @tc.require: AR000H0MJ8 /SR000H09N7
260  */
261 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList002, TestSize.Level0)
262 {
263     int32_t ret;
264     int32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
265 
266     ret = CmInstallTestCert();
267     EXPECT_EQ(ret, CM_SUCCESS) << "Install test cert failed, recode:" << ret;
268 
269     struct CertList *certList002 = nullptr;
270     InitCertList(&certList002);
271     struct UserCAProperty prop = { SA_USERID, CM_CURRENT_USER };
272     ret = CmGetUserCACertList(&prop, certList002);
273     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert list test failed, recode:" << ret;
274 
275     uint32_t certsCount002 = certList002->certsCount;
276     EXPECT_EQ(certsCount002, size) << "Get certs count wrong, recode:" << ret;
277 
278     ret = CmUninstallAllUserTrustedCert();
279     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
280     FreeCertList(certList002);
281 }
282 
283 /**
284  * @tc.name: CmGetUserCACertList003
285  * @tc.desc: Test CertManager Get target user cert list interface performance
286  * @tc.type: FUNC
287  * @tc.require: AR000H0MJ8 /SR000H09N7
288  */
289 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList003, TestSize.Level0)
290 {
291     int32_t ret;
292     int32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
293 
294     ret = CmInstallTestCert();
295     EXPECT_EQ(ret, CM_SUCCESS) << "Install test cert failed, recode:" << ret;
296 
297     struct CertList *certList003 = nullptr;
298     InitCertList(&certList003);
299     struct UserCAProperty prop = { SA_USERID, CM_GLOBAL_USER };
300     ret = CmGetUserCACertList(&prop, certList003);
301     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert list test failed, recode:" << ret;
302 
303     uint32_t certsCount003 = certList003->certsCount;
304     EXPECT_EQ(certsCount003, size) << "Get certs count wrong, recode:" << ret;
305 
306     ret = CmUninstallAllUserTrustedCert();
307     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
308     FreeCertList(certList003);
309 }
310 
311 /**
312  * @tc.name: CmGetUserCACertList004
313  * @tc.desc: Test CertManager Get target user cert list interface performance
314  * @tc.type: FUNC
315  * @tc.require: AR000H0MJ8 /SR000H09N7
316  */
317 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList004, TestSize.Level0)
318 {
319     int32_t ret;
320     int32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
321 
322     ret = CmInstallTestCert();
323     EXPECT_EQ(ret, CM_SUCCESS) << "Install test cert failed, recode:" << ret;
324 
325     struct CertList *certList004 = nullptr;
326     InitCertList(&certList004);
327     struct UserCAProperty prop = { TEST_USERID, CM_ALL_USER };
328     ret = CmGetUserCACertList(&prop, certList004);
329     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert list test failed, recode:" << ret;
330 
331     uint32_t certsCount004 = certList004->certsCount;
332     EXPECT_EQ(certsCount004, size) << "Get certs count wrong, recode:" << ret;
333 
334 
335     ret = CmUninstallAllUserTrustedCert();
336     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
337     FreeCertList(certList004);
338 }
339 
340 /**
341  * @tc.name: CmGetUserCACertList005
342  * @tc.desc: Test CertManager Get target user cert list interface performance
343  * @tc.type: FUNC
344  * @tc.require: AR000H0MJ8 /SR000H09N7
345  */
346 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList005, TestSize.Level0)
347 {
348     int32_t ret;
349     uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
350 
351     ret = CmInstallCATestCert(TEST_USERID);
352     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install CA test cert failed, recode:" << ret;
353 
354     struct CertList *certList005 = nullptr;
355     InitCertList(&certList005);
356     struct UserCAProperty prop = { TEST_USERID, CM_ALL_USER };
357     ret = CmGetUserCACertList(&prop, certList005);
358     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user cert list test failed, recode:" << ret;
359 
360     uint32_t certsCount005 = certList005->certsCount;
361     EXPECT_EQ(certsCount005, size) << "Get certs count wrong, recode:" << ret;
362 
363     ret = CmUninstallCACertList(certList005);
364     EXPECT_EQ(ret, CM_SUCCESS) << "Normal uninstall CA cert list failed, recode:" << ret;
365     FreeCertList(certList005);
366 }
367 
368 // /**
369 //  * @tc.name: CmGetUserCACertList006
370 //  * @tc.desc: Test CertManager Get target user cert list interface performance
371 //  * @tc.type: FUNC
372 //  * @tc.require: AR000H0MJ8 /SR000H09N7
373 //  */
374 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList006, TestSize.Level0)
375 {
376     int32_t ret;
377     uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
378 
379     ret = CmInstallTestCert();
380     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install test cert failed, recode:" << ret;
381     ret = CmInstallCATestCert(TEST_USERID);
382     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install CA test cert failed, recode:" << ret;
383 
384     struct CertList *certList006 = nullptr;
385     InitCertList(&certList006);
386     struct CertList *certList007 = nullptr;
387     InitCertList(&certList007);
388     struct UserCAProperty prop = { SA_USERID, CM_ALL_USER };
389     ret = CmGetUserCACertList(&prop, certList006);
390     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
391 
392     uint32_t certsCount006 = certList006->certsCount;
393     EXPECT_EQ(certsCount006, size) << "Get certs count wrong, recode:" << ret;
394 
395     prop = { TEST_USERID, CM_ALL_USER };
396     ret = CmGetUserCACertList(&prop, certList007);
397 
398     CmUninstallCACertList(certList007);
399     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall CA test cert failed, recode:" << ret;
400     FreeCertList(certList006);
401     FreeCertList(certList007);
402 }
403 
404 // /**
405 //  * @tc.name: CmGetUserCACertList007
406 //  * @tc.desc: Test CertManager Get target user cert list interface performance
407 //  * @tc.type: FUNC
408 //  * @tc.require: AR000H0MJ8 /SR000H09N7
409 //  */
410 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList007, TestSize.Level0)
411 {
412     int32_t ret;
413     uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]) * 2;
414 
415     ret = CmInstallTestCert();
416     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install test cert failed, recode:" << ret;
417     ret = CmInstallCATestCert(TEST_USERID);
418     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install CA test cert failed, recode:" << ret;
419 
420     struct CertList *certList007 = nullptr;
421     InitCertList(&certList007);
422     struct UserCAProperty prop = { TEST_USERID, CM_ALL_USER };
423     ret = CmGetUserCACertList(&prop, certList007);
424     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
425 
426     uint32_t certsCount007 = certList007->certsCount;
427     EXPECT_EQ(certsCount007, size) << "Get certs count wrong, recode:" << ret;
428 
429     CmUninstallCACertList(certList007);
430     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall CA test cert failed, recode:" << ret;
431     FreeCertList(certList007);
432 }
433 
434 /**
435  * @tc.name: CmGetUserCACertList008
436  * @tc.desc: Test CertManager Get target user cert list interface Abnormal performance
437  * @tc.type: FUNC
438  * @tc.require: AR000H0MJ8 /SR000H09N7
439  */
440 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList008, TestSize.Level0)
441 {
442     int32_t ret;
443     struct CertList *certList008 = nullptr;
444     InitCertList(&certList008);
445 
446     struct UserCAProperty prop = { SA_USERID, CM_ALL_USER };
447     ret = CmGetUserCACertList(&prop, certList008);
448     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
449 
450     uint32_t certsCount008 = certList008->certsCount;
451     EXPECT_EQ(certsCount008, 0) << "Get certs count wrong, recode:" << ret;
452     FreeCertList(certList008);
453 }
454 
455 // /**
456 //  * @tc.name: CmGetUserCACertList009
457 //  * @tc.desc: Test CertManager Get target user cert list interface Abnormal performance
458 //  * @tc.type: FUNC
459 //  * @tc.require: AR000H0MJ8 /SR000H09N7
460 //  */
461 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList009, TestSize.Level0)
462 {
463     int32_t ret;
464     struct CertList *certList009 = nullptr;
465     InitCertList(&certList009);
466 
467     struct UserCAProperty prop = { SA_USERID, CM_CURRENT_USER };
468     ret = CmGetUserCACertList(&prop, certList009);
469     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
470 
471     uint32_t certsCount009 = certList009->certsCount;
472     EXPECT_EQ(certsCount009, 0) << "Get certs count wrong, recode:" << ret;
473     FreeCertList(certList009);
474 }
475 
476 
477 // /**
478 //  * @tc.name: CmGetUserCACertList010
479 //  * @tc.desc: Test CertManager Get target user cert list interface Abnormal performance
480 //  * @tc.type: FUNC
481 //  * @tc.require: AR000H0MJ8 /SR000H09N7
482 //  */
483 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList010, TestSize.Level0)
484 {
485     int32_t ret;
486     struct CertList *certList010 = nullptr;
487     InitCertList(&certList010);
488 
489     struct UserCAProperty prop = { SA_USERID, CM_GLOBAL_USER };
490     ret = CmGetUserCACertList(&prop, certList010);
491     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
492 
493     uint32_t certsCount010 = certList010->certsCount;
494     EXPECT_EQ(certsCount010, 0) << "Get certs count wrong, recode:" << ret;
495     FreeCertList(certList010);
496 }
497 
498 // /**
499 //  * @tc.name: CmGetUserCACertList011
500 //  * @tc.desc: Test CertManager Get target user cert list interface Abnormal performance
501 //  * @tc.type: FUNC
502 //  * @tc.require: AR000H0MJ8 /SR000H09N7
503 //  */
504 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList011, TestSize.Level0)
505 {
506     int32_t ret;
507     struct CertList *certList011 = nullptr;
508     InitCertList(&certList011);
509 
510     struct UserCAProperty prop = { TEST_USERID, CM_ALL_USER };
511     ret = CmGetUserCACertList(&prop, certList011);
512     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
513 
514     uint32_t certsCount011 = certList011->certsCount;
515     EXPECT_EQ(certsCount011, 0) << "Get certs count wrong, recode:" << ret;
516     FreeCertList(certList011);
517 }
518 
519 // /**
520 //  * @tc.name: CmGetUserCACertList012
521 //  * @tc.desc: Test CertManager Get target user cert list interface boundary performance
522 //  * @tc.type: FUNC
523 //  * @tc.require: AR000H0MJ8 /SR000H09N7s
524 //  */
525 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList012, TestSize.Level0)
526 {
527     int32_t ret;
528     struct CertList *certList012 = nullptr;
529     InitCertList(&certList012);
530 
531     ret = CmInstallBorderTestCert();
532     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border test cert failed, recode:" << ret;
533 
534     struct UserCAProperty prop = { SA_USERID, CM_ALL_USER };
535     ret = CmGetUserCACertList(&prop, certList012);
536     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
537 
538     uint32_t certsCount012 = certList012->certsCount;
539     EXPECT_EQ(certsCount012, MAX_COUNT_CERTIFICATE) << "Get certs count wrong, recode:" << ret;
540 
541     ret = CmUninstallAllUserTrustedCert();
542     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
543     FreeCertList(certList012);
544 }
545 
546 // /**
547 //  * @tc.name: CmGetUserCACertList013
548 //  * @tc.desc: Test CertManager Get target user cert list interface boundary performance
549 //  * @tc.type: FUNC
550 //  * @tc.require: AR000H0MJ8 /SR000H09N7s
551 //  */
552 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList013, TestSize.Level0)
553 {
554     int32_t ret;
555     struct CertList *certList013 = nullptr;
556     InitCertList(&certList013);
557 
558     ret = CmInstallBorderTestCert();
559     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border test cert failed, recode:" << ret;
560 
561     struct UserCAProperty prop = { SA_USERID, CM_CURRENT_USER };
562     ret = CmGetUserCACertList(&prop, certList013);
563     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
564 
565     uint32_t certsCount013 = certList013->certsCount;
566     EXPECT_EQ(certsCount013, MAX_COUNT_CERTIFICATE) << "Get certs count wrong, recode:" << ret;
567 
568     ret = CmUninstallAllUserTrustedCert();
569     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
570     FreeCertList(certList013);
571 }
572 
573 // /**
574 //  * @tc.name: CmGetUserCACertList014
575 //  * @tc.desc: Test CertManager Get target user cert list interface boundary performance
576 //  * @tc.type: FUNC
577 //  * @tc.require: AR000H0MJ8 /SR000H09N7
578 //  */
579 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList014, TestSize.Level0)
580 {
581     int32_t ret;
582     struct CertList *certList014 = nullptr;
583     InitCertList(&certList014);
584 
585     ret = CmInstallBorderTestCert();
586     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border test cert failed, recode:" << ret;
587 
588     struct UserCAProperty prop = { SA_USERID, CM_GLOBAL_USER };
589     ret = CmGetUserCACertList(&prop, certList014);
590     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
591 
592     uint32_t certsCount014 = certList014->certsCount;
593     EXPECT_EQ(certsCount014, MAX_COUNT_CERTIFICATE) << "Get certs count wrong, recode:" << ret;
594 
595     ret = CmUninstallAllUserTrustedCert();
596     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
597     FreeCertList(certList014);
598 }
599 
600 // /**
601 //  * @tc.name: CmGetUserCACertList015
602 //  * @tc.desc: Test CertManager Get target user cert list interface boundary performance
603 //  * @tc.type: FUNC
604 //  * @tc.require: AR000H0MJ8 /SR000H09N7
605 //  */
606 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList015, TestSize.Level0)
607 {
608     int32_t ret;
609     struct CertList *certList015 = nullptr;
610     InitCertList(&certList015);
611 
612     ret = CmInstallBorderTestCert();
613     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border test cert failed, recode:" << ret;
614 
615     struct UserCAProperty prop = { TEST_USERID, CM_ALL_USER };
616     ret = CmGetUserCACertList(&prop, certList015);
617     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
618 
619     uint32_t certsCount015 = certList015->certsCount;
620     EXPECT_EQ(certsCount015, MAX_COUNT_CERTIFICATE) << "Get certs count wrong, recode:" << ret;
621 
622     ret = CmUninstallAllUserTrustedCert();
623     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
624     FreeCertList(certList015);
625 }
626 
627 // /**
628 //  * @tc.name: CmGetUserCACertList016
629 //  * @tc.desc: Test CertManager Get target user cert list interface boundary performance
630 //  * @tc.type: FUNC
631 //  * @tc.require: AR000H0MJ8 /SR000H09N7
632 //  */
633 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList016, TestSize.Level0)
634 {
635     int32_t ret;
636     struct CertList *certList016 = nullptr;
637     InitCertList(&certList016);
638 
639     ret = CmInstallCABorderTestCert(TEST_USERID);
640     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border CA test cert failed, recode:" << ret;
641 
642     struct UserCAProperty prop = { TEST_USERID, CM_ALL_USER };
643     ret = CmGetUserCACertList(&prop, certList016);
644     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
645 
646     uint32_t certsCount016 = certList016->certsCount;
647     EXPECT_EQ(certsCount016, MAX_COUNT_CERTIFICATE) << "Get certs count wrong, recode:" << ret;
648 
649     CmUninstallCACertList(certList016);
650     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall CA test cert failed, recode:" << ret;
651     FreeCertList(certList016);
652 }
653 
654 // /**
655 //  * @tc.name: CmGetUserCACertList017
656 //  * @tc.desc: Test CertManager Get target user cert list interface boundary performance
657 //  * @tc.type: FUNC
658 //  * @tc.require: AR000H0MJ8 /SR000H09N7
659 //  */
660 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList017, TestSize.Level0)
661 {
662     int32_t ret;
663     struct CertList *certList017 = nullptr;
664     InitCertList(&certList017);
665     struct CertList *certList018 = nullptr;
666     InitCertList(&certList018);
667 
668     ret = CmInstallBorderTestCert();
669     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border test cert failed, recode:" << ret;
670     ret = CmInstallCABorderTestCert(TEST_USERID);
671     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border CA test cert failed, recode:" << ret;
672 
673     struct UserCAProperty prop = { SA_USERID, CM_ALL_USER };
674     ret = CmGetUserCACertList(&prop, certList017);
675     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
676     /* Make sure that the certificate can be completely unmounted */
677     prop = { TEST_USERID, CM_CURRENT_USER };
678     ret = CmGetUserCACertList(&prop, certList018);
679     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
680 
681     uint32_t certsCount017 = certList017->certsCount;
682     EXPECT_EQ(certsCount017, MAX_COUNT_CERTIFICATE) << "Get certs count wrong, recode:" << ret;
683     uint32_t certsCountBak = certList018->certsCount;
684     EXPECT_EQ(certsCountBak, MAX_COUNT_CERTIFICATE) << "Get certs count wrong, recode:" << ret;
685 
686     ret = CmUninstallAllUserTrustedCert();
687     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
688     ret = CmUninstallCACertList(certList018);
689     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall CA test cert failed, recode:" << ret;
690 
691     FreeCertList(certList017);
692     FreeCertList(certList018);
693 }
694 
695 // /**
696 //  * @tc.name: CmGetUserCACertList018
697 //  * @tc.desc: Test CertManager Get target user cert list interface boundary performance
698 //  * @tc.type: FUNC
699 //  * @tc.require: AR000H0MJ8 /SR000H09N7
700 //  */
701 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList018, TestSize.Level0)
702 {
703     int32_t ret;
704     struct CertList *certList018 = nullptr;
705     InitCertList(&certList018);
706 
707     ret = CmInstallBorderTestCert();
708     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border test cert failed, recode:" << ret;
709     ret = CmInstallCABorderTestCert(TEST_USERID);
710     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install border CA test cert failed, recode:" << ret;
711 
712     struct UserCAProperty prop = { TEST_USERID, CM_ALL_USER };
713     ret = CmGetUserCACertList(&prop, certList018);
714     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
715 
716     uint32_t certsCount018 = certList018->certsCount;
717     EXPECT_EQ(certsCount018, MAX_COUNT_CERTIFICATE_ALL) << "Get certs count wrong, recode:" << ret;
718 
719     ret = CmUninstallCACertList(certList018);
720     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall CA test cert failed, recode:" << ret;
721 
722     FreeCertList(certList018);
723 }
724 
725 // /**
726 //  * @tc.name: CmGetUserCACertList019
727 //  * @tc.desc: Test CertManager Get target user cert list interface Abnormal performance
728 //  * @tc.type: FUNC
729 //  * @tc.require: AR000H0MJ8 /SR000H09N7
730 //  */
731 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList019, TestSize.Level0)
732 {
733     int32_t ret;
734     struct CertList *certList019 = nullptr;
735     InitCertList(&certList019);
736 
737     ret = CmGetUserCACertList(nullptr, certList019);
738     EXPECT_EQ(ret, CMR_ERROR_NULL_POINTER) << "Normal get user ca cert list test failed, recode:" << ret;
739     FreeCertList(certList019);
740 }
741 
742 // /**
743 //  * @tc.name: CmGetUserCACertList020
744 //  * @tc.desc: Test CertManager Get target user cert list interface Abnormal performance
745 //  * @tc.type: FUNC
746 //  * @tc.require: AR000H0MJ8 /SR000H09N7
747 //  */
748 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList020, TestSize.Level0)
749 {
750     int32_t ret;
751 
752     struct UserCAProperty prop = { SA_USERID, CM_ALL_USER };
753     ret = CmGetUserCACertList(&prop, nullptr);
754     EXPECT_EQ(ret, CMR_ERROR_NULL_POINTER) << "Normal get user ca cert list test failed, recode:" << ret;
755 }
756 
757 // /**
758 //  * @tc.name: CmGetUserCACertList021
759 //  * @tc.desc: Test CertManager Get target user cert list interface Abnormal performance
760 //  * @tc.type: FUNC
761 //  * @tc.require: AR000H0MJ8 /SR000H09N7
762 //  */
763 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList021, TestSize.Level0)
764 {
765     int32_t ret;
766     struct CertList *certList021 = nullptr;
767     InitCertList(&certList021);
768 
769     struct UserCAProperty prop = { SA_USERID, static_cast<CmCertScope>(ERROR_SCOPE) };
770     ret = CmGetUserCACertList(&prop, certList021);
771     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT) << "Normal get user ca cert list test failed, recode:" << ret;
772     FreeCertList(certList021);
773 }
774 
775 // /**
776 //  * @tc.name: CmGetUserCACertList022
777 //  * @tc.desc: Test CertManager Get target user cert list interface performance
778 //  * @tc.type: FUNC
779 //  * @tc.require: AR000H0MJ8 /SR000H09N7
780 //  */
781 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList022, TestSize.Level0)
782 {
783     int32_t ret;
784     struct CertList *certList022 = nullptr;
785     InitSmallCertList(&certList022);
786 
787     ret = CmInstallTestCert();
788     EXPECT_EQ(ret, CM_SUCCESS) << "Install test cert failed, recode:" << ret;
789 
790     struct UserCAProperty prop = { SA_USERID, CM_ALL_USER };
791     ret = CmGetUserCACertList(&prop, certList022);
792     EXPECT_EQ(ret, CMR_ERROR_BUFFER_TOO_SMALL) << "Normal get user ca cert list test failed, recode:" << ret;
793 
794     ret = CmUninstallAllUserTrustedCert();
795     EXPECT_EQ(ret, CM_SUCCESS) << "Normal user cert Uninstall All test failed, recode:" << ret;
796     FreeCertList(certList022);
797 }
798 
799 // /**
800 //  * @tc.name: CmGetUserCACertList023
801 //  * @tc.desc: Test CertManager Get target user cert list interface performance
802 //  * @tc.type: FUNC
803 //  * @tc.require: AR000H0MJ8 /SR000H09N7
804 //  */
805 HWTEST_F(CmGetUserCertListTest, CmGetUserCACertList023, TestSize.Level0)
806 {
807     int32_t ret;
808     uint32_t size = sizeof(certAlias) / sizeof(certAlias[0]);
809     struct CertList *certList023 = nullptr;
810     InitCertList(&certList023);
811     struct CertList *certList024 = nullptr;
812     InitCertList(&certList024);
813 
814     ret = CmInstallTestCert();
815     EXPECT_EQ(ret, CM_SUCCESS) << "Install test cert failed, recode:" << ret;
816     ret = CmInstallCATestCert(TEST_USERID);
817     EXPECT_EQ(ret, CM_SUCCESS) << "Normal install CA test cert failed, recode:" << ret;
818 
819     struct UserCAProperty prop = { INIT_INVALID_VALUE, CM_ALL_USER };
820     ret = CmGetUserCACertList(&prop, certList023);
821     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
822     uint32_t certsCount = certList023->certsCount;
823     EXPECT_EQ(certsCount, size) << "Get certs count wrong, recode:" << ret;
824 
825     prop = { TEST_USERID, CM_ALL_USER };
826     ret = CmGetUserCACertList(&prop, certList024);
827     EXPECT_EQ(ret, CM_SUCCESS) << "Normal get user ca cert list test failed, recode:" << ret;
828     ret = CmUninstallCACertList(certList024);
829     EXPECT_EQ(ret, CM_SUCCESS) << "Normal uninstall CA cert list failed, recode:" << ret;
830     FreeCertList(certList023);
831     FreeCertList(certList024);
832 }
833 }