1 /*
2 * Copyright (c) 2021-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 "distributed_sched_permission_test.h"
17
18 #include "accesstoken_kit.h"
19 #include "adapter/dnetwork_adapter.h"
20 #include "bundle/bundle_manager_internal.h"
21 #include "distributed_sched_interface.h"
22 #define private public
23 #include "distributed_sched_permission.h"
24 #undef private
25 #include "distributed_sched_test_util.h"
26 #include "distributed_sched_utils.h"
27 #include "dms_constant.h"
28 #include "dtbschedmgr_device_info_storage.h"
29 #include "dtbschedmgr_log.h"
30 #include "nativetoken_kit.h"
31 #include "test_log.h"
32 #include "token_setproc.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36 using namespace OHOS::AppExecFwk;
37 using namespace OHOS::DistributedHardware;
38 using namespace OHOS::Security::AccessToken;
39
40 namespace OHOS {
41 namespace DistributedSchedule {
42 using namespace Constants;
43 namespace {
44 constexpr uint32_t ACCESS_TOKEN = 100000000;
45 constexpr uint32_t INVALID_ACCESS_TOKEN = 0;
46 const string BUNDLE_NAME = "com.ohos.mms";
47 const string INVALID_BUNDLE_NAME = "";
48 const string PACKAGE_NAME = "com.ohos.mms";
49 const string ABILITY_NAME = "com.ohos.mms.MainAbility";
50 const string INVALID_ABILITY_NAME = "";
51 const string GROUP_ID = "TEST_GROUP_ID";
52 const string INVALID_GROUP_ID = "";
53 const string DEVICE_ID = "255.255.255.255";
54 const string INVALID_DEVICE_ID = "";
55 const string PERMISSION_NAME = "ohos.permission.DISTRIBUTED_DATASYNC";
56 const string INVALID_PERMISSION_NAME = "ohos.permission.TEST";
57 const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
58 const string DMS_API_VERSION = "dmsApiVersion";
59 const string DMS_MISSION_ID = "dmsMissionId";
60 const string DMS_VERSION_ID = "dmsVersion";
61 const int API_VERSION = 9;
62 const int FA_MODULE_ALLOW_MIN_API_VERSION = 8;
63
64 const string MOCK_FIELD_GROUP_NAME = "MockName";
65 const string MOCK_FIELD_GROUP_ID = "MockId";
66 const string MOCK_FIELD_GROUP_OWNER = "MockOwner";
67 const int32_t MOCK_FIELD_GROUP_TYPE = 0;
68 const int32_t MOCK_FIELD_GROUP_VISIBILITY = 0;
69 const string FIELD_GROUP_NAME = "groupName";
70 const string FIELD_GROUP_ID = "groupId";
71 const string FIELD_GROUP_OWNER = "groupOwner";
72 const string FIELD_GROUP_TYPE = "groupType";
73 const string FIELD_GROUP_VISIBILITY = "groupVisibility";
74 const char* FOUNDATION_PROCESS_NAME = "foundation";
75
NativeTokenGet()76 void NativeTokenGet()
77 {
78 uint32_t tokenId = AccessTokenKit::GetNativeTokenId("token_sync_service");
79 ASSERT_NE(tokenId, 0);
80 SetSelfTokenID(tokenId);
81 }
82 }
83
SetUpTestCase()84 void DistributedSchedPermissionTest::SetUpTestCase()
85 {
86 DTEST_LOG << "DistributedSchedPermissionTest::SetUpTestCase" << std::endl;
87 const std::string pkgName = "DBinderBus_PermissionTest" + std::to_string(getprocpid());
88 std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
89 DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
90 }
91
TearDownTestCase()92 void DistributedSchedPermissionTest::TearDownTestCase()
93 {
94 DTEST_LOG << "DistributedSchedPermissionTest::TearDownTestCase" << std::endl;
95 }
96
TearDown()97 void DistributedSchedPermissionTest::TearDown()
98 {
99 DTEST_LOG << "DistributedSchedPermissionTest::TearDown" << std::endl;
100 }
101
SetUp()102 void DistributedSchedPermissionTest::SetUp()
103 {
104 DTEST_LOG << "DistributedSchedPermissionTest::SetUp" << std::endl;
105 DistributedSchedUtil::MockPermission();
106 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId_);
107
108 NativeTokenGet();
109 }
110
OnRemoteDied()111 void DistributedSchedPermissionTest::DeviceInitCallBack::OnRemoteDied()
112 {
113 }
114
115 /**
116 * @tc.name: CheckSendResultPermission_001
117 * @tc.desc: input invalid params
118 * @tc.type: FUNC
119 * @tc.require: issueI5T6GJ
120 */
121 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_001, TestSize.Level3)
122 {
123 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_001 begin" << std::endl;
124 AAFwk::Want want;
125 CallerInfo callerInfo;
126 IDistributedSched::AccountInfo accountInfo;
127 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
128 AppExecFwk::AbilityInfo targetAbility;
129 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
130 callerInfo, accountInfo, targetAbility);
131 EXPECT_NE(ret, ERR_OK);
132 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_001 end ret:" << ret << std::endl;
133 }
134
135 /**
136 * @tc.name: CheckSendResultPermission_002
137 * @tc.desc: input invalid params
138 * @tc.type: FUNC
139 * @tc.require: issueI5T6GJ
140 */
141 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_002, TestSize.Level3)
142 {
143 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission begin" << std::endl;
144 AAFwk::Want want;
145 CallerInfo callerInfo;
146 IDistributedSched::AccountInfo accountInfo;
147 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
148 AppExecFwk::AbilityInfo targetAbility;
149 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
150 callerInfo, accountInfo, targetAbility);
151 EXPECT_NE(ret, ERR_OK);
152 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_002 end ret:" << ret << std::endl;
153 }
154
155 /**
156 * @tc.name: CheckSendResultPermission_005
157 * @tc.desc: call CheckDPermission with illegal parameter
158 * @tc.type: FUNC
159 */
160 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_005, TestSize.Level3)
161 {
162 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_005 begin" << std::endl;
163 AAFwk::Want want;
164 CallerInfo callerInfo;
165 callerInfo.accessToken = ACCESS_TOKEN;
166 IDistributedSched::AccountInfo accountInfo;
167 std::string localDeviceId = DEVICE_ID;
168 AppExecFwk::AbilityInfo targetAbility;
169 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
170 callerInfo, accountInfo, targetAbility);
171 EXPECT_NE(ret, ERR_OK);
172 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_005 end result:" << ret << std::endl;
173 }
174
175 /**
176 * @tc.name: CheckSendResultPermission_006
177 * @tc.desc: call CheckDPermission with different account type
178 * @tc.type: FUNC
179 */
180 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_006, TestSize.Level3)
181 {
182 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_006 begin" << std::endl;
183 AAFwk::Want want;
184 CallerInfo callerInfo;
185 callerInfo.accessToken = ACCESS_TOKEN;
186 IDistributedSched::AccountInfo accountInfo;
187 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
188 string localDeviceId = DEVICE_ID;
189 AppExecFwk::AbilityInfo targetAbility;
190 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
191 callerInfo, accountInfo, targetAbility);
192 EXPECT_NE(ret, ERR_OK);
193 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_006 end result:" << ret << std::endl;
194 }
195
196 /**
197 * @tc.name: CheckSendResultPermission_007
198 * @tc.desc: call CheckDPermission with illegal ability info
199 * @tc.type: FUNC
200 */
201 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_007, TestSize.Level3)
202 {
203 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_007 begin" << std::endl;
204 AAFwk::Want want;
205 CallerInfo callerInfo;
206 callerInfo.accessToken = ACCESS_TOKEN;
207 IDistributedSched::AccountInfo accountInfo;
208 string localDeviceId = DEVICE_ID;
209 AppExecFwk::AbilityInfo targetAbility;
210 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
211 callerInfo, accountInfo, targetAbility);
212 EXPECT_NE(ret, ERR_OK);
213 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_007 end result:" << ret << std::endl;
214 }
215
216 /**
217 * @tc.name: CheckSendResultPermission_008
218 * @tc.desc: call CheckDPermission with same account type
219 * @tc.type: FUNC
220 */
221 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_008, TestSize.Level3)
222 {
223 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_008 begin" << std::endl;
224 AAFwk::Want want;
225 CallerInfo callerInfo;
226 callerInfo.accessToken = ACCESS_TOKEN;
227 IDistributedSched::AccountInfo accountInfo;
228 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
229 string localDeviceId = DEVICE_ID;
230 AppExecFwk::AbilityInfo targetAbility;
231 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
232 callerInfo, accountInfo, targetAbility);
233 EXPECT_NE(ret, ERR_OK);
234 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_008 end result:" << ret << std::endl;
235 }
236
237 /**
238 * @tc.name: CheckSendResultPermission_009
239 * @tc.desc: call CheckDPermission with illegal account info
240 * @tc.type: FUNC
241 */
242 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_009, TestSize.Level3)
243 {
244 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_009 begin" << std::endl;
245 AAFwk::Want want;
246 CallerInfo callerInfo;
247 callerInfo.accessToken = ACCESS_TOKEN;
248 IDistributedSched::AccountInfo accountInfo;
249 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
250 std::string groupId = GROUP_ID;
251 accountInfo.groupIdList.push_back(groupId);
252 string localDeviceId = DEVICE_ID;
253 AppExecFwk::AbilityInfo targetAbility;
254 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
255 callerInfo, accountInfo, targetAbility);
256 EXPECT_NE(ret, ERR_OK);
257 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_009 end result:" << ret << std::endl;
258 }
259
260 /**
261 * @tc.name: CheckSendResultPermission_010
262 * @tc.desc: call CheckDPermission with illegal account info
263 * @tc.type: FUNC
264 */
265 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_010, TestSize.Level3)
266 {
267 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_010 begin" << std::endl;
268 AAFwk::Want want;
269 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
270 want.SetElement(element);
271 CallerInfo callerInfo;
272 callerInfo.accessToken = ACCESS_TOKEN;
273 IDistributedSched::AccountInfo accountInfo;
274 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
275 std::string groupId = GROUP_ID;
276 accountInfo.groupIdList.push_back(groupId);
277 string localDeviceId = DEVICE_ID;
278 AppExecFwk::AbilityInfo targetAbility;
279 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
280 callerInfo, accountInfo, targetAbility);
281 EXPECT_NE(ret, ERR_OK);
282 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_010 end result:" << ret << std::endl;
283 }
284
285 /**
286 * @tc.name: CheckStartPermission_001
287 * @tc.desc: input invalid params
288 * @tc.type: FUNC
289 * @tc.require: issueI5T6GJ
290 */
291 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_001, TestSize.Level3)
292 {
293 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_001 begin" << std::endl;
294 AAFwk::Want want;
295 CallerInfo callerInfo;
296 IDistributedSched::AccountInfo accountInfo;
297 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
298 AppExecFwk::AbilityInfo targetAbility;
299 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
300 callerInfo, accountInfo, targetAbility);
301 EXPECT_NE(ret, ERR_OK);
302 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_001 end ret:" << ret << std::endl;
303 }
304
305 /**
306 * @tc.name: CheckStartPermission_002
307 * @tc.desc: input invalid params
308 * @tc.type: FUNC
309 * @tc.require: issueI5T6GJ
310 */
311 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_002, TestSize.Level3)
312 {
313 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_002 begin" << std::endl;
314 AAFwk::Want want;
315 CallerInfo callerInfo;
316 IDistributedSched::AccountInfo accountInfo;
317 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
318 AppExecFwk::AbilityInfo targetAbility;
319 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
320 callerInfo, accountInfo, targetAbility);
321 EXPECT_NE(ret, ERR_OK);
322 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_002 end ret:" << ret << std::endl;
323 }
324
325 /**
326 * @tc.name: CheckStartPermission_003
327 * @tc.desc: input invalid params
328 * @tc.type: FUNC
329 * @tc.require: issueI5T6GJ
330 */
331 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_003, TestSize.Level3)
332 {
333 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_003 begin" << std::endl;
334 AAFwk::Want want;
335 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
336 CallerInfo callerInfo;
337 IDistributedSched::AccountInfo accountInfo;
338 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
339 AppExecFwk::AbilityInfo targetAbility;
340 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
341 callerInfo, accountInfo, targetAbility);
342 EXPECT_NE(ret, ERR_OK);
343 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_003 end ret:" << ret << std::endl;
344 }
345
346 /**
347 * @tc.name: CheckStartPermission_005
348 * @tc.desc: input invalid params
349 * @tc.type: FUNC
350 * @tc.require: issueI5T6GJ
351 */
352 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_005, TestSize.Level3)
353 {
354 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_005 begin" << std::endl;
355 AAFwk::Want want;
356 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
357 CallerInfo callerInfo;
358 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
359 IDistributedSched::AccountInfo accountInfo;
360 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
361 AppExecFwk::AbilityInfo targetAbility;
362 targetAbility.permissions.push_back(INVALID_PERMISSION_NAME);
363 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
364 callerInfo, accountInfo, targetAbility);
365 EXPECT_NE(ret, ERR_OK);
366 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_005 end ret:" << ret << std::endl;
367 }
368
369 /**
370 * @tc.name: GetTargetAbility_001
371 * @tc.desc: input invalid params
372 * @tc.type: FUNC
373 * @tc.require: issueI5T6GJ
374 */
375 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_001, TestSize.Level3)
376 {
377 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_001 begin" << std::endl;
378 AAFwk::Want want;
379 AppExecFwk::AbilityInfo targetAbility;
380 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, false);
381 EXPECT_FALSE(ret);
382 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_001 end ret:" << ret << std::endl;
383 }
384
385 /**
386 * @tc.name: CheckGetCallerPermission_001
387 * @tc.desc: input invalid params
388 * @tc.type: FUNC
389 * @tc.require: issueI5T6GJ
390 */
391 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_001, TestSize.Level3)
392 {
393 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_001 begin" << std::endl;
394 AAFwk::Want want;
395 CallerInfo callerInfo;
396 IDistributedSched::AccountInfo accountInfo;
397 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
398 AppExecFwk::AbilityInfo targetAbility;
399 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
400 targetAbility);
401 EXPECT_EQ(ret, DMS_ACCOUNT_ACCESS_PERMISSION_DENIED);
402 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_001 end ret:" << ret << std::endl;
403 }
404
405 /**
406 * @tc.name: CheckStartControlPermission_001
407 * @tc.desc: input invalid params
408 * @tc.type: FUNC
409 * @tc.require: issueI5T6GJ
410 */
411 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_001, TestSize.Level3)
412 {
413 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_001 begin" << std::endl;
414 AppExecFwk::AbilityInfo targetAbility;
415 CallerInfo callerInfo;
416 AAFwk::Want want;
417 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
418 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
419 EXPECT_FALSE(ret);
420 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_001 end ret:" << ret << std::endl;
421 }
422
423 /**
424 * @tc.name: CheckStartControlPermission_002
425 * @tc.desc: input invalid params
426 * @tc.type: FUNC
427 * @tc.require: issueI5T6GJ
428 */
429 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_002, TestSize.Level3)
430 {
431 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_002 begin" << std::endl;
432 AppExecFwk::AbilityInfo targetAbility;
433 targetAbility.bundleName = BUNDLE_NAME;
434 CallerInfo callerInfo;
435 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
436 EXPECT_EQ(result, true);
437 AAFwk::Want want;
438 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
439 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
440 EXPECT_FALSE(ret);
441 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_002 end ret:" << ret << std::endl;
442 }
443
444 /**
445 * @tc.name: CheckStartControlPermission_003
446 * @tc.desc: input invalid params
447 * @tc.type: FUNC
448 * @tc.require: issueI5T6GJ
449 */
450 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_003, TestSize.Level3)
451 {
452 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_003 begin" << std::endl;
453 AppExecFwk::AbilityInfo targetAbility;
454 CallerInfo callerInfo;
455 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
456 EXPECT_EQ(result, true);
457 AAFwk::Want want;
458 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
459 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
460 EXPECT_FALSE(ret);
461 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_003 end ret:" << ret << std::endl;
462 }
463
464 /**
465 * @tc.name: CheckStartControlPermission_004
466 * @tc.desc: input invalid params
467 * @tc.type: FUNC
468 * @tc.require: issueI5T6GJ
469 */
470 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_004, TestSize.Level3)
471 {
472 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_004 begin" << std::endl;
473 AppExecFwk::AbilityInfo targetAbility;
474 CallerInfo callerInfo;
475 AAFwk::Want want;
476 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
477 EXPECT_FALSE(ret);
478 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_004 end ret:" << ret << std::endl;
479 }
480
481 /**
482 * @tc.name: CheckStartControlPermission_005
483 * @tc.desc: input invalid params
484 * @tc.type: FUNC
485 * @tc.require: issueI5T6GJ
486 */
487 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_005, TestSize.Level3)
488 {
489 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_005 begin" << std::endl;
490 AppExecFwk::AbilityInfo targetAbility;
491 CallerInfo callerInfo;
492 AAFwk::Want want;
493 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
494 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
495 EXPECT_FALSE(ret);
496 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_005 end ret:" << ret << std::endl;
497 }
498
499 /**
500 * @tc.name: CheckStartControlPermission_006
501 * @tc.desc: input invalid params
502 * @tc.type: FUNC
503 * @tc.require: issueI5T6GJ
504 */
505 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_006, TestSize.Level3)
506 {
507 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_006 begin" << std::endl;
508 AppExecFwk::AbilityInfo targetAbility;
509 targetAbility.bundleName = BUNDLE_NAME;
510 CallerInfo callerInfo;
511 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
512 EXPECT_EQ(result, true);
513 AAFwk::Want want;
514 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
515 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
516 EXPECT_FALSE(ret);
517 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_006 end ret:" << ret << std::endl;
518 }
519
520 /**
521 * @tc.name: CheckStartControlPermission_007
522 * @tc.desc: input invalid params
523 * @tc.type: FUNC
524 * @tc.require: issueI5T6GJ
525 */
526 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_007, TestSize.Level3)
527 {
528 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_007 begin" << std::endl;
529 AppExecFwk::AbilityInfo targetAbility;
530 CallerInfo callerInfo;
531 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
532 EXPECT_EQ(result, true);
533 AAFwk::Want want;
534 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
535 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
536 EXPECT_FALSE(ret);
537 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_007 end ret:" << ret << std::endl;
538 }
539
540 /**
541 * @tc.name: CheckStartControlPermission_008
542 * @tc.desc: input invalid params
543 * @tc.type: FUNC
544 * @tc.require: issueI5T6GJ
545 */
546 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_008, TestSize.Level3)
547 {
548 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_008 begin" << std::endl;
549 AppExecFwk::AbilityInfo targetAbility;
550 targetAbility.visible = true;
551 targetAbility.isStageBasedModel = true;
552 CallerInfo callerInfo;
553 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
554 EXPECT_EQ(result, true);
555 AAFwk::Want want;
556 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
557 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
558 EXPECT_TRUE(ret);
559 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_008 end ret:" << ret << std::endl;
560 }
561
562 /**
563 * @tc.name: CheckStartControlPermission_009
564 * @tc.desc: input invalid params
565 * @tc.type: FUNC
566 * @tc.require: issueI5T6GJ
567 */
568 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_009, TestSize.Level3)
569 {
570 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_009 begin" << std::endl;
571 AppExecFwk::AbilityInfo targetAbility;
572 targetAbility.visible = true;
573 targetAbility.type = AppExecFwk::AbilityType::PAGE;
574 CallerInfo callerInfo;
575 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
576 EXPECT_EQ(result, true);
577 AAFwk::Want want;
578 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
579 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
580 EXPECT_TRUE(ret);
581 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_009 end ret:" << ret << std::endl;
582 }
583
584 /**
585 * @tc.name: CheckStartControlPermission_010
586 * @tc.desc: input invalid params
587 * @tc.type: FUNC
588 * @tc.require: issueI5T6GJ
589 */
590 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_010, TestSize.Level3)
591 {
592 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_010 begin" << std::endl;
593 AppExecFwk::AbilityInfo targetAbility;
594 targetAbility.visible = true;
595 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
596 CallerInfo callerInfo;
597 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
598 EXPECT_EQ(result, true);
599 AAFwk::Want want;
600 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
601 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
602 EXPECT_FALSE(ret);
603 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_010 end ret:" << ret << std::endl;
604 }
605
606 /**
607 * @tc.name: CheckStartControlPermission_011
608 * @tc.desc: input invalid params
609 * @tc.type: FUNC
610 * @tc.require: issueI5T6GJ
611 */
612 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_011, TestSize.Level3)
613 {
614 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_011 begin" << std::endl;
615 AppExecFwk::AbilityInfo targetAbility;
616 targetAbility.visible = true;
617 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
618 targetAbility.applicationInfo.associatedWakeUp = true;
619 CallerInfo callerInfo;
620 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
621 EXPECT_EQ(result, true);
622 AAFwk::Want want;
623 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
624 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
625 EXPECT_TRUE(ret);
626 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_011 end ret:" << ret << std::endl;
627 }
628
629 /**
630 * @tc.name: CheckStartControlPermission_013
631 * @tc.desc: input invalid params
632 * @tc.type: FUNC
633 * @tc.require: issueI5T6GJ
634 */
635 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_013, TestSize.Level3)
636 {
637 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_013 begin" << std::endl;
638 AppExecFwk::AbilityInfo targetAbility;
639 targetAbility.visible = true;
640 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
641 targetAbility.applicationInfo.associatedWakeUp = true;
642 CallerInfo callerInfo;
643 AAFwk::Want want;
644 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
645 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
646 EXPECT_FALSE(ret);
647 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_013 end ret:" << ret << std::endl;
648 }
649
650 /**
651 * @tc.name: CheckStartControlPermission_014
652 * @tc.desc: input invalid params
653 * @tc.type: FUNC
654 * @tc.require: issueI5T6GJ
655 */
656 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_014, TestSize.Level3)
657 {
658 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_014 begin" << std::endl;
659 AppExecFwk::AbilityInfo targetAbility;
660 targetAbility.visible = true;
661 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
662 targetAbility.applicationInfo.associatedWakeUp = true;
663 CallerInfo callerInfo;
664 AAFwk::Want want;
665 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
666 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
667 EXPECT_FALSE(ret);
668 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_014 end ret:" << ret << std::endl;
669 }
670
671 /**
672 * @tc.name: CheckBackgroundPermission_001
673 * @tc.desc: input invalid params
674 * @tc.type: FUNC
675 * @tc.require: issueI5T6GJ
676 */
677 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_001, TestSize.Level3)
678 {
679 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_001 begin" << std::endl;
680 AppExecFwk::AbilityInfo targetAbility;
681 CallerInfo callerInfo;
682 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
683 AAFwk::Want want;
684 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
685 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
686 false);
687 EXPECT_TRUE(ret);
688 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_001 end ret:" << ret << std::endl;
689 }
690
691 /**
692 * @tc.name: CheckBackgroundPermission_002
693 * @tc.desc: input invalid params
694 * @tc.type: FUNC
695 * @tc.require: issueI5T6GJ
696 */
697 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_002, TestSize.Level3)
698 {
699 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_002 begin" << std::endl;
700 AppExecFwk::AbilityInfo targetAbility;
701 CallerInfo callerInfo;
702 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
703 AAFwk::Want want;
704 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
705 false);
706 EXPECT_FALSE(ret);
707 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_002 end ret:" << ret << std::endl;
708 }
709
710 /**
711 * @tc.name: CheckBackgroundPermission_003
712 * @tc.desc: input invalid params
713 * @tc.type: FUNC
714 * @tc.require: issueI5T6GJ
715 */
716 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_003, TestSize.Level3)
717 {
718 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_003 begin" << std::endl;
719 AppExecFwk::AbilityInfo targetAbility;
720 targetAbility.isStageBasedModel = true;
721 CallerInfo callerInfo;
722 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
723 AAFwk::Want want;
724 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
725 true);
726 EXPECT_FALSE(ret);
727 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_003 end ret:" << ret << std::endl;
728 }
729
730 /**
731 * @tc.name: CheckBackgroundPermission_004
732 * @tc.desc: input invalid params
733 * @tc.type: FUNC
734 * @tc.require: issueI5T6GJ
735 */
736 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_004, TestSize.Level3)
737 {
738 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_004 begin" << std::endl;
739 AppExecFwk::AbilityInfo targetAbility;
740 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
741 CallerInfo callerInfo;
742 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
743 AAFwk::Want want;
744 want.SetParam(DMS_API_VERSION, FA_MODULE_ALLOW_MIN_API_VERSION);
745 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
746 true);
747 EXPECT_TRUE(ret);
748 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_004 end ret:" << ret << std::endl;
749 }
750
751 /**
752 * @tc.name: CheckBackgroundPermission_005
753 * @tc.desc: input invalid params
754 * @tc.type: FUNC
755 * @tc.require: issueI5T6GJ
756 */
757 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_005, TestSize.Level3)
758 {
759 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_005 begin" << std::endl;
760 AppExecFwk::AbilityInfo targetAbility;
761 CallerInfo callerInfo;
762 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
763 callerInfo.sourceDeviceId = "";
764 callerInfo.accessToken = GetSelfTokenID();
765 AAFwk::Want want;
766 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
767 false);
768 EXPECT_FALSE(ret);
769 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_005 end ret:" << ret << std::endl;
770 }
771
772 /**
773 * @tc.name: CheckBackgroundPermission_006
774 * @tc.desc: input invalid params
775 * @tc.type: FUNC
776 * @tc.require: issueI5T6GJ
777 */
778 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_006, TestSize.Level3)
779 {
780 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_006 begin" << std::endl;
781 AppExecFwk::AbilityInfo targetAbility;
782 CallerInfo callerInfo;
783 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
784 callerInfo.sourceDeviceId = deviceId_;
785 uint64_t tokenId = GetSelfTokenID();
786 callerInfo.accessToken = tokenId;
787 AAFwk::Want want;
788 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
789 false);
790 EXPECT_FALSE(ret);
791 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_006 end ret:" << ret << std::endl;
792 }
793
794 /**
795 * @tc.name: CheckBackgroundPermission_007
796 * @tc.desc: check CheckTargetAbilityVisible
797 * @tc.type: FUNC
798 * @tc.require: issueI5T6GJ
799 */
800 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_007, TestSize.Level3)
801 {
802 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_007 begin" << std::endl;
803 ASSERT_NE(DnetworkAdapter::GetInstance(), nullptr);
804 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
805 std::string deviceId = udid;
806 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
807 HapTokenInfo baseInfo = {
808 .apl = APL_NORMAL,
809 .ver = 1,
810 .userID = 1,
811 .bundleName = "com.ohos.dms_test",
812 .instIndex = 1,
813 .appID = "dmstest",
814 .deviceID = udid,
815 .tokenID = 0x20100000,
816 .tokenAttr = 0
817 };
818
819 PermissionStateFull infoManagerTestState = {
820 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
821 .isGeneral = true,
822 .resDeviceID = {"local"},
823 .grantStatus = {PermissionState::PERMISSION_GRANTED}, // first grant
824 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
825 std::vector<PermissionStateFull> permStateList;
826 permStateList.emplace_back(infoManagerTestState);
827
828 HapTokenInfoForSync remoteTokenInfo = {
829 .baseInfo = baseInfo,
830 .permStateList = permStateList
831 };
832
833 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
834 ASSERT_EQ(result, RET_SUCCESS);
835
836 // Get local map token ID
837 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
838 ASSERT_NE(mapID, 0);
839
840 AppExecFwk::AbilityInfo targetAbility;
841 CallerInfo callerInfo;
842 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
843 callerInfo.sourceDeviceId = deviceId_;
844 callerInfo.accessToken = 0x20100000;
845 AAFwk::Want want;
846 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
847 false);
848 EXPECT_FALSE(ret);
849 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_007 end ret:" << ret << std::endl;
850 }
851
852 /**
853 * @tc.name: CheckMinApiVersion_001
854 * @tc.desc: input invalid params
855 * @tc.type: FUNC
856 * @tc.require: issueI5T6GJ
857 */
858 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_001, TestSize.Level3)
859 {
860 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 begin" << std::endl;
861 AppExecFwk::AbilityInfo targetAbility;
862 targetAbility.isStageBasedModel = true;
863 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
864 EXPECT_FALSE(ret);
865 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 end ret:" << ret << std::endl;
866 }
867
868 /**
869 * @tc.name: CheckMinApiVersion_002
870 * @tc.desc: input invalid params
871 * @tc.type: FUNC
872 * @tc.require: issueI5T6GJ
873 */
874 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_002, TestSize.Level3)
875 {
876 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 begin" << std::endl;
877 AppExecFwk::AbilityInfo targetAbility;
878 targetAbility.type = AppExecFwk::AbilityType::PAGE;
879 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
880 EXPECT_FALSE(ret);
881 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 end ret:" << ret << std::endl;
882 }
883
884 /**
885 * @tc.name: CheckMinApiVersion_003
886 * @tc.desc: input invalid params
887 * @tc.type: FUNC
888 * @tc.require: issueI5T6GJ
889 */
890 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_003, TestSize.Level3)
891 {
892 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 begin" << std::endl;
893 AppExecFwk::AbilityInfo targetAbility;
894 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
895 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
896 EXPECT_FALSE(ret);
897 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 end ret:" << ret << std::endl;
898 }
899
900 /**
901 * @tc.name: CheckMinApiVersion_004
902 * @tc.desc: input invalid params
903 * @tc.type: FUNC
904 * @tc.require: issueI5T6GJ
905 */
906 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_004, TestSize.Level3)
907 {
908 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 begin" << std::endl;
909 AppExecFwk::AbilityInfo targetAbility;
910 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
911 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility,
912 FA_MODULE_ALLOW_MIN_API_VERSION);
913 EXPECT_TRUE(ret);
914 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 end ret:" << ret << std::endl;
915 }
916
917 /**
918 * @tc.name: CheckTargetAbilityVisible_001
919 * @tc.desc: input invalid params
920 * @tc.type: FUNC
921 * @tc.require: issueI5T6GJ
922 */
923 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_001, TestSize.Level3)
924 {
925 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 begin" << std::endl;
926 AppExecFwk::AbilityInfo targetAbility;
927 targetAbility.visible = true;
928 CallerInfo callerInfo;
929 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
930 EXPECT_TRUE(ret);
931 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 end ret:" << ret << std::endl;
932 }
933
934 /**
935 * @tc.name: CheckTargetAbilityVisible_002
936 * @tc.desc: input invalid params
937 * @tc.type: FUNC
938 * @tc.require: issueI5T6GJ
939 */
940 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_002, TestSize.Level3)
941 {
942 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 begin" << std::endl;
943 AppExecFwk::AbilityInfo targetAbility;
944 CallerInfo callerInfo;
945 callerInfo.sourceDeviceId = "";
946 callerInfo.accessToken = GetSelfTokenID();
947 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
948 EXPECT_FALSE(ret);
949 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 end ret:" << ret << std::endl;
950 }
951
952 /**
953 * @tc.name: CheckTargetAbilityVisible_003
954 * @tc.desc: input invalid params
955 * @tc.type: FUNC
956 * @tc.require: issueI5T6GJ
957 */
958 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_003, TestSize.Level3)
959 {
960 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 begin" << std::endl;
961 AppExecFwk::AbilityInfo targetAbility;
962 CallerInfo callerInfo;
963 callerInfo.sourceDeviceId = "deviceId_";
964 callerInfo.accessToken = GetSelfTokenID();
965 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
966 EXPECT_FALSE(ret);
967 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 end ret:" << ret << std::endl;
968 }
969
970 #ifdef TOKEN_SYNC_ENABLE
971 /**
972 * @tc.name: CheckTargetAbilityVisible_004
973 * @tc.desc: check CheckTargetAbilityVisible
974 * @tc.type: FUNC
975 * @tc.require: issueI5T6GJ
976 */
977 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_004, TestSize.Level3)
978 {
979 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 begin" << std::endl;
980 ASSERT_NE(DnetworkAdapter::GetInstance(), nullptr);
981 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
982 std::string deviceId = udid;
983 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
984 HapTokenInfo baseInfo = {
985 .apl = APL_NORMAL,
986 .ver = 1,
987 .userID = 1,
988 .bundleName = "com.ohos.dms_test",
989 .instIndex = 1,
990 .appID = "dmstest",
991 .deviceID = udid,
992 .tokenID = 0x20100000,
993 .tokenAttr = 0
994 };
995
996 PermissionStateFull infoManagerTestState = {
997 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
998 .isGeneral = true,
999 .resDeviceID = {"local"},
1000 .grantStatus = {PermissionState::PERMISSION_GRANTED}, // first grant
1001 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
1002 std::vector<PermissionStateFull> permStateList;
1003 permStateList.emplace_back(infoManagerTestState);
1004
1005 HapTokenInfoForSync remoteTokenInfo = {
1006 .baseInfo = baseInfo,
1007 .permStateList = permStateList
1008 };
1009
1010 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1011 ASSERT_EQ(result, RET_SUCCESS);
1012
1013 // Get local map token ID
1014 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1015 ASSERT_NE(mapID, 0);
1016
1017 AppExecFwk::AbilityInfo targetAbility;
1018 CallerInfo callerInfo;
1019 callerInfo.sourceDeviceId = deviceId_;
1020 callerInfo.accessToken = 0x20100000;
1021 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1022 EXPECT_TRUE(ret);
1023 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 end ret:" << ret << std::endl;
1024 }
1025
1026 /**
1027 * @tc.name: CheckTargetAbilityVisible_005
1028 * @tc.desc: check CheckTargetAbilityVisible
1029 * @tc.type: FUNC
1030 * @tc.require: issueI5T6GJ
1031 */
1032 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_005, TestSize.Level3)
1033 {
1034 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 begin" << std::endl;
1035 ASSERT_NE(DnetworkAdapter::GetInstance(), nullptr);
1036 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
1037 std::string deviceId = udid;
1038 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
1039 HapTokenInfo baseInfo = {
1040 .apl = APL_NORMAL,
1041 .ver = 1,
1042 .userID = 1,
1043 .bundleName = "com.ohos.dms_test",
1044 .instIndex = 1,
1045 .appID = "dmstest",
1046 .deviceID = udid,
1047 .tokenID = 0x20100000,
1048 .tokenAttr = 0
1049 };
1050
1051 PermissionStateFull infoManagerTestState = {
1052 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
1053 .isGeneral = true,
1054 .resDeviceID = {"local"},
1055 .grantStatus = {PermissionState::PERMISSION_DENIED},
1056 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
1057 std::vector<PermissionStateFull> permStateList;
1058 permStateList.emplace_back(infoManagerTestState);
1059
1060 HapTokenInfoForSync remoteTokenInfo = {
1061 .baseInfo = baseInfo,
1062 .permStateList = permStateList
1063 };
1064
1065 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1066 ASSERT_EQ(result, RET_SUCCESS);
1067
1068 // Get local map token ID
1069 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1070 ASSERT_NE(mapID, 0);
1071
1072 AppExecFwk::AbilityInfo targetAbility;
1073 CallerInfo callerInfo;
1074 callerInfo.sourceDeviceId = deviceId_;
1075 callerInfo.accessToken = 0x20100000;
1076 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1077 EXPECT_FALSE(ret);
1078 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 end ret:" << ret << std::endl;
1079 }
1080 #endif
1081
1082 /**
1083 * @tc.name: GetAccountInfo_001
1084 * @tc.desc: call GetAccountInfo with empty networkId
1085 * @tc.type: FUNC
1086 * @tc.require: I5RWIV
1087 */
1088 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_001, TestSize.Level3)
1089 {
1090 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 begin" << std::endl;
1091 std::string remoteNetworkId;
1092 CallerInfo callerInfo;
1093 IDistributedSched::AccountInfo accountInfo;
1094 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1095 remoteNetworkId, callerInfo, accountInfo);
1096 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1097 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 end result:" << ret << std::endl;
1098 }
1099
1100 /**
1101 * @tc.name: GetAccountInfo_002
1102 * @tc.desc: call GetAccountInfo with invalid networkId
1103 * @tc.type: FUNC
1104 * @tc.require: I5RWIV
1105 */
1106 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_002, TestSize.Level3)
1107 {
1108 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 begin" << std::endl;
1109 std::string remoteNetworkId = "0";
1110 CallerInfo callerInfo;
1111 IDistributedSched::AccountInfo accountInfo;
1112 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1113 remoteNetworkId, callerInfo, accountInfo);
1114 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1115 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 end result:" << ret << std::endl;
1116 }
1117
1118 /**
1119 * @tc.name: GetRelatedGroups_001
1120 * @tc.desc: call GetRelatedGroups with empty bundleNames
1121 * @tc.type: FUNC
1122 * @tc.require: I5RWIV
1123 */
1124 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_001, TestSize.Level3)
1125 {
1126 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 begin" << std::endl;
1127 std::string udid;
1128 std::vector<std::string> bundleNames;
1129 IDistributedSched::AccountInfo accountInfo;
1130 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1131 udid, bundleNames, accountInfo);
1132 EXPECT_EQ(ret, false);
1133 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1134 }
1135
1136 /**
1137 * @tc.name: GetRelatedGroups_002
1138 * @tc.desc: call GetRelatedGroups with invalid bundleNames
1139 * @tc.type: FUNC
1140 * @tc.require: I5RWIV
1141 */
1142 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_002, TestSize.Level3)
1143 {
1144 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 begin" << std::endl;
1145 std::string udid = "0";
1146 std::vector<std::string> bundleNames = {"mock.bundle1", "mock.bundle2"};
1147 IDistributedSched::AccountInfo accountInfo;
1148 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1149 udid, bundleNames, accountInfo);
1150 EXPECT_EQ(ret, false);
1151 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1152 }
1153
1154 /**
1155 * @tc.name: ParseGroupInfos_001
1156 * @tc.desc: call ParseGroupInfos with empty returnGroupStr
1157 * @tc.type: FUNC
1158 * @tc.require: I5RWIV
1159 */
1160 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_001, TestSize.Level3)
1161 {
1162 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_001 begin" << std::endl;
1163 std::string returnGroupStr;
1164 std::vector<GroupInfo> groupInfos;
1165 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1166 returnGroupStr, groupInfos);
1167 EXPECT_EQ(ret, false);
1168 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1169 }
1170
1171 /**
1172 * @tc.name: ParseGroupInfos_002
1173 * @tc.desc: call ParseGroupInfos with invalid returnGroupStr
1174 * @tc.type: FUNC
1175 * @tc.require: I5RWIV
1176 */
1177 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_002, TestSize.Level3)
1178 {
1179 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_002 begin" << std::endl;
1180 std::string returnGroupStr = "mockInvalidGroup";
1181 std::vector<GroupInfo> groupInfos;
1182 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1183 returnGroupStr, groupInfos);
1184 EXPECT_EQ(ret, false);
1185 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1186 }
1187
1188 /**
1189 * @tc.name: ParseGroupInfos_003
1190 * @tc.desc: call ParseGroupInfos
1191 * @tc.type: FUNC
1192 * @tc.require: I5RWIV
1193 */
1194 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_003, TestSize.Level3)
1195 {
1196 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_003 begin" << std::endl;
1197 std::string returnGroupStr = "[{\"groupName\":\"mockGroupName\",\"groupId\":\"mockGroupId\",";
1198 returnGroupStr += "\"groupOwner\":\"mockGroupOwner\",\"groupType\":0,\"groupVisibility\":0}]";
1199 std::vector<GroupInfo> groupInfos;
1200 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1201 returnGroupStr, groupInfos);
1202 EXPECT_EQ(ret, true);
1203 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_003 end result:" << ret << std::endl;
1204 }
1205
1206 /**
1207 * @tc.name: IsFoundationCall_001
1208 * @tc.desc: call IsFoundationCall not from foundation
1209 * @tc.type: FUNC
1210 * @tc.require: I5RWIV
1211 */
1212 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_001, TestSize.Level3)
1213 {
1214 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 begin" << std::endl;
1215 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1216 EXPECT_EQ(ret, false);
1217 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 end result:" << ret << std::endl;
1218 }
1219
1220 /**
1221 * @tc.name: IsFoundationCall_002
1222 * @tc.desc: call IsFoundationCall from foundation
1223 * @tc.type: FUNC
1224 * @tc.require: I5RWIV
1225 */
1226 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_002, TestSize.Level3)
1227 {
1228 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 begin" << std::endl;
1229 DistributedSchedUtil::MockProcess(FOUNDATION_PROCESS_NAME);
1230 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1231 EXPECT_EQ(ret, true);
1232 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 end result:" << ret << std::endl;
1233 }
1234
1235 /**
1236 * @tc.name: CheckAccountAccessPermission_001
1237 * @tc.desc: call CheckAccountAccessPermission in same account
1238 * @tc.type: FUNC
1239 */
1240 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_001, TestSize.Level1)
1241 {
1242 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 begin" << std::endl;
1243 CallerInfo callerInfo;
1244 IDistributedSched::AccountInfo accountInfo;
1245 string targetBundle = BUNDLE_NAME;
1246 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1247 callerInfo, accountInfo, targetBundle);
1248 EXPECT_EQ(ret, false);
1249 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 end result:" << ret << std::endl;
1250 }
1251
1252 /**
1253 * @tc.name: CheckComponentAccessPermission_001
1254 * @tc.desc: call CheckComponentAccessPermission in same account
1255 * @tc.type: FUNC
1256 */
1257 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_001, TestSize.Level1)
1258 {
1259 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 begin" << std::endl;
1260 AppExecFwk::AbilityInfo targetAbility;
1261 CallerInfo callerInfo;
1262 callerInfo.accessToken = ACCESS_TOKEN;
1263 IDistributedSched::AccountInfo accountInfo;
1264 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1265 std::string groupId = GROUP_ID;
1266 accountInfo.groupIdList.push_back(groupId);
1267 AAFwk::Want want;
1268 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1269 want.SetElement(element);
1270 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1271 callerInfo, accountInfo, want);
1272 EXPECT_EQ(ret, false);
1273 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 end result:" << ret << std::endl;
1274 }
1275
1276 /**
1277 * @tc.name: CheckComponentAccessPermission_002
1278 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in same account
1279 * @tc.type: FUNC
1280 */
1281 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_002, TestSize.Level1)
1282 {
1283 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 begin" << std::endl;
1284 AppExecFwk::AbilityInfo targetAbility;
1285 CallerInfo callerInfo;
1286 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1287 IDistributedSched::AccountInfo accountInfo;
1288 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1289 std::string groupId = GROUP_ID;
1290 accountInfo.groupIdList.push_back(groupId);
1291 AAFwk::Want want;
1292 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1293 want.SetElement(element);
1294 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1295 callerInfo, accountInfo, want);
1296 EXPECT_EQ(ret, false);
1297 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 end result:" << ret << std::endl;
1298 }
1299
1300 /**
1301 * @tc.name: CheckComponentAccessPermission_003
1302 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in same account
1303 * @tc.type: FUNC
1304 */
1305 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_003, TestSize.Level1)
1306 {
1307 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 begin" << std::endl;
1308 AppExecFwk::AbilityInfo targetAbility;
1309 CallerInfo callerInfo;
1310 callerInfo.accessToken = ACCESS_TOKEN;
1311 IDistributedSched::AccountInfo accountInfo;
1312 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1313 std::string groupId = INVALID_GROUP_ID;
1314 accountInfo.groupIdList.push_back(groupId);
1315 AAFwk::Want want;
1316 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1317 want.SetElement(element);
1318 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1319 callerInfo, accountInfo, want);
1320 EXPECT_EQ(ret, false);
1321 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 end result:" << ret << std::endl;
1322 }
1323
1324 /**
1325 * @tc.name: CheckComponentAccessPermission_004
1326 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in same account
1327 * @tc.type: FUNC
1328 */
1329 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_004, TestSize.Level1)
1330 {
1331 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 begin" << std::endl;
1332 AppExecFwk::AbilityInfo targetAbility;
1333 CallerInfo callerInfo;
1334 callerInfo.accessToken = ACCESS_TOKEN;
1335 IDistributedSched::AccountInfo accountInfo;
1336 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1337 std::string groupId = GROUP_ID;
1338 accountInfo.groupIdList.push_back(groupId);
1339 AAFwk::Want want;
1340 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1341 want.SetElement(element);
1342 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1343 callerInfo, accountInfo, want);
1344 EXPECT_EQ(ret, false);
1345 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 end result:" << ret << std::endl;
1346 }
1347
1348 /**
1349 * @tc.name: CheckComponentAccessPermission_005
1350 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in same account
1351 * @tc.type: FUNC
1352 */
1353 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_005, TestSize.Level1)
1354 {
1355 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 begin" << std::endl;
1356 AppExecFwk::AbilityInfo targetAbility;
1357 CallerInfo callerInfo;
1358 callerInfo.accessToken = ACCESS_TOKEN;
1359 IDistributedSched::AccountInfo accountInfo;
1360 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1361 std::string groupId = GROUP_ID;
1362 accountInfo.groupIdList.push_back(groupId);
1363 AAFwk::Want want;
1364 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1365 want.SetElement(element);
1366 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1367 callerInfo, accountInfo, want);
1368 EXPECT_EQ(ret, false);
1369 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 end result:" << ret << std::endl;
1370 }
1371
1372 /**
1373 * @tc.name: CheckComponentAccessPermission_006
1374 * @tc.desc: call CheckComponentAccessPermission with visible: true in same account
1375 * @tc.type: FUNC
1376 */
1377 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_006, TestSize.Level1)
1378 {
1379 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 begin" << std::endl;
1380 AppExecFwk::AbilityInfo targetAbility;
1381 targetAbility.visible = true;
1382 CallerInfo callerInfo;
1383 callerInfo.accessToken = ACCESS_TOKEN;
1384 IDistributedSched::AccountInfo accountInfo;
1385 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1386 std::string groupId = GROUP_ID;
1387 accountInfo.groupIdList.push_back(groupId);
1388 AAFwk::Want want;
1389 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1390 want.SetElement(element);
1391 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1392 callerInfo, accountInfo, want);
1393 EXPECT_EQ(ret, true);
1394 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 end result:" << ret << std::endl;
1395 }
1396
1397 /**
1398 * @tc.name: CheckComponentAccessPermission_007
1399 * @tc.desc: call CheckComponentAccessPermission with visible: false in same account
1400 * @tc.type: FUNC
1401 */
1402 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_007, TestSize.Level1)
1403 {
1404 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 begin" << std::endl;
1405 AppExecFwk::AbilityInfo targetAbility;
1406 targetAbility.visible = false;
1407 CallerInfo callerInfo;
1408 callerInfo.accessToken = ACCESS_TOKEN;
1409 IDistributedSched::AccountInfo accountInfo;
1410 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1411 std::string groupId = GROUP_ID;
1412 accountInfo.groupIdList.push_back(groupId);
1413 AAFwk::Want want;
1414 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1415 want.SetElement(element);
1416 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1417 callerInfo, accountInfo, want);
1418 EXPECT_EQ(ret, false);
1419 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 end result:" << ret << std::endl;
1420 }
1421
1422 /**
1423 * @tc.name: CheckComponentAccessPermission_008
1424 * @tc.desc: call CheckComponentAccessPermission in diff account
1425 * @tc.type: FUNC
1426 */
1427 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_008, TestSize.Level1)
1428 {
1429 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 begin" << std::endl;
1430 AppExecFwk::AbilityInfo targetAbility;
1431 CallerInfo callerInfo;
1432 callerInfo.accessToken = ACCESS_TOKEN;
1433 IDistributedSched::AccountInfo accountInfo;
1434 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1435 std::string groupId = GROUP_ID;
1436 accountInfo.groupIdList.push_back(groupId);
1437 AAFwk::Want want;
1438 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1439 want.SetElement(element);
1440 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1441 callerInfo, accountInfo, want);
1442 EXPECT_EQ(ret, false);
1443 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 end result:" << ret << std::endl;
1444 }
1445
1446 /**
1447 * @tc.name: CheckComponentAccessPermission_009
1448 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in diff account
1449 * @tc.type: FUNC
1450 */
1451 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_009, TestSize.Level1)
1452 {
1453 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 begin" << std::endl;
1454 AppExecFwk::AbilityInfo targetAbility;
1455 CallerInfo callerInfo;
1456 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1457 IDistributedSched::AccountInfo accountInfo;
1458 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1459 std::string groupId = GROUP_ID;
1460 accountInfo.groupIdList.push_back(groupId);
1461 AAFwk::Want want;
1462 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1463 want.SetElement(element);
1464 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1465 callerInfo, accountInfo, want);
1466 EXPECT_EQ(ret, false);
1467 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 end result:" << ret << std::endl;
1468 }
1469
1470 /**
1471 * @tc.name: CheckComponentAccessPermission_010
1472 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in diff account
1473 * @tc.type: FUNC
1474 */
1475 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_010, TestSize.Level1)
1476 {
1477 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 begin" << std::endl;
1478 AppExecFwk::AbilityInfo targetAbility;
1479 CallerInfo callerInfo;
1480 callerInfo.accessToken = ACCESS_TOKEN;
1481 IDistributedSched::AccountInfo accountInfo;
1482 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1483 std::string groupId = INVALID_GROUP_ID;
1484 accountInfo.groupIdList.push_back(groupId);
1485 AAFwk::Want want;
1486 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1487 want.SetElement(element);
1488 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1489 callerInfo, accountInfo, want);
1490 EXPECT_EQ(ret, false);
1491 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 end result:" << ret << std::endl;
1492 }
1493
1494 /**
1495 * @tc.name: CheckComponentAccessPermission_011
1496 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in diff account
1497 * @tc.type: FUNC
1498 */
1499 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_011, TestSize.Level1)
1500 {
1501 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 begin" << std::endl;
1502 AppExecFwk::AbilityInfo targetAbility;
1503 CallerInfo callerInfo;
1504 callerInfo.accessToken = ACCESS_TOKEN;
1505 IDistributedSched::AccountInfo accountInfo;
1506 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1507 std::string groupId = GROUP_ID;
1508 accountInfo.groupIdList.push_back(groupId);
1509 AAFwk::Want want;
1510 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1511 want.SetElement(element);
1512 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1513 callerInfo, accountInfo, want);
1514 EXPECT_EQ(ret, false);
1515 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 end result:" << ret << std::endl;
1516 }
1517
1518 /**
1519 * @tc.name: CheckComponentAccessPermission_012
1520 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in diff account
1521 * @tc.type: FUNC
1522 */
1523 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_012, TestSize.Level1)
1524 {
1525 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 begin" << std::endl;
1526 AppExecFwk::AbilityInfo targetAbility;
1527 CallerInfo callerInfo;
1528 callerInfo.accessToken = ACCESS_TOKEN;
1529 IDistributedSched::AccountInfo accountInfo;
1530 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1531 std::string groupId = GROUP_ID;
1532 accountInfo.groupIdList.push_back(groupId);
1533 AAFwk::Want want;
1534 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1535 want.SetElement(element);
1536 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1537 callerInfo, accountInfo, want);
1538 EXPECT_EQ(ret, false);
1539 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 end result:" << ret << std::endl;
1540 }
1541
1542 /**
1543 * @tc.name: CheckComponentAccessPermission_013
1544 * @tc.desc: call CheckComponentAccessPermission with visible: true in diff account
1545 * @tc.type: FUNC
1546 */
1547 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_013, TestSize.Level1)
1548 {
1549 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 begin" << std::endl;
1550 AppExecFwk::AbilityInfo targetAbility;
1551 targetAbility.visible = true;
1552 CallerInfo callerInfo;
1553 callerInfo.accessToken = ACCESS_TOKEN;
1554 IDistributedSched::AccountInfo accountInfo;
1555 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1556 std::string groupId = GROUP_ID;
1557 accountInfo.groupIdList.push_back(groupId);
1558 AAFwk::Want want;
1559 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1560 want.SetElement(element);
1561 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1562 callerInfo, accountInfo, want);
1563 EXPECT_EQ(ret, true);
1564 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 end result:" << ret << std::endl;
1565 }
1566
1567 /**
1568 * @tc.name: CheckComponentAccessPermission_014
1569 * @tc.desc: call CheckComponentAccessPermission with visible: false in diff account
1570 * @tc.type: FUNC
1571 */
1572 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_014, TestSize.Level1)
1573 {
1574 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 begin" << std::endl;
1575 AppExecFwk::AbilityInfo targetAbility;
1576 targetAbility.visible = false;
1577 CallerInfo callerInfo;
1578 callerInfo.accessToken = ACCESS_TOKEN;
1579 IDistributedSched::AccountInfo accountInfo;
1580 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1581 std::string groupId = GROUP_ID;
1582 accountInfo.groupIdList.push_back(groupId);
1583 AAFwk::Want want;
1584 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1585 want.SetElement(element);
1586 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1587 callerInfo, accountInfo, want);
1588 EXPECT_EQ(ret, false);
1589 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 end result:" << ret << std::endl;
1590 }
1591
1592 /**
1593 * @tc.name: CheckPermission_001
1594 * @tc.desc: call CheckPermission
1595 * @tc.type: FUNC
1596 */
1597 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_001, TestSize.Level1)
1598 {
1599 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 begin" << std::endl;
1600 uint32_t accessToken = ACCESS_TOKEN;
1601 string permissionName = PERMISSION_NAME;
1602 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
1603 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1604 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 end result:" << ret << std::endl;
1605 }
1606
1607 /**
1608 * @tc.name: CheckPermission_002
1609 * @tc.desc: call CheckPermission with invalid accessToken
1610 * @tc.type: FUNC
1611 */
1612 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_002, TestSize.Level1)
1613 {
1614 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_002 begin" << std::endl;
1615 uint32_t accessToken = INVALID_ACCESS_TOKEN;
1616 string permissionName = PERMISSION_NAME;
1617 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
1618 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1619 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_002 end result:" << ret << std::endl;
1620 }
1621
1622 /**
1623 * @tc.name: CheckPermission_003
1624 * @tc.desc: call CheckPermission with invalid permission
1625 * @tc.type: FUNC
1626 */
1627 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_003, TestSize.Level1)
1628 {
1629 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_003 begin" << std::endl;
1630 uint32_t accessToken = INVALID_ACCESS_TOKEN;
1631 string permissionName = PERMISSION_NAME;
1632 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
1633 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1634 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_003 end result:" << ret << std::endl;
1635 }
1636
1637 /**
1638 * @tc.name: from_json_001
1639 * @tc.desc: parse groupInfo from json
1640 * @tc.type: FUNC
1641 */
1642 HWTEST_F(DistributedSchedPermissionTest, FromJson_001, TestSize.Level3)
1643 {
1644 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 begin" << std::endl;
1645 GroupInfo groupInfo;
1646 nlohmann::json jsonObject = nlohmann::json {
1647 {FIELD_GROUP_NAME, MOCK_FIELD_GROUP_NAME},
1648 {FIELD_GROUP_ID, MOCK_FIELD_GROUP_ID},
1649 {FIELD_GROUP_OWNER, MOCK_FIELD_GROUP_OWNER},
1650 {FIELD_GROUP_TYPE, MOCK_FIELD_GROUP_TYPE},
1651 {FIELD_GROUP_VISIBILITY, MOCK_FIELD_GROUP_VISIBILITY}
1652 };
1653 if (jsonObject.is_discarded()) {
1654 return;
1655 }
1656 from_json(jsonObject, groupInfo);
1657 EXPECT_EQ(groupInfo.groupName, MOCK_FIELD_GROUP_NAME);
1658 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 end" << std::endl;
1659 }
1660
1661 /**
1662 * @tc.name: from_json_002
1663 * @tc.desc: parse groupInfo from json with invalid params
1664 * @tc.type: FUNC
1665 */
1666 HWTEST_F(DistributedSchedPermissionTest, FromJson_002, TestSize.Level3)
1667 {
1668 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 begin" << std::endl;
1669 GroupInfo groupInfo;
1670 nlohmann::json jsonObject;
1671 if (jsonObject.is_discarded()) {
1672 return;
1673 }
1674 from_json(jsonObject, groupInfo);
1675 EXPECT_EQ(groupInfo.groupName, "");
1676 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 end " << std::endl;
1677 }
1678
1679 /**
1680 * @tc.name: MarkUriPermission_001
1681 * @tc.desc: parse groupInfo from json with invalid params
1682 * @tc.type: FUNC
1683 */
1684 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_001, TestSize.Level3)
1685 {
1686 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_001 begin" << std::endl;
1687 AAFwk::Want want;
1688 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
1689 want.SetUri("file://ohos.dms.ets/data/test_B");
1690 DistributedSchedPermission::GetInstance().MarkUriPermission(want, 0);
1691 CallerInfo callerInfo;
1692 callerInfo.accessToken = ACCESS_TOKEN;
1693 IDistributedSched::AccountInfo accountInfo;
1694 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1695 std::string groupId = INVALID_GROUP_ID;
1696 accountInfo.groupIdList.push_back(groupId);
1697 string targetBundle = INVALID_BUNDLE_NAME;
1698 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1699 callerInfo, accountInfo, targetBundle);
1700 EXPECT_EQ(ret, false);
1701 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_001 end " << std::endl;
1702 }
1703
1704 /**
1705 * @tc.name: MarkUriPermission_002
1706 * @tc.desc: parse groupInfo from json with invalid params
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_002, TestSize.Level3)
1710 {
1711 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_002 begin" << std::endl;
1712 AAFwk::Want want;
1713 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
1714 want.SetUri("file://com.ohos.mms/data/test_B");
1715 DistributedSchedPermission::GetInstance().MarkUriPermission(want, 0);
1716 CallerInfo callerInfo;
1717 callerInfo.accessToken = ACCESS_TOKEN;
1718 IDistributedSched::AccountInfo accountInfo;
1719 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1720 std::string groupId = INVALID_GROUP_ID;
1721 accountInfo.groupIdList.push_back(groupId);
1722 string targetBundle = INVALID_BUNDLE_NAME;
1723 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1724 callerInfo, accountInfo, targetBundle);
1725 EXPECT_EQ(ret, false);
1726 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_002 end " << std::endl;
1727 }
1728
1729 /**
1730 * @tc.name: MarkUriPermission_003
1731 * @tc.desc: parse groupInfo from json with invalid params
1732 * @tc.type: FUNC
1733 */
1734 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_003, TestSize.Level3)
1735 {
1736 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_003 begin" << std::endl;
1737 DistributedSchedUtil::MockBundlePermission();
1738 AAFwk::Want want;
1739 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
1740 want.SetUri("file://com.ohos.mms/data/test_B");
1741 const std::string bundleName = "com.ohos.mms";
1742 uint16_t bundleNameId = 0;
1743 int32_t ret = BundleManagerInternal::GetBundleNameId(bundleName, bundleNameId);
1744 EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
1745 DistributedSchedPermission::GetInstance().MarkUriPermission(want, bundleNameId);
1746 CallerInfo callerInfo;
1747 callerInfo.accessToken = ACCESS_TOKEN;
1748 IDistributedSched::AccountInfo accountInfo;
1749 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1750 std::string groupId = INVALID_GROUP_ID;
1751 accountInfo.groupIdList.push_back(groupId);
1752 string targetBundle = INVALID_BUNDLE_NAME;
1753 ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1754 callerInfo, accountInfo, targetBundle);
1755 EXPECT_EQ(ret, false);
1756 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_003 end " << std::endl;
1757 }
1758
1759 /**
1760 * @tc.name: GetDeviceSecurityLevel_001
1761 * @tc.desc: parse groupInfo from json with invalid params
1762 * @tc.type: FUNC
1763 */
1764 HWTEST_F(DistributedSchedPermissionTest, GetDeviceSecurityLevel_001, TestSize.Level3)
1765 {
1766 DTEST_LOG << "DistributedSchedPermissionTest GetDeviceSecurityLevel_001 begin" << std::endl;
1767 string udid = "123456";
1768 int32_t ret = DistributedSchedPermission::GetInstance().GetDeviceSecurityLevel(udid);
1769 EXPECT_NE(ret, 0);
1770 DTEST_LOG << "DistributedSchedPermissionTest GetDeviceSecurityLevel_001 end " << std::endl;
1771 }
1772
1773 /**
1774 * @tc.name: CheckAclList_001
1775 * @tc.desc: call CheckAclList
1776 * @tc.type: FUNC
1777 * @tc.require: I5RWIV
1778 */
1779 HWTEST_F(DistributedSchedPermissionTest, CheckAclList_001, TestSize.Level3)
1780 {
1781 DTEST_LOG << "DistributedSchedPermissionTest CheckAclList_001 begin" << std::endl;
1782 std::string dstNetworkId;
1783 IDistributedSched::AccountInfo dmsAccountInfo;
1784 CallerInfo callerInfo;
1785 DistributedSchedPermission::GetInstance().GetOsAccountData(dmsAccountInfo);
1786 DistributedSchedPermission::GetInstance().CheckDstSameAccount(dstNetworkId, dmsAccountInfo, callerInfo);
1787 bool ret = DistributedSchedPermission::GetInstance().CheckAclList(dstNetworkId, dmsAccountInfo, callerInfo);
1788 EXPECT_EQ(ret, false);
1789 DTEST_LOG << "DistributedSchedPermissionTest CheckAclList_001 end result:" << ret << std::endl;
1790 }
1791 } // namespace DistributedSchedule
1792 } // namespace OHOS