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