1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "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.Level0)
134 {
135 JsonObject jsonObject;
136 g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject);
137 int32_t sessionId = 0;
138 authManager_->remoteDeviceId_ = "ProcRespNegotiate001";
139 authManager_->ProcRespNegotiate(sessionId);
140
141 jsonObject[TAG_CRYPTO_SUPPORT] = false;
142 g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject);
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 = SafetyDump(jsonObject);
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 = SafetyDump(jsonObject);
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 = SafetyDump(jsonObject);
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.Level0)
180 {
181 JsonObject jsonObject;
182 g_createSimpleMessageReturnDataStr = SafetyDump(jsonObject);
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 = SafetyDump(jsonObject);
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 = SafetyDump(jsonObject);
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.Level0)
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.Level0)
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, DeleteAcl001, testing::ext::TestSize.Level0)
275 {
276 std::string pkgName = "pkgName";
277 std::string localUdid = "localUdid";
278 std::string remoteUdid = "remoteUdid";
279 std::string extra = "extraTest";
280 int32_t sessionId = 0;
281 int32_t bindLevel = APP;
282 g_bindType = INVALIED_TYPE;
283 int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
284 EXPECT_EQ(ret, ERR_DM_FAILED);
285 }
286
287 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList001, testing::ext::TestSize.Level0)
288 {
289 DmOfflineParam offlineParam;
290 offlineParam.leftAclNumber = 1;
291 std::string pkgName = "pkgName";
292 std::string localDeviceId = "localDeviceId";
293 std::string remoteDeviceId = "remoteDeviceId";
294 int32_t bindLevel = APP;
295 std::string extra = "";
296 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
297 remoteDeviceId, bindLevel, extra);
298 EXPECT_EQ(0, ret.leftAclNumber);
299 }
300
301 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList002, testing::ext::TestSize.Level0)
302 {
303 DmOfflineParam offlineParam;
304 offlineParam.leftAclNumber = 1;
305 std::string pkgName = "pkgName";
306 std::string localDeviceId = "localDeviceId";
307 std::string remoteDeviceId = "remoteDeviceId";
308 int32_t bindLevel = APP;
309 std::string extra = "extratest";
310 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
311 remoteDeviceId, bindLevel, extra);
312 EXPECT_EQ(0, ret.leftAclNumber);
313 }
314
315 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList003, testing::ext::TestSize.Level0)
316 {
317 DmOfflineParam offlineParam;
318 offlineParam.leftAclNumber = 1;
319 std::string pkgName = "pkgName";
320 std::string localDeviceId = "localDeviceId";
321 std::string remoteDeviceId = "remoteDeviceId";
322 int32_t bindLevel = SERVICE;
323 std::string extra = "extratest";
324 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
325 remoteDeviceId, bindLevel, extra);
326 EXPECT_EQ(0, ret.leftAclNumber);
327 }
328
329 HWTEST_F(DmAuthManagerTest, DeleteAccessControlList004, testing::ext::TestSize.Level0)
330 {
331 DmOfflineParam offlineParam;
332 offlineParam.leftAclNumber = 1;
333 std::string pkgName = "pkgName";
334 std::string localDeviceId = "localDeviceId";
335 std::string remoteDeviceId = "remoteDeviceId";
336 int32_t bindLevel = DEVICE;
337 std::string extra = "";
338 auto ret = DeviceProfileConnector::GetInstance().DeleteAccessControlList(pkgName, localDeviceId,
339 remoteDeviceId, bindLevel, extra);
340 EXPECT_EQ(0, ret.leftAclNumber);
341 }
342
343 HWTEST_F(DmAuthManagerTest, OnUserOperation001, testing::ext::TestSize.Level0)
344 {
345 int32_t action = USER_OPERATION_TYPE_AUTH_CONFIRM_TIMEOUT;
346 std::string params = "12345";
347 g_reportAuthConfirmBoxReturnBoolValue = false;
348 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
349 g_reportAuthInputPinBoxReturnBoolValue = true;
350 int32_t ret = authManager_->OnUserOperation(action, params);
351 g_reportAuthInputPinBoxReturnBoolValue = false;
352 ASSERT_EQ(ret, DM_OK);
353 }
354
355 HWTEST_F(DmAuthManagerTest, OnUserOperation002, testing::ext::TestSize.Level0)
356 {
357 int32_t action = USER_OPERATION_TYPE_CANCEL_PINCODE_DISPLAY;
358 std::string params = "12345";
359 g_reportAuthConfirmBoxReturnBoolValue = false;
360 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
361 g_reportAuthInputPinBoxReturnBoolValue = true;
362 int32_t ret = authManager_->OnUserOperation(action, params);
363 g_reportAuthInputPinBoxReturnBoolValue = false;
364 ASSERT_EQ(ret, DM_OK);
365 }
366
367 HWTEST_F(DmAuthManagerTest, OnUserOperation003, testing::ext::TestSize.Level0)
368 {
369 int32_t action = USER_OPERATION_TYPE_CANCEL_PINCODE_INPUT;
370 std::string params = "12345";
371 g_reportAuthConfirmBoxReturnBoolValue = false;
372 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
373 g_reportAuthInputPinBoxReturnBoolValue = true;
374 int32_t ret = authManager_->OnUserOperation(action, params);
375 g_reportAuthInputPinBoxReturnBoolValue = false;
376 ASSERT_EQ(ret, DM_OK);
377 }
378
379 HWTEST_F(DmAuthManagerTest, OnUserOperation004, testing::ext::TestSize.Level0)
380 {
381 int32_t action = USER_OPERATION_TYPE_DONE_PINCODE_INPUT;
382 std::string params = "12345";
383 g_reportAuthConfirmBoxReturnBoolValue = false;
384 authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
385 g_reportAuthInputPinBoxReturnBoolValue = true;
386 int32_t ret = authManager_->OnUserOperation(action, params);
387 g_reportAuthInputPinBoxReturnBoolValue = false;
388 ASSERT_EQ(ret, DM_OK);
389 }
390
391 HWTEST_F(DmAuthManagerTest, ProcRespNegotiateExt001, testing::ext::TestSize.Level0)
392 {
393 int32_t sessionId = 0;
394 g_accountId = "test";
395 authManager_->authResponseContext_->localAccountId = "test";
396 authManager_->authenticationMap_.clear();
397 authManager_->authResponseContext_->hostPkgName = "test";
398 authManager_->importPkgName_ = "test";
399 authManager_->importAuthCode_ = "12345";
400 authManager_->ProcRespNegotiateExt(sessionId);
401 ASSERT_EQ(authManager_->authResponseContext_->reply, ERR_DM_UNSUPPORTED_AUTH_TYPE);
402 g_accountId = "";
403 }
404
405 HWTEST_F(DmAuthManagerTest, ProcRespNegotiateExt002, testing::ext::TestSize.Level0)
406 {
407 authManager_->authenticationMap_.clear();
408 authManager_->authResponseContext_->hostPkgName = "test";
409 authManager_->authResponseContext_->localAccountId = "test";
410 authManager_->importAuthCode_ = "12345";
411 authManager_->importPkgName_ = "test";
412 g_accountId = "ohosAnonymousUid";
413 int32_t sessionId = 0;
414 authManager_->ProcRespNegotiateExt(sessionId);
415 ASSERT_EQ(authManager_->authResponseContext_->reply, ERR_DM_UNSUPPORTED_AUTH_TYPE);
416 g_accountId = "";
417 }
418
419 HWTEST_F(DmAuthManagerTest, CheckTrustState_001, testing::ext::TestSize.Level0)
420 {
421 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
422 authManager_->authResponseContext_->importAuthCode = "importAuthCode";
423 authManager_->authResponseContext_->isIdenticalAccount = true;
424 authManager_->authResponseContext_->isOnline = true;
425 authManager_->importAuthCode_ = "";
426 g_isIdenticalAccountReturnBoolValue = true;
427 int32_t ret = authManager_->CheckTrustState();
428 g_isIdenticalAccountReturnBoolValue = false;
429 ASSERT_EQ(ret, 1);
430 }
431
432 HWTEST_F(DmAuthManagerTest, CheckTrustState_002, testing::ext::TestSize.Level0)
433 {
434 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
435 authManager_->authResponseContext_->importAuthCode = "";
436 authManager_->authResponseContext_->isAuthCodeReady = false;
437 authManager_->authResponseContext_->isIdenticalAccount = true;
438 authManager_->authResponseContext_->isOnline = true;
439 authManager_->authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT;
440 g_checkSrcDevIdInAclForDevBindReturnBoolValue = false;
441 g_isDevicesInP2PGroupReturnBoolValue = true;
442 g_isIdenticalAccountReturnBoolValue = false;
443 int32_t ret = authManager_->CheckTrustState();
444 g_isDevicesInP2PGroupReturnBoolValue = false;
445 ASSERT_EQ(ret, 1);
446 }
447
448 HWTEST_F(DmAuthManagerTest, CheckTrustState_003, testing::ext::TestSize.Level0)
449 {
450 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
451 authManager_->authResponseContext_->importAuthCode = "";
452 authManager_->authResponseContext_->isAuthCodeReady = false;
453 authManager_->authResponseContext_->isIdenticalAccount = true;
454 authManager_->authResponseContext_->isOnline = true;
455 authManager_->authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT;
456 g_checkSrcDevIdInAclForDevBindReturnBoolValue = true;
457 g_isDevicesInP2PGroupReturnBoolValue = true;
458 g_isIdenticalAccountReturnBoolValue = false;
459 int32_t ret = authManager_->CheckTrustState();
460 g_isDevicesInP2PGroupReturnBoolValue = false;
461 ASSERT_EQ(ret, 1);
462 }
463
464 HWTEST_F(DmAuthManagerTest, CheckTrustState_004, testing::ext::TestSize.Level0)
465 {
466 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
467 authManager_->authResponseContext_->importAuthCode = "";
468 authManager_->authResponseContext_->isIdenticalAccount = true;
469 authManager_->authResponseContext_->isOnline = true;
470 authManager_->authResponseContext_->reply = ERR_DM_AUTH_PEER_REJECT;
471 g_isDevicesInP2PGroupReturnBoolValue = false;
472 g_isIdenticalAccountReturnBoolValue = false;
473 int32_t ret = authManager_->CheckTrustState();
474 ASSERT_EQ(ret, DM_OK);
475 }
476
477 HWTEST_F(DmAuthManagerTest, CheckTrustState_005, testing::ext::TestSize.Level0)
478 {
479 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
480 authManager_->authResponseContext_->importAuthCode = "";
481 authManager_->authResponseContext_->isIdenticalAccount = true;
482 authManager_->authResponseContext_->isOnline = false;
483 authManager_->authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE;
484 g_isDevicesInP2PGroupReturnBoolValue = false;
485 g_isIdenticalAccountReturnBoolValue = false;
486 int32_t ret = authManager_->CheckTrustState();
487 ASSERT_EQ(ret, ERR_DM_BIND_PEER_UNSUPPORTED);
488 }
489
490 HWTEST_F(DmAuthManagerTest, CheckTrustState_006, testing::ext::TestSize.Level0)
491 {
492 authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
493 authManager_->authResponseContext_->importAuthCode = "";
494 authManager_->authResponseContext_->isAuthCodeReady = false;
495 authManager_->authResponseContext_->isIdenticalAccount = true;
496 authManager_->authResponseContext_->isOnline = false;
497 authManager_->authResponseContext_->reply = AUTH_TYPE_IMPORT_AUTH_CODE;
498 g_isDevicesInP2PGroupReturnBoolValue = false;
499 g_isIdenticalAccountReturnBoolValue = false;
500 int32_t ret = authManager_->CheckTrustState();
501 ASSERT_EQ(ret, ERR_DM_BIND_PEER_UNSUPPORTED);
502 }
503
504 HWTEST_F(DmAuthManagerTest, CheckTrustState_007, testing::ext::TestSize.Level0)
505 {
506 authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
507 authManager_->authResponseContext_->importAuthCode = "";
508 authManager_->authResponseContext_->isAuthCodeReady = false;
509 authManager_->authResponseContext_->isIdenticalAccount = true;
510 authManager_->authResponseContext_->isOnline = false;
511 authManager_->authResponseContext_->reply = AUTH_TYPE_IMPORT_AUTH_CODE;
512 g_isDevicesInP2PGroupReturnBoolValue = false;
513 g_isIdenticalAccountReturnBoolValue = false;
514 int32_t ret = authManager_->CheckTrustState();
515 ASSERT_EQ(ret, DM_OK);
516 }
517
518 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_001, testing::ext::TestSize.Level0)
519 {
520 std::string delaySecondsStr("123jlk");
521 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
522 ASSERT_EQ(ret, 0);
523 }
524
525 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_002, testing::ext::TestSize.Level0)
526 {
527 std::string delaySecondsStr("123");
528 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
529 ASSERT_EQ(ret, 0);
530 }
531
532 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_003, testing::ext::TestSize.Level0)
533 {
534 std::string delaySecondsStr("5");
535 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
536 ASSERT_EQ(ret, 5);
537 }
538
539 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_004, testing::ext::TestSize.Level0)
540 {
541 std::string delaySecondsStr("10");
542 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
543 ASSERT_EQ(ret, 10);
544 }
545
546 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_005, testing::ext::TestSize.Level0)
547 {
548 std::string delaySecondsStr("0");
549 int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
550 ASSERT_EQ(ret, 0);
551 }
552 } // namespace DistributedHardware
553 } // namespace OHOS
554