1 /*
2 * Copyright (c) 2024-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_auth_manager_third.h"
17
18 #include "auth_message_processor.h"
19 #include "device_manager_service_listener.h"
20 #include "deviceprofile_connector.h"
21 #include "dm_auth_manager.h"
22 #include "dm_anonymous.h"
23 #include "dm_constants.h"
24 #include "dm_dialog_manager.h"
25 #include "dm_log.h"
26 #include "dm_radar_helper.h"
27 #include "multiple_user_connector.h"
28 #include "json_object.h"
29 #include "softbus_error_code.h"
30
31 static bool g_checkIsOnlineReturnBoolValue = false;
32 static bool g_checkSrcDevIdInAclForDevBindReturnBoolValue = false;
33 static bool g_isDevicesInP2PGroupReturnBoolValue = false;
34 static bool g_isIdenticalAccountReturnBoolValue = false;
35 static bool g_isLocked = false;
36 static bool g_reportAuthConfirmBoxReturnBoolValue = false;
37 static bool g_reportAuthInputPinBoxReturnBoolValue = false;
38 static int32_t g_bindType = INVALIED_TYPE;
39 static int32_t g_leftAclNumber = 0;
40 static int32_t g_trustNumber = 0;
41 static std::string g_accountId = "";
42 static std::string g_createSimpleMessageReturnDataStr = "{}";
43 static std::string g_peerUdidHash = "";
44
45 namespace OHOS {
46 namespace DistributedHardware {
CreateSimpleMessage(int32_t msgType)47 std::string AuthMessageProcessor::CreateSimpleMessage(int32_t msgType)
48 {
49 return g_createSimpleMessageReturnDataStr;
50 }
51
IsIdenticalAccount()52 bool DmAuthManager::IsIdenticalAccount()
53 {
54 return g_isIdenticalAccountReturnBoolValue;
55 }
56
GetPeerUdidHash(int32_t sessionId,std::string & peerUdidHash)57 void DmAuthManager::GetPeerUdidHash(int32_t sessionId, std::string &peerUdidHash)
58 {
59 peerUdidHash = g_peerUdidHash;
60 }
61
IsScreenLocked()62 bool DmAuthManager::IsScreenLocked()
63 {
64 return g_isLocked;
65 }
66
CheckIsOnline(const std::string & targetDeviceId)67 bool SoftbusConnector::CheckIsOnline(const std::string &targetDeviceId)
68 {
69 return g_checkIsOnlineReturnBoolValue;
70 }
71
ReportAuthConfirmBox(struct RadarInfo & info)72 bool DmRadarHelper::ReportAuthConfirmBox(struct RadarInfo &info)
73 {
74 return g_reportAuthConfirmBoxReturnBoolValue;
75 }
76
ReportAuthInputPinBox(struct RadarInfo & info)77 bool DmRadarHelper::ReportAuthInputPinBox(struct RadarInfo &info)
78 {
79 return g_reportAuthInputPinBoxReturnBoolValue;
80 }
81
GetTrustNumber(const std::string & deviceId)82 int32_t DeviceProfileConnector::GetTrustNumber(const std::string &deviceId)
83 {
84 return g_trustNumber;
85 }
86
GetOhosAccountId(void)87 std::string MultipleUserConnector::GetOhosAccountId(void)
88 {
89 return g_accountId;
90 }
91
IsDevicesInP2PGroup(const std::string & hostDevice,const std::string & peerDevice)92 bool HiChainConnector::IsDevicesInP2PGroup(const std::string &hostDevice, const std::string &peerDevice)
93 {
94 return g_isDevicesInP2PGroupReturnBoolValue;
95 }
96
CheckSrcDevIdInAclForDevBind(const std::string & pkgName,const std::string & deviceId)97 bool DeviceProfileConnector::CheckSrcDevIdInAclForDevBind(const std::string &pkgName, const std::string &deviceId)
98 {
99 return g_checkSrcDevIdInAclForDevBindReturnBoolValue;
100 }
101
SetUp()102 void DmAuthManagerTest::SetUp()
103 {
104 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
105 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
106 std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
107 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector = std::make_shared<HiChainAuthConnector>();
108 authManager_ = std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector);
109
110 authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
111 authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
112 authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
113 authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
114 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
115 authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
116 authManager_->hiChainAuthConnector_ = std::make_shared<HiChainAuthConnector>();
117 authManager_->softbusConnector_ = std::make_shared<SoftbusConnector>();
118 authManager_->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(
119 std::shared_ptr<ISoftbusSessionCallback>(authManager_));
120 authManager_->timer_ = std::make_shared<DmTimer>();
121 }
TearDown()122 void DmAuthManagerTest::TearDown()
123 {
124 g_bindType = INVALIED_TYPE;
125 g_createSimpleMessageReturnDataStr = "{}";
126 g_isIdenticalAccountReturnBoolValue = false;
127 g_leftAclNumber = 0;
128 g_peerUdidHash = "";
129 }
SetUpTestCase()130 void DmAuthManagerTest::SetUpTestCase() {}
TearDownTestCase()131 void DmAuthManagerTest::TearDownTestCase() {}
132
133 HWTEST_F(DmAuthManagerTest, ProcRespNegotiate001, testing::ext::TestSize.Level1)
134 {
135 JsonObject jsonObject;
136 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
137 int32_t sessionId = 0;
138 authManager_->remoteDeviceId_ = "ProcRespNegotiate001";
139 authManager_->ProcRespNegotiate(sessionId);
140
141 jsonObject[TAG_CRYPTO_SUPPORT] = false;
142 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
143 g_isIdenticalAccountReturnBoolValue = true;
144 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
145 authManager_->authResponseContext_->authType = AUTH_TYPE_CRE;
146 authManager_->ProcRespNegotiate(sessionId);
147
148 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
149 authManager_->authResponseState_->context_ = std::make_shared<DmAuthResponseContext>();
150 jsonObject[TAG_CRYPTO_SUPPORT] = true;
151 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
152 g_isIdenticalAccountReturnBoolValue = true;
153 authManager_->importAuthCode_ = "";
154 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
155 authManager_->authResponseState_->context_->cryptoSupport = false;
156 authManager_->ProcRespNegotiate(sessionId);
157
158 authManager_->authResponseState_->context_ = std::make_shared<DmAuthResponseContext>();
159 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
160 g_isIdenticalAccountReturnBoolValue = true;
161 authManager_->importAuthCode_ = "test";
162 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
163 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
164 authManager_->authResponseState_->context_->cryptoSupport = true;
165 authManager_->ProcRespNegotiate(sessionId);
166
167 authManager_->authResponseState_->context_ = std::make_shared<DmAuthResponseContext>();
168 jsonObject[TAG_CRYPTO_NAME] = "test";
169 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
170 g_isIdenticalAccountReturnBoolValue = true;
171 authManager_->importAuthCode_ = "test";
172 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
173 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
174 authManager_->authResponseState_->context_->cryptoSupport = true;
175 authManager_->ProcRespNegotiate(sessionId);
176 EXPECT_FALSE(authManager_->authResponseContext_->isOnline);
177 }
178
179 HWTEST_F(DmAuthManagerTest, ProcRespNegotiate002, testing::ext::TestSize.Level1)
180 {
181 JsonObject jsonObject;
182 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
183 int32_t sessionId = 0;
184 authManager_->authResponseState_->context_ = std::make_shared<DmAuthResponseContext>();
185 jsonObject[TAG_CRYPTO_SUPPORT] = true;
186 jsonObject[TAG_CRYPTO_NAME] = "test";
187 jsonObject[TAG_CRYPTO_VERSION] = "test";
188 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
189 g_isIdenticalAccountReturnBoolValue = false;
190 authManager_->remoteDeviceId_ = "ProcRespNegotiate002";
191 authManager_->importAuthCode_ = "test";
192 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
193 authManager_->authResponseState_->context_->cryptoSupport = true;
194 authManager_->authResponseState_->context_->cryptoName = jsonObject[TAG_CRYPTO_NAME].Get<std::string>();
195 authManager_->ProcRespNegotiate(sessionId);
196 EXPECT_FALSE(authManager_->authResponseContext_->isOnline);
197
198 authManager_->authResponseState_->context_ = std::make_shared<DmAuthResponseContext>();
199 jsonObject[TAG_CRYPTO_SUPPORT] = true;
200 jsonObject[TAG_CRYPTO_NAME] = "test";
201 jsonObject[TAG_CRYPTO_VERSION] = "test";
202 g_createSimpleMessageReturnDataStr = jsonObject.Dump();
203 g_isIdenticalAccountReturnBoolValue = false;
204 authManager_->importAuthCode_ = "test";
205 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
206 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
207 authManager_->authResponseState_->context_->cryptoSupport = true;
208 authManager_->authResponseState_->context_->cryptoName = jsonObject[TAG_CRYPTO_NAME].Get<std::string>();
209 authManager_->authResponseState_->context_->cryptoVer = jsonObject[TAG_CRYPTO_VERSION].Get<std::string>();
210 authManager_->ProcRespNegotiate(sessionId);
211 EXPECT_FALSE(authManager_->authResponseContext_->isOnline);
212 }
213
214 HWTEST_F(DmAuthManagerTest, AuthenticateFinish001, testing::ext::TestSize.Level1)
215 {
216 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
217 std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
218 authManager_->authUiStateMgr_ = std::make_shared<AuthUiStateManager>(listener);
219 authManager_->authResponseState_ = nullptr;
220 authManager_->remoteVersion_ = "4.1.5.2";
221 authManager_->authResponseContext_->bindLevel = INVALIED_TYPE;
222 authManager_->authResponseContext_->isFinish = true;
223 authManager_->authRequestState_ = std::make_shared<AuthRequestJoinState>();
224 g_checkIsOnlineReturnBoolValue = true;
225 g_trustNumber = 1;
226 authManager_->softbusConnector_->deviceStateManagerCallback_ = std::make_shared<SoftbusStateCallbackMock>();
227 authManager_->AuthenticateFinish();
228 ASSERT_EQ(authManager_->authMessageProcessor_, nullptr);
229
230 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
231 authManager_->authResponseContext_->isFinish = false;
232 g_trustNumber = 1;
233 authManager_->AuthenticateFinish();
234 ASSERT_EQ(authManager_->authMessageProcessor_, nullptr);
235
236 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
237 g_checkIsOnlineReturnBoolValue = false;
238 g_trustNumber = 1;
239 authManager_->AuthenticateFinish();
240 ASSERT_EQ(authManager_->authMessageProcessor_, nullptr);
241
242 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
243 authManager_->authResponseContext_->bindLevel = APP_PEER_TO_PEER_TYPE;
244 g_trustNumber = 1;
245 authManager_->AuthenticateFinish();
246 ASSERT_EQ(authManager_->authMessageProcessor_, nullptr);
247
248 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
249 authManager_->remoteVersion_ = "4.1.5.0";
250 g_trustNumber = 2;
251 authManager_->AuthenticateFinish();
252 ASSERT_EQ(authManager_->authMessageProcessor_, nullptr);
253
254 g_trustNumber = 0;
255 authManager_->AuthenticateFinish();
256 ASSERT_EQ(authManager_->authMessageProcessor_, nullptr);
257 }
258
259 HWTEST_F(DmAuthManagerTest, ShowStartAuthDialog001, testing::ext::TestSize.Level1)
260 {
261 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
262 authManager_->authRequestState_ = nullptr;
263 authManager_->authResponseState_ = nullptr;
264 g_isLocked = true;
265 authManager_->ShowStartAuthDialog();
266 ASSERT_EQ(authManager_->authResponseContext_->state, STATUS_DM_AUTH_DEFAULT);
267
268 g_isLocked = false;
269 authManager_->authResponseContext_->targetDeviceName = "test";
270 authManager_->ShowStartAuthDialog();
271 ASSERT_EQ(authManager_->authResponseContext_->targetDeviceName, DmDialogManager::GetInstance().targetDeviceName_);
272 }
273
274 HWTEST_F(DmAuthManagerTest, ShowStartAuthDialog002, testing::ext::TestSize.Level0)
275 {
276 authManager_->authResponseContext_->authType = AUTH_TYPE_NFC;
277 authManager_->importAuthCode_ = "123456";
278 authManager_->importPkgName_ = "hostPkgName";
279 authManager_->authResponseContext_->hostPkgName = "hostPkgName";
280 authManager_->authResponseContext_->targetDeviceName = "ShowStartAuthDialog_004";
281 authManager_->ShowStartAuthDialog();
282 EXPECT_NE(authManager_->authResponseContext_->targetDeviceName, DmDialogManager::GetInstance().targetDeviceName_);
283 }
284
285 HWTEST_F(DmAuthManagerTest, DeleteAcl001, testing::ext::TestSize.Level0)
286 {
287 std::string pkgName = "pkgName";
288 std::string localUdid = "localUdid";
289 std::string remoteUdid = "remoteUdid";
290 std::string extra = "extraTest";
291 int32_t sessionId = 0;
292 int32_t bindLevel = APP;
293 g_bindType = INVALIED_TYPE;
294 int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
295 EXPECT_EQ(ret, ERR_DM_FAILED);
296 }
297
298 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList001, testing::ext::TestSize.Level1)
299 {
300 DmOfflineParam offlineParam;
301 offlineParam.leftAclNumber = 1;
302 std::string pkgName = "pkgName";
303 std::string localDeviceId = "localDeviceId";
304 std::string remoteDeviceId = "remoteDeviceId";
305 int32_t bindLevel = APP;
306 std::string extra = "";
307 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
308 remoteDeviceId, bindLevel, extra);
309 EXPECT_EQ(0, ret.leftAclNumber);
310 }
311
312 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList002, testing::ext::TestSize.Level1)
313 {
314 DmOfflineParam offlineParam;
315 offlineParam.leftAclNumber = 1;
316 std::string pkgName = "pkgName";
317 std::string localDeviceId = "localDeviceId";
318 std::string remoteDeviceId = "remoteDeviceId";
319 int32_t bindLevel = APP;
320 std::string extra = "extratest";
321 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
322 remoteDeviceId, bindLevel, extra);
323 EXPECT_EQ(0, ret.leftAclNumber);
324 }
325
326 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList003, testing::ext::TestSize.Level1)
327 {
328 DmOfflineParam offlineParam;
329 offlineParam.leftAclNumber = 1;
330 std::string pkgName = "pkgName";
331 std::string localDeviceId = "localDeviceId";
332 std::string remoteDeviceId = "remoteDeviceId";
333 int32_t bindLevel = SERVICE;
334 std::string extra = "extratest";
335 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
336 remoteDeviceId, bindLevel, extra);
337 EXPECT_EQ(0, ret.leftAclNumber);
338 }
339
340 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList004, testing::ext::TestSize.Level1)
341 {
342 DmOfflineParam offlineParam;
343 offlineParam.leftAclNumber = 1;
344 std::string pkgName = "pkgName";
345 std::string localDeviceId = "localDeviceId";
346 std::string remoteDeviceId = "remoteDeviceId";
347 int32_t bindLevel = USER;
348 std::string extra = "";
349 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
350 remoteDeviceId, bindLevel, extra);
351 EXPECT_EQ(0, ret.leftAclNumber);
352 }
353
354 HWTEST_F(DmAuthManagerTest, OnUserOperation001, testing::ext::TestSize.Level1)
355 {
356 int32_t action = USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT;
357 std::string params = "12345";
358 g_reportAuthConfirmBoxReturnBoolValue = false;
359 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
360 g_reportAuthInputPinBoxReturnBoolValue = true;
361 int32_t ret = authManager_->OnUserOperation(action, params);
362 g_reportAuthInputPinBoxReturnBoolValue = false;
363 ASSERT_EQ(ret, DM_OK);
364 }
365
366 HWTEST_F(DmAuthManagerTest, OnUserOperation002, testing::ext::TestSize.Level1)
367 {
368 int32_t action = USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY;
369 std::string params = "12345";
370 g_reportAuthConfirmBoxReturnBoolValue = false;
371 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
372 g_reportAuthInputPinBoxReturnBoolValue = true;
373 int32_t ret = authManager_->OnUserOperation(action, params);
374 g_reportAuthInputPinBoxReturnBoolValue = false;
375 ASSERT_EQ(ret, DM_OK);
376 }
377
378 HWTEST_F(DmAuthManagerTest, OnUserOperation003, testing::ext::TestSize.Level1)
379 {
380 int32_t action = USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT;
381 std::string params = "12345";
382 g_reportAuthConfirmBoxReturnBoolValue = false;
383 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
384 g_reportAuthInputPinBoxReturnBoolValue = true;
385 int32_t ret = authManager_->OnUserOperation(action, params);
386 g_reportAuthInputPinBoxReturnBoolValue = false;
387 ASSERT_EQ(ret, DM_OK);
388 }
389
390 HWTEST_F(DmAuthManagerTest, OnUserOperation004, testing::ext::TestSize.Level1)
391 {
392 int32_t action = USER_OPERATION_TYPE_DONE_PINCODE_INPUT;
393 std::string params = "12345";
394 g_reportAuthConfirmBoxReturnBoolValue = false;
395 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
396 g_reportAuthInputPinBoxReturnBoolValue = true;
397 int32_t ret = authManager_->OnUserOperation(action, params);
398 g_reportAuthInputPinBoxReturnBoolValue = false;
399 ASSERT_EQ(ret, DM_OK);
400 }
401
402 HWTEST_F(DmAuthManagerTest, ProcRespNegotiateExt001, testing::ext::TestSize.Level1)
403 {
404 int32_t sessionId = 0;
405 g_accountId = "test";
406 authManager_->authResponseContext_->localAccountId = "test";
407 authManager_->authenticationMap_.clear();
408 authManager_->authResponseContext_->hostPkgName = "test";
409 authManager_->importPkgName_ = "test";
410 authManager_->importAuthCode_ = "12345";
411 authManager_->ProcRespNegotiateExt(sessionId);
412 ASSERT_EQ(authManager_->authResponseContext_->reply, ERR_DM_UNSUPPORTED_AUTH_TYPE);
413 g_accountId = "";
414 }
415
416 HWTEST_F(DmAuthManagerTest, ProcRespNegotiateExt002, testing::ext::TestSize.Level1)
417 {
418 authManager_->authenticationMap_.clear();
419 authManager_->authResponseContext_->hostPkgName = "test";
420 authManager_->authResponseContext_->localAccountId = "test";
421 authManager_->importAuthCode_ = "12345";
422 authManager_->importPkgName_ = "test";
423 g_accountId = "ohosAnonymousUid";
424 int32_t sessionId = 0;
425 authManager_->ProcRespNegotiateExt(sessionId);
426 ASSERT_EQ(authManager_->authResponseContext_->reply, ERR_DM_UNSUPPORTED_AUTH_TYPE);
427 g_accountId = "";
428 }
429
430 HWTEST_F(DmAuthManagerTest, CheckTrustState_001, testing::ext::TestSize.Level1)
431 {
432 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
433 authManager_->authResponseContext_->importAuthCode = "importAuthCode";
434 authManager_->authResponseContext_->isIdenticalAccount = true;
435 authManager_->authResponseContext_->isOnline = true;
436 authManager_->importAuthCode_ = "";
437 g_isIdenticalAccountReturnBoolValue = true;
438 int32_t ret = authManager_->CheckTrustState();
439 g_isIdenticalAccountReturnBoolValue = false;
440 ASSERT_EQ(ret, 1);
441 }
442
443 HWTEST_F(DmAuthManagerTest, CheckTrustState_002, testing::ext::TestSize.Level1)
444 {
445 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
446 authManager_->authResponseContext_->importAuthCode = "";
447 authManager_->authResponseContext_->isAuthCodeReady = false;
448 authManager_->authResponseContext_->isIdenticalAccount = true;
449 authManager_->authResponseContext_->isOnline = true;
450 authManager_->authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT;
451 g_checkSrcDevIdInAclForDevBindReturnBoolValue = false;
452 g_isDevicesInP2PGroupReturnBoolValue = true;
453 g_isIdenticalAccountReturnBoolValue = false;
454 int32_t ret = authManager_->CheckTrustState();
455 g_isDevicesInP2PGroupReturnBoolValue = false;
456 ASSERT_EQ(ret, 1);
457 }
458
459 HWTEST_F(DmAuthManagerTest, CheckTrustState_003, testing::ext::TestSize.Level1)
460 {
461 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
462 authManager_->authResponseContext_->importAuthCode = "";
463 authManager_->authResponseContext_->isAuthCodeReady = false;
464 authManager_->authResponseContext_->isIdenticalAccount = true;
465 authManager_->authResponseContext_->isOnline = true;
466 authManager_->authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT;
467 g_checkSrcDevIdInAclForDevBindReturnBoolValue = true;
468 g_isDevicesInP2PGroupReturnBoolValue = true;
469 g_isIdenticalAccountReturnBoolValue = false;
470 int32_t ret = authManager_->CheckTrustState();
471 g_isDevicesInP2PGroupReturnBoolValue = false;
472 ASSERT_EQ(ret, 1);
473 }
474
475 HWTEST_F(DmAuthManagerTest, CheckTrustState_004, testing::ext::TestSize.Level1)
476 {
477 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
478 authManager_->authResponseContext_->importAuthCode = "";
479 authManager_->authResponseContext_->isIdenticalAccount = true;
480 authManager_->authResponseContext_->isOnline = true;
481 authManager_->authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT;
482 g_isDevicesInP2PGroupReturnBoolValue = false;
483 g_isIdenticalAccountReturnBoolValue = false;
484 int32_t ret = authManager_->CheckTrustState();
485 ASSERT_EQ(ret, DM_OK);
486 }
487
488 HWTEST_F(DmAuthManagerTest, CheckTrustState_005, testing::ext::TestSize.Level1)
489 {
490 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
491 authManager_->authResponseContext_->importAuthCode = "";
492 authManager_->authResponseContext_->isIdenticalAccount = true;
493 authManager_->authResponseContext_->isOnline = false;
494 authManager_->authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE;
495 g_isDevicesInP2PGroupReturnBoolValue = false;
496 g_isIdenticalAccountReturnBoolValue = false;
497 int32_t ret = authManager_->CheckTrustState();
498 ASSERT_EQ(ret, ERR_DM_BIND_PEER_UNSUPPORTED);
499 }
500
501 HWTEST_F(DmAuthManagerTest, CheckTrustState_006, testing::ext::TestSize.Level1)
502 {
503 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
504 authManager_->authResponseContext_->importAuthCode = "";
505 authManager_->authResponseContext_->isAuthCodeReady = false;
506 authManager_->authResponseContext_->isIdenticalAccount = true;
507 authManager_->authResponseContext_->isOnline = false;
508 authManager_->authResponseContext_->reply = AUTH_TYPE_IMPORT_AUTH_CODE;
509 g_isDevicesInP2PGroupReturnBoolValue = false;
510 g_isIdenticalAccountReturnBoolValue = false;
511 int32_t ret = authManager_->CheckTrustState();
512 ASSERT_EQ(ret, ERR_DM_BIND_PEER_UNSUPPORTED);
513 }
514
515 HWTEST_F(DmAuthManagerTest, CheckTrustState_007, testing::ext::TestSize.Level1)
516 {
517 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
518 authManager_->authResponseContext_->importAuthCode = "";
519 authManager_->authResponseContext_->isAuthCodeReady = false;
520 authManager_->authResponseContext_->isIdenticalAccount = true;
521 authManager_->authResponseContext_->isOnline = false;
522 authManager_->authResponseContext_->reply = AUTH_TYPE_IMPORT_AUTH_CODE;
523 g_isDevicesInP2PGroupReturnBoolValue = false;
524 g_isIdenticalAccountReturnBoolValue = false;
525 int32_t ret = authManager_->CheckTrustState();
526 ASSERT_EQ(ret, DM_OK);
527 }
528
529 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_001, testing::ext::TestSize.Level1)
530 {
531 std::string delaySecondsStr("123jlk");
532 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
533 ASSERT_EQ(ret, 0);
534 }
535
536 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_002, testing::ext::TestSize.Level1)
537 {
538 std::string delaySecondsStr("123");
539 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
540 ASSERT_EQ(ret, 0);
541 }
542
543 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_003, testing::ext::TestSize.Level1)
544 {
545 std::string delaySecondsStr("5");
546 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
547 ASSERT_EQ(ret, 5);
548 }
549
550 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_004, testing::ext::TestSize.Level1)
551 {
552 std::string delaySecondsStr("10");
553 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
554 ASSERT_EQ(ret, 10);
555 }
556
557 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_005, testing::ext::TestSize.Level1)
558 {
559 std::string delaySecondsStr("0");
560 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
561 ASSERT_EQ(ret, 0);
562 }
563 } // namespace DistributedHardware
564 } // namespace OHOS
565