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