1 /*
2 * Copyright (c) 2023-2025 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 "UTTest_dm_deviceprofile_connector_second.h"
17
18 #include "dm_constants.h"
19 #include "deviceprofile_connector.h"
20 #include <iterator>
21 #include "dp_inited_callback_stub.h"
22 #include "dm_error_type.h"
23 #include "dm_crypto.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27 namespace OHOS {
28 namespace DistributedHardware {
29
SetUp()30 void DeviceProfileConnectorSecondTest::SetUp()
31 {
32 }
33
TearDown()34 void DeviceProfileConnectorSecondTest::TearDown()
35 {
36 }
37
SetUpTestCase()38 void DeviceProfileConnectorSecondTest::SetUpTestCase()
39 {
40 DistributedDeviceProfile::DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient =
41 distributedDeviceProfileClientMock_;
42 }
43
TearDownTestCase()44 void DeviceProfileConnectorSecondTest::TearDownTestCase()
45 {
46 DistributedDeviceProfile::DpDistributedDeviceProfileClient::dpDistributedDeviceProfileClient = nullptr;
47 distributedDeviceProfileClientMock_ = nullptr;
48 }
49
50 class DpInitedCallback : public DistributedDeviceProfile::DpInitedCallbackStub {
51 public:
DpInitedCallback()52 DpInitedCallback()
53 {
54 }
~DpInitedCallback()55 ~DpInitedCallback()
56 {
57 }
OnDpInited()58 int32_t OnDpInited()
59 {
60 return 0;
61 }
62 };
63
AddAccessControlProfile(std::vector<DistributedDeviceProfile::AccessControlProfile> & accessControlProfiles)64 void AddAccessControlProfile(std::vector<DistributedDeviceProfile::AccessControlProfile>& accessControlProfiles)
65 {
66 int32_t userId = 123456;
67 int32_t bindType = 256;
68 int32_t deviceIdType = 1;
69 uint32_t bindLevel = 1;
70 uint32_t status = 1;
71 uint32_t authenticationType = 2;
72 uint32_t accesserId = 1;
73 uint32_t tokenId = 1001;
74
75 std::string oldAccountId = "oldAccountId";
76 std::string newAccountId = "newAccountId";
77 std::string deviceIdEr = "remoteDeviceId";
78 std::string deviceIdEe = "localDeviceId";
79 std::string trustDeviceId = "123456";
80
81 DistributedDeviceProfile::Accesser accesser;
82 accesser.SetAccesserId(accesserId);
83 accesser.SetAccesserDeviceId(deviceIdEr);
84 accesser.SetAccesserUserId(userId);
85 accesser.SetAccesserAccountId(oldAccountId);
86 accesser.SetAccesserTokenId(tokenId);
87 accesser.SetAccesserBundleName("bundleName");
88 accesser.SetAccesserHapSignature("uph1");
89 accesser.SetAccesserBindLevel(bindLevel);
90
91 DistributedDeviceProfile::Accessee accessee;
92 accessee.SetAccesseeId(accesserId);
93 accessee.SetAccesseeDeviceId(deviceIdEe);
94 accessee.SetAccesseeUserId(userId);
95 accessee.SetAccesseeAccountId(newAccountId);
96 accessee.SetAccesseeTokenId(tokenId);
97 accessee.SetAccesseeBundleName("bundleName");
98 accessee.SetAccesseeHapSignature("uph1");
99 accessee.SetAccesseeBindLevel(bindLevel);
100
101 DistributedDeviceProfile::AccessControlProfile profileFifth;
102 profileFifth.SetAccessControlId(accesserId);
103 profileFifth.SetAccesserId(accesserId);
104 profileFifth.SetAccesseeId(accesserId);
105 profileFifth.SetTrustDeviceId(trustDeviceId);
106 profileFifth.SetBindType(bindType);
107 profileFifth.SetAuthenticationType(authenticationType);
108 profileFifth.SetDeviceIdType(deviceIdType);
109 profileFifth.SetStatus(status);
110 profileFifth.SetBindLevel(bindLevel);
111 profileFifth.SetAccesser(accesser);
112 profileFifth.SetAccessee(accessee);
113 accessControlProfiles.push_back(profileFifth);
114 }
115
116 HWTEST_F(DeviceProfileConnectorSecondTest, GetAccessControlProfile_201, testing::ext::TestSize.Level1)
117 {
118 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
119 auto ret = DeviceProfileConnector::GetInstance().GetAccessControlProfile();
120 EXPECT_TRUE(ret.empty());
121 }
122
123 HWTEST_F(DeviceProfileConnectorSecondTest, GetAccessControlProfileByUserId_201, testing::ext::TestSize.Level1)
124 {
125 int32_t userId = USER;
126 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
127 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
128 profiles = DeviceProfileConnector::GetInstance().GetAccessControlProfileByUserId(userId);
129 EXPECT_TRUE(profiles.empty());
130 }
131
132 HWTEST_F(DeviceProfileConnectorSecondTest, CheckAuthForm_201, testing::ext::TestSize.Level1)
133 {
134 DmAuthForm form = DmAuthForm::ACROSS_ACCOUNT;
135 DistributedDeviceProfile::AccessControlProfile profiles;
136 profiles.SetBindType(DM_ACROSS_ACCOUNT);
137 profiles.SetBindLevel(APP);
138 profiles.accessee_.SetAccesseeBundleName("pkgName");
139 profiles.accessee_.SetAccesseeDeviceId("localDeviceId");
140 DmDiscoveryInfo discoveryInfo;
141 discoveryInfo.pkgname = "pkgName";
142 discoveryInfo.localDeviceId = "localDeviceId";
143 int32_t ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
144 EXPECT_EQ(ret, DmAuthForm::ACROSS_ACCOUNT);
145
146 profiles.accesser_.SetAccesserBundleName("pkgName");
147 profiles.accesser_.SetAccesserDeviceId("localDeviceId");
148 ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
149 EXPECT_EQ(ret, DmAuthForm::ACROSS_ACCOUNT);
150
151 profiles.SetBindLevel(SERVICE);
152 ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
153 EXPECT_EQ(ret, DmAuthForm::ACROSS_ACCOUNT);
154
155 profiles.SetBindLevel(USER);
156 ret = DeviceProfileConnector::GetInstance().CheckAuthForm(form, profiles, discoveryInfo);
157 EXPECT_EQ(ret, DmAuthForm::ACROSS_ACCOUNT);
158 }
159
160 HWTEST_F(DeviceProfileConnectorSecondTest, PutAccessControlList_201, testing::ext::TestSize.Level1)
161 {
162 DmAclInfo aclInfo;
163 DmAccesser dmAccesser;
164 DmAccessee dmAccessee;
165 EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAccessControlProfile(_)).WillOnce(Return(ERR_DM_FAILED));
166 int32_t ret = DeviceProfileConnector::GetInstance().PutAccessControlList(aclInfo, dmAccesser, dmAccessee);
167 EXPECT_EQ(ret, ERR_DM_FAILED);
168 }
169
170 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteSigTrustACL_201, testing::ext::TestSize.Level1)
171 {
172 int32_t userId = 0;
173 std::string accountId;
174 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
175
176 userId = 1;
177 int32_t bindType = 1;
178 std::string deviceIdEr = "deviceId";
179 std::string deviceIdEe = "deviceIdEe";
180 uint32_t accesserId = 1;
181 DistributedDeviceProfile::Accesser accesser;
182 accesser.SetAccesserDeviceId(deviceIdEr);
183 accesser.SetAccesserUserId(userId);
184 DistributedDeviceProfile::Accessee accessee;
185 accessee.SetAccesseeDeviceId(deviceIdEe);
186 accessee.SetAccesseeUserId(userId);
187 DistributedDeviceProfile::AccessControlProfile profile;
188 profile.SetAccessControlId(accesserId);
189 profile.SetBindType(bindType);
190 profile.SetAccesser(accesser);
191 profile.SetAccessee(accessee);
192
193 int userIds = 12356;
194 std::string remoteUdid = "deviceId";
195 std::vector<int32_t> remoteFrontUserIds;
196 remoteFrontUserIds.push_back(userIds);
197 std::vector<int32_t> remoteBackUserIds;
198 remoteBackUserIds.push_back(userIds);
199 DmOfflineParam offlineParam;
200 DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds,
201 offlineParam);
202
203 remoteUdid = "deviceIdEe";
204 DeviceProfileConnector::GetInstance().DeleteSigTrustACL(profile, remoteUdid, remoteFrontUserIds, remoteBackUserIds,
205 offlineParam);
206
207 int32_t userIdee = 0;
208 accessee.SetAccesseeUserId(userIdee);
209 DistributedDeviceProfile::AccessControlProfile profilesecond;
210 profilesecond.SetAccessControlId(accesserId);
211 profilesecond.SetBindType(bindType);
212 profilesecond.SetAccesser(accesser);
213 profilesecond.SetAccessee(accessee);
214 std::string localUdid = "deviceId";
215 std::vector<int32_t> localUserIds;
216 int32_t localUserId = 1;
217 localUserIds.push_back(localUserId);
218 DeviceProfileConnector::GetInstance().UpdatePeerUserId(profilesecond, localUdid, localUserIds,
219 remoteUdid, remoteFrontUserIds);
220 }
221
222 HWTEST_F(DeviceProfileConnectorSecondTest, GetAllAccessControlProfile_201, testing::ext::TestSize.Level1)
223 {
224 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_))
225 .Times(::testing::AtLeast(1)).WillOnce(Return(ERR_DM_FAILED));
226 auto ret = DeviceProfileConnector::GetInstance().GetAllAccessControlProfile();
227 EXPECT_TRUE(ret.empty());
228 }
229
230 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByDeviceIdAndUserId_201, testing::ext::TestSize.Level1)
231 {
232 std::string deviceId = "deviceId";
233 int32_t userId = 123456;
234 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
235 auto ret = DeviceProfileConnector::GetInstance().GetAclProfileByDeviceIdAndUserId(deviceId, userId);
236 EXPECT_TRUE(ret.empty());
237 }
238
239 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAclForAccountLogOut_001, testing::ext::TestSize.Level1)
240 {
241 std::string localUdid = "local_device_id";
242 int32_t localUserId = 1;
243 std::string peerUdid = "peer_device_id";
244 int32_t peerUserId = 2;
245 DmOfflineParam offlineParam;
246 DMAclQuadInfo info = {localUdid, localUserId, peerUdid, peerUserId};
247 std::string accoutId = "accountId";
248 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
249 int32_t result = connector.DeleteAclForAccountLogOut(info, accoutId, offlineParam);
250
251 EXPECT_EQ(result, false);
252 }
253
254 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAppBindLevel_001, testing::ext::TestSize.Level1)
255 {
256 DmOfflineParam offlineParam;
257 std::string pkgName = "com.example.app";
258 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles = {};
259 std::string localUdid = "local_udid";
260 std::string remoteUdid = "remote_udid";
261 connector.DeleteAppBindLevel(offlineParam, pkgName, profiles, localUdid, remoteUdid);
262
263 EXPECT_EQ(offlineParam.processVec.size(), 0);
264 }
265
266 HWTEST_F(DeviceProfileConnectorSecondTest, CheckIsSameAccount_001, testing::ext::TestSize.Level1)
267 {
268 DmAccessCaller caller;
269 caller.pkgName = "test_pkg";
270 std::string srcUdid = "src_udid";
271 DmAccessCallee callee;
272 std::string sinkUdid = "non_identical_udid";
273 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
274 EXPECT_EQ(connector.CheckIsSameAccount(caller, srcUdid, callee, sinkUdid), false);
275 }
276
277 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndBindLevel_001, testing::ext::TestSize.Level1)
278 {
279 std::vector<int32_t> userIds = {4, 5, 6};
280 std::string localUdid = "local_udid";
281 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_))
282 .Times(::testing::AtLeast(2)).WillOnce(Return(DM_OK));
283 auto result = connector.GetDeviceIdAndBindLevel(userIds, localUdid);
284 EXPECT_TRUE(result.empty());
285 }
286
287 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_001, testing::ext::TestSize.Level1)
288 {
289 std::string localUdid = "localDevice";
290 int32_t userId = -1;
291 std::string remoteUdid = "remoteDevice";
292 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
293 auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid);
294
295 EXPECT_TRUE(result.empty());
296 }
297
298 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_002, testing::ext::TestSize.Level1)
299 {
300 std::string localUdid = "localDevice";
301 int32_t userId = 1;
302 std::string remoteUdid = "nonExistentDevice";
303 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
304 auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid);
305
306 EXPECT_TRUE(result.empty());
307 }
308
309 HWTEST_F(DeviceProfileConnectorSecondTest, GetAclProfileByUserId_003, testing::ext::TestSize.Level1)
310 {
311 std::string localUdid = "";
312 int32_t userId = 0;
313 std::string remoteUdid = "";
314 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
315 auto result = connector.GetAclProfileByUserId(localUdid, userId, remoteUdid);
316
317 EXPECT_TRUE(result.empty());
318 }
319
320 HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_001, testing::ext::TestSize.Level1)
321 {
322 std::string localUdid = "invalid_device";
323 std::vector<int32_t> localUserIds = {1, 2};
324 std::string remoteUdid = "remote_device";
325 std::vector<int32_t> remoteUserIds = {3, 4};
326 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
327 std::vector<ProcessInfo> result =
328 connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds);
329
330 EXPECT_TRUE(result.empty());
331 }
332
333 HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_002, testing::ext::TestSize.Level1)
334 {
335 std::string localUdid = "local_device";
336 std::vector<int32_t> localUserIds = {1, 2};
337 std::string remoteUdid = "remote_device";
338 std::vector<int32_t> remoteUserIds = {99, 100};
339 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
340 std::vector<ProcessInfo> result =
341 connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds);
342
343 EXPECT_TRUE(result.empty());
344 }
345
346 HWTEST_F(DeviceProfileConnectorSecondTest, GetOfflineProcessInfo_003, testing::ext::TestSize.Level1)
347 {
348 std::string localUdid = "local_device";
349 std::vector<int32_t> localUserIds = {};
350 std::string remoteUdid = "remote_device";
351 std::vector<int32_t> remoteUserIds = {3, 4};
352 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
353 std::vector<ProcessInfo> result =
354 connector.GetOfflineProcessInfo(localUdid, localUserIds, remoteUdid, remoteUserIds);
355
356 EXPECT_TRUE(result.empty());
357 }
358
359 HWTEST_F(DeviceProfileConnectorSecondTest, GetUserIdAndBindLevel_001, testing::ext::TestSize.Level1)
360 {
361 std::string localUdid = "local_udid";
362 std::string peerUdid = "peer_udid";
363 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
364 std::map<int32_t, int32_t> result = connector.GetUserIdAndBindLevel(localUdid, peerUdid);
365
366 EXPECT_TRUE(result.empty());
367 }
368
369 HWTEST_F(DeviceProfileConnectorSecondTest, GetUserIdAndBindLevel_002, testing::ext::TestSize.Level1)
370 {
371 std::string localUdid = "local_udid";
372 std::string peerUdid = "peer_udid";
373 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
374 std::map<int32_t, int32_t> result = connector.GetUserIdAndBindLevel(localUdid, peerUdid);
375
376 EXPECT_TRUE(result.empty());
377 }
378
379 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_001, testing::ext::TestSize.Level1)
380 {
381 std::string localUdid = "local_udid_123";
382 std::string peerUdid = "peer_udid_456";
383 int32_t peerUserId = 789;
384 std::string peerAccountHash = "invalid_hash";
385 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
386 std::multimap<std::string, int32_t> result =
387 connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
388
389 EXPECT_TRUE(result.empty());
390 }
391
392 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_002, testing::ext::TestSize.Level1)
393 {
394 std::string localUdid = "local_udid_123";
395 std::string peerUdid = "non_matching_udid";
396 int32_t peerUserId = 789;
397 std::string peerAccountHash = "valid_hash";
398 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
399 std::multimap<std::string, int32_t> result =
400 connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
401
402 EXPECT_TRUE(result.empty());
403 }
404
405 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_003, testing::ext::TestSize.Level1)
406 {
407 std::string localUdid = "local_udid_123";
408 std::string peerUdid = "peer_udid_456";
409 int32_t peerUserId = -1;
410 std::string peerAccountHash = "valid_hash";
411 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
412 std::multimap<std::string, int32_t> result =
413 connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
414
415 EXPECT_TRUE(result.empty());
416 }
417
418 HWTEST_F(DeviceProfileConnectorSecondTest, GetDevIdAndUserIdByActHash_004, testing::ext::TestSize.Level1)
419 {
420 std::string localUdid = "";
421 std::string peerUdid = "";
422 int32_t peerUserId = 0;
423 std::string peerAccountHash = "";
424 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
425 std::multimap<std::string, int32_t> result =
426 connector.GetDevIdAndUserIdByActHash(localUdid, peerUdid, peerUserId, peerAccountHash);
427
428 EXPECT_TRUE(result.empty());
429 }
430
431 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUserId_001, testing::ext::TestSize.Level1)
432 {
433 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
434 auto result = connector.GetDeviceIdAndUserId("device4", 4);
435 EXPECT_EQ(result.size(), 0);
436 }
437
438 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUserId_002, testing::ext::TestSize.Level1)
439 {
440 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
441 auto result = connector.GetDeviceIdAndUserId("", 0);
442 EXPECT_EQ(result.size(), 0);
443 }
444
445 HWTEST_F(DeviceProfileConnectorSecondTest, SubscribeDeviceProfileInited_201, testing::ext::TestSize.Level1)
446 {
447 OHOS::sptr<DistributedDeviceProfile::IDpInitedCallback> dpInitedCallback = nullptr;
448 int32_t ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
449 EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
450
451 dpInitedCallback = sptr<DistributedDeviceProfile::IDpInitedCallback>(new DpInitedCallback());
452 EXPECT_CALL(*distributedDeviceProfileClientMock_, SubscribeDeviceProfileInited(_, _))
453 .WillOnce(Return(ERR_DM_FAILED));
454 ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
455 EXPECT_EQ(ret, ERR_DM_FAILED);
456
457 EXPECT_CALL(*distributedDeviceProfileClientMock_, SubscribeDeviceProfileInited(_, _))
458 .WillOnce(Return(DM_OK));
459 ret = DeviceProfileConnector::GetInstance().SubscribeDeviceProfileInited(dpInitedCallback);
460 EXPECT_EQ(ret, DM_OK);
461 }
462
463 HWTEST_F(DeviceProfileConnectorSecondTest, UnSubscribeDeviceProfileInited_201, testing::ext::TestSize.Level1)
464 {
465 EXPECT_CALL(*distributedDeviceProfileClientMock_, UnSubscribeDeviceProfileInited(_))
466 .WillOnce(Return(ERR_DM_FAILED));
467 int32_t ret = DeviceProfileConnector::GetInstance().UnSubscribeDeviceProfileInited();
468 EXPECT_EQ(ret, ERR_DM_FAILED);
469
470 EXPECT_CALL(*distributedDeviceProfileClientMock_, UnSubscribeDeviceProfileInited(_))
471 .WillOnce(Return(DM_OK));
472 ret = DeviceProfileConnector::GetInstance().UnSubscribeDeviceProfileInited();
473 EXPECT_EQ(ret, DM_OK);
474 }
475
476 HWTEST_F(DeviceProfileConnectorSecondTest, PutAllTrustedDevices_201, testing::ext::TestSize.Level1)
477 {
478 std::vector<DistributedDeviceProfile::TrustedDeviceInfo> deviceInfos;
479 EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAllTrustedDevices(_))
480 .WillOnce(Return(ERR_DM_FAILED));
481 int32_t ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);
482 EXPECT_EQ(ret, ERR_DM_FAILED);
483
484 EXPECT_CALL(*distributedDeviceProfileClientMock_, PutAllTrustedDevices(_))
485 .WillOnce(Return(DM_OK));
486 ret = DeviceProfileConnector::GetInstance().PutAllTrustedDevices(deviceInfos);
487 EXPECT_EQ(ret, DM_OK);
488
489 int32_t bindType = 0;
490 std::string peerUdid = "";
491 std::string localUdid = "";
492 int32_t localUserId = 1234;
493 std::string localAccountId = "";
494 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
495 DeviceProfileConnector::GetInstance().HandleDeviceUnBind(bindType, peerUdid, localUdid, localUserId,
496 localAccountId);
497 }
498
499 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteAccessControlList_201, testing::ext::TestSize.Level1)
500 {
501 std::string pkgName;
502 std::string localDeviceId = "";
503 std::string remoteDeviceId = "";
504 int32_t bindLevel = 2;
505 std::string extra = "";
506 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAccessControlProfile(_, _)).WillOnce(Return(ERR_DM_FAILED));
507 DmOfflineParam offlineParam = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
508 remoteDeviceId, bindLevel, extra);
509 EXPECT_EQ(offlineParam.bindType, INVALIED_TYPE);
510 }
511
512 HWTEST_F(DeviceProfileConnectorSecondTest, PutSessionKey_201, testing::ext::TestSize.Level1)
513 {
514 std::vector<unsigned char> sessionKeyArray;
515 int32_t sessionKeyId = 1;
516 int32_t userId = 100;
517 int32_t ret = DeviceProfileConnector::GetInstance().PutSessionKey(userId, sessionKeyArray, sessionKeyId);
518 EXPECT_EQ(ret, ERR_DM_FAILED);
519
520 sessionKeyArray.push_back('1');
521 sessionKeyArray.push_back('2');
522 sessionKeyArray.push_back('3');
523 sessionKeyArray.push_back('4');
524 sessionKeyArray.push_back('5');
525 EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(ERR_DM_FAILED));
526 ret = DeviceProfileConnector::GetInstance().PutSessionKey(userId, sessionKeyArray, sessionKeyId);
527 EXPECT_EQ(ret, ERR_DM_FAILED);
528
529 EXPECT_CALL(*distributedDeviceProfileClientMock_, PutSessionKey(_, _, _)).WillOnce(Return(DM_OK));
530 ret = DeviceProfileConnector::GetInstance().PutSessionKey(userId, sessionKeyArray, sessionKeyId);
531 EXPECT_EQ(ret, DM_OK);
532 }
533
534 HWTEST_F(DeviceProfileConnectorSecondTest, PutLocalServiceInfo_201, testing::ext::TestSize.Level1)
535 {
536 DistributedDeviceProfile::LocalServiceInfo localServiceInfo;
537 EXPECT_CALL(*distributedDeviceProfileClientMock_, PutLocalServiceInfo(_)).WillOnce(Return(DM_OK));
538 int32_t ret = DeviceProfileConnector::GetInstance().PutLocalServiceInfo(localServiceInfo);
539 EXPECT_EQ(ret, DM_OK);
540
541 EXPECT_CALL(*distributedDeviceProfileClientMock_, PutLocalServiceInfo(_)).WillOnce(Return(ERR_DM_FAILED));
542 ret = DeviceProfileConnector::GetInstance().PutLocalServiceInfo(localServiceInfo);
543 EXPECT_EQ(ret, ERR_DM_FAILED);
544 }
545
546 HWTEST_F(DeviceProfileConnectorSecondTest, DeleteLocalServiceInfo_201, testing::ext::TestSize.Level1)
547 {
548 std::string bundleName = "b********pl";
549 int32_t pinExchangeType = 1;
550 EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteLocalServiceInfo(_, _)).WillOnce(Return(DM_OK));
551 int32_t ret = DeviceProfileConnector::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType);
552 EXPECT_EQ(ret, DM_OK);
553
554 EXPECT_CALL(*distributedDeviceProfileClientMock_, DeleteLocalServiceInfo(_, _)).WillOnce(Return(ERR_DM_FAILED));
555 ret = DeviceProfileConnector::GetInstance().DeleteLocalServiceInfo(bundleName, pinExchangeType);
556 EXPECT_EQ(ret, ERR_DM_FAILED);
557 }
558
559 HWTEST_F(DeviceProfileConnectorSecondTest, UpdateLocalServiceInfo_201, testing::ext::TestSize.Level1)
560 {
561 DistributedDeviceProfile::LocalServiceInfo localServiceInfo;
562 EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateLocalServiceInfo(_)).WillOnce(Return(DM_OK));
563 int32_t ret = DeviceProfileConnector::GetInstance().UpdateLocalServiceInfo(localServiceInfo);
564 EXPECT_EQ(ret, DM_OK);
565
566 EXPECT_CALL(*distributedDeviceProfileClientMock_, UpdateLocalServiceInfo(_)).WillOnce(Return(ERR_DM_FAILED));
567 ret = DeviceProfileConnector::GetInstance().UpdateLocalServiceInfo(localServiceInfo);
568 EXPECT_EQ(ret, ERR_DM_FAILED);
569 }
570
571 HWTEST_F(DeviceProfileConnectorSecondTest, GetLocalServiceInfoByBundleNameAndPinExchangeType_201,
572 testing::ext::TestSize.Level1)
573 {
574 std::string bundleName = "b********pl";
575 int32_t pinExchangeType = 1;
576 DistributedDeviceProfile::LocalServiceInfo localServiceInfo;
577 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetLocalServiceInfoByBundleAndPinType(_, _, _))
578 .WillOnce(Return(DM_OK));
579 int32_t ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName,
580 pinExchangeType, localServiceInfo);
581 EXPECT_EQ(ret, DM_OK);
582
583 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetLocalServiceInfoByBundleAndPinType(_, _, _))
584 .WillOnce(Return(ERR_DM_FAILED));
585 ret = DeviceProfileConnector::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName,
586 pinExchangeType, localServiceInfo);
587 EXPECT_EQ(ret, ERR_DM_FAILED);
588 }
589
590 HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_009, testing::ext::TestSize.Level1)
591 {
592 DistributedDeviceProfile::AccessControlProfile profiles;
593 profiles.SetBindType(DM_SHARE);
594 profiles.SetBindLevel(USER);
595 DmDiscoveryInfo discoveryInfo;
596 int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo);
597 EXPECT_EQ(ret, SHARE);
598 }
599
600 HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_010, testing::ext::TestSize.Level1)
601 {
602 DistributedDeviceProfile::AccessControlProfile profiles;
603 profiles.SetBindType(DM_SHARE);
604 profiles.SetBindLevel(APP);
605 profiles.accesser_.SetAccesserBundleName("ohos_test");
606 profiles.accesser_.SetAccesserDeviceId("localDeviceId");
607 DmDiscoveryInfo discoveryInfo;
608 discoveryInfo.pkgname = "ohos_test";
609 discoveryInfo.localDeviceId = "localDeviceId";
610 int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo);
611 EXPECT_EQ(ret, SHARE);
612 }
613
614 HWTEST_F(DeviceProfileConnectorSecondTest, HandleDmAuthForm_011, testing::ext::TestSize.Level1)
615 {
616 DistributedDeviceProfile::AccessControlProfile profiles;
617 profiles.SetBindType(DM_SHARE);
618 profiles.SetBindLevel(APP);
619 profiles.accessee_.SetAccesseeBundleName("pkgName");
620 profiles.accessee_.SetAccesseeDeviceId("localDeviceId");
621 DmDiscoveryInfo discoveryInfo;
622 discoveryInfo.pkgname = "pkgName";
623 discoveryInfo.localDeviceId = "localDeviceId";
624 int32_t ret = DeviceProfileConnector::GetInstance().HandleDmAuthForm(profiles, discoveryInfo);
625 EXPECT_EQ(ret, SHARE);
626 }
627
628 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_001, testing::ext::TestSize.Level1)
629 {
630 DistributedDeviceProfile::AccessControlProfile profile;
631 int32_t userId = 123456;
632 std::string deviceId = "deviceId";
633 std::string trustDeviceId = "trustDeviceId";
634 int32_t bindType = DmAuthForm::SHARE;
635
636 DistributedDeviceProfile::Accessee accessee;
637 accessee.SetAccesseeUserId(userId);
638 accessee.SetAccesseeDeviceId(deviceId);
639 profile.SetAccessee(accessee);
640
641 DistributedDeviceProfile::Accesser accesser;
642 accesser.SetAccesserDeviceId(trustDeviceId);
643 profile.SetAccesser(accesser);
644
645 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
646 profile, userId, deviceId, trustDeviceId, bindType);
647 EXPECT_TRUE(ret);
648 }
649
650 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_002, testing::ext::TestSize.Level1)
651 {
652 DistributedDeviceProfile::AccessControlProfile profile;
653 int32_t userId = 123456;
654 std::string deviceId = "deviceId";
655 std::string trustDeviceId = "trustDeviceId";
656 int32_t bindType = DmAuthForm::SHARE;
657
658 DistributedDeviceProfile::Accessee accessee;
659 accessee.SetAccesseeUserId(0);
660 accessee.SetAccesseeDeviceId(deviceId);
661 profile.SetAccessee(accessee);
662
663 DistributedDeviceProfile::Accesser accesser;
664 accesser.SetAccesserDeviceId(trustDeviceId);
665 profile.SetAccesser(accesser);
666
667 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
668 profile, userId, deviceId, trustDeviceId, bindType);
669 EXPECT_FALSE(ret);
670 }
671
672 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_003, testing::ext::TestSize.Level1)
673 {
674 DistributedDeviceProfile::AccessControlProfile profile;
675 int32_t userId = 123456;
676 std::string deviceId = "deviceId";
677 std::string trustDeviceId = "trustDeviceId";
678 int32_t bindType = DmAuthForm::SHARE;
679
680 DistributedDeviceProfile::Accessee accessee;
681 accessee.SetAccesseeUserId(-1);
682 accessee.SetAccesseeDeviceId(deviceId);
683 profile.SetAccessee(accessee);
684
685 DistributedDeviceProfile::Accesser accesser;
686 accesser.SetAccesserDeviceId(trustDeviceId);
687 profile.SetAccesser(accesser);
688 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
689 profile, userId, deviceId, trustDeviceId, bindType);
690 EXPECT_FALSE(ret);
691 }
692
693 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_004, testing::ext::TestSize.Level1)
694 {
695 DistributedDeviceProfile::AccessControlProfile profile;
696 int32_t userId = 123456;
697 std::string deviceId = "deviceId";
698 std::string trustDeviceId = "trustDeviceId";
699 int32_t bindType = DmAuthForm::ACROSS_ACCOUNT;
700
701 DistributedDeviceProfile::Accessee accessee;
702 accessee.SetAccesseeUserId(userId);
703 accessee.SetAccesseeDeviceId("wrongDeviceId");
704 profile.SetAccessee(accessee);
705
706 DistributedDeviceProfile::Accesser accesser;
707 accesser.SetAccesserDeviceId(trustDeviceId);
708 profile.SetAccesser(accesser);
709
710 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
711 profile, userId, deviceId, trustDeviceId, bindType);
712 EXPECT_FALSE(ret);
713 }
714
715 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_005, testing::ext::TestSize.Level1)
716 {
717 DistributedDeviceProfile::AccessControlProfile profile;
718 int32_t userId = 123456;
719 std::string deviceId = "deviceId";
720 std::string trustDeviceId = "trustDeviceId";
721 int32_t bindType = DmAuthForm::ACROSS_ACCOUNT;
722
723 DistributedDeviceProfile::Accessee accessee;
724 accessee.SetAccesseeUserId(userId);
725 accessee.SetAccesseeDeviceId(deviceId);
726 profile.SetAccessee(accessee);
727
728 DistributedDeviceProfile::Accesser accesser;
729 accesser.SetAccesserDeviceId("wrongTrustDeviceId");
730 profile.SetAccesser(accesser);
731
732 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
733 profile, userId, deviceId, trustDeviceId, bindType);
734 EXPECT_FALSE(ret);
735 }
736
737 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_006, testing::ext::TestSize.Level1)
738 {
739 DistributedDeviceProfile::AccessControlProfile profile;
740 int32_t userId = 123456;
741 std::string deviceId = "deviceId";
742 std::string trustDeviceId = "trustDeviceId";
743 int32_t bindType = DmAuthForm::PEER_TO_PEER; // Wrong bind type
744
745 DistributedDeviceProfile::Accessee accessee;
746 accessee.SetAccesseeUserId(userId);
747 accessee.SetAccesseeDeviceId(deviceId);
748 profile.SetAccessee(accessee);
749
750 DistributedDeviceProfile::Accesser accesser;
751 accesser.SetAccesserDeviceId(trustDeviceId);
752 profile.SetAccesser(accesser);
753
754 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
755 profile, userId, deviceId, trustDeviceId, bindType);
756 EXPECT_FALSE(ret);
757 }
758
759 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_007, testing::ext::TestSize.Level1)
760 {
761 DistributedDeviceProfile::AccessControlProfile profile;
762 int32_t userId = 123456;
763 std::string deviceId = "deviceId";
764 std::string trustDeviceId = "trustDeviceId";
765 int32_t bindType = DmAuthForm::ACROSS_ACCOUNT;
766
767 DistributedDeviceProfile::Accessee accessee;
768 accessee.SetAccesseeUserId(999999); // Different user ID
769 accessee.SetAccesseeDeviceId(deviceId);
770 profile.SetAccessee(accessee);
771
772 DistributedDeviceProfile::Accesser accesser;
773 accesser.SetAccesserDeviceId(trustDeviceId);
774 profile.SetAccesser(accesser);
775 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
776 profile, userId, deviceId, trustDeviceId, bindType);
777 EXPECT_FALSE(ret);
778 }
779
780 HWTEST_F(DeviceProfileConnectorSecondTest, CheckSinkShareType_008, testing::ext::TestSize.Level1)
781 {
782 DistributedDeviceProfile::AccessControlProfile profile;
783 int32_t userId = 123456;
784 std::string deviceId = "deviceId";
785 std::string trustDeviceId = "trustDeviceId";
786 int32_t bindType = DmAuthForm::ACROSS_ACCOUNT;
787
788 // Empty profile (no accessee/accesser set)
789 bool ret = DeviceProfileConnector::GetInstance().CheckSinkShareType(
790 profile, userId, deviceId, trustDeviceId, bindType);
791 EXPECT_FALSE(ret);
792 }
793
794 HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_001, testing::ext::TestSize.Level1)
795 {
796 // Test case 1: Empty input - should return empty map
797 std::string pkgName = "testPkg";;
798 std::string deviceId = "deviceId1";
799 int32_t userId = 123456;
800 std::vector<DistributedDeviceProfile::AccessControlProfile> profilesFilter;
801
802 auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
803 EXPECT_EQ(ret.size(), 0);
804 }
805
806 HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_002, testing::ext::TestSize.Level1)
807 {
808 // Test case 2: Profile with trustDeviceId matching input deviceId - should be skipped
809 std::string pkgName = "testPkg";
810 std::string deviceId = "deviceId1";
811 int32_t userId = 123456;
812
813 std::vector<DistributedDeviceProfile::AccessControlProfile> profilesFilter;
814 DistributedDeviceProfile::AccessControlProfile profile;
815 profile.SetTrustDeviceId(deviceId); // Matching deviceId
816 profile.SetStatus(ACTIVE);
817 profilesFilter.push_back(profile);
818
819 auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
820 EXPECT_EQ(ret.size(), 0);
821 }
822
823 HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_003, testing::ext::TestSize.Level1)
824 {
825 // Test case 3: Profile with INACTIVE status - should be skipped
826 std::string pkgName = "testPkg";
827 std::string deviceId = "deviceId1";
828 std::string trustDeviceId = "trustDeviceId1";
829 int32_t userId = 123456;
830
831 std::vector<DistributedDeviceProfile::AccessControlProfile> profilesFilter;
832 DistributedDeviceProfile::AccessControlProfile profile;
833 profile.SetTrustDeviceId(trustDeviceId);
834 profile.SetStatus(INACTIVE);
835 profilesFilter.push_back(profile);
836
837 auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
838 EXPECT_EQ(ret.size(), 0);
839 }
840
841 HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_004, testing::ext::TestSize.Level1)
842 {
843 // Test case 4: Profile with INVALID_TYPE auth form - should be skipped
844 std::string pkgName = "testPkg";
845 std::string deviceId = "deviceId1";
846 std::string trustDeviceId = "trustDeviceId1";
847 int32_t userId = 123456;
848
849 std::vector<DistributedDeviceProfile::AccessControlProfile> profilesFilter;
850 DistributedDeviceProfile::AccessControlProfile profile;
851 profile.SetTrustDeviceId(trustDeviceId);
852 profile.SetStatus(ACTIVE);
853 profile.SetBindType(DmAuthForm::INVALID_TYPE);
854 profilesFilter.push_back(profile);
855
856 auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
857 EXPECT_EQ(ret.size(), 0);
858 }
859
860 HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_005, testing::ext::TestSize.Level1)
861 {
862 // Test case 5: Single valid profile with IDENTICAL_ACCOUNT type
863 std::string pkgName = "testPkg";
864 std::string deviceId = "deviceId1";
865 std::string trustDeviceId = "trustDeviceId1";
866 int32_t userId = 123456;
867
868 std::vector<DistributedDeviceProfile::AccessControlProfile> profilesFilter;
869 DistributedDeviceProfile::AccessControlProfile profile;
870 profile.SetTrustDeviceId(trustDeviceId);
871 profile.SetStatus(ACTIVE);
872 profile.SetBindType(DmAuthForm::IDENTICAL_ACCOUNT);
873 profilesFilter.push_back(profile);
874
875 auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
876 EXPECT_EQ(ret.size(), 1);
877 EXPECT_EQ(ret[trustDeviceId], DmAuthForm::IDENTICAL_ACCOUNT);
878 }
879
880 HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_006, testing::ext::TestSize.Level1)
881 {
882 // Test case 6: CheckSinkShareType returns true - should skip adding to map
883 std::string pkgName = "testPkg";
884 std::string deviceId = "deviceId1";
885 std::string trustDeviceId = "trustDeviceId1";
886 int32_t userId = 123456;
887
888 std::vector<DistributedDeviceProfile::AccessControlProfile> profilesFilter;
889 DistributedDeviceProfile::AccessControlProfile profile;
890 profile.SetTrustDeviceId(trustDeviceId);
891 profile.SetStatus(ACTIVE);
892 // Set up accessee/accesser to make CheckSinkShareType return true
893 DistributedDeviceProfile::Accessee accessee;
894 accessee.SetAccesseeUserId(userId);
895 accessee.SetAccesseeDeviceId(deviceId);
896 profile.SetAccessee(accessee);
897 DistributedDeviceProfile::Accesser accesser;
898 accesser.SetAccesserDeviceId(trustDeviceId);
899 profile.SetAccesser(accesser);
900 profile.SetBindType(DmAuthForm::ACROSS_ACCOUNT);
901
902 profilesFilter.push_back(profile);
903
904 auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
905 EXPECT_EQ(ret.size(), 0);
906 }
907
908 HWTEST_F(DeviceProfileConnectorSecondTest, GetAuthFormMap_007, testing::ext::TestSize.Level1)
909 {
910 // Test case 7: Multiple profiles with different auth forms - should keep highest priority
911 std::string pkgName = "testPkg";
912 std::string deviceId = "deviceId1";
913 std::string trustDeviceId = "trustDeviceId1";
914 int32_t userId = 123456;
915
916 std::vector<DistributedDeviceProfile::AccessControlProfile> profilesFilter;
917 // First profile - PEER_TO_PEER
918 DistributedDeviceProfile::AccessControlProfile profile1;
919 profile1.SetTrustDeviceId(trustDeviceId);
920 profile1.SetStatus(ACTIVE);
921 profile1.SetBindType(DmAuthForm::PEER_TO_PEER);
922 profilesFilter.push_back(profile1);
923
924 // Second profile - ACROSS_ACCOUNT (should override PEER_TO_PEER)
925 DistributedDeviceProfile::AccessControlProfile profile2;
926 profile2.SetTrustDeviceId(trustDeviceId);
927 profile2.SetStatus(ACTIVE);
928 profile2.SetBindType(DmAuthForm::ACROSS_ACCOUNT);
929 profilesFilter.push_back(profile2);
930
931 // Third profile - IDENTICAL_ACCOUNT (should override everything)
932 DistributedDeviceProfile::AccessControlProfile profile3;
933 profile3.SetTrustDeviceId(trustDeviceId);
934 profile3.SetStatus(ACTIVE);
935 profile3.SetBindType(DmAuthForm::IDENTICAL_ACCOUNT);
936 profilesFilter.push_back(profile3);
937
938 auto ret = DeviceProfileConnector::GetInstance().GetAuthFormMap(pkgName, deviceId, profilesFilter, userId);
939 EXPECT_EQ(ret.size(), 1);
940 EXPECT_EQ(ret[trustDeviceId], DmAuthForm::IDENTICAL_ACCOUNT);
941 }
942
943 HWTEST_F(DeviceProfileConnectorSecondTest, GetVersionByExtra_001, testing::ext::TestSize.Level1)
944 {
945 std::string extraInfo = "";
946 std::string dmVersion;
947
948 int32_t ret = DeviceProfileConnector::GetInstance().GetVersionByExtra(extraInfo, dmVersion);
949 EXPECT_EQ(ret, ERR_DM_FAILED);
950 }
951 HWTEST_F(DeviceProfileConnectorSecondTest, GetVersionByExtra_002, testing::ext::TestSize.Level1)
952 {
953 std::string extraInfo = "invalid_json";
954 std::string dmVersion;
955
956 int32_t ret = DeviceProfileConnector::GetInstance().GetVersionByExtra(extraInfo, dmVersion);
957 EXPECT_EQ(ret, ERR_DM_FAILED);
958 }
959
960 HWTEST_F(DeviceProfileConnectorSecondTest, GetVersionByExtra_003, testing::ext::TestSize.Level1)
961 {
962 std::string extraInfo = R"({"key": "value"})";
963 std::string dmVersion;
964
965 int32_t ret = DeviceProfileConnector::GetInstance().GetVersionByExtra(extraInfo, dmVersion);
966 EXPECT_EQ(ret, ERR_DM_FAILED);
967 }
968
969 HWTEST_F(DeviceProfileConnectorSecondTest, GetVersionByExtra_004, testing::ext::TestSize.Level1)
970 {
971 std::string extraInfo = R"({"dmVersion": "5.1.0"})";
972 std::string dmVersion;
973
974 int32_t ret = DeviceProfileConnector::GetInstance().GetVersionByExtra(extraInfo, dmVersion);
975 EXPECT_EQ(ret, DM_OK);
976 EXPECT_EQ(dmVersion, "5.1.0");
977 }
978
979 HWTEST_F(DeviceProfileConnectorSecondTest, GetAllVerionAclMap_001, testing::ext::TestSize.Level1)
980 {
981 DistributedDeviceProfile::AccessControlProfile acl;
982 std::map<std::string, std::vector<std::string>> aclMap;
983 std::string dmVersion = "";
984
985 EXPECT_NO_THROW(DeviceProfileConnector::GetInstance().GetAllVerionAclMap(acl, aclMap, dmVersion));
986 EXPECT_EQ(aclMap.size(), 1);
987 EXPECT_TRUE(aclMap.find(DM_VERSION_5_1_0) != aclMap.end());
988 }
989
990 HWTEST_F(DeviceProfileConnectorSecondTest, GetAllVerionAclMap_002, testing::ext::TestSize.Level1)
991 {
992 DistributedDeviceProfile::AccessControlProfile acl;
993 std::map<std::string, std::vector<std::string>> aclMap;
994 std::string dmVersion = DM_VERSION_5_1_0;
995
996 EXPECT_NO_THROW(DeviceProfileConnector::GetInstance().GetAllVerionAclMap(acl, aclMap, dmVersion));
997 EXPECT_EQ(aclMap.size(), 1);
998 EXPECT_TRUE(aclMap.find(dmVersion) != aclMap.end());
999 }
1000
1001 HWTEST_F(DeviceProfileConnectorSecondTest, GetAllVerionAclMap_003, testing::ext::TestSize.Level1)
1002 {
1003 DistributedDeviceProfile::AccessControlProfile acl;
1004 std::map<std::string, std::vector<std::string>> aclMap;
1005 std::string dmVersion = "invalid_version";
1006
1007 EXPECT_NO_THROW(DeviceProfileConnector::GetInstance().GetAllVerionAclMap(acl, aclMap, dmVersion));
1008 EXPECT_EQ(aclMap.size(), 0);
1009 }
1010
1011 HWTEST_F(DeviceProfileConnectorSecondTest, GetAllVerionAclMap_004, testing::ext::TestSize.Level1)
1012 {
1013 DistributedDeviceProfile::AccessControlProfile acl;
1014 acl.SetAccessControlId(12345);
1015 acl.SetAccesserId(1);
1016 acl.SetAccesseeId(2);
1017 acl.SetTrustDeviceId("trustDeviceId");
1018 acl.SetBindType(256);
1019 acl.SetAuthenticationType(2);
1020 acl.SetDeviceIdType(1);
1021 acl.SetStatus(1);
1022 acl.SetBindLevel(1);
1023
1024 std::map<std::string, std::vector<std::string>> aclMap;
1025 std::string dmVersion = DM_VERSION_5_1_0;
1026
1027 EXPECT_NO_THROW(DeviceProfileConnector::GetInstance().GetAllVerionAclMap(acl, aclMap, dmVersion));
1028 EXPECT_EQ(aclMap.size(), 1);
1029 EXPECT_TRUE(aclMap.find(dmVersion) != aclMap.end());
1030 EXPECT_FALSE(aclMap[dmVersion].empty());
1031 }
1032
1033 HWTEST_F(DeviceProfileConnectorSecondTest, GenerateAclHash_001, testing::ext::TestSize.Level1)
1034 {
1035 DistributedDeviceProfile::AccessControlProfile acl;
1036 acl.SetAccessControlId(12345);
1037 acl.SetAccesserId(1);
1038 acl.SetAccesseeId(2);
1039 acl.SetTrustDeviceId("trustDeviceId");
1040 acl.SetBindType(256);
1041 acl.SetAuthenticationType(2);
1042 acl.SetDeviceIdType(1);
1043 acl.SetStatus(1);
1044 acl.SetBindLevel(1);
1045
1046 std::map<std::string, std::vector<std::string>> aclMap;
1047 std::string dmVersion = DM_VERSION_5_1_0;
1048
1049 EXPECT_NO_THROW(DeviceProfileConnector::GetInstance().GenerateAclHash(acl, aclMap, dmVersion));
1050 EXPECT_EQ(aclMap.size(), 1);
1051 EXPECT_TRUE(aclMap.find(dmVersion) != aclMap.end());
1052 EXPECT_FALSE(aclMap[dmVersion].empty());
1053 }
1054
1055 HWTEST_F(DeviceProfileConnectorSecondTest, GenerateAclHash_002, testing::ext::TestSize.Level1)
1056 {
1057 DistributedDeviceProfile::AccessControlProfile acl;
1058 acl.SetAccessControlId(12345);
1059 acl.SetAccesserId(1);
1060 acl.SetAccesseeId(2);
1061 acl.SetTrustDeviceId("trustDeviceId");
1062 acl.SetBindType(256);
1063 acl.SetAuthenticationType(2);
1064 acl.SetDeviceIdType(1);
1065 acl.SetStatus(1);
1066 acl.SetBindLevel(1);
1067
1068 std::map<std::string, std::vector<std::string>> aclMap;
1069 std::string dmVersion = "invalid_version";
1070
1071 EXPECT_NO_THROW(DeviceProfileConnector::GetInstance().GenerateAclHash(acl, aclMap, dmVersion));
1072 EXPECT_EQ(aclMap.size(), 0);
1073 }
1074
1075 HWTEST_F(DeviceProfileConnectorSecondTest, GenerateAclHash_003, testing::ext::TestSize.Level1)
1076 {
1077 DistributedDeviceProfile::AccessControlProfile acl;
1078 acl.SetAccessControlId(12345);
1079 acl.SetAccesserId(1);
1080 acl.SetAccesseeId(2);
1081 acl.SetTrustDeviceId("trustDeviceId");
1082 acl.SetBindType(256);
1083 acl.SetAuthenticationType(2);
1084 acl.SetDeviceIdType(1);
1085 acl.SetStatus(1);
1086 acl.SetBindLevel(1);
1087
1088 std::map<std::string, std::vector<std::string>> aclMap;
1089 std::string dmVersion = DM_VERSION_5_1_0;;
1090 aclMap[dmVersion].push_back("existing_hash");
1091
1092 EXPECT_NO_THROW(DeviceProfileConnector::GetInstance().GenerateAclHash(acl, aclMap, dmVersion));
1093 EXPECT_EQ(aclMap.size(), 1);
1094 EXPECT_TRUE(aclMap.find(dmVersion) != aclMap.end());
1095 EXPECT_EQ(aclMap[dmVersion].size(), 2);
1096 }
1097
1098
1099 HWTEST_F(DeviceProfileConnectorSecondTest, IsAuthNewVersion_001, testing::ext::TestSize.Level1)
1100 {
1101 int32_t bindLevel = 0;
1102 std::string localUdid = "localDeviceId";
1103 std::string remoteUdid = "remoteDeviceId";
1104 int32_t tokenId = 12345;
1105 int32_t userId = 1001;
1106
1107 std::string result = DeviceProfileConnector::GetInstance()
1108 .IsAuthNewVersion(bindLevel, localUdid, remoteUdid, tokenId, userId);
1109 EXPECT_TRUE(result.empty());
1110 }
1111
1112 HWTEST_F(DeviceProfileConnectorSecondTest, IsAuthNewVersion_002, testing::ext::TestSize.Level1)
1113 {
1114 int32_t bindLevel = 4;
1115 std::string localUdid = "localDeviceId";
1116 std::string remoteUdid = "remoteDeviceId";
1117 int32_t tokenId = 12345;
1118 int32_t userId = 1001;
1119
1120 std::string result = DeviceProfileConnector::GetInstance()
1121 .IsAuthNewVersion(bindLevel, localUdid, remoteUdid, tokenId, userId);
1122 EXPECT_TRUE(result.empty());
1123 }
1124
1125 HWTEST_F(DeviceProfileConnectorSecondTest, ChecksumAcl_001, testing::ext::TestSize.Level1)
1126 {
1127 DistributedDeviceProfile::AccessControlProfile acl;
1128 acl.SetAccessControlId(12345);
1129 acl.SetAccesserId(1);
1130 acl.SetAccesseeId(2);
1131 acl.SetTrustDeviceId("trustDeviceId");
1132 acl.SetBindType(256);
1133 acl.SetAuthenticationType(2);
1134 acl.SetDeviceIdType(1);
1135 acl.SetStatus(1);
1136 acl.SetBindLevel(1);
1137
1138 std::vector<std::string> acLStrList;
1139
1140 bool result = DeviceProfileConnector::GetInstance().ChecksumAcl(acl, acLStrList);
1141 EXPECT_FALSE(result);
1142 }
1143
1144 HWTEST_F(DeviceProfileConnectorSecondTest, ChecksumAcl_002, testing::ext::TestSize.Level1)
1145 {
1146 DistributedDeviceProfile::AccessControlProfile acl;
1147 acl.SetAccessControlId(12345);
1148 acl.SetAccesserId(1);
1149 acl.SetAccesseeId(2);
1150 acl.SetTrustDeviceId("trustDeviceId");
1151 acl.SetBindType(256);
1152 acl.SetAuthenticationType(2);
1153 acl.SetDeviceIdType(1);
1154 acl.SetStatus(1);
1155 acl.SetBindLevel(1);
1156
1157 std::string aclStr = DeviceProfileConnector::GetInstance().AccessToStr(acl);
1158 std::string aclHash = Crypto::Sha256(aclStr);
1159
1160 std::vector<std::string> acLStrList = {aclHash};
1161
1162 bool result = DeviceProfileConnector::GetInstance().ChecksumAcl(acl, acLStrList);
1163 EXPECT_TRUE(result);
1164 }
1165
1166 HWTEST_F(DeviceProfileConnectorSecondTest, ChecksumAcl_003, testing::ext::TestSize.Level1)
1167 {
1168 DistributedDeviceProfile::AccessControlProfile acl;
1169 acl.SetAccessControlId(12345);
1170 acl.SetAccesserId(1);
1171 acl.SetAccesseeId(2);
1172 acl.SetTrustDeviceId("trustDeviceId");
1173 acl.SetBindType(256);
1174 acl.SetAuthenticationType(2);
1175 acl.SetDeviceIdType(1);
1176 acl.SetStatus(1);
1177 acl.SetBindLevel(1);
1178
1179 std::vector<std::string> acLStrList = {"invalid_hash"};
1180
1181 bool result = DeviceProfileConnector::GetInstance().ChecksumAcl(acl, acLStrList);
1182 EXPECT_FALSE(result);
1183 }
1184
1185 HWTEST_F(DeviceProfileConnectorSecondTest, ChecksumAcl_004, testing::ext::TestSize.Level1)
1186 {
1187 DistributedDeviceProfile::AccessControlProfile acl;
1188 acl.SetAccessControlId(12345);
1189 acl.SetAccesserId(1);
1190 acl.SetAccesseeId(2);
1191 acl.SetTrustDeviceId("trustDeviceId");
1192 acl.SetBindType(256);
1193 acl.SetAuthenticationType(2);
1194 acl.SetDeviceIdType(1);
1195 acl.SetStatus(1);
1196 acl.SetBindLevel(1);
1197
1198 std::string aclStr = DeviceProfileConnector::GetInstance().AccessToStr(acl);
1199 std::string aclHash = Crypto::Sha256(aclStr);
1200
1201 std::vector<std::string> acLStrList = {"invalid_hash1", aclHash, "invalid_hash2"};
1202
1203 bool result = DeviceProfileConnector::GetInstance().ChecksumAcl(acl, acLStrList);
1204 EXPECT_TRUE(result);
1205 }
1206
1207 HWTEST_F(DeviceProfileConnectorSecondTest, ChecksumAcl_005, testing::ext::TestSize.Level1)
1208 {
1209 DistributedDeviceProfile::AccessControlProfile acl;
1210
1211 std::vector<std::string> acLStrList = {"some_hash"};
1212
1213 bool result = DeviceProfileConnector::GetInstance().ChecksumAcl(acl, acLStrList);
1214 EXPECT_FALSE(result);
1215 }
1216
1217 HWTEST_F(DeviceProfileConnectorSecondTest, AccessToStr_001, testing::ext::TestSize.Level1)
1218 {
1219 DistributedDeviceProfile::AccessControlProfile acl;
1220
1221 DistributedDeviceProfile::Accesser accesser;
1222 accesser.SetAccesserDeviceId("accesserDeviceId");
1223 accesser.SetAccesserUserId(1001);
1224 accesser.SetAccesserAccountId("accesserAccountId");
1225 accesser.SetAccesserTokenId(2001);
1226 accesser.SetAccesserBundleName("accesserBundleName");
1227 accesser.SetAccesserHapSignature("accesserHapSignature");
1228 accesser.SetAccesserBindLevel(1);
1229 accesser.SetAccesserCredentialIdStr("accesserCredentialIdStr");
1230 accesser.SetAccesserStatus(1);
1231 accesser.SetAccesserSKTimeStamp(1234567890);
1232
1233 DistributedDeviceProfile::Accessee accessee;
1234 accessee.SetAccesseeDeviceId("accesseeDeviceId");
1235 accessee.SetAccesseeUserId(1002);
1236 accessee.SetAccesseeAccountId("accesseeAccountId");
1237 accessee.SetAccesseeTokenId(2002);
1238 accessee.SetAccesseeBundleName("accesseeBundleName");
1239 accessee.SetAccesseeHapSignature("accesseeHapSignature");
1240 accessee.SetAccesseeBindLevel(2);
1241 accessee.SetAccesseeCredentialIdStr("accesseeCredentialIdStr");
1242 accessee.SetAccesseeStatus(2);
1243 accessee.SetAccesseeSKTimeStamp(987654321);
1244
1245 acl.SetAccesser(accesser);
1246 acl.SetAccessee(accessee);
1247
1248 std::string result = DeviceProfileConnector::GetInstance().AccessToStr(acl);
1249
1250 EXPECT_FALSE(result.empty());
1251 EXPECT_NE(result.find("accesserDeviceId"), std::string::npos);
1252 EXPECT_NE(result.find("accesserAccountId"), std::string::npos);
1253 EXPECT_NE(result.find("accesseeDeviceId"), std::string::npos);
1254 EXPECT_NE(result.find("accesseeAccountId"), std::string::npos);
1255 }
1256
1257 HWTEST_F(DeviceProfileConnectorSecondTest, AccessToStr_002, testing::ext::TestSize.Level1)
1258 {
1259 DistributedDeviceProfile::AccessControlProfile acl;
1260
1261 DistributedDeviceProfile::Accesser accesser;
1262 accesser.SetAccesserDeviceId("accesserDeviceId");
1263 accesser.SetAccesserUserId(1001);
1264 accesser.SetAccesserAccountId("accesserAccountId");
1265 accesser.SetAccesserTokenId(2001);
1266 accesser.SetAccesserBundleName("accesserBundleName");
1267 accesser.SetAccesserHapSignature("accesserHapSignature");
1268 accesser.SetAccesserBindLevel(1);
1269 accesser.SetAccesserCredentialIdStr("accesserCredentialIdStr");
1270 accesser.SetAccesserStatus(1);
1271 accesser.SetAccesserSKTimeStamp(1234567890);
1272
1273 acl.SetAccesser(accesser);
1274
1275 std::string result = DeviceProfileConnector::GetInstance().AccessToStr(acl);
1276
1277 EXPECT_FALSE(result.empty());
1278 EXPECT_NE(result.find("accesserDeviceId"), std::string::npos);
1279 EXPECT_NE(result.find("accesserAccountId"), std::string::npos);
1280 EXPECT_EQ(result.find("accesseeDeviceId"), std::string::npos);
1281 }
1282
1283 HWTEST_F(DeviceProfileConnectorSecondTest, AccessToStr_003, testing::ext::TestSize.Level1)
1284 {
1285 DistributedDeviceProfile::AccessControlProfile acl;
1286
1287 DistributedDeviceProfile::Accessee accessee;
1288 accessee.SetAccesseeDeviceId("accesseeDeviceId");
1289 accessee.SetAccesseeUserId(1002);
1290 accessee.SetAccesseeAccountId("accesseeAccountId");
1291 accessee.SetAccesseeTokenId(2002);
1292 accessee.SetAccesseeBundleName("accesseeBundleName");
1293 accessee.SetAccesseeHapSignature("accesseeHapSignature");
1294 accessee.SetAccesseeBindLevel(2);
1295 accessee.SetAccesseeCredentialIdStr("accesseeCredentialIdStr");
1296 accessee.SetAccesseeStatus(2);
1297 accessee.SetAccesseeSKTimeStamp(987654321);
1298
1299 acl.SetAccessee(accessee);
1300
1301 std::string result = DeviceProfileConnector::GetInstance().AccessToStr(acl);
1302
1303 EXPECT_FALSE(result.empty());
1304 EXPECT_EQ(result.find("accesserDeviceId"), std::string::npos);
1305 EXPECT_NE(result.find("accesseeDeviceId"), std::string::npos);
1306 EXPECT_NE(result.find("accesseeAccountId"), std::string::npos);
1307 }
1308
1309 HWTEST_F(DeviceProfileConnectorSecondTest, AccessToStr_004, testing::ext::TestSize.Level1)
1310 {
1311 DistributedDeviceProfile::AccessControlProfile acl;
1312
1313 DistributedDeviceProfile::Accesser accesser;
1314 accesser.SetAccesserDeviceId("accesserDeviceId");
1315 accesser.SetAccesserUserId(1001);
1316 accesser.SetAccesserAccountId("");
1317 accesser.SetAccesserTokenId(2001);
1318 accesser.SetAccesserBundleName("");
1319 accesser.SetAccesserHapSignature("accesserHapSignature");
1320 accesser.SetAccesserBindLevel(1);
1321 accesser.SetAccesserCredentialIdStr("");
1322 accesser.SetAccesserStatus(1);
1323 accesser.SetAccesserSKTimeStamp(1234567890);
1324
1325 DistributedDeviceProfile::Accessee accessee;
1326 accessee.SetAccesseeDeviceId("");
1327 accessee.SetAccesseeUserId(1002);
1328 accessee.SetAccesseeAccountId("accesseeAccountId");
1329 accessee.SetAccesseeTokenId(2002);
1330 accessee.SetAccesseeBundleName("accesseeBundleName");
1331 accessee.SetAccesseeHapSignature("");
1332 accessee.SetAccesseeBindLevel(2);
1333 accessee.SetAccesseeCredentialIdStr("accesseeCredentialIdStr");
1334 accessee.SetAccesseeStatus(2);
1335 accessee.SetAccesseeSKTimeStamp(987654321);
1336
1337 acl.SetAccesser(accesser);
1338 acl.SetAccessee(accessee);
1339 std::string result = DeviceProfileConnector::GetInstance().AccessToStr(acl);
1340
1341 EXPECT_FALSE(result.empty());
1342 EXPECT_NE(result.find("accesserDeviceId"), std::string::npos);
1343 EXPECT_EQ(result.find("accesserAccountId"), std::string::npos);
1344 EXPECT_NE(result.find("accesseeAccountId"), std::string::npos);
1345 EXPECT_EQ(result.find("accesseeDeviceId"), std::string::npos);
1346 }
1347
1348 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_001, testing::ext::TestSize.Level1)
1349 {
1350 std::string localUdid = "localDeviceId";
1351 std::string remoteUdid = "remoteDeviceId";
1352 int32_t tokenId = 12345;
1353 int32_t userId = 1001;
1354 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1355
1356 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1357 localUdid, remoteUdid, tokenId, userId, profiles);
1358 EXPECT_TRUE(result.empty());
1359 }
1360
1361 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_002, testing::ext::TestSize.Level1)
1362 {
1363 std::string localUdid = "localDeviceId";
1364 std::string remoteUdid = "remoteDeviceId";
1365 int32_t tokenId = 12345;
1366 int32_t userId = 1001;
1367 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1368
1369 DistributedDeviceProfile::AccessControlProfile profile;
1370 profile.SetBindType(DM_IDENTICAL_ACCOUNT);
1371 profiles.push_back(profile);
1372
1373 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1374 localUdid, remoteUdid, tokenId, userId, profiles);
1375 EXPECT_TRUE(result.empty());
1376 }
1377
1378 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_003, testing::ext::TestSize.Level1)
1379 {
1380 std::string localUdid = "localDeviceId";
1381 std::string remoteUdid = "remoteDeviceId";
1382 int32_t tokenId = 12345;
1383 int32_t userId = 1001;
1384 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1385
1386 DistributedDeviceProfile::AccessControlProfile profile;
1387 profile.SetBindLevel(USER);
1388 profiles.push_back(profile);
1389
1390 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1391 localUdid, remoteUdid, tokenId, userId, profiles);
1392 EXPECT_TRUE(result.empty());
1393 }
1394
1395 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_004, testing::ext::TestSize.Level1)
1396 {
1397 std::string localUdid = "localDeviceId";
1398 std::string remoteUdid = "remoteDeviceId";
1399 int32_t tokenId = 12345;
1400 int32_t userId = 1001;
1401 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1402
1403 DistributedDeviceProfile::AccessControlProfile profile;
1404 profile.SetBindType(DM_ACROSS_ACCOUNT);
1405 profile.SetBindLevel(APP);
1406
1407 DistributedDeviceProfile::Accesser accesser;
1408 accesser.SetAccesserUserId(userId);
1409 accesser.SetAccesserTokenId(tokenId);
1410 accesser.SetAccesserDeviceId(localUdid);
1411 accesser.SetAccesserExtraData("5.1.0");
1412 profile.SetAccesser(accesser);
1413
1414 DistributedDeviceProfile::Accessee accessee;
1415 accessee.SetAccesseeDeviceId(remoteUdid);
1416 profile.SetAccessee(accessee);
1417
1418 profiles.push_back(profile);
1419
1420 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1421 localUdid, remoteUdid, tokenId, userId, profiles);
1422 EXPECT_EQ(result, "5.1.0");
1423 }
1424
1425 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_005, testing::ext::TestSize.Level1)
1426 {
1427 std::string localUdid = "localDeviceId";
1428 std::string remoteUdid = "remoteDeviceId";
1429 int32_t tokenId = 12345;
1430 int32_t userId = 1001;
1431 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1432
1433 DistributedDeviceProfile::AccessControlProfile profile;
1434 profile.SetBindType(DM_ACROSS_ACCOUNT);
1435 profile.SetBindLevel(SERVICE);
1436
1437 DistributedDeviceProfile::Accesser accesser;
1438 accesser.SetAccesserDeviceId(remoteUdid);
1439 profile.SetAccesser(accesser);
1440
1441 DistributedDeviceProfile::Accessee accessee;
1442 accessee.SetAccesseeUserId(userId);
1443 accessee.SetAccesseeTokenId(tokenId);
1444 accessee.SetAccesseeDeviceId(localUdid);
1445 accessee.SetAccesseeExtraData("5.1.0");
1446 profile.SetAccessee(accessee);
1447
1448 profiles.push_back(profile);
1449
1450 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1451 localUdid, remoteUdid, tokenId, userId, profiles);
1452 EXPECT_EQ(result, "5.1.0");
1453 }
1454
1455 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_006, testing::ext::TestSize.Level1)
1456 {
1457 std::string localUdid = "localDeviceId";
1458 std::string remoteUdid = "remoteDeviceId";
1459 int32_t tokenId = 12345;
1460 int32_t userId = 1001;
1461 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1462
1463 DistributedDeviceProfile::AccessControlProfile profile;
1464 profile.SetBindType(DM_ACROSS_ACCOUNT);
1465 profile.SetBindLevel(APP);
1466
1467 DistributedDeviceProfile::Accesser accesser;
1468 accesser.SetAccesserUserId(9999);
1469 accesser.SetAccesserTokenId(tokenId);
1470 accesser.SetAccesserDeviceId(localUdid);
1471 accesser.SetAccesserExtraData("5.1.0");
1472 profile.SetAccesser(accesser);
1473
1474 DistributedDeviceProfile::Accessee accessee;
1475 accessee.SetAccesseeDeviceId(remoteUdid);
1476 profile.SetAccessee(accessee);
1477
1478 profiles.push_back(profile);
1479
1480 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1481 localUdid, remoteUdid, tokenId, userId, profiles);
1482 EXPECT_TRUE(result.empty());
1483 }
1484
1485 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_007, testing::ext::TestSize.Level1)
1486 {
1487 std::string localUdid = "localDeviceId";
1488 std::string remoteUdid = "remoteDeviceId";
1489 int32_t tokenId = 12345;
1490 int32_t userId = 1001;
1491 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1492
1493 DistributedDeviceProfile::AccessControlProfile profile;
1494 profile.SetBindType(DM_ACROSS_ACCOUNT);
1495 profile.SetBindLevel(SERVICE);
1496
1497 DistributedDeviceProfile::Accesser accesser;
1498 accesser.SetAccesserUserId(userId);
1499 accesser.SetAccesserTokenId(9999);
1500 accesser.SetAccesserDeviceId(localUdid);
1501 accesser.SetAccesserExtraData("5.1.0");
1502 profile.SetAccesser(accesser);
1503
1504 DistributedDeviceProfile::Accessee accessee;
1505 accessee.SetAccesseeDeviceId(remoteUdid);
1506 profile.SetAccessee(accessee);
1507
1508 profiles.push_back(profile);
1509
1510 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1511 localUdid, remoteUdid, tokenId, userId, profiles);
1512 EXPECT_TRUE(result.empty());
1513 }
1514
1515 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_008, testing::ext::TestSize.Level1)
1516 {
1517 std::string localUdid = "localDeviceId";
1518 std::string remoteUdid = "remoteDeviceId";
1519 int32_t tokenId = 12345;
1520 int32_t userId = 1001;
1521 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1522
1523 DistributedDeviceProfile::AccessControlProfile profile;
1524 profile.SetBindType(DM_ACROSS_ACCOUNT);
1525 profile.SetBindLevel(APP);
1526
1527 DistributedDeviceProfile::Accesser accesser;
1528 accesser.SetAccesserUserId(userId);
1529 accesser.SetAccesserTokenId(tokenId);
1530 accesser.SetAccesserDeviceId("wrongDeviceId");
1531 accesser.SetAccesserExtraData("5.1.0");
1532 profile.SetAccesser(accesser);
1533
1534 DistributedDeviceProfile::Accessee accessee;
1535 accessee.SetAccesseeDeviceId(remoteUdid);
1536 profile.SetAccessee(accessee);
1537
1538 profiles.push_back(profile);
1539
1540 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1541 localUdid, remoteUdid, tokenId, userId, profiles);
1542 EXPECT_TRUE(result.empty());
1543 }
1544
1545 HWTEST_F(DeviceProfileConnectorSecondTest, GetAppServiceAuthVersionInfo_009, testing::ext::TestSize.Level1)
1546 {
1547 std::string localUdid = "localDeviceId";
1548 std::string remoteUdid = "remoteDeviceId";
1549 int32_t tokenId = 12345;
1550 int32_t userId = 1001;
1551 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1552
1553 DistributedDeviceProfile::AccessControlProfile profile1;
1554 profile1.SetBindType(DM_IDENTICAL_ACCOUNT);
1555 profiles.push_back(profile1);
1556
1557 DistributedDeviceProfile::AccessControlProfile profile2;
1558 profile2.SetBindType(DM_ACROSS_ACCOUNT);
1559 profile2.SetBindLevel(USER);
1560 profiles.push_back(profile2);
1561
1562 DistributedDeviceProfile::AccessControlProfile profile3;
1563 profile3.SetBindType(DM_ACROSS_ACCOUNT);
1564 profile3.SetBindLevel(APP);
1565
1566 DistributedDeviceProfile::Accesser accesser;
1567 accesser.SetAccesserUserId(userId);
1568 accesser.SetAccesserTokenId(tokenId);
1569 accesser.SetAccesserDeviceId(localUdid);
1570 accesser.SetAccesserExtraData("5.1.0");
1571 profile3.SetAccesser(accesser);
1572
1573 DistributedDeviceProfile::Accessee accessee;
1574 accessee.SetAccesseeDeviceId(remoteUdid);
1575 profile3.SetAccessee(accessee);
1576
1577 profiles.push_back(profile3);
1578
1579 std::string result = DeviceProfileConnector::GetInstance().GetAppServiceAuthVersionInfo(
1580 localUdid, remoteUdid, tokenId, userId, profiles);
1581 EXPECT_EQ(result, "5.1.0");
1582 }
1583
1584 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceAuthVersionInfo_001, testing::ext::TestSize.Level1)
1585 {
1586 std::string localUdid = "localDeviceId";
1587 std::string remoteUdid = "remoteDeviceId";
1588 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles;
1589
1590 std::string result = DeviceProfileConnector::GetInstance()
1591 .GetDeviceAuthVersionInfo(localUdid, remoteUdid, profiles);
1592 EXPECT_EQ(result, "");
1593 }
1594
1595 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceAuthVersionInfo_002, testing::ext::TestSize.Level1)
1596 {
1597 std::string localUdid = "localDeviceId";
1598 std::string remoteUdid = "remoteDeviceId";
1599 DistributedDeviceProfile::AccessControlProfile profile;
1600 profile.SetBindType(DM_IDENTICAL_ACCOUNT);
1601 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles = {profile};
1602
1603 std::string result = DeviceProfileConnector::GetInstance()
1604 .GetDeviceAuthVersionInfo(localUdid, remoteUdid, profiles);
1605 EXPECT_EQ(result, "");
1606 }
1607
1608 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceAuthVersionInfo_003, testing::ext::TestSize.Level1)
1609 {
1610 std::string localUdid = "localDeviceId";
1611 std::string remoteUdid = "remoteDeviceId";
1612 DistributedDeviceProfile::AccessControlProfile profile;
1613 profile.SetBindType(DM_POINT_TO_POINT);
1614 profile.SetBindLevel(APP);
1615 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles = {profile};
1616
1617 std::string result = DeviceProfileConnector::GetInstance()
1618 .GetDeviceAuthVersionInfo(localUdid, remoteUdid, profiles);
1619 EXPECT_EQ(result, "");
1620 }
1621
1622 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceAuthVersionInfo_004, testing::ext::TestSize.Level1)
1623 {
1624 std::string localUdid = "localDeviceId";
1625 std::string remoteUdid = "remoteDeviceId";
1626 DistributedDeviceProfile::AccessControlProfile profile;
1627 profile.SetBindType(DM_POINT_TO_POINT);
1628 profile.SetBindLevel(USER);
1629 DistributedDeviceProfile::Accesser accesser;
1630 accesser.SetAccesserDeviceId(localUdid);
1631 accesser.SetAccesserExtraData("AccesserExtraData");
1632 profile.SetAccesser(accesser);
1633 DistributedDeviceProfile::Accessee accessee;
1634 accessee.SetAccesseeDeviceId(remoteUdid);
1635 profile.SetAccessee(accessee);
1636 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles = {profile};
1637
1638 std::string result = DeviceProfileConnector::GetInstance()
1639 .GetDeviceAuthVersionInfo(localUdid, remoteUdid, profiles);
1640 EXPECT_EQ(result, "AccesserExtraData");
1641 }
1642
1643 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceAuthVersionInfo_005, testing::ext::TestSize.Level1)
1644 {
1645 std::string localUdid = "localDeviceId";
1646 std::string remoteUdid = "remoteDeviceId";
1647 DistributedDeviceProfile::AccessControlProfile profile;
1648 profile.SetBindType(DM_POINT_TO_POINT);
1649 profile.SetBindLevel(USER);
1650 DistributedDeviceProfile::Accesser accesser;
1651 accesser.SetAccesserDeviceId(remoteUdid);
1652 profile.SetAccesser(accesser);
1653 DistributedDeviceProfile::Accessee accessee;
1654 accessee.SetAccesseeDeviceId(localUdid);
1655 accessee.SetAccesseeExtraData("AccesseeExtraData");
1656 profile.SetAccessee(accessee);
1657 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles = {profile};
1658
1659 std::string result = DeviceProfileConnector::GetInstance()
1660 .GetDeviceAuthVersionInfo(localUdid, remoteUdid, profiles);
1661 EXPECT_EQ(result, "AccesseeExtraData");
1662 }
1663
1664 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceAuthVersionInfo_006, testing::ext::TestSize.Level1)
1665 {
1666 std::string localUdid = "localDeviceId";
1667 std::string remoteUdid = "remoteDeviceId";
1668 DistributedDeviceProfile::AccessControlProfile profile;
1669 profile.SetBindType(DM_POINT_TO_POINT);
1670 profile.SetBindLevel(USER);
1671 DistributedDeviceProfile::Accesser accesser;
1672 accesser.SetAccesserDeviceId("differentDeviceId");
1673 profile.SetAccesser(accesser);
1674 std::vector<DistributedDeviceProfile::AccessControlProfile> profiles = {profile};
1675
1676 std::string result = DeviceProfileConnector::GetInstance()
1677 .GetDeviceAuthVersionInfo(localUdid, remoteUdid, profiles);
1678 EXPECT_EQ(result, "");
1679 }
1680 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_001, testing::ext::TestSize.Level1)
1681 {
1682 std::vector<int32_t> userIds;
1683 std::string emptyUdid;
1684 int32_t tokenId = 1234;
1685
1686 auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, emptyUdid, tokenId);
1687 EXPECT_TRUE(result.empty());
1688 }
1689
1690 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_002, testing::ext::TestSize.Level1)
1691 {
1692 std::vector<int32_t> emptyUserIds;
1693 std::string localUdid = "localDeviceId";
1694 int32_t tokenId = 1234;
1695
1696 auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(emptyUserIds, localUdid, tokenId);
1697 EXPECT_TRUE(result.empty());
1698 }
1699
1700 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_003, testing::ext::TestSize.Level1)
1701 {
1702 std::vector<int32_t> userIds = {1, 2};
1703 std::string emptyUdid;
1704 int32_t tokenId = 1234;
1705
1706 auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, emptyUdid, tokenId);
1707 EXPECT_TRUE(result.empty());
1708 }
1709
1710 HWTEST_F(DeviceProfileConnectorSecondTest, GetDeviceIdAndUdidListByTokenId_004, testing::ext::TestSize.Level1)
1711 {
1712 std::vector<int32_t> userIds = {1, 2};
1713 std::string localUdid = "localDeviceId";
1714 int32_t tokenId = 1234;
1715
1716 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAccessControlProfile(_)).WillOnce(Return(DM_OK));
1717 auto result = DeviceProfileConnector::GetInstance().GetDeviceIdAndUdidListByTokenId(userIds, localUdid, tokenId);
1718 EXPECT_TRUE(result.empty());
1719 }
1720
1721 HWTEST_F(DeviceProfileConnectorSecondTest, IsAllowAuthAlways_001, testing::ext::TestSize.Level1)
1722 {
1723 std::vector<DistributedDeviceProfile::AccessControlProfile> acls;
1724 AddAccessControlProfile(acls);
1725 auto &item = acls[0];
1726 item.SetAuthenticationType(ALLOW_AUTH_ALWAYS);
1727 std::string localUdid = item.GetAccesser().GetAccesserDeviceId();
1728 int32_t userId = item.GetAccesser().GetAccesserUserId();
1729 std::string peerUdid = item.GetAccessee().GetAccesseeDeviceId();
1730 std::string pkgName = item.GetAccesser().GetAccesserBundleName();
1731 uint64_t tokenId = item.GetAccesser().GetAccesserTokenId();
1732 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAclIncludeLnnAcl(_))
1733 .WillOnce(DoAll(SetArgReferee<0>(acls), Return(0)));
1734 bool result = DeviceProfileConnector::GetInstance().IsAllowAuthAlways(localUdid, userId, peerUdid,
1735 pkgName, tokenId);
1736 EXPECT_TRUE(result);
1737
1738 localUdid = item.GetAccessee().GetAccesseeDeviceId();
1739 userId = item.GetAccessee().GetAccesseeUserId();
1740 peerUdid = item.GetAccesser().GetAccesserDeviceId();
1741 pkgName = item.GetAccessee().GetAccesseeBundleName();
1742 tokenId = item.GetAccessee().GetAccesseeTokenId();
1743 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAclIncludeLnnAcl(_))
1744 .WillOnce(DoAll(SetArgReferee<0>(acls), Return(0)));
1745 result = DeviceProfileConnector::GetInstance().IsAllowAuthAlways(localUdid, userId, peerUdid,
1746 pkgName, tokenId);
1747 EXPECT_TRUE(result);
1748 }
1749
1750 HWTEST_F(DeviceProfileConnectorSecondTest, IsAllowAuthAlways_002, testing::ext::TestSize.Level1)
1751 {
1752 std::vector<DistributedDeviceProfile::AccessControlProfile> acls;
1753 AddAccessControlProfile(acls);
1754 auto &item = acls[0];
1755 std::string localUdid = item.GetAccesser().GetAccesserDeviceId();
1756 int32_t userId = item.GetAccesser().GetAccesserUserId();
1757 std::string peerUdid = item.GetAccessee().GetAccesseeDeviceId();
1758 std::string pkgName = item.GetAccesser().GetAccesserBundleName();
1759 uint64_t tokenId = item.GetAccesser().GetAccesserTokenId();
1760 item.SetAuthenticationType(ALLOW_AUTH_ONCE);
1761 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAclIncludeLnnAcl((_)))
1762 .WillOnce(DoAll(SetArgReferee<0>(acls), Return(0)));
1763 bool result = DeviceProfileConnector::GetInstance().IsAllowAuthAlways(localUdid, userId, peerUdid,
1764 pkgName, tokenId);
1765 EXPECT_FALSE(result);
1766 }
1767
1768 HWTEST_F(DeviceProfileConnectorSecondTest, IsAllowAuthAlways_003, testing::ext::TestSize.Level1)
1769 {
1770 std::vector<DistributedDeviceProfile::AccessControlProfile> acls;
1771 std::string localUdid = "localUdid3";
1772 int32_t userId = 3;
1773 std::string peerUdid = "peerUdid3";
1774 std::string pkgName = "com.example.app3";
1775 uint64_t tokenId = 123458;
1776 EXPECT_CALL(*distributedDeviceProfileClientMock_, GetAllAclIncludeLnnAcl((_)))
1777 .WillOnce(DoAll(SetArgReferee<0>(acls), Return(0)));
1778 bool result = DeviceProfileConnector::GetInstance().IsAllowAuthAlways(localUdid, userId, peerUdid,
1779 pkgName, tokenId);
1780 EXPECT_FALSE(result);
1781 }
1782 } // namespace DistributedHardware
1783 } // namespace OHOS
1784