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