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 .ver = 1,
788 .userID = 1,
789 .bundleName = "com.ohos.dms_test",
790 .instIndex = 1,
791 .tokenID = 0x20100000,
792 .tokenAttr = 0
793 };
794
795 Security::AccessToken::PermissionStatus infoManagerTestState = {
796 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
797 .grantStatus = PermissionState::PERMISSION_GRANTED, // first grant
798 .grantFlag = PermissionFlag::PERMISSION_SYSTEM_FIXED};
799 std::vector<Security::AccessToken::PermissionStatus> permStateList;
800 permStateList.emplace_back(infoManagerTestState);
801
802 HapTokenInfoForSync remoteTokenInfo = {
803 .baseInfo = baseInfo,
804 .permStateList = permStateList
805 };
806
807 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
808 ASSERT_EQ(result, RET_SUCCESS);
809
810 // Get local map token ID
811 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
812 ASSERT_NE(mapID, 0);
813
814 AppExecFwk::AbilityInfo targetAbility;
815 CallerInfo callerInfo;
816 callerInfo.extraInfoJson[DMS_VERSION_ID] = DMS_VERSION;
817 callerInfo.sourceDeviceId = deviceId_;
818 callerInfo.accessToken = 0x20100000;
819 AAFwk::Want want;
820 bool ret = DistributedSchedPermission::GetInstance().CheckBackgroundPermission(targetAbility, callerInfo, want,
821 false);
822 EXPECT_FALSE(ret);
823 DTEST_LOG << "DistributedSchedPermissionTest CheckBackgroundPermission_007 end ret:" << ret << std::endl;
824 }
825
826 /**
827 * @tc.name: CheckMinApiVersion_001
828 * @tc.desc: input invalid params
829 * @tc.type: FUNC
830 * @tc.require: issueI5T6GJ
831 */
832 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_001, TestSize.Level3)
833 {
834 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 begin" << std::endl;
835 AppExecFwk::AbilityInfo targetAbility;
836 targetAbility.isStageBasedModel = true;
837 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
838 EXPECT_FALSE(ret);
839 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_001 end ret:" << ret << std::endl;
840 }
841
842 /**
843 * @tc.name: CheckMinApiVersion_002
844 * @tc.desc: input invalid params
845 * @tc.type: FUNC
846 * @tc.require: issueI5T6GJ
847 */
848 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_002, TestSize.Level3)
849 {
850 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 begin" << std::endl;
851 AppExecFwk::AbilityInfo targetAbility;
852 targetAbility.type = AppExecFwk::AbilityType::PAGE;
853 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
854 EXPECT_FALSE(ret);
855 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_002 end ret:" << ret << std::endl;
856 }
857
858 /**
859 * @tc.name: CheckMinApiVersion_003
860 * @tc.desc: input invalid params
861 * @tc.type: FUNC
862 * @tc.require: issueI5T6GJ
863 */
864 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_003, TestSize.Level3)
865 {
866 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 begin" << std::endl;
867 AppExecFwk::AbilityInfo targetAbility;
868 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
869 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility, API_VERSION);
870 EXPECT_FALSE(ret);
871 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_003 end ret:" << ret << std::endl;
872 }
873
874 /**
875 * @tc.name: CheckMinApiVersion_004
876 * @tc.desc: input invalid params
877 * @tc.type: FUNC
878 * @tc.require: issueI5T6GJ
879 */
880 HWTEST_F(DistributedSchedPermissionTest, CheckMinApiVersion_004, TestSize.Level3)
881 {
882 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 begin" << std::endl;
883 AppExecFwk::AbilityInfo targetAbility;
884 targetAbility.type = AppExecFwk::AbilityType::SERVICE;
885 bool ret = DistributedSchedPermission::GetInstance().CheckMinApiVersion(targetAbility,
886 FA_MODULE_ALLOW_MIN_API_VERSION);
887 EXPECT_TRUE(ret);
888 DTEST_LOG << "DistributedSchedPermissionTest CheckMinApiVersion_004 end ret:" << ret << std::endl;
889 }
890
891 /**
892 * @tc.name: CheckTargetAbilityVisible_001
893 * @tc.desc: input invalid params
894 * @tc.type: FUNC
895 * @tc.require: issueI5T6GJ
896 */
897 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_001, TestSize.Level3)
898 {
899 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 begin" << std::endl;
900 AppExecFwk::AbilityInfo targetAbility;
901 targetAbility.visible = true;
902 CallerInfo callerInfo;
903 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
904 EXPECT_TRUE(ret);
905 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_001 end ret:" << ret << std::endl;
906 }
907
908 /**
909 * @tc.name: CheckTargetAbilityVisible_002
910 * @tc.desc: input invalid params
911 * @tc.type: FUNC
912 * @tc.require: issueI5T6GJ
913 */
914 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_002, TestSize.Level3)
915 {
916 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 begin" << std::endl;
917 AppExecFwk::AbilityInfo targetAbility;
918 CallerInfo callerInfo;
919 callerInfo.sourceDeviceId = "";
920 callerInfo.accessToken = GetSelfTokenID();
921 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
922 EXPECT_FALSE(ret);
923 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_002 end ret:" << ret << std::endl;
924 }
925
926 /**
927 * @tc.name: CheckTargetAbilityVisible_003
928 * @tc.desc: input invalid params
929 * @tc.type: FUNC
930 * @tc.require: issueI5T6GJ
931 */
932 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_003, TestSize.Level3)
933 {
934 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 begin" << std::endl;
935 AppExecFwk::AbilityInfo targetAbility;
936 CallerInfo callerInfo;
937 callerInfo.sourceDeviceId = "deviceId_";
938 callerInfo.accessToken = GetSelfTokenID();
939 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
940 EXPECT_FALSE(ret);
941 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_003 end ret:" << ret << std::endl;
942 }
943
944 #ifdef TOKEN_SYNC_ENABLE
945 /**
946 * @tc.name: CheckTargetAbilityVisible_004
947 * @tc.desc: check CheckTargetAbilityVisible
948 * @tc.type: FUNC
949 * @tc.require: issueI5T6GJ
950 */
951 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_004, TestSize.Level3)
952 {
953 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 begin" << std::endl;
954 ASSERT_NE(DnetworkAdapter::GetInstance(), nullptr);
955 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
956 std::string deviceId = udid;
957 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
958 HapTokenInfo baseInfo = {
959 .ver = 1,
960 .userID = 1,
961 .bundleName = "com.ohos.dms_test",
962 .instIndex = 1,
963 .tokenID = 0x20100000,
964 .tokenAttr = 0
965 };
966
967 Security::AccessToken::PermissionStatus infoManagerTestState = {
968 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
969 .grantStatus = PermissionState::PERMISSION_GRANTED, // first grant
970 .grantFlag = PermissionFlag::PERMISSION_SYSTEM_FIXED};
971 std::vector<Security::AccessToken::PermissionStatus> permStateList;
972 permStateList.emplace_back(infoManagerTestState);
973
974 HapTokenInfoForSync remoteTokenInfo = {
975 .baseInfo = baseInfo,
976 .permStateList = permStateList
977 };
978
979 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
980 ASSERT_EQ(result, RET_SUCCESS);
981
982 // Get local map token ID
983 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
984 ASSERT_NE(mapID, 0);
985
986 AppExecFwk::AbilityInfo targetAbility;
987 CallerInfo callerInfo;
988 callerInfo.sourceDeviceId = deviceId_;
989 callerInfo.accessToken = 0x20100000;
990 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
991 EXPECT_TRUE(ret);
992 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_004 end ret:" << ret << std::endl;
993 }
994
995 /**
996 * @tc.name: CheckTargetAbilityVisible_005
997 * @tc.desc: check CheckTargetAbilityVisible
998 * @tc.type: FUNC
999 * @tc.require: issueI5T6GJ
1000 */
1001 HWTEST_F(DistributedSchedPermissionTest, CheckTargetAbilityVisible_005, TestSize.Level3)
1002 {
1003 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 begin" << std::endl;
1004 ASSERT_NE(DnetworkAdapter::GetInstance(), nullptr);
1005 std::string udid = DnetworkAdapter::GetInstance()->GetUdidByNetworkId(deviceId_);
1006 std::string deviceId = udid;
1007 AccessTokenKit::DeleteRemoteToken(deviceId, 0x20100000);
1008 HapTokenInfo baseInfo = {
1009 .ver = 1,
1010 .userID = 1,
1011 .bundleName = "com.ohos.dms_test",
1012 .instIndex = 1,
1013 .tokenID = 0x20100000,
1014 .tokenAttr = 0
1015 };
1016
1017 Security::AccessToken::PermissionStatus infoManagerTestState = {
1018 .permissionName = "ohos.permission.START_INVISIBLE_ABILITY",
1019 .grantStatus = PermissionState::PERMISSION_DENIED,
1020 .grantFlag = PermissionFlag::PERMISSION_SYSTEM_FIXED};
1021 std::vector<Security::AccessToken::PermissionStatus> permStateList;
1022 permStateList.emplace_back(infoManagerTestState);
1023
1024 HapTokenInfoForSync remoteTokenInfo = {
1025 .baseInfo = baseInfo,
1026 .permStateList = permStateList
1027 };
1028
1029 int result = AccessTokenKit::SetRemoteHapTokenInfo(deviceId, remoteTokenInfo);
1030 ASSERT_EQ(result, RET_SUCCESS);
1031
1032 // Get local map token ID
1033 AccessTokenID mapID = AccessTokenKit::AllocLocalTokenID(deviceId_, 0x20100000);
1034 ASSERT_NE(mapID, 0);
1035
1036 AppExecFwk::AbilityInfo targetAbility;
1037 CallerInfo callerInfo;
1038 callerInfo.sourceDeviceId = deviceId_;
1039 callerInfo.accessToken = 0x20100000;
1040 bool ret = DistributedSchedPermission::GetInstance().CheckTargetAbilityVisible(targetAbility, callerInfo);
1041 EXPECT_FALSE(ret);
1042 DTEST_LOG << "DistributedSchedPermissionTest CheckTargetAbilityVisible_005 end ret:" << ret << std::endl;
1043 }
1044 #endif
1045
1046 /**
1047 * @tc.name: GetAccountInfo_001
1048 * @tc.desc: call GetAccountInfo with empty networkId
1049 * @tc.type: FUNC
1050 * @tc.require: I5RWIV
1051 */
1052 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_001, TestSize.Level3)
1053 {
1054 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 begin" << std::endl;
1055 std::string remoteNetworkId;
1056 CallerInfo callerInfo;
1057 IDistributedSched::AccountInfo accountInfo;
1058 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1059 remoteNetworkId, callerInfo, accountInfo);
1060 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1061 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_001 end result:" << ret << std::endl;
1062 }
1063
1064 /**
1065 * @tc.name: GetAccountInfo_002
1066 * @tc.desc: call GetAccountInfo with invalid networkId
1067 * @tc.type: FUNC
1068 * @tc.require: I5RWIV
1069 */
1070 HWTEST_F(DistributedSchedPermissionTest, GetAccountInfo_002, TestSize.Level3)
1071 {
1072 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 begin" << std::endl;
1073 std::string remoteNetworkId = "0";
1074 CallerInfo callerInfo;
1075 IDistributedSched::AccountInfo accountInfo;
1076 int32_t ret = DistributedSchedPermission::GetInstance().GetAccountInfo(
1077 remoteNetworkId, callerInfo, accountInfo);
1078 EXPECT_EQ(ret, ERR_NULL_OBJECT);
1079 DTEST_LOG << "DistributedSchedPermissionTest GetAccountInfo_002 end result:" << ret << std::endl;
1080 }
1081
1082 /**
1083 * @tc.name: GetRelatedGroups_001
1084 * @tc.desc: call GetRelatedGroups with empty bundleNames
1085 * @tc.type: FUNC
1086 * @tc.require: I5RWIV
1087 */
1088 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_001, TestSize.Level3)
1089 {
1090 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 begin" << std::endl;
1091 std::string udid;
1092 std::vector<std::string> bundleNames;
1093 IDistributedSched::AccountInfo accountInfo;
1094 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1095 udid, bundleNames, accountInfo);
1096 EXPECT_EQ(ret, false);
1097 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1098 }
1099
1100 /**
1101 * @tc.name: GetRelatedGroups_002
1102 * @tc.desc: call GetRelatedGroups with invalid bundleNames
1103 * @tc.type: FUNC
1104 * @tc.require: I5RWIV
1105 */
1106 HWTEST_F(DistributedSchedPermissionTest, GetRelatedGroups_002, TestSize.Level3)
1107 {
1108 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 begin" << std::endl;
1109 std::string udid = "0";
1110 std::vector<std::string> bundleNames = {"mock.bundle1", "mock.bundle2"};
1111 IDistributedSched::AccountInfo accountInfo;
1112 bool ret = DistributedSchedPermission::GetInstance().GetRelatedGroups(
1113 udid, bundleNames, accountInfo);
1114 EXPECT_EQ(ret, false);
1115 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1116 }
1117
1118 /**
1119 * @tc.name: ParseGroupInfos_001
1120 * @tc.desc: call ParseGroupInfos with empty returnGroupStr
1121 * @tc.type: FUNC
1122 * @tc.require: I5RWIV
1123 */
1124 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_001, TestSize.Level3)
1125 {
1126 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_001 begin" << std::endl;
1127 std::string returnGroupStr;
1128 std::vector<GroupInfo> groupInfos;
1129 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1130 returnGroupStr, groupInfos);
1131 EXPECT_EQ(ret, false);
1132 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_001 end result:" << ret << std::endl;
1133 }
1134
1135 /**
1136 * @tc.name: ParseGroupInfos_002
1137 * @tc.desc: call ParseGroupInfos with invalid returnGroupStr
1138 * @tc.type: FUNC
1139 * @tc.require: I5RWIV
1140 */
1141 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_002, TestSize.Level3)
1142 {
1143 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_002 begin" << std::endl;
1144 std::string returnGroupStr = "mockInvalidGroup";
1145 std::vector<GroupInfo> groupInfos;
1146 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1147 returnGroupStr, groupInfos);
1148 EXPECT_EQ(ret, false);
1149 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_002 end result:" << ret << std::endl;
1150 }
1151
1152 /**
1153 * @tc.name: ParseGroupInfos_003
1154 * @tc.desc: call ParseGroupInfos
1155 * @tc.type: FUNC
1156 * @tc.require: I5RWIV
1157 */
1158 HWTEST_F(DistributedSchedPermissionTest, ParseGroupInfos_003, TestSize.Level3)
1159 {
1160 DTEST_LOG << "DistributedSchedPermissionTest ParseGroupInfos_003 begin" << std::endl;
1161 std::string returnGroupStr = "[{\"groupName\":\"mockGroupName\",\"groupId\":\"mockGroupId\",";
1162 returnGroupStr += "\"groupOwner\":\"mockGroupOwner\",\"groupType\":0,\"groupVisibility\":0}]";
1163 std::vector<GroupInfo> groupInfos;
1164 bool ret = DistributedSchedPermission::GetInstance().ParseGroupInfos(
1165 returnGroupStr, groupInfos);
1166 EXPECT_EQ(ret, true);
1167 DTEST_LOG << "DistributedSchedPermissionTest GetRelatedGroups_003 end result:" << ret << std::endl;
1168 }
1169
1170 /**
1171 * @tc.name: IsFoundationCall_001
1172 * @tc.desc: call IsFoundationCall not from foundation
1173 * @tc.type: FUNC
1174 * @tc.require: I5RWIV
1175 */
1176 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_001, TestSize.Level3)
1177 {
1178 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 begin" << std::endl;
1179 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1180 EXPECT_EQ(ret, false);
1181 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_001 end result:" << ret << std::endl;
1182 }
1183
1184 /**
1185 * @tc.name: IsFoundationCall_002
1186 * @tc.desc: call IsFoundationCall from foundation
1187 * @tc.type: FUNC
1188 * @tc.require: I5RWIV
1189 */
1190 HWTEST_F(DistributedSchedPermissionTest, IsFoundationCall_002, TestSize.Level3)
1191 {
1192 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 begin" << std::endl;
1193 DistributedSchedUtil::MockProcess(FOUNDATION_PROCESS_NAME);
1194 bool ret = DistributedSchedPermission::GetInstance().IsFoundationCall();
1195 EXPECT_EQ(ret, true);
1196 DTEST_LOG << "DistributedSchedPermissionTest IsFoundationCall_002 end result:" << ret << std::endl;
1197 }
1198
1199 /**
1200 * @tc.name: CheckAccountAccessPermission_001
1201 * @tc.desc: call CheckAccountAccessPermission in same account
1202 * @tc.type: FUNC
1203 */
1204 HWTEST_F(DistributedSchedPermissionTest, CheckAccountAccessPermission_001, TestSize.Level1)
1205 {
1206 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 begin" << std::endl;
1207 CallerInfo callerInfo;
1208 IDistributedSched::AccountInfo accountInfo;
1209 string targetBundle = BUNDLE_NAME;
1210 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1211 callerInfo, accountInfo, targetBundle);
1212 EXPECT_EQ(ret, false);
1213 DTEST_LOG << "DistributedSchedPermissionTest CheckAccountAccessPermission_001 end result:" << ret << std::endl;
1214 }
1215
1216 /**
1217 * @tc.name: CheckComponentAccessPermission_001
1218 * @tc.desc: call CheckComponentAccessPermission in same account
1219 * @tc.type: FUNC
1220 */
1221 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_001, TestSize.Level1)
1222 {
1223 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 begin" << std::endl;
1224 AppExecFwk::AbilityInfo targetAbility;
1225 CallerInfo callerInfo;
1226 callerInfo.accessToken = ACCESS_TOKEN;
1227 IDistributedSched::AccountInfo accountInfo;
1228 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1229 std::string groupId = GROUP_ID;
1230 accountInfo.groupIdList.push_back(groupId);
1231 AAFwk::Want want;
1232 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1233 want.SetElement(element);
1234 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1235 callerInfo, accountInfo, want);
1236 EXPECT_EQ(ret, false);
1237 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_001 end result:" << ret << std::endl;
1238 }
1239
1240 /**
1241 * @tc.name: CheckComponentAccessPermission_002
1242 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in same account
1243 * @tc.type: FUNC
1244 */
1245 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_002, TestSize.Level1)
1246 {
1247 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 begin" << std::endl;
1248 AppExecFwk::AbilityInfo targetAbility;
1249 CallerInfo callerInfo;
1250 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1251 IDistributedSched::AccountInfo accountInfo;
1252 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1253 std::string groupId = GROUP_ID;
1254 accountInfo.groupIdList.push_back(groupId);
1255 AAFwk::Want want;
1256 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1257 want.SetElement(element);
1258 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1259 callerInfo, accountInfo, want);
1260 EXPECT_EQ(ret, false);
1261 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_002 end result:" << ret << std::endl;
1262 }
1263
1264 /**
1265 * @tc.name: CheckComponentAccessPermission_003
1266 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in same account
1267 * @tc.type: FUNC
1268 */
1269 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_003, TestSize.Level1)
1270 {
1271 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 begin" << std::endl;
1272 AppExecFwk::AbilityInfo targetAbility;
1273 CallerInfo callerInfo;
1274 callerInfo.accessToken = ACCESS_TOKEN;
1275 IDistributedSched::AccountInfo accountInfo;
1276 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1277 std::string groupId = INVALID_GROUP_ID;
1278 accountInfo.groupIdList.push_back(groupId);
1279 AAFwk::Want want;
1280 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1281 want.SetElement(element);
1282 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1283 callerInfo, accountInfo, want);
1284 EXPECT_EQ(ret, false);
1285 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_003 end result:" << ret << std::endl;
1286 }
1287
1288 /**
1289 * @tc.name: CheckComponentAccessPermission_004
1290 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in same account
1291 * @tc.type: FUNC
1292 */
1293 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_004, TestSize.Level1)
1294 {
1295 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 begin" << std::endl;
1296 AppExecFwk::AbilityInfo targetAbility;
1297 CallerInfo callerInfo;
1298 callerInfo.accessToken = ACCESS_TOKEN;
1299 IDistributedSched::AccountInfo accountInfo;
1300 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1301 std::string groupId = GROUP_ID;
1302 accountInfo.groupIdList.push_back(groupId);
1303 AAFwk::Want want;
1304 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1305 want.SetElement(element);
1306 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1307 callerInfo, accountInfo, want);
1308 EXPECT_EQ(ret, false);
1309 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_004 end result:" << ret << std::endl;
1310 }
1311
1312 /**
1313 * @tc.name: CheckComponentAccessPermission_005
1314 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in same account
1315 * @tc.type: FUNC
1316 */
1317 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_005, TestSize.Level1)
1318 {
1319 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 begin" << std::endl;
1320 AppExecFwk::AbilityInfo targetAbility;
1321 CallerInfo callerInfo;
1322 callerInfo.accessToken = ACCESS_TOKEN;
1323 IDistributedSched::AccountInfo accountInfo;
1324 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1325 std::string groupId = GROUP_ID;
1326 accountInfo.groupIdList.push_back(groupId);
1327 AAFwk::Want want;
1328 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1329 want.SetElement(element);
1330 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1331 callerInfo, accountInfo, want);
1332 EXPECT_EQ(ret, false);
1333 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_005 end result:" << ret << std::endl;
1334 }
1335
1336 /**
1337 * @tc.name: CheckComponentAccessPermission_006
1338 * @tc.desc: call CheckComponentAccessPermission with visible: true in same account
1339 * @tc.type: FUNC
1340 */
1341 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_006, TestSize.Level1)
1342 {
1343 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 begin" << std::endl;
1344 AppExecFwk::AbilityInfo targetAbility;
1345 targetAbility.visible = true;
1346 CallerInfo callerInfo;
1347 callerInfo.accessToken = ACCESS_TOKEN;
1348 IDistributedSched::AccountInfo accountInfo;
1349 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1350 std::string groupId = GROUP_ID;
1351 accountInfo.groupIdList.push_back(groupId);
1352 AAFwk::Want want;
1353 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1354 want.SetElement(element);
1355 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1356 callerInfo, accountInfo, want);
1357 EXPECT_EQ(ret, true);
1358 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_006 end result:" << ret << std::endl;
1359 }
1360
1361 /**
1362 * @tc.name: CheckComponentAccessPermission_007
1363 * @tc.desc: call CheckComponentAccessPermission with visible: false in same account
1364 * @tc.type: FUNC
1365 */
1366 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_007, TestSize.Level1)
1367 {
1368 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 begin" << std::endl;
1369 AppExecFwk::AbilityInfo targetAbility;
1370 targetAbility.visible = false;
1371 CallerInfo callerInfo;
1372 callerInfo.accessToken = ACCESS_TOKEN;
1373 IDistributedSched::AccountInfo accountInfo;
1374 accountInfo.accountType = IDistributedSched::SAME_ACCOUNT_TYPE;
1375 std::string groupId = GROUP_ID;
1376 accountInfo.groupIdList.push_back(groupId);
1377 AAFwk::Want want;
1378 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1379 want.SetElement(element);
1380 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1381 callerInfo, accountInfo, want);
1382 EXPECT_EQ(ret, false);
1383 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_007 end result:" << ret << std::endl;
1384 }
1385
1386 /**
1387 * @tc.name: CheckComponentAccessPermission_008
1388 * @tc.desc: call CheckComponentAccessPermission in diff account
1389 * @tc.type: FUNC
1390 */
1391 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_008, TestSize.Level1)
1392 {
1393 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 begin" << std::endl;
1394 AppExecFwk::AbilityInfo targetAbility;
1395 CallerInfo callerInfo;
1396 callerInfo.accessToken = ACCESS_TOKEN;
1397 IDistributedSched::AccountInfo accountInfo;
1398 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1399 std::string groupId = GROUP_ID;
1400 accountInfo.groupIdList.push_back(groupId);
1401 AAFwk::Want want;
1402 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1403 want.SetElement(element);
1404 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1405 callerInfo, accountInfo, want);
1406 EXPECT_EQ(ret, false);
1407 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_008 end result:" << ret << std::endl;
1408 }
1409
1410 /**
1411 * @tc.name: CheckComponentAccessPermission_009
1412 * @tc.desc: call CheckComponentAccessPermission with invalid accessToken in diff account
1413 * @tc.type: FUNC
1414 */
1415 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_009, TestSize.Level1)
1416 {
1417 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 begin" << std::endl;
1418 AppExecFwk::AbilityInfo targetAbility;
1419 CallerInfo callerInfo;
1420 callerInfo.accessToken = INVALID_ACCESS_TOKEN;
1421 IDistributedSched::AccountInfo accountInfo;
1422 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1423 std::string groupId = GROUP_ID;
1424 accountInfo.groupIdList.push_back(groupId);
1425 AAFwk::Want want;
1426 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1427 want.SetElement(element);
1428 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1429 callerInfo, accountInfo, want);
1430 EXPECT_EQ(ret, false);
1431 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_009 end result:" << ret << std::endl;
1432 }
1433
1434 /**
1435 * @tc.name: CheckComponentAccessPermission_010
1436 * @tc.desc: call CheckComponentAccessPermission with invalid groupId in diff account
1437 * @tc.type: FUNC
1438 */
1439 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_010, TestSize.Level1)
1440 {
1441 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 begin" << std::endl;
1442 AppExecFwk::AbilityInfo targetAbility;
1443 CallerInfo callerInfo;
1444 callerInfo.accessToken = ACCESS_TOKEN;
1445 IDistributedSched::AccountInfo accountInfo;
1446 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1447 std::string groupId = INVALID_GROUP_ID;
1448 accountInfo.groupIdList.push_back(groupId);
1449 AAFwk::Want want;
1450 AppExecFwk::ElementName element("", BUNDLE_NAME, ABILITY_NAME);
1451 want.SetElement(element);
1452 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1453 callerInfo, accountInfo, want);
1454 EXPECT_EQ(ret, false);
1455 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_010 end result:" << ret << std::endl;
1456 }
1457
1458 /**
1459 * @tc.name: CheckComponentAccessPermission_011
1460 * @tc.desc: call CheckComponentAccessPermission with invalid bundleName in diff account
1461 * @tc.type: FUNC
1462 */
1463 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_011, TestSize.Level1)
1464 {
1465 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 begin" << std::endl;
1466 AppExecFwk::AbilityInfo targetAbility;
1467 CallerInfo callerInfo;
1468 callerInfo.accessToken = ACCESS_TOKEN;
1469 IDistributedSched::AccountInfo accountInfo;
1470 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1471 std::string groupId = GROUP_ID;
1472 accountInfo.groupIdList.push_back(groupId);
1473 AAFwk::Want want;
1474 AppExecFwk::ElementName element("", INVALID_BUNDLE_NAME, ABILITY_NAME);
1475 want.SetElement(element);
1476 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1477 callerInfo, accountInfo, want);
1478 EXPECT_EQ(ret, false);
1479 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_011 end result:" << ret << std::endl;
1480 }
1481
1482 /**
1483 * @tc.name: CheckComponentAccessPermission_012
1484 * @tc.desc: call CheckComponentAccessPermission with invalid abilityName in diff account
1485 * @tc.type: FUNC
1486 */
1487 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_012, TestSize.Level1)
1488 {
1489 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 begin" << std::endl;
1490 AppExecFwk::AbilityInfo targetAbility;
1491 CallerInfo callerInfo;
1492 callerInfo.accessToken = ACCESS_TOKEN;
1493 IDistributedSched::AccountInfo accountInfo;
1494 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1495 std::string groupId = GROUP_ID;
1496 accountInfo.groupIdList.push_back(groupId);
1497 AAFwk::Want want;
1498 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1499 want.SetElement(element);
1500 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1501 callerInfo, accountInfo, want);
1502 EXPECT_EQ(ret, false);
1503 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_012 end result:" << ret << std::endl;
1504 }
1505
1506 /**
1507 * @tc.name: CheckComponentAccessPermission_013
1508 * @tc.desc: call CheckComponentAccessPermission with visible: true in diff account
1509 * @tc.type: FUNC
1510 */
1511 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_013, TestSize.Level1)
1512 {
1513 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 begin" << std::endl;
1514 AppExecFwk::AbilityInfo targetAbility;
1515 targetAbility.visible = true;
1516 CallerInfo callerInfo;
1517 callerInfo.accessToken = ACCESS_TOKEN;
1518 IDistributedSched::AccountInfo accountInfo;
1519 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1520 std::string groupId = GROUP_ID;
1521 accountInfo.groupIdList.push_back(groupId);
1522 AAFwk::Want want;
1523 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1524 want.SetElement(element);
1525 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1526 callerInfo, accountInfo, want);
1527 EXPECT_EQ(ret, true);
1528 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_013 end result:" << ret << std::endl;
1529 }
1530
1531 /**
1532 * @tc.name: CheckComponentAccessPermission_014
1533 * @tc.desc: call CheckComponentAccessPermission with visible: false in diff account
1534 * @tc.type: FUNC
1535 */
1536 HWTEST_F(DistributedSchedPermissionTest, CheckComponentAccessPermission_014, TestSize.Level1)
1537 {
1538 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 begin" << std::endl;
1539 AppExecFwk::AbilityInfo targetAbility;
1540 targetAbility.visible = false;
1541 CallerInfo callerInfo;
1542 callerInfo.accessToken = ACCESS_TOKEN;
1543 IDistributedSched::AccountInfo accountInfo;
1544 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1545 std::string groupId = GROUP_ID;
1546 accountInfo.groupIdList.push_back(groupId);
1547 AAFwk::Want want;
1548 AppExecFwk::ElementName element("", BUNDLE_NAME, INVALID_ABILITY_NAME);
1549 want.SetElement(element);
1550 bool ret = DistributedSchedPermission::GetInstance().CheckComponentAccessPermission(targetAbility,
1551 callerInfo, accountInfo, want);
1552 EXPECT_EQ(ret, false);
1553 DTEST_LOG << "DistributedSchedPermissionTest CheckComponentAccessPermission_014 end result:" << ret << std::endl;
1554 }
1555
1556 /**
1557 * @tc.name: CheckPermission_001
1558 * @tc.desc: call CheckPermission
1559 * @tc.type: FUNC
1560 */
1561 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_001, TestSize.Level1)
1562 {
1563 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 begin" << std::endl;
1564 uint32_t accessToken = ACCESS_TOKEN;
1565 string permissionName = PERMISSION_NAME;
1566 int32_t ret = DistributedSchedPermission::GetInstance().CheckPermission(accessToken, permissionName);
1567 EXPECT_EQ(ret, DMS_PERMISSION_DENIED);
1568 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_001 end result:" << ret << std::endl;
1569 }
1570
1571 /**
1572 * @tc.name: CheckPermission_002
1573 * @tc.desc: call CheckPermission with invalid accessToken
1574 * @tc.type: FUNC
1575 */
1576 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_002, TestSize.Level1)
1577 {
1578 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_002 begin" << std::endl;
1579 uint32_t accessToken = INVALID_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_002 end result:" << ret << std::endl;
1584 }
1585
1586 /**
1587 * @tc.name: CheckPermission_003
1588 * @tc.desc: call CheckPermission with invalid permission
1589 * @tc.type: FUNC
1590 */
1591 HWTEST_F(DistributedSchedPermissionTest, CheckPermission_003, TestSize.Level1)
1592 {
1593 DTEST_LOG << "DistributedSchedPermissionTest CheckPermission_003 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_003 end result:" << ret << std::endl;
1599 }
1600
1601 /**
1602 * @tc.name: from_json_001
1603 * @tc.desc: parse groupInfo from json
1604 * @tc.type: FUNC
1605 */
1606 HWTEST_F(DistributedSchedPermissionTest, FromJson_001, TestSize.Level3)
1607 {
1608 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 begin" << std::endl;
1609 GroupInfo groupInfo;
1610 nlohmann::json jsonObject = nlohmann::json {
1611 {FIELD_GROUP_NAME, MOCK_FIELD_GROUP_NAME},
1612 {FIELD_GROUP_ID, MOCK_FIELD_GROUP_ID},
1613 {FIELD_GROUP_OWNER, MOCK_FIELD_GROUP_OWNER},
1614 {FIELD_GROUP_TYPE, MOCK_FIELD_GROUP_TYPE},
1615 {FIELD_GROUP_VISIBILITY, MOCK_FIELD_GROUP_VISIBILITY}
1616 };
1617 ASSERT_NE(true, jsonObject.is_discarded());
1618 from_json(jsonObject, groupInfo);
1619 EXPECT_EQ(groupInfo.groupName, MOCK_FIELD_GROUP_NAME);
1620 DTEST_LOG << "DistributedSchedPermissionTest FromJson_001 end" << std::endl;
1621 }
1622
1623 /**
1624 * @tc.name: from_json_002
1625 * @tc.desc: parse groupInfo from json with invalid params
1626 * @tc.type: FUNC
1627 */
1628 HWTEST_F(DistributedSchedPermissionTest, FromJson_002, TestSize.Level3)
1629 {
1630 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 begin" << std::endl;
1631 GroupInfo groupInfo;
1632 nlohmann::json jsonObject;
1633 ASSERT_NE(true, jsonObject.is_discarded());
1634 from_json(jsonObject, groupInfo);
1635 EXPECT_EQ(groupInfo.groupName, "");
1636 DTEST_LOG << "DistributedSchedPermissionTest FromJson_002 end " << std::endl;
1637 }
1638
1639 /**
1640 * @tc.name: MarkUriPermission_001
1641 * @tc.desc: parse groupInfo from json with invalid params
1642 * @tc.type: FUNC
1643 */
1644 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_001, TestSize.Level3)
1645 {
1646 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_001 begin" << std::endl;
1647 AAFwk::Want want;
1648 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
1649 want.SetUri("file://ohos.dms.ets/data/test_B");
1650 DistributedSchedPermission::GetInstance().MarkUriPermission(want, 0);
1651 CallerInfo callerInfo;
1652 callerInfo.accessToken = ACCESS_TOKEN;
1653 IDistributedSched::AccountInfo accountInfo;
1654 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1655 std::string groupId = INVALID_GROUP_ID;
1656 accountInfo.groupIdList.push_back(groupId);
1657 string targetBundle = INVALID_BUNDLE_NAME;
1658 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1659 callerInfo, accountInfo, targetBundle);
1660 EXPECT_EQ(ret, false);
1661 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_001 end " << std::endl;
1662 }
1663
1664 /**
1665 * @tc.name: MarkUriPermission_002
1666 * @tc.desc: parse groupInfo from json with invalid params
1667 * @tc.type: FUNC
1668 */
1669 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_002, TestSize.Level3)
1670 {
1671 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_002 begin" << std::endl;
1672 AAFwk::Want want;
1673 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
1674 want.SetUri("file://com.ohos.mms/data/test_B");
1675 DistributedSchedPermission::GetInstance().MarkUriPermission(want, 0);
1676 CallerInfo callerInfo;
1677 callerInfo.accessToken = ACCESS_TOKEN;
1678 IDistributedSched::AccountInfo accountInfo;
1679 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1680 std::string groupId = INVALID_GROUP_ID;
1681 accountInfo.groupIdList.push_back(groupId);
1682 string targetBundle = INVALID_BUNDLE_NAME;
1683 bool ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1684 callerInfo, accountInfo, targetBundle);
1685 EXPECT_EQ(ret, false);
1686 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_002 end " << std::endl;
1687 }
1688
1689 /**
1690 * @tc.name: MarkUriPermission_003
1691 * @tc.desc: parse groupInfo from json with invalid params
1692 * @tc.type: FUNC
1693 */
1694 HWTEST_F(DistributedSchedPermissionTest, MarkUriPermission_003, TestSize.Level3)
1695 {
1696 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_003 begin" << std::endl;
1697 AAFwk::Want want;
1698 want.AddFlags(want.FLAG_AUTH_READ_URI_PERMISSION);
1699 want.SetUri("file://com.ohos.mms/data/test_B");
1700 const std::string bundleName = "com.ohos.mms";
1701 uint16_t bundleNameId = 0;
1702 int32_t ret = BundleManagerInternal::GetBundleNameId(bundleName, bundleNameId);
1703 EXPECT_EQ(ret, CAN_NOT_FOUND_ABILITY_ERR);
1704 DistributedSchedPermission::GetInstance().MarkUriPermission(want, bundleNameId);
1705 CallerInfo callerInfo;
1706 callerInfo.accessToken = ACCESS_TOKEN;
1707 IDistributedSched::AccountInfo accountInfo;
1708 accountInfo.accountType = IDistributedSched::DIFF_ACCOUNT_TYPE;
1709 std::string groupId = INVALID_GROUP_ID;
1710 accountInfo.groupIdList.push_back(groupId);
1711 string targetBundle = INVALID_BUNDLE_NAME;
1712 ret = DistributedSchedPermission::GetInstance().CheckAccountAccessPermission(
1713 callerInfo, accountInfo, targetBundle);
1714 EXPECT_EQ(ret, false);
1715 DTEST_LOG << "DistributedSchedPermissionTest MarkUriPermission_003 end " << std::endl;
1716 }
1717
1718 /**
1719 * @tc.name: GetDeviceSecurityLevel_001
1720 * @tc.desc: parse groupInfo from json with invalid params
1721 * @tc.type: FUNC
1722 */
1723 HWTEST_F(DistributedSchedPermissionTest, GetDeviceSecurityLevel_001, TestSize.Level3)
1724 {
1725 DTEST_LOG << "DistributedSchedPermissionTest GetDeviceSecurityLevel_001 begin" << std::endl;
1726 string udid = "123456";
1727 int32_t ret = DistributedSchedPermission::GetInstance().GetDeviceSecurityLevel(udid);
1728 EXPECT_NE(ret, 0);
1729 DTEST_LOG << "DistributedSchedPermissionTest GetDeviceSecurityLevel_001 end " << std::endl;
1730 }
1731
1732 /**
1733 * @tc.name: CheckAclList_001
1734 * @tc.desc: call CheckAclList
1735 * @tc.type: FUNC
1736 * @tc.require: I5RWIV
1737 */
1738 HWTEST_F(DistributedSchedPermissionTest, CheckAclList_001, TestSize.Level3)
1739 {
1740 DTEST_LOG << "DistributedSchedPermissionTest CheckAclList_001 begin" << std::endl;
1741 std::string dstNetworkId;
1742 IDistributedSched::AccountInfo dmsAccountInfo;
1743 CallerInfo callerInfo;
1744 DistributedSchedPermission::GetInstance().GetOsAccountData(dmsAccountInfo);
1745 DistributedSchedPermission::GetInstance().CheckDstSameAccount(dstNetworkId, dmsAccountInfo, callerInfo);
1746 bool ret = DistributedSchedPermission::GetInstance().CheckAclList(dstNetworkId, dmsAccountInfo, callerInfo);
1747 EXPECT_EQ(ret, false);
1748 DTEST_LOG << "DistributedSchedPermissionTest CheckAclList_001 end result:" << ret << std::endl;
1749 }
1750 } // namespace DistributedSchedule
1751 } // namespace OHOS
1752