179a732c7Sopenharmony_ci/* 279a732c7Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 379a732c7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 479a732c7Sopenharmony_ci * you may not use this file except in compliance with the License. 579a732c7Sopenharmony_ci * You may obtain a copy of the License at 679a732c7Sopenharmony_ci * 779a732c7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 879a732c7Sopenharmony_ci * 979a732c7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1079a732c7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1179a732c7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1279a732c7Sopenharmony_ci * See the License for the specific language governing permissions and 1379a732c7Sopenharmony_ci * limitations under the License. 1479a732c7Sopenharmony_ci */ 1579a732c7Sopenharmony_ci 1679a732c7Sopenharmony_ci#include "UTTest_pin_auth.h" 1779a732c7Sopenharmony_ci 1879a732c7Sopenharmony_ci#include <unistd.h> 1979a732c7Sopenharmony_ci#include <memory> 2079a732c7Sopenharmony_ci 2179a732c7Sopenharmony_ci#include "dm_constants.h" 2279a732c7Sopenharmony_ci#include "dm_log.h" 2379a732c7Sopenharmony_ci#include "nlohmann/json.hpp" 2479a732c7Sopenharmony_ci#include "device_manager_service_listener.h" 2579a732c7Sopenharmony_ci 2679a732c7Sopenharmony_cinamespace OHOS { 2779a732c7Sopenharmony_cinamespace DistributedHardware { 2879a732c7Sopenharmony_civoid PinAuthTest::SetUp() 2979a732c7Sopenharmony_ci{ 3079a732c7Sopenharmony_ci} 3179a732c7Sopenharmony_ci 3279a732c7Sopenharmony_civoid PinAuthTest::TearDown() 3379a732c7Sopenharmony_ci{ 3479a732c7Sopenharmony_ci} 3579a732c7Sopenharmony_ci 3679a732c7Sopenharmony_civoid PinAuthTest::SetUpTestCase() 3779a732c7Sopenharmony_ci{ 3879a732c7Sopenharmony_ci} 3979a732c7Sopenharmony_ci 4079a732c7Sopenharmony_civoid PinAuthTest::TearDownTestCase() 4179a732c7Sopenharmony_ci{ 4279a732c7Sopenharmony_ci} 4379a732c7Sopenharmony_ci 4479a732c7Sopenharmony_cinamespace { 4579a732c7Sopenharmony_cistd::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>(); 4679a732c7Sopenharmony_cistd::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>(); 4779a732c7Sopenharmony_cistd::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>(); 4879a732c7Sopenharmony_cistd::shared_ptr<HiChainAuthConnector> hiChainAuthConnector = std::make_shared<HiChainAuthConnector>(); 4979a732c7Sopenharmony_cistd::shared_ptr<DmAuthManager> authManager = 5079a732c7Sopenharmony_ci std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector); 5179a732c7Sopenharmony_ci/** 5279a732c7Sopenharmony_ci * @tc.name: DmAuthManager::ShowAuthInfo_001 5379a732c7Sopenharmony_ci * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED 5479a732c7Sopenharmony_ci * @tc.type: FUNC 5579a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 5679a732c7Sopenharmony_ci */ 5779a732c7Sopenharmony_ciHWTEST_F(PinAuthTest, ShowAuthInfo_001, testing::ext::TestSize.Level0) 5879a732c7Sopenharmony_ci{ 5979a732c7Sopenharmony_ci std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>(); 6079a732c7Sopenharmony_ci std::string authToken = "123456"; 6179a732c7Sopenharmony_ci int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); 6279a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 6379a732c7Sopenharmony_ci} 6479a732c7Sopenharmony_ci 6579a732c7Sopenharmony_ci/** 6679a732c7Sopenharmony_ci * @tc.name: DmAuthManager::ShowAuthInfo_002 6779a732c7Sopenharmony_ci * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED 6879a732c7Sopenharmony_ci * @tc.type: FUNC 6979a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 7079a732c7Sopenharmony_ci */ 7179a732c7Sopenharmony_ciHWTEST_F(PinAuthTest, ShowAuthInfo_002, testing::ext::TestSize.Level0) 7279a732c7Sopenharmony_ci{ 7379a732c7Sopenharmony_ci std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>(); 7479a732c7Sopenharmony_ci nlohmann::json jsonObject; 7579a732c7Sopenharmony_ci jsonObject[PIN_TOKEN] = 123456; 7679a732c7Sopenharmony_ci std::string authToken = jsonObject.dump(); 7779a732c7Sopenharmony_ci int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); 7879a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 7979a732c7Sopenharmony_ci} 8079a732c7Sopenharmony_ci 8179a732c7Sopenharmony_ci/** 8279a732c7Sopenharmony_ci * @tc.name: DmAuthManager::ShowAuthInfo_003 8379a732c7Sopenharmony_ci * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK 8479a732c7Sopenharmony_ci * @tc.type: FUNC 8579a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 8679a732c7Sopenharmony_ci */ 8779a732c7Sopenharmony_ciHWTEST_F(PinAuthTest, ShowAuthInfo_003, testing::ext::TestSize.Level0) 8879a732c7Sopenharmony_ci{ 8979a732c7Sopenharmony_ci std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>(); 9079a732c7Sopenharmony_ci nlohmann::json jsonObject; 9179a732c7Sopenharmony_ci jsonObject[PIN_CODE_KEY] = 123456; 9279a732c7Sopenharmony_ci std::string authToken = jsonObject.dump(); 9379a732c7Sopenharmony_ci int32_t ret = pinAuth->ShowAuthInfo(authToken, nullptr); 9479a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 9579a732c7Sopenharmony_ci} 9679a732c7Sopenharmony_ci 9779a732c7Sopenharmony_ci/** 9879a732c7Sopenharmony_ci * @tc.name: DmAuthManager::ShowAuthInfo_004 9979a732c7Sopenharmony_ci * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK 10079a732c7Sopenharmony_ci * @tc.type: FUNC 10179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 10279a732c7Sopenharmony_ci */ 10379a732c7Sopenharmony_ciHWTEST_F(PinAuthTest, ShowAuthInfo_004, testing::ext::TestSize.Level0) 10479a732c7Sopenharmony_ci{ 10579a732c7Sopenharmony_ci std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>(); 10679a732c7Sopenharmony_ci nlohmann::json jsonObject; 10779a732c7Sopenharmony_ci jsonObject[PIN_CODE_KEY] = 123456; 10879a732c7Sopenharmony_ci std::string authToken = jsonObject.dump(); 10979a732c7Sopenharmony_ci int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager); 11079a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 11179a732c7Sopenharmony_ci} 11279a732c7Sopenharmony_ci 11379a732c7Sopenharmony_ci/** 11479a732c7Sopenharmony_ci * @tc.name: DmAuthManager::StartAuth_001 11579a732c7Sopenharmony_ci * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED 11679a732c7Sopenharmony_ci * @tc.type: FUNC 11779a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 11879a732c7Sopenharmony_ci */ 11979a732c7Sopenharmony_ciHWTEST_F(PinAuthTest, StartAuth_001, testing::ext::TestSize.Level0) 12079a732c7Sopenharmony_ci{ 12179a732c7Sopenharmony_ci std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>(); 12279a732c7Sopenharmony_ci std::string authToken = ""; 12379a732c7Sopenharmony_ci int32_t ret = pinAuth->StartAuth(authToken, nullptr); 12479a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 12579a732c7Sopenharmony_ci} 12679a732c7Sopenharmony_ci 12779a732c7Sopenharmony_ci/** 12879a732c7Sopenharmony_ci * @tc.name: DmAuthManager::StartAuth_002 12979a732c7Sopenharmony_ci * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED 13079a732c7Sopenharmony_ci * @tc.type: FUNC 13179a732c7Sopenharmony_ci * @tc.require: AR000GHSJK 13279a732c7Sopenharmony_ci */ 13379a732c7Sopenharmony_ciHWTEST_F(PinAuthTest, StartAuth_002, testing::ext::TestSize.Level0) 13479a732c7Sopenharmony_ci{ 13579a732c7Sopenharmony_ci std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>(); 13679a732c7Sopenharmony_ci std::string authToken = ""; 13779a732c7Sopenharmony_ci int32_t ret = pinAuth->StartAuth(authToken, authManager); 13879a732c7Sopenharmony_ci ASSERT_EQ(ret, ERR_DM_FAILED); 13979a732c7Sopenharmony_ci} 14079a732c7Sopenharmony_ci} 14179a732c7Sopenharmony_ci} // namespace DistributedHardware 14279a732c7Sopenharmony_ci} // namespace OHOS 143