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 = "3.2.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: GetTargetAbility_001
436 * @tc.desc: input invalid params
437 * @tc.type: FUNC
438 * @tc.require: issueI5T6GJ
439 */
440 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_001, TestSize.Level3)
441 {
442 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_001 begin" << std::endl;
443 AAFwk::Want want;
444 AppExecFwk::AbilityInfo targetAbility;
445 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, false);
446 EXPECT_FALSE(ret);
447 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_001 end ret:" << ret << std::endl;
448 }
449
450 /**
451 * @tc.name: GetTargetAbility_002
452 * @tc.desc: input invalid params
453 * @tc.type: FUNC
454 * @tc.require: issueI5T6GJ
455 */
456 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_002, TestSize.Level3)
457 {
458 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_002 begin" << std::endl;
459 AAFwk::Want want;
460 ElementName name;
461 name.SetAbilityName(ABILITY_NAME);
462 name.SetBundleName(BUNDLE_NAME);
463 want.SetElement(name);
464 AppExecFwk::AbilityInfo targetAbility;
465 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, false);
466 EXPECT_FALSE(ret);
467 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_002 end ret:" << ret << std::endl;
468 }
469
470 /**
471 * @tc.name: GetTargetAbility_003
472 * @tc.desc: input invalid params
473 * @tc.type: FUNC
474 * @tc.require: issueI5T6GJ
475 */
476 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_003, TestSize.Level3)
477 {
478 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_003 begin" << std::endl;
479 AAFwk::Want want;
480 ElementName name;
481 name.SetAbilityName(ABILITY_NAME);
482 name.SetBundleName(BUNDLE_NAME);
483 want.SetElement(name);
484 want.SetParam(DMS_MISSION_ID, 0);
485 AppExecFwk::AbilityInfo targetAbility;
486 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, false);
487 EXPECT_FALSE(ret);
488 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_003 end ret:" << ret << std::endl;
489 }
490
491 /**
492 * @tc.name: GetTargetAbility_004
493 * @tc.desc: input invalid params
494 * @tc.type: FUNC
495 * @tc.require: issueI5T6GJ
496 */
497 HWTEST_F(DistributedSchedPermissionTest, GetTargetAbility_004, TestSize.Level3)
498 {
499 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_004 begin" << std::endl;
500 AAFwk::Want want;
501 ElementName name;
502 name.SetAbilityName(ABILITY_NAME);
503 name.SetBundleName(BUNDLE_NAME);
504 want.SetElement(name);
505 AppExecFwk::AbilityInfo targetAbility;
506 bool ret = DistributedSchedPermission::GetInstance().GetTargetAbility(want, targetAbility, true);
507 EXPECT_TRUE(ret);
508 DTEST_LOG << "DistributedSchedPermissionTest GetTargetAbility_004 end ret:" << ret << std::endl;
509 }
510
511 /**
512 * @tc.name: CheckGetCallerPermission_001
513 * @tc.desc: input invalid params
514 * @tc.type: FUNC
515 * @tc.require: issueI5T6GJ
516 */
517 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_001, TestSize.Level3)
518 {
519 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_001 begin" << std::endl;
520 AAFwk::Want want;
521 CallerInfo callerInfo;
522 IDistributedSched::AccountInfo accountInfo;
523 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
524 AppExecFwk::AbilityInfo targetAbility;
525 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
526 targetAbility);
527 EXPECT_EQ(ret, DMS_ACCOUNT_ACCESS_PERMISSION_DENIED);
528 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_001 end ret:" << ret << std::endl;
529 }
530
531 /**
532 * @tc.name: CheckGetCallerPermission_002
533 * @tc.desc: input invalid params
534 * @tc.type: FUNC
535 * @tc.require: issueI5T6GJ
536 */
537 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_002, TestSize.Level3)
538 {
539 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_002 begin" << std::endl;
540 AAFwk::Want want;
541 CallerInfo callerInfo;
542 IDistributedSched::AccountInfo accountInfo;
543 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
544 AppExecFwk::AbilityInfo targetAbility;
545 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
546 targetAbility);
547 EXPECT_EQ(ret, CALL_PERMISSION_DENIED);
548 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_002 end ret:" << ret << std::endl;
549 }
550
551 /**
552 * @tc.name: CheckGetCallerPermission_003
553 * @tc.desc: input invalid params
554 * @tc.type: FUNC
555 * @tc.require: issueI5T6GJ
556 */
557 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_003, TestSize.Level3)
558 {
559 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_003 begin" << std::endl;
560 AAFwk::Want want;
561 CallerInfo callerInfo;
562 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
563 EXPECT_EQ(result, true);
564 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
565 IDistributedSched::AccountInfo accountInfo;
566 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
567 AppExecFwk::AbilityInfo targetAbility;
568 targetAbility.bundleName = BUNDLE_NAME;
569 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
570 targetAbility);
571 EXPECT_EQ(ret, DMS_BACKGROUND_PERMISSION_DENIED);
572 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_003 end ret:" << ret << std::endl;
573 }
574
575 /**
576 * @tc.name: CheckGetCallerPermission_004
577 * @tc.desc: input invalid params
578 * @tc.type: FUNC
579 * @tc.require: issueI5T6GJ
580 */
581 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_004, TestSize.Level3)
582 {
583 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_004 begin" << std::endl;
584 AAFwk::Want want;
585 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
586 CallerInfo callerInfo;
587 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
588 EXPECT_EQ(result, true);
589 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
590 IDistributedSched::AccountInfo accountInfo;
591 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
592 AppExecFwk::AbilityInfo targetAbility;
593 targetAbility.bundleName = BUNDLE_NAME;
594 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
595 targetAbility);
596 EXPECT_EQ(ret, ERR_OK);
597 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_004 end ret:" << ret << std::endl;
598 }
599
600 /**
601 * @tc.name: CheckGetCallerPermission_005
602 * @tc.desc: input invalid params
603 * @tc.type: FUNC
604 * @tc.require: issueI5T6GJ
605 */
606 HWTEST_F(DistributedSchedPermissionTest, CheckGetCallerPermission_005, TestSize.Level3)
607 {
608 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_005 begin" << std::endl;
609 AAFwk::Want want;
610 ElementName name;
611 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
612 CallerInfo callerInfo;
613 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
614 EXPECT_EQ(result, true);
615 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
616 IDistributedSched::AccountInfo accountInfo;
617 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
618 AppExecFwk::AbilityInfo targetAbility;
619 targetAbility.bundleName = BUNDLE_NAME;
620 targetAbility.permissions.push_back(INVALID_PERMISSION_NAME);
621 int32_t ret = DistributedSchedPermission::GetInstance().CheckGetCallerPermission(want, callerInfo, accountInfo,
622 targetAbility);
623 EXPECT_EQ(ret, DMS_COMPONENT_ACCESS_PERMISSION_DENIED);
624 DTEST_LOG << "DistributedSchedPermissionTest CheckGetCallerPermission_005 end ret:" << ret << std::endl;
625 }
626
627 /**
628 * @tc.name: CheckStartControlPermission_001
629 * @tc.desc: input invalid params
630 * @tc.type: FUNC
631 * @tc.require: issueI5T6GJ
632 */
633 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_001, TestSize.Level3)
634 {
635 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_001 begin" << std::endl;
636 AppExecFwk::AbilityInfo targetAbility;
637 CallerInfo callerInfo;
638 AAFwk::Want want;
639 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
640 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
641 EXPECT_FALSE(ret);
642 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_001 end ret:" << ret << std::endl;
643 }
644
645 /**
646 * @tc.name: CheckStartControlPermission_002
647 * @tc.desc: input invalid params
648 * @tc.type: FUNC
649 * @tc.require: issueI5T6GJ
650 */
651 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_002, TestSize.Level3)
652 {
653 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_002 begin" << std::endl;
654 AppExecFwk::AbilityInfo targetAbility;
655 targetAbility.bundleName = BUNDLE_NAME;
656 CallerInfo callerInfo;
657 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
658 EXPECT_EQ(result, true);
659 AAFwk::Want want;
660 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
661 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
662 EXPECT_TRUE(ret);
663 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_002 end ret:" << ret << std::endl;
664 }
665
666 /**
667 * @tc.name: CheckStartControlPermission_003
668 * @tc.desc: input invalid params
669 * @tc.type: FUNC
670 * @tc.require: issueI5T6GJ
671 */
672 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_003, TestSize.Level3)
673 {
674 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_003 begin" << std::endl;
675 AppExecFwk::AbilityInfo targetAbility;
676 CallerInfo callerInfo;
677 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
678 EXPECT_EQ(result, true);
679 AAFwk::Want want;
680 want.AddFlags(want.FLAG_ABILITY_CONTINUATION);
681 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
682 EXPECT_FALSE(ret);
683 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_003 end ret:" << ret << std::endl;
684 }
685
686 /**
687 * @tc.name: CheckStartControlPermission_004
688 * @tc.desc: input invalid params
689 * @tc.type: FUNC
690 * @tc.require: issueI5T6GJ
691 */
692 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_004, TestSize.Level3)
693 {
694 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_004 begin" << std::endl;
695 AppExecFwk::AbilityInfo targetAbility;
696 CallerInfo callerInfo;
697 AAFwk::Want want;
698 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
699 EXPECT_FALSE(ret);
700 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_004 end ret:" << ret << std::endl;
701 }
702
703 /**
704 * @tc.name: CheckStartControlPermission_005
705 * @tc.desc: input invalid params
706 * @tc.type: FUNC
707 * @tc.require: issueI5T6GJ
708 */
709 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_005, TestSize.Level3)
710 {
711 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_005 begin" << std::endl;
712 AppExecFwk::AbilityInfo targetAbility;
713 CallerInfo callerInfo;
714 AAFwk::Want want;
715 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
716 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
717 EXPECT_FALSE(ret);
718 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_005 end ret:" << ret << std::endl;
719 }
720
721 /**
722 * @tc.name: CheckStartControlPermission_006
723 * @tc.desc: input invalid params
724 * @tc.type: FUNC
725 * @tc.require: issueI5T6GJ
726 */
727 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_006, TestSize.Level3)
728 {
729 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_006 begin" << std::endl;
730 AppExecFwk::AbilityInfo targetAbility;
731 targetAbility.bundleName = BUNDLE_NAME;
732 CallerInfo callerInfo;
733 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
734 EXPECT_EQ(result, true);
735 AAFwk::Want want;
736 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
737 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
738 EXPECT_TRUE(ret);
739 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_006 end ret:" << ret << std::endl;
740 }
741
742 /**
743 * @tc.name: CheckStartControlPermission_007
744 * @tc.desc: input invalid params
745 * @tc.type: FUNC
746 * @tc.require: issueI5T6GJ
747 */
748 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_007, TestSize.Level3)
749 {
750 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_007 begin" << std::endl;
751 AppExecFwk::AbilityInfo targetAbility;
752 CallerInfo callerInfo;
753 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
754 EXPECT_EQ(result, true);
755 AAFwk::Want want;
756 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
757 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
758 EXPECT_FALSE(ret);
759 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_007 end ret:" << ret << std::endl;
760 }
761
762 /**
763 * @tc.name: CheckStartControlPermission_008
764 * @tc.desc: input invalid params
765 * @tc.type: FUNC
766 * @tc.require: issueI5T6GJ
767 */
768 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_008, TestSize.Level3)
769 {
770 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_008 begin" << std::endl;
771 AppExecFwk::AbilityInfo targetAbility;
772 targetAbility.visible = true;
773 targetAbility.isStageBasedModel = true;
774 CallerInfo callerInfo;
775 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
776 EXPECT_EQ(result, true);
777 AAFwk::Want want;
778 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
779 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
780 EXPECT_TRUE(ret);
781 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_008 end ret:" << ret << std::endl;
782 }
783
784 /**
785 * @tc.name: CheckStartControlPermission_009
786 * @tc.desc: input invalid params
787 * @tc.type: FUNC
788 * @tc.require: issueI5T6GJ
789 */
790 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_009, TestSize.Level3)
791 {
792 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_009 begin" << std::endl;
793 AppExecFwk::AbilityInfo targetAbility;
794 targetAbility.visible = true;
795 targetAbility.type = AppExecFwk::AbilityType::PAGE;
796 CallerInfo callerInfo;
797 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
798 EXPECT_EQ(result, true);
799 AAFwk::Want want;
800 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
801 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
802 EXPECT_TRUE(ret);
803 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_009 end ret:" << ret << std::endl;
804 }
805
806 /**
807 * @tc.name: CheckStartControlPermission_010
808 * @tc.desc: input invalid params
809 * @tc.type: FUNC
810 * @tc.require: issueI5T6GJ
811 */
812 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_010, TestSize.Level3)
813 {
814 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_010 begin" << std::endl;
815 AppExecFwk::AbilityInfo targetAbility;
816 targetAbility.visible = true;
817 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
818 CallerInfo callerInfo;
819 bool result = BundleManagerInternal::GetCallerAppIdFromBms(BUNDLE_NAME, callerInfo.callerAppId);
820 EXPECT_EQ(result, true);
821 AAFwk::Want want;
822 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
823 bool ret = DistributedSchedPermission::GetInstance().CheckStartControlPermission(targetAbility, callerInfo, want);
824 EXPECT_FALSE(ret);
825 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_010 end ret:" << ret << std::endl;
826 }
827
828 /**
829 * @tc.name: CheckStartControlPermission_011
830 * @tc.desc: input invalid params
831 * @tc.type: FUNC
832 * @tc.require: issueI5T6GJ
833 */
834 HWTEST_F(DistributedSchedPermissionTest, CheckStartControlPermission_011, TestSize.Level3)
835 {
836 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_011 begin" << std::endl;
837 AppExecFwk::AbilityInfo targetAbility;
838 targetAbility.visible = true;
839 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
840 targetAbility.applicationInfo.associatedWakeUp = true;
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_TRUE(ret);
848 DTEST_LOG << "DistributedSchedPermissionTest CheckStartControlPermission_011 end ret:" << ret << std::endl;
849 }
850
851 /**
852 * @tc.name: CheckBackgroundPermission_001
853 * @tc.desc: input invalid params
854 * @tc.type: FUNC
855 * @tc.require: issueI5T6GJ
856 */
857 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_001, TestSize.Level3)
858 {
859 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_001 begin" << std::endl;
860 AppExecFwk::AbilityInfo targetAbility;
861 CallerInfo callerInfo;
862 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
863 AAFwk::Want want;
864 want.SetParam(DMS_IS_CALLER_BACKGROUND, false);
865 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
866 false);
867 EXPECT_TRUE(ret);
868 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_001 end ret:" << ret << std::endl;
869 }
870
871 /**
872 * @tc.name: CheckBackgroundPermission_002
873 * @tc.desc: input invalid params
874 * @tc.type: FUNC
875 * @tc.require: issueI5T6GJ
876 */
877 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_002, TestSize.Level3)
878 {
879 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_002 begin" << std::endl;
880 AppExecFwk::AbilityInfo targetAbility;
881 CallerInfo callerInfo;
882 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
883 AAFwk::Want want;
884 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
885 false);
886 EXPECT_FALSE(ret);
887 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_002 end ret:" << ret << std::endl;
888 }
889
890 /**
891 * @tc.name: CheckBackgroundPermission_003
892 * @tc.desc: input invalid params
893 * @tc.type: FUNC
894 * @tc.require: issueI5T6GJ
895 */
896 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_003, TestSize.Level3)
897 {
898 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_003 begin" << std::endl;
899 AppExecFwk::AbilityInfo targetAbility;
900 targetAbility.isStageBasedModel = true;
901 CallerInfo callerInfo;
902 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
903 AAFwk::Want want;
904 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
905 true);
906 EXPECT_FALSE(ret);
907 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_003 end ret:" << ret << std::endl;
908 }
909
910 /**
911 * @tc.name: CheckBackgroundPermission_004
912 * @tc.desc: input invalid params
913 * @tc.type: FUNC
914 * @tc.require: issueI5T6GJ
915 */
916 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_004, TestSize.Level3)
917 {
918 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_004 begin" << std::endl;
919 AppExecFwk::AbilityInfo targetAbility;
920 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
921 CallerInfo callerInfo;
922 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
923 AAFwk::Want want;
924 want.SetParam(DMS_API_VERSION, FA_MODULE_ALLOW_MIN_API_VERSION);
925 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
926 true);
927 EXPECT_TRUE(ret);
928 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_004 end ret:" << ret << std::endl;
929 }
930
931 /**
932 * @tc.name: CheckBackgroundPermission_005
933 * @tc.desc: input invalid params
934 * @tc.type: FUNC
935 * @tc.require: issueI5T6GJ
936 */
937 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_005, TestSize.Level3)
938 {
939 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_005 begin" << std::endl;
940 AppExecFwk::AbilityInfo targetAbility;
941 CallerInfo callerInfo;
942 callerInfo.sourceDeviceId = "";
943 callerInfo.accessToken = GetSelfTokenID();
944 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
945 AAFwk::Want want;
946 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
947 false);
948 EXPECT_FALSE(ret);
949 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_005 end ret:" << ret << std::endl;
950 }
951
952 /**
953 * @tc.name: CheckBackgroundPermission_006
954 * @tc.desc: input invalid params
955 * @tc.type: FUNC
956 * @tc.require: issueI5T6GJ
957 */
958 HWTEST_F(DistributedSchedPermissionTest, CheckBackgroundPermission_006, TestSize.Level3)
959 {
960 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_006 begin" << std::endl;
961 AppExecFwk::AbilityInfo targetAbility;
962 CallerInfo callerInfo;
963 callerInfo.sourceDeviceId = deviceId_;
964 uint64_t tokenId = GetSelfTokenID();
965 callerInfo.accessToken = tokenId;
966 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
967 AAFwk::Want want;
968 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
969 false);
970 EXPECT_FALSE(ret);
971 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_006 end ret:" << ret << std::endl;
972 }
973
974 /**
975 * @tc.name: CheckMinApiVersion_001
976 * @tc.desc: input invalid params
977 * @tc.type: FUNC
978 * @tc.require: issueI5T6GJ
979 */
980 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_001, TestSize.Level3)
981 {
982 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 begin" << std::endl;
983 AppExecFwk::AbilityInfo targetAbility;
984 targetAbility.isStageBasedModel = true;
985 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
986 EXPECT_FALSE(ret);
987 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 end ret:" << ret << std::endl;
988 }
989
990 /**
991 * @tc.name: CheckMinApiVersion_002
992 * @tc.desc: input invalid params
993 * @tc.type: FUNC
994 * @tc.require: issueI5T6GJ
995 */
996 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_002, TestSize.Level3)
997 {
998 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 begin" << std::endl;
999 AppExecFwk::AbilityInfo targetAbility;
1000 targetAbility.type = AppExecFwk::AbilityType::PAGE;
1001 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
1002 EXPECT_FALSE(ret);
1003 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 end ret:" << ret << std::endl;
1004 }
1005
1006 /**
1007 * @tc.name: CheckMinApiVersion_003
1008 * @tc.desc: input invalid params
1009 * @tc.type: FUNC
1010 * @tc.require: issueI5T6GJ
1011 */
1012 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_003, TestSize.Level3)
1013 {
1014 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 begin" << std::endl;
1015 AppExecFwk::AbilityInfo targetAbility;
1016 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
1017 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
1018 EXPECT_FALSE(ret);
1019 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 end ret:" << ret << std::endl;
1020 }
1021
1022 /**
1023 * @tc.name: CheckMinApiVersion_004
1024 * @tc.desc: input invalid params
1025 * @tc.type: FUNC
1026 * @tc.require: issueI5T6GJ
1027 */
1028 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_004, TestSize.Level3)
1029 {
1030 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 begin" << std::endl;
1031 AppExecFwk::AbilityInfo targetAbility;
1032 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
1033 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility,
1034 FA_MODULE_ALLOW_MIN_API_VERSION);
1035 EXPECT_TRUE(ret);
1036 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 end ret:" << ret << std::endl;
1037 }
1038
1039 /**
1040 * @tc.name: CheckTargetAbilityVisible_001
1041 * @tc.desc: input invalid params
1042 * @tc.type: FUNC
1043 * @tc.require: issueI5T6GJ
1044 */
1045 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_001, TestSize.Level3)
1046 {
1047 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 begin" << std::endl;
1048 AppExecFwk::AbilityInfo targetAbility;
1049 targetAbility.visible = true;
1050 CallerInfo callerInfo;
1051 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1052 EXPECT_TRUE(ret);
1053 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 end ret:" << ret << std::endl;
1054 }
1055
1056 /**
1057 * @tc.name: CheckTargetAbilityVisible_002
1058 * @tc.desc: input invalid params
1059 * @tc.type: FUNC
1060 * @tc.require: issueI5T6GJ
1061 */
1062 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_002, TestSize.Level3)
1063 {
1064 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 begin" << std::endl;
1065 AppExecFwk::AbilityInfo targetAbility;
1066 CallerInfo callerInfo;
1067 callerInfo.sourceDeviceId = "";
1068 callerInfo.accessToken = GetSelfTokenID();
1069 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1070 EXPECT_FALSE(ret);
1071 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 end ret:" << ret << std::endl;
1072 }
1073
1074 /**
1075 * @tc.name: CheckTargetAbilityVisible_003
1076 * @tc.desc: input invalid params
1077 * @tc.type: FUNC
1078 * @tc.require: issueI5T6GJ
1079 */
1080 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_003, TestSize.Level3)
1081 {
1082 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 begin" << std::endl;
1083 AppExecFwk::AbilityInfo targetAbility;
1084 CallerInfo callerInfo;
1085 callerInfo.sourceDeviceId = "deviceId_";
1086 callerInfo.accessToken = GetSelfTokenID();
1087 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1088 EXPECT_FALSE(ret);
1089 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 end ret:" << ret << std::endl;
1090 }
1091
1092 #ifdef TOKEN_SYNC_ENABLE
1093 /**
1094 * @tc.name: CheckTargetAbilityVisible_004
1095 * @tc.desc: check CheckTargetAbilityVisible
1096 * @tc.type: FUNC
1097 * @tc.require: issueI5T6GJ
1098 */
1099 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_004, TestSize.Level3)
1100 {
1101 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 begin" << std::endl;
1102 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
1103 std::string deviceId = udid;
1104 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
1105 HapTokenInfo baseInfo = {
1106 .apl = APL_NORMAL,
1107 .ver = 1,
1108 .userID = 1,
1109 .bundleName = "com.ohos.dms_test",
1110 .instIndex = 1,
1111 .appID = "dmstest",
1112 .deviceID = udid,
1113 .tokenID = 0x20100000,
1114 .tokenAttr = 0
1115 };
1116
1117 PermissionStateFull infoManagerTestState = {
1118 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
1119 .isGeneral = true,
1120 .resDeviceID = {"local"},
1121 .grantStatus = {PermissionState::PERMISSION_GRANTED}, // first grant
1122 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
1123 std::vector<PermissionStateFull> permStateList;
1124 permStateList.emplace_back(infoManagerTestState);
1125
1126 HapTokenInfoForSync remoteTokenInfo = {
1127 .baseInfo = baseInfo,
1128 .permStateList = permStateList
1129 };
1130
1131 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1132 ASSERT_EQ(result, RET_SUCCESS);
1133
1134 // Get local map token ID
1135 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1136 ASSERT_NE(mapID, 0);
1137
1138 AppExecFwk::AbilityInfo targetAbility;
1139 CallerInfo callerInfo;
1140 callerInfo.sourceDeviceId = deviceId_;
1141 callerInfo.accessToken = 0x20100000;
1142 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1143 EXPECT_TRUE(ret);
1144 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 end ret:" << ret << std::endl;
1145 }
1146
1147 /**
1148 * @tc.name: CheckTargetAbilityVisible_005
1149 * @tc.desc: check CheckTargetAbilityVisible
1150 * @tc.type: FUNC
1151 * @tc.require: issueI5T6GJ
1152 */
1153 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_005, TestSize.Level3)
1154 {
1155 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 begin" << std::endl;
1156 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
1157 std::string deviceId = udid;
1158 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
1159 HapTokenInfo baseInfo = {
1160 .apl = APL_NORMAL,
1161 .ver = 1,
1162 .userID = 1,
1163 .bundleName = "com.ohos.dms_test",
1164 .instIndex = 1,
1165 .appID = "dmstest",
1166 .deviceID = udid,
1167 .tokenID = 0x20100000,
1168 .tokenAttr = 0
1169 };
1170
1171 PermissionStateFull infoManagerTestState = {
1172 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
1173 .isGeneral = true,
1174 .resDeviceID = {"local"},
1175 .grantStatus = {PermissionState::PERMISSION_DENIED},
1176 .grantFlags = {PermissionFlag::PERMISSION_SYSTEM_FIXED}};
1177 std::vector<PermissionStateFull> permStateList;
1178 permStateList.emplace_back(infoManagerTestState);
1179
1180 HapTokenInfoForSync remoteTokenInfo = {
1181 .baseInfo = baseInfo,
1182 .permStateList = permStateList
1183 };
1184
1185 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1186 ASSERT_EQ(result, RET_SUCCESS);
1187
1188 // Get local map token ID
1189 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1190 ASSERT_NE(mapID, 0);
1191
1192 AppExecFwk::AbilityInfo targetAbility;
1193 CallerInfo callerInfo;
1194 callerInfo.sourceDeviceId = deviceId_;
1195 callerInfo.accessToken = 0x20100000;
1196 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1197 EXPECT_FALSE(ret);
1198 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 end ret:" << ret << std::endl;
1199 }
1200 #endif
1201
1202 /**
1203 * @tc.name: GetAccountInfo_001
1204 * @tc.desc: call GetAccountInfo with empty networkId
1205 * @tc.type: FUNC
1206 * @tc.require: I5RWIV
1207 */
1208 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_001, TestSize.Level3)
1209 {
1210 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 begin" << std::endl;
1211 std::string remoteNetworkId;
1212 CallerInfo callerInfo;
1213 IDistributedSched::AccountInfo accountInfo;
1214 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1215 remoteNetworkId, callerInfo, accountInfo);
1216 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1217 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 end result:" << ret << std::endl;
1218 }
1219
1220 /**
1221 * @tc.name: GetAccountInfo_002
1222 * @tc.desc: call GetAccountInfo with invalid networkId
1223 * @tc.type: FUNC
1224 * @tc.require: I5RWIV
1225 */
1226 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_002, TestSize.Level3)
1227 {
1228 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 begin" << std::endl;
1229 std::string remoteNetworkId = "0";
1230 CallerInfo callerInfo;
1231 IDistributedSched::AccountInfo accountInfo;
1232 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1233 remoteNetworkId, callerInfo, accountInfo);
1234 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1235 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 end result:" << ret << std::endl;
1236 }
1237
1238 /**
1239 * @tc.name: GetRelatedGroups_001
1240 * @tc.desc: call GetRelatedGroups with empty bundleNames
1241 * @tc.type: FUNC
1242 * @tc.require: I5RWIV
1243 */
1244 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_001, TestSize.Level3)
1245 {
1246 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 begin" << std::endl;
1247 std::string udid;
1248 std::vector<std::string> bundleNames;
1249 IDistributedSched::AccountInfo accountInfo;
1250 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1251 udid, bundleNames, accountInfo);
1252 EXPECT_EQ(ret, false);
1253 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1254 }
1255
1256 /**
1257 * @tc.name: GetRelatedGroups_002
1258 * @tc.desc: call GetRelatedGroups with invalid bundleNames
1259 * @tc.type: FUNC
1260 * @tc.require: I5RWIV
1261 */
1262 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_002, TestSize.Level3)
1263 {
1264 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 begin" << std::endl;
1265 std::string udid = "0";
1266 std::vector<std::string> bundleNames = {"mock.bundle1", "mock.bundle2"};
1267 IDistributedSched::AccountInfo accountInfo;
1268 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1269 udid, bundleNames, accountInfo);
1270 EXPECT_EQ(ret, false);
1271 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1272 }
1273
1274 /**
1275 * @tc.name: ParseGroupInfos_001
1276 * @tc.desc: call ParseGroupInfos with empty returnGroupStr
1277 * @tc.type: FUNC
1278 * @tc.require: I5RWIV
1279 */
1280 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_001, TestSize.Level3)
1281 {
1282 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_001 begin" << std::endl;
1283 std::string returnGroupStr;
1284 std::vector<GroupInfo> groupInfos;
1285 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1286 returnGroupStr, groupInfos);
1287 EXPECT_EQ(ret, false);
1288 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1289 }
1290
1291 /**
1292 * @tc.name: ParseGroupInfos_002
1293 * @tc.desc: call ParseGroupInfos with invalid returnGroupStr
1294 * @tc.type: FUNC
1295 * @tc.require: I5RWIV
1296 */
1297 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_002, TestSize.Level3)
1298 {
1299 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_002 begin" << std::endl;
1300 std::string returnGroupStr = "mockInvalidGroup";
1301 std::vector<GroupInfo> groupInfos;
1302 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1303 returnGroupStr, groupInfos);
1304 EXPECT_EQ(ret, false);
1305 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1306 }
1307
1308 /**
1309 * @tc.name: ParseGroupInfos_003
1310 * @tc.desc: call ParseGroupInfos
1311 * @tc.type: FUNC
1312 * @tc.require: I5RWIV
1313 */
1314 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_003, TestSize.Level3)
1315 {
1316 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_003 begin" << std::endl;
1317 std::string returnGroupStr = "[{\"groupName\":\"mockGroupName\",\"groupId\":\"mockGroupId\",";
1318 returnGroupStr += "\"groupOwner\":\"mockGroupOwner\",\"groupType\":0,\"groupVisibility\":0}]";
1319 std::vector<GroupInfo> groupInfos;
1320 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1321 returnGroupStr, groupInfos);
1322 EXPECT_EQ(ret, true);
1323 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_003 end result:" << ret << std::endl;
1324 }
1325
1326 /**
1327 * @tc.name: IsFoundationCall_001
1328 * @tc.desc: call IsFoundationCall not from foundation
1329 * @tc.type: FUNC
1330 * @tc.require: I5RWIV
1331 */
1332 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_001, TestSize.Level3)
1333 {
1334 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 begin" << std::endl;
1335 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1336 EXPECT_EQ(ret, false);
1337 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 end result:" << ret << std::endl;
1338 }
1339
1340 /**
1341 * @tc.name: IsFoundationCall_002
1342 * @tc.desc: call IsFoundationCall from foundation
1343 * @tc.type: FUNC
1344 * @tc.require: I5RWIV
1345 */
1346 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_002, TestSize.Level3)
1347 {
1348 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 begin" << std::endl;
1349 DistributedSchedUtil::MockProcess(FOUNDATION_PROCESS_NAME);
1350 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1351 EXPECT_EQ(ret, true);
1352 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 end result:" << ret << std::endl;
1353 }
1354
1355 /**
1356 * @tc.name: CheckAccountAccessPermission_001
1357 * @tc.desc: call CheckAccountAccessPermission in same account
1358 * @tc.type: FUNC
1359 */
1360 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_001, TestSize.Level1)
1361 {
1362 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 begin" << std::endl;
1363 CallerInfo callerInfo;
1364 callerInfo.accessToken = ACCESS_TOKEN;
1365 IDistributedSched::AccountInfo accountInfo;
1366 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1367 std::string groupId = GROUP_ID;
1368 accountInfo.groupIdList.push_back(groupId);
1369 string targetBundle = BUNDLE_NAME;
1370 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1371 callerInfo, accountInfo, targetBundle);
1372 EXPECT_EQ(ret, true);
1373 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 end result:" << ret << std::endl;
1374 }
1375
1376 /**
1377 * @tc.name: CheckAccountAccessPermission_002
1378 * @tc.desc: call CheckAccountAccessPermission with invalid accessToken in same account
1379 * @tc.type: FUNC
1380 */
1381 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_002, TestSize.Level1)
1382 {
1383 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_002 begin" << std::endl;
1384 CallerInfo callerInfo;
1385 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1386 IDistributedSched::AccountInfo accountInfo;
1387 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1388 std::string groupId = GROUP_ID;
1389 accountInfo.groupIdList.push_back(groupId);
1390 string targetBundle = BUNDLE_NAME;
1391 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1392 callerInfo, accountInfo, targetBundle);
1393 EXPECT_EQ(ret, true);
1394 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_002 end result:" << ret << std::endl;
1395 }
1396
1397 /**
1398 * @tc.name: CheckAccountAccessPermission_003
1399 * @tc.desc: call CheckAccountAccessPermission with invalid groupId in same account
1400 * @tc.type: FUNC
1401 */
1402 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_003, TestSize.Level1)
1403 {
1404 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_003 begin" << std::endl;
1405 CallerInfo callerInfo;
1406 callerInfo.accessToken = ACCESS_TOKEN;
1407 IDistributedSched::AccountInfo accountInfo;
1408 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1409 std::string groupId = INVALID_GROUP_ID;
1410 accountInfo.groupIdList.push_back(groupId);
1411 string targetBundle = BUNDLE_NAME;
1412 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1413 callerInfo, accountInfo, targetBundle);
1414 EXPECT_EQ(ret, true);
1415 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_003 end result:" << ret << std::endl;
1416 }
1417
1418 /**
1419 * @tc.name: CheckAccountAccessPermission_004
1420 * @tc.desc: call CheckAccountAccessPermission with invalid bundleName in same account
1421 * @tc.type: FUNC
1422 */
1423 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_004, TestSize.Level1)
1424 {
1425 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_004 begin" << std::endl;
1426 CallerInfo callerInfo;
1427 callerInfo.accessToken = ACCESS_TOKEN;
1428 IDistributedSched::AccountInfo accountInfo;
1429 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1430 std::string groupId = GROUP_ID;
1431 accountInfo.groupIdList.push_back(groupId);
1432 string targetBundle = INVALID_BUNDLE_NAME;
1433 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1434 callerInfo, accountInfo, targetBundle);
1435 EXPECT_EQ(ret, true);
1436 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_004 end result:" << ret << std::endl;
1437 }
1438
1439 /**
1440 * @tc.name: CheckAccountAccessPermission_005
1441 * @tc.desc: call CheckAccountAccessPermission in diff account
1442 * @tc.type: FUNC
1443 */
1444 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_005, TestSize.Level1)
1445 {
1446 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_005 begin" << std::endl;
1447 CallerInfo callerInfo;
1448 callerInfo.accessToken = ACCESS_TOKEN;
1449 IDistributedSched::AccountInfo accountInfo;
1450 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1451 std::string groupId = GROUP_ID;
1452 accountInfo.groupIdList.push_back(groupId);
1453 string targetBundle = BUNDLE_NAME;
1454 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1455 callerInfo, accountInfo, targetBundle);
1456 EXPECT_EQ(ret, false);
1457 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_005 end result:" << ret << std::endl;
1458 }
1459
1460 /**
1461 * @tc.name: CheckAccountAccessPermission_006
1462 * @tc.desc: call CheckAccountAccessPermission with invalid accessToken in diff account
1463 * @tc.type: FUNC
1464 */
1465 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_006, TestSize.Level1)
1466 {
1467 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_006 begin" << std::endl;
1468 CallerInfo callerInfo;
1469 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1470 IDistributedSched::AccountInfo accountInfo;
1471 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1472 std::string groupId = GROUP_ID;
1473 accountInfo.groupIdList.push_back(groupId);
1474 string targetBundle = BUNDLE_NAME;
1475 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1476 callerInfo, accountInfo, targetBundle);
1477 EXPECT_EQ(ret, false);
1478 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_006 end result:" << ret << std::endl;
1479 }
1480
1481 /**
1482 * @tc.name: CheckAccountAccessPermission_007
1483 * @tc.desc: call CheckAccountAccessPermission with invalid groupId in diff account
1484 * @tc.type: FUNC
1485 */
1486 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_007, TestSize.Level1)
1487 {
1488 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_007 begin" << std::endl;
1489 CallerInfo callerInfo;
1490 callerInfo.accessToken = ACCESS_TOKEN;
1491 IDistributedSched::AccountInfo accountInfo;
1492 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1493 std::string groupId = INVALID_GROUP_ID;
1494 accountInfo.groupIdList.push_back(groupId);
1495 string targetBundle = BUNDLE_NAME;
1496 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1497 callerInfo, accountInfo, targetBundle);
1498 EXPECT_EQ(ret, false);
1499 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_007 end result:" << ret << std::endl;
1500 }
1501
1502 /**
1503 * @tc.name: CheckAccountAccessPermission_008
1504 * @tc.desc: call CheckAccountAccessPermission with invalid bundleName in diff account
1505 * @tc.type: FUNC
1506 */
1507 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_008, TestSize.Level1)
1508 {
1509 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_008 begin" << std::endl;
1510 CallerInfo callerInfo;
1511 callerInfo.accessToken = ACCESS_TOKEN;
1512 IDistributedSched::AccountInfo accountInfo;
1513 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1514 std::string groupId = GROUP_ID;
1515 accountInfo.groupIdList.push_back(groupId);
1516 string targetBundle = INVALID_BUNDLE_NAME;
1517 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1518 callerInfo, accountInfo, targetBundle);
1519 EXPECT_EQ(ret, false);
1520 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_008 end result:" << ret << std::endl;
1521 }
1522
1523 /**
1524 * @tc.name: CheckComponentAccessPermission_001
1525 * @tc.desc: call CheckComponentAccessPermission in same account
1526 * @tc.type: FUNC
1527 */
1528 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_001, TestSize.Level1)
1529 {
1530 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 begin" << std::endl;
1531 AppExecFwk::AbilityInfo targetAbility;
1532 CallerInfo callerInfo;
1533 callerInfo.accessToken = ACCESS_TOKEN;
1534 IDistributedSched::AccountInfo accountInfo;
1535 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1536 std::string groupId = GROUP_ID;
1537 accountInfo.groupIdList.push_back(groupId);
1538 AAFwk::Want want;
1539 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1540 want.SetElement(element);
1541 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1542 callerInfo, accountInfo, want);
1543 EXPECT_EQ(ret, false);
1544 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 end result:" << ret << std::endl;
1545 }
1546
1547 /**
1548 * @tc.name: CheckComponentAccessPermission_002
1549 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in same account
1550 * @tc.type: FUNC
1551 */
1552 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_002, TestSize.Level1)
1553 {
1554 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 begin" << std::endl;
1555 AppExecFwk::AbilityInfo targetAbility;
1556 CallerInfo callerInfo;
1557 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1558 IDistributedSched::AccountInfo accountInfo;
1559 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1560 std::string groupId = GROUP_ID;
1561 accountInfo.groupIdList.push_back(groupId);
1562 AAFwk::Want want;
1563 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1564 want.SetElement(element);
1565 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1566 callerInfo, accountInfo, want);
1567 EXPECT_EQ(ret, false);
1568 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 end result:" << ret << std::endl;
1569 }
1570
1571 /**
1572 * @tc.name: CheckComponentAccessPermission_003
1573 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in same account
1574 * @tc.type: FUNC
1575 */
1576 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_003, TestSize.Level1)
1577 {
1578 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 begin" << std::endl;
1579 AppExecFwk::AbilityInfo targetAbility;
1580 CallerInfo callerInfo;
1581 callerInfo.accessToken = ACCESS_TOKEN;
1582 IDistributedSched::AccountInfo accountInfo;
1583 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1584 std::string groupId = INVALID_GROUP_ID;
1585 accountInfo.groupIdList.push_back(groupId);
1586 AAFwk::Want want;
1587 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1588 want.SetElement(element);
1589 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1590 callerInfo, accountInfo, want);
1591 EXPECT_EQ(ret, false);
1592 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 end result:" << ret << std::endl;
1593 }
1594
1595 /**
1596 * @tc.name: CheckComponentAccessPermission_004
1597 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in same account
1598 * @tc.type: FUNC
1599 */
1600 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_004, TestSize.Level1)
1601 {
1602 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 begin" << std::endl;
1603 AppExecFwk::AbilityInfo targetAbility;
1604 CallerInfo callerInfo;
1605 callerInfo.accessToken = ACCESS_TOKEN;
1606 IDistributedSched::AccountInfo accountInfo;
1607 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1608 std::string groupId = GROUP_ID;
1609 accountInfo.groupIdList.push_back(groupId);
1610 AAFwk::Want want;
1611 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1612 want.SetElement(element);
1613 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1614 callerInfo, accountInfo, want);
1615 EXPECT_EQ(ret, false);
1616 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 end result:" << ret << std::endl;
1617 }
1618
1619 /**
1620 * @tc.name: CheckComponentAccessPermission_005
1621 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in same account
1622 * @tc.type: FUNC
1623 */
1624 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_005, TestSize.Level1)
1625 {
1626 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 begin" << std::endl;
1627 AppExecFwk::AbilityInfo targetAbility;
1628 CallerInfo callerInfo;
1629 callerInfo.accessToken = ACCESS_TOKEN;
1630 IDistributedSched::AccountInfo accountInfo;
1631 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1632 std::string groupId = GROUP_ID;
1633 accountInfo.groupIdList.push_back(groupId);
1634 AAFwk::Want want;
1635 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1636 want.SetElement(element);
1637 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1638 callerInfo, accountInfo, want);
1639 EXPECT_EQ(ret, false);
1640 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 end result:" << ret << std::endl;
1641 }
1642
1643 /**
1644 * @tc.name: CheckComponentAccessPermission_006
1645 * @tc.desc: call CheckComponentAccessPermission with visible: true in same account
1646 * @tc.type: FUNC
1647 */
1648 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_006, TestSize.Level1)
1649 {
1650 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 begin" << std::endl;
1651 AppExecFwk::AbilityInfo targetAbility;
1652 targetAbility.visible = true;
1653 CallerInfo callerInfo;
1654 callerInfo.accessToken = ACCESS_TOKEN;
1655 IDistributedSched::AccountInfo accountInfo;
1656 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1657 std::string groupId = GROUP_ID;
1658 accountInfo.groupIdList.push_back(groupId);
1659 AAFwk::Want want;
1660 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1661 want.SetElement(element);
1662 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1663 callerInfo, accountInfo, want);
1664 EXPECT_EQ(ret, true);
1665 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 end result:" << ret << std::endl;
1666 }
1667
1668 /**
1669 * @tc.name: CheckComponentAccessPermission_007
1670 * @tc.desc: call CheckComponentAccessPermission with visible: false in same account
1671 * @tc.type: FUNC
1672 */
1673 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_007, TestSize.Level1)
1674 {
1675 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 begin" << std::endl;
1676 AppExecFwk::AbilityInfo targetAbility;
1677 targetAbility.visible = false;
1678 CallerInfo callerInfo;
1679 callerInfo.accessToken = ACCESS_TOKEN;
1680 IDistributedSched::AccountInfo accountInfo;
1681 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1682 std::string groupId = GROUP_ID;
1683 accountInfo.groupIdList.push_back(groupId);
1684 AAFwk::Want want;
1685 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1686 want.SetElement(element);
1687 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1688 callerInfo, accountInfo, want);
1689 EXPECT_EQ(ret, false);
1690 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 end result:" << ret << std::endl;
1691 }
1692
1693 /**
1694 * @tc.name: CheckComponentAccessPermission_008
1695 * @tc.desc: call CheckComponentAccessPermission in diff account
1696 * @tc.type: FUNC
1697 */
1698 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_008, TestSize.Level1)
1699 {
1700 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 begin" << std::endl;
1701 AppExecFwk::AbilityInfo targetAbility;
1702 CallerInfo callerInfo;
1703 callerInfo.accessToken = ACCESS_TOKEN;
1704 IDistributedSched::AccountInfo accountInfo;
1705 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1706 std::string groupId = GROUP_ID;
1707 accountInfo.groupIdList.push_back(groupId);
1708 AAFwk::Want want;
1709 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1710 want.SetElement(element);
1711 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1712 callerInfo, accountInfo, want);
1713 EXPECT_EQ(ret, false);
1714 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 end result:" << ret << std::endl;
1715 }
1716
1717 /**
1718 * @tc.name: CheckComponentAccessPermission_009
1719 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in diff account
1720 * @tc.type: FUNC
1721 */
1722 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_009, TestSize.Level1)
1723 {
1724 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 begin" << std::endl;
1725 AppExecFwk::AbilityInfo targetAbility;
1726 CallerInfo callerInfo;
1727 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1728 IDistributedSched::AccountInfo accountInfo;
1729 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1730 std::string groupId = GROUP_ID;
1731 accountInfo.groupIdList.push_back(groupId);
1732 AAFwk::Want want;
1733 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1734 want.SetElement(element);
1735 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1736 callerInfo, accountInfo, want);
1737 EXPECT_EQ(ret, false);
1738 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 end result:" << ret << std::endl;
1739 }
1740
1741 /**
1742 * @tc.name: CheckComponentAccessPermission_010
1743 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in diff account
1744 * @tc.type: FUNC
1745 */
1746 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_010, TestSize.Level1)
1747 {
1748 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 begin" << std::endl;
1749 AppExecFwk::AbilityInfo targetAbility;
1750 CallerInfo callerInfo;
1751 callerInfo.accessToken = ACCESS_TOKEN;
1752 IDistributedSched::AccountInfo accountInfo;
1753 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1754 std::string groupId = INVALID_GROUP_ID;
1755 accountInfo.groupIdList.push_back(groupId);
1756 AAFwk::Want want;
1757 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1758 want.SetElement(element);
1759 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1760 callerInfo, accountInfo, want);
1761 EXPECT_EQ(ret, false);
1762 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 end result:" << ret << std::endl;
1763 }
1764
1765 /**
1766 * @tc.name: CheckComponentAccessPermission_011
1767 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in diff account
1768 * @tc.type: FUNC
1769 */
1770 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_011, TestSize.Level1)
1771 {
1772 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 begin" << std::endl;
1773 AppExecFwk::AbilityInfo targetAbility;
1774 CallerInfo callerInfo;
1775 callerInfo.accessToken = ACCESS_TOKEN;
1776 IDistributedSched::AccountInfo accountInfo;
1777 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1778 std::string groupId = GROUP_ID;
1779 accountInfo.groupIdList.push_back(groupId);
1780 AAFwk::Want want;
1781 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1782 want.SetElement(element);
1783 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1784 callerInfo, accountInfo, want);
1785 EXPECT_EQ(ret, false);
1786 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 end result:" << ret << std::endl;
1787 }
1788
1789 /**
1790 * @tc.name: CheckComponentAccessPermission_012
1791 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in diff account
1792 * @tc.type: FUNC
1793 */
1794 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_012, TestSize.Level1)
1795 {
1796 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 begin" << std::endl;
1797 AppExecFwk::AbilityInfo targetAbility;
1798 CallerInfo callerInfo;
1799 callerInfo.accessToken = ACCESS_TOKEN;
1800 IDistributedSched::AccountInfo accountInfo;
1801 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1802 std::string groupId = GROUP_ID;
1803 accountInfo.groupIdList.push_back(groupId);
1804 AAFwk::Want want;
1805 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1806 want.SetElement(element);
1807 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1808 callerInfo, accountInfo, want);
1809 EXPECT_EQ(ret, false);
1810 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 end result:" << ret << std::endl;
1811 }
1812
1813 /**
1814 * @tc.name: CheckComponentAccessPermission_013
1815 * @tc.desc: call CheckComponentAccessPermission with visible: true in diff account
1816 * @tc.type: FUNC
1817 */
1818 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_013, TestSize.Level1)
1819 {
1820 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 begin" << std::endl;
1821 AppExecFwk::AbilityInfo targetAbility;
1822 targetAbility.visible = true;
1823 CallerInfo callerInfo;
1824 callerInfo.accessToken = ACCESS_TOKEN;
1825 IDistributedSched::AccountInfo accountInfo;
1826 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1827 std::string groupId = GROUP_ID;
1828 accountInfo.groupIdList.push_back(groupId);
1829 AAFwk::Want want;
1830 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1831 want.SetElement(element);
1832 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1833 callerInfo, accountInfo, want);
1834 EXPECT_EQ(ret, true);
1835 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 end result:" << ret << std::endl;
1836 }
1837
1838 /**
1839 * @tc.name: CheckComponentAccessPermission_014
1840 * @tc.desc: call CheckComponentAccessPermission with visible: false in diff account
1841 * @tc.type: FUNC
1842 */
1843 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_014, TestSize.Level1)
1844 {
1845 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 begin" << std::endl;
1846 AppExecFwk::AbilityInfo targetAbility;
1847 targetAbility.visible = false;
1848 CallerInfo callerInfo;
1849 callerInfo.accessToken = ACCESS_TOKEN;
1850 IDistributedSched::AccountInfo accountInfo;
1851 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1852 std::string groupId = GROUP_ID;
1853 accountInfo.groupIdList.push_back(groupId);
1854 AAFwk::Want want;
1855 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1856 want.SetElement(element);
1857 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1858 callerInfo, accountInfo, want);
1859 EXPECT_EQ(ret, false);
1860 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 end result:" << ret << std::endl;
1861 }
1862
1863 /**
1864 * @tc.name: CheckCustomPermission_001
1865 * @tc.desc: call CheckCustomPermission with no permissions
1866 * @tc.type: FUNC
1867 */
1868 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_001, TestSize.Level1)
1869 {
1870 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_001 begin" << std::endl;
1871 AppExecFwk::AbilityInfo targetAbility;
1872 CallerInfo callerInfo;
1873 callerInfo.accessToken = ACCESS_TOKEN;
1874 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
1875 EXPECT_EQ(ret, true);
1876 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_001 end result:" << ret << std::endl;
1877 }
1878
1879 /**
1880 * @tc.name: CheckCustomPermission_002
1881 * @tc.desc: call CheckCustomPermission with no permissions and invalid accessToken
1882 * @tc.type: FUNC
1883 */
1884 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_002, TestSize.Level1)
1885 {
1886 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_002 begin" << std::endl;
1887 AppExecFwk::AbilityInfo targetAbility;
1888 CallerInfo callerInfo;
1889 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1890 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
1891 EXPECT_EQ(ret, true);
1892 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_002 end result:" << ret << std::endl;
1893 }
1894
1895 /**
1896 * @tc.name: CheckCustomPermission_003
1897 * @tc.desc: call CheckCustomPermission with invalid permissions
1898 * @tc.type: FUNC
1899 */
1900 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_003, TestSize.Level1)
1901 {
1902 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_003 begin" << std::endl;
1903 AppExecFwk::AbilityInfo targetAbility;
1904 targetAbility.permissions.emplace_back(INVALID_PERMISSION_NAME);
1905 CallerInfo callerInfo;
1906 callerInfo.accessToken = ACCESS_TOKEN;
1907 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
1908 EXPECT_EQ(ret, false);
1909 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_003 end result:" << ret << std::endl;
1910 }
1911
1912 /**
1913 * @tc.name: CheckCustomPermission_004
1914 * @tc.desc: call CheckCustomPermission with invalid permissions and invalid accessToken
1915 * @tc.type: FUNC
1916 */
1917 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_004, TestSize.Level1)
1918 {
1919 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_004 begin" << std::endl;
1920 AppExecFwk::AbilityInfo targetAbility;
1921 targetAbility.permissions.emplace_back(INVALID_PERMISSION_NAME);
1922 CallerInfo callerInfo;
1923 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1924 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
1925 EXPECT_EQ(ret, false);
1926 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_004 end result:" << ret << std::endl;
1927 }
1928
1929 /**
1930 * @tc.name: CheckCustomPermission_005
1931 * @tc.desc: call CheckCustomPermission with correct permissions
1932 * @tc.type: FUNC
1933 */
1934 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_005, TestSize.Level1)
1935 {
1936 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_005 begin" << std::endl;
1937 AppExecFwk::AbilityInfo targetAbility;
1938 targetAbility.permissions.emplace_back(PERMISSION_NAME);
1939 CallerInfo callerInfo;
1940 callerInfo.accessToken = ACCESS_TOKEN;
1941 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
1942 EXPECT_EQ(ret, false);
1943 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_005 end result:" << ret << std::endl;
1944 }
1945
1946 /**
1947 * @tc.name: CheckCustomPermission_006
1948 * @tc.desc: call CheckCustomPermission with correct permissions and invalid accessToken
1949 * @tc.type: FUNC
1950 */
1951 HWTEST_F(DistributedSchedPermissionTest, CheckCustomPermission_006, TestSize.Level1)
1952 {
1953 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_006 begin" << std::endl;
1954 AppExecFwk::AbilityInfo targetAbility;
1955 targetAbility.permissions.emplace_back(PERMISSION_NAME);
1956 CallerInfo callerInfo;
1957 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1958 bool ret = DistributedSchedPermission::GetInstance().CheckCustomPermission(targetAbility, callerInfo);
1959 EXPECT_EQ(ret, false);
1960 DTEST_LOG << "DistributedSchedPermissionTest CheckCustomPermission_006 end result:" << ret << std::endl;
1961 }
1962
1963 /**
1964 * @tc.name: CheckPermission_001
1965 * @tc.desc: call CheckPermission
1966 * @tc.type: FUNC
1967 */
1968 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_001, TestSize.Level1)
1969 {
1970 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 begin" << std::endl;
1971 uint32_t accessToken = ACCESS_TOKEN;
1972 string permissionName = PERMISSION_NAME;
1973 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
1974 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1975 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 end result:" << ret << std::endl;
1976 }
1977
1978 /**
1979 * @tc.name: CheckPermission_002
1980 * @tc.desc: call CheckPermission with invalid accessToken
1981 * @tc.type: FUNC
1982 */
1983 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_002, TestSize.Level1)
1984 {
1985 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_002 begin" << std::endl;
1986 uint32_t accessToken = INVALID_ACCESS_TOKEN;
1987 string permissionName = PERMISSION_NAME;
1988 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
1989 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1990 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_002 end result:" << ret << std::endl;
1991 }
1992
1993 /**
1994 * @tc.name: CheckPermission_003
1995 * @tc.desc: call CheckPermission with invalid permission
1996 * @tc.type: FUNC
1997 */
1998 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_003, TestSize.Level1)
1999 {
2000 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_003 begin" << std::endl;
2001 uint32_t accessToken = INVALID_ACCESS_TOKEN;
2002 string permissionName = PERMISSION_NAME;
2003 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
2004 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
2005 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_003 end result:" << ret << std::endl;
2006 }
2007
2008 /**
2009 * @tc.name: from_json_001
2010 * @tc.desc: parse groupInfo from json
2011 * @tc.type: FUNC
2012 */
2013 HWTEST_F(DistributedSchedPermissionTest, FromJson_001, TestSize.Level3)
2014 {
2015 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 begin" << std::endl;
2016 GroupInfo groupInfo;
2017 nlohmann::json jsonObject = nlohmann::json {
2018 {FIELD_GROUP_NAME, MOCK_FIELD_GROUP_NAME},
2019 {FIELD_GROUP_ID, MOCK_FIELD_GROUP_ID},
2020 {FIELD_GROUP_OWNER, MOCK_FIELD_GROUP_OWNER},
2021 {FIELD_GROUP_TYPE, MOCK_FIELD_GROUP_TYPE},
2022 {FIELD_GROUP_VISIBILITY, MOCK_FIELD_GROUP_VISIBILITY}
2023 };
2024 if (jsonObject.is_discarded()) {
2025 return;
2026 }
2027 from_json(jsonObject, groupInfo);
2028 EXPECT_EQ(groupInfo.groupName, MOCK_FIELD_GROUP_NAME);
2029 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 end" << std::endl;
2030 }
2031
2032 /**
2033 * @tc.name: from_json_002
2034 * @tc.desc: parse groupInfo from json with invalid params
2035 * @tc.type: FUNC
2036 */
2037 HWTEST_F(DistributedSchedPermissionTest, FromJson_002, TestSize.Level3)
2038 {
2039 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 begin" << std::endl;
2040 GroupInfo groupInfo;
2041 nlohmann::json jsonObject;
2042 if (jsonObject.is_discarded()) {
2043 return;
2044 }
2045 from_json(jsonObject, groupInfo);
2046 EXPECT_EQ(groupInfo.groupName, "");
2047 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 end " << std::endl;
2048 }
2049 } // namespace DistributedSchedule
2050 } // namespace OHOS