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