1 /*
2  * Copyright (c) 2024-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 
18 #include "hks_config_parser.h"
19 #include "hks_log.h"
20 #include "hks_mem.h"
21 #include "hks_param.h"
22 #include "hks_type_inner.h"
23 
24 #undef HUKS_SA_UPGRADE_CONFIG
25 #undef HUKS_HAP_UPGRADE_CONFIG
26 #undef HUKS_SA_SKIP_UPGRADE_CONFIG
27 #undef HUKS_HAP_SKIP_UPGRADE_CONFIG
28 
29 #define HUKS_SA_UPGRADE_CONFIG { { 6, false, false }, { 7, false, true }, { 8, true, false }, { 9, true, true } }
30 #define HUKS_HAP_UPGRADE_CONFIG { { "com.example.demo1", true, true }, \
31     { "com.example.demo2", true, false }, \
32     { "com.example.demo3", false, true }, \
33     { "com.example.demo4", false, false } }
34 #define HUKS_SA_SKIP_UPGRADE_CONFIG { 0, 10, 99 }
35 #define HUKS_HAP_SKIP_UPGRADE_CONFIG { "com.example.skip1", "com.example.skip2" }
36 
37 #include "base/security/huks/services/huks_standard/huks_service/main/upgrade/file_transfer/src/hks_config_parser.c"
38 
39 enum HksAtType g_accessTokenType = HKS_TOKEN_HAP;
40 char *g_hapName = nullptr;
41 
HksGetAtType(uint64_t accessTokenId,enum HksAtType * atType)42 int32_t HksGetAtType(uint64_t accessTokenId, enum HksAtType *atType)
43 {
44     *atType = g_accessTokenType;
45     return HKS_SUCCESS;
46 }
47 
HksGetHapNameFromAccessToken(int32_t tokenId,char * hapName,int32_t hapNameSize)48 int32_t HksGetHapNameFromAccessToken(int32_t tokenId, char *hapName, int32_t hapNameSize)
49 {
50     (void)memcpy_s(hapName, hapNameSize, g_hapName, strlen(g_hapName));
51     return HKS_SUCCESS;
52 }
53 
54 using namespace testing::ext;
55 namespace Unittest::HksServiceUpgradeConfigParserTest {
56 class HksServiceUpgradeConfigParserTest : public testing::Test {
57 public:
58     static void SetUpTestCase(void);
59 
60     static void TearDownTestCase(void);
61 
62     void SetUp();
63 
64     void TearDown();
65 };
66 
SetUpTestCase(void)67 void HksServiceUpgradeConfigParserTest::SetUpTestCase(void)
68 {
69 }
70 
TearDownTestCase(void)71 void HksServiceUpgradeConfigParserTest::TearDownTestCase(void)
72 {
73 }
74 
SetUp()75 void HksServiceUpgradeConfigParserTest::SetUp()
76 {
77 }
78 
TearDown()79 void HksServiceUpgradeConfigParserTest::TearDown()
80 {
81 }
82 
83 /**
84  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest001
85  * @tc.desc: test HksParseConfig with hap, DE and front-user
86  * @tc.type: FUNC
87  */
88 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest001, TestSize.Level0)
89 {
90     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest001");
91     g_hapName = const_cast<char *>("com.example.demo1");
92     g_accessTokenType = HKS_TOKEN_HAP;
93     struct HksParamSet *paramSet001 = nullptr;
94     (void)HksInitParamSet(&paramSet001);
95     uint32_t userId001 = 0;
96     struct HksParam params[] = {
97         {
98             .tag = HKS_TAG_PROCESS_NAME,
99             .blob = {
100                 .data = reinterpret_cast<uint8_t *>(&userId001),
101                 .size = sizeof(uint32_t)
102             }
103         }, {
104             .tag = HKS_TAG_USER_ID,
105             .uint32Param = userId001
106         }, {
107             .tag = HKS_TAG_ACCESS_TOKEN_ID,
108             .uint64Param = 0
109         }
110     };
111     (void)HksAddParams(paramSet001, params, HKS_ARRAY_SIZE(params));
112     (void)HksBuildParamSet(&paramSet001);
113     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet001),
114         .size = paramSet001->paramSetSize };
115     struct HksUpgradeFileTransferInfo info = { 0 };
116     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
117     EXPECT_EQ(true, info.needDe);
118     EXPECT_EQ(true, info.needFrontUser);
119     EXPECT_EQ(false, info.skipTransfer);
120     EXPECT_EQ(userId001, info.uid);
121     EXPECT_EQ(userId001, info.userId);
122 
123     HksFreeParamSet(&paramSet001);
124 }
125 
126 /**
127  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest002
128  * @tc.desc: test HksParseConfig with hap, DE and self-user
129  * @tc.type: FUNC
130  */
131 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest002, TestSize.Level0)
132 {
133     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest002");
134     g_hapName = const_cast<char *>("com.example.demo2");
135     g_accessTokenType = HKS_TOKEN_HAP;
136     struct HksParamSet *paramSet002 = nullptr;
137     (void)HksInitParamSet(&paramSet002);
138     uint32_t userId002 = 100;
139     struct HksParam params[] = {
140         {
141             .tag = HKS_TAG_PROCESS_NAME,
142             .blob = {
143                 .data = reinterpret_cast<uint8_t *>(&userId002),
144                 .size = sizeof(uint32_t)
145             }
146         }, {
147             .tag = HKS_TAG_USER_ID,
148             .uint32Param = userId002
149         }, {
150             .tag = HKS_TAG_ACCESS_TOKEN_ID,
151             .uint64Param = 0
152         }
153     };
154     (void)HksAddParams(paramSet002, params, HKS_ARRAY_SIZE(params));
155     (void)HksBuildParamSet(&paramSet002);
156     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet002),
157         .size = paramSet002->paramSetSize };
158     struct HksUpgradeFileTransferInfo info = { 0 };
159     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
160     EXPECT_EQ(true, info.needDe);
161     EXPECT_EQ(false, info.needFrontUser);
162     EXPECT_EQ(false, info.skipTransfer);
163     EXPECT_EQ(userId002, info.uid);
164     EXPECT_EQ(userId002, info.userId);
165 
166     HksFreeParamSet(&paramSet002);
167 }
168 
169 /**
170  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest003
171  * @tc.desc: test HksParseConfig with hap, CE and front-user
172  * @tc.type: FUNC
173  */
174 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest003, TestSize.Level0)
175 {
176     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest003");
177     g_hapName = const_cast<char *>("com.example.demo3");
178     g_accessTokenType = HKS_TOKEN_HAP;
179     struct HksParamSet *paramSet003 = nullptr;
180     (void)HksInitParamSet(&paramSet003);
181     uint32_t userId003 = 100;
182     struct HksParam params[] = {
183         {
184             .tag = HKS_TAG_PROCESS_NAME,
185             .blob = {
186                 .data = reinterpret_cast<uint8_t *>(&userId003),
187                 .size = sizeof(uint32_t)
188             }
189         }, {
190             .tag = HKS_TAG_USER_ID,
191             .uint32Param = userId003
192         }, {
193             .tag = HKS_TAG_ACCESS_TOKEN_ID,
194             .uint64Param = 0
195         }
196     };
197     (void)HksAddParams(paramSet003, params, HKS_ARRAY_SIZE(params));
198     (void)HksBuildParamSet(&paramSet003);
199     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet003),
200         .size = paramSet003->paramSetSize };
201     struct HksUpgradeFileTransferInfo info = { 0 };
202     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
203     EXPECT_EQ(false, info.needDe);
204     EXPECT_EQ(true, info.needFrontUser);
205     EXPECT_EQ(false, info.skipTransfer);
206     EXPECT_EQ(userId003, info.uid);
207     EXPECT_EQ(userId003, info.userId);
208 
209     HksFreeParamSet(&paramSet003);
210 }
211 
212 /**
213  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest004
214  * @tc.desc: test HksParseConfig with hap, CE and self-user
215  * @tc.type: FUNC
216  */
217 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest004, TestSize.Level0)
218 {
219     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest004");
220     g_hapName = const_cast<char *>("com.example.demo4");
221     g_accessTokenType = HKS_TOKEN_HAP;
222     struct HksParamSet *paramSet004 = nullptr;
223     (void)HksInitParamSet(&paramSet004);
224     uint32_t userId004 = 100;
225     struct HksParam params[] = {
226         {
227             .tag = HKS_TAG_PROCESS_NAME,
228             .blob = {
229                 .data = reinterpret_cast<uint8_t *>(&userId004),
230                 .size = sizeof(uint32_t)
231             }
232         }, {
233             .tag = HKS_TAG_USER_ID,
234             .uint32Param = userId004
235         }, {
236             .tag = HKS_TAG_ACCESS_TOKEN_ID,
237             .uint64Param = 0
238         }
239     };
240     (void)HksAddParams(paramSet004, params, HKS_ARRAY_SIZE(params));
241     (void)HksBuildParamSet(&paramSet004);
242     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet004),
243         .size = paramSet004->paramSetSize };
244     struct HksUpgradeFileTransferInfo info = { 0 };
245     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
246     EXPECT_EQ(false, info.needDe);
247     EXPECT_EQ(false, info.needFrontUser);
248     EXPECT_EQ(false, info.skipTransfer);
249     EXPECT_EQ(userId004, info.uid);
250     EXPECT_EQ(userId004, info.userId);
251 
252     HksFreeParamSet(&paramSet004);
253 }
254 
255 /**
256  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest005
257  * @tc.desc: test HksParseConfig with hap, skip upgrade
258  * @tc.type: FUNC
259  */
260 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest005, TestSize.Level0)
261 {
262     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest005");
263     g_hapName = const_cast<char *>("com.example.skip1");
264     g_accessTokenType = HKS_TOKEN_HAP;
265     struct HksParamSet *paramSet005 = nullptr;
266     (void)HksInitParamSet(&paramSet005);
267     uint32_t userId005 = 100;
268     struct HksParam params[] = {
269         {
270             .tag = HKS_TAG_PROCESS_NAME,
271             .blob = {
272                 .data = reinterpret_cast<uint8_t *>(&userId005),
273                 .size = sizeof(uint32_t)
274             }
275         }, {
276             .tag = HKS_TAG_USER_ID,
277             .uint32Param = userId005
278         }, {
279             .tag = HKS_TAG_ACCESS_TOKEN_ID,
280             .uint64Param = 0
281         }
282     };
283     (void)HksAddParams(paramSet005, params, HKS_ARRAY_SIZE(params));
284     (void)HksBuildParamSet(&paramSet005);
285     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet005),
286         .size = paramSet005->paramSetSize };
287     struct HksUpgradeFileTransferInfo info = { 0 };
288     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
289     EXPECT_EQ(true, info.skipTransfer);
290     HksFreeParamSet(&paramSet005);
291 }
292 
293 /**
294  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest006
295  * @tc.desc: test HksParseConfig with sa, ce and self-user
296  * @tc.type: FUNC
297  */
298 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest006, TestSize.Level0)
299 {
300     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest006");
301     g_accessTokenType = HKS_TOKEN_NATIVE;
302     struct HksParamSet *paramSet006 = nullptr;
303     (void)HksInitParamSet(&paramSet006);
304     uint32_t userId006 = 0;
305     uint32_t uid006 = 6;
306     struct HksParam params[] = {
307         {
308             .tag = HKS_TAG_PROCESS_NAME,
309             .blob = {
310                 .data = reinterpret_cast<uint8_t *>(&uid006),
311                 .size = sizeof(uint32_t)
312             }
313         }, {
314             .tag = HKS_TAG_USER_ID,
315             .uint32Param = userId006
316         }, {
317             .tag = HKS_TAG_ACCESS_TOKEN_ID,
318             .uint64Param = 0
319         }
320     };
321     (void)HksAddParams(paramSet006, params, HKS_ARRAY_SIZE(params));
322     (void)HksBuildParamSet(&paramSet006);
323     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet006),
324         .size = paramSet006->paramSetSize };
325     struct HksUpgradeFileTransferInfo info = { 0 };
326     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
327     EXPECT_EQ(false, info.needDe);
328     EXPECT_EQ(false, info.needFrontUser);
329     EXPECT_EQ(false, info.skipTransfer);
330     EXPECT_EQ(uid006, info.uid);
331     EXPECT_EQ(userId006, info.userId);
332 
333     HksFreeParamSet(&paramSet006);
334 }
335 
336 /**
337  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest007
338  * @tc.desc: test HksParseConfig with sa, ce and front-user
339  * @tc.type: FUNC
340  */
341 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest007, TestSize.Level0)
342 {
343     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest007");
344     g_accessTokenType = HKS_TOKEN_NATIVE;
345     struct HksParamSet *paramSet007 = nullptr;
346     (void)HksInitParamSet(&paramSet007);
347     uint32_t userId007 = 0;
348     uint32_t uid007 = 7;
349     struct HksParam params[] = {
350         {
351             .tag = HKS_TAG_PROCESS_NAME,
352             .blob = {
353                 .data = reinterpret_cast<uint8_t *>(&uid007),
354                 .size = sizeof(uint32_t)
355             }
356         }, {
357             .tag = HKS_TAG_USER_ID,
358             .uint32Param = userId007
359         }, {
360             .tag = HKS_TAG_ACCESS_TOKEN_ID,
361             .uint64Param = 0
362         }
363     };
364     (void)HksAddParams(paramSet007, params, HKS_ARRAY_SIZE(params));
365     (void)HksBuildParamSet(&paramSet007);
366     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet007),
367         .size = paramSet007->paramSetSize };
368     struct HksUpgradeFileTransferInfo info = { 0 };
369     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
370     EXPECT_EQ(false, info.needDe);
371     EXPECT_EQ(true, info.needFrontUser);
372     EXPECT_EQ(false, info.skipTransfer);
373     EXPECT_EQ(uid007, info.uid);
374     EXPECT_EQ(userId007, info.userId);
375 
376     HksFreeParamSet(&paramSet007);
377 }
378 
379 /**
380  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest008
381  * @tc.desc: test HksParseConfig with sa, de and self-user
382  * @tc.type: FUNC
383  */
384 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest008, TestSize.Level0)
385 {
386     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest008");
387     g_accessTokenType = HKS_TOKEN_NATIVE;
388     struct HksParamSet *paramSet008 = nullptr;
389     (void)HksInitParamSet(&paramSet008);
390     uint32_t userId008 = 0;
391     uint32_t uid008 = 8;
392     struct HksParam params[] = {
393         {
394             .tag = HKS_TAG_PROCESS_NAME,
395             .blob = {
396                 .data = reinterpret_cast<uint8_t *>(&uid008),
397                 .size = sizeof(uint32_t)
398             }
399         }, {
400             .tag = HKS_TAG_USER_ID,
401             .uint32Param = userId008
402         }, {
403             .tag = HKS_TAG_ACCESS_TOKEN_ID,
404             .uint64Param = 0
405         }
406     };
407     (void)HksAddParams(paramSet008, params, HKS_ARRAY_SIZE(params));
408     (void)HksBuildParamSet(&paramSet008);
409     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet008),
410         .size = paramSet008->paramSetSize };
411     struct HksUpgradeFileTransferInfo info = { 0 };
412     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
413     EXPECT_EQ(true, info.needDe);
414     EXPECT_EQ(false, info.needFrontUser);
415     EXPECT_EQ(false, info.skipTransfer);
416     EXPECT_EQ(uid008, info.uid);
417     EXPECT_EQ(userId008, info.userId);
418 
419     HksFreeParamSet(&paramSet008);
420 }
421 
422 /**
423  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest009
424  * @tc.desc: test HksParseConfig with sa, de and front-user
425  * @tc.type: FUNC
426  */
427 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest009, TestSize.Level0)
428 {
429     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest009");
430     g_accessTokenType = HKS_TOKEN_NATIVE;
431     struct HksParamSet *paramSet009 = nullptr;
432     (void)HksInitParamSet(&paramSet009);
433     uint32_t userId009 = 0;
434     uint32_t uid009 = 9;
435     struct HksParam params[] = {
436         {
437             .tag = HKS_TAG_PROCESS_NAME,
438             .blob = {
439                 .data = reinterpret_cast<uint8_t *>(&uid009),
440                 .size = sizeof(uint32_t)
441             }
442         }, {
443             .tag = HKS_TAG_USER_ID,
444             .uint32Param = userId009
445         }, {
446             .tag = HKS_TAG_ACCESS_TOKEN_ID,
447             .uint64Param = 0
448         }
449     };
450     (void)HksAddParams(paramSet009, params, HKS_ARRAY_SIZE(params));
451     (void)HksBuildParamSet(&paramSet009);
452     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet009),
453         .size = paramSet009->paramSetSize };
454     struct HksUpgradeFileTransferInfo info = { 0 };
455     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
456     EXPECT_EQ(true, info.needDe);
457     EXPECT_EQ(true, info.needFrontUser);
458     EXPECT_EQ(false, info.skipTransfer);
459     EXPECT_EQ(uid009, info.uid);
460     EXPECT_EQ(userId009, info.userId);
461 
462     HksFreeParamSet(&paramSet009);
463 }
464 
465 /**
466  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest010
467  * @tc.desc: test HksParseConfig with sa, skip upgrade
468  * @tc.type: FUNC
469  */
470 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest010, TestSize.Level0)
471 {
472     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest010");
473     g_accessTokenType = HKS_TOKEN_NATIVE;
474     struct HksParamSet *paramSet010 = nullptr;
475     (void)HksInitParamSet(&paramSet010);
476     uint32_t userId010 = 0;
477     uint32_t uid010 = 10;
478     struct HksParam params[] = {
479         {
480             .tag = HKS_TAG_PROCESS_NAME,
481             .blob = {
482                 .data = reinterpret_cast<uint8_t *>(&uid010),
483                 .size = sizeof(uint32_t)
484             }
485         }, {
486             .tag = HKS_TAG_USER_ID,
487             .uint32Param = userId010
488         }, {
489             .tag = HKS_TAG_ACCESS_TOKEN_ID,
490             .uint64Param = 0
491         }
492     };
493     (void)HksAddParams(paramSet010, params, HKS_ARRAY_SIZE(params));
494     (void)HksBuildParamSet(&paramSet010);
495     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet010),
496         .size = paramSet010->paramSetSize };
497     struct HksUpgradeFileTransferInfo info = { 0 };
498     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("", &fileContent, &info));
499     EXPECT_EQ(true, info.skipTransfer);
500 
501     HksFreeParamSet(&paramSet010);
502 }
503 
504 /**
505  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest011
506  * @tc.desc: test HksParseConfig with DistributedDataRdb prefix, de and self-user
507  * @tc.type: FUNC
508  */
509 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest011, TestSize.Level0)
510 {
511     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest011");
512     g_accessTokenType = HKS_TOKEN_NATIVE;
513     struct HksParamSet *paramSet011 = nullptr;
514     (void)HksInitParamSet(&paramSet011);
515     uint32_t userId011 = 0;
516     uint32_t uid011 = 11;
517     struct HksParam params[] = {
518         {
519             .tag = HKS_TAG_PROCESS_NAME,
520             .blob = {
521                 .data = reinterpret_cast<uint8_t *>(&uid011),
522                 .size = sizeof(uint32_t)
523             }
524         }, {
525             .tag = HKS_TAG_USER_ID,
526             .uint32Param = userId011
527         }, {
528             .tag = HKS_TAG_ACCESS_TOKEN_ID,
529             .uint64Param = 0
530         }
531     };
532     (void)HksAddParams(paramSet011, params, HKS_ARRAY_SIZE(params));
533     (void)HksBuildParamSet(&paramSet011);
534     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet011),
535         .size = paramSet011->paramSetSize };
536     struct HksUpgradeFileTransferInfo info = { 0 };
537     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("DistributedDataRdb_test", &fileContent, &info));
538     EXPECT_EQ(true, info.needDe);
539     EXPECT_EQ(false, info.needFrontUser);
540     EXPECT_EQ(false, info.skipTransfer);
541     EXPECT_EQ(uid011, info.uid);
542     EXPECT_EQ(userId011, info.userId);
543 
544     HksFreeParamSet(&paramSet011);
545 }
546 
547 /**
548  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest012
549  * @tc.desc: test HksParseConfig with distributeddb_client_root_key, de and self-user
550  * @tc.type: FUNC
551  */
552 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest012, TestSize.Level0)
553 {
554     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest012");
555     g_accessTokenType = HKS_TOKEN_NATIVE;
556     struct HksParamSet *paramSet012 = nullptr;
557     (void)HksInitParamSet(&paramSet012);
558     uint32_t userId012 = 0;
559     uint32_t uid012 = 11;
560     struct HksParam params[] = {
561         {
562             .tag = HKS_TAG_PROCESS_NAME,
563             .blob = {
564                 .data = reinterpret_cast<uint8_t *>(&uid012),
565                 .size = sizeof(uint32_t)
566             }
567         }, {
568             .tag = HKS_TAG_USER_ID,
569             .uint32Param = userId012
570         }, {
571             .tag = HKS_TAG_ACCESS_TOKEN_ID,
572             .uint64Param = 0
573         }
574     };
575     (void)HksAddParams(paramSet012, params, HKS_ARRAY_SIZE(params));
576     (void)HksBuildParamSet(&paramSet012);
577     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet012),
578         .size = paramSet012->paramSetSize };
579     struct HksUpgradeFileTransferInfo info = { 0 };
580     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("distributeddb_client_root_key", &fileContent, &info));
581     EXPECT_EQ(true, info.needDe);
582     EXPECT_EQ(false, info.needFrontUser);
583     EXPECT_EQ(false, info.skipTransfer);
584     EXPECT_EQ(uid012, info.uid);
585     EXPECT_EQ(userId012, info.userId);
586 
587     HksFreeParamSet(&paramSet012);
588 }
589 
590 /**
591  * @tc.name: HksServiceUpgradeConfigParserTest.HksServiceUpgradeConfigParserTest013
592  * @tc.desc: test HksParseConfig with distributeddb_client_root_key with ectra suffix, ce and self-user as default
593  * @tc.type: FUNC
594  */
595 HWTEST_F(HksServiceUpgradeConfigParserTest, HksServiceUpgradeConfigParserTest013, TestSize.Level0)
596 {
597     HKS_LOG_I("enter HksServiceUpgradeConfigParserTest013");
598     g_accessTokenType = HKS_TOKEN_NATIVE;
599     struct HksParamSet *paramSet013 = nullptr;
600     (void)HksInitParamSet(&paramSet013);
601     uint32_t userId013 = 0;
602     uint32_t uid013 = 11;
603     struct HksParam params[] = {
604         {
605             .tag = HKS_TAG_PROCESS_NAME,
606             .blob = {
607                 .data = reinterpret_cast<uint8_t *>(&uid013),
608                 .size = sizeof(uint32_t)
609             }
610         }, {
611             .tag = HKS_TAG_USER_ID,
612             .uint32Param = userId013
613         }, {
614             .tag = HKS_TAG_ACCESS_TOKEN_ID,
615             .uint64Param = 0
616         }
617     };
618     (void)HksAddParams(paramSet013, params, HKS_ARRAY_SIZE(params));
619     (void)HksBuildParamSet(&paramSet013);
620     struct HksBlob fileContent = { .data = reinterpret_cast<uint8_t *>(paramSet013),
621         .size = paramSet013->paramSetSize };
622     struct HksUpgradeFileTransferInfo info = { 0 };
623     EXPECT_EQ(HKS_SUCCESS, HksParseConfig("distributeddb_client_root_key_etc", &fileContent, &info));
624     EXPECT_EQ(false, info.needDe);
625     EXPECT_EQ(false, info.needFrontUser);
626     EXPECT_EQ(false, info.skipTransfer);
627     EXPECT_EQ(uid013, info.uid);
628     EXPECT_EQ(userId013, info.userId);
629 
630     HksFreeParamSet(&paramSet013);
631 }
632 }
633