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