• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_first.h"
17 
18 #include "auth_message_processor.h"
19 #include "common_event_support.h"
20 #include "device_manager_service_listener.h"
21 #include "dm_auth_manager.h"
22 #include "dm_anonymous.h"
23 #include "dm_constants.h"
24 #include "dm_log.h"
25 #include "dm_radar_helper.h"
26 #include "json_object.h"
27 #include "softbus_error_code.h"
28 #include <memory>
29 
30 static bool g_reportAuthOpenSessionReturnBoolValue = false;
31 static bool g_reportAuthConfirmBoxReturnBoolValue = false;
32 
33 constexpr const char* DM_VERSION_4_1_5_1 = "4.1.5";
34 constexpr const char* DM_VERSION_5_0_1 = "5.0.1";
35 constexpr const char* DM_VERSION_5_0_2 = "5.0.2";
36 constexpr const char* AUTHENTICATE_TIMEOUT_TASK = "deviceManagerTimer:authenticate";
37 
38 using namespace testing;
39 using namespace testing::ext;
40 namespace OHOS {
41 namespace DistributedHardware {
42 
43 namespace {
44     const std::string PINCODE = "100001";
45     constexpr int32_t MIN_PIN_CODE_VALUE = 10;
46     constexpr int32_t MAX_PIN_CODE_VALUE = 9999999;
47     constexpr int32_t INVALID_AUTHBOX_TYPE = 100;
48 }
49 
ReportAuthOpenSession(struct RadarInfo & info)50 bool DmRadarHelper::ReportAuthOpenSession(struct RadarInfo &info)
51 {
52     return g_reportAuthOpenSessionReturnBoolValue;
53 }
54 
ReportAuthConfirmBox(struct RadarInfo & info)55 bool DmRadarHelper::ReportAuthConfirmBox(struct RadarInfo &info)
56 {
57     return g_reportAuthConfirmBoxReturnBoolValue;
58 }
59 
60 class SoftbusStateCallbackTest : public ISoftbusStateCallback {
61 public:
SoftbusStateCallbackTest()62     SoftbusStateCallbackTest() {}
~SoftbusStateCallbackTest()63     virtual ~SoftbusStateCallbackTest() {}
OnDeviceOnline(std::string deviceId,int32_t authForm)64     void OnDeviceOnline(std::string deviceId, int32_t authForm) {}
OnDeviceOffline(std::string deviceId)65     void OnDeviceOffline(std::string deviceId) {}
DeleteOffLineTimer(std::string udidHash)66     void DeleteOffLineTimer(std::string udidHash) {}
67 };
68 
SetUp()69 void DmAuthManagerTest::SetUp()
70 {
71     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
72     authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
73     authManager_->authMessageProcessor_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
74     authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
75     authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
76     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
77     authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
78     authManager_->hiChainAuthConnector_ = std::make_shared<HiChainAuthConnector>();
79     authManager_->softbusConnector_ = std::make_shared<SoftbusConnector>();
80     authManager_->softbusConnector_->GetSoftbusSession()->RegisterSessionCallback(
81         std::shared_ptr<ISoftbusSessionCallback>(authManager_));
82     authManager_->timer_ = std::make_shared<DmTimer>();
83 }
84 
TearDown()85 void DmAuthManagerTest::TearDown()
86 {
87     Mock::VerifyAndClearExpectations(softbusSessionMock_.get());
88 }
89 
SetUpTestCase()90 void DmAuthManagerTest::SetUpTestCase()
91 {
92     softbusSessionMock_ = std::make_shared<SoftbusSessionMock>();
93     DmSoftbusSession::dmSoftbusSession = softbusSessionMock_;
94     appManagerMock_ = std::make_shared<AppManagerMock>();
95     DmAppManager::dmAppManager = appManagerMock_;
96     cryptoMock_ = std::make_shared<CryptoMock>();
97     DmCrypto::dmCrypto = cryptoMock_;
98     deviceProfileConnectorMock_ = std::make_shared<DeviceProfileConnectorMock>();
99     DmDeviceProfileConnector::dmDeviceProfileConnector = deviceProfileConnectorMock_;
100     hiChainAuthConnectorMock_ = std::make_shared<HiChainAuthConnectorMock>();
101     DmHiChainAuthConnector::dmHiChainAuthConnector = hiChainAuthConnectorMock_;
102     multipleUserConnectorMock_ = std::make_shared<MultipleUserConnectorMock>();
103     DmMultipleUserConnector::dmMultipleUserConnector = multipleUserConnectorMock_;
104     cryptoMgrMock_ = std::make_shared<CryptoMgrMock>();
105     DmCryptoMgr::dmCryptoMgr = cryptoMgrMock_;
106 }
107 
TearDownTestCase()108 void DmAuthManagerTest::TearDownTestCase()
109 {
110     DmSoftbusSession::dmSoftbusSession = nullptr;
111     softbusSessionMock_ = nullptr;
112     DmAppManager::dmAppManager = nullptr;
113     appManagerMock_ = nullptr;
114     DmCrypto::dmCrypto = nullptr;
115     cryptoMock_ = nullptr;
116     DmDeviceProfileConnector::dmDeviceProfileConnector = nullptr;
117     deviceProfileConnectorMock_ = nullptr;
118     DmHiChainAuthConnector::dmHiChainAuthConnector = nullptr;
119     hiChainAuthConnectorMock_ = nullptr;
120     DmMultipleUserConnector::dmMultipleUserConnector = nullptr;
121     multipleUserConnectorMock_ = nullptr;
122     DmCryptoMgr::dmCryptoMgr = nullptr;
123     cryptoMgrMock_ = nullptr;
124 }
125 
126 namespace {
127 const std::string MIN_PIN_CODE = "100000";
128 const std::string MAX_PIN_CODE = "999999";
129 
130 HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_001, testing::ext::TestSize.Level1)
131 {
132     std::string name = "test";
133     std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestNetworkState>();
134     authManager_->authRequestState_ = std::make_shared<AuthRequestNetworkState>();
135     authManager_->authResponseContext_ = nullptr;
136     authManager_->SetAuthRequestState(authRequestState);
137     authManager_->HandleAuthenticateTimeout(name);
138     ASSERT_TRUE(authManager_->authResponseContext_ != nullptr);
139 }
140 
141 HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_002, testing::ext::TestSize.Level1)
142 {
143     std::string name = "test";
144     std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>();
145     authManager_->SetAuthRequestState(authRequestState);
146     authManager_->HandleAuthenticateTimeout(name);
147     ASSERT_TRUE(authManager_->authRequestState_ != nullptr);
148 }
149 
150 HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_003, testing::ext::TestSize.Level1)
151 {
152     std::string name = "test";
153     std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>();
154     authManager_->SetAuthRequestState(authRequestState);
155     authManager_->HandleAuthenticateTimeout(name);
156     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseFinishState>();
157     authManager_->SetAuthResponseState(authResponseState);
158     ASSERT_TRUE(authManager_->authRequestState_ != nullptr);
159 }
160 
161 HWTEST_F(DmAuthManagerTest, HandleAuthenticateTimeout_004, testing::ext::TestSize.Level1)
162 {
163     std::string name = "test";
164     authManager_->authRequestContext_->reason = DM_OK;
165     std::shared_ptr<AuthRequestInitStateMock> requestInitState = std::make_shared<AuthRequestInitStateMock>();
166     EXPECT_CALL(*requestInitState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_NEGOTIATE));
167     authManager_->authRequestState_ = requestInitState;
168     authManager_->HandleAuthenticateTimeout(name);
169     EXPECT_EQ(authManager_->authRequestContext_->reason, ERR_DM_TIME_OUT);
170 
171     std::shared_ptr<AuthResponseInitStateMock> authResponseInitState = std::make_shared<AuthResponseInitStateMock>();
172     EXPECT_CALL(*authResponseInitState, GetStateType())
173         .WillRepeatedly(testing::Return(AuthState::AUTH_RESPONSE_FINISH));
174     authManager_->authResponseState_ = authResponseInitState;
175     authManager_->HandleAuthenticateTimeout(name);
176     EXPECT_EQ(authManager_->authRequestContext_->reason, ERR_DM_TIME_OUT);
177 
178     authManager_->authResponseState_ = nullptr;
179     authManager_->HandleAuthenticateTimeout(name);
180     EXPECT_EQ(authManager_->authRequestContext_->reason, ERR_DM_TIME_OUT);
181 }
182 
183 HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_001, testing::ext::TestSize.Level1)
184 {
185     std::string deviceId1;
186     authManager_->AbilityNegotiate();
187     g_reportAuthOpenSessionReturnBoolValue = false;
188     int32_t ret = authManager_->EstablishAuthChannel(deviceId1);
189     ASSERT_EQ(ret, DM_OK);
190 }
191 
192 HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_002, testing::ext::TestSize.Level1)
193 {
194     std::string deviceId;
195     authManager_->authResponseContext_ = nullptr;
196     authManager_->authRequestContext_ = nullptr;
197     authManager_->authRequestState_ = nullptr;
198     g_reportAuthOpenSessionReturnBoolValue = true;
199     int32_t ret = authManager_->EstablishAuthChannel(deviceId);
200     g_reportAuthOpenSessionReturnBoolValue = false;
201     ASSERT_EQ(ret, DM_OK);
202 }
203 
204 HWTEST_F(DmAuthManagerTest, StartAuthProcess_001, testing::ext::TestSize.Level1)
205 {
206     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseConfirmState>();
207     authManager_->SetAuthResponseState(authResponseState);
208     int32_t action = 0;
209     g_reportAuthConfirmBoxReturnBoolValue = false;
210     authManager_->remoteVersion_ = "4.1.5.2";
211     authManager_->authResponseContext_->bindLevel = USER;
212     int32_t ret = authManager_->StartAuthProcess(action);
213     ASSERT_EQ(ret, DM_OK);
214 }
215 
216 HWTEST_F(DmAuthManagerTest, StartAuthProcess_002, testing::ext::TestSize.Level1)
217 {
218     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseConfirmState>();
219     authManager_->SetAuthResponseState(authResponseState);
220     int32_t action = 0;
221     g_reportAuthConfirmBoxReturnBoolValue = true;
222     authManager_->remoteVersion_ = "4.1.5.2";
223     authManager_->authResponseContext_->bindLevel = APP + 1;
224     int32_t ret = authManager_->StartAuthProcess(action);
225     g_reportAuthConfirmBoxReturnBoolValue = false;
226     ASSERT_EQ(ret, DM_OK);
227 }
228 
229 HWTEST_F(DmAuthManagerTest, StartAuthProcess_003, testing::ext::TestSize.Level1)
230 {
231     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseConfirmState>();
232     authManager_->SetAuthResponseState(authResponseState);
233     int32_t action = 0;
234     authManager_->remoteVersion_ = "4.1.5.2";
235     authManager_->authResponseContext_->bindLevel = INVALIED_TYPE;
236     int32_t ret = authManager_->StartAuthProcess(action);
237     ASSERT_EQ(ret, DM_OK);
238 }
239 
240 HWTEST_F(DmAuthManagerTest, StartAuthProcess_004, testing::ext::TestSize.Level1)
241 {
242     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseConfirmState>();
243     authManager_->SetAuthResponseState(authResponseState);
244     int32_t action = 0;
245     authManager_->remoteVersion_ = "4.1.5.0";
246     int32_t ret = authManager_->StartAuthProcess(action);
247     ASSERT_EQ(ret, DM_OK);
248 }
249 
250 HWTEST_F(DmAuthManagerTest, StartAuthProcess_005, testing::ext::TestSize.Level1)
251 {
252     authManager_->authResponseContext_ = nullptr;
253     int32_t action = 1;
254     int32_t ret = authManager_->StartAuthProcess(action);
255     ASSERT_EQ(ret, ERR_DM_AUTH_NOT_START);
256 }
257 
258 HWTEST_F(DmAuthManagerTest, CreateGroup_001, testing::ext::TestSize.Level1)
259 {
260     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseConfirmState>();
261     std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
262     authManager_->SetAuthResponseState(authResponseState);
263     authManager_->authResponseContext_->requestId = 111;
264     authManager_->authResponseContext_->groupName = "111";
265     int32_t ret = authManager_->CreateGroup();
266     ASSERT_EQ(ret, DM_OK);
267 }
268 
269 HWTEST_F(DmAuthManagerTest, CreateGroup_002, testing::ext::TestSize.Level1)
270 {
271     authManager_->authResponseContext_ = nullptr;
272     int32_t ret = authManager_->CreateGroup();
273     ASSERT_EQ(ret, ERR_DM_FAILED);
274 }
275 
276 HWTEST_F(DmAuthManagerTest, AddMember_001, testing::ext::TestSize.Level1)
277 {
278     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseInitState>();
279     std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
280     JsonObject jsonObject;
281     authManager_->authResponseContext_->groupId = "111";
282     authManager_->authResponseContext_->groupName = "222";
283     authManager_->authResponseContext_->code = 123;
284     authManager_->authResponseContext_->requestId = 234;
285     authManager_->authResponseContext_->deviceId = "234";
286     std::string pinCode = "444444";
287     authManager_->hiChainConnector_->RegisterHiChainCallback(authManager_);
288     authManager_->SetAuthResponseState(authResponseState);
289     int32_t ret = authManager_->AddMember(pinCode);
290     ASSERT_NE(ret, -1);
291 }
292 
293 HWTEST_F(DmAuthManagerTest, AddMember_002, testing::ext::TestSize.Level1)
294 {
295     std::string pinCode = "33333";
296     authManager_->authResponseContext_ = nullptr;
297     int32_t ret = authManager_->AddMember(pinCode);
298     ASSERT_EQ(ret, ERR_DM_FAILED);
299     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
300     std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
301     authManager_->authUiStateMgr_ = std::make_shared<AuthUiStateManager>(listener);
302     authManager_->isAddingMember_ = true;
303     ret = authManager_->AddMember(pinCode);
304     ASSERT_EQ(ret, ERR_DM_FAILED);
305 }
306 
307 HWTEST_F(DmAuthManagerTest, JoinNetwork_001, testing::ext::TestSize.Level1)
308 {
309     std::shared_ptr<AuthRequestState> authRequestState = std::make_shared<AuthRequestFinishState>();
310     const int32_t sessionId = 65;
311     const std::string message = "messageTest";
312     int64_t requestId = 444;
313     const std::string groupId = "{}";
314     int32_t status = 1;
315     authManager_->OnGroupCreated(requestId, groupId);
316     authManager_->OnMemberJoin(requestId, status, 0);
317     authManager_->OnDataReceived(sessionId, message);
318     authManager_->SetAuthRequestState(authRequestState);
319     int32_t ret = authManager_->JoinNetwork();
320     ASSERT_EQ(ret, DM_OK);
321 }
322 
323 HWTEST_F(DmAuthManagerTest, JoinNetwork_002, testing::ext::TestSize.Level1)
324 {
325     authManager_->authResponseContext_ = nullptr;
326     authManager_->AuthenticateFinish();
327     int32_t ret = authManager_->JoinNetwork();
328     ASSERT_EQ(ret, ERR_DM_FAILED);
329 }
330 
331 HWTEST_F(DmAuthManagerTest, SetAuthResponseState_001, testing::ext::TestSize.Level1)
332 {
333     std::shared_ptr<AuthResponseState> authResponseState = std::make_shared<AuthResponseFinishState>();
334     authManager_->authResponseState_ = std::make_shared<AuthResponseFinishState>();
335     int32_t ret = authManager_->SetAuthResponseState(authResponseState);
336     ASSERT_EQ(ret, DM_OK);
337 }
338 
339 HWTEST_F(DmAuthManagerTest, SetAuthResponseState_002, testing::ext::TestSize.Level1)
340 {
341     std::shared_ptr<AuthResponseState> authResponseState = nullptr;
342     int32_t ret = authManager_->SetAuthResponseState(authResponseState);
343     ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
344 }
345 
346 HWTEST_F(DmAuthManagerTest, GetPinCode_001, testing::ext::TestSize.Level1)
347 {
348     authManager_->authResponseContext_->code = "123456";
349     std::string code = "0";
350     authManager_->GetPinCode(code);
351     ASSERT_EQ(code, "123456");
352 }
353 
354 HWTEST_F(DmAuthManagerTest, GetPinCode_002, testing::ext::TestSize.Level1)
355 {
356     authManager_->authResponseContext_ = nullptr;
357     authManager_->ShowConfigDialog();
358     authManager_->ShowAuthInfoDialog();
359     authManager_->ShowStartAuthDialog();
360     std::string code = "0";
361     int32_t ret = authManager_->GetPinCode(code);
362     ASSERT_NE(ret, ERR_DM_TIME_OUT);
363 }
364 
365 HWTEST_F(DmAuthManagerTest, SetPageId_001, testing::ext::TestSize.Level1)
366 {
367     int32_t pageId = 123;
368     int32_t ret = authManager_->SetPageId(pageId);
369     ASSERT_EQ(ret, DM_OK);
370 }
371 
372 HWTEST_F(DmAuthManagerTest, SetPageId_002, testing::ext::TestSize.Level1)
373 {
374     int32_t pageId = 123;
375     authManager_->authResponseContext_ = nullptr;
376     authManager_->authMessageProcessor_ = nullptr;
377     const int32_t sessionId = 65;
378     std::string message = "messageTest";
379     int64_t requestId = 555;
380     int32_t status = 2;
381     JsonObject jsonObject;
382     jsonObject[TAG_MSG_TYPE] = MSG_TYPE_AUTH_BY_PIN;
383     authManager_->OnMemberJoin(requestId, status, 0);
384     authManager_->OnDataReceived(sessionId, message);
385     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
386     authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
387     authManager_->authResponseContext_->sessionId = sessionId;
388     message = jsonObject.Dump();
389     authManager_->authResponseState_ = nullptr;
390     authManager_->OnDataReceived(sessionId, message);
391     authManager_->authRequestState_ = nullptr;
392     authManager_->authResponseState_ = std::make_shared<AuthResponseFinishState>();
393     authManager_->OnDataReceived(sessionId, message);
394     int32_t ret = authManager_->SetPageId(pageId);
395     ASSERT_EQ(ret, DM_OK);
396 }
397 
398 HWTEST_F(DmAuthManagerTest, SetPageId_003, testing::ext::TestSize.Level1)
399 {
400     int32_t pageId = 123;
401     authManager_->authResponseContext_ = nullptr;
402     int32_t ret = authManager_->SetPageId(pageId);
403     ASSERT_NE(ret, DM_OK);
404 }
405 
406 HWTEST_F(DmAuthManagerTest, SetReasonAndFinish_001, testing::ext::TestSize.Level1)
407 {
408     const int32_t sessionId = 78;
409     int32_t reason = 123;
410     int32_t state = 456;
411     authManager_->OnSessionClosed(sessionId);
412     authManager_->authResponseContext_ = nullptr;
413     int64_t requestId = 333;
414     const std::string groupId = "{}";
415     authManager_->OnGroupCreated(requestId, groupId);
416     int32_t ret = authManager_->SetReasonAndFinish(reason, state);
417     ASSERT_EQ(ret, ERR_DM_AUTH_NOT_START);
418 }
419 
420 HWTEST_F(DmAuthManagerTest, SetReasonAndFinish_002, testing::ext::TestSize.Level1)
421 {
422     int32_t reason = 1234;
423     int32_t state = 5678;
424     int64_t requestId = 22;
425     const std::string groupId = "{}";
426     authManager_->OnGroupCreated(requestId, groupId);
427     int32_t ret = authManager_->SetReasonAndFinish(reason, state);
428     ASSERT_EQ(ret, DM_OK);
429 }
430 
431 HWTEST_F(DmAuthManagerTest, SetReasonAndFinish_003, testing::ext::TestSize.Level1)
432 {
433     authManager_->authRequestState_ = nullptr;
434     authManager_->authResponseState_ = std::make_shared<AuthResponseFinishState>();
435     int32_t reason = 12;
436     int32_t state = 36;
437     int32_t ret = authManager_->SetReasonAndFinish(reason, state);
438     ASSERT_EQ(ret, DM_OK);
439 }
440 
441 HWTEST_F(DmAuthManagerTest, IsIdenticalAccount_001, testing::ext::TestSize.Level1)
442 {
443     bool ret = authManager_->IsIdenticalAccount();
444     ASSERT_EQ(ret, false);
445 }
446 
447 HWTEST_F(DmAuthManagerTest, GetAccountGroupIdHash_001, testing::ext::TestSize.Level1)
448 {
449     auto ret = authManager_->GetAccountGroupIdHash();
450     ASSERT_EQ(ret.empty(), true);
451 }
452 
453 HWTEST_F(DmAuthManagerTest, GeneratePincode_001, testing::ext::TestSize.Level1)
454 {
455     int32_t openedSessionId = 66;
456     int32_t sessionSide = 0;
457     int32_t result = 3;
458     const int32_t closedSessionId = 11;
459     authManager_->authResponseState_ = nullptr;
460     authManager_->authRequestState_ = nullptr;
461     authManager_->timer_ = nullptr;
462     authManager_->OnSessionOpened(openedSessionId, sessionSide, result);
463     authManager_->OnSessionClosed(closedSessionId);
464     std::string ret = authManager_->GeneratePincode();
465     ASSERT_LE(ret, MAX_PIN_CODE);
466     ASSERT_GE(ret, MIN_PIN_CODE);
467 }
468 
469 HWTEST_F(DmAuthManagerTest, GeneratePincode_002, testing::ext::TestSize.Level1)
470 {
471     int32_t openedSessionId = 66;
472     int32_t sessionSide = 0;
473     int32_t result = 3;
474     const int32_t closedSessionId = 11;
475     authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
476     authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
477     authManager_->timer_ = std::make_shared<DmTimer>();
478     authManager_->OnSessionOpened(openedSessionId, sessionSide, result);
479     authManager_->OnSessionClosed(closedSessionId);
480     std::string ret = authManager_->GeneratePincode();
481     ASSERT_LE(ret, MAX_PIN_CODE);
482     ASSERT_GE(ret, MIN_PIN_CODE);
483 }
484 
485 HWTEST_F(DmAuthManagerTest, GeneratePincode_003, testing::ext::TestSize.Level1)
486 {
487     int32_t openedSessionId = 66;
488     int32_t sessionSide = 1;
489     int32_t result = 3;
490     const int32_t closedSessionId = 11;
491     authManager_->authResponseState_ = nullptr;
492     authManager_->authRequestState_ = nullptr;
493     authManager_->timer_ = nullptr;
494     authManager_->OnSessionOpened(openedSessionId, sessionSide, result);
495     authManager_->OnSessionClosed(closedSessionId);
496     std::string ret = authManager_->GeneratePincode();
497     ASSERT_LE(ret, MAX_PIN_CODE);
498     ASSERT_GE(ret, MIN_PIN_CODE);
499 }
500 
501 HWTEST_F(DmAuthManagerTest, GeneratePincode_004, testing::ext::TestSize.Level1)
502 {
503     int32_t openedSessionId = 66;
504     int32_t sessionSide = 1;
505     int32_t result = 3;
506     const int32_t closedSessionId = 11;
507     authManager_->authResponseState_ = nullptr;
508     authManager_->authRequestState_ = std::make_shared<AuthRequestInitState>();
509     authManager_->timer_ = std::make_shared<DmTimer>();
510     authManager_->OnSessionOpened(openedSessionId, sessionSide, result);
511     authManager_->OnSessionClosed(closedSessionId);
512     std::string ret = authManager_->GeneratePincode();
513     ASSERT_LE(ret, MAX_PIN_CODE);
514     ASSERT_GE(ret, MIN_PIN_CODE);
515 }
516 
517 HWTEST_F(DmAuthManagerTest, AuthenticateDevice_001, testing::ext::TestSize.Level1)
518 {
519     std::string pkgName = "com.ohos.test";
520     int32_t authType = -1;
521     std::string deviceId = "113456";
522     std::string extra = "extraTest";
523     int32_t ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
524     ASSERT_EQ(ret, ERR_DM_AUTH_FAILED);
525 
526     authType = 0;
527     JsonObject jsonObject;
528     jsonObject["bindLevel"] = 5;
529     extra = jsonObject.Dump();
530     ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
531     ASSERT_EQ(ret, ERR_DM_AUTH_BUSINESS_BUSY);
532 }
533 
534 HWTEST_F(DmAuthManagerTest, AuthenticateDevice_002, testing::ext::TestSize.Level1)
535 {
536     int32_t authType = 0;
537     std::string extra;
538     std::string pkgName = "ohos_test";
539     std::string deviceId = "512156";
540     authManager_->importPkgName_ = "ohos_test";
541     authManager_->importAuthCode_ = "156161";
542     authManager_->authRequestState_ = nullptr;
543     authManager_->authResponseState_ = nullptr;
544     std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
545     authManager_->authUiStateMgr_ = std::make_shared<AuthUiStateManager>(listener);
546     authManager_->authenticationMap_.insert(std::pair<int32_t, std::shared_ptr<IAuthentication>>(authType, nullptr));
547     std::shared_ptr<DeviceInfo> infoPtr = std::make_shared<DeviceInfo>();
548     authManager_->softbusConnector_->discoveryDeviceInfoMap_.emplace(deviceId, infoPtr);
549     int32_t ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
550     ASSERT_EQ(ret, DM_OK);
551 }
552 
553 HWTEST_F(DmAuthManagerTest, AuthenticateDevice_003, testing::ext::TestSize.Level1)
554 {
555     std::string pkgName = "com.ohos.test";
556     int32_t authType = 1;
557     std::string deviceId = "deviceIdTest";
558     std::string extra = "extraTest";
559     std::shared_ptr<DeviceInfo> infoPtr = std::make_shared<DeviceInfo>();
560     authManager_->authRequestState_ = nullptr;
561     authManager_->authResponseState_ = nullptr;
562     authManager_->timer_ = nullptr;
563     authManager_->softbusConnector_->discoveryDeviceInfoMap_.emplace(deviceId, infoPtr);
564     int32_t ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
565     ASSERT_EQ(ret, DM_OK);
566 }
567 
568 HWTEST_F(DmAuthManagerTest, UnAuthenticateDevice_001, testing::ext::TestSize.Level1)
569 {
570     std::string pkgName;
571     std::string udid = "UnAuthenticateDevice_001";
572     int32_t bindLevel = USER;
573     int32_t ret = authManager_->UnAuthenticateDevice(pkgName, udid, bindLevel);
574     EXPECT_NE(ret, DM_OK);
575 
576     pkgName = "com.ohos.test";
577     authManager_->isAuthenticateDevice_ = false;
578     ret = authManager_->UnAuthenticateDevice(pkgName, udid, bindLevel);
579     EXPECT_NE(ret, DM_OK);
580 
581     authManager_->authRequestState_ = nullptr;
582     authManager_->authResponseContext_ = nullptr;
583     ret = authManager_->UnAuthenticateDevice(pkgName, udid, bindLevel);
584     EXPECT_NE(ret, DM_OK);
585 
586     bindLevel = 0;
587     ret = authManager_->UnAuthenticateDevice(pkgName, udid, bindLevel);
588     EXPECT_NE(ret, DM_OK);
589 }
590 
591 HWTEST_F(DmAuthManagerTest, GenerateGroupName_001, testing::ext::TestSize.Level1)
592 {
593     authManager_->authResponseContext_ = nullptr;
594     std::string ret = authManager_->GenerateGroupName();
595     ASSERT_TRUE(ret.empty());
596 }
597 
598 HWTEST_F(DmAuthManagerTest, UnBindDevice_002, testing::ext::TestSize.Level1)
599 {
600     std::string pkgName;
601     std::string udid = "UnBindDevice_002";
602     int32_t bindLevel = USER;
603     std::string extra = "extraTest";
604     int32_t ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra);
605     EXPECT_NE(ret, DM_OK);
606 
607     pkgName = "com.ohos.test";
608     authManager_->isAuthenticateDevice_ = false;
609     ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra);
610     EXPECT_NE(ret, DM_OK);
611 
612     authManager_->authRequestState_ = nullptr;
613     authManager_->authResponseContext_ = nullptr;
614     ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra);
615     EXPECT_NE(ret, DM_OK);
616 
617     bindLevel = 0;
618     ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra);
619     EXPECT_NE(ret, DM_OK);
620 }
621 
622 HWTEST_F(DmAuthManagerTest, GenerateGroupName_002, testing::ext::TestSize.Level1)
623 {
624     authManager_->authResponseContext_->targetPkgName = "targetPkgNameTest";
625     authManager_->authResponseContext_->localDeviceId = "localDeviceIdTest";
626     authManager_->action_ = 6;
627     std::string ret = authManager_->GenerateGroupName();
628     ASSERT_TRUE(!ret.empty());
629 }
630 
631 HWTEST_F(DmAuthManagerTest, GenerateGroupName_003, testing::ext::TestSize.Level1)
632 {
633     authManager_->authResponseContext_->targetPkgName = "targetPkgNameTest";
634     authManager_->authResponseContext_->localDeviceId = "localDeviceIdTest";
635     authManager_->action_ = 7;
636     std::string ret = authManager_->GenerateGroupName();
637     ASSERT_TRUE(!ret.empty());
638 }
639 
640 HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_001, testing::ext::TestSize.Level1)
641 {
642     authManager_->authResponseState_ = nullptr;
643     bool ret = authManager_->GetIsCryptoSupport();
644     ASSERT_EQ(ret, false);
645 }
646 
647 HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_002, testing::ext::TestSize.Level1)
648 {
649     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
650     authManager_->authRequestState_ = nullptr;
651     bool ret = authManager_->GetIsCryptoSupport();
652     ASSERT_EQ(ret, false);
653 }
654 
655 HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_003, testing::ext::TestSize.Level1)
656 {
657     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
658     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
659     bool ret = authManager_->GetIsCryptoSupport();
660     ASSERT_EQ(ret, false);
661 }
662 
663 HWTEST_F(DmAuthManagerTest, GetIsCryptoSupport_004, testing::ext::TestSize.Level1)
664 {
665     authManager_->isCryptoSupport_ = true;
666     authManager_->authRequestState_ = nullptr;
667     std::shared_ptr<AuthResponseInitStateMock> authResponseInitState = std::make_shared<AuthResponseInitStateMock>();
668     EXPECT_CALL(*authResponseInitState, GetStateType())
669         .WillRepeatedly(testing::Return(AuthState::AUTH_RESPONSE_FINISH));
670     authManager_->authResponseState_ = authResponseInitState;
671     bool ret = authManager_->GetIsCryptoSupport();
672     ASSERT_TRUE(ret);
673 
674     EXPECT_CALL(*authResponseInitState, GetStateType())
675         .WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_NEGOTIATE_DONE));
676     ret = authManager_->GetIsCryptoSupport();
677     ASSERT_FALSE(ret);
678 
679     std::shared_ptr<AuthRequestFinishStateMock> requestFinishState = std::make_shared<AuthRequestFinishStateMock>();
680     EXPECT_CALL(*requestFinishState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_NEGOTIATE));
681     authManager_->authRequestState_ = requestFinishState;
682     ret = authManager_->GetIsCryptoSupport();
683     ASSERT_FALSE(ret);
684 
685     EXPECT_CALL(*requestFinishState, GetStateType())
686         .WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_NEGOTIATE_DONE));
687     ret = authManager_->GetIsCryptoSupport();
688     ASSERT_FALSE(ret);
689 
690     EXPECT_CALL(*requestFinishState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_INIT));
691     ret = authManager_->GetIsCryptoSupport();
692     ASSERT_TRUE(ret);
693 }
694 
695 HWTEST_F(DmAuthManagerTest, OnUserOperation_001, testing::ext::TestSize.Level1)
696 {
697     int32_t action = 0;
698     std::string params = "paramsTest";
699     authManager_->authResponseContext_ = nullptr;
700     int32_t ret = authManager_->OnUserOperation(action, params);
701     ASSERT_EQ(ret, ERR_DM_AUTH_NOT_START);
702 }
703 
704 HWTEST_F(DmAuthManagerTest, OnUserOperation_002, testing::ext::TestSize.Level1)
705 {
706     int32_t action = 1;
707     std::string params = "paramsTest1";
708     int32_t ret = authManager_->OnUserOperation(action, params);
709     ASSERT_EQ(ret, DM_OK);
710 }
711 
712 HWTEST_F(DmAuthManagerTest, OnUserOperation_003, testing::ext::TestSize.Level1)
713 {
714     int32_t action = 2;
715     std::string params = "paramsTest2";
716     int32_t ret = authManager_->OnUserOperation(action, params);
717     ASSERT_EQ(ret, DM_OK);
718 }
719 
720 HWTEST_F(DmAuthManagerTest, OnUserOperation_004, testing::ext::TestSize.Level1)
721 {
722     int32_t action = 3;
723     std::string params = "paramsTest3";
724     int32_t ret = authManager_->OnUserOperation(action, params);
725     ASSERT_EQ(ret, DM_OK);
726 }
727 
728 HWTEST_F(DmAuthManagerTest, OnUserOperation_005, testing::ext::TestSize.Level1)
729 {
730     int32_t action = 4;
731     std::string params = "paramsTest4";
732     int32_t ret = authManager_->OnUserOperation(action, params);
733     ASSERT_EQ(ret, DM_OK);
734 }
735 
736 HWTEST_F(DmAuthManagerTest, OnUserOperation_006, testing::ext::TestSize.Level1)
737 {
738     int32_t action = 5;
739     std::string params = "5";
740     int32_t ret = authManager_->OnUserOperation(action, params);
741     ASSERT_EQ(ret, DM_OK);
742 }
743 
744 HWTEST_F(DmAuthManagerTest, OnUserOperation_007, testing::ext::TestSize.Level1)
745 {
746     int32_t action = 1111;
747     std::string params = "paramsTest1111";
748     int32_t ret = authManager_->OnUserOperation(action, params);
749     ASSERT_EQ(ret, DM_OK);
750 }
751 
752 HWTEST_F(DmAuthManagerTest, RequestCredential001, testing::ext::TestSize.Level1)
753 {
754     authManager_->hiChainAuthConnector_ = std::make_shared<HiChainAuthConnector>();
755     authManager_->RequestCredential();
756     ASSERT_EQ(authManager_->isAuthDevice_, false);
757 }
758 
759 HWTEST_F(DmAuthManagerTest, GenerateCredential001, testing::ext::TestSize.Level1)
760 {
761     std::string publicKey = "publicKey";
762     authManager_->GenerateCredential(publicKey);
763     ASSERT_EQ(authManager_->isAuthDevice_, false);
764 }
765 
766 HWTEST_F(DmAuthManagerTest, RequestCredentialDone001, testing::ext::TestSize.Level1)
767 {
768     authManager_->authResponseContext_ = nullptr;
769     authManager_->RequestCredentialDone();
770     ASSERT_EQ(authManager_->isAuthDevice_, false);
771 }
772 
773 HWTEST_F(DmAuthManagerTest, RequestCredentialDone002, testing::ext::TestSize.Level1)
774 {
775     authManager_->hiChainAuthConnector_ = std::make_shared<HiChainAuthConnector>();
776     authManager_->RequestCredential();
777     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
778     authManager_->RequestCredentialDone();
779     ASSERT_EQ(authManager_->isAuthDevice_, false);
780 }
781 
782 HWTEST_F(DmAuthManagerTest, ImportCredential001, testing::ext::TestSize.Level1)
783 {
784     std::string deviceId = "deviceId";
785     std::string publicKey = "publicKey";
786     EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED));
787     int32_t ret = authManager_->ImportCredential(deviceId, publicKey);
788     ASSERT_NE(ret, ERR_DM_FAILED);
789 }
790 
791 HWTEST_F(DmAuthManagerTest, ResponseCredential001, testing::ext::TestSize.Level1)
792 {
793     authManager_->ResponseCredential();
794     ASSERT_EQ(authManager_->isAuthDevice_, false);
795 
796     authManager_->authResponseContext_->publicKey = "publicKey";
797     EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED));
798     authManager_->ResponseCredential();
799     ASSERT_EQ(authManager_->isAuthDevice_, false);
800 
801     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
802     authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
803     EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(DM_OK));
804     authManager_->ResponseCredential();
805     ASSERT_EQ(authManager_->isAuthDevice_, false);
806 }
807 
808 HWTEST_F(DmAuthManagerTest, AuthDeviceTransmit001, testing::ext::TestSize.Level1)
809 {
810     int64_t requestId = 0;
811     authManager_->authResponseContext_->requestId = 11;
812     uint8_t *data = nullptr;
813     uint32_t dataLen = 0;
814     bool ret = authManager_->AuthDeviceTransmit(requestId, data, dataLen);
815     ASSERT_EQ(ret, false);
816 }
817 
818 HWTEST_F(DmAuthManagerTest, AuthDeviceTransmit002, testing::ext::TestSize.Level1)
819 {
820     int64_t requestId = 0;
821     authManager_->authResponseContext_->requestId = 0;
822     authManager_->authResponseState_ = nullptr;
823     uint8_t *data = nullptr;
824     uint32_t dataLen = 0;
825     EXPECT_CALL(*softbusSessionMock_, SendData(_, _)).WillOnce(Return(ERR_DM_FAILED));
826     bool ret = authManager_->AuthDeviceTransmit(requestId, data, dataLen);
827     ASSERT_EQ(ret, false);
828 }
829 
830 HWTEST_F(DmAuthManagerTest, AuthDeviceTransmit003, testing::ext::TestSize.Level1)
831 {
832     int64_t requestId = 0;
833     authManager_->authResponseContext_->requestId = 0;
834     authManager_->authRequestState_ = nullptr;
835     uint8_t *data = nullptr;
836     uint32_t dataLen = 0;
837     EXPECT_CALL(*softbusSessionMock_, SendData(_, _)).WillOnce(Return(ERR_DM_FAILED));
838     bool ret = authManager_->AuthDeviceTransmit(requestId, data, dataLen);
839     ASSERT_EQ(ret, false);
840 }
841 
842 HWTEST_F(DmAuthManagerTest, AuthDeviceTransmit004, testing::ext::TestSize.Level1)
843 {
844     int64_t requestId = 0;
845     uint8_t *data = nullptr;
846     uint32_t dataLen = 0;
847     EXPECT_CALL(*softbusSessionMock_, SendData(_, _)).WillOnce(Return(ERR_DM_FAILED));
848     bool ret = authManager_->AuthDeviceTransmit(requestId, data, dataLen);
849     ASSERT_EQ(ret, false);
850 }
851 
852 HWTEST_F(DmAuthManagerTest, SrcAuthDeviceFinish001, testing::ext::TestSize.Level1)
853 {
854     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
855     authManager_->authResponseContext_->isOnline = true;
856     authManager_->authResponseContext_->confirmOperation = USER_OPERATION_TYPE_ALLOW_AUTH;
857     authManager_->authResponseContext_->haveCredential = true;
858     authManager_->authResponseContext_->bindLevel = APP;
859     authManager_->authResponseContext_->isIdenticalAccount = false;
860     authManager_->authResponseContext_->hostPkgName = "hostPkgName";
861     authManager_->softbusConnector_->deviceStateManagerCallback_ = std::make_shared<SoftbusStateCallbackTest>();
862     authManager_->SrcAuthDeviceFinish();
863     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
864 
865     authManager_->authResponseContext_->confirmOperation = USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS;
866     authManager_->authResponseContext_->hostPkgName = "";
867     authManager_->SrcAuthDeviceFinish();
868     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
869 
870     authManager_->authResponseContext_->isIdenticalAccount = true;
871     authManager_->SrcAuthDeviceFinish();
872     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
873 
874     authManager_->authResponseContext_->bindLevel = SERVICE;
875     authManager_->SrcAuthDeviceFinish();
876     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
877 
878     authManager_->authResponseContext_->haveCredential = false;
879     authManager_->authResponseContext_->bindLevel = APP;
880     authManager_->authResponseContext_->isIdenticalAccount = false;
881     authManager_->authResponseContext_->hostPkgName = "hostPkgName";
882     authManager_->SrcAuthDeviceFinish();
883     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
884 
885     authManager_->authResponseContext_->hostPkgName = "";
886     authManager_->SrcAuthDeviceFinish();
887     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
888 
889     authManager_->authResponseContext_->bindLevel = SERVICE;
890     authManager_->authResponseContext_->isIdenticalAccount = true;
891     authManager_->SrcAuthDeviceFinish();
892     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
893 
894     authManager_->authResponseContext_->confirmOperation = USER_OPERATION_TYPE_DONE_PINCODE_INPUT;
895     authManager_->SrcAuthDeviceFinish();
896     EXPECT_TRUE(authManager_->softbusConnector_->processInfoVec_.size() > 0);
897 }
898 
899 HWTEST_F(DmAuthManagerTest, SrcAuthDeviceFinish002, testing::ext::TestSize.Level1)
900 {
901     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
902     authManager_->authResponseContext_->isOnline = false;
903     authManager_->authResponseContext_->confirmOperation = USER_OPERATION_TYPE_ALLOW_AUTH;
904     authManager_->authResponseContext_->haveCredential = true;
905     authManager_->authResponseContext_->bindLevel = APP;
906     authManager_->authResponseContext_->isIdenticalAccount = false;
907     authManager_->authResponseContext_->hostPkgName = "hostPkgName";
908     authManager_->softbusConnector_->deviceStateManagerCallback_ = std::make_shared<SoftbusStateCallbackTest>();
909     authManager_->SrcAuthDeviceFinish();
910     EXPECT_EQ(authManager_->authRequestContext_->reason, DM_OK);
911 
912     authManager_->authRequestContext_->reason = ERR_DM_FAILED;
913     authManager_->authResponseContext_->haveCredential = false;
914     authManager_->SrcAuthDeviceFinish();
915     EXPECT_EQ(authManager_->authRequestContext_->reason, ERR_DM_FAILED);
916 
917     authManager_->authResponseContext_->isOnline = false;
918     authManager_->remoteVersion_ = "5.1.1";
919     authManager_->SrcAuthDeviceFinish();
920     EXPECT_EQ(authManager_->authRequestContext_->reason, ERR_DM_FAILED);
921 }
922 
923 HWTEST_F(DmAuthManagerTest, SinkAuthDeviceFinish001, testing::ext::TestSize.Level1)
924 {
925     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
926     authManager_->softbusConnector_->RegisterSoftbusStateCallback(std::make_shared<SoftbusStateCallbackTest>());
927     authManager_->authResponseContext_->haveCredential = false;
928     authManager_->authResponseContext_->isOnline = true;
929     authManager_->authResponseContext_->bindLevel = 3;
930     authManager_->authResponseContext_->isIdenticalAccount = false;
931     authManager_->SinkAuthDeviceFinish();
932     ASSERT_EQ(authManager_->isAuthDevice_, false);
933 }
934 
935 HWTEST_F(DmAuthManagerTest, AuthDeviceFinish001, testing::ext::TestSize.Level1)
936 {
937     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
938     int64_t requestId = 0;
939     authManager_->authResponseContext_->requestId = 1;
940     authManager_->AuthDeviceFinish(requestId);
941     ASSERT_EQ(authManager_->isAuthDevice_, false);
942 }
943 
944 HWTEST_F(DmAuthManagerTest, AuthDeviceFinish002, testing::ext::TestSize.Level1)
945 {
946     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
947     authManager_->authResponseState_ = nullptr;
948     int64_t requestId = 0;
949     authManager_->authResponseContext_->requestId = 0;
950     authManager_->AuthDeviceFinish(requestId);
951     ASSERT_EQ(authManager_->isAuthDevice_, false);
952 }
953 
954 HWTEST_F(DmAuthManagerTest, AuthDeviceFinish003, testing::ext::TestSize.Level1)
955 {
956     authManager_->authRequestState_ = nullptr;
957     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
958     int64_t requestId = 0;
959     authManager_->authResponseContext_->requestId = 0;
960     authManager_->AuthDeviceFinish(requestId);
961     ASSERT_EQ(authManager_->isAuthDevice_, false);
962 }
963 
964 HWTEST_F(DmAuthManagerTest, AuthDeviceError001, testing::ext::TestSize.Level1)
965 {
966     authManager_->authRequestState_ = nullptr;
967     int64_t requestId = 0;
968     int32_t errorCode = -1;
969     authManager_->AuthDeviceError(requestId, errorCode);
970     ASSERT_EQ(authManager_->isAuthDevice_, false);
971 }
972 
973 HWTEST_F(DmAuthManagerTest, AuthDeviceError002, testing::ext::TestSize.Level1)
974 {
975     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
976     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
977     authManager_->authResponseContext_->authType = 5;
978     int64_t requestId = 0;
979     int32_t errorCode = -1;
980     authManager_->AuthDeviceError(requestId, errorCode);
981     ASSERT_EQ(authManager_->isAuthDevice_, false);
982 }
983 
984 HWTEST_F(DmAuthManagerTest, AuthDeviceError003, testing::ext::TestSize.Level1)
985 {
986     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
987     authManager_->authResponseState_ = nullptr;
988     authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
989     authManager_->authResponseContext_->requestId = 2;
990     int64_t requestId = 0;
991     int32_t errorCode = -1;
992     authManager_->AuthDeviceError(requestId, errorCode);
993     ASSERT_EQ(authManager_->isAuthDevice_, false);
994 }
995 
996 HWTEST_F(DmAuthManagerTest, AuthDeviceError004, testing::ext::TestSize.Level1)
997 {
998     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
999     authManager_->authResponseState_ = nullptr;
1000     authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
1001     authManager_->authResponseContext_->requestId = 3;
1002     authManager_->authTimes_ = 3;
1003     int64_t requestId = 0;
1004     int32_t errorCode = ERR_DM_FAILED;
1005     authManager_->AuthDeviceError(requestId, errorCode);
1006     ASSERT_EQ(authManager_->authResponseContext_->state, DmAuthStatus::STATUS_DM_AUTH_DEFAULT);
1007 }
1008 
1009 HWTEST_F(DmAuthManagerTest, AuthDeviceError005, testing::ext::TestSize.Level1)
1010 {
1011     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1012     authManager_->authResponseState_ = nullptr;
1013     authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
1014     authManager_->authResponseContext_->requestId = 3;
1015     authManager_->authTimes_ = 0;
1016     int64_t requestId = authManager_->authResponseContext_->requestId + 1;
1017     int32_t errorCode = DM_OK;
1018     uint32_t sessionKeyLen = 0;
1019     authManager_->AuthDeviceError(requestId, errorCode);
1020     authManager_->AuthDeviceSessionKey(requestId, nullptr, sessionKeyLen);
1021     ASSERT_EQ(authManager_->isAuthDevice_, false);
1022     authManager_->GetSessionKeyIdSync(requestId);
1023 }
1024 
1025 HWTEST_F(DmAuthManagerTest, AuthDeviceError006, testing::ext::TestSize.Level1)
1026 {
1027     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1028     authManager_->authResponseState_ = nullptr;
1029     authManager_->authResponseContext_->authType = AUTH_TYPE_UNKNOW;
1030     authManager_->authResponseContext_->requestId = 3;
1031     authManager_->authTimes_ = 0;
1032     int64_t requestId = authManager_->authResponseContext_->requestId;
1033     int32_t errorCode = DM_OK;
1034     authManager_->AuthDeviceError(requestId, errorCode);
1035     ASSERT_EQ(authManager_->isAuthDevice_, false);
1036 }
1037 
1038 HWTEST_F(DmAuthManagerTest, AuthDeviceSessionKey001, testing::ext::TestSize.Level1)
1039 {
1040     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1041     int64_t requestId = 0;
1042     uint8_t *sessionKey = nullptr;
1043     uint32_t sessionKeyLen = 0;
1044     authManager_->AuthDeviceSessionKey(requestId, sessionKey, sessionKeyLen);
1045     ASSERT_EQ(authManager_->isAuthDevice_, false);
1046     authManager_->GetSessionKeyIdSync(requestId);
1047 }
1048 
1049 HWTEST_F(DmAuthManagerTest, CompatiblePutAcl001, testing::ext::TestSize.Level1)
1050 {
1051     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1052     authManager_->CompatiblePutAcl();
1053     ASSERT_EQ(authManager_->isAuthDevice_, false);
1054 }
1055 
1056 HWTEST_F(DmAuthManagerTest, CompatiblePutAcl002, testing::ext::TestSize.Level1)
1057 {
1058     authManager_->action_ = USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS;
1059     authManager_->CompatiblePutAcl();
1060     ASSERT_EQ(authManager_->isAuthDevice_, false);
1061 }
1062 
1063 HWTEST_F(DmAuthManagerTest, CompatiblePutAcl003, testing::ext::TestSize.Level1)
1064 {
1065     authManager_->action_ = USER_OPERATION_TYPE_ALLOW_AUTH;
1066     authManager_->CompatiblePutAcl();
1067     ASSERT_EQ(authManager_->isAuthDevice_, false);
1068 }
1069 
1070 HWTEST_F(DmAuthManagerTest, ProcRespNegotiateExt001, testing::ext::TestSize.Level1)
1071 {
1072     int32_t sessionId = 0;
1073     authManager_->ProcRespNegotiateExt(sessionId);
1074     ASSERT_EQ(authManager_->isAuthDevice_, false);
1075 }
1076 
1077 HWTEST_F(DmAuthManagerTest, GenerateBindResultContent001, testing::ext::TestSize.Level1)
1078 {
1079     auto ret = authManager_->GenerateBindResultContent();
1080     ASSERT_EQ(ret.empty(), false);
1081 }
1082 
1083 HWTEST_F(DmAuthManagerTest, GenerateBindResultContent002, testing::ext::TestSize.Level1)
1084 {
1085     authManager_->remoteDeviceId_ = "test";
1086     auto ret = authManager_->GenerateBindResultContent();
1087     ASSERT_FALSE(ret.empty());
1088 }
1089 
1090 
1091 HWTEST_F(DmAuthManagerTest, OnScreenLocked001, testing::ext::TestSize.Level1)
1092 {
1093     authManager_->authResponseContext_ = nullptr;
1094     authManager_->authRequestState_ = nullptr;
1095     authManager_->OnScreenLocked();
1096 
1097     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1098     authManager_->authRequestState_ = nullptr;
1099     authManager_->authResponseContext_->authType = AUTH_TYPE_CRE;
1100     authManager_->OnScreenLocked();
1101 
1102     authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1103     authManager_->OnScreenLocked();
1104 
1105     authManager_->authResponseContext_->authType = AUTH_REQUEST_INIT;
1106     std::shared_ptr<AuthRequestFinishStateMock> requestFinishState = std::make_shared<AuthRequestFinishStateMock>();
1107     EXPECT_CALL(*requestFinishState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_NEGOTIATE));
1108     authManager_->authRequestState_ = requestFinishState;
1109     authManager_->OnScreenLocked();
1110 
1111     EXPECT_CALL(*requestFinishState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_INIT));
1112     authManager_->OnScreenLocked();
1113 
1114     EXPECT_CALL(*requestFinishState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_JOIN));
1115     authManager_->OnScreenLocked();
1116 
1117     EXPECT_CALL(*requestFinishState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_JOIN));
1118     authManager_->authUiStateMgr_ = nullptr;
1119     authManager_->OnScreenLocked();
1120 
1121     EXPECT_CALL(*requestFinishState, GetStateType())
1122         .WillRepeatedly(testing::Return(AuthState::AUTH_REQUEST_NEGOTIATE_DONE));
1123     authManager_->OnScreenLocked();
1124 
1125     EXPECT_CALL(*requestFinishState, GetStateType()).WillRepeatedly(testing::Return(AuthState::AUTH_RESPONSE_FINISH));
1126     authManager_->OnScreenLocked();
1127     EXPECT_EQ(authManager_->authResponseContext_->state, STATUS_DM_AUTH_DEFAULT);
1128 }
1129 
1130 HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived001, testing::ext::TestSize.Level1)
1131 {
1132     int32_t sessionId = 0;
1133     std::string message;
1134     authManager_->OnAuthDeviceDataReceived(sessionId, message);
1135     ASSERT_EQ(authManager_->isAuthDevice_, false);
1136 }
1137 
1138 HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived002, testing::ext::TestSize.Level1)
1139 {
1140     int32_t sessionId = 0;
1141     JsonObject jsonObject;
1142     jsonObject[TAG_DATA] = 123;
1143     std::string message = jsonObject.Dump();
1144     authManager_->OnAuthDeviceDataReceived(sessionId, message);
1145     ASSERT_EQ(authManager_->isAuthDevice_, false);
1146 }
1147 
1148 HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived003, testing::ext::TestSize.Level1)
1149 {
1150     int32_t sessionId = 0;
1151     JsonObject jsonObject;
1152     jsonObject[TAG_DATA] = "123";
1153     jsonObject[TAG_DATA_LEN] = "123";
1154     std::string message = jsonObject.Dump();
1155     authManager_->OnAuthDeviceDataReceived(sessionId, message);
1156     ASSERT_EQ(authManager_->isAuthDevice_, false);
1157 }
1158 
1159 HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived004, testing::ext::TestSize.Level1)
1160 {
1161     int32_t sessionId = 0;
1162     JsonObject jsonObject;
1163     jsonObject[TAG_DATA] = "123";
1164     jsonObject[TAG_DATA_LEN] = 123;
1165     jsonObject[TAG_MSG_TYPE] = "123";
1166     std::string message = jsonObject.Dump();
1167     authManager_->OnAuthDeviceDataReceived(sessionId, message);
1168     ASSERT_EQ(authManager_->isAuthDevice_, false);
1169 }
1170 
1171 HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived005, testing::ext::TestSize.Level1)
1172 {
1173     int32_t sessionId = 0;
1174     JsonObject jsonObject;
1175     jsonObject[TAG_DATA] = "123";
1176     jsonObject[TAG_DATA_LEN] = 123;
1177     jsonObject[TAG_MSG_TYPE] = 123;
1178     std::string message = jsonObject.Dump();
1179     authManager_->OnAuthDeviceDataReceived(sessionId, message);
1180     ASSERT_EQ(authManager_->isAuthDevice_, false);
1181 }
1182 
1183 HWTEST_F(DmAuthManagerTest, DeleteGroup001, testing::ext::TestSize.Level1)
1184 {
1185     std::string pkgName;
1186     std::string deviceId;
1187     int32_t ret = authManager_->DeleteGroup(pkgName, deviceId);
1188     ASSERT_EQ(ret, ERR_DM_FAILED);
1189 }
1190 
1191 HWTEST_F(DmAuthManagerTest, DeleteGroup002, testing::ext::TestSize.Level1)
1192 {
1193     std::string pkgName = "pkgName";
1194     std::string deviceId;
1195     int32_t ret = authManager_->DeleteGroup(pkgName, deviceId);
1196     ASSERT_EQ(ret, DM_OK);
1197 }
1198 
1199 HWTEST_F(DmAuthManagerTest, PutAccessControlList001, testing::ext::TestSize.Level1)
1200 {
1201     authManager_->PutAccessControlList();
1202     ASSERT_EQ(authManager_->isAuthDevice_, false);
1203     authManager_->authResponseContext_->isIdenticalAccount = true;
1204     authManager_->PutAccessControlList();
1205     ASSERT_EQ(authManager_->isAuthDevice_, false);
1206     authManager_->authResponseContext_->isIdenticalAccount = true;
1207     authManager_->PutAccessControlList();
1208     ASSERT_EQ(authManager_->isAuthDevice_, false);
1209     authManager_->authResponseContext_->isIdenticalAccount = false;
1210     authManager_->authResponseContext_->localAccountId = "ohosAnonymousUid";
1211     authManager_->authResponseContext_->confirmOperation = USER_OPERATION_TYPE_ALLOW_AUTH_ALWAYS;
1212     authManager_->PutAccessControlList();
1213     ASSERT_EQ(authManager_->authResponseContext_->isIdenticalAccount, false);
1214 }
1215 
1216 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_001, testing::ext::TestSize.Level1)
1217 {
1218     authManager_->authResponseContext_->msgType = 200;
1219     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateDoneState>();
1220     authManager_->ProcessSourceMsg();
1221     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1222 }
1223 
1224 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_002, testing::ext::TestSize.Level1)
1225 {
1226     authManager_->authResponseContext_->msgType = 200;
1227     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1228     authManager_->ProcessSourceMsg();
1229     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1230 }
1231 
1232 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_003, testing::ext::TestSize.Level1)
1233 {
1234     authManager_->authResponseContext_->msgType = 501;
1235     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateDoneState>();
1236     authManager_->ProcessSourceMsg();
1237     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1238 }
1239 
1240 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_004, testing::ext::TestSize.Level1)
1241 {
1242     authManager_->authResponseContext_->msgType = 501;
1243     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1244     authManager_->ProcessSourceMsg();
1245     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1246 }
1247 
1248 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_005, testing::ext::TestSize.Level1)
1249 {
1250     authManager_->authResponseContext_->msgType = 90;
1251     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1252     authManager_->ProcessSourceMsg();
1253     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1254 }
1255 
1256 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_006, testing::ext::TestSize.Level1)
1257 {
1258     authManager_->authResponseContext_->msgType = 90;
1259     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateDoneState>();
1260     authManager_->ProcessSourceMsg();
1261     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1262 }
1263 
1264 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_007, testing::ext::TestSize.Level1)
1265 {
1266     authManager_->authResponseContext_->msgType = 104;
1267     authManager_->authRequestState_ = std::make_shared<AuthRequestNetworkState>();
1268     authManager_->ProcessSourceMsg();
1269     ASSERT_EQ(authManager_->isFinishOfLocal_, false);
1270 }
1271 
1272 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_008, testing::ext::TestSize.Level1)
1273 {
1274     authManager_->authResponseContext_->msgType = 104;
1275     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateDoneState>();
1276     authManager_->ProcessSourceMsg();
1277     ASSERT_EQ(authManager_->isFinishOfLocal_, false);
1278 }
1279 
1280 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_009, testing::ext::TestSize.Level1)
1281 {
1282     authManager_->authResponseContext_->msgType = 503;
1283     authManager_->authRequestState_ = std::make_shared<AuthRequestCredential>();
1284     authManager_->ProcessSourceMsg();
1285     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1286 }
1287 
1288 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_010, testing::ext::TestSize.Level1)
1289 {
1290     authManager_->authResponseContext_->msgType = 503;
1291     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateDoneState>();
1292     authManager_->ProcessSourceMsg();
1293     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1294 }
1295 
1296 HWTEST_F(DmAuthManagerTest, ProcessSourceMsg_0012, testing::ext::TestSize.Level1)
1297 {
1298     authManager_->authResponseContext_->msgType = 505;
1299     authManager_->authRequestState_ = std::make_shared<AuthRequestReCheckMsg>();
1300     authManager_->ProcessSourceMsg();
1301     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1302 }
1303 
1304 HWTEST_F(DmAuthManagerTest, ProcessSinkMsg_001, testing::ext::TestSize.Level1)
1305 {
1306     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1307     authManager_->authResponseContext_->msgType = 80;
1308     authManager_->authResponseState_ = std::make_shared<AuthResponseInitState>();
1309     authManager_->ProcessSinkMsg();
1310     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1311 }
1312 
1313 HWTEST_F(DmAuthManagerTest, ProcessSinkMsg_002, testing::ext::TestSize.Level1)
1314 {
1315     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1316     authManager_->authResponseContext_->msgType = 80;
1317     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
1318     authManager_->ProcessSinkMsg();
1319     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1320 }
1321 
1322 HWTEST_F(DmAuthManagerTest, ProcessSinkMsg_003, testing::ext::TestSize.Level1)
1323 {
1324     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1325     authManager_->authResponseContext_->msgType = 100;
1326     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
1327     authManager_->ProcessSinkMsg();
1328     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1329 }
1330 
1331 HWTEST_F(DmAuthManagerTest, ProcessSinkMsg_004, testing::ext::TestSize.Level1)
1332 {
1333     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1334     authManager_->authResponseContext_->msgType = 100;
1335     authManager_->authResponseState_ = std::make_shared<AuthResponseInitState>();
1336     authManager_->ProcessSinkMsg();
1337     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1338 }
1339 
1340 HWTEST_F(DmAuthManagerTest, ProcessSinkMsg_005, testing::ext::TestSize.Level1)
1341 {
1342     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1343     authManager_->authResponseContext_->msgType = 104;
1344     authManager_->authResponseState_ = std::make_shared<AuthResponseShowState>();
1345     authManager_->ProcessSinkMsg();
1346     ASSERT_EQ(authManager_->isFinishOfLocal_, false);
1347 }
1348 
1349 HWTEST_F(DmAuthManagerTest, ProcessSinkMsg_006, testing::ext::TestSize.Level1)
1350 {
1351     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1352     authManager_->authResponseContext_->msgType = 502;
1353     authManager_->authResponseState_ = std::make_shared<AuthResponseShowState>();
1354     authManager_->ProcessSinkMsg();
1355     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1356 }
1357 
1358 HWTEST_F(DmAuthManagerTest, ProcessSinkMsg_007, testing::ext::TestSize.Level1)
1359 {
1360     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1361     authManager_->authResponseContext_->msgType = 504;
1362     authManager_->authResponseState_ = std::make_shared<AuthResponseAuthFinish>();
1363     authManager_->ProcessSinkMsg();
1364     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1365 
1366     authManager_->authResponseState_ = std::make_shared<AuthResponseShowState>();
1367     authManager_->ProcessSinkMsg();
1368     ASSERT_EQ(authManager_->isFinishOfLocal_, true);
1369 }
1370 
1371 HWTEST_F(DmAuthManagerTest, ConvertSrcVersion_001, testing::ext::TestSize.Level1)
1372 {
1373     std::string version = "";
1374     std::string edition = "test";
1375     EXPECT_EQ(authManager_->ConvertSrcVersion(version, edition), "test");
1376 
1377     edition = "";
1378     EXPECT_NE(authManager_->ConvertSrcVersion(version, edition), "test");
1379 
1380     version = "test";
1381     EXPECT_EQ(authManager_->ConvertSrcVersion(version, edition), "test");
1382 }
1383 
1384 HWTEST_F(DmAuthManagerTest, GetTaskTimeout_001, testing::ext::TestSize.Level1)
1385 {
1386     int32_t taskTimeOut = 0;
1387     authManager_->SetAuthType(AUTH_TYPE_CRE);
1388     EXPECT_EQ(authManager_->GetTaskTimeout("test", taskTimeOut), taskTimeOut);
1389 
1390     taskTimeOut = 1000;
1391 
1392     authManager_->SetAuthType(AUTH_TYPE_IMPORT_AUTH_CODE);
1393     EXPECT_EQ(authManager_->GetTaskTimeout("test", taskTimeOut), taskTimeOut);
1394 
1395     authManager_->SetAuthType(AUTH_TYPE_IMPORT_AUTH_CODE);
1396     EXPECT_EQ(authManager_->GetTaskTimeout(AUTHENTICATE_TIMEOUT_TASK, taskTimeOut), 20);
1397 }
1398 
1399 HWTEST_F(DmAuthManagerTest, CheckAuthParamVaildExtra_001, testing::ext::TestSize.Level1)
1400 {
1401     std::string extra = R"({"extra": {"bindLevel": "123"}})";
1402     JsonObject jsonObject;
1403     jsonObject["bindLevel"] = 1;
1404     int32_t ret = authManager_->CheckAuthParamVaildExtra(extra, "");
1405     EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
1406 
1407     extra = jsonObject.Dump();
1408     EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false));
1409     ret = authManager_->CheckAuthParamVaildExtra(extra, "");
1410     EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
1411 
1412     EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(true));
1413     ret = authManager_->CheckAuthParamVaildExtra(extra, "");
1414     EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
1415 
1416     jsonObject["bindLevel"] = 15;
1417     extra = jsonObject.Dump();
1418     ret = authManager_->CheckAuthParamVaildExtra(extra, "");
1419     EXPECT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
1420 }
1421 
1422 HWTEST_F(DmAuthManagerTest, AuthenticateDevice_004, testing::ext::TestSize.Level1)
1423 {
1424     int32_t authType = 0;
1425     std::string extra = R"({"extra": {"bindLevel": 789}})";
1426     std::string pkgName = "ohos_test_004";
1427     std::string deviceId = "512156";
1428     authManager_->importPkgName_ = "ohos_test_004";
1429     authManager_->importAuthCode_ = "156161";
1430     authManager_->authRequestState_ = nullptr;
1431     authManager_->authResponseState_ = nullptr;
1432     std::shared_ptr<IDeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
1433     authManager_->authUiStateMgr_ = std::make_shared<AuthUiStateManager>(listener);
1434     authManager_->authenticationMap_.insert(std::pair<int32_t, std::shared_ptr<IAuthentication>>(authType, nullptr));
1435     int32_t ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
1436     ASSERT_EQ(ret, DM_OK);
1437 
1438     JsonObject jsonObject;
1439     jsonObject[PARAM_KEY_CONN_SESSIONTYPE] = "TML";
1440     deviceId = "sdcwafefawe";
1441     extra = jsonObject.Dump();
1442     ret = authManager_->AuthenticateDevice(pkgName, authType, deviceId, extra);
1443     ASSERT_EQ(ret, ERR_DM_AUTH_BUSINESS_BUSY);
1444 }
1445 
1446 HWTEST_F(DmAuthManagerTest, StopAuthenticateDevice_001, testing::ext::TestSize.Level1)
1447 {
1448     std::string pkgName;
1449     int32_t ret = authManager_->StopAuthenticateDevice(pkgName);
1450     ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
1451 
1452     pkgName = "pkgName_001";
1453     int64_t requestId = 12;
1454     int32_t status = 0;
1455     int32_t sessionId = 1;
1456     std::string peerUdidHash;
1457     if (authManager_->timer_ == nullptr) {
1458         authManager_->timer_ = std::make_shared<DmTimer>();
1459     }
1460     authManager_->authRequestState_ = std::make_shared<AuthRequestInitState>();
1461     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1462     authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
1463     authManager_->authRequestContext_->hostPkgName = pkgName;
1464     authManager_->authResponseContext_->hostPkgName = pkgName;
1465     authManager_->isAuthenticateDevice_ = true;
1466 
1467     authManager_->authResponseContext_->authType == AUTH_TYPE_IMPORT_AUTH_CODE;
1468     authManager_->MemberJoinAuthRequest(requestId, status);
1469     authManager_->authResponseContext_->authType == AUTH_TYPE_NFC;
1470     authManager_->authResponseContext_->requestId = requestId;
1471     status = 1;
1472     authManager_->authTimes_ = 3;
1473     authManager_->MemberJoinAuthRequest(requestId, status);
1474     status = 0;
1475     authManager_->authTimes_ = 2;
1476     authManager_->MemberJoinAuthRequest(requestId, status);
1477     status = 0;
1478     authManager_->HandleMemberJoinImportAuthCode(requestId, status);
1479     authManager_->NegotiateRespMsg(DM_VERSION_5_0_1);
1480     authManager_->NegotiateRespMsg(DM_VERSION_4_1_5_1);
1481     authManager_->NegotiateRespMsg(DM_VERSION_5_0_2);
1482     EXPECT_CALL(*softbusSessionMock_, GetPeerDeviceId(_, _)).WillOnce(Return(DM_OK));
1483     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK));
1484     authManager_->GetPeerUdidHash(sessionId, peerUdidHash);
1485 
1486     EXPECT_CALL(*softbusSessionMock_, GetPeerDeviceId(_, _)).WillOnce(Return(DM_OK));
1487     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(ERR_DM_FAILED));
1488     authManager_->GetPeerUdidHash(sessionId, peerUdidHash);
1489     ret = authManager_->StopAuthenticateDevice(pkgName);
1490     ASSERT_EQ(ret, DM_OK);
1491 }
1492 
1493 HWTEST_F(DmAuthManagerTest, IsAuthFinish_001, testing::ext::TestSize.Level1)
1494 {
1495     authManager_->authResponseContext_->reply = ERR_DM_UNSUPPORTED_AUTH_TYPE;
1496     bool ret = authManager_->IsAuthFinish();
1497     EXPECT_TRUE(ret);
1498 
1499     authManager_->authResponseContext_->isOnline = false;
1500     authManager_->authResponseContext_->isIdenticalAccount = true;
1501     authManager_->authResponseContext_->authed = false;
1502     ret = authManager_->IsAuthFinish();
1503     EXPECT_TRUE(ret);
1504 
1505     authManager_->authResponseContext_->isIdenticalAccount = false;
1506     authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1507     authManager_->authResponseContext_->isAuthCodeReady = false;
1508     ret = authManager_->IsAuthFinish();
1509     EXPECT_TRUE(ret);
1510 
1511     authManager_->authResponseContext_->reply = ERR_DM_AUTH_BUSINESS_BUSY;
1512     authManager_->authResponseContext_->isAuthCodeReady = true;
1513     ret = authManager_->IsAuthFinish();
1514     EXPECT_FALSE(ret);
1515 
1516     int32_t sessionId = 1;
1517     authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1518     authManager_->authResponseContext_->importAuthCode = "importAuthCode";
1519     authManager_->importAuthCode_= "importAuthCode";
1520     authManager_->ProcessAuthRequestExt(sessionId);
1521 
1522     authManager_->authResponseContext_->isOnline = true;
1523     authManager_->authResponseContext_->authed = true;
1524     authManager_->authResponseContext_->importAuthCode = "";
1525     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1)).WillOnce(Return(DM_OK));
1526     authManager_->ProcessAuthRequestExt(sessionId);
1527     authManager_->authResponseContext_->reply = ERR_DM_AUTH_BUSINESS_BUSY;
1528     authManager_->authResponseContext_->isOnline = false;
1529     authManager_->authResponseContext_->importAuthCode = "importAuthCode";
1530     authManager_->authResponseContext_->isIdenticalAccount = false;
1531     authManager_->authResponseContext_->isAuthCodeReady = true;
1532     authManager_->ProcessAuthRequestExt(sessionId);
1533 }
1534 
1535 HWTEST_F(DmAuthManagerTest, RespNegotiate_101, testing::ext::TestSize.Level1)
1536 {
1537     int64_t requestId = 1;
1538     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1539     authManager_->authResponseContext_->dmVersion = "5.0.2";
1540     authManager_->authResponseContext_->bindLevel = 1;
1541     authManager_->RespNegotiate(requestId);
1542     authManager_->authResponseContext_->dmVersion = "5.0.1";
1543     authManager_->authResponseContext_->bindLevel = 0;
1544     authManager_->RespNegotiate(requestId);
1545     ASSERT_NE(authManager_->authResponseContext_, nullptr);
1546 
1547     authManager_->authResponseContext_->edition = "";
1548     authManager_->authResponseContext_->bindLevel = 1;
1549     authManager_->timer_ = std::make_shared<DmTimer>();
1550     authManager_->RespNegotiate(requestId);
1551     ASSERT_NE(authManager_->authResponseContext_, nullptr);
1552 
1553     authManager_->authResponseContext_->bindLevel = 5;
1554     authManager_->RespNegotiate(requestId);
1555     ASSERT_NE(authManager_->authResponseContext_, nullptr);
1556 }
1557 
1558 HWTEST_F(DmAuthManagerTest, SendAuthRequest_101, testing::ext::TestSize.Level1)
1559 {
1560     int64_t sessionId = 1;
1561     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1562     authManager_->authResponseContext_->reply = ERR_DM_VERSION_INCOMPATIBLE;
1563     authManager_->SendAuthRequest(sessionId);
1564 
1565     authManager_->authResponseContext_->reply = ERR_DM_AUTH_CODE_INCORRECT;
1566     authManager_->authResponseContext_->bindLevel = 5;
1567     ASSERT_NE(authManager_->authResponseContext_, nullptr);
1568 }
1569 
1570 HWTEST_F(DmAuthManagerTest, AuthDeviceError_007, testing::ext::TestSize.Level1)
1571 {
1572     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1573     authManager_->authResponseState_ = nullptr;
1574     authManager_->authResponseContext_->requestId = 3;
1575     authManager_->authTimes_ = 0;
1576     authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1577     int64_t requestId = authManager_->authResponseContext_->requestId;
1578     int32_t errorCode = DM_OK;
1579     authManager_->AuthDeviceError(requestId, errorCode);
1580     ASSERT_NE(authManager_->authRequestState_, nullptr);
1581 
1582     authManager_->authRequestState_ = nullptr;
1583     authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
1584     authManager_->authTimes_ = 5;
1585     authManager_->AuthDeviceError(requestId, errorCode);
1586     ASSERT_NE(authManager_->authResponseState_, nullptr);
1587 }
1588 
1589 HWTEST_F(DmAuthManagerTest, DeleteGroup_003, testing::ext::TestSize.Level1)
1590 {
1591     std::string pkgName = "pkgName";
1592     int32_t userId = 0;
1593     std::string deviceId;
1594     int32_t ret = authManager_->DeleteGroup(pkgName, userId, deviceId);
1595     ASSERT_EQ(ret, ERR_DM_FAILED);
1596 }
1597 
1598 HWTEST_F(DmAuthManagerTest, CompatiblePutAcl_004, testing::ext::TestSize.Level1)
1599 {
1600     authManager_->action_ = USER_OPERATION_TYPE_ALLOW_AUTH;
1601     authManager_->authRequestState_ = nullptr;
1602     authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
1603     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK));
1604     authManager_->CompatiblePutAcl();
1605     ASSERT_EQ(authManager_->authRequestState_, nullptr);
1606 }
1607 
1608 HWTEST_F(DmAuthManagerTest, ProcRespNegotiateExt002, testing::ext::TestSize.Level1)
1609 {
1610     int32_t sessionId = 0;
1611     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1612     authManager_->authResponseContext_->authed = true;
1613     authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1614     authManager_->importAuthCode_ = "importAuthCode_";
1615     authManager_->authResponseContext_->bundleName = "";
1616     std::vector<int32_t> bindType;
1617     bindType.push_back(1);
1618     bindType.push_back(0);
1619     EXPECT_CALL(*multipleUserConnectorMock_, GetOhosAccountId()).WillOnce(Return("remoteAccountId"));
1620     EXPECT_CALL(*deviceProfileConnectorMock_, GetBindTypeByPkgName(_, _, _)).WillOnce(Return(bindType));
1621     authManager_->authResponseContext_->remoteAccountId = "remoteAccountId";
1622     authManager_->authResponseContext_->localAccountId = "remoteAccountId";
1623     authManager_->ProcRespNegotiateExt(sessionId);
1624     ASSERT_EQ(authManager_->isAuthDevice_, false);
1625 }
1626 
1627 HWTEST_F(DmAuthManagerTest, OnAuthDeviceDataReceived006, testing::ext::TestSize.Level1)
1628 {
1629     int32_t sessionId = 0;
1630     JsonObject jsonObject;
1631     jsonObject[TAG_DATA] = "123";
1632     jsonObject[TAG_DATA_LEN] = 123;
1633     jsonObject[TAG_MSG_TYPE] = 123;
1634     std::string message = jsonObject.Dump();
1635     authManager_->authResponseContext_ = nullptr;
1636     authManager_->OnAuthDeviceDataReceived(sessionId, message);
1637     ASSERT_EQ(authManager_->isAuthDevice_, false);
1638 }
1639 
1640 HWTEST_F(DmAuthManagerTest, GetBinderInfo_001, testing::ext::TestSize.Level1)
1641 {
1642     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1643     authManager_->authResponseContext_->bundleName = "bundleName";
1644     EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(DM_OK));
1645     int32_t ret = authManager_->GetBinderInfo();
1646     ASSERT_EQ(ret, DM_OK);
1647 
1648     EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(ERR_DM_FAILED));
1649     EXPECT_CALL(*appManagerMock_, GetHapTokenIdByName(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED));
1650     ret = authManager_->GetBinderInfo();
1651     ASSERT_EQ(ret, ERR_DM_FAILED);
1652 
1653     EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(ERR_DM_FAILED));
1654     EXPECT_CALL(*appManagerMock_, GetHapTokenIdByName(_, _, _, _)).WillOnce(Return(DM_OK));
1655     authManager_->authResponseContext_->bindLevel = APP;
1656     ret = authManager_->GetBinderInfo();
1657     ASSERT_EQ(ret, DM_OK);
1658 
1659     authManager_->authResponseContext_->bindLevel = USER;
1660     authManager_->SetProcessInfo();
1661 
1662     authManager_->authResponseContext_->bindLevel = SERVICE;
1663     authManager_->SetProcessInfo();
1664 
1665     authManager_->authResponseContext_->bindLevel = APP;
1666     authManager_->authRequestState_ = nullptr;
1667     authManager_->authResponseState_ = nullptr;
1668     authManager_->SetProcessInfo();
1669 
1670     authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
1671     authManager_->SetProcessInfo();
1672 
1673     authManager_->authResponseState_ = nullptr;
1674     authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
1675     authManager_->SetProcessInfo();
1676 
1677     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
1678     authManager_->RequestReCheckMsg();
1679 }
1680 
1681 HWTEST_F(DmAuthManagerTest, ResponseReCheckMsg_001, testing::ext::TestSize.Level1)
1682 {
1683     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1684     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
1685     authManager_->authResponseState_ = std::make_shared<AuthResponseConfirmState>();
1686     authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
1687     authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1688     authManager_->authResponseContext_->edition = "edition";
1689     authManager_->remoteVersion_ = "";
1690     authManager_->ResponseReCheckMsg();
1691 
1692     authManager_->authResponseContext_->edition = "";
1693     authManager_->remoteDeviceId_ = "remoteDeviceId_";
1694     authManager_->authResponseContext_->localDeviceId = authManager_->remoteDeviceId_;
1695     authManager_->authResponseContext_->remoteUserId = 1;
1696     authManager_->authResponseContext_->hostPkgName = "hostPkgName";
1697     authManager_->authResponseContext_->bindLevel = 1;
1698     authManager_->authResponseContext_->localUserId = authManager_->authResponseContext_->remoteUserId;
1699     authManager_->authResponseContext_->bundleName = authManager_->authResponseContext_->hostPkgName;
1700     authManager_->authResponseContext_->localBindLevel = authManager_->authResponseContext_->bindLevel;
1701     EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).Times(::testing::AtLeast(1))
1702         .WillOnce(Return(ERR_DM_FAILED));
1703     EXPECT_CALL(*appManagerMock_, GetHapTokenIdByName(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED));
1704     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK));
1705     authManager_->ResponseReCheckMsg();
1706     ASSERT_EQ(authManager_->authResponseContext_->localBindLevel, 1);
1707 }
1708 
1709 HWTEST_F(DmAuthManagerTest, RequestReCheckMsgDone_001, testing::ext::TestSize.Level1)
1710 {
1711     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1712     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
1713     authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
1714     authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
1715     authManager_->authResponseContext_->edition = "edition";
1716     authManager_->remoteVersion_ = "";
1717     authManager_->RequestReCheckMsgDone();
1718 
1719     authManager_->authResponseContext_->edition = "";
1720     authManager_->remoteDeviceId_ = "remoteDeviceId_";
1721     authManager_->authResponseContext_->localDeviceId = authManager_->remoteDeviceId_;
1722     authManager_->authRequestContext_->remoteUserId = 1;
1723     authManager_->authResponseContext_->peerBundleName = "peerBundleName";
1724     authManager_->authResponseContext_->bindLevel = 1;
1725     authManager_->authResponseContext_->localUserId = authManager_->authRequestContext_->remoteUserId;
1726     authManager_->authResponseContext_->bundleName = authManager_->authResponseContext_->peerBundleName;
1727     authManager_->authResponseContext_->localBindLevel = authManager_->authResponseContext_->bindLevel;
1728     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK));
1729     authManager_->RequestReCheckMsgDone();
1730     ASSERT_EQ(authManager_->authResponseContext_->localBindLevel, 1);
1731 
1732     authManager_->ConverToFinish();
1733 }
1734 
1735 HWTEST_F(DmAuthManagerTest, SinkAuthDeviceFinish_002, testing::ext::TestSize.Level1)
1736 {
1737     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1738     authManager_->softbusConnector_->RegisterSoftbusStateCallback(std::make_shared<SoftbusStateCallbackTest>());
1739     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
1740     authManager_->authResponseContext_->haveCredential = false;
1741     authManager_->authResponseContext_->isOnline = true;
1742     authManager_->authResponseContext_->bindLevel = 3;
1743     authManager_->authResponseContext_->isIdenticalAccount = false;
1744     authManager_->isNeedProcCachedSrcReqMsg_ = true;
1745     authManager_->srcReqMsg_ = "srcReqMsg";
1746     authManager_->SinkAuthDeviceFinish();
1747     ASSERT_EQ(authManager_->isAuthDevice_, false);
1748 
1749     authManager_->authResponseContext_->haveCredential = true;
1750     JsonObject jsonObject;
1751     jsonObject["MSG_TYPE"] = MSG_TYPE_REQ_RECHECK_MSG;
1752     authManager_->srcReqMsg_ = jsonObject.Dump();
1753     authManager_->remoteVersion_ = "4.0.1";
1754     authManager_->SinkAuthDeviceFinish();
1755     ASSERT_EQ(authManager_->isAuthDevice_, false);
1756 
1757     authManager_->remoteVersion_ = "5.1.2";
1758     authManager_->SinkAuthDeviceFinish();
1759     ASSERT_EQ(authManager_->isAuthDevice_, false);
1760 }
1761 
1762 HWTEST_F(DmAuthManagerTest, AuthDeviceFinish004, testing::ext::TestSize.Level1)
1763 {
1764     authManager_->authRequestState_ = nullptr;
1765     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
1766     int64_t requestId = 0;
1767     authManager_->authResponseContext_->requestId = 0;
1768     authManager_->remoteVersion_ = "5.0.2";
1769     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).WillOnce(Return(DM_OK));
1770     authManager_->AuthDeviceFinish(requestId);
1771     ASSERT_EQ(authManager_->isAuthDevice_, false);
1772 
1773     if (authManager_->authMessageProcessor_ == nullptr) {
1774         authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
1775     }
1776     authManager_->remoteVersion_ = "5.1.2";
1777     authManager_->AuthDeviceFinish(requestId);
1778     ASSERT_EQ(authManager_->isAuthDevice_, false);
1779 }
1780 
1781 HWTEST_F(DmAuthManagerTest, RequestCredentialDone_003, testing::ext::TestSize.Level1)
1782 {
1783     authManager_->hiChainAuthConnector_ = std::make_shared<HiChainAuthConnector>();
1784     authManager_->RequestCredential();
1785     authManager_->authRequestState_ = std::make_shared<AuthRequestNegotiateState>();
1786     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1787     authManager_->authResponseContext_->publicKey = "";
1788     authManager_->RequestCredentialDone();
1789     ASSERT_EQ(authManager_->isAuthDevice_, false);
1790 
1791     authManager_->authResponseContext_->publicKey = "publicKey";
1792     EXPECT_CALL(*hiChainAuthConnectorMock_, ImportCredential(_, _, _, _)).WillOnce(Return(ERR_DM_FAILED));
1793     authManager_->RequestCredentialDone();
1794     ASSERT_EQ(authManager_->isAuthDevice_, false);
1795 }
1796 
1797 HWTEST_F(DmAuthManagerTest, AuthDevice_003, testing::ext::TestSize.Level1)
1798 {
1799     std::string pinCode = "123456";
1800     authManager_->isAuthDevice_ = false;
1801     authManager_->authResponseContext_->authType = 5;
1802     EXPECT_CALL(*hiChainAuthConnectorMock_, AuthDevice(_, _, _, _)).WillOnce(Return(DM_OK));
1803     int32_t ret = authManager_->AuthDevice(pinCode);
1804     ASSERT_EQ(ret, DM_OK);
1805 }
1806 
1807 HWTEST_F(DmAuthManagerTest, UnBindDevice_001, testing::ext::TestSize.Level1)
1808 {
1809     std::string pkgName;
1810     std::string udid = "udid";
1811     int32_t bindLevel = 1;
1812     std::string extra;
1813     int32_t ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra);
1814     ASSERT_EQ(ret, ERR_DM_FAILED);
1815 
1816     pkgName = "pkgName";
1817     DmOfflineParam offlineParam;
1818     offlineParam.bindType = INVALIED_TYPE;
1819     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1820     ret = authManager_->UnBindDevice(pkgName, udid, bindLevel, extra);
1821     ASSERT_EQ(ret, ERR_DM_FAILED);
1822 }
1823 
1824 HWTEST_F(DmAuthManagerTest, DeleteAcl_001, testing::ext::TestSize.Level1)
1825 {
1826     std::string pkgName = "pkgName";
1827     std::string localUdid = "localUdid";
1828     std::string remoteUdid = "remoteUdid";
1829     int32_t bindLevel = 1;
1830     std::string extra = "extra";
1831     DmOfflineParam offlineParam;
1832     offlineParam.bindType = APP_PEER_TO_PEER_TYPE;
1833     offlineParam.leftAclNumber = 1;
1834     authManager_->softbusConnector_->deviceStateManagerCallback_ = std::make_shared<SoftbusStateCallbackTest>();
1835     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1836     int32_t ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
1837     ASSERT_EQ(ret, DM_OK);
1838 
1839     offlineParam.leftAclNumber = 0;
1840     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1841     ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
1842     ASSERT_EQ(ret, DM_OK);
1843 
1844     bindLevel = 3;
1845     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1846     ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
1847     ASSERT_EQ(ret, DM_OK);
1848 
1849     offlineParam.leftAclNumber = 1;
1850     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1851     ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
1852     ASSERT_EQ(ret, DM_OK);
1853 
1854     bindLevel = 2;
1855     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1856     ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
1857     ASSERT_EQ(ret, ERR_DM_FAILED);
1858 
1859     bindLevel = 1;
1860     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1861     ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
1862     ASSERT_EQ(ret, DM_OK);
1863 
1864     offlineParam.leftAclNumber = 0;
1865     EXPECT_CALL(*deviceProfileConnectorMock_, DeleteAccessControlList(_, _, _, _, _)).WillOnce(Return(offlineParam));
1866     ret = authManager_->DeleteAcl(pkgName, localUdid, remoteUdid, bindLevel, extra);
1867     ASSERT_EQ(ret, DM_OK);
1868 }
1869 
1870 HWTEST_F(DmAuthManagerTest, StopAuthenticateDevice_002, testing::ext::TestSize.Level1)
1871 {
1872     std::string pkgName = "pkgName";
1873     authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
1874     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1875     authManager_->authRequestContext_->hostPkgName = pkgName;
1876     authManager_->authResponseContext_->hostPkgName = pkgName;
1877     authManager_->isAuthenticateDevice_ = true;
1878     authManager_->authRequestState_ = std::make_shared<AuthRequestFinishState>();
1879     int32_t ret = authManager_->StopAuthenticateDevice(pkgName);
1880     ASSERT_EQ(ret, DM_OK);
1881 
1882     authManager_->authRequestContext_->hostPkgName = "";
1883     ret = authManager_->StopAuthenticateDevice(pkgName);
1884     ASSERT_EQ(ret, DM_OK);
1885 
1886     JsonObject jsonObject;
1887     jsonObject["PEER_BUNDLE_NAME"] = "";
1888     authManager_->authRequestContext_->hostPkgName = "hostPkgName";
1889     authManager_->ParseJsonObject(jsonObject);
1890 
1891     int32_t sessionId = 1;
1892     authManager_->remoteUdidHash_ = "remoteUdidhash";
1893     std::string udidHashTemp = "remoteUdidhash";
1894     EXPECT_CALL(*softbusSessionMock_, GetPeerDeviceId(_, _)).WillOnce(Return(DM_OK));
1895     EXPECT_CALL(*cryptoMock_, GetUdidHash(_, _)).Times(::testing::AtLeast(1))
__anon70089ded0302(unsigned char *udidHash) 1896     .WillOnce(WithArgs<1>(Invoke([udidHashTemp](unsigned char *udidHash) {
1897         memcpy_s(udidHash, (udidHashTemp.length() + 1), udidHashTemp.c_str(), (udidHashTemp.length()));
1898         return DM_OK;
1899     })));
1900     authManager_->DeleteOffLineTimer(sessionId);
1901 
1902     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
1903     authManager_->authMessageProcessor_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1904     sessionId = 1;
1905     std::string message;
1906     authManager_->authResponseContext_->sessionId = sessionId;
1907     JsonObject jsonObject1;
1908     jsonObject1[TAG_MSG_TYPE] = 800;
1909     message = jsonObject1.Dump();
1910     authManager_->authResponseState_ = nullptr;
1911     authManager_->OnDataReceived(sessionId, message);
1912 
1913     authManager_->authRequestState_ = nullptr;
1914     authManager_->authResponseState_ = std::make_shared<AuthResponseNegotiateState>();
1915     authManager_->OnDataReceived(sessionId, message);
1916 }
1917 
1918 HWTEST_F(DmAuthManagerTest, RegisterAuthenticationType_001, testing::ext::TestSize.Level1)
1919 {
1920     int32_t authenticationType = 1;
1921     int32_t ret = authManager_->RegisterAuthenticationType(authenticationType);
1922     ASSERT_EQ(ret, DM_OK);
1923 
1924     authenticationType = 0;
1925     ret = authManager_->RegisterAuthenticationType(authenticationType);
1926     ASSERT_EQ(ret, DM_OK);
1927 
1928     authManager_->authResponseState_ = std::make_shared<AuthResponseReCheckMsg>();
1929     authManager_->ProcessReqPublicKey();
1930 
1931     authManager_->authResponseState_ = std::make_shared<AuthResponseAuthFinish>();
1932     authManager_->ProcessReqPublicKey();
1933 }
1934 
1935 HWTEST_F(DmAuthManagerTest, CheckProcessNameInWhiteList_001, testing::ext::TestSize.Level1)
1936 {
1937     std::string processName = "";
1938     bool ret = authManager_->CheckProcessNameInWhiteList(processName);
1939     ASSERT_FALSE(ret);
1940 
1941     processName = "processName";
1942     ret = authManager_->CheckProcessNameInWhiteList(processName);
1943     ASSERT_FALSE(ret);
1944 
1945     processName = "com.example.myapplication";
1946     ret = authManager_->CheckProcessNameInWhiteList(processName);
1947     ASSERT_TRUE(ret);
1948 }
1949 
1950 HWTEST_F(DmAuthManagerTest, GetCloseSessionDelaySeconds_001, testing::ext::TestSize.Level1)
1951 {
1952     std::string delaySecondsStr = "";
1953     int32_t ret = authManager_->GetCloseSessionDelaySeconds(delaySecondsStr);
1954     ASSERT_EQ(ret, DM_OK);
1955 }
1956 
1957 HWTEST_F(DmAuthManagerTest, CheckNeedShowAuthInfoDialog_001, testing::ext::TestSize.Level1)
1958 {
1959     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
1960     int32_t errorCode = ERR_DM_HICHAIN_PROOFMISMATCH;
1961     authManager_->pincodeDialogEverShown_ = false;
1962     authManager_->authResponseContext_->authType = AUTH_TYPE_NFC;
1963     authManager_->serviceInfoProfile_.SetPinCode(PINCODE);
1964     authManager_->serviceInfoProfile_.SetPinExchangeType(
1965         static_cast<int32_t>(DMLocalServiceInfoPinExchangeType::FROMDP));
1966     bool ret = authManager_->CheckNeedShowAuthInfoDialog(errorCode);
1967     ASSERT_TRUE(ret);
1968 
1969     authManager_->authResponseContext_->authType = AUTH_TYPE_IMPORT_AUTH_CODE;
1970     ret = authManager_->CheckNeedShowAuthInfoDialog(errorCode);
1971     ASSERT_FALSE(ret);
1972 
1973     EXPECT_CALL(*deviceProfileConnectorMock_, GetLocalServiceInfoByBundleNameAndPinExchangeType(_, _, _))
1974         .WillOnce(Return(ERR_DM_FAILED));
1975     authManager_->GetLocalServiceInfoInDp();
1976 
1977     DistributedDeviceProfile::LocalServiceInfo localServiceInfo;
1978     localServiceInfo.SetAuthType(static_cast<int32_t>(DMLocalServiceInfoAuthType::TRUST_ONETIME));
1979     localServiceInfo.SetAuthBoxType(static_cast<int32_t>(DMLocalServiceInfoAuthBoxType::STATE3));
1980     localServiceInfo.SetPinExchangeType(static_cast<int32_t>(DMLocalServiceInfoPinExchangeType::FROMDP));
1981     localServiceInfo.SetPinCode(PINCODE);
1982     EXPECT_CALL(*deviceProfileConnectorMock_, GetLocalServiceInfoByBundleNameAndPinExchangeType(_, _, _))
1983         .WillOnce(DoAll(SetArgReferee<2>(localServiceInfo), Return(DM_OK)));
1984     authManager_->GetLocalServiceInfoInDp();
1985 
1986     int64_t requestId = 1;
1987     uint8_t arrayPtr[] = {1, 2, 3, 4};
1988     uint8_t *sessionKey = arrayPtr;
1989     uint32_t sessionKeyLen = static_cast<uint32_t>(sizeof(arrayPtr) / sizeof(arrayPtr[0]));
1990     authManager_->authResponseContext_->requestId = 1;
1991     authManager_->authMessageProcessor_ = std::make_shared<AuthMessageProcessor>(authManager_);
1992     EXPECT_CALL(*cryptoMgrMock_, SaveSessionKey(_, _)).WillOnce(Return(DM_OK));
1993     EXPECT_CALL(*deviceProfileConnectorMock_, PutSessionKey(_, _, _))
1994         .WillOnce(DoAll(SetArgReferee<2>(1), Return(DM_OK)));
1995     authManager_->AuthDeviceSessionKey(requestId, sessionKey, sessionKeyLen);
1996     authManager_->GetSessionKeyIdSync(requestId);
1997 }
1998 
1999 HWTEST_F(DmAuthManagerTest, IsPinCodeValid_001, testing::ext::TestSize.Level1)
2000 {
2001     authManager_->authResponseContext_ = nullptr;
2002     authManager_->ShowConfigDialog();
2003 
2004     authManager_->authResponseContext_ = std::make_shared<DmAuthResponseContext>();
2005     authManager_->serviceInfoProfile_.SetAuthBoxType(
2006         static_cast<int32_t>(DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM));
2007 
2008     authManager_->authResponseContext_->authType = AUTH_TYPE_NFC;
2009     authManager_->serviceInfoProfile_.SetPinCode(PINCODE);
2010     authManager_->serviceInfoProfile_.SetPinExchangeType(
2011         static_cast<int32_t>(DMLocalServiceInfoPinExchangeType::FROMDP));
2012     authManager_->ShowConfigDialog();
2013 
2014     authManager_->authResponseContext_->isShowDialog = false;
2015     authManager_->serviceInfoProfile_.SetPinExchangeType(
2016         static_cast<int32_t>(DMLocalServiceInfoPinExchangeType::PINBOX));
2017     authManager_->ShowConfigDialog();
2018 
2019     authManager_->authResponseContext_->isShowDialog = true;
2020     authManager_->ShowConfigDialog();
2021 
2022     ASSERT_FALSE(authManager_->IsPinCodeValid(MIN_PIN_CODE_VALUE));
2023     ASSERT_FALSE(authManager_->IsPinCodeValid(MAX_PIN_CODE_VALUE));
2024     ASSERT_TRUE(authManager_->IsPinCodeValid(PINCODE));
2025 }
2026 
2027 HWTEST_F(DmAuthManagerTest, IsPinCodeValid_002, testing::ext::TestSize.Level1)
2028 {
2029     std::string strPin = "";
2030     ASSERT_FALSE(authManager_->IsPinCodeValid(strPin));
2031     strPin = "pinCode";
2032     ASSERT_FALSE(authManager_->IsPinCodeValid(strPin));
2033 }
2034 
2035 HWTEST_F(DmAuthManagerTest, IsServiceInfoAuthTypeValid_001, testing::ext::TestSize.Level1)
2036 {
2037     int32_t authType = 2;
2038     ASSERT_FALSE(authManager_->IsServiceInfoAuthTypeValid(authType));
2039 }
2040 
2041 HWTEST_F(DmAuthManagerTest, IsServiceInfoAuthBoxTypeValid_001, testing::ext::TestSize.Level1)
2042 {
2043     int32_t authBoxType = 3;
2044     ASSERT_FALSE(authManager_->IsServiceInfoAuthBoxTypeValid(authBoxType));
2045 }
2046 
2047 HWTEST_F(DmAuthManagerTest, IsServiceInfoPinExchangeTypeValid_001, testing::ext::TestSize.Level1)
2048 {
2049     int32_t pinExchangeType = 4;
2050     ASSERT_FALSE(authManager_->IsServiceInfoPinExchangeTypeValid(pinExchangeType));
2051 }
2052 
2053 HWTEST_F(DmAuthManagerTest, IsLocalServiceInfoValid_001, testing::ext::TestSize.Level1)
2054 {
2055     DistributedDeviceProfile::LocalServiceInfo profile;
2056     profile.SetAuthType(2);
2057     ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile));
2058 
2059     profile.SetAuthType(static_cast<int32_t>(DMLocalServiceInfoAuthType::TRUST_ONETIME));
2060     profile.SetAuthBoxType(3);
2061     ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile));
2062 
2063     profile.SetAuthBoxType(static_cast<int32_t>(DMLocalServiceInfoAuthBoxType::STATE3));
2064     profile.SetPinExchangeType(4);
2065     ASSERT_FALSE(authManager_->IsLocalServiceInfoValid(profile));
2066 
2067     profile.SetPinExchangeType(static_cast<int32_t>(DMLocalServiceInfoPinExchangeType::FROMDP));
2068     profile.SetPinCode("");
2069     ASSERT_TRUE(authManager_->IsLocalServiceInfoValid(profile));
2070 
2071     profile.SetPinCode(PINCODE);
2072     ASSERT_TRUE(authManager_->IsLocalServiceInfoValid(profile));
2073 }
2074 
2075 HWTEST_F(DmAuthManagerTest, EstablishAuthChannel_003, testing::ext::TestSize.Level1)
2076 {
2077     std::string deviceId = "d********3";
2078     authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
2079     authManager_->authRequestContext_->connSessionType = CONN_SESSION_TYPE_HML;
2080     int32_t ret = authManager_->EstablishAuthChannel(deviceId);
2081     ASSERT_EQ(ret, DM_OK);
2082 
2083     JsonObject jsonObject;
2084     jsonObject[PARAM_KEY_CONN_SESSIONTYPE] = "param_key_conn_sessionType";
2085     jsonObject[PARAM_KEY_HML_ENABLE_160M] = true;
2086     jsonObject[PARAM_KEY_HML_ACTIONID] = 0;
2087     authManager_->ParseHmlInfoInJsonObject(jsonObject);
2088 }
2089 
2090 HWTEST_F(DmAuthManagerTest, ParseHmlInfoInJsonObject_001, testing::ext::TestSize.Level1)
2091 {
2092     JsonObject jsonObject;
2093     jsonObject[PARAM_KEY_CONN_SESSIONTYPE] = CONN_SESSION_TYPE_HML;
2094     jsonObject[PARAM_KEY_HML_ACTIONID] = 0;
2095     authManager_->ParseHmlInfoInJsonObject(jsonObject);
2096     ASSERT_EQ(authManager_->authRequestContext_->hmlActionId, 0);
2097 
2098     jsonObject[PARAM_KEY_HML_ACTIONID] = 1;
2099     authManager_->ParseHmlInfoInJsonObject(jsonObject);
2100     ASSERT_EQ(authManager_->authRequestContext_->hmlActionId, 0);
2101 
2102     jsonObject[PARAM_KEY_HML_ACTIONID] = "1";
2103     authManager_->ParseHmlInfoInJsonObject(jsonObject);
2104     ASSERT_EQ(authManager_->authRequestContext_->hmlActionId, 1);
2105 
2106     authManager_->authRequestContext_->hmlActionId = 0;
2107     jsonObject[PARAM_KEY_CONN_SESSIONTYPE] = CONN_SESSION_TYPE_BLE;
2108     jsonObject[PARAM_KEY_HML_ACTIONID] = "1";
2109     authManager_->ParseHmlInfoInJsonObject(jsonObject);
2110     ASSERT_EQ(authManager_->authRequestContext_->hmlActionId, 0);
2111 }
2112 
2113 HWTEST_F(DmAuthManagerTest, CanUsePincodeFromDp_001, testing::ext::TestSize.Level1)
2114 {
2115     DistributedDeviceProfile::LocalServiceInfo info;
2116     info.SetAuthBoxType((int32_t)DMLocalServiceInfoAuthBoxType::SKIP_CONFIRM);
2117     info.SetAuthType((int32_t)DMLocalServiceInfoAuthType::TRUST_ONETIME);
2118     info.SetPinExchangeType((int32_t)DMLocalServiceInfoPinExchangeType::FROMDP);
2119     info.SetPinCode("******");
2120     authManager_->serviceInfoProfile_ = info;
2121     ASSERT_FALSE(authManager_->CanUsePincodeFromDp());
2122 
2123     info.SetPinCode("123456");
2124     authManager_->serviceInfoProfile_ = info;
2125     ASSERT_TRUE(authManager_->CanUsePincodeFromDp());
2126 
2127     info.SetAuthBoxType(INVALID_AUTHBOX_TYPE);
2128     info.SetPinCode("123456");
2129     authManager_->serviceInfoProfile_ = info;
2130     ASSERT_TRUE(authManager_->CanUsePincodeFromDp());
2131 
2132     info.SetPinExchangeType((int32_t)DMLocalServiceInfoPinExchangeType::ULTRASOUND);
2133     info.SetPinCode("123456");
2134     authManager_->serviceInfoProfile_ = info;
2135     ASSERT_FALSE(authManager_->CanUsePincodeFromDp());
2136 }
2137 
2138 HWTEST_F(DmAuthManagerTest, CheckAuthParamVaildExtra_002, testing::ext::TestSize.Level1)
2139 {
2140     JsonObject jsonObject;
2141     jsonObject[PARAM_KEY_CONN_SESSIONTYPE] = CONN_SESSION_TYPE_HML;
2142     jsonObject[PARAM_KEY_HML_ENABLE_160M] = true;
2143     jsonObject[PARAM_KEY_HML_ACTIONID] = "kwjewkkl";
2144     std::string deviceId = "de*************12";
2145     std::shared_ptr<DeviceInfo> deviceInfo = std::make_shared<DeviceInfo>();
2146     authManager_->softbusConnector_->AddMemberToDiscoverMap(deviceId, deviceInfo);
2147     std::string strExtra = jsonObject.Dump();
2148     int32_t ret = authManager_->CheckAuthParamVaildExtra(strExtra, deviceId);
2149     ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
2150 
2151     jsonObject[PARAM_KEY_HML_ACTIONID] = 0;
2152     strExtra = jsonObject.Dump();
2153     ret = authManager_->CheckAuthParamVaildExtra(strExtra, deviceId);
2154     ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
2155 
2156     jsonObject[PARAM_KEY_HML_ACTIONID] = 1;
2157     strExtra = jsonObject.Dump();
2158     ret = authManager_->CheckAuthParamVaildExtra(strExtra, deviceId);
2159     ASSERT_EQ(ret, ERR_DM_INPUT_PARA_INVALID);
2160 
2161     jsonObject[PARAM_KEY_HML_ACTIONID] = "1";
2162     jsonObject[TAG_BIND_LEVEL] = 1;
2163     strExtra = jsonObject.Dump();
2164     EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(true));
2165     ret = authManager_->CheckAuthParamVaildExtra(strExtra, deviceId);
2166     ASSERT_EQ(ret, DM_OK);
2167 
2168     EXPECT_CALL(*appManagerMock_, IsSystemSA()).WillOnce(Return(false));
2169     ret = authManager_->CheckAuthParamVaildExtra(strExtra, deviceId);
2170     ASSERT_EQ(ret, DM_OK);
2171 
2172     std::string pkgName = "pkgName_pickerProxy_Info";
2173     int32_t authType = 1;
2174     std::string extra = "extra";
2175     authManager_->authRequestContext_ = std::make_shared<DmAuthRequestContext>();
2176     EXPECT_CALL(*appManagerMock_, GetNativeTokenIdByName(_, _)).WillOnce(Return(DM_OK));
2177     authManager_->GetAuthParam(pkgName, authType, deviceId, extra);
2178 }
2179 
2180 HWTEST_F(DmAuthManagerTest, CheckHmlParamValid_001, testing::ext::TestSize.Level1)
2181 {
2182     JsonObject jsonObject;
2183     jsonObject[PARAM_KEY_HML_ACTIONID] = 1;
2184     bool ret = authManager_->CheckHmlParamValid(jsonObject);
2185     EXPECT_FALSE(ret);
2186 
2187     jsonObject[PARAM_KEY_HML_ACTIONID] = "kjsdkad";
2188     ret = authManager_->CheckHmlParamValid(jsonObject);
2189     EXPECT_FALSE(ret);
2190 
2191     jsonObject[PARAM_KEY_HML_ACTIONID] = "0";
2192     ret = authManager_->CheckHmlParamValid(jsonObject);
2193     EXPECT_FALSE(ret);
2194 
2195     jsonObject[PARAM_KEY_HML_ACTIONID] = "1";
2196     ret = authManager_->CheckHmlParamValid(jsonObject);
2197     EXPECT_TRUE(ret);
2198 }
2199 } // namespace
2200 } // namespace DistributedHardware
2201 } // namespace OHOS
2202