1 /*
2  * Copyright (c) 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 "gtest/gtest.h"
17 
18 #include "iam_executor_iauth_executor_hdi.h"
19 
20 #include "iam_logger.h"
21 #include "iam_ptr.h"
22 
23 using namespace std;
24 using namespace testing;
25 using namespace testing::ext;
26 using namespace OHOS::UserIam;
27 using namespace OHOS::UserIam::Common;
28 using namespace OHOS::UserIam::UserAuth;
29 
30 #define LOG_TAG "USER_AUTH_EXECUTOR_TEST"
31 
32 namespace OHOS {
33 namespace UserIam {
34 namespace UserAuth {
35 class IAuthExecutorHdiTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp();
40     void TearDown();
41 };
42 
SetUpTestCase()43 void IAuthExecutorHdiTest::SetUpTestCase()
44 {
45 }
46 
TearDownTestCase()47 void IAuthExecutorHdiTest::TearDownTestCase()
48 {
49 }
50 
SetUp()51 void IAuthExecutorHdiTest::SetUp()
52 {
53 }
54 
TearDown()55 void IAuthExecutorHdiTest::TearDown()
56 {
57 }
58 
59 class IAuthExecutorHdiMock : public IAuthExecutorHdi {
60 public:
61     ResultCode GetExecutorInfo(ExecutorInfo &info);
62     ResultCode OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
63         const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo);
64     ResultCode Cancel(uint64_t scheduleId);
65     ResultCode SendMessage(uint64_t scheduleId, int32_t srcRole, const std::vector<uint8_t> &msg);
66 };
67 
GetExecutorInfo(ExecutorInfo & info)68 ResultCode IAuthExecutorHdiMock::GetExecutorInfo(ExecutorInfo &info)
69 {
70     IAM_LOGE("method not implemented");
71     return GENERAL_ERROR;
72 }
73 
OnRegisterFinish(const std::vector<uint64_t> & templateIdList,const std::vector<uint8_t> & frameworkPublicKey,const std::vector<uint8_t> & extraInfo)74 ResultCode IAuthExecutorHdiMock::OnRegisterFinish(const std::vector<uint64_t> &templateIdList,
75     const std::vector<uint8_t> &frameworkPublicKey, const std::vector<uint8_t> &extraInfo)
76 {
77     IAM_LOGE("method not implemented");
78     return GENERAL_ERROR;
79 }
80 
Cancel(uint64_t scheduleId)81 ResultCode IAuthExecutorHdiMock::Cancel(uint64_t scheduleId)
82 {
83     IAM_LOGE("method not implemented");
84     return GENERAL_ERROR;
85 }
86 
SendMessage(uint64_t scheduleId,int32_t srcRole,const std::vector<uint8_t> & msg)87 ResultCode IAuthExecutorHdiMock::SendMessage(uint64_t scheduleId, int32_t srcRole,
88     const std::vector<uint8_t> &msg)
89 {
90     IAM_LOGE("method not implemented");
91     return GENERAL_ERROR;
92 }
93 
94 HWTEST_F(IAuthExecutorHdiTest, OnRegisterFinishTest, TestSize.Level0)
95 {
96     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
97     std::vector<uint64_t> templateIdList = {};
98     std::vector<uint8_t> frameworkPublicKey = {};
99     std::vector<uint8_t> extraInfo = {};
100     EXPECT_EQ(authExecutorHdi->OnRegisterFinish(templateIdList, frameworkPublicKey, extraInfo), GENERAL_ERROR);
101 }
102 
103 HWTEST_F(IAuthExecutorHdiTest, CancelTest, TestSize.Level0)
104 {
105     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
106     uint64_t scheduleId = 0;
107     EXPECT_EQ(authExecutorHdi->Cancel(scheduleId), GENERAL_ERROR);
108 }
109 
110 HWTEST_F(IAuthExecutorHdiTest, SendMessageTest, TestSize.Level0)
111 {
112     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
113     uint64_t scheduleId = 0;
114     int32_t srcRole = 1;
115     std::vector<uint8_t> msg = {};
116     EXPECT_EQ(authExecutorHdi->SendMessage(scheduleId, srcRole, msg), GENERAL_ERROR);
117 }
118 
119 HWTEST_F(IAuthExecutorHdiTest, GetExecutorInfoTest, TestSize.Level0)
120 {
121     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
122     ExecutorInfo info = {};
123     EXPECT_EQ(authExecutorHdi->GetExecutorInfo(info), GENERAL_ERROR);
124 }
125 
126 HWTEST_F(IAuthExecutorHdiTest, EnrollTest, TestSize.Level0)
127 {
128     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
129     uint64_t scheduleId = 0;
130     EnrollParam param = {};
131     std::shared_ptr<UserAuth::IExecuteCallback> callbackObj = nullptr;
132     EXPECT_EQ(authExecutorHdi->Enroll(scheduleId, param, callbackObj), GENERAL_ERROR);
133 }
134 
135 HWTEST_F(IAuthExecutorHdiTest, AuthenticateTest, TestSize.Level0)
136 {
137     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
138     uint64_t scheduleId = 0;
139     AuthenticateParam param = {};
140     std::shared_ptr<UserAuth::IExecuteCallback> callbackObj = nullptr;
141     EXPECT_EQ(authExecutorHdi->Authenticate(scheduleId, param, callbackObj), GENERAL_ERROR);
142 }
143 
144 HWTEST_F(IAuthExecutorHdiTest, CollectTest, TestSize.Level0)
145 {
146     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
147     uint64_t scheduleId = 0;
148     CollectParam param = {};
149     std::shared_ptr<UserAuth::IExecuteCallback> callbackObj = nullptr;
150     EXPECT_EQ(authExecutorHdi->Collect(scheduleId, param, callbackObj), GENERAL_ERROR);
151 }
152 
153 HWTEST_F(IAuthExecutorHdiTest, IdentifyTest, TestSize.Level0)
154 {
155     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
156     uint64_t scheduleId = 0;
157     IdentifyParam param = {};
158     std::shared_ptr<UserAuth::IExecuteCallback> callbackObj = nullptr;
159     EXPECT_EQ(authExecutorHdi->Identify(scheduleId, param, callbackObj), GENERAL_ERROR);
160 }
161 
162 HWTEST_F(IAuthExecutorHdiTest, DeleteTest, TestSize.Level0)
163 {
164     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
165     std::vector<uint64_t> templateIdList = {1, 2, 3};
166     EXPECT_EQ(authExecutorHdi->Delete(templateIdList), GENERAL_ERROR);
167 }
168 
169 HWTEST_F(IAuthExecutorHdiTest, SendCommandTest, TestSize.Level0)
170 {
171     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
172     PropertyMode commandId = PROPERTY_INIT_ALGORITHM;
173     std::vector<uint8_t> extraInfo = {1, 2, 3};
174     std::shared_ptr<UserAuth::IExecuteCallback> callbackObj = nullptr;
175     EXPECT_EQ(authExecutorHdi->SendCommand(commandId, extraInfo, callbackObj), GENERAL_ERROR);
176 }
177 
178 HWTEST_F(IAuthExecutorHdiTest, GetPropertyTest, TestSize.Level0)
179 {
180     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
181     std::vector<uint64_t> templateIdList = {0, 1, 2};
182     std::vector<Attributes::AttributeKey> keys = {};
183     Property property = {};
184     EXPECT_EQ(authExecutorHdi->GetProperty(templateIdList, keys, property), GENERAL_ERROR);
185 }
186 
187 HWTEST_F(IAuthExecutorHdiTest, SetCachedTemplatesTest, TestSize.Level0)
188 {
189     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
190     std::vector<uint64_t> templateIdList = {0, 1, 2};
191     EXPECT_EQ(authExecutorHdi->SetCachedTemplates(templateIdList), GENERAL_ERROR);
192 }
193 
194 HWTEST_F(IAuthExecutorHdiTest, NotifyCollectorReadyTest, TestSize.Level0)
195 {
196     auto authExecutorHdi = MakeShared<IAuthExecutorHdiMock>();
197     uint64_t scheduleId = 0;
198     EXPECT_EQ(authExecutorHdi->NotifyCollectorReady(scheduleId), GENERAL_ERROR);
199 }
200 
201 } // namespace UserAuth
202 } // namespace UserIam
203 } // namespace OHOS
204