1 /*
2 * Copyright (c) 2022 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_pin_auth.h"
17
18 #include <unistd.h>
19 #include <memory>
20
21 #include "dm_constants.h"
22 #include "dm_log.h"
23 #include "nlohmann/json.hpp"
24 #include "device_manager_service_listener.h"
25
26 namespace OHOS {
27 namespace DistributedHardware {
SetUp()28 void PinAuthTest::SetUp()
29 {
30 }
31
TearDown()32 void PinAuthTest::TearDown()
33 {
34 }
35
SetUpTestCase()36 void PinAuthTest::SetUpTestCase()
37 {
38 }
39
TearDownTestCase()40 void PinAuthTest::TearDownTestCase()
41 {
42 }
43
44 namespace {
45 std::shared_ptr<DeviceManagerServiceListener> listener = std::make_shared<DeviceManagerServiceListener>();
46 std::shared_ptr<SoftbusConnector> softbusConnector = std::make_shared<SoftbusConnector>();
47 std::shared_ptr<HiChainConnector> hiChainConnector = std::make_shared<HiChainConnector>();
48 std::shared_ptr<HiChainAuthConnector> hiChainAuthConnector = std::make_shared<HiChainAuthConnector>();
49 std::shared_ptr<DmAuthManager> authManager =
50 std::make_shared<DmAuthManager>(softbusConnector, hiChainConnector, listener, hiChainAuthConnector);
51 /**
52 * @tc.name: DmAuthManager::ShowAuthInfo_001
53 * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED
54 * @tc.type: FUNC
55 * @tc.require: AR000GHSJK
56 */
57 HWTEST_F(PinAuthTest, ShowAuthInfo_001, testing::ext::TestSize.Level0)
58 {
59 std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>();
60 std::string authToken = "123456";
61 int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager);
62 ASSERT_EQ(ret, ERR_DM_FAILED);
63 }
64
65 /**
66 * @tc.name: DmAuthManager::ShowAuthInfo_002
67 * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED
68 * @tc.type: FUNC
69 * @tc.require: AR000GHSJK
70 */
71 HWTEST_F(PinAuthTest, ShowAuthInfo_002, testing::ext::TestSize.Level0)
72 {
73 std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>();
74 nlohmann::json jsonObject;
75 jsonObject[PIN_TOKEN] = 123456;
76 std::string authToken = jsonObject.dump();
77 int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager);
78 ASSERT_EQ(ret, ERR_DM_FAILED);
79 }
80
81 /**
82 * @tc.name: DmAuthManager::ShowAuthInfo_003
83 * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK
84 * @tc.type: FUNC
85 * @tc.require: AR000GHSJK
86 */
87 HWTEST_F(PinAuthTest, ShowAuthInfo_003, testing::ext::TestSize.Level0)
88 {
89 std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>();
90 nlohmann::json jsonObject;
91 jsonObject[PIN_CODE_KEY] = 123456;
92 std::string authToken = jsonObject.dump();
93 int32_t ret = pinAuth->ShowAuthInfo(authToken, nullptr);
94 ASSERT_EQ(ret, ERR_DM_FAILED);
95 }
96
97 /**
98 * @tc.name: DmAuthManager::ShowAuthInfo_004
99 * @tc.desc: Call unauthenticateddevice to check whether the return value is DM_OK
100 * @tc.type: FUNC
101 * @tc.require: AR000GHSJK
102 */
103 HWTEST_F(PinAuthTest, ShowAuthInfo_004, testing::ext::TestSize.Level0)
104 {
105 std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>();
106 nlohmann::json jsonObject;
107 jsonObject[PIN_CODE_KEY] = 123456;
108 std::string authToken = jsonObject.dump();
109 int32_t ret = pinAuth->ShowAuthInfo(authToken, authManager);
110 ASSERT_EQ(ret, ERR_DM_FAILED);
111 }
112
113 /**
114 * @tc.name: DmAuthManager::StartAuth_001
115 * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED
116 * @tc.type: FUNC
117 * @tc.require: AR000GHSJK
118 */
119 HWTEST_F(PinAuthTest, StartAuth_001, testing::ext::TestSize.Level0)
120 {
121 std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>();
122 std::string authToken = "";
123 int32_t ret = pinAuth->StartAuth(authToken, nullptr);
124 ASSERT_EQ(ret, ERR_DM_FAILED);
125 }
126
127 /**
128 * @tc.name: DmAuthManager::StartAuth_002
129 * @tc.desc: Call unauthenticateddevice to check whether the return value is ERR_DM_FAILED
130 * @tc.type: FUNC
131 * @tc.require: AR000GHSJK
132 */
133 HWTEST_F(PinAuthTest, StartAuth_002, testing::ext::TestSize.Level0)
134 {
135 std::shared_ptr<PinAuth> pinAuth = std::make_shared<PinAuth>();
136 std::string authToken = "";
137 int32_t ret = pinAuth->StartAuth(authToken, authManager);
138 ASSERT_EQ(ret, ERR_DM_FAILED);
139 }
140 }
141 } // namespace DistributedHardware
142 } // namespace OHOS
143