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 #ifndef IAM_MOCK_IUSER_AUTH_INTERFACE_H 16 #define IAM_MOCK_IUSER_AUTH_INTERFACE_H 17 18 #include <memory> 19 #include <mutex> 20 21 #include <gmock/gmock.h> 22 23 #include "singleton.h" 24 25 #include "hdi_wrapper.h" 26 #include "v1_0/iuser_auth_interface.h" 27 28 namespace OHOS { 29 namespace UserIam { 30 namespace UserAuth { 31 class MockIUserAuthInterface final : public HDI::UserAuth::V1_0::IUserAuthInterface { 32 public: 33 using ExecutorRegisterInfo = OHOS::HDI::UserAuth::V1_0::ExecutorRegisterInfo; 34 using EnrollParam = OHOS::HDI::UserAuth::V1_0::EnrollParam; 35 using ScheduleInfo = OHOS::HDI::UserAuth::V1_0::ScheduleInfo; 36 using CredentialInfo = OHOS::HDI::UserAuth::V1_0::CredentialInfo; 37 using EnrolledInfo = OHOS::HDI::UserAuth::V1_0::EnrolledInfo; 38 using AuthType = OHOS::HDI::UserAuth::V1_0::AuthType; 39 using PinSubType = OHOS::HDI::UserAuth::V1_0::PinSubType; 40 using AuthSolution = OHOS::HDI::UserAuth::V1_0::AuthSolution; 41 using AuthResultInfo = OHOS::HDI::UserAuth::V1_0::AuthResultInfo; 42 using IdentifyResultInfo = OHOS::HDI::UserAuth::V1_0::IdentifyResultInfo; 43 using EnrollResultInfo = OHOS::HDI::UserAuth::V1_0::EnrollResultInfo; 44 45 class Holder; 46 MOCK_METHOD0(Init, int32_t()); 47 48 MOCK_METHOD4(AddExecutor, int32_t(const ExecutorRegisterInfo &info, uint64_t &index, 49 std::vector<uint8_t> &publicKey, std::vector<uint64_t> &templateIds)); 50 MOCK_METHOD1(DeleteExecutor, int32_t(uint64_t index)); 51 MOCK_METHOD2(OpenSession, int32_t(int32_t userId, std::vector<uint8_t> &challenge)); 52 MOCK_METHOD1(CloseSession, int32_t(int32_t userId)); 53 MOCK_METHOD4(BeginEnrollment, 54 int32_t(int32_t userId, const std::vector<uint8_t> &authToken, const EnrollParam ¶m, ScheduleInfo &info)); 55 MOCK_METHOD3(UpdateEnrollmentResult, int32_t(int32_t userId, const std::vector<uint8_t> &scheduleResult, 56 EnrollResultInfo &info)); 57 MOCK_METHOD1(CancelEnrollment, int32_t(int32_t userId)); 58 MOCK_METHOD4(DeleteCredential, 59 int32_t(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, CredentialInfo &info)); 60 MOCK_METHOD3(GetCredential, int32_t(int32_t userId, AuthType authType, std::vector<CredentialInfo> &infos)); 61 62 MOCK_METHOD4(GetUserInfo, 63 int32_t(int32_t userId, uint64_t &secureUid, PinSubType &pinSubType, std::vector<EnrolledInfo> &infos)); 64 MOCK_METHOD3(DeleteUser, 65 int32_t(int32_t userId, const std::vector<uint8_t> &authToken, std::vector<CredentialInfo> &deletedInfos)); 66 MOCK_METHOD2(EnforceDeleteUser, int32_t(int32_t userId, std::vector<CredentialInfo> &deletedInfos)); 67 MOCK_METHOD3(BeginAuthentication, 68 int32_t(uint64_t contextId, const AuthSolution ¶m, std::vector<ScheduleInfo> &scheduleInfos)); 69 MOCK_METHOD3(UpdateAuthenticationResult, 70 int32_t(uint64_t contextId, const std::vector<uint8_t> &scheduleResult, AuthResultInfo &info)); 71 MOCK_METHOD1(CancelAuthentication, int32_t(uint64_t contextId)); 72 MOCK_METHOD5(BeginIdentification, 73 int32_t(uint64_t contextId, AuthType authType, const std::vector<uint8_t> &challenge, uint32_t executorId, 74 ScheduleInfo &scheduleInfo)); 75 MOCK_METHOD3(UpdateIdentificationResult, 76 int32_t(uint64_t contextId, const std::vector<uint8_t> &scheduleResult, IdentifyResultInfo &info)); 77 MOCK_METHOD1(CancelIdentification, int32_t(uint64_t contextId)); 78 MOCK_METHOD3(GetAuthTrustLevel, int32_t(int32_t userId, AuthType authType, uint32_t &authTrustLevel)); 79 MOCK_METHOD4(GetValidSolution, int32_t(int32_t userId, const std::vector<AuthType> &authTypes, 80 uint32_t authTrustLevel, std::vector<AuthType> &validTypes)); 81 }; 82 83 class MockIUserAuthInterface::Holder : public Singleton<MockIUserAuthInterface::Holder> { 84 public: 85 void Reset(); 86 std::shared_ptr<MockIUserAuthInterface> Get(); 87 88 private: 89 std::mutex mutex_; 90 std::shared_ptr<MockIUserAuthInterface> mock_; 91 }; 92 } // namespace UserAuth 93 } // namespace UserIam 94 } // namespace OHOS 95 #endif // IAM_MOCK_IUSER_AUTH_INTERFACE_H