• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "el5_filekey_manager_service_mock_unittest.h"
17 
18 #include "accesstoken_kit.h"
19 #include "el5_filekey_callback_stub.h"
20 #include "mock_ipc.h"
21 #include "token_setproc.h"
22 
23 using namespace testing::ext;
24 using namespace OHOS::Security::AccessToken;
25 namespace {
26 constexpr uint32_t SCREEN_ON_DELAY_TIME = 30;
27 } // namespace
28 
SetUpTestCase()29 void El5FilekeyManagerServiceMockTest::SetUpTestCase()
30 {
31 }
32 
TearDownTestCase()33 void El5FilekeyManagerServiceMockTest::TearDownTestCase()
34 {
35     sleep(SCREEN_ON_DELAY_TIME);
36 }
37 
SetUp()38 void El5FilekeyManagerServiceMockTest::SetUp()
39 {
40     el5FilekeyManagerService_ = DelayedSingleton<El5FilekeyManagerService>::GetInstance();
41     el5FilekeyManagerService_->Init();
42     el5FilekeyManagerService_->service_ = nullptr;
43 }
44 
TearDown()45 void El5FilekeyManagerServiceMockTest::TearDown()
46 {
47 }
48 
49 class TestEl5FilekeyCallback : public El5FilekeyCallbackStub {
50 public:
OnRegenerateAppKey(std::vector<AppKeyInfo> & infos)51     void OnRegenerateAppKey(std::vector<AppKeyInfo> &infos)
52     {
53         GTEST_LOG_(INFO) << "OnRegenerateAppKey.";
54     }
55 };
56 
57 class TestEl5FilekeyServiceExt : public El5FilekeyServiceExtInterface {
58 public:
AcquireAccess(DataLockType type,bool isApp)59     int32_t AcquireAccess(DataLockType type, bool isApp)
60     {
61         return EFM_SUCCESS;
62     }
63 
ReleaseAccess(DataLockType type,bool isApp)64     int32_t ReleaseAccess(DataLockType type, bool isApp)
65     {
66         return EFM_SUCCESS;
67     }
68 
GenerateAppKey(uint32_t uid,const std::string & bundleName,std::string & keyId)69     int32_t GenerateAppKey(uint32_t uid, const std::string& bundleName, std::string& keyId)
70     {
71         return EFM_SUCCESS;
72     }
73 
DeleteAppKey(const std::string & bundleName,int32_t userId)74     int32_t DeleteAppKey(const std::string& bundleName, int32_t userId)
75     {
76         return EFM_SUCCESS;
77     }
78 
GetUserAppKey(int32_t userId,bool getAllFlag,std::vector<std::pair<int32_t,std::string>> & keyInfos)79     int32_t GetUserAppKey(int32_t userId, bool getAllFlag, std::vector<std::pair<int32_t, std::string>> &keyInfos)
80     {
81         int32_t key = 111;
82         std::string info = "test";
83         keyInfos.emplace_back(std::make_pair(key, info));
84         return EFM_SUCCESS;
85     }
86 
ChangeUserAppkeysLoadInfo(int32_t userId,std::vector<std::pair<std::string,bool>> & loadInfos)87     int32_t ChangeUserAppkeysLoadInfo(int32_t userId, std::vector<std::pair<std::string, bool>> &loadInfos)
88     {
89         return EFM_SUCCESS;
90     }
91 
SetFilePathPolicy(int32_t userId)92     int32_t SetFilePathPolicy(int32_t userId)
93     {
94         return EFM_SUCCESS;
95     }
96 
RegisterCallback(const OHOS::sptr<El5FilekeyCallbackInterface> & callback)97     int32_t RegisterCallback(const OHOS::sptr<El5FilekeyCallbackInterface> &callback)
98     {
99         return EFM_SUCCESS;
100     }
101 
GenerateGroupIDKey(uint32_t uid,const std::string & groupID,std::string & keyId)102     int32_t GenerateGroupIDKey(uint32_t uid, const std::string &groupID, std::string &keyId)
103     {
104         return EFM_SUCCESS;
105     }
106 
DeleteGroupIDKey(uint32_t uid,const std::string & groupID)107     int32_t DeleteGroupIDKey(uint32_t uid, const std::string &groupID)
108     {
109         return EFM_SUCCESS;
110     }
111 
QueryAppKeyState(DataLockType type,bool isApp)112     int32_t QueryAppKeyState(DataLockType type, bool isApp)
113     {
114         return EFM_SUCCESS;
115     }
116 
HandleUserCommonEvent(const std::string & eventName,int32_t userId)117     int32_t HandleUserCommonEvent(const std::string &eventName, int32_t userId)
118     {
119         return EFM_SUCCESS;
120     }
121 
SetPolicyScreenLocked()122     int32_t SetPolicyScreenLocked()
123     {
124         return EFM_SUCCESS;
125     }
126 
DumpData(int fd,const std::vector<std::u16string> & args)127     int32_t DumpData(int fd, const std::vector<std::u16string>& args)
128     {
129         return EFM_SUCCESS;
130     }
131 
OnAddSystemAbility(int32_t systemAbilityId,const std::string & deviceId)132     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId)
133     {
134         GTEST_LOG_(INFO) << "OnAddSystemAbility.";
135     }
136 
UnInit()137     void UnInit()
138     {
139         GTEST_LOG_(INFO) << "UnInit.";
140     }
141 };
142 
143 /**
144  * @tc.name: AcquireAccess001
145  * @tc.desc: Acquire default type data access.
146  * @tc.type: FUNC
147  * @tc.require: issueIAD2MD
148  */
149 HWTEST_F(El5FilekeyManagerServiceMockTest, AcquireAccess001, TestSize.Level1)
150 {
151     el5FilekeyManagerService_->service_ = nullptr;
152 
153     MockIpc::SetCallingUid(20020025);
154     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
155     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
156 
157     ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DEFAULT_DATA), EFM_SUCCESS);
158 }
159 
160 /**
161  * @tc.name: AcquireAccess002
162  * @tc.desc: Acquire default type data access.
163  * @tc.type: FUNC
164  * @tc.require: issueIAD2MD
165  */
166 HWTEST_F(El5FilekeyManagerServiceMockTest, AcquireAccess002, TestSize.Level1)
167 {
168     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
169 
170     MockIpc::SetCallingUid(20020025);
171     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
172     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
173 
174     ASSERT_EQ(el5FilekeyManagerService_->AcquireAccess(DEFAULT_DATA), EFM_SUCCESS);
175 }
176 
177 /**
178  * @tc.name: ReleaseAccess001
179  * @tc.desc: Release default type data access.
180  * @tc.type: FUNC
181  * @tc.require: issueIAD2MD
182  */
183 HWTEST_F(El5FilekeyManagerServiceMockTest, ReleaseAccess001, TestSize.Level1)
184 {
185     el5FilekeyManagerService_->service_ = nullptr;
186 
187     MockIpc::SetCallingUid(20020025);
188     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
189     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
190 
191     ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DEFAULT_DATA), EFM_SUCCESS);
192 }
193 
194 /**
195  * @tc.name: ReleaseAccess002
196  * @tc.desc: Release default type data access.
197  * @tc.type: FUNC
198  * @tc.require: issueIAD2MD
199  */
200 HWTEST_F(El5FilekeyManagerServiceMockTest, ReleaseAccess002, TestSize.Level1)
201 {
202     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
203 
204     MockIpc::SetCallingUid(20020025);
205     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
206     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
207 
208     ASSERT_EQ(el5FilekeyManagerService_->ReleaseAccess(DEFAULT_DATA), EFM_SUCCESS);
209 }
210 
211 /**
212  * @tc.name: GenerateAppKey001
213  * @tc.desc: Generate app key by uid and bundle name.
214  * @tc.type: FUNC
215  * @tc.require: issueIAD2MD
216  */
217 HWTEST_F(El5FilekeyManagerServiceMockTest, GenerateAppKey001, TestSize.Level1)
218 {
219     el5FilekeyManagerService_->service_ = nullptr;
220 
221     int32_t uid = 12345;
222     std::string bundleName = "com.ohos.el5_test";
223     std::string keyId;
224 
225     MockIpc::SetCallingUid(3060);
226 
227     ASSERT_EQ(el5FilekeyManagerService_->GenerateAppKey(uid, bundleName, keyId), EFM_SUCCESS);
228 }
229 
230 /**
231  * @tc.name: GenerateAppKey002
232  * @tc.desc: Generate app key by uid and bundle name.
233  * @tc.type: FUNC
234  * @tc.require: issueIAD2MD
235  */
236 HWTEST_F(El5FilekeyManagerServiceMockTest, GenerateAppKey002, TestSize.Level1)
237 {
238     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
239 
240     int32_t uid = 12345;
241     std::string bundleName = "com.ohos.el5_test";
242     std::string keyId;
243 
244     MockIpc::SetCallingUid(3060);
245 
246     ASSERT_EQ(el5FilekeyManagerService_->GenerateAppKey(uid, bundleName, keyId), EFM_SUCCESS);
247 }
248 
249 /**
250  * @tc.name: DeleteAppKey001
251  * @tc.desc: Delete app key by bundle name and user id.
252  * @tc.type: FUNC
253  * @tc.require: issueIAD2MD
254  */
255 HWTEST_F(El5FilekeyManagerServiceMockTest, DeleteAppKey001, TestSize.Level1)
256 {
257     el5FilekeyManagerService_->service_ = nullptr;
258 
259     std::string bundleName = "";
260     int32_t userId = 100;
261 
262     MockIpc::SetCallingUid(3060);
263 
264     ASSERT_EQ(el5FilekeyManagerService_->DeleteAppKey(bundleName, userId), EFM_SUCCESS);
265 }
266 
267 /**
268  * @tc.name: DeleteAppKey002
269  * @tc.desc: Delete app key by bundle name and user id.
270  * @tc.type: FUNC
271  * @tc.require: issueIAD2MD
272  */
273 HWTEST_F(El5FilekeyManagerServiceMockTest, DeleteAppKey002, TestSize.Level1)
274 {
275     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
276 
277     std::string bundleName = "";
278     int32_t userId = 100;
279 
280     MockIpc::SetCallingUid(3060);
281 
282     ASSERT_EQ(el5FilekeyManagerService_->DeleteAppKey(bundleName, userId), EFM_SUCCESS);
283 }
284 
285 /**
286  * @tc.name: GetUserAppKey001
287  * @tc.desc: Find key infos of the specified user id.
288  * @tc.type: FUNC
289  * @tc.require: issueIAD2MD
290  */
291 HWTEST_F(El5FilekeyManagerServiceMockTest, GetUserAppKey001, TestSize.Level1)
292 {
293     el5FilekeyManagerService_->service_ = nullptr;
294 
295     int32_t userId = 100;
296     std::vector<std::pair<int32_t, std::string>> keyInfos;
297 
298     AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon");
299     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
300 
301     ASSERT_EQ(el5FilekeyManagerService_->GetUserAppKey(userId, false, keyInfos), EFM_SUCCESS);
302 }
303 
304 /**
305  * @tc.name: GetUserAppKey002
306  * @tc.desc: Find key infos of the specified user id.
307  * @tc.type: FUNC
308  * @tc.require: issueIAD2MD
309  */
310 HWTEST_F(El5FilekeyManagerServiceMockTest, GetUserAppKey002, TestSize.Level1)
311 {
312     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
313 
314     int32_t userId = 100;
315     std::vector<std::pair<int32_t, std::string>> keyInfos;
316 
317     AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon");
318     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
319 
320     ASSERT_EQ(el5FilekeyManagerService_->GetUserAppKey(userId, false, keyInfos), EFM_SUCCESS);
321 }
322 
323 /**
324  * @tc.name: GetUserAppKey003
325  * @tc.desc: Find key infos of the specified user id.
326  * @tc.type: FUNC
327  * @tc.require: issueIAD2MD
328  */
329 HWTEST_F(El5FilekeyManagerServiceMockTest, GetUserAppKey003, TestSize.Level1)
330 {
331     OHOS::MessageParcel data;
332     OHOS::MessageParcel reply;
333     OHOS::MessageOption option(OHOS::MessageOption::TF_SYNC);
334 
335     ASSERT_EQ(true, data.WriteInterfaceToken(El5FilekeyManagerInterface::GetDescriptor()));
336 
337     data.WriteInt32(100);
338     data.WriteBool(false);
339 
340     ASSERT_EQ(el5FilekeyManagerService_->OnRemoteRequest(
341         static_cast<uint32_t>(EFMInterfaceCode::GET_USER_APP_KEY), data, reply, option), OHOS::NO_ERROR);
342 }
343 
344 /**
345  * @tc.name: ChangeUserAppkeysLoadInfo001
346  * @tc.desc: Change key infos of the specified user id.
347  * @tc.type: FUNC
348  * @tc.require: issueIAD2MD
349  */
350 HWTEST_F(El5FilekeyManagerServiceMockTest, ChangeUserAppkeysLoadInfo001, TestSize.Level1)
351 {
352     el5FilekeyManagerService_->service_ = nullptr;
353 
354     int32_t userId = 100;
355     std::vector<std::pair<std::string, bool>> loadInfos;
356     loadInfos.emplace_back(std::make_pair("", true));
357 
358     AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon");
359     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
360 
361     ASSERT_EQ(el5FilekeyManagerService_->ChangeUserAppkeysLoadInfo(userId, loadInfos), EFM_SUCCESS);
362 }
363 
364 /**
365  * @tc.name: ChangeUserAppkeysLoadInfo002
366  * @tc.desc: Change key infos of the specified user id.
367  * @tc.type: FUNC
368  * @tc.require: issueIAD2MD
369  */
370 HWTEST_F(El5FilekeyManagerServiceMockTest, ChangeUserAppkeysLoadInfo002, TestSize.Level1)
371 {
372     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
373 
374     int32_t userId = 100;
375     std::vector<std::pair<std::string, bool>> loadInfos;
376     loadInfos.emplace_back(std::make_pair("", true));
377 
378     AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("storage_daemon");
379     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
380 
381     ASSERT_EQ(el5FilekeyManagerService_->ChangeUserAppkeysLoadInfo(userId, loadInfos), EFM_SUCCESS);
382 }
383 
384 /**
385  * @tc.name: SetFilePathPolicy001
386  * @tc.desc: Set path policy.
387  * @tc.type: FUNC
388  * @tc.require: issueIAD2MD
389  */
390 HWTEST_F(El5FilekeyManagerServiceMockTest, SetFilePathPolicy001, TestSize.Level1)
391 {
392     el5FilekeyManagerService_->service_ = nullptr;
393 
394     MockIpc::SetCallingUid(20020025);
395     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
396     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
397 
398     ASSERT_EQ(el5FilekeyManagerService_->SetFilePathPolicy(), EFM_SUCCESS);
399 }
400 
401 /**
402  * @tc.name: SetFilePathPolicy002
403  * @tc.desc: Set path policy.
404  * @tc.type: FUNC
405  * @tc.require: issueIAD2MD
406  */
407 HWTEST_F(El5FilekeyManagerServiceMockTest, SetFilePathPolicy002, TestSize.Level1)
408 {
409     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
410 
411     MockIpc::SetCallingUid(20020025);
412     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
413     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
414 
415     ASSERT_EQ(el5FilekeyManagerService_->SetFilePathPolicy(), EFM_SUCCESS);
416 }
417 
418 /**
419  * @tc.name: RegisterCallback001
420  * @tc.desc: Register app key generation callback.
421  * @tc.type: FUNC
422  * @tc.require: issueIAD2MD
423  */
424 HWTEST_F(El5FilekeyManagerServiceMockTest, RegisterCallback001, TestSize.Level1)
425 {
426     el5FilekeyManagerService_->service_ = nullptr;
427 
428     AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("foundation");
429     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
430 
431     ASSERT_EQ(el5FilekeyManagerService_->RegisterCallback((new TestEl5FilekeyCallback())), EFM_SUCCESS);
432 }
433 
434 /**
435  * @tc.name: RegisterCallback002
436  * @tc.desc: Register app key generation callback.
437  * @tc.type: FUNC
438  * @tc.require: issueIAD2MD
439  */
440 HWTEST_F(El5FilekeyManagerServiceMockTest, RegisterCallback002, TestSize.Level1)
441 {
442     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
443 
444     AccessTokenID tokenId = AccessTokenKit::GetNativeTokenId("foundation");
445     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
446 
447     ASSERT_EQ(el5FilekeyManagerService_->RegisterCallback((new TestEl5FilekeyCallback())), EFM_SUCCESS);
448 }
449 
450 /**
451  * @tc.name: GenerateGroupIDKey001
452  * @tc.desc: Generate data group key by user id and group id.
453  * @tc.type: FUNC
454  * @tc.require: issueIAD2MD
455  */
456 HWTEST_F(El5FilekeyManagerServiceMockTest, GenerateGroupIDKey001, TestSize.Level1)
457 {
458     el5FilekeyManagerService_->service_ = nullptr;
459 
460     uint32_t uid = 100;
461     std::string groupID = "abcdefghijklmn";
462     std::string keyId;
463 
464     MockIpc::SetCallingUid(3060);
465 
466     ASSERT_EQ(el5FilekeyManagerService_->GenerateGroupIDKey(uid, groupID, keyId), EFM_SUCCESS);
467 }
468 
469 /**
470  * @tc.name: GenerateGroupIDKey002
471  * @tc.desc: Generate data group key by user id and group id.
472  * @tc.type: FUNC
473  * @tc.require: issueIAD2MD
474  */
475 HWTEST_F(El5FilekeyManagerServiceMockTest, GenerateGroupIDKey002, TestSize.Level1)
476 {
477     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
478 
479     uint32_t uid = 100;
480     std::string groupID = "abcdefghijklmn";
481     std::string keyId;
482 
483     MockIpc::SetCallingUid(3060);
484 
485     ASSERT_EQ(el5FilekeyManagerService_->GenerateGroupIDKey(uid, groupID, keyId), EFM_SUCCESS);
486 }
487 
488 /**
489  * @tc.name: DeleteGroupIDKey001
490  * @tc.desc: Delete data group key by user id and group id.
491  * @tc.type: FUNC
492  * @tc.require: issueIAD2MD
493  */
494 HWTEST_F(El5FilekeyManagerServiceMockTest, DeleteGroupIDKey001, TestSize.Level1)
495 {
496     el5FilekeyManagerService_->service_ = nullptr;
497 
498     uint32_t uid = 100;
499     std::string groupID = "";
500 
501     MockIpc::SetCallingUid(3060);
502 
503     ASSERT_EQ(el5FilekeyManagerService_->DeleteGroupIDKey(uid, groupID), EFM_SUCCESS);
504 }
505 
506 /**
507  * @tc.name: DeleteGroupIDKey002
508  * @tc.desc: Delete data group key by user id and group id.
509  * @tc.type: FUNC
510  * @tc.require: issueIAD2MD
511  */
512 HWTEST_F(El5FilekeyManagerServiceMockTest, DeleteGroupIDKey002, TestSize.Level1)
513 {
514     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
515 
516     uint32_t uid = 100;
517     std::string groupID = "";
518 
519     MockIpc::SetCallingUid(3060);
520 
521     ASSERT_EQ(el5FilekeyManagerService_->DeleteGroupIDKey(uid, groupID), EFM_SUCCESS);
522 }
523 
524 /**
525  * @tc.name: QueryAppKeyState001
526  * @tc.desc: Query default type app key.
527  * @tc.type: FUNC
528  * @tc.require: issueIAD2MD
529  */
530 HWTEST_F(El5FilekeyManagerServiceMockTest, QueryAppKeyState001, TestSize.Level1)
531 {
532     el5FilekeyManagerService_->service_ = nullptr;
533 
534     MockIpc::SetCallingUid(20020025);
535     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
536     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
537 
538     ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DEFAULT_DATA), EFM_SUCCESS);
539 }
540 
541 /**
542  * @tc.name: QueryAppKeyState002
543  * @tc.desc: Query default type app key.
544  * @tc.type: FUNC
545  * @tc.require: issueIAD2MD
546  */
547 HWTEST_F(El5FilekeyManagerServiceMockTest, QueryAppKeyState002, TestSize.Level1)
548 {
549     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
550 
551     MockIpc::SetCallingUid(20020025);
552     AccessTokenID tokenId = AccessTokenKit::GetHapTokenID(100, "com.ohos.medialibrary.medialibrarydata", 0);
553     MockIpc::SetCallingTokenID(static_cast<uint32_t>(tokenId));
554 
555     ASSERT_EQ(el5FilekeyManagerService_->QueryAppKeyState(DEFAULT_DATA), EFM_SUCCESS);
556 }
557 
558 /**
559  * @tc.name: SetPolicyScreenLocked001
560  * @tc.desc: SetPolicyScreenLocked
561  * @tc.type: FUNC
562  * @tc.require: issueIAD2MD
563  */
564 HWTEST_F(El5FilekeyManagerServiceMockTest, SetPolicyScreenLocked001, TestSize.Level1)
565 {
566     el5FilekeyManagerService_->service_ = nullptr;
567 
568     ASSERT_EQ(el5FilekeyManagerService_->SetPolicyScreenLocked(), EFM_SUCCESS);
569 }
570 
571 /**
572  * @tc.name: SetPolicyScreenLocked002
573  * @tc.desc: SetPolicyScreenLocked
574  * @tc.type: FUNC
575  * @tc.require: issueIAD2MD
576  */
577 HWTEST_F(El5FilekeyManagerServiceMockTest, SetPolicyScreenLocked002, TestSize.Level1)
578 {
579     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
580 
581     ASSERT_EQ(el5FilekeyManagerService_->SetPolicyScreenLocked(), EFM_SUCCESS);
582 }
583 
584 /**
585  * @tc.name: Dump001
586  * @tc.desc: Dump fd > 0
587  * @tc.type: FUNC
588  * @tc.require: issueIAD2MD
589  */
590 HWTEST_F(El5FilekeyManagerServiceMockTest, Dump001, TestSize.Level1)
591 {
592     el5FilekeyManagerService_->service_ = nullptr;
593 
594     int fd = 1;
595     std::vector<std::u16string> args = {};
596     ASSERT_EQ(el5FilekeyManagerService_->Dump(fd, args), EFM_SUCCESS);
597 }
598 
599 /**
600  * @tc.name: Dump002
601  * @tc.desc: Dump fd > 0
602  * @tc.type: FUNC
603  * @tc.require: issueIAD2MD
604  */
605 HWTEST_F(El5FilekeyManagerServiceMockTest, Dump002, TestSize.Level1)
606 {
607     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
608 
609     int fd = 1;
610     std::vector<std::u16string> args = {};
611     ASSERT_EQ(el5FilekeyManagerService_->Dump(fd, args), EFM_SUCCESS);
612 }
613 
614 /**
615  * @tc.name: HandleUserCommonEvent001
616  * @tc.desc: HandleUserCommonEvent func test, service_ == null.
617  * @tc.type: FUNC
618  * @tc.require: issueIAD2MD
619  */
620 HWTEST_F(El5FilekeyManagerServiceMockTest, HandleUserCommonEvent001, TestSize.Level1)
621 {
622     el5FilekeyManagerService_->service_ = nullptr;
623     std::string eventName = "abc";
624     int userId = 1;
625     ASSERT_EQ(el5FilekeyManagerService_->HandleUserCommonEvent(eventName, userId), EFM_SUCCESS);
626 }
627 
628 /**
629  * @tc.name: HandleUserCommonEvent002
630  * @tc.desc: HandleUserCommonEvent func test, service_ != null.
631  * @tc.type: FUNC
632  * @tc.require: issueIAD2MD
633  */
634 HWTEST_F(El5FilekeyManagerServiceMockTest, HandleUserCommonEvent002, TestSize.Level1)
635 {
636     el5FilekeyManagerService_->service_ = new TestEl5FilekeyServiceExt();
637     std::string eventName = "abc";
638     int userId = 1;
639     ASSERT_EQ(el5FilekeyManagerService_->HandleUserCommonEvent(eventName, userId), EFM_SUCCESS);
640 }
641 
642 /**
643  * @tc.name: OnRemoteRequest001
644  * @tc.desc: El5FilekeyCallbackStub function test OnRemoteRequest001.
645  * @tc.type: FUNC
646  * @tc.require: Issue Number
647  */
648 HWTEST_F(El5FilekeyManagerServiceMockTest, OnRemoteRequest001, TestSize.Level1)
649 {
650     TestEl5FilekeyCallback testEl5FilekeyCallback;
651     OHOS::MessageParcel data;
652     OHOS::MessageParcel reply;
653     OHOS::MessageOption option;
654     uint32_t code = static_cast<uint32_t>(El5FilekeyCallbackInterface::Code::ON_REGENERATE_APP_KEY);
655 
656     ASSERT_EQ(data.WriteInterfaceToken(El5FilekeyCallbackInterface::GetDescriptor()), true);
657     data.WriteUint32(1); // infosSize
658     data.WriteInt32(1);  // AppKeyInfo size
659     data.WriteUint32(static_cast<uint32_t>(AppKeyType::APP));
660     data.WriteUint32(1000);
661     std::string bundleName = "ohos.permission.test";
662     data.WriteString(bundleName);
663     data.WriteInt32(100);
664     data.WriteString("testGroupId");
665     ASSERT_EQ(testEl5FilekeyCallback.OnRemoteRequest(code, data, reply, option), OHOS::NO_ERROR);
666 }
667 
668 /**
669  * @tc.name: Marshalling001
670  * @tc.desc: AppKeyInfo function test Marshalling.
671  * @tc.type: FUNC
672  * @tc.require: Issue Number
673  */
674 HWTEST_F(El5FilekeyManagerServiceMockTest, Marshalling001, TestSize.Level1)
675 {
676     AppKeyInfo appKeyInfo;
677     appKeyInfo.uid = 1000;
678     appKeyInfo.bundleName = "test";
679     appKeyInfo.userId = 200;
680     appKeyInfo.groupID = "testGroupId";
681     OHOS::Parcel parcel;
682     ASSERT_EQ(appKeyInfo.Marshalling(parcel), true);
683 }
684 
685 /**
686  * @tc.name: Unmarshalling001
687  * @tc.desc: AppKeyInfo function test Marshalling.
688  * @tc.type: FUNC
689  * @tc.require: Issue Number
690  */
691 HWTEST_F(El5FilekeyManagerServiceMockTest, Unmarshalling001, TestSize.Level1)
692 {
693     AppKeyInfo appKeyInfo;
694     OHOS::Parcel parcel;
695     parcel.WriteUint32(static_cast<uint32_t>(AppKeyType::GROUPID));
696     parcel.WriteUint32(1000);
697     parcel.WriteString("ohos.permission.test");
698     parcel.WriteInt32(100);
699     parcel.WriteString("testGroupId");
700     auto info = appKeyInfo.Unmarshalling(parcel);
701     ASSERT_EQ(info != nullptr, true);
702     ASSERT_EQ(info->bundleName, "ohos.permission.test");
703 }
704