1 /*
2 * Copyright (c) 2021-2022 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_util.h"
26 #include "dtbschedmgr_device_info_storage.h"
27 #include "dtbschedmgr_log.h"
28 #include "nativetoken_kit.h"
29 #include "test_log.h"
30 #include "token_setproc.h"
31
32 using namespace testing;
33 using namespace testing::ext;
34 using namespace OHOS::AppExecFwk;
35 using namespace OHOS::DistributedHardware;
36 using namespace OHOS::Security::AccessToken;
37
38 namespace OHOS {
39 namespace DistributedSchedule {
40 namespace {
41 constexpr uint32_t ACCESS_TOKEN = 100000000;
42 constexpr uint32_t INVALID_ACCESS_TOKEN = 0;
43 const string BUNDLE_NAME = "com.ohos.launcher";
44 const string INVALID_BUNDLE_NAME = "";
45 const string PACKAGE_NAME = "com.ohos.launcher";
46 const string ABILITY_NAME = "com.ohos.launcher.MainAbility";
47 const string INVALID_ABILITY_NAME = "";
48 const string GROUP_ID = "TEST_GROUP_ID";
49 const string INVALID_GROUP_ID = "";
50 const string DEVICE_ID = "255.255.255.255";
51 const string INVALID_DEVICE_ID = "";
52 const string PERMISSION_NAME = "ohos.permission.DISTRIBUTED_DATASYNC";
53 const string INVALID_PERMISSION_NAME = "ohos.permission.TEST";
54 const string DMS_IS_CALLER_BACKGROUND = "dmsIsCallerBackGround";
55 const string DMS_API_VERSION = "dmsApiVersion";
56 const string DMS_MISSION_ID = "dmsMissionId";
57 const string DMS_VERSION_ID = "dmsVersion";
58 const string DMS_VERSION = "4.0.0";
59 const int API_VERSION = 9;
60 const int FA_MODULE_ALLOW_MIN_API_VERSION = 8;
61
62 const string MOCK_FIELD_GROUP_NAME = "MockName";
63 const string MOCK_FIELD_GROUP_ID = "MockId";
64 const string MOCK_FIELD_GROUP_OWNER = "MockOwner";
65 const int32_t MOCK_FIELD_GROUP_TYPE = 0;
66 const int32_t MOCK_FIELD_GROUP_VISIBILITY = 0;
67 const string FIELD_GROUP_NAME = "groupName";
68 const string FIELD_GROUP_ID = "groupId";
69 const string FIELD_GROUP_OWNER = "groupOwner";
70 const string FIELD_GROUP_TYPE = "groupType";
71 const string FIELD_GROUP_VISIBILITY = "groupVisibility";
72 const char* FOUNDATION_PROCESS_NAME = "foundation";
73
NativeTokenGet()74 void NativeTokenGet()
75 {
76 uint32_t tokenId = AccessTokenKit::GetNativeTokenId("token_sync_service");
77 ASSERT_NE(tokenId, 0);
78 SetSelfTokenID(tokenId);
79 }
80 }
81
SetUpTestCase()82 void DistributedSchedPermissionTest::SetUpTestCase()
83 {
84 DTEST_LOG << "DistributedSchedPermissionTest::SetUpTestCase" << std::endl;
85 const std::string pkgName = "DBinderBus_PermissionTest" + std::to_string(getpid());
86 std::shared_ptr<DmInitCallback> initCallback_ = std::make_shared<DeviceInitCallBack>();
87 DeviceManager::GetInstance().InitDeviceManager(pkgName, initCallback_);
88 }
89
TearDownTestCase()90 void DistributedSchedPermissionTest::TearDownTestCase()
91 {
92 DTEST_LOG << "DistributedSchedPermissionTest::TearDownTestCase" << std::endl;
93 }
94
TearDown()95 void DistributedSchedPermissionTest::TearDown()
96 {
97 DTEST_LOG << "DistributedSchedPermissionTest::TearDown" << std::endl;
98 }
99
SetUp()100 void DistributedSchedPermissionTest::SetUp()
101 {
102 DTEST_LOG << "DistributedSchedPermissionTest::SetUp" << std::endl;
103 DistributedSchedUtil::MockPermission();
104 DtbschedmgrDeviceInfoStorage::GetInstance().GetLocalDeviceId(deviceId_);
105
106 NativeTokenGet();
107 }
108
OnRemoteDied()109 void DistributedSchedPermissionTest::DeviceInitCallBack::OnRemoteDied()
110 {
111 }
112
113 /**
114 * @tc.name: CheckSendResultPermission_001
115 * @tc.desc: input invalid params
116 * @tc.type: FUNC
117 * @tc.require: issueI5T6GJ
118 */
119 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_001, TestSize.Level3)
120 {
121 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_001 begin" << std::endl;
122 AAFwk::Want want;
123 CallerInfo callerInfo;
124 IDistributedSched::AccountInfo accountInfo;
125 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
126 AppExecFwk::AbilityInfo targetAbility;
127 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
128 callerInfo, accountInfo, targetAbility);
129 EXPECT_NE(ret, ERR_OK);
130 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_001 end ret:" << ret << std::endl;
131 }
132
133 /**
134 * @tc.name: CheckSendResultPermission_002
135 * @tc.desc: input invalid params
136 * @tc.type: FUNC
137 * @tc.require: issueI5T6GJ
138 */
139 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_002, TestSize.Level3)
140 {
141 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission begin" << std::endl;
142 AAFwk::Want want;
143 CallerInfo callerInfo;
144 IDistributedSched::AccountInfo accountInfo;
145 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
146 AppExecFwk::AbilityInfo targetAbility;
147 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
148 callerInfo, accountInfo, targetAbility);
149 EXPECT_NE(ret, ERR_OK);
150 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_002 end ret:" << ret << std::endl;
151 }
152
153 /**
154 * @tc.name: CheckSendResultPermission_003
155 * @tc.desc: call CheckSendResultPermission
156 * @tc.type: FUNC
157 * @tc.require: issueI5T6GJ
158 */
159 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_003, TestSize.Level3)
160 {
161 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission begin" << std::endl;
162 AAFwk::Want want;
163 CallerInfo callerInfo;
164 IDistributedSched::AccountInfo accountInfo;
165 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
166 AppExecFwk::AbilityInfo targetAbility;
167 targetAbility.visible = true;
168 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
169 callerInfo, accountInfo, targetAbility);
170 EXPECT_EQ(ret, ERR_OK);
171 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_003 end ret:" << ret << std::endl;
172 }
173
174 /**
175 * @tc.name: CheckSendResultPermission_004
176 * @tc.desc: input invalid params
177 * @tc.type: FUNC
178 * @tc.require: issueI5T6GJ
179 */
180 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_004, TestSize.Level3)
181 {
182 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_005 begin" << std::endl;
183 AAFwk::Want want;
184 IDistributedSched::AccountInfo accountInfo;
185 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
186 AppExecFwk::AbilityInfo targetAbility;
187 targetAbility.visible = true;
188 targetAbility.permissions.push_back(INVALID_PERMISSION_NAME);
189 CallerInfo callerInfo;
190 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
191 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
192 callerInfo, accountInfo, targetAbility);
193 EXPECT_NE(ret, ERR_OK);
194 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_005 end result:" << ret << std::endl;
195 }
196
197 /**
198 * @tc.name: CheckSendResultPermission_005
199 * @tc.desc: call CheckDPermission with illegal parameter
200 * @tc.type: FUNC
201 */
202 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_005, TestSize.Level3)
203 {
204 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_005 begin" << std::endl;
205 AAFwk::Want want;
206 CallerInfo callerInfo;
207 callerInfo.accessToken = ACCESS_TOKEN;
208 IDistributedSched::AccountInfo accountInfo;
209 std::string localDeviceId = DEVICE_ID;
210 AppExecFwk::AbilityInfo targetAbility;
211 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
212 callerInfo, accountInfo, targetAbility);
213 EXPECT_NE(ret, ERR_OK);
214 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_005 end result:" << ret << std::endl;
215 }
216
217 /**
218 * @tc.name: CheckSendResultPermission_006
219 * @tc.desc: call CheckDPermission with different account type
220 * @tc.type: FUNC
221 */
222 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_006, TestSize.Level3)
223 {
224 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_006 begin" << std::endl;
225 AAFwk::Want want;
226 CallerInfo callerInfo;
227 callerInfo.accessToken = ACCESS_TOKEN;
228 IDistributedSched::AccountInfo accountInfo;
229 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
230 string localDeviceId = DEVICE_ID;
231 AppExecFwk::AbilityInfo targetAbility;
232 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
233 callerInfo, accountInfo, targetAbility);
234 EXPECT_NE(ret, ERR_OK);
235 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_006 end result:" << ret << std::endl;
236 }
237
238 /**
239 * @tc.name: CheckSendResultPermission_007
240 * @tc.desc: call CheckDPermission with illegal ability info
241 * @tc.type: FUNC
242 */
243 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_007, TestSize.Level3)
244 {
245 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_007 begin" << std::endl;
246 AAFwk::Want want;
247 CallerInfo callerInfo;
248 callerInfo.accessToken = ACCESS_TOKEN;
249 IDistributedSched::AccountInfo accountInfo;
250 string localDeviceId = DEVICE_ID;
251 AppExecFwk::AbilityInfo targetAbility;
252 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
253 callerInfo, accountInfo, targetAbility);
254 EXPECT_NE(ret, ERR_OK);
255 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_007 end result:" << ret << std::endl;
256 }
257
258 /**
259 * @tc.name: CheckSendResultPermission_008
260 * @tc.desc: call CheckDPermission with same account type
261 * @tc.type: FUNC
262 */
263 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_008, TestSize.Level3)
264 {
265 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_008 begin" << std::endl;
266 AAFwk::Want want;
267 CallerInfo callerInfo;
268 callerInfo.accessToken = ACCESS_TOKEN;
269 IDistributedSched::AccountInfo accountInfo;
270 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
271 string localDeviceId = DEVICE_ID;
272 AppExecFwk::AbilityInfo targetAbility;
273 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
274 callerInfo, accountInfo, targetAbility);
275 EXPECT_NE(ret, ERR_OK);
276 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_008 end result:" << ret << std::endl;
277 }
278
279 /**
280 * @tc.name: CheckSendResultPermission_009
281 * @tc.desc: call CheckDPermission with illegal account info
282 * @tc.type: FUNC
283 */
284 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_009, TestSize.Level3)
285 {
286 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_009 begin" << std::endl;
287 AAFwk::Want want;
288 CallerInfo callerInfo;
289 callerInfo.accessToken = ACCESS_TOKEN;
290 IDistributedSched::AccountInfo accountInfo;
291 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
292 std::string groupId = GROUP_ID;
293 accountInfo.groupIdList.push_back(groupId);
294 string localDeviceId = DEVICE_ID;
295 AppExecFwk::AbilityInfo targetAbility;
296 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
297 callerInfo, accountInfo, targetAbility);
298 EXPECT_NE(ret, ERR_OK);
299 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_009 end result:" << ret << std::endl;
300 }
301
302 /**
303 * @tc.name: CheckSendResultPermission_010
304 * @tc.desc: call CheckDPermission with illegal account info
305 * @tc.type: FUNC
306 */
307 HWTEST_F(DistributedSchedPermissionTest, CheckSendResultPermission_010, TestSize.Level3)
308 {
309 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_010 begin" << std::endl;
310 AAFwk::Want want;
311 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
312 want.SetElement(element);
313 CallerInfo callerInfo;
314 callerInfo.accessToken = ACCESS_TOKEN;
315 IDistributedSched::AccountInfo accountInfo;
316 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
317 std::string groupId = GROUP_ID;
318 accountInfo.groupIdList.push_back(groupId);
319 string localDeviceId = DEVICE_ID;
320 AppExecFwk::AbilityInfo targetAbility;
321 int32_t ret = DistributedSchedPermission::GetInstance().CheckSendResultPermission(want,
322 callerInfo, accountInfo, targetAbility);
323 EXPECT_NE(ret, ERR_OK);
324 DTEST_LOG << "DistributedSchedPermissionTest CheckSendResultPermission_010 end result:" << ret << std::endl;
325 }
326
327 /**
328 * @tc.name: CheckStartPermission_001
329 * @tc.desc: input invalid params
330 * @tc.type: FUNC
331 * @tc.require: issueI5T6GJ
332 */
333 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_001, TestSize.Level3)
334 {
335 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_001 begin" << std::endl;
336 AAFwk::Want want;
337 CallerInfo callerInfo;
338 IDistributedSched::AccountInfo accountInfo;
339 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
340 AppExecFwk::AbilityInfo targetAbility;
341 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
342 callerInfo, accountInfo, targetAbility);
343 EXPECT_NE(ret, ERR_OK);
344 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_001 end ret:" << ret << std::endl;
345 }
346
347 /**
348 * @tc.name: CheckStartPermission_002
349 * @tc.desc: input invalid params
350 * @tc.type: FUNC
351 * @tc.require: issueI5T6GJ
352 */
353 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_002, TestSize.Level3)
354 {
355 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_002 begin" << std::endl;
356 AAFwk::Want want;
357 CallerInfo callerInfo;
358 IDistributedSched::AccountInfo accountInfo;
359 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
360 AppExecFwk::AbilityInfo targetAbility;
361 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
362 callerInfo, accountInfo, targetAbility);
363 EXPECT_NE(ret, ERR_OK);
364 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_002 end ret:" << ret << std::endl;
365 }
366
367 /**
368 * @tc.name: CheckStartPermission_003
369 * @tc.desc: input invalid params
370 * @tc.type: FUNC
371 * @tc.require: issueI5T6GJ
372 */
373 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_003, TestSize.Level3)
374 {
375 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_003 begin" << std::endl;
376 AAFwk::Want want;
377 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
378 CallerInfo callerInfo;
379 IDistributedSched::AccountInfo accountInfo;
380 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
381 AppExecFwk::AbilityInfo targetAbility;
382 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
383 callerInfo, accountInfo, targetAbility);
384 EXPECT_NE(ret, ERR_OK);
385 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_003 end ret:" << ret << std::endl;
386 }
387
388 /**
389 * @tc.name: CheckStartPermission_004
390 * @tc.desc: input invalid params
391 * @tc.type: FUNC
392 * @tc.require: issueI5T6GJ
393 */
394 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_004, TestSize.Level3)
395 {
396 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_004 begin" << std::endl;
397 AAFwk::Want want;
398 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
399 CallerInfo callerInfo;
400 IDistributedSched::AccountInfo accountInfo;
401 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
402 AppExecFwk::AbilityInfo targetAbility;
403 targetAbility.visible = true;
404 targetAbility.isStageBasedModel = true;
405 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
406 callerInfo, accountInfo, targetAbility);
407 EXPECT_EQ(ret, ERR_OK);
408 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_004 end ret:" << ret << std::endl;
409 }
410
411 /**
412 * @tc.name: CheckStartPermission_005
413 * @tc.desc: input invalid params
414 * @tc.type: FUNC
415 * @tc.require: issueI5T6GJ
416 */
417 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_005, TestSize.Level3)
418 {
419 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_005 begin" << std::endl;
420 AAFwk::Want want;
421 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
422 CallerInfo callerInfo;
423 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
424 IDistributedSched::AccountInfo accountInfo;
425 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
426 AppExecFwk::AbilityInfo targetAbility;
427 targetAbility.permissions.push_back(INVALID_PERMISSION_NAME);
428 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
429 callerInfo, accountInfo, targetAbility);
430 EXPECT_NE(ret, ERR_OK);
431 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_005 end ret:" << ret << std::endl;
432 }
433
434 /**
435 * @tc.name: CheckStartPermission_006
436 * @tc.desc: input invalid params
437 * @tc.type: FUNC
438 * @tc.require: issueI5T6GJ
439 */
440 HWTEST_F(DistributedSchedPermissionTest, CheckStartPermission_006, TestSize.Level3)
441 {
442 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_006 begin" << std::endl;
443 AAFwk::Want want;
444 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
445 CallerInfo callerInfo;
446 callerInfo.accessToken = 0;
447 IDistributedSched::AccountInfo accountInfo;
448 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
449 AppExecFwk::AbilityInfo targetAbility;
450 targetAbility.visible = true;
451 targetAbility.isStageBasedModel = true;
452 int32_t ret = DistributedSchedPermission::GetInstance().CheckStartPermission(want,
453 callerInfo, accountInfo, targetAbility);
454 EXPECT_EQ(ret, ERR_OK);
455 DTEST_LOG << "DistributedSchedPermissionTest CheckStartPermission_006 end ret:" << ret << std::endl;
456 }
457
458 /**
459 * @tc.name: GetTargetAbility_001
460 * @tc.desc: input invalid params
461 * @tc.type: FUNC
462 * @tc.require: issueI5T6GJ
463 */
464 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_001, TestSize.Level3)
465 {
466 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_001 begin" << std::endl;
467 AAFwk::Want want;
468 AppExecFwk::AbilityInfo targetAbility;
469 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, false);
470 EXPECT_FALSE(ret);
471 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_001 end ret:" << ret << std::endl;
472 }
473
474 /**
475 * @tc.name: GetTargetAbility_002
476 * @tc.desc: input invalid params
477 * @tc.type: FUNC
478 * @tc.require: issueI5T6GJ
479 */
480 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_002, TestSize.Level3)
481 {
482 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_002 begin" << std::endl;
483 AAFwk::Want want;
484 ElementName name;
485 name.SetAbilityName(ABILITY_NAME);
486 name.SetBundleName(BUNDLE_NAME);
487 want.SetElement(name);
488 AppExecFwk::AbilityInfo targetAbility;
489 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, false);
490 EXPECT_FALSE(ret);
491 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_002 end ret:" << ret << std::endl;
492 }
493
494 /**
495 * @tc.name: GetTargetAbility_003
496 * @tc.desc: input invalid params
497 * @tc.type: FUNC
498 * @tc.require: issueI5T6GJ
499 */
500 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_003, TestSize.Level3)
501 {
502 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_003 begin" << std::endl;
503 AAFwk::Want want;
504 ElementName name;
505 name.SetAbilityName(ABILITY_NAME);
506 name.SetBundleName(BUNDLE_NAME);
507 want.SetElement(name);
508 want.SetParam(DMS_MISSION_ID, 0);
509 AppExecFwk::AbilityInfo targetAbility;
510 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, false);
511 EXPECT_FALSE(ret);
512 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_003 end ret:" << ret << std::endl;
513 }
514
515 /**
516 * @tc.name: GetTargetAbility_004
517 * @tc.desc: input invalid params
518 * @tc.type: FUNC
519 * @tc.require: issueI5T6GJ
520 */
521 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_004, TestSize.Level3)
522 {
523 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_004 begin" << std::endl;
524 AAFwk::Want want;
525 ElementName name;
526 name.SetAbilityName(ABILITY_NAME);
527 name.SetBundleName(BUNDLE_NAME);
528 want.SetElement(name);
529 AppExecFwk::AbilityInfo targetAbility;
530 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, true);
531 EXPECT_TRUE(ret);
532 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_004 end ret:" << ret << std::endl;
533 }
534
535 /**
536 * @tc.name: GetTargetAbility_005
537 * @tc.desc: input invalid params
538 * @tc.type: FUNC
539 * @tc.require: issueI5T6GJ
540 */
541 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_005, TestSize.Level3)
542 {
543 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_005 begin" << std::endl;
544 AAFwk::Want want;
545 ElementName name;
546 name.SetAbilityName(ABILITY_NAME);
547 name.SetBundleName(BUNDLE_NAME);
548 want.SetElement(name);
549 want.SetParam(DMS_MISSION_ID, 8);
550 AppExecFwk::AbilityInfo targetAbility;
551 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, true);
552 EXPECT_TRUE(ret);
553 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_005 end ret:" << ret << std::endl;
554 }
555
556 /**
557 * @tc.name: GetTargetAbility_006
558 * @tc.desc: input invalid params
559 * @tc.type: FUNC
560 * @tc.require: issueI5T6GJ
561 */
562 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_006, TestSize.Level3)
563 {
564 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_006 begin" << std::endl;
565 AAFwk::Want want;
566 ElementName name;
567 name.SetAbilityName(ABILITY_NAME);
568 name.SetBundleName(BUNDLE_NAME);
569 want.SetElement(name);
570 want.SetParam(DMS_MISSION_ID, 8);
571 AppExecFwk::AbilityInfo targetAbility;
572 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
573 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, true);
574 EXPECT_TRUE(ret);
575 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_006 end ret:" << ret << std::endl;
576 }
577
578 /**
579 * @tc.name: GetTargetAbility_007
580 * @tc.desc: input invalid params
581 * @tc.type: FUNC
582 * @tc.require: issueI5T6GJ
583 */
584 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_007, TestSize.Level3)
585 {
586 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_007 begin" << std::endl;
587 AAFwk::Want want;
588 ElementName name;
589 name.SetAbilityName(ABILITY_NAME);
590 name.SetBundleName(BUNDLE_NAME);
591 want.SetElement(name);
592 want.SetParam(DMS_MISSION_ID, 8);
593 AppExecFwk::AbilityInfo targetAbility;
594 targetAbility.type = AppExecFwk::AbilityType::EXTENSION;
595 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, true);
596 EXPECT_TRUE(ret);
597 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_007 end ret:" << ret << std::endl;
598 }
599
600 /**
601 * @tc.name: CheckGetCallerPermission_001
602 * @tc.desc: input invalid params
603 * @tc.type: FUNC
604 * @tc.require: issueI5T6GJ
605 */
606 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_001, TestSize.Level3)
607 {
608 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_001 begin" << std::endl;
609 AAFwk::Want want;
610 CallerInfo callerInfo;
611 IDistributedSched::AccountInfo accountInfo;
612 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
613 AppExecFwk::AbilityInfo targetAbility;
614 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
615 targetAbility);
616 EXPECT_EQ(ret, DMS_ACCOUNT_ACCESS_PERMISSION_DENIED);
617 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_001 end ret:" << ret << std::endl;
618 }
619
620 /**
621 * @tc.name: CheckGetCallerPermission_002
622 * @tc.desc: input invalid params
623 * @tc.type: FUNC
624 * @tc.require: issueI5T6GJ
625 */
626 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_002, TestSize.Level3)
627 {
628 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_002 begin" << std::endl;
629 AAFwk::Want want;
630 CallerInfo callerInfo;
631 IDistributedSched::AccountInfo accountInfo;
632 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
633 AppExecFwk::AbilityInfo targetAbility;
634 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
635 targetAbility);
636 EXPECT_EQ(ret, CALL_PERMISSION_DENIED);
637 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_002 end ret:" << ret << std::endl;
638 }
639
640 /**
641 * @tc.name: CheckGetCallerPermission_003
642 * @tc.desc: input invalid params
643 * @tc.type: FUNC
644 * @tc.require: issueI5T6GJ
645 */
646 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_003, TestSize.Level3)
647 {
648 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_003 begin" << std::endl;
649 AAFwk::Want want;
650 CallerInfo callerInfo;
651 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
652 EXPECT_EQ(result, true);
653 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
654 IDistributedSched::AccountInfo accountInfo;
655 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
656 AppExecFwk::AbilityInfo targetAbility;
657 targetAbility.bundleName = BUNDLE_NAME;
658 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
659 targetAbility);
660 EXPECT_EQ(ret, DMS_BACKGROUND_PERMISSION_DENIED);
661 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_003 end ret:" << ret << std::endl;
662 }
663
664 /**
665 * @tc.name: CheckGetCallerPermission_004
666 * @tc.desc: input invalid params
667 * @tc.type: FUNC
668 * @tc.require: issueI5T6GJ
669 */
670 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_004, TestSize.Level3)
671 {
672 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_004 begin" << std::endl;
673 AAFwk::Want want;
674 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
675 CallerInfo callerInfo;
676 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
677 EXPECT_EQ(result, true);
678 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
679 IDistributedSched::AccountInfo accountInfo;
680 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
681 AppExecFwk::AbilityInfo targetAbility;
682 targetAbility.bundleName = BUNDLE_NAME;
683 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
684 targetAbility);
685 EXPECT_EQ(ret, CALL_PERMISSION_DENIED);
686 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_004 end ret:" << ret << std::endl;
687 }
688
689 /**
690 * @tc.name: CheckGetCallerPermission_005
691 * @tc.desc: input invalid params
692 * @tc.type: FUNC
693 * @tc.require: issueI5T6GJ
694 */
695 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_005, TestSize.Level3)
696 {
697 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_005 begin" << std::endl;
698 AAFwk::Want want;
699 ElementName name;
700 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
701 CallerInfo callerInfo;
702 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
703 EXPECT_EQ(result, true);
704 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
705 IDistributedSched::AccountInfo accountInfo;
706 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
707 AppExecFwk::AbilityInfo targetAbility;
708 targetAbility.bundleName = BUNDLE_NAME;
709 targetAbility.permissions.push_back(INVALID_PERMISSION_NAME);
710 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
711 targetAbility);
712 EXPECT_EQ(ret, CALL_PERMISSION_DENIED);
713 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_005 end ret:" << ret << std::endl;
714 }
715
716 /**
717 * @tc.name: CheckStartControlPermission_001
718 * @tc.desc: input invalid params
719 * @tc.type: FUNC
720 * @tc.require: issueI5T6GJ
721 */
722 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_001, TestSize.Level3)
723 {
724 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_001 begin" << std::endl;
725 AppExecFwk::AbilityInfo targetAbility;
726 CallerInfo callerInfo;
727 AAFwk::Want want;
728 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
729 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
730 EXPECT_FALSE(ret);
731 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_001 end ret:" << ret << std::endl;
732 }
733
734 /**
735 * @tc.name: CheckStartControlPermission_002
736 * @tc.desc: input invalid params
737 * @tc.type: FUNC
738 * @tc.require: issueI5T6GJ
739 */
740 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_002, TestSize.Level3)
741 {
742 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_002 begin" << std::endl;
743 AppExecFwk::AbilityInfo targetAbility;
744 targetAbility.bundleName = BUNDLE_NAME;
745 CallerInfo callerInfo;
746 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
747 EXPECT_EQ(result, true);
748 AAFwk::Want want;
749 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
750 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
751 EXPECT_FALSE(ret);
752 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_002 end ret:" << ret << std::endl;
753 }
754
755 /**
756 * @tc.name: CheckStartControlPermission_003
757 * @tc.desc: input invalid params
758 * @tc.type: FUNC
759 * @tc.require: issueI5T6GJ
760 */
761 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_003, TestSize.Level3)
762 {
763 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_003 begin" << std::endl;
764 AppExecFwk::AbilityInfo targetAbility;
765 CallerInfo callerInfo;
766 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
767 EXPECT_EQ(result, true);
768 AAFwk::Want want;
769 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
770 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
771 EXPECT_FALSE(ret);
772 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_003 end ret:" << ret << std::endl;
773 }
774
775 /**
776 * @tc.name: CheckStartControlPermission_004
777 * @tc.desc: input invalid params
778 * @tc.type: FUNC
779 * @tc.require: issueI5T6GJ
780 */
781 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_004, TestSize.Level3)
782 {
783 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_004 begin" << std::endl;
784 AppExecFwk::AbilityInfo targetAbility;
785 CallerInfo callerInfo;
786 AAFwk::Want want;
787 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
788 EXPECT_FALSE(ret);
789 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_004 end ret:" << ret << std::endl;
790 }
791
792 /**
793 * @tc.name: CheckStartControlPermission_005
794 * @tc.desc: input invalid params
795 * @tc.type: FUNC
796 * @tc.require: issueI5T6GJ
797 */
798 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_005, TestSize.Level3)
799 {
800 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_005 begin" << std::endl;
801 AppExecFwk::AbilityInfo targetAbility;
802 CallerInfo callerInfo;
803 AAFwk::Want want;
804 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
805 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
806 EXPECT_FALSE(ret);
807 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_005 end ret:" << ret << std::endl;
808 }
809
810 /**
811 * @tc.name: CheckStartControlPermission_006
812 * @tc.desc: input invalid params
813 * @tc.type: FUNC
814 * @tc.require: issueI5T6GJ
815 */
816 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_006, TestSize.Level3)
817 {
818 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_006 begin" << std::endl;
819 AppExecFwk::AbilityInfo targetAbility;
820 targetAbility.bundleName = BUNDLE_NAME;
821 CallerInfo callerInfo;
822 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
823 EXPECT_EQ(result, true);
824 AAFwk::Want want;
825 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
826 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
827 EXPECT_FALSE(ret);
828 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_006 end ret:" << ret << std::endl;
829 }
830
831 /**
832 * @tc.name: CheckStartControlPermission_007
833 * @tc.desc: input invalid params
834 * @tc.type: FUNC
835 * @tc.require: issueI5T6GJ
836 */
837 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_007, TestSize.Level3)
838 {
839 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_007 begin" << std::endl;
840 AppExecFwk::AbilityInfo targetAbility;
841 CallerInfo callerInfo;
842 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
843 EXPECT_EQ(result, true);
844 AAFwk::Want want;
845 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
846 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
847 EXPECT_FALSE(ret);
848 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_007 end ret:" << ret << std::endl;
849 }
850
851 /**
852 * @tc.name: CheckStartControlPermission_008
853 * @tc.desc: input invalid params
854 * @tc.type: FUNC
855 * @tc.require: issueI5T6GJ
856 */
857 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_008, TestSize.Level3)
858 {
859 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_008 begin" << std::endl;
860 AppExecFwk::AbilityInfo targetAbility;
861 targetAbility.visible = true;
862 targetAbility.isStageBasedModel = true;
863 CallerInfo callerInfo;
864 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
865 EXPECT_EQ(result, true);
866 AAFwk::Want want;
867 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
868 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
869 EXPECT_TRUE(ret);
870 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_008 end ret:" << ret << std::endl;
871 }
872
873 /**
874 * @tc.name: CheckStartControlPermission_009
875 * @tc.desc: input invalid params
876 * @tc.type: FUNC
877 * @tc.require: issueI5T6GJ
878 */
879 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_009, TestSize.Level3)
880 {
881 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_009 begin" << std::endl;
882 AppExecFwk::AbilityInfo targetAbility;
883 targetAbility.visible = true;
884 targetAbility.type = AppExecFwk::AbilityType::PAGE;
885 CallerInfo callerInfo;
886 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
887 EXPECT_EQ(result, true);
888 AAFwk::Want want;
889 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
890 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
891 EXPECT_TRUE(ret);
892 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_009 end ret:" << ret << std::endl;
893 }
894
895 /**
896 * @tc.name: CheckStartControlPermission_010
897 * @tc.desc: input invalid params
898 * @tc.type: FUNC
899 * @tc.require: issueI5T6GJ
900 */
901 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_010, TestSize.Level3)
902 {
903 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_010 begin" << std::endl;
904 AppExecFwk::AbilityInfo targetAbility;
905 targetAbility.visible = true;
906 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
907 CallerInfo callerInfo;
908 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
909 EXPECT_EQ(result, true);
910 AAFwk::Want want;
911 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
912 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
913 EXPECT_FALSE(ret);
914 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_010 end ret:" << ret << std::endl;
915 }
916
917 /**
918 * @tc.name: CheckStartControlPermission_011
919 * @tc.desc: input invalid params
920 * @tc.type: FUNC
921 * @tc.require: issueI5T6GJ
922 */
923 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_011, TestSize.Level3)
924 {
925 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_011 begin" << std::endl;
926 AppExecFwk::AbilityInfo targetAbility;
927 targetAbility.visible = true;
928 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
929 targetAbility.applicationInfo.associatedWakeUp = true;
930 CallerInfo callerInfo;
931 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
932 EXPECT_EQ(result, true);
933 AAFwk::Want want;
934 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
935 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
936 EXPECT_TRUE(ret);
937 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_011 end ret:" << ret << std::endl;
938 }
939
940 /**
941 * @tc.name: CheckStartControlPermission_012
942 * @tc.desc: input invalid params
943 * @tc.type: FUNC
944 * @tc.require: issueI5T6GJ
945 */
946 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_012, TestSize.Level3)
947 {
948 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_012 begin" << std::endl;
949 AppExecFwk::AbilityInfo targetAbility;
950 targetAbility.visible = true;
951 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
952 targetAbility.applicationInfo.associatedWakeUp = true;
953 targetAbility.bundleName = BUNDLE_NAME;
954 CallerInfo callerInfo;
955 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
956 EXPECT_EQ(result, true);
957 AAFwk::Want want;
958 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
959 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
960 EXPECT_TRUE(ret);
961 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_012 end ret:" << ret << std::endl;
962 }
963
964 /**
965 * @tc.name: CheckStartControlPermission_013
966 * @tc.desc: input invalid params
967 * @tc.type: FUNC
968 * @tc.require: issueI5T6GJ
969 */
970 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_013, TestSize.Level3)
971 {
972 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_013 begin" << std::endl;
973 AppExecFwk::AbilityInfo targetAbility;
974 targetAbility.visible = true;
975 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
976 targetAbility.applicationInfo.associatedWakeUp = true;
977 CallerInfo callerInfo;
978 AAFwk::Want want;
979 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
980 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
981 EXPECT_FALSE(ret);
982 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_013 end ret:" << ret << std::endl;
983 }
984
985 /**
986 * @tc.name: CheckStartControlPermission_014
987 * @tc.desc: input invalid params
988 * @tc.type: FUNC
989 * @tc.require: issueI5T6GJ
990 */
991 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_014, TestSize.Level3)
992 {
993 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_014 begin" << std::endl;
994 AppExecFwk::AbilityInfo targetAbility;
995 targetAbility.visible = true;
996 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
997 targetAbility.applicationInfo.associatedWakeUp = true;
998 CallerInfo callerInfo;
999 AAFwk::Want want;
1000 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
1001 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
1002 EXPECT_FALSE(ret);
1003 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_014 end ret:" << ret << std::endl;
1004 }
1005
1006 /**
1007 * @tc.name: CheckBackgroundPermission_001
1008 * @tc.desc: input invalid params
1009 * @tc.type: FUNC
1010 * @tc.require: issueI5T6GJ
1011 */
1012 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_001, TestSize.Level3)
1013 {
1014 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_001 begin" << std::endl;
1015 AppExecFwk::AbilityInfo targetAbility;
1016 CallerInfo callerInfo;
1017 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1018 AAFwk::Want want;
1019 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
1020 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
1021 false);
1022 EXPECT_TRUE(ret);
1023 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_001 end ret:" << ret << std::endl;
1024 }
1025
1026 /**
1027 * @tc.name: CheckBackgroundPermission_002
1028 * @tc.desc: input invalid params
1029 * @tc.type: FUNC
1030 * @tc.require: issueI5T6GJ
1031 */
1032 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_002, TestSize.Level3)
1033 {
1034 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_002 begin" << std::endl;
1035 AppExecFwk::AbilityInfo targetAbility;
1036 CallerInfo callerInfo;
1037 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1038 AAFwk::Want want;
1039 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
1040 false);
1041 EXPECT_FALSE(ret);
1042 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_002 end ret:" << ret << std::endl;
1043 }
1044
1045 /**
1046 * @tc.name: CheckBackgroundPermission_003
1047 * @tc.desc: input invalid params
1048 * @tc.type: FUNC
1049 * @tc.require: issueI5T6GJ
1050 */
1051 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_003, TestSize.Level3)
1052 {
1053 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_003 begin" << std::endl;
1054 AppExecFwk::AbilityInfo targetAbility;
1055 targetAbility.isStageBasedModel = true;
1056 CallerInfo callerInfo;
1057 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1058 AAFwk::Want want;
1059 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
1060 true);
1061 EXPECT_FALSE(ret);
1062 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_003 end ret:" << ret << std::endl;
1063 }
1064
1065 /**
1066 * @tc.name: CheckBackgroundPermission_004
1067 * @tc.desc: input invalid params
1068 * @tc.type: FUNC
1069 * @tc.require: issueI5T6GJ
1070 */
1071 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_004, TestSize.Level3)
1072 {
1073 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_004 begin" << std::endl;
1074 AppExecFwk::AbilityInfo targetAbility;
1075 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
1076 CallerInfo callerInfo;
1077 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1078 AAFwk::Want want;
1079 want.SetParam(DMS_API_VERSION, FA_MODULE_ALLOW_MIN_API_VERSION);
1080 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
1081 true);
1082 EXPECT_TRUE(ret);
1083 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_004 end ret:" << ret << std::endl;
1084 }
1085
1086 /**
1087 * @tc.name: CheckBackgroundPermission_005
1088 * @tc.desc: input invalid params
1089 * @tc.type: FUNC
1090 * @tc.require: issueI5T6GJ
1091 */
1092 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_005, TestSize.Level3)
1093 {
1094 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_005 begin" << std::endl;
1095 AppExecFwk::AbilityInfo targetAbility;
1096 CallerInfo callerInfo;
1097 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1098 callerInfo.sourceDeviceId = "";
1099 callerInfo.accessToken = GetSelfTokenID();
1100 AAFwk::Want want;
1101 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
1102 false);
1103 EXPECT_FALSE(ret);
1104 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_005 end ret:" << ret << std::endl;
1105 }
1106
1107 /**
1108 * @tc.name: CheckBackgroundPermission_006
1109 * @tc.desc: input invalid params
1110 * @tc.type: FUNC
1111 * @tc.require: issueI5T6GJ
1112 */
1113 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_006, TestSize.Level3)
1114 {
1115 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_006 begin" << std::endl;
1116 AppExecFwk::AbilityInfo targetAbility;
1117 CallerInfo callerInfo;
1118 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1119 callerInfo.sourceDeviceId = deviceId_;
1120 uint64_t tokenId = GetSelfTokenID();
1121 callerInfo.accessToken = tokenId;
1122 AAFwk::Want want;
1123 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
1124 false);
1125 EXPECT_FALSE(ret);
1126 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_006 end ret:" << ret << std::endl;
1127 }
1128
1129 /**
1130 * @tc.name: CheckBackgroundPermission_007
1131 * @tc.desc: check CheckTargetAbilityVisible
1132 * @tc.type: FUNC
1133 * @tc.require: issueI5T6GJ
1134 */
1135 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_007, TestSize.Level3)
1136 {
1137 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_007 begin" << std::endl;
1138 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
1139 std::string deviceId = udid;
1140 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
1141 HapTokenInfo baseInfo = {
1142 .apl = APL_NORMAL,
1143 .ver = 1,
1144 .userID = 1,
1145 .bundleName = "com.ohos.dms_test",
1146 .instIndex = 1,
1147 .appID = "dmstest",
1148 .deviceID = udid,
1149 .tokenID = 0x20100000,
1150 .tokenAttr = 0
1151 };
1152
1153 PermissionStateFull infoManagerTestState = {
1154 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
1155 .isGeneral = true,
1156 .resDeviceID = {"local"},
1157 .grantStatus = {PermissionState::PERMISSION_GRANTED}, // first grant
1158 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
1159 std::vector<PermissionStateFull> permStateList;
1160 permStateList.emplace_back(infoManagerTestState);
1161
1162 HapTokenInfoForSync remoteTokenInfo = {
1163 .baseInfo = baseInfo,
1164 .permStateList = permStateList
1165 };
1166
1167 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1168 ASSERT_EQ(result, RET_SUCCESS);
1169
1170 // Get local map token ID
1171 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1172 ASSERT_NE(mapID, 0);
1173
1174 AppExecFwk::AbilityInfo targetAbility;
1175 CallerInfo callerInfo;
1176 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
1177 callerInfo.sourceDeviceId = deviceId_;
1178 callerInfo.accessToken = 0x20100000;
1179 AAFwk::Want want;
1180 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
1181 false);
1182 EXPECT_FALSE(ret);
1183 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_007 end ret:" << ret << std::endl;
1184 }
1185
1186 /**
1187 * @tc.name: CheckMinApiVersion_001
1188 * @tc.desc: input invalid params
1189 * @tc.type: FUNC
1190 * @tc.require: issueI5T6GJ
1191 */
1192 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_001, TestSize.Level3)
1193 {
1194 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 begin" << std::endl;
1195 AppExecFwk::AbilityInfo targetAbility;
1196 targetAbility.isStageBasedModel = true;
1197 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
1198 EXPECT_FALSE(ret);
1199 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 end ret:" << ret << std::endl;
1200 }
1201
1202 /**
1203 * @tc.name: CheckMinApiVersion_002
1204 * @tc.desc: input invalid params
1205 * @tc.type: FUNC
1206 * @tc.require: issueI5T6GJ
1207 */
1208 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_002, TestSize.Level3)
1209 {
1210 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 begin" << std::endl;
1211 AppExecFwk::AbilityInfo targetAbility;
1212 targetAbility.type = AppExecFwk::AbilityType::PAGE;
1213 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
1214 EXPECT_FALSE(ret);
1215 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 end ret:" << ret << std::endl;
1216 }
1217
1218 /**
1219 * @tc.name: CheckMinApiVersion_003
1220 * @tc.desc: input invalid params
1221 * @tc.type: FUNC
1222 * @tc.require: issueI5T6GJ
1223 */
1224 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_003, TestSize.Level3)
1225 {
1226 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 begin" << std::endl;
1227 AppExecFwk::AbilityInfo targetAbility;
1228 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
1229 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
1230 EXPECT_FALSE(ret);
1231 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 end ret:" << ret << std::endl;
1232 }
1233
1234 /**
1235 * @tc.name: CheckMinApiVersion_004
1236 * @tc.desc: input invalid params
1237 * @tc.type: FUNC
1238 * @tc.require: issueI5T6GJ
1239 */
1240 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_004, TestSize.Level3)
1241 {
1242 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 begin" << std::endl;
1243 AppExecFwk::AbilityInfo targetAbility;
1244 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
1245 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility,
1246 FA_MODULE_ALLOW_MIN_API_VERSION);
1247 EXPECT_TRUE(ret);
1248 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 end ret:" << ret << std::endl;
1249 }
1250
1251 /**
1252 * @tc.name: CheckTargetAbilityVisible_001
1253 * @tc.desc: input invalid params
1254 * @tc.type: FUNC
1255 * @tc.require: issueI5T6GJ
1256 */
1257 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_001, TestSize.Level3)
1258 {
1259 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 begin" << std::endl;
1260 AppExecFwk::AbilityInfo targetAbility;
1261 targetAbility.visible = true;
1262 CallerInfo callerInfo;
1263 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1264 EXPECT_TRUE(ret);
1265 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 end ret:" << ret << std::endl;
1266 }
1267
1268 /**
1269 * @tc.name: CheckTargetAbilityVisible_002
1270 * @tc.desc: input invalid params
1271 * @tc.type: FUNC
1272 * @tc.require: issueI5T6GJ
1273 */
1274 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_002, TestSize.Level3)
1275 {
1276 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 begin" << std::endl;
1277 AppExecFwk::AbilityInfo targetAbility;
1278 CallerInfo callerInfo;
1279 callerInfo.sourceDeviceId = "";
1280 callerInfo.accessToken = GetSelfTokenID();
1281 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1282 EXPECT_FALSE(ret);
1283 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 end ret:" << ret << std::endl;
1284 }
1285
1286 /**
1287 * @tc.name: CheckTargetAbilityVisible_003
1288 * @tc.desc: input invalid params
1289 * @tc.type: FUNC
1290 * @tc.require: issueI5T6GJ
1291 */
1292 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_003, TestSize.Level3)
1293 {
1294 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 begin" << std::endl;
1295 AppExecFwk::AbilityInfo targetAbility;
1296 CallerInfo callerInfo;
1297 callerInfo.sourceDeviceId = "deviceId_";
1298 callerInfo.accessToken = GetSelfTokenID();
1299 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1300 EXPECT_FALSE(ret);
1301 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 end ret:" << ret << std::endl;
1302 }
1303
1304 #ifdef TOKEN_SYNC_ENABLE
1305 /**
1306 * @tc.name: CheckTargetAbilityVisible_004
1307 * @tc.desc: check CheckTargetAbilityVisible
1308 * @tc.type: FUNC
1309 * @tc.require: issueI5T6GJ
1310 */
1311 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_004, TestSize.Level3)
1312 {
1313 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 begin" << std::endl;
1314 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
1315 std::string deviceId = udid;
1316 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
1317 HapTokenInfo baseInfo = {
1318 .apl = APL_NORMAL,
1319 .ver = 1,
1320 .userID = 1,
1321 .bundleName = "com.ohos.dms_test",
1322 .instIndex = 1,
1323 .appID = "dmstest",
1324 .deviceID = udid,
1325 .tokenID = 0x20100000,
1326 .tokenAttr = 0
1327 };
1328
1329 PermissionStateFull infoManagerTestState = {
1330 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
1331 .isGeneral = true,
1332 .resDeviceID = {"local"},
1333 .grantStatus = {PermissionState::PERMISSION_GRANTED}, // first grant
1334 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
1335 std::vector<PermissionStateFull> permStateList;
1336 permStateList.emplace_back(infoManagerTestState);
1337
1338 HapTokenInfoForSync remoteTokenInfo = {
1339 .baseInfo = baseInfo,
1340 .permStateList = permStateList
1341 };
1342
1343 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1344 ASSERT_EQ(result, RET_SUCCESS);
1345
1346 // Get local map token ID
1347 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1348 ASSERT_NE(mapID, 0);
1349
1350 AppExecFwk::AbilityInfo targetAbility;
1351 CallerInfo callerInfo;
1352 callerInfo.sourceDeviceId = deviceId_;
1353 callerInfo.accessToken = 0x20100000;
1354 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1355 EXPECT_TRUE(ret);
1356 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 end ret:" << ret << std::endl;
1357 }
1358
1359 /**
1360 * @tc.name: CheckTargetAbilityVisible_005
1361 * @tc.desc: check CheckTargetAbilityVisible
1362 * @tc.type: FUNC
1363 * @tc.require: issueI5T6GJ
1364 */
1365 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_005, TestSize.Level3)
1366 {
1367 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 begin" << std::endl;
1368 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
1369 std::string deviceId = udid;
1370 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
1371 HapTokenInfo baseInfo = {
1372 .apl = APL_NORMAL,
1373 .ver = 1,
1374 .userID = 1,
1375 .bundleName = "com.ohos.dms_test",
1376 .instIndex = 1,
1377 .appID = "dmstest",
1378 .deviceID = udid,
1379 .tokenID = 0x20100000,
1380 .tokenAttr = 0
1381 };
1382
1383 PermissionStateFull infoManagerTestState = {
1384 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
1385 .isGeneral = true,
1386 .resDeviceID = {"local"},
1387 .grantStatus = {PermissionState::PERMISSION_DENIED},
1388 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
1389 std::vector<PermissionStateFull> permStateList;
1390 permStateList.emplace_back(infoManagerTestState);
1391
1392 HapTokenInfoForSync remoteTokenInfo = {
1393 .baseInfo = baseInfo,
1394 .permStateList = permStateList
1395 };
1396
1397 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1398 ASSERT_EQ(result, RET_SUCCESS);
1399
1400 // Get local map token ID
1401 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1402 ASSERT_NE(mapID, 0);
1403
1404 AppExecFwk::AbilityInfo targetAbility;
1405 CallerInfo callerInfo;
1406 callerInfo.sourceDeviceId = deviceId_;
1407 callerInfo.accessToken = 0x20100000;
1408 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1409 EXPECT_FALSE(ret);
1410 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 end ret:" << ret << std::endl;
1411 }
1412 #endif
1413
1414 /**
1415 * @tc.name: GetAccountInfo_001
1416 * @tc.desc: call GetAccountInfo with empty networkId
1417 * @tc.type: FUNC
1418 * @tc.require: I5RWIV
1419 */
1420 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_001, TestSize.Level3)
1421 {
1422 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 begin" << std::endl;
1423 std::string remoteNetworkId;
1424 CallerInfo callerInfo;
1425 IDistributedSched::AccountInfo accountInfo;
1426 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1427 remoteNetworkId, callerInfo, accountInfo);
1428 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1429 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 end result:" << ret << std::endl;
1430 }
1431
1432 /**
1433 * @tc.name: GetAccountInfo_002
1434 * @tc.desc: call GetAccountInfo with invalid networkId
1435 * @tc.type: FUNC
1436 * @tc.require: I5RWIV
1437 */
1438 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_002, TestSize.Level3)
1439 {
1440 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 begin" << std::endl;
1441 std::string remoteNetworkId = "0";
1442 CallerInfo callerInfo;
1443 IDistributedSched::AccountInfo accountInfo;
1444 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1445 remoteNetworkId, callerInfo, accountInfo);
1446 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1447 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 end result:" << ret << std::endl;
1448 }
1449
1450 /**
1451 * @tc.name: GetRelatedGroups_001
1452 * @tc.desc: call GetRelatedGroups with empty bundleNames
1453 * @tc.type: FUNC
1454 * @tc.require: I5RWIV
1455 */
1456 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_001, TestSize.Level3)
1457 {
1458 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 begin" << std::endl;
1459 std::string udid;
1460 std::vector<std::string> bundleNames;
1461 IDistributedSched::AccountInfo accountInfo;
1462 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1463 udid, bundleNames, accountInfo);
1464 EXPECT_EQ(ret, false);
1465 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1466 }
1467
1468 /**
1469 * @tc.name: GetRelatedGroups_002
1470 * @tc.desc: call GetRelatedGroups with invalid bundleNames
1471 * @tc.type: FUNC
1472 * @tc.require: I5RWIV
1473 */
1474 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_002, TestSize.Level3)
1475 {
1476 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 begin" << std::endl;
1477 std::string udid = "0";
1478 std::vector<std::string> bundleNames = {"mock.bundle1", "mock.bundle2"};
1479 IDistributedSched::AccountInfo accountInfo;
1480 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1481 udid, bundleNames, accountInfo);
1482 EXPECT_EQ(ret, false);
1483 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1484 }
1485
1486 /**
1487 * @tc.name: ParseGroupInfos_001
1488 * @tc.desc: call ParseGroupInfos with empty returnGroupStr
1489 * @tc.type: FUNC
1490 * @tc.require: I5RWIV
1491 */
1492 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_001, TestSize.Level3)
1493 {
1494 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_001 begin" << std::endl;
1495 std::string returnGroupStr;
1496 std::vector<GroupInfo> groupInfos;
1497 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1498 returnGroupStr, groupInfos);
1499 EXPECT_EQ(ret, false);
1500 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1501 }
1502
1503 /**
1504 * @tc.name: ParseGroupInfos_002
1505 * @tc.desc: call ParseGroupInfos with invalid returnGroupStr
1506 * @tc.type: FUNC
1507 * @tc.require: I5RWIV
1508 */
1509 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_002, TestSize.Level3)
1510 {
1511 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_002 begin" << std::endl;
1512 std::string returnGroupStr = "mockInvalidGroup";
1513 std::vector<GroupInfo> groupInfos;
1514 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1515 returnGroupStr, groupInfos);
1516 EXPECT_EQ(ret, false);
1517 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1518 }
1519
1520 /**
1521 * @tc.name: ParseGroupInfos_003
1522 * @tc.desc: call ParseGroupInfos
1523 * @tc.type: FUNC
1524 * @tc.require: I5RWIV
1525 */
1526 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_003, TestSize.Level3)
1527 {
1528 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_003 begin" << std::endl;
1529 std::string returnGroupStr = "[{\"groupName\":\"mockGroupName\",\"groupId\":\"mockGroupId\",";
1530 returnGroupStr += "\"groupOwner\":\"mockGroupOwner\",\"groupType\":0,\"groupVisibility\":0}]";
1531 std::vector<GroupInfo> groupInfos;
1532 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1533 returnGroupStr, groupInfos);
1534 EXPECT_EQ(ret, true);
1535 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_003 end result:" << ret << std::endl;
1536 }
1537
1538 /**
1539 * @tc.name: IsFoundationCall_001
1540 * @tc.desc: call IsFoundationCall not from foundation
1541 * @tc.type: FUNC
1542 * @tc.require: I5RWIV
1543 */
1544 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_001, TestSize.Level3)
1545 {
1546 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 begin" << std::endl;
1547 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1548 EXPECT_EQ(ret, false);
1549 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 end result:" << ret << std::endl;
1550 }
1551
1552 /**
1553 * @tc.name: IsFoundationCall_002
1554 * @tc.desc: call IsFoundationCall from foundation
1555 * @tc.type: FUNC
1556 * @tc.require: I5RWIV
1557 */
1558 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_002, TestSize.Level3)
1559 {
1560 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 begin" << std::endl;
1561 DistributedSchedUtil::MockProcess(FOUNDATION_PROCESS_NAME);
1562 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1563 EXPECT_EQ(ret, true);
1564 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 end result:" << ret << std::endl;
1565 }
1566
1567 /**
1568 * @tc.name: CheckAccountAccessPermission_001
1569 * @tc.desc: call CheckAccountAccessPermission in same account
1570 * @tc.type: FUNC
1571 */
1572 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_001, TestSize.Level1)
1573 {
1574 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 begin" << std::endl;
1575 CallerInfo callerInfo;
1576 callerInfo.accessToken = ACCESS_TOKEN;
1577 IDistributedSched::AccountInfo accountInfo;
1578 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1579 std::string groupId = GROUP_ID;
1580 accountInfo.groupIdList.push_back(groupId);
1581 string targetBundle = BUNDLE_NAME;
1582 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1583 callerInfo, accountInfo, targetBundle);
1584 EXPECT_EQ(ret, true);
1585 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 end result:" << ret << std::endl;
1586 }
1587
1588 /**
1589 * @tc.name: CheckAccountAccessPermission_002
1590 * @tc.desc: call CheckAccountAccessPermission with invalid accessToken in same account
1591 * @tc.type: FUNC
1592 */
1593 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_002, TestSize.Level1)
1594 {
1595 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_002 begin" << std::endl;
1596 CallerInfo callerInfo;
1597 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1598 IDistributedSched::AccountInfo accountInfo;
1599 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1600 std::string groupId = GROUP_ID;
1601 accountInfo.groupIdList.push_back(groupId);
1602 string targetBundle = BUNDLE_NAME;
1603 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1604 callerInfo, accountInfo, targetBundle);
1605 EXPECT_EQ(ret, true);
1606 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_002 end result:" << ret << std::endl;
1607 }
1608
1609 /**
1610 * @tc.name: CheckAccountAccessPermission_003
1611 * @tc.desc: call CheckAccountAccessPermission with invalid groupId in same account
1612 * @tc.type: FUNC
1613 */
1614 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_003, TestSize.Level1)
1615 {
1616 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_003 begin" << std::endl;
1617 CallerInfo callerInfo;
1618 callerInfo.accessToken = ACCESS_TOKEN;
1619 IDistributedSched::AccountInfo accountInfo;
1620 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1621 std::string groupId = INVALID_GROUP_ID;
1622 accountInfo.groupIdList.push_back(groupId);
1623 string targetBundle = BUNDLE_NAME;
1624 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1625 callerInfo, accountInfo, targetBundle);
1626 EXPECT_EQ(ret, true);
1627 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_003 end result:" << ret << std::endl;
1628 }
1629
1630 /**
1631 * @tc.name: CheckAccountAccessPermission_004
1632 * @tc.desc: call CheckAccountAccessPermission with invalid bundleName in same account
1633 * @tc.type: FUNC
1634 */
1635 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_004, TestSize.Level1)
1636 {
1637 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_004 begin" << std::endl;
1638 CallerInfo callerInfo;
1639 callerInfo.accessToken = ACCESS_TOKEN;
1640 IDistributedSched::AccountInfo accountInfo;
1641 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1642 std::string groupId = GROUP_ID;
1643 accountInfo.groupIdList.push_back(groupId);
1644 string targetBundle = INVALID_BUNDLE_NAME;
1645 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1646 callerInfo, accountInfo, targetBundle);
1647 EXPECT_EQ(ret, true);
1648 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_004 end result:" << ret << std::endl;
1649 }
1650
1651 /**
1652 * @tc.name: CheckAccountAccessPermission_005
1653 * @tc.desc: call CheckAccountAccessPermission in diff account
1654 * @tc.type: FUNC
1655 */
1656 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_005, TestSize.Level1)
1657 {
1658 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_005 begin" << std::endl;
1659 CallerInfo callerInfo;
1660 callerInfo.accessToken = ACCESS_TOKEN;
1661 IDistributedSched::AccountInfo accountInfo;
1662 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1663 std::string groupId = GROUP_ID;
1664 accountInfo.groupIdList.push_back(groupId);
1665 string targetBundle = BUNDLE_NAME;
1666 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1667 callerInfo, accountInfo, targetBundle);
1668 EXPECT_EQ(ret, false);
1669 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_005 end result:" << ret << std::endl;
1670 }
1671
1672 /**
1673 * @tc.name: CheckAccountAccessPermission_006
1674 * @tc.desc: call CheckAccountAccessPermission with invalid accessToken in diff account
1675 * @tc.type: FUNC
1676 */
1677 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_006, TestSize.Level1)
1678 {
1679 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_006 begin" << std::endl;
1680 CallerInfo callerInfo;
1681 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1682 IDistributedSched::AccountInfo accountInfo;
1683 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1684 std::string groupId = GROUP_ID;
1685 accountInfo.groupIdList.push_back(groupId);
1686 string targetBundle = BUNDLE_NAME;
1687 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1688 callerInfo, accountInfo, targetBundle);
1689 EXPECT_EQ(ret, false);
1690 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_006 end result:" << ret << std::endl;
1691 }
1692
1693 /**
1694 * @tc.name: CheckAccountAccessPermission_007
1695 * @tc.desc: call CheckAccountAccessPermission with invalid groupId in diff account
1696 * @tc.type: FUNC
1697 */
1698 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_007, TestSize.Level1)
1699 {
1700 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_007 begin" << std::endl;
1701 CallerInfo callerInfo;
1702 callerInfo.accessToken = ACCESS_TOKEN;
1703 IDistributedSched::AccountInfo accountInfo;
1704 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1705 std::string groupId = INVALID_GROUP_ID;
1706 accountInfo.groupIdList.push_back(groupId);
1707 string targetBundle = BUNDLE_NAME;
1708 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1709 callerInfo, accountInfo, targetBundle);
1710 EXPECT_EQ(ret, false);
1711 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_007 end result:" << ret << std::endl;
1712 }
1713
1714 /**
1715 * @tc.name: CheckAccountAccessPermission_008
1716 * @tc.desc: call CheckAccountAccessPermission with invalid bundleName in diff account
1717 * @tc.type: FUNC
1718 */
1719 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_008, TestSize.Level1)
1720 {
1721 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_008 begin" << std::endl;
1722 CallerInfo callerInfo;
1723 callerInfo.accessToken = ACCESS_TOKEN;
1724 IDistributedSched::AccountInfo accountInfo;
1725 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1726 std::string groupId = GROUP_ID;
1727 accountInfo.groupIdList.push_back(groupId);
1728 string targetBundle = INVALID_BUNDLE_NAME;
1729 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1730 callerInfo, accountInfo, targetBundle);
1731 EXPECT_EQ(ret, false);
1732 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_008 end result:" << ret << std::endl;
1733 }
1734
1735 /**
1736 * @tc.name: CheckComponentAccessPermission_001
1737 * @tc.desc: call CheckComponentAccessPermission in same account
1738 * @tc.type: FUNC
1739 */
1740 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_001, TestSize.Level1)
1741 {
1742 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 begin" << std::endl;
1743 AppExecFwk::AbilityInfo targetAbility;
1744 CallerInfo callerInfo;
1745 callerInfo.accessToken = ACCESS_TOKEN;
1746 IDistributedSched::AccountInfo accountInfo;
1747 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1748 std::string groupId = GROUP_ID;
1749 accountInfo.groupIdList.push_back(groupId);
1750 AAFwk::Want want;
1751 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1752 want.SetElement(element);
1753 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1754 callerInfo, accountInfo, want);
1755 EXPECT_EQ(ret, false);
1756 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 end result:" << ret << std::endl;
1757 }
1758
1759 /**
1760 * @tc.name: CheckComponentAccessPermission_002
1761 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in same account
1762 * @tc.type: FUNC
1763 */
1764 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_002, TestSize.Level1)
1765 {
1766 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 begin" << std::endl;
1767 AppExecFwk::AbilityInfo targetAbility;
1768 CallerInfo callerInfo;
1769 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1770 IDistributedSched::AccountInfo accountInfo;
1771 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1772 std::string groupId = GROUP_ID;
1773 accountInfo.groupIdList.push_back(groupId);
1774 AAFwk::Want want;
1775 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1776 want.SetElement(element);
1777 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1778 callerInfo, accountInfo, want);
1779 EXPECT_EQ(ret, false);
1780 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 end result:" << ret << std::endl;
1781 }
1782
1783 /**
1784 * @tc.name: CheckComponentAccessPermission_003
1785 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in same account
1786 * @tc.type: FUNC
1787 */
1788 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_003, TestSize.Level1)
1789 {
1790 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 begin" << std::endl;
1791 AppExecFwk::AbilityInfo targetAbility;
1792 CallerInfo callerInfo;
1793 callerInfo.accessToken = ACCESS_TOKEN;
1794 IDistributedSched::AccountInfo accountInfo;
1795 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1796 std::string groupId = INVALID_GROUP_ID;
1797 accountInfo.groupIdList.push_back(groupId);
1798 AAFwk::Want want;
1799 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1800 want.SetElement(element);
1801 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1802 callerInfo, accountInfo, want);
1803 EXPECT_EQ(ret, false);
1804 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 end result:" << ret << std::endl;
1805 }
1806
1807 /**
1808 * @tc.name: CheckComponentAccessPermission_004
1809 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in same account
1810 * @tc.type: FUNC
1811 */
1812 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_004, TestSize.Level1)
1813 {
1814 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 begin" << std::endl;
1815 AppExecFwk::AbilityInfo targetAbility;
1816 CallerInfo callerInfo;
1817 callerInfo.accessToken = ACCESS_TOKEN;
1818 IDistributedSched::AccountInfo accountInfo;
1819 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1820 std::string groupId = GROUP_ID;
1821 accountInfo.groupIdList.push_back(groupId);
1822 AAFwk::Want want;
1823 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1824 want.SetElement(element);
1825 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1826 callerInfo, accountInfo, want);
1827 EXPECT_EQ(ret, false);
1828 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 end result:" << ret << std::endl;
1829 }
1830
1831 /**
1832 * @tc.name: CheckComponentAccessPermission_005
1833 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in same account
1834 * @tc.type: FUNC
1835 */
1836 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_005, TestSize.Level1)
1837 {
1838 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 begin" << std::endl;
1839 AppExecFwk::AbilityInfo targetAbility;
1840 CallerInfo callerInfo;
1841 callerInfo.accessToken = ACCESS_TOKEN;
1842 IDistributedSched::AccountInfo accountInfo;
1843 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1844 std::string groupId = GROUP_ID;
1845 accountInfo.groupIdList.push_back(groupId);
1846 AAFwk::Want want;
1847 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1848 want.SetElement(element);
1849 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1850 callerInfo, accountInfo, want);
1851 EXPECT_EQ(ret, false);
1852 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 end result:" << ret << std::endl;
1853 }
1854
1855 /**
1856 * @tc.name: CheckComponentAccessPermission_006
1857 * @tc.desc: call CheckComponentAccessPermission with visible: true in same account
1858 * @tc.type: FUNC
1859 */
1860 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_006, TestSize.Level1)
1861 {
1862 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 begin" << std::endl;
1863 AppExecFwk::AbilityInfo targetAbility;
1864 targetAbility.visible = true;
1865 CallerInfo callerInfo;
1866 callerInfo.accessToken = ACCESS_TOKEN;
1867 IDistributedSched::AccountInfo accountInfo;
1868 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1869 std::string groupId = GROUP_ID;
1870 accountInfo.groupIdList.push_back(groupId);
1871 AAFwk::Want want;
1872 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1873 want.SetElement(element);
1874 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1875 callerInfo, accountInfo, want);
1876 EXPECT_EQ(ret, true);
1877 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 end result:" << ret << std::endl;
1878 }
1879
1880 /**
1881 * @tc.name: CheckComponentAccessPermission_007
1882 * @tc.desc: call CheckComponentAccessPermission with visible: false in same account
1883 * @tc.type: FUNC
1884 */
1885 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_007, TestSize.Level1)
1886 {
1887 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 begin" << std::endl;
1888 AppExecFwk::AbilityInfo targetAbility;
1889 targetAbility.visible = false;
1890 CallerInfo callerInfo;
1891 callerInfo.accessToken = ACCESS_TOKEN;
1892 IDistributedSched::AccountInfo accountInfo;
1893 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1894 std::string groupId = GROUP_ID;
1895 accountInfo.groupIdList.push_back(groupId);
1896 AAFwk::Want want;
1897 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1898 want.SetElement(element);
1899 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1900 callerInfo, accountInfo, want);
1901 EXPECT_EQ(ret, false);
1902 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 end result:" << ret << std::endl;
1903 }
1904
1905 /**
1906 * @tc.name: CheckComponentAccessPermission_008
1907 * @tc.desc: call CheckComponentAccessPermission in diff account
1908 * @tc.type: FUNC
1909 */
1910 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_008, TestSize.Level1)
1911 {
1912 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 begin" << std::endl;
1913 AppExecFwk::AbilityInfo targetAbility;
1914 CallerInfo callerInfo;
1915 callerInfo.accessToken = ACCESS_TOKEN;
1916 IDistributedSched::AccountInfo accountInfo;
1917 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1918 std::string groupId = GROUP_ID;
1919 accountInfo.groupIdList.push_back(groupId);
1920 AAFwk::Want want;
1921 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1922 want.SetElement(element);
1923 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1924 callerInfo, accountInfo, want);
1925 EXPECT_EQ(ret, false);
1926 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 end result:" << ret << std::endl;
1927 }
1928
1929 /**
1930 * @tc.name: CheckComponentAccessPermission_009
1931 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in diff account
1932 * @tc.type: FUNC
1933 */
1934 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_009, TestSize.Level1)
1935 {
1936 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 begin" << std::endl;
1937 AppExecFwk::AbilityInfo targetAbility;
1938 CallerInfo callerInfo;
1939 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1940 IDistributedSched::AccountInfo accountInfo;
1941 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1942 std::string groupId = GROUP_ID;
1943 accountInfo.groupIdList.push_back(groupId);
1944 AAFwk::Want want;
1945 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1946 want.SetElement(element);
1947 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1948 callerInfo, accountInfo, want);
1949 EXPECT_EQ(ret, false);
1950 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 end result:" << ret << std::endl;
1951 }
1952
1953 /**
1954 * @tc.name: CheckComponentAccessPermission_010
1955 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in diff account
1956 * @tc.type: FUNC
1957 */
1958 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_010, TestSize.Level1)
1959 {
1960 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 begin" << std::endl;
1961 AppExecFwk::AbilityInfo targetAbility;
1962 CallerInfo callerInfo;
1963 callerInfo.accessToken = ACCESS_TOKEN;
1964 IDistributedSched::AccountInfo accountInfo;
1965 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1966 std::string groupId = INVALID_GROUP_ID;
1967 accountInfo.groupIdList.push_back(groupId);
1968 AAFwk::Want want;
1969 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1970 want.SetElement(element);
1971 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1972 callerInfo, accountInfo, want);
1973 EXPECT_EQ(ret, false);
1974 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 end result:" << ret << std::endl;
1975 }
1976
1977 /**
1978 * @tc.name: CheckComponentAccessPermission_011
1979 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in diff account
1980 * @tc.type: FUNC
1981 */
1982 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_011, TestSize.Level1)
1983 {
1984 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 begin" << std::endl;
1985 AppExecFwk::AbilityInfo targetAbility;
1986 CallerInfo callerInfo;
1987 callerInfo.accessToken = ACCESS_TOKEN;
1988 IDistributedSched::AccountInfo accountInfo;
1989 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1990 std::string groupId = GROUP_ID;
1991 accountInfo.groupIdList.push_back(groupId);
1992 AAFwk::Want want;
1993 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1994 want.SetElement(element);
1995 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1996 callerInfo, accountInfo, want);
1997 EXPECT_EQ(ret, false);
1998 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 end result:" << ret << std::endl;
1999 }
2000
2001 /**
2002 * @tc.name: CheckComponentAccessPermission_012
2003 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in diff account
2004 * @tc.type: FUNC
2005 */
2006 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_012, TestSize.Level1)
2007 {
2008 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 begin" << std::endl;
2009 AppExecFwk::AbilityInfo targetAbility;
2010 CallerInfo callerInfo;
2011 callerInfo.accessToken = ACCESS_TOKEN;
2012 IDistributedSched::AccountInfo accountInfo;
2013 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
2014 std::string groupId = GROUP_ID;
2015 accountInfo.groupIdList.push_back(groupId);
2016 AAFwk::Want want;
2017 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
2018 want.SetElement(element);
2019 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
2020 callerInfo, accountInfo, want);
2021 EXPECT_EQ(ret, false);
2022 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 end result:" << ret << std::endl;
2023 }
2024
2025 /**
2026 * @tc.name: CheckComponentAccessPermission_013
2027 * @tc.desc: call CheckComponentAccessPermission with visible: true in diff account
2028 * @tc.type: FUNC
2029 */
2030 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_013, TestSize.Level1)
2031 {
2032 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 begin" << std::endl;
2033 AppExecFwk::AbilityInfo targetAbility;
2034 targetAbility.visible = true;
2035 CallerInfo callerInfo;
2036 callerInfo.accessToken = ACCESS_TOKEN;
2037 IDistributedSched::AccountInfo accountInfo;
2038 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
2039 std::string groupId = GROUP_ID;
2040 accountInfo.groupIdList.push_back(groupId);
2041 AAFwk::Want want;
2042 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
2043 want.SetElement(element);
2044 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
2045 callerInfo, accountInfo, want);
2046 EXPECT_EQ(ret, true);
2047 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 end result:" << ret << std::endl;
2048 }
2049
2050 /**
2051 * @tc.name: CheckComponentAccessPermission_014
2052 * @tc.desc: call CheckComponentAccessPermission with visible: false in diff account
2053 * @tc.type: FUNC
2054 */
2055 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_014, TestSize.Level1)
2056 {
2057 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 begin" << std::endl;
2058 AppExecFwk::AbilityInfo targetAbility;
2059 targetAbility.visible = false;
2060 CallerInfo callerInfo;
2061 callerInfo.accessToken = ACCESS_TOKEN;
2062 IDistributedSched::AccountInfo accountInfo;
2063 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
2064 std::string groupId = GROUP_ID;
2065 accountInfo.groupIdList.push_back(groupId);
2066 AAFwk::Want want;
2067 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
2068 want.SetElement(element);
2069 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
2070 callerInfo, accountInfo, want);
2071 EXPECT_EQ(ret, false);
2072 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 end result:" << ret << std::endl;
2073 }
2074
2075 /**
2076 * @tc.name: CheckCustomPermission_001
2077 * @tc.desc: call CheckCustomPermission with no permissions
2078 * @tc.type: FUNC
2079 */
2080 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_001, TestSize.Level1)
2081 {
2082 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_001 begin" << std::endl;
2083 AppExecFwk::AbilityInfo targetAbility;
2084 CallerInfo callerInfo;
2085 callerInfo.accessToken = ACCESS_TOKEN;
2086 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
2087 EXPECT_EQ(ret, true);
2088 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_001 end result:" << ret << std::endl;
2089 }
2090
2091 /**
2092 * @tc.name: CheckCustomPermission_002
2093 * @tc.desc: call CheckCustomPermission with no permissions and invalid accessToken
2094 * @tc.type: FUNC
2095 */
2096 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_002, TestSize.Level1)
2097 {
2098 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_002 begin" << std::endl;
2099 AppExecFwk::AbilityInfo targetAbility;
2100 CallerInfo callerInfo;
2101 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
2102 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
2103 EXPECT_EQ(ret, true);
2104 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_002 end result:" << ret << std::endl;
2105 }
2106
2107 /**
2108 * @tc.name: CheckCustomPermission_003
2109 * @tc.desc: call CheckCustomPermission with invalid permissions
2110 * @tc.type: FUNC
2111 */
2112 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_003, TestSize.Level1)
2113 {
2114 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_003 begin" << std::endl;
2115 AppExecFwk::AbilityInfo targetAbility;
2116 targetAbility.permissions.emplace_back(INVALID_PERMISSION_NAME);
2117 CallerInfo callerInfo;
2118 callerInfo.accessToken = ACCESS_TOKEN;
2119 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
2120 EXPECT_EQ(ret, false);
2121 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_003 end result:" << ret << std::endl;
2122 }
2123
2124 /**
2125 * @tc.name: CheckCustomPermission_004
2126 * @tc.desc: call CheckCustomPermission with invalid permissions and invalid accessToken
2127 * @tc.type: FUNC
2128 */
2129 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_004, TestSize.Level1)
2130 {
2131 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_004 begin" << std::endl;
2132 AppExecFwk::AbilityInfo targetAbility;
2133 targetAbility.permissions.emplace_back(INVALID_PERMISSION_NAME);
2134 CallerInfo callerInfo;
2135 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
2136 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
2137 EXPECT_EQ(ret, false);
2138 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_004 end result:" << ret << std::endl;
2139 }
2140
2141 /**
2142 * @tc.name: CheckCustomPermission_005
2143 * @tc.desc: call CheckCustomPermission with correct permissions
2144 * @tc.type: FUNC
2145 */
2146 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_005, TestSize.Level1)
2147 {
2148 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_005 begin" << std::endl;
2149 AppExecFwk::AbilityInfo targetAbility;
2150 targetAbility.permissions.emplace_back(PERMISSION_NAME);
2151 CallerInfo callerInfo;
2152 callerInfo.accessToken = ACCESS_TOKEN;
2153 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
2154 EXPECT_EQ(ret, false);
2155 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_005 end result:" << ret << std::endl;
2156 }
2157
2158 /**
2159 * @tc.name: CheckCustomPermission_006
2160 * @tc.desc: call CheckCustomPermission with correct permissions and invalid accessToken
2161 * @tc.type: FUNC
2162 */
2163 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_006, TestSize.Level1)
2164 {
2165 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_006 begin" << std::endl;
2166 AppExecFwk::AbilityInfo targetAbility;
2167 targetAbility.permissions.emplace_back(PERMISSION_NAME);
2168 CallerInfo callerInfo;
2169 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
2170 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
2171 EXPECT_EQ(ret, false);
2172 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_006 end result:" << ret << std::endl;
2173 }
2174
2175 /**
2176 * @tc.name: CheckCustomPermission_007
2177 * @tc.desc: CheckBackgroundPermission
2178 * @tc.type: FUNC
2179 * @tc.require: issueI5T6GJ
2180 */
2181 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_007, TestSize.Level3)
2182 {
2183 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_007 begin" << std::endl;
2184 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
2185 std::string deviceId = udid;
2186 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
2187 HapTokenInfo baseInfo = {
2188 .apl = APL_NORMAL,
2189 .ver = 1,
2190 .userID = 1,
2191 .bundleName = "com.ohos.dms_test",
2192 .instIndex = 1,
2193 .appID = "dmstest",
2194 .deviceID = udid,
2195 .tokenID = 0x20100000,
2196 .tokenAttr = 0
2197 };
2198
2199 PermissionStateFull infoManagerTestState = {
2200 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
2201 .isGeneral = true,
2202 .resDeviceID = {"local"},
2203 .grantStatus = {PermissionState::PERMISSION_GRANTED}, // first grant
2204 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
2205 std::vector<PermissionStateFull> permStateList;
2206 permStateList.emplace_back(infoManagerTestState);
2207
2208 HapTokenInfoForSync remoteTokenInfo = {
2209 .baseInfo = baseInfo,
2210 .permStateList = permStateList
2211 };
2212
2213 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
2214 ASSERT_EQ(result, RET_SUCCESS);
2215
2216 // Get local map token ID
2217 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
2218 ASSERT_NE(mapID, 0);
2219
2220 AppExecFwk::AbilityInfo targetAbility;
2221 CallerInfo callerInfo;
2222 targetAbility.permissions.emplace_back("");
2223 targetAbility.permissions.emplace_back(PERMISSION_NAME);
2224 callerInfo.sourceDeviceId = deviceId_;
2225 callerInfo.accessToken = 0x20100000;
2226 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
2227 EXPECT_EQ(ret, false);
2228 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_007 end ret:" << ret << std::endl;
2229 }
2230
2231 /**
2232 * @tc.name: CheckPermission_001
2233 * @tc.desc: call CheckPermission
2234 * @tc.type: FUNC
2235 */
2236 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_001, TestSize.Level1)
2237 {
2238 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 begin" << std::endl;
2239 uint32_t accessToken = ACCESS_TOKEN;
2240 string permissionName = PERMISSION_NAME;
2241 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
2242 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
2243 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 end result:" << ret << std::endl;
2244 }
2245
2246 /**
2247 * @tc.name: CheckPermission_002
2248 * @tc.desc: call CheckPermission with invalid accessToken
2249 * @tc.type: FUNC
2250 */
2251 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_002, TestSize.Level1)
2252 {
2253 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_002 begin" << std::endl;
2254 uint32_t accessToken = INVALID_ACCESS_TOKEN;
2255 string permissionName = PERMISSION_NAME;
2256 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
2257 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
2258 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_002 end result:" << ret << std::endl;
2259 }
2260
2261 /**
2262 * @tc.name: CheckPermission_003
2263 * @tc.desc: call CheckPermission with invalid permission
2264 * @tc.type: FUNC
2265 */
2266 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_003, TestSize.Level1)
2267 {
2268 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_003 begin" << std::endl;
2269 uint32_t accessToken = INVALID_ACCESS_TOKEN;
2270 string permissionName = PERMISSION_NAME;
2271 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
2272 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
2273 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_003 end result:" << ret << std::endl;
2274 }
2275
2276 /**
2277 * @tc.name: from_json_001
2278 * @tc.desc: parse groupInfo from json
2279 * @tc.type: FUNC
2280 */
2281 HWTEST_F(DistributedSchedPermissionTest, FromJson_001, TestSize.Level3)
2282 {
2283 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 begin" << std::endl;
2284 GroupInfo groupInfo;
2285 nlohmann::json jsonObject = nlohmann::json {
2286 {FIELD_GROUP_NAME, MOCK_FIELD_GROUP_NAME},
2287 {FIELD_GROUP_ID, MOCK_FIELD_GROUP_ID},
2288 {FIELD_GROUP_OWNER, MOCK_FIELD_GROUP_OWNER},
2289 {FIELD_GROUP_TYPE, MOCK_FIELD_GROUP_TYPE},
2290 {FIELD_GROUP_VISIBILITY, MOCK_FIELD_GROUP_VISIBILITY}
2291 };
2292 if (jsonObject.is_discarded()) {
2293 return;
2294 }
2295 from_json(jsonObject, groupInfo);
2296 EXPECT_EQ(groupInfo.groupName, MOCK_FIELD_GROUP_NAME);
2297 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 end" << std::endl;
2298 }
2299
2300 /**
2301 * @tc.name: from_json_002
2302 * @tc.desc: parse groupInfo from json with invalid params
2303 * @tc.type: FUNC
2304 */
2305 HWTEST_F(DistributedSchedPermissionTest, FromJson_002, TestSize.Level3)
2306 {
2307 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 begin" << std::endl;
2308 GroupInfo groupInfo;
2309 nlohmann::json jsonObject;
2310 if (jsonObject.is_discarded()) {
2311 return;
2312 }
2313 from_json(jsonObject, groupInfo);
2314 EXPECT_EQ(groupInfo.groupName, "");
2315 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 end " << std::endl;
2316 }
2317
2318 /**
2319 * @tc.name: MarkUriPermission_001
2320 * @tc.desc: parse groupInfo from json with invalid params
2321 * @tc.type: FUNC
2322 */
2323 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_001, TestSize.Level3)
2324 {
2325 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_001 begin" << std::endl;
2326 AAFwk::Want want;
2327 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
2328 want.SetUri("file://ohos.dms.ets/data/test_B");
2329 DistributedSchedPermission::GetInstance().MarkUriPermission(want, 0);
2330 CallerInfo callerInfo;
2331 callerInfo.accessToken = ACCESS_TOKEN;
2332 IDistributedSched::AccountInfo accountInfo;
2333 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
2334 std::string groupId = INVALID_GROUP_ID;
2335 accountInfo.groupIdList.push_back(groupId);
2336 string targetBundle = INVALID_BUNDLE_NAME;
2337 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
2338 callerInfo, accountInfo, targetBundle);
2339 EXPECT_EQ(ret, false);
2340 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_001 end " << std::endl;
2341 }
2342
2343 /**
2344 * @tc.name: MarkUriPermission_002
2345 * @tc.desc: parse groupInfo from json with invalid params
2346 * @tc.type: FUNC
2347 */
2348 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_002, TestSize.Level3)
2349 {
2350 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_002 begin" << std::endl;
2351 AAFwk::Want want;
2352 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
2353 want.SetUri("file://com.ohos.launcher/data/test_B");
2354 DistributedSchedPermission::GetInstance().MarkUriPermission(want, 0);
2355 CallerInfo callerInfo;
2356 callerInfo.accessToken = ACCESS_TOKEN;
2357 IDistributedSched::AccountInfo accountInfo;
2358 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
2359 std::string groupId = INVALID_GROUP_ID;
2360 accountInfo.groupIdList.push_back(groupId);
2361 string targetBundle = INVALID_BUNDLE_NAME;
2362 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
2363 callerInfo, accountInfo, targetBundle);
2364 EXPECT_EQ(ret, false);
2365 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_002 end " << std::endl;
2366 }
2367
2368 /**
2369 * @tc.name: MarkUriPermission_003
2370 * @tc.desc: parse groupInfo from json with invalid params
2371 * @tc.type: FUNC
2372 */
2373 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_003, TestSize.Level3)
2374 {
2375 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_003 begin" << std::endl;
2376 AAFwk::Want want;
2377 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
2378 want.SetUri("file://com.ohos.launcher/data/test_B");
2379 const std::string bundleName = "com.ohos.launcher";
2380 uint32_t accessTokenId;
2381 int32_t ret = BundleManagerInternal::GetBundleIdFromBms(bundleName, accessTokenId);
2382 EXPECT_EQ(ret, ERR_OK);
2383 DistributedSchedPermission::GetInstance().MarkUriPermission(want, accessTokenId);
2384 CallerInfo callerInfo;
2385 callerInfo.accessToken = ACCESS_TOKEN;
2386 IDistributedSched::AccountInfo accountInfo;
2387 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
2388 std::string groupId = INVALID_GROUP_ID;
2389 accountInfo.groupIdList.push_back(groupId);
2390 string targetBundle = INVALID_BUNDLE_NAME;
2391 ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
2392 callerInfo, accountInfo, targetBundle);
2393 EXPECT_EQ(ret, false);
2394 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_003 end " << std::endl;
2395 }
2396
2397 /**
2398 * @tc.name: GetDeviceSecurityLevel_001
2399 * @tc.desc: parse groupInfo from json with invalid params
2400 * @tc.type: FUNC
2401 */
2402 HWTEST_F(DistributedSchedPermissionTest, GetDeviceSecurityLevel_001, TestSize.Level3)
2403 {
2404 DTEST_LOG << "DistributedSchedPermissionTest GetDeviceSecurityLevel_001 begin" << std::endl;
2405 string udid = "123456";
2406 int32_t ret = DistributedSchedPermission::GetInstance().GetDeviceSecurityLevel(udid);
2407 EXPECT_NE(ret, 0);
2408 DTEST_LOG << "DistributedSchedPermissionTest GetDeviceSecurityLevel_001 end " << std::endl;
2409 }
2410 } // namespace DistributedSchedule
2411 } // namespace OHOS