diff --git a/CODEOWNERS b/CODEOWNERS index f3c2e07c19a5b209c02f9b79cadc45cb3645f135..51eff843dee5c6e9ffadef23943ba647b204f2c6 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -11,19 +11,29 @@ # See the License for the specific language governing permissions and # limitations under the License. -#any change to frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h @leonchan5 -#any change to frameworks/native/ipc/common_defines/executor_callback_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/executor_callback_interface_ipc_interface_code.h @leonchan5 -#any change to frameworks/native/ipc/common_defines/executor_messenger_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/executor_messenger_interface_ipc_interface_code.h @leonchan5 -#any change to frameworks/native/ipc/common_defines/idm_callback_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/idm_callback_interface_ipc_interface_code.h @leonchan5 -#any change to frameworks/native/ipc/common_defines/idm_get_cred_info_callback_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/idm_get_cred_info_callback_interface_ipc_interface_code.h @leonchan5 -#any change to frameworks/native/ipc/common_defines/idm_get_secure_user_info_callback_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/idm_get_secure_user_info_callback_interface_ipc_interface_code.h @leonchan5 -#any change to frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h @leonchan5 -#any change to frameworks/native/ipc/common_defines/user_idm_interface_ipc_interface_code.h needs to be reviewed by @leonchan5 -frameworks/native/ipc/common_defines/user_idm_interface_ipc_interface_code.h @leonchan5 +#any change to frameworks/native/ipc/idl/ICoAuth.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/ICoAuth.idl +#any change to frameworks/native/ipc/idl/IUserAuth.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IUserAuth.idl +#any change to frameworks/native/ipc/idl/IUserIdm.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IUserIdm.idl +#any change to frameworks/native/ipc/idl/IExecutorCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IExecutorCallback.idl +#any change to frameworks/native/ipc/idl/IExecutorMessenger.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IExecutorMessenger.idl +#any change to frameworks/native/ipc/idl/IGetExecutorPropertyCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IGetExecutorPropertyCallback.idl +#any change to frameworks/native/ipc/idl/IIamCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IIamCallback.idl +#any change to frameworks/native/ipc/idl/IIdmGetCredInfoCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IIdmGetCredInfoCallback.idl +#any change to frameworks/native/ipc/idl/IIdmGetSecureUserInfoCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IIdmGetSecureUserInfoCallback.idl +#any change to frameworks/native/ipc/idl/IModalCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IModalCallback.idl +#any change to frameworks/native/ipc/idl/ISetExecutorPropertyCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/ISetExecutorPropertyCallback.idl +#any change to frameworks/native/ipc/idl/IVerifyTokenCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IVerifyTokenCallback.idl +#any change to frameworks/native/ipc/idl/IWidgetCallback.idl needs to be reviewed by @leonchan5 +frameworks/native/ipc/idl/IWidgetCallback.idl \ No newline at end of file diff --git a/bundle.json b/bundle.json index 275021d07ff072fa6b677455aa13b289cb29cab7..5f75d8c49cfd3d092c6b6bde841d96a4e71796f7 100644 --- a/bundle.json +++ b/bundle.json @@ -67,7 +67,6 @@ "//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_extension/module_loader:user_auth_extension", "//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_extension/module_loader:user_auth_extension_module", "//base/useriam/user_auth_framework/frameworks/js/napi/user_auth_icon:userauthicon", - "//base/useriam/user_auth_framework/frameworks/cj/user_auth:cj_userauth_ffi", "//base/useriam/user_auth_framework/frameworks/js/napi/user_access_ctrl:useraccessctrl" ], "service_group": [ @@ -91,7 +90,6 @@ "user_auth_client.h", "user_auth_client_callback.h", "user_auth_client_defines.h", - "user_auth_event_listener_stub.h", "user_idm_client.h", "user_idm_client_callback.h", "user_idm_client_defines.h" @@ -112,6 +110,13 @@ ], "header_base": "//base/useriam/user_auth_framework/interfaces/inner_api/iam_executor/" } + }, + { + "name": "//base/useriam/user_auth_framework/frameworks/cj/user_auth:cj_userauth_ffi", + "header": { + "header_files": [], + "header_base": "//base/useriam/user_auth_framework/frameworks/cj/user_auth/inc" + } } ], "test": [ diff --git a/common/utils/iam_defines.h b/common/utils/iam_defines.h index 047c8a7fe17ee7669ebd97bab97b05f5b3a92033..f0070027c3fa937300bf142ef91d9d0b48c045ab 100644 --- a/common/utils/iam_defines.h +++ b/common/utils/iam_defines.h @@ -21,7 +21,6 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -const int32_t INVALID_AUTH_TYPE = -1; const int32_t INNER_API_VERSION_10000 = 10000; const int32_t INNER_API_VERSION_20000 = 20000; diff --git a/frameworks/cj/user_auth/BUILD.gn b/frameworks/cj/user_auth/BUILD.gn index be9255bdc326fcad3d8f65ce336c9957f2d06be2..626fb039ef4c372d1b2690cb8adee075c07deb17 100644 --- a/frameworks/cj/user_auth/BUILD.gn +++ b/frameworks/cj/user_auth/BUILD.gn @@ -40,6 +40,7 @@ ohos_shared_library("cj_userauth_ffi") { deps = [ "../../native/client:userauth_client" ] external_deps = [ + "hilog:libhilog", "ipc:ipc_core", "napi:cj_bind_native", ] diff --git a/frameworks/js/napi/user_auth/src/user_auth_callback_v10.cpp b/frameworks/js/napi/user_auth/src/user_auth_callback_v10.cpp index 05059353bf56879e4df947afce67dcae583f35e2..997c54a65c7a71a6c5739a4577b50609d49c8b8e 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_callback_v10.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_callback_v10.cpp @@ -81,7 +81,7 @@ napi_status UserAuthCallbackV10::DoResultCallback(int32_t result, if (resultCallback == nullptr) { return napi_ok; } - IAM_LOGI("start"); + IAM_LOGD("start"); napi_value eventInfo; napi_status ret = napi_create_object(env_, &eventInfo); if (ret != napi_ok) { @@ -102,10 +102,7 @@ napi_status UserAuthCallbackV10::DoResultCallback(int32_t result, } } - if (authType == AuthType::PIN || - authType == AuthType::FACE || - authType == AuthType::FINGERPRINT || - authType == AuthType::PRIVATE_PIN) { + if (UserAuthNapiHelper::CheckUserAuthType(authType)) { ret = UserAuthNapiHelper::SetInt32Property(env_, eventInfo, "authType", authType); if (ret != napi_ok) { IAM_LOGE("napi_create_int32 failed %{public}d", ret); @@ -129,7 +126,7 @@ void UserAuthCallbackV10::OnAcquireInfo(int32_t module, uint32_t acquireInfo, void UserAuthCallbackV10::OnResult(int32_t result, const Attributes &extraInfo) { - IAM_LOGI("start, result:%{public}d", result); + IAM_LOGD("start, result:%{public}d", result); uv_loop_s *loop; napi_status napiStatus = napi_get_uv_event_loop(env_, &loop); if (napiStatus != napi_ok || loop == nullptr) { @@ -158,7 +155,7 @@ void UserAuthCallbackV10::OnResult(int32_t result, const Attributes &extraInfo) } IAM_LOGI("result token size: %{public}zu.", resultHolder->token.size()); auto task = [resultHolder] () { - IAM_LOGI("start"); + IAM_LOGD("start"); if (resultHolder == nullptr || resultHolder->callback == nullptr) { IAM_LOGE("resultHolder is invalid"); return; diff --git a/frameworks/js/napi/user_auth/src/user_auth_entry.cpp b/frameworks/js/napi/user_auth/src/user_auth_entry.cpp index 1cf9c0aeb4774287426a98a63595492567be241a..68cc763b4cc02f5c23906586658e2092b0021182 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_entry.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_entry.cpp @@ -448,7 +448,7 @@ static bool VerifyNoticeParam(const std::string &eventData) IAM_LOGE("Invalid payload exist in notice data"); return false; } - IAM_LOGI("valid notice parameter"); + IAM_LOGD("valid notice parameter"); return true; } @@ -486,7 +486,6 @@ napi_value SendNotice(napi_env env, napi_callback_info info) napi_throw(env, UserAuthNapiHelper::GenerateErrorMsg(env, UserAuthResultCode::OHOS_INVALID_PARAM, msgStr)); return nullptr; } - IAM_LOGI("recv SendNotice noticeType:%{public}d", noticeType_value); if (noticeType_value != WIDGET_NOTICE) { std::string msgStr = "Parameter error. The value of \"noticeType\" must be NoticeType.WIDGET_NOTICE."; @@ -495,7 +494,7 @@ napi_value SendNotice(napi_env env, napi_callback_info info) } std::string eventData = UserAuthNapiHelper::GetStringFromValueUtf8(env, argv[PARAM1]); - IAM_LOGI("recv SendNotice eventData:%{public}s", eventData.c_str()); + IAM_LOGI("recv SendNotice type:%{public}d, eventData:%{public}s", noticeType_value, eventData.c_str()); if (!VerifyNoticeParam(eventData)) { IAM_LOGE("Invalid notice parameter"); std::string msgStr = "Parameter error. The value of \"eventData\" for WIDGET_NOTICE must be json string."; @@ -509,7 +508,7 @@ napi_value SendNotice(napi_env env, napi_callback_info info) IAM_LOGE("SendNotice fail. result: %{public}d, errCode: %{public}d", result, errCode); return ResultOfSendNotice(env, errCode); } - IAM_LOGI("end SendNotice"); + IAM_LOGD("end SendNotice"); return nullptr; } @@ -611,7 +610,7 @@ napi_value GetUserAuthWidgetMgrV10(napi_env env, napi_callback_info info) napi_throw(env, UserAuthNapiHelper::GenerateBusinessErrorV9(env, code)); return nullptr; } - IAM_LOGI("end"); + IAM_LOGD("end"); return userAuthWidgetMgrV10; } diff --git a/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp b/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp index a2d854ec8ef772f0bbb185870a72286eafd70b6e..fe98418dfe7f30ed6994655d5de39175242e0e20 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_instance_v10.cpp @@ -90,7 +90,7 @@ napi_value UserAuthInstanceV10::GetEnrolledState(napi_env env, napi_callback_inf napi_value UserAuthInstanceV10::DoGetEnrolledStateResult(napi_env env, EnrolledState enrolledState) { - IAM_LOGI("start"); + IAM_LOGD("start"); napi_value eventInfo; napi_status ret = napi_create_object(env, &eventInfo); if (ret != napi_ok) { @@ -114,7 +114,7 @@ napi_value UserAuthInstanceV10::DoGetEnrolledStateResult(napi_env env, EnrolledS napi_throw(env, UserAuthNapiHelper::GenerateBusinessErrorV9(env, UserAuthResultCode::GENERAL_ERROR)); return nullptr; } - IAM_LOGI("get enrolled state end"); + IAM_LOGD("get enrolled state end"); return eventInfo; } diff --git a/frameworks/js/napi/user_auth/src/user_auth_modal_callback.cpp b/frameworks/js/napi/user_auth/src/user_auth_modal_callback.cpp index 2fc3af5db59ce0c4186450fc5090056078da729a..c0dc2c9658ea032f7062475487e19581e3e8cebe 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_modal_callback.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_modal_callback.cpp @@ -72,14 +72,14 @@ void UserAuthModalCallback::SendCommand(uint64_t contextId, const std::string &c bool UserAuthModalCallback::IsModalInit() { - IAM_LOGI("get is modal init"); + IAM_LOGD("get is modal init"); std::lock_guard lock(mutex_); return isInit_; } bool UserAuthModalCallback::IsModalDestroy() { - IAM_LOGI("get is modal on destroy"); + IAM_LOGD("get is modal on destroy"); std::lock_guard lock(mutex_); if (isInitError_ || (uiExtCallback_ != nullptr && uiExtCallback_->IsModalDestroy())) { IAM_LOGI("modal on destroy"); diff --git a/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp b/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp index 0c315c92c86def0076a52d425bc93e373dd6d1ec..e20742303e99df69ba7fe6dc0228c61dfa115bba 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_napi_helper.cpp @@ -81,7 +81,7 @@ JsRefHolder::~JsRefHolder() IAM_LOGI("invalid"); return; } - IAM_LOGI("delete reference"); + IAM_LOGD("delete reference"); uv_loop_s *loop; napi_status napiStatus = napi_get_uv_event_loop(env_, &loop); if (napiStatus != napi_ok || loop == nullptr) { @@ -572,8 +572,9 @@ bool UserAuthNapiHelper::CheckAuthType(int32_t authType) bool UserAuthNapiHelper::CheckUserAuthType(int32_t authType) { - if (authType != AuthType::PIN && authType != AuthType::FACE && - authType != AuthType::FINGERPRINT && authType != AuthType::PRIVATE_PIN) { + const std::set WIDGET_AUTH_TYPE_VALID_SET = {AuthType::PIN, AuthType::FACE, AuthType::FINGERPRINT, + AuthType::PRIVATE_PIN}; + if (WIDGET_AUTH_TYPE_VALID_SET.find(static_cast(authType)) == WIDGET_AUTH_TYPE_VALID_SET.end()) { IAM_LOGE("authType check fail:%{public}d", authType); return false; } diff --git a/frameworks/js/napi/user_auth/src/user_auth_widget_callback_v10.cpp b/frameworks/js/napi/user_auth/src/user_auth_widget_callback_v10.cpp index 017a7137e2867b3a6dae63ea0d6b38df6445b05d..28f0cf4932f2d03c6dcc58080eb5d446dc47cb3a 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_widget_callback_v10.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_widget_callback_v10.cpp @@ -76,7 +76,7 @@ napi_status UserAuthWidgetCallback::DoCommandCallback(const std::string &cmdData if (commandCallback == nullptr) { return napi_ok; } - IAM_LOGI("start"); + IAM_LOGD("start"); napi_value eventInfo = nullptr; napi_status ret = napi_create_string_utf8(env_, cmdData.c_str(), cmdData.size(), &eventInfo); if (ret != napi_ok) { @@ -88,7 +88,7 @@ napi_status UserAuthWidgetCallback::DoCommandCallback(const std::string &cmdData void UserAuthWidgetCallback::SendCommand(const std::string &cmdData) { - IAM_LOGI("start"); + IAM_LOGD("start"); uv_loop_s *loop; napi_status napiStatus = napi_get_uv_event_loop(env_, &loop); if (napiStatus != napi_ok || loop == nullptr) { diff --git a/frameworks/js/napi/user_auth/src/user_auth_widget_mgr_v10.cpp b/frameworks/js/napi/user_auth/src/user_auth_widget_mgr_v10.cpp index c14dc4e48ad166b5a6fb5a1be43fece17b1bb0ca..7162af88bf034cbe0ef83fdba698a2d4ab75839e 100644 --- a/frameworks/js/napi/user_auth/src/user_auth_widget_mgr_v10.cpp +++ b/frameworks/js/napi/user_auth/src/user_auth_widget_mgr_v10.cpp @@ -72,7 +72,7 @@ UserAuthResultCode UserAuthWidgetMgr::Init(napi_env env, napi_callback_info info } version_ = version; int32_t result = UserAuthClientImpl::Instance().SetWidgetCallback(version_, callback_); - IAM_LOGI("version SetWidgetCallback result: %{public}d", result); + IAM_LOGD("version SetWidgetCallback result: %{public}d", result); return static_cast(UserAuthNapiHelper::GetResultCodeV10(result)); } diff --git a/frameworks/js/napi/user_auth_extension/module_loader/js_user_auth_extension.cpp b/frameworks/js/napi/user_auth_extension/module_loader/js_user_auth_extension.cpp index 65910f62d3eb75f0bbf9ed114e968529bd71a694..7ffe1e322896d8d80989126104af47a738f9a95c 100644 --- a/frameworks/js/napi/user_auth_extension/module_loader/js_user_auth_extension.cpp +++ b/frameworks/js/napi/user_auth_extension/module_loader/js_user_auth_extension.cpp @@ -31,14 +31,14 @@ JsUserAuthExtension *JsUserAuthExtension::Create(const std::unique_ptr JsUserAuthExtension::JsUserAuthExtension(const std::unique_ptr &runtime) { - IAM_LOGI("JsUserAuthExtension constructor."); + IAM_LOGD("JsUserAuthExtension constructor."); auto uiExtensionBaseImpl = std::make_shared(runtime); SetUIExtensionBaseImpl(std::move(uiExtensionBaseImpl)); } JsUserAuthExtension::~JsUserAuthExtension() { - IAM_LOGI("JsUserAuthExtension destructor."); + IAM_LOGD("JsUserAuthExtension destructor."); } } } diff --git a/frameworks/js/napi/user_auth_icon/user_auth_icon.js b/frameworks/js/napi/user_auth_icon/user_auth_icon.js index a4be1a3ee5c7e84b0d1282e4e9e11d1194d53fd8..1017d90357d5025c1ffd91d7432c3938b44c2799 100644 --- a/frameworks/js/napi/user_auth_icon/user_auth_icon.js +++ b/frameworks/js/napi/user_auth_icon/user_auth_icon.js @@ -174,6 +174,45 @@ export class UserAuthIcon extends ViewPU { this.initImageSource(this.authParam.authType, this.authParam.authTrustLevel); this.info(`after init image source, imageSource = ${this.imageSource}.`); } + onclick() { + this.info('start handle click event.'); + if (this.onIconClick !== undefined) { + this.info('click event has response.'); + this.onIconClick(); + } + if (this.authFlag === ICON_AVAILABLE) { + try { + let b = userAuth.getUserAuthInstance(this.authParam, this.widgetParam); + let h1 = setTimeout(() => { + this.error('auth timeout.'); + b.cancel(); + this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); + }, TIMEOUT_MILLISECONDS); + this.info('get userAuth instance success.'); + b.on('result', { + onResult: (m1) => { + this.info(`userAuthInstance callback result = ${JSON.stringify(m1)}.`); + this.onAuthResult(m1); + b.off('result'); + } + }); + this.info('auth before start.'); + b.start(); + this.info('auth start success.'); + clearTimeout(h1); + } + catch (a) { + if (a) { + this.error(`auth catch error, code: ${a.code}, message: ${a.message}`); + this.onAuthResult({ result: a.code }); + return; + } + this.error('auth error.'); + this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); + } + } + this.info('end handle click event.'); + } initialRender() { this.observeComponentCreation2((n, o) => { Row.create(); @@ -185,45 +224,7 @@ export class UserAuthIcon extends ViewPU { SymbolGlyph.create({ 'id': -1, 'type': -1, params: [this.imageSource], 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); SymbolGlyph.fontSize(this.iconHeight); SymbolGlyph.fontColor([this.iconColor]); - SymbolGlyph.onClick(() => { - this.info('start handle click event.'); - if (this.onIconClick !== undefined) { - this.info('click event has response.'); - this.onIconClick(); - } - if (this.authFlag === ICON_AVAILABLE) { - try { - let h = userAuth.getUserAuthInstance(this.authParam, this.widgetParam); - let i = setTimeout(() => { - this.error('auth timeout.'); - h.cancel(); - this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); - }, TIMEOUT_MILLISECONDS); - this.info('get userAuth instance success.'); - h.on('result', { - onResult: (k) => { - this.info(`userAuthInstance callback result = ${JSON.stringify(k)}.`); - this.onAuthResult(k); - h.off('result'); - } - }); - this.info('auth before start.'); - h.start(); - this.info('auth start success.'); - clearTimeout(i); - } - catch (g) { - if (g) { - this.error(`auth catch error, code: ${g.code}, message: ${g.message}`); - this.onAuthResult({ result: g.code }); - return; - } - this.error('auth error.'); - this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); - } - } - this.info('end handle click event.'); - }); + SymbolGlyph.onClick(() => this.onclick()); }, SymbolGlyph); Column.pop(); Row.pop(); diff --git a/frameworks/native/client/BUILD.gn b/frameworks/native/client/BUILD.gn index 35a72af0e0208bb479121a93804e4f39d2d50979..e1f9e88c194e39f24f69b015909ce16602a8970c 100644 --- a/frameworks/native/client/BUILD.gn +++ b/frameworks/native/client/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("userauth_client") { "src/auth_message_impl.cpp", "src/callback_manager_impl.cpp", "src/co_auth_client_impl.cpp", + "src/event_listener_callback_service.cpp", "src/executor_callback_service.cpp", "src/executor_messenger_client.cpp", "src/ipc_client_utils.cpp", diff --git a/frameworks/native/client/inc/co_auth_client_impl.h b/frameworks/native/client/inc/co_auth_client_impl.h index 5de313555fc3cf96fde46be94ea182915e6a9d57..9b2b8386012fa8f2deac82378a033b40130e2829 100644 --- a/frameworks/native/client/inc/co_auth_client_impl.h +++ b/frameworks/native/client/inc/co_auth_client_impl.h @@ -20,8 +20,10 @@ #include "nocopyable.h" +#include "ico_auth.h" #include "co_auth_client.h" #include "co_auth_interface.h" +#include "user_auth_types.h" namespace OHOS { namespace UserIam { @@ -36,6 +38,7 @@ private: CoAuthClientImpl() = default; ~CoAuthClientImpl() override = default; static CoAuthClientImpl &Instance(); + void InitIpcExecutorInfo(const ExecutorInfo &info, IpcExecutorRegisterInfo &ipcExecutorRegisterInfo); class CoAuthImplDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable { public: CoAuthImplDeathRecipient() = default; @@ -43,8 +46,8 @@ private: void OnRemoteDied(const wptr &remote) override; }; void ResetProxy(const wptr &remote); - sptr GetProxy(); - sptr proxy_ {nullptr}; + sptr GetProxy(); + sptr proxy_ {nullptr}; sptr deathRecipient_ {nullptr}; std::mutex mutex_; }; diff --git a/frameworks/native/client/inc/event_listener_callback_service.h b/frameworks/native/client/inc/event_listener_callback_service.h new file mode 100644 index 0000000000000000000000000000000000000000..2d8bb023b146ec4e3ffe39f65a2a5be257f3d772 --- /dev/null +++ b/frameworks/native/client/inc/event_listener_callback_service.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef EVENT_LISTENER_CALLBACK_SERVICE_H +#define EVENT_LISTENER_CALLBACK_SERVICE_H + +#include +#include +#include + +#include "event_listener_callback_stub.h" +#include "iuser_auth.h" +#include "iuser_idm.h" +#include "user_auth_client_callback.h" +#include "user_idm_client_callback.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class EventListenerCallbackManager { +public: + static EventListenerCallbackManager &GetInstance(); + int32_t AddUserAuthSuccessEventListener(const sptr &proxy, const std::vector &authTypes, + const std::shared_ptr &listener); + int32_t RemoveUserAuthSuccessEventListener(const sptr &proxy, + const std::shared_ptr &listener); + int32_t AddCredChangeEventListener(const sptr &proxy, const std::vector &authTypes, + const std::shared_ptr &listener); + int32_t RemoveCredChangeEventListener(const sptr &proxy, + const std::shared_ptr &listener); + void OnServiceDeath(); + +protected: + std::set> GetAuthEventListenerSet(AuthType authType); + std::set> GetCredEventListenerSet(AuthType authType); + +private: + class EventListenerCallbackImpl : public EventListenerCallbackStub { + public: + explicit EventListenerCallbackImpl() = default; + ~EventListenerCallbackImpl() override = default; + + int32_t OnNotifyAuthSuccessEvent(int32_t userId, int32_t authType, int32_t callerType, + const std::string &callerName) override; + int32_t OnNotifyCredChangeEvent(int32_t userId, int32_t authType, int32_t eventType, + uint64_t credentialId) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; + }; + + EventListenerCallbackManager() = default; + ~EventListenerCallbackManager() = default; + sptr authEventListenerCallbackImpl_ = nullptr; + sptr credEventListenerCallbackImpl_ = nullptr; + std::recursive_mutex eventListenerMutex_; + std::map>> authEventListenerMap_ = {}; + std::map>> credEventListenerMap_ = {}; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // EVENT_LISTENER_CALLBACK_SERVICE_H diff --git a/frameworks/native/client/inc/executor_callback_service.h b/frameworks/native/client/inc/executor_callback_service.h index a009d16727d569225a58e9cb0ab6ba388fb4750c..8e4b7aef1463500b1751a33392d2f9e99978e453 100644 --- a/frameworks/native/client/inc/executor_callback_service.h +++ b/frameworks/native/client/inc/executor_callback_service.h @@ -27,15 +27,16 @@ class ExecutorCallbackService : public ExecutorCallbackStub { public: explicit ExecutorCallbackService(const std::shared_ptr &impl); ~ExecutorCallbackService() override = default; - void OnMessengerReady(sptr &messenger, + int32_t OnMessengerReady(const sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) override; int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) override; - int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) override; - int32_t OnSetProperty(const Attributes &properties) override; - int32_t OnGetProperty(const Attributes &condition, Attributes &values) override; - int32_t OnSendData(uint64_t scheduleId, const Attributes &data) override; - + const std::vector &command) override; + int32_t OnEndExecute(uint64_t scheduleId, const std::vector &command) override; + int32_t OnSetProperty(const std::vector &properties) override; + int32_t OnGetProperty(const std::vector &condition, std::vector &values) override; + int32_t OnSendData(uint64_t scheduleId, const std::vector &extraInfo) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr callback_ {nullptr}; }; diff --git a/frameworks/native/client/inc/executor_messenger_client.h b/frameworks/native/client/inc/executor_messenger_client.h index ead15fbb7ff0f97ab84758525c2d28378d3fa8ac..92ef2e7905e4c9bc75379310d9890df5dd80a77c 100644 --- a/frameworks/native/client/inc/executor_messenger_client.h +++ b/frameworks/native/client/inc/executor_messenger_client.h @@ -17,20 +17,20 @@ #define EXECUTOR_MESSENGER_CLIENT_H #include "co_auth_client_defines.h" -#include "executor_messenger_interface.h" +#include "iexecutor_messenger.h" namespace OHOS { namespace UserIam { namespace UserAuth { class ExecutorMessengerClient final : public ExecutorMessenger { public: - explicit ExecutorMessengerClient(const sptr &messenger); + explicit ExecutorMessengerClient(const sptr &messenger); int32_t SendData(uint64_t scheduleId, ExecutorRole dstRole, const std::shared_ptr &msg) override; int32_t Finish(uint64_t scheduleId, int32_t resultCode, const Attributes &finalResult) override; private: - sptr messenger_ {nullptr}; + sptr messenger_ {nullptr}; }; } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/inc/modal_callback_service.h b/frameworks/native/client/inc/modal_callback_service.h index e42dd14875035a27de1fd4cec014dfeaf1fb833d..760e40a137cb06cdbed5706c555510e0206bfdaf 100644 --- a/frameworks/native/client/inc/modal_callback_service.h +++ b/frameworks/native/client/inc/modal_callback_service.h @@ -28,7 +28,9 @@ class ModalCallbackService : public ModalCallbackStub { public: explicit ModalCallbackService(const std::shared_ptr &impl); ~ModalCallbackService() override; - void SendCommand(uint64_t contextId, const std::string &cmdData) override; + int32_t SendCommand(uint64_t contextId, const std::string &cmdData) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr modalCallback_ {nullptr}; diff --git a/frameworks/native/client/inc/user_access_ctrl_callback_service.h b/frameworks/native/client/inc/user_access_ctrl_callback_service.h index 7781ef4fab5e060f2e747c1cedaac396fd74e27f..f6acf0ed4f965788f7ddfa3d6e50c41b51a4c50c 100644 --- a/frameworks/native/client/inc/user_access_ctrl_callback_service.h +++ b/frameworks/native/client/inc/user_access_ctrl_callback_service.h @@ -16,7 +16,7 @@ #ifndef USER_ACCESS_CTRL_CALLBACK_SERVICE_H #define USER_ACCESS_CTRL_CALLBACK_SERVICE_H -#include "user_access_ctrl_callback_stub.h" +#include "verify_token_callback_stub.h" #include "iam_hitrace_helper.h" #include "user_access_ctrl_client_callback.h" @@ -28,7 +28,9 @@ class VerifyTokenCallbackService : public VerifyTokenCallbackStub { public: explicit VerifyTokenCallbackService(const std::shared_ptr &impl); ~VerifyTokenCallbackService() override; - void OnVerifyTokenResult(int32_t result, const Attributes &attributes) override; + int32_t OnVerifyTokenResult(int32_t resultCode, const std::vector &extraInfo) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr verifyTokenCallback_ {nullptr}; diff --git a/frameworks/native/client/inc/user_access_ctrl_client_impl.h b/frameworks/native/client/inc/user_access_ctrl_client_impl.h index 3a975ef26fbf4d0b69a4daff2385a7deb3bf307f..1825880c5f76015da1c369210ec21303cc7adf10 100644 --- a/frameworks/native/client/inc/user_access_ctrl_client_impl.h +++ b/frameworks/native/client/inc/user_access_ctrl_client_impl.h @@ -21,7 +21,7 @@ #include "nocopyable.h" #include "user_access_ctrl_client.h" -#include "user_auth_interface.h" +#include "iuser_auth.h" namespace OHOS { namespace UserIam { @@ -43,8 +43,8 @@ private: void OnRemoteDied(const wptr &remote) override; }; void ResetProxy(const wptr &remote); - sptr GetProxy(); - sptr proxy_ {nullptr}; + sptr GetProxy(); + sptr proxy_ {nullptr}; sptr deathRecipient_ {nullptr}; std::mutex mutex_; }; diff --git a/frameworks/native/client/inc/user_auth_callback_service.h b/frameworks/native/client/inc/user_auth_callback_service.h index 3cce995c256ec2d79b0d3bf9177d86e6b5115978..9b8a96a3820d581f2cf7bcbd523d1a956c39c724 100644 --- a/frameworks/native/client/inc/user_auth_callback_service.h +++ b/frameworks/native/client/inc/user_auth_callback_service.h @@ -16,16 +16,18 @@ #ifndef USER_AUTH_CALLBACK_SERVICE_H #define USER_AUTH_CALLBACK_SERVICE_H -#include "user_auth_callback_stub.h" +#include "iam_callback_stub.h" #include "iam_hitrace_helper.h" +#include "get_executor_property_callback_stub.h" +#include "set_executor_property_callback_stub.h" #include "user_auth_client_callback.h" #include "user_auth_modal_client_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class UserAuthCallbackService : public UserAuthCallbackStub { +class UserAuthCallbackService : public IamCallbackStub { public: explicit UserAuthCallbackService(const std::shared_ptr &impl); explicit UserAuthCallbackService(const std::shared_ptr &impl, @@ -33,8 +35,10 @@ public: explicit UserAuthCallbackService(const std::shared_ptr &impl); explicit UserAuthCallbackService(const std::shared_ptr &impl); ~UserAuthCallbackService() override; - void OnResult(int32_t result, const Attributes &extraInfo) override; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; + int32_t OnResult(int32_t resultCode, const std::vector &extraInfo) override; + int32_t OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr authCallback_ {nullptr}; @@ -48,7 +52,9 @@ class GetExecutorPropertyCallbackService : public GetExecutorPropertyCallbackStu public: explicit GetExecutorPropertyCallbackService(const std::shared_ptr &impl); ~GetExecutorPropertyCallbackService() override; - void OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes) override; + int32_t OnGetExecutorPropertyResult(int32_t resultCode, const std::vector &attributes) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr getPropCallback_ {nullptr}; @@ -58,7 +64,9 @@ class SetExecutorPropertyCallbackService : public SetExecutorPropertyCallbackStu public: explicit SetExecutorPropertyCallbackService(const std::shared_ptr &impl); ~SetExecutorPropertyCallbackService() override; - void OnSetExecutorPropertyResult(int32_t result) override; + int32_t OnSetExecutorPropertyResult(int32_t resultCode) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr setPropCallback_ {nullptr}; diff --git a/frameworks/native/client/inc/user_auth_client_impl.h b/frameworks/native/client/inc/user_auth_client_impl.h index c523140ed5f7b9019b8ea4954e9996f78e9b5691..4f5ec6d701173fcebc9fc4012ba62257e6829c30 100644 --- a/frameworks/native/client/inc/user_auth_client_impl.h +++ b/frameworks/native/client/inc/user_auth_client_impl.h @@ -21,9 +21,12 @@ #include "nocopyable.h" -#include "user_auth_client.h" -#include "user_auth_interface.h" +#include "event_listener_callback_service.h" +#include "iuser_auth.h" #include "iuser_auth_widget_callback.h" +#include "user_auth_client.h" +#include "user_auth_types.h" +#include "user_auth_common_defines.h" namespace OHOS { namespace UserIam { @@ -56,10 +59,10 @@ public: int32_t SetWidgetCallback(int32_t version, const std::shared_ptr &callback); int32_t Notice(NoticeType noticeType, const std::string &eventData); int32_t GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState); - int32_t RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) override; + int32_t RegistUserAuthSuccessEventListener(const std::vector &authTypes, + const std::shared_ptr &listener) override; int32_t UnRegistUserAuthSuccessEventListener( - const sptr &listener) override; + const std::shared_ptr &listener) override; int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) override; int32_t PrepareRemoteAuth(const std::string &networkId, const std::shared_ptr &callback) override; @@ -69,6 +72,12 @@ private: const std::shared_ptr &callback); uint64_t BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParamInner &widgetParam, const std::shared_ptr &callback); + void InitIpcRemoteAuthParam(const std::optional &remoteAuthParam, + IpcRemoteAuthParam &ipcRemoteAuthParam); + void InitIpcGlobalConfigParam(const GlobalConfigParam &globalConfigParam, + IpcGlobalConfigParam &ipcGlobalConfigParam); + void InitIpcAuthParam(const AuthParamInner &authParam, IpcAuthParamInner &ipcAuthParam); + void InitIpcWidgetParam(const WidgetParamInner &widgetParam, IpcWidgetParamInner &ipcWidgetParam); friend class UserAuthClient; UserAuthClientImpl() = default; @@ -80,8 +89,8 @@ private: void OnRemoteDied(const wptr &remote) override; }; void ResetProxy(const wptr &remote); - sptr GetProxy(); - sptr proxy_ {nullptr}; + sptr GetProxy(); + sptr proxy_ {nullptr}; sptr deathRecipient_ {nullptr}; constexpr static int32_t MINIMUM_VERSION {0}; std::mutex mutex_; diff --git a/frameworks/native/client/inc/user_auth_napi_client_impl.h b/frameworks/native/client/inc/user_auth_napi_client_impl.h index 9c01cbfc8bb0124832c54d077db381590834e3db..78f4287961b21f74dc9e4d01c3619f473de2f6e3 100644 --- a/frameworks/native/client/inc/user_auth_napi_client_impl.h +++ b/frameworks/native/client/inc/user_auth_napi_client_impl.h @@ -22,8 +22,10 @@ #include "user_auth_client_callback.h" #include "user_auth_client_defines.h" -#include "user_auth_interface.h" +#include "iuser_auth.h" #include "user_auth_modal_client_callback.h" +#include "user_auth_types.h" +#include "user_auth_common_defines.h" namespace OHOS { namespace UserIam { @@ -54,6 +56,8 @@ private: uint64_t BeginWidgetAuthInner(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParamInner &widgetParam, const std::shared_ptr &callback, const std::shared_ptr &modalCallback); + void InitIpcAuthParam(const AuthParamInner &authParam, IpcAuthParamInner &ipcWidgetParamInner); + void InitIpcWidgetParam(const WidgetParamInner &widgetParam, IpcWidgetParamInner &ipcWidgetParamInner); UserAuthNapiClientImpl() = default; ~UserAuthNapiClientImpl() override = default; @@ -64,8 +68,8 @@ private: void OnRemoteDied(const wptr &remote) override; }; void ResetProxy(const wptr &remote); - sptr GetProxy(); - sptr proxy_ {nullptr}; + sptr GetProxy(); + sptr proxy_ {nullptr}; sptr deathRecipient_ {nullptr}; constexpr static int32_t MINIMUM_VERSION {0}; std::mutex mutex_; diff --git a/frameworks/native/client/inc/user_idm_callback_service.h b/frameworks/native/client/inc/user_idm_callback_service.h index 7ab73c7da218b13f3fa558f2143ddf49ff62f219..5e9b5966128f508ff08fdb9b393cf5e98f006df0 100644 --- a/frameworks/native/client/inc/user_idm_callback_service.h +++ b/frameworks/native/client/inc/user_idm_callback_service.h @@ -16,7 +16,9 @@ #ifndef USER_IDM_CALLBACK_SERVICE_H #define USER_IDM_CALLBACK_SERVICE_H -#include "user_idm_callback_stub.h" +#include "iam_callback_stub.h" +#include "idm_get_cred_info_callback_stub.h" +#include "idm_get_secure_user_info_callback_stub.h" #include "iam_hitrace_helper.h" #include "user_idm_client_callback.h" @@ -24,12 +26,14 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -class IdmCallbackService : public IdmCallbackStub { +class IdmCallbackService : public IamCallbackStub { public: explicit IdmCallbackService(const std::shared_ptr &impl); ~IdmCallbackService() override; - void OnResult(int32_t result, const Attributes &extraInfo) override; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; + int32_t OnResult(int32_t resultCode, const std::vector &extraInfo) override; + int32_t OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr idmClientCallback_ {nullptr}; @@ -40,7 +44,9 @@ class IdmGetCredInfoCallbackService : public IdmGetCredInfoCallbackStub { public: explicit IdmGetCredInfoCallbackService(const std::shared_ptr &impl); ~IdmGetCredInfoCallbackService() override; - void OnCredentialInfos(int32_t result, const std::vector &credInfoList) override; + int32_t OnCredentialInfos(int32_t resultCode, const std::vector &credInfoList) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr getCredInfoCallback_ {nullptr}; @@ -50,7 +56,9 @@ class IdmGetSecureUserInfoCallbackService : public IdmGetSecureUserInfoCallbackS public: explicit IdmGetSecureUserInfoCallbackService(const std::shared_ptr &impl); ~IdmGetSecureUserInfoCallbackService() override; - void OnSecureUserInfo(int32_t result, const SecUserInfo &secUserInfo) override; + int32_t OnSecureUserInfo(int32_t resultCode, const IpcSecUserInfo &ipcSecUserInfo) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr getSecInfoCallback_ {nullptr}; diff --git a/frameworks/native/client/inc/user_idm_client_impl.h b/frameworks/native/client/inc/user_idm_client_impl.h index 7fa3f0c552211ff72e0460fff324d414acd8cf88..0ff41dcd67a200be4d9806133eda19f6002f53ff 100644 --- a/frameworks/native/client/inc/user_idm_client_impl.h +++ b/frameworks/native/client/inc/user_idm_client_impl.h @@ -20,8 +20,10 @@ #include "nocopyable.h" +#include "event_listener_callback_service.h" +#include "iuser_idm.h" +#include "user_auth_types.h" #include "user_idm_client.h" -#include "user_idm_interface.h" namespace OHOS { namespace UserIam { @@ -44,6 +46,12 @@ public: const std::shared_ptr &callback) override; int32_t GetSecUserInfo(int32_t userId, const std::shared_ptr &callback) override; void ClearRedundancyCredential(const std::shared_ptr &callback) override; + int32_t RegistCredChangeEventListener(const std::vector &authTypes, + const std::shared_ptr &listener) override; + int32_t UnRegistCredChangeEventListener(const std::shared_ptr &listener) override; + int32_t GetCredentialInfoSync(int32_t userId, AuthType authType, + std::vector &credentialInfoList) override; + private: friend class UserIdmClient; UserIdmClientImpl() = default; @@ -56,8 +64,8 @@ private: void OnRemoteDied(const wptr &remote) override; }; void ResetProxy(const wptr &remote); - sptr GetProxy(); - sptr proxy_ {nullptr}; + sptr GetProxy(); + sptr proxy_ {nullptr}; sptr deathRecipient_ {nullptr}; std::mutex mutex_; }; diff --git a/frameworks/native/client/inc/widget_callback_service.h b/frameworks/native/client/inc/widget_callback_service.h index e03d1d90ee94d8b11ac38c2a5f6d1442238d1547..2204f154116df0197e6f8bfb5436c6a6b7e6d022 100644 --- a/frameworks/native/client/inc/widget_callback_service.h +++ b/frameworks/native/client/inc/widget_callback_service.h @@ -28,7 +28,9 @@ class WidgetCallbackService : public WidgetCallbackStub { public: explicit WidgetCallbackService(const std::shared_ptr &impl); ~WidgetCallbackService() override; - void SendCommand(const std::string &cmdData) override; + int32_t SendCommand(const std::string &cmdData) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: std::shared_ptr widgetCallback_ {nullptr}; diff --git a/frameworks/native/client/src/callback_manager_impl.cpp b/frameworks/native/client/src/callback_manager_impl.cpp index 0b7dd6e3294e12e17be14df3e24596fe1d71fcbb..f981ed133beab892b6a33e2ca2f74fd4627a669c 100644 --- a/frameworks/native/client/src/callback_manager_impl.cpp +++ b/frameworks/native/client/src/callback_manager_impl.cpp @@ -42,14 +42,14 @@ private: void CallbackManagerImpl::AddCallback(uintptr_t key, CallbackAction &action) { - IAM_LOGI("start"); + IAM_LOGD("start"); std::lock_guard lock(mutex_); callbackActionMap_.emplace(key, action); } void CallbackManagerImpl::RemoveCallback(uintptr_t key) { - IAM_LOGI("start"); + IAM_LOGD("start"); std::lock_guard lock(mutex_); callbackActionMap_.erase(key); } diff --git a/frameworks/native/client/src/co_auth_client_impl.cpp b/frameworks/native/client/src/co_auth_client_impl.cpp index 6b9b6cb40aa8e65f884e44a865760adad4705ef7..6a540f8c78389bd014f9717e7bd1208547d28b88 100644 --- a/frameworks/native/client/src/co_auth_client_impl.cpp +++ b/frameworks/native/client/src/co_auth_client_impl.cpp @@ -27,6 +27,19 @@ namespace OHOS { namespace UserIam { namespace UserAuth { +void CoAuthClientImpl::InitIpcExecutorInfo(const ExecutorInfo &info, IpcExecutorRegisterInfo &ipcExecutorRegisterInfo) +{ + ipcExecutorRegisterInfo.authType = static_cast(info.authType); + ipcExecutorRegisterInfo.executorRole = static_cast(info.executorRole); + ipcExecutorRegisterInfo.executorSensorHint = static_cast(info.executorSensorHint); + ipcExecutorRegisterInfo.executorMatcher = static_cast(info.executorMatcher); + ipcExecutorRegisterInfo.esl = static_cast(info.esl); + ipcExecutorRegisterInfo.publicKey = info.publicKey; + ipcExecutorRegisterInfo.deviceUdid = info.deviceUdid; + ipcExecutorRegisterInfo.signedRemoteExecutorInfo = info.signedRemoteExecutorInfo; + ipcExecutorRegisterInfo.maxTemplateAcl = static_cast(info.maxTemplateAcl); +} + uint64_t CoAuthClientImpl::Register(const ExecutorInfo &info, const std::shared_ptr &callback) { IAM_LOGI("start type:%{public}d role:%{public}d", info.authType, info.executorRole); @@ -40,22 +53,21 @@ uint64_t CoAuthClientImpl::Register(const ExecutorInfo &info, const std::shared_ return INVALID_EXECUTOR_INDEX; } - CoAuthInterface::ExecutorRegisterInfo regInfo; - regInfo.authType = info.authType; - regInfo.executorRole = info.executorRole; - regInfo.executorSensorHint = info.executorSensorHint; - regInfo.executorMatcher = info.executorMatcher; - regInfo.esl = info.esl; - regInfo.publicKey = info.publicKey; - regInfo.deviceUdid = info.deviceUdid; - regInfo.signedRemoteExecutorInfo = info.signedRemoteExecutorInfo; - regInfo.maxTemplateAcl = info.maxTemplateAcl; - sptr wrapper(new (std::nothrow) ExecutorCallbackService(callback)); + IpcExecutorRegisterInfo regInfo = {}; + InitIpcExecutorInfo(info, regInfo); + sptr wrapper(new (std::nothrow) ExecutorCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); return INVALID_EXECUTOR_INDEX; } - return proxy->ExecutorRegister(regInfo, wrapper); + uint64_t executorIndex = INVALID_EXECUTOR_INDEX; + auto ret = proxy->ExecutorRegister(regInfo, wrapper, executorIndex); + if (ret != SUCCESS) { + IAM_LOGE("ExecutorRegister fail, ret:%{public}d", ret); + return INVALID_EXECUTOR_INDEX; + } + + return executorIndex; } void CoAuthClientImpl::Unregister(uint64_t executorIndex) @@ -67,10 +79,14 @@ void CoAuthClientImpl::Unregister(uint64_t executorIndex) return; } - proxy->ExecutorUnregister(executorIndex); + auto ret = proxy->ExecutorUnregister(executorIndex); + if (ret != SUCCESS) { + IAM_LOGE("ExecutorUnregister fail, ret:%{public}d", ret); + return; + } } -sptr CoAuthClientImpl::GetProxy() +sptr CoAuthClientImpl::GetProxy() { std::lock_guard lock(mutex_); if (proxy_ != nullptr) { @@ -87,7 +103,7 @@ sptr CoAuthClientImpl::GetProxy() return proxy_; } - proxy_ = iface_cast(obj); + proxy_ = iface_cast(obj); deathRecipient_ = dr; return proxy_; } diff --git a/frameworks/native/client/src/event_listener_callback_service.cpp b/frameworks/native/client/src/event_listener_callback_service.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ba2cf494a349124a6330b24fdef9b2fe15226ab4 --- /dev/null +++ b/frameworks/native/client/src/event_listener_callback_service.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "event_listener_callback_service.h" + +#include "callback_manager.h" +#include "iam_check.h" +#include "iam_logger.h" +#include "iam_ptr.h" + +#define LOG_TAG "USER_AUTH_SDK" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +int32_t EventListenerCallbackManager::AddUserAuthSuccessEventListener(const sptr &proxy, + const std::vector &authTypes, const std::shared_ptr &listener) +{ + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS); + + std::lock_guard lock(eventListenerMutex_); + if (authEventListenerMap_.size() == 0) { + authEventListenerCallbackImpl_ = new (std::nothrow) EventListenerCallbackImpl(); + IF_FALSE_LOGE_AND_RETURN_VAL(authEventListenerCallbackImpl_ != nullptr, GENERAL_ERROR); + auto ret = proxy->RegistUserAuthSuccessEventListener(authEventListenerCallbackImpl_); + IF_FALSE_LOGE_AND_RETURN_VAL(ret == SUCCESS, ret); + } + + for (auto authType : authTypes) { + auto addCount = authEventListenerMap_[authType].insert(listener); + IAM_LOGI("AddEventListener addCount:%{public}d, authType:%{public}d, listenerSize:%{public}zu", + addCount.second, static_cast(authType), authEventListenerMap_[authType].size()); + } + return SUCCESS; +} + +int32_t EventListenerCallbackManager::RemoveUserAuthSuccessEventListener(const sptr &proxy, + const std::shared_ptr &listener) +{ + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS); + + std::lock_guard lock(eventListenerMutex_); + auto mapIter = authEventListenerMap_.begin(); + while (mapIter != authEventListenerMap_.end()) { + size_t eraseCount = mapIter->second.erase(listener); + IAM_LOGI("RemoveEventListener eraseCount:%{public}zu, authType:%{public}d, listenerSize:%{public}zu", + eraseCount, mapIter->first, mapIter->second.size()); + if (mapIter->second.size() == 0) { + mapIter = authEventListenerMap_.erase(mapIter); + } else { + mapIter++; + } + } + + if (authEventListenerMap_.size() == 0) { + auto ret = proxy->UnRegistUserAuthSuccessEventListener(authEventListenerCallbackImpl_); + authEventListenerCallbackImpl_ = nullptr; + return ret; + } + return SUCCESS; +} + +int32_t EventListenerCallbackManager::AddCredChangeEventListener(const sptr &proxy, + const std::vector &authTypes, const std::shared_ptr &listener) +{ + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS); + + std::lock_guard lock(eventListenerMutex_); + if (credEventListenerMap_.size() == 0) { + credEventListenerCallbackImpl_ = new (std::nothrow) EventListenerCallbackImpl(); + IF_FALSE_LOGE_AND_RETURN_VAL(credEventListenerCallbackImpl_ != nullptr, GENERAL_ERROR); + auto ret = proxy->RegistCredChangeEventListener(credEventListenerCallbackImpl_); + IF_FALSE_LOGE_AND_RETURN_VAL(ret == SUCCESS, ret); + } + + for (auto authType : authTypes) { + auto addCount = credEventListenerMap_[authType].insert(listener); + IAM_LOGI("AddEventListener addCount:%{public}d, authType:%{public}d, listenerSize:%{public}zu", + addCount.second, static_cast(authType), credEventListenerMap_[authType].size()); + } + return SUCCESS; +} + +int32_t EventListenerCallbackManager::RemoveCredChangeEventListener(const sptr &proxy, + const std::shared_ptr &listener) +{ + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); + IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS); + + std::lock_guard lock(eventListenerMutex_); + auto mapIter = credEventListenerMap_.begin(); + while (mapIter != credEventListenerMap_.end()) { + size_t eraseCount = mapIter->second.erase(listener); + IAM_LOGI("RemoveEventListener eraseCount:%{public}zu, authType:%{public}d, listenerSize:%{public}zu", + eraseCount, mapIter->first, mapIter->second.size()); + if (mapIter->second.size() == 0) { + mapIter = credEventListenerMap_.erase(mapIter); + } else { + mapIter++; + } + } + + if (credEventListenerMap_.size() == 0) { + auto ret = proxy->UnRegistCredChangeEventListener(credEventListenerCallbackImpl_); + credEventListenerCallbackImpl_ = nullptr; + return ret; + } + return SUCCESS; +} + +std::set> EventListenerCallbackManager::GetAuthEventListenerSet( + AuthType authType) +{ + std::lock_guard lock(eventListenerMutex_); + if (authEventListenerMap_.find(authType) != authEventListenerMap_.end()) { + return authEventListenerMap_[authType]; + } + return {}; +} + +std::set> EventListenerCallbackManager::GetCredEventListenerSet( + AuthType authType) +{ + std::lock_guard lock(eventListenerMutex_); + if (credEventListenerMap_.find(authType) != credEventListenerMap_.end()) { + return credEventListenerMap_[authType]; + } + return {}; +} + +void EventListenerCallbackManager::OnServiceDeath() +{ + IAM_LOGI("userauthservice death, clear caller map and register again"); + std::lock_guard lock(eventListenerMutex_); + authEventListenerMap_.clear(); + credEventListenerMap_.clear(); +} + +EventListenerCallbackManager &EventListenerCallbackManager::GetInstance() +{ + static EventListenerCallbackManager eventListenerCallbackManager; + return eventListenerCallbackManager; +} + +int32_t EventListenerCallbackManager::EventListenerCallbackImpl::OnNotifyAuthSuccessEvent(int32_t userId, + int32_t authType, int32_t callerType, const std::string &callerName) +{ + IAM_LOGI("OnNotifyAuthSuccessEvent, userId:%{public}d, authType:%{public}d, callerName:%{public}s," + "callerType:%{public}d", userId, authType, callerName.c_str(), callerType); + auto eventListenerSet = + EventListenerCallbackManager::GetInstance().GetAuthEventListenerSet(static_cast(authType)); + for (const auto &listener : eventListenerSet) { + if (listener == nullptr) { + IAM_LOGE("authListener is nullptr"); + continue; + } + listener->OnNotifyAuthSuccessEvent(userId, static_cast(authType), callerType, callerName); + } + return SUCCESS; +} + +int32_t EventListenerCallbackManager::EventListenerCallbackImpl::OnNotifyCredChangeEvent(int32_t userId, + int32_t authType, int32_t eventType, uint64_t credentialId) +{ + IAM_LOGI("OnNotifyCredChangeEvent, userId:%{public}d, authType:%{public}d, eventType:%{public}d," + "credentialId:%{public}u", userId, authType, eventType, static_cast(credentialId)); + auto eventListenerSet = + EventListenerCallbackManager::GetInstance().GetCredEventListenerSet(static_cast(authType)); + for (const auto &listener : eventListenerSet) { + if (listener == nullptr) { + IAM_LOGE("credListener is nullptr"); + continue; + } + listener->OnNotifyCredChangeEvent(userId, static_cast(authType), + static_cast(eventType), credentialId); + } + return SUCCESS; +} + +int32_t EventListenerCallbackManager::EventListenerCallbackImpl::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t EventListenerCallbackManager::EventListenerCallbackImpl::CallbackExit([[maybe_unused]] uint32_t code, + [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/client/src/executor_callback_service.cpp b/frameworks/native/client/src/executor_callback_service.cpp index 0a49742d4254d9eaa007ee16f81f84e7289a8dab..7c7b48268059ada16452c3e763378e91194e433e 100644 --- a/frameworks/native/client/src/executor_callback_service.cpp +++ b/frameworks/native/client/src/executor_callback_service.cpp @@ -29,71 +29,94 @@ ExecutorCallbackService::ExecutorCallbackService(const std::shared_ptr &messenger, +int32_t ExecutorCallbackService::OnMessengerReady(const sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ == nullptr) { IAM_LOGE("callback is nullptr"); - return; + return GENERAL_ERROR; } auto wrapper = Common::MakeShared(messenger); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); - return; + return GENERAL_ERROR; } callback_->OnMessengerReady(wrapper, publicKey, templateIdList); + return SUCCESS; } int32_t ExecutorCallbackService::OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) + const std::vector &command) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ == nullptr) { IAM_LOGE("callback is nullptr"); return GENERAL_ERROR; } - return callback_->OnBeginExecute(scheduleId, publicKey, command); + Attributes attributes(command); + return callback_->OnBeginExecute(scheduleId, publicKey, attributes); } -int32_t ExecutorCallbackService::OnEndExecute(uint64_t scheduleId, const Attributes &command) +int32_t ExecutorCallbackService::OnEndExecute(uint64_t scheduleId, const std::vector &command) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ == nullptr) { IAM_LOGE("callback is nullptr"); return GENERAL_ERROR; } - return callback_->OnEndExecute(scheduleId, command); + Attributes attributes(command); + return callback_->OnEndExecute(scheduleId, attributes); } -int32_t ExecutorCallbackService::OnSetProperty(const Attributes &properties) +int32_t ExecutorCallbackService::OnSetProperty(const std::vector &properties) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ == nullptr) { IAM_LOGE("callback is nullptr"); return GENERAL_ERROR; } - return callback_->OnSetProperty(properties); + Attributes attributes(properties); + return callback_->OnSetProperty(attributes); } -int32_t ExecutorCallbackService::OnGetProperty(const Attributes &condition, Attributes &values) +int32_t ExecutorCallbackService::OnGetProperty(const std::vector &condition, std::vector &values) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ == nullptr) { IAM_LOGE("callback is nullptr"); return GENERAL_ERROR; } - return callback_->OnGetProperty(condition, values); + Attributes conditionAttr(condition); + Attributes valuesAttr; + auto ret = callback_->OnGetProperty(conditionAttr, valuesAttr); + if (ret == SUCCESS) { + values = valuesAttr.Serialize(); + } + return ret; } -int32_t ExecutorCallbackService::OnSendData(uint64_t scheduleId, const Attributes &data) +int32_t ExecutorCallbackService::OnSendData(uint64_t scheduleId, const std::vector &extraInfo) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ == nullptr) { IAM_LOGE("callback is nullptr"); return GENERAL_ERROR; } - return callback_->OnSendData(scheduleId, data); + Attributes attributes(extraInfo); + return callback_->OnSendData(scheduleId, attributes); +} + +int32_t ExecutorCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t ExecutorCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/src/executor_messenger_client.cpp b/frameworks/native/client/src/executor_messenger_client.cpp index 313dcb980be7b594152838714d5f05ca755e5285..57f97a10705064f1caf8116577e3778fcc024728 100644 --- a/frameworks/native/client/src/executor_messenger_client.cpp +++ b/frameworks/native/client/src/executor_messenger_client.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -ExecutorMessengerClient::ExecutorMessengerClient(const sptr &messenger) +ExecutorMessengerClient::ExecutorMessengerClient(const sptr &messenger) : messenger_(messenger) { } @@ -32,7 +32,7 @@ ExecutorMessengerClient::ExecutorMessengerClient(const sptr &msg) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (messenger_ == nullptr) { IAM_LOGE("messenger is nullptr"); return GENERAL_ERROR; @@ -50,17 +50,12 @@ int32_t ExecutorMessengerClient::SendData(uint64_t scheduleId, ExecutorRole dstR int32_t ExecutorMessengerClient::Finish(uint64_t scheduleId, int32_t resultCode, const Attributes &finalResult) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (messenger_ == nullptr) { IAM_LOGE("messenger is nullptr"); return GENERAL_ERROR; } - auto attr = Common::MakeShared(finalResult.Serialize()); - if (attr == nullptr) { - IAM_LOGE("failed to create attributes"); - return GENERAL_ERROR; - } - return messenger_->Finish(scheduleId, static_cast(resultCode), attr); + return messenger_->Finish(scheduleId, static_cast(resultCode), finalResult.Serialize()); } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/src/modal_callback_service.cpp b/frameworks/native/client/src/modal_callback_service.cpp index a6a00c3ae4a4d3d1d0775699d6de7b7a5f91e33d..3f0531d4bbef176fed39f5ef76832c20f7c5c769 100644 --- a/frameworks/native/client/src/modal_callback_service.cpp +++ b/frameworks/native/client/src/modal_callback_service.cpp @@ -18,6 +18,7 @@ #include "callback_manager.h" #include "iam_logger.h" #include "iam_ptr.h" +#include "iam_common_defines.h" #define LOG_TAG "USER_AUTH_SDK" @@ -47,15 +48,28 @@ ModalCallbackService::~ModalCallbackService() CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); } -void ModalCallbackService::SendCommand(uint64_t contextId, const std::string &cmdData) +int32_t ModalCallbackService::SendCommand(uint64_t contextId, const std::string &cmdData) { IAM_LOGI("SendCommand start"); if (modalCallback_ == nullptr) { IAM_LOGE("modal callback is nullptr"); - return; + return GENERAL_ERROR; } modalCallback_->SendCommand(contextId, cmdData); iamHitraceHelper_ = nullptr; + return SUCCESS; +} + +int32_t ModalCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t ModalCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/src/user_access_ctrl_callback_service.cpp b/frameworks/native/client/src/user_access_ctrl_callback_service.cpp index 5b22caebdb2da23f2b276146955355e45f2c3292..de510f93baeb7af293ab9c1ab9133c0885576fc3 100644 --- a/frameworks/native/client/src/user_access_ctrl_callback_service.cpp +++ b/frameworks/native/client/src/user_access_ctrl_callback_service.cpp @@ -18,6 +18,7 @@ #include "callback_manager.h" #include "iam_logger.h" #include "iam_ptr.h" +#include "iam_common_defines.h" #define LOG_TAG "USER_ACCESS_CTRL_SDK" @@ -42,15 +43,28 @@ VerifyTokenCallbackService::~VerifyTokenCallbackService() CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); } -void VerifyTokenCallbackService::OnVerifyTokenResult(int32_t result, const Attributes &attributes) +int32_t VerifyTokenCallbackService::OnVerifyTokenResult(int32_t resultCode, const std::vector &extraInfo) { - IAM_LOGI("start, verify token result: %{public}d", result); + IAM_LOGI("start, verify token result: %{public}d", resultCode); if (verifyTokenCallback_ == nullptr) { IAM_LOGE("verifyTokenCallback is nullptr"); - return; + return GENERAL_ERROR; } + Attributes attributes(extraInfo); + verifyTokenCallback_->OnResult(resultCode, attributes); + return SUCCESS; +} - verifyTokenCallback_->OnResult(result, attributes); +int32_t VerifyTokenCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t VerifyTokenCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/src/user_access_ctrl_client_impl.cpp b/frameworks/native/client/src/user_access_ctrl_client_impl.cpp index db42e6a0f719e90aab47b27cda0da1f177e48a0f..7db7fd6e801df9f34c4edfaa91a938e279bd386f 100644 --- a/frameworks/native/client/src/user_access_ctrl_client_impl.cpp +++ b/frameworks/native/client/src/user_access_ctrl_client_impl.cpp @@ -18,6 +18,7 @@ #include "system_ability_definition.h" #include "callback_manager.h" +#include "iam_common_defines.h" #include "iam_logger.h" #include "ipc_client_utils.h" #include "user_access_ctrl_callback_service.h" @@ -43,7 +44,7 @@ void UserAccessCtrlClientImpl::VerifyAuthToken(const std::vector &token return; } - sptr wrapper(new (std::nothrow) VerifyTokenCallbackService(callback)); + sptr wrapper(new (std::nothrow) VerifyTokenCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; @@ -53,7 +54,7 @@ void UserAccessCtrlClientImpl::VerifyAuthToken(const std::vector &token proxy->VerifyAuthToken(tokenIn, allowableDuration, wrapper); } -sptr UserAccessCtrlClientImpl::GetProxy() +sptr UserAccessCtrlClientImpl::GetProxy() { std::lock_guard lock(mutex_); if (proxy_ != nullptr) { @@ -70,7 +71,7 @@ sptr UserAccessCtrlClientImpl::GetProxy() return proxy_; } - proxy_ = iface_cast(obj); + proxy_ = iface_cast(obj); deathRecipient_ = dr; return proxy_; } diff --git a/frameworks/native/client/src/user_auth_callback_service.cpp b/frameworks/native/client/src/user_auth_callback_service.cpp index cdaddaaa0876ea63ab51b7dad5a9fbbb94531c1d..c516211057c40cee5be179eeaeb45c8da7c2ee29 100644 --- a/frameworks/native/client/src/user_auth_callback_service.cpp +++ b/frameworks/native/client/src/user_auth_callback_service.cpp @@ -82,14 +82,15 @@ UserAuthCallbackService::UserAuthCallbackService(const std::shared_ptr(this)); } -void UserAuthCallbackService::OnResult(int32_t result, const Attributes &extraInfo) +int32_t UserAuthCallbackService::OnResult(int32_t resultCode, const std::vector &extraInfo) { - IAM_LOGI("start, result:%{public}d", result); + IAM_LOGD("start, result:%{public}d", resultCode); + Attributes attribute(extraInfo); if (authCallback_ != nullptr) { if (modalCallback_ != nullptr) { IAM_LOGI("IsModalInit :%{public}d, IsModalDestroy :%{public}d", modalCallback_->IsModalInit(), @@ -100,31 +101,47 @@ void UserAuthCallbackService::OnResult(int32_t result, const Attributes &extraIn IAM_LOGI("process result continue"); } } - authCallback_->OnResult(result, extraInfo); + authCallback_->OnResult(resultCode, attribute); } else if (identifyCallback_ != nullptr) { - identifyCallback_->OnResult(result, extraInfo); + identifyCallback_->OnResult(resultCode, attribute); } else if (prepareRemoteAuthCallback_ != nullptr) { - prepareRemoteAuthCallback_->OnResult(result); + prepareRemoteAuthCallback_->OnResult(resultCode); } else { IAM_LOGE("all callback is nullptr"); - return; + return GENERAL_ERROR; } iamHitraceHelper_= nullptr; + return SUCCESS; } -void UserAuthCallbackService::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) +int32_t UserAuthCallbackService::OnAcquireInfo(int32_t module, int32_t acquireInfo, + const std::vector &extraInfo) { - IAM_LOGI("start, module:%{public}d acquireInfo:%{public}d", module, acquireInfo); + IAM_LOGD("start, module:%{public}d acquireInfo:%{public}d", module, acquireInfo); + Attributes attribute(extraInfo); if (authCallback_ != nullptr) { - authCallback_->OnAcquireInfo(module, acquireInfo, extraInfo); + authCallback_->OnAcquireInfo(module, acquireInfo, attribute); } else if (identifyCallback_ != nullptr) { - identifyCallback_->OnAcquireInfo(module, acquireInfo, extraInfo); + identifyCallback_->OnAcquireInfo(module, acquireInfo, attribute); } else if (prepareRemoteAuthCallback_ != nullptr) { IAM_LOGE("prepare remote auth callback not support acquire info"); } else { IAM_LOGE("all callback is nullptr"); - return; + return GENERAL_ERROR; } + return SUCCESS; +} + +int32_t UserAuthCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t UserAuthCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } GetExecutorPropertyCallbackService::GetExecutorPropertyCallbackService(const std::shared_ptr &impl) @@ -145,14 +162,30 @@ GetExecutorPropertyCallbackService::~GetExecutorPropertyCallbackService() CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); } -void GetExecutorPropertyCallbackService::OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes) +int32_t GetExecutorPropertyCallbackService::OnGetExecutorPropertyResult(int32_t resultCode, + const std::vector &attributes) { - IAM_LOGI("start, result:%{public}d", result); + IAM_LOGD("start, result:%{public}d", resultCode); if (getPropCallback_ == nullptr) { IAM_LOGE("get prop callback is nullptr"); - return; + return GENERAL_ERROR; } - getPropCallback_->OnResult(result, attributes); + Attributes attribute(attributes); + getPropCallback_->OnResult(resultCode, attribute); + return SUCCESS; +} + +int32_t GetExecutorPropertyCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t GetExecutorPropertyCallbackService::CallbackExit([[maybe_unused]] uint32_t code, + [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } SetExecutorPropertyCallbackService::SetExecutorPropertyCallbackService(const std::shared_ptr &impl) @@ -173,15 +206,29 @@ SetExecutorPropertyCallbackService::~SetExecutorPropertyCallbackService() CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); } -void SetExecutorPropertyCallbackService::OnSetExecutorPropertyResult(int32_t result) +int32_t SetExecutorPropertyCallbackService::OnSetExecutorPropertyResult(int32_t resultCode) { - IAM_LOGI("start, result:%{public}d", result); + IAM_LOGD("start, result:%{public}d", resultCode); if (setPropCallback_ == nullptr) { IAM_LOGE("set prop callback is nullptr"); - return; + return GENERAL_ERROR; } Attributes attr; - setPropCallback_->OnResult(result, attr); + setPropCallback_->OnResult(resultCode, attr); + return SUCCESS; +} + +int32_t SetExecutorPropertyCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t SetExecutorPropertyCallbackService::CallbackExit([[maybe_unused]] uint32_t code, + [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/src/user_auth_client_impl.cpp b/frameworks/native/client/src/user_auth_client_impl.cpp index e3fe19b2aadade839a9a851ae64cfccc7b3d5cd5..82ed9a422af2d070efca237712ddb75dd72b7feb 100644 --- a/frameworks/native/client/src/user_auth_client_impl.cpp +++ b/frameworks/native/client/src/user_auth_client_impl.cpp @@ -36,6 +36,7 @@ namespace OHOS { namespace UserIam { namespace UserAuth { namespace { + const uint32_t MAX_ATTR_COUNT = 512; class NorthAuthenticationCallback : public AuthenticationCallback, public NoCopyable { public: explicit NorthAuthenticationCallback(std::shared_ptr innerCallback); @@ -92,7 +93,8 @@ int32_t UserAuthClientImpl::GetAvailableStatus(AuthType authType, AuthTrustLevel ACCESS_BIOMETRIC_PERMISSION })); } - return proxy->GetAvailableStatus(INNER_API_VERSION_10000, authType, authTrustLevel); + return proxy->GetAvailableStatus(INNER_API_VERSION_10000, static_cast(authType), + static_cast(authTrustLevel)); } int32_t UserAuthClientImpl::GetNorthAvailableStatus(int32_t apiVersion, AuthType authType, @@ -107,7 +109,8 @@ int32_t UserAuthClientImpl::GetNorthAvailableStatus(int32_t apiVersion, AuthType ACCESS_BIOMETRIC_PERMISSION })); } - return proxy->GetAvailableStatus(apiVersion, authType, authTrustLevel); + return proxy->GetAvailableStatus(apiVersion, static_cast(authType), + static_cast(authTrustLevel)); } int32_t UserAuthClientImpl::GetAvailableStatus(int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel) @@ -120,7 +123,8 @@ int32_t UserAuthClientImpl::GetAvailableStatus(int32_t userId, AuthType authType ACCESS_USER_AUTH_INTERNAL_PERMISSION })); } - return proxy->GetAvailableStatus(INNER_API_VERSION_10000, userId, authType, authTrustLevel); + return proxy->GetAvailableStatus(INNER_API_VERSION_10000, userId, static_cast(authType), + static_cast(authTrustLevel)); } void UserAuthClientImpl::GetProperty(int32_t userId, const GetPropertyRequest &request, @@ -142,7 +146,7 @@ void UserAuthClientImpl::GetProperty(int32_t userId, const GetPropertyRequest &r return; } - sptr wrapper( + sptr wrapper( new (std::nothrow) GetExecutorPropertyCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); @@ -150,13 +154,32 @@ void UserAuthClientImpl::GetProperty(int32_t userId, const GetPropertyRequest &r callback->OnResult(GENERAL_ERROR, extraInfo); return; } - proxy->GetProperty(userId, request.authType, request.keys, wrapper); + + if (request.keys.empty() || request.keys.size() > MAX_ATTR_COUNT) { + IAM_LOGE("the attribute key vector is bad param, key size:%{public}zu", request.keys.size()); + Attributes attr; + callback->OnResult(INVALID_PARAMETERS, attr); + return; + } + + std::vector attrkeys; + attrkeys.resize(request.keys.size()); + std::transform(request.keys.begin(), request.keys.end(), attrkeys.begin(), [](Attributes::AttributeKey key) { + return static_cast(key); + }); + auto ret = proxy->GetProperty(userId, static_cast(request.authType), attrkeys, wrapper); + if (ret != SUCCESS) { + IAM_LOGE("GetProperty fail, ret:%{public}d", ret); + Attributes extraInfo; + callback->OnResult(GENERAL_ERROR, extraInfo); + return; + } } void UserAuthClientImpl::GetPropertyById(uint64_t credentialId, const std::vector &keys, const std::shared_ptr &callback) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (!callback) { IAM_LOGE("get prop callback is nullptr"); return; @@ -172,7 +195,7 @@ void UserAuthClientImpl::GetPropertyById(uint64_t credentialId, const std::vecto return; } - sptr wrapper( + sptr wrapper( new (std::nothrow) GetExecutorPropertyCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); @@ -180,7 +203,24 @@ void UserAuthClientImpl::GetPropertyById(uint64_t credentialId, const std::vecto callback->OnResult(GENERAL_ERROR, extraInfo); return; } - proxy->GetPropertyById(credentialId, keys, wrapper); + if (keys.empty() || keys.size() > MAX_ATTR_COUNT) { + IAM_LOGE("the attribute key vector is bad param, key size:%{public}zu", keys.size()); + Attributes attr; + callback->OnResult(INVALID_PARAMETERS, attr); + return; + } + std::vector attrkeys; + attrkeys.resize(keys.size()); + std::transform(keys.begin(), keys.end(), attrkeys.begin(), [](Attributes::AttributeKey key) { + return static_cast(key); + }); + auto ret = proxy->GetPropertyById(credentialId, attrkeys, wrapper); + if (ret != SUCCESS) { + IAM_LOGE("GetPropertyById fail, ret:%{public}d", ret); + Attributes extraInfo; + callback->OnResult(GENERAL_ERROR, extraInfo); + return; + } } ResultCode UserAuthClientImpl::SetPropertyInner(int32_t userId, const SetPropertyRequest &request, @@ -210,10 +250,14 @@ ResultCode UserAuthClientImpl::SetPropertyInner(int32_t userId, const SetPropert bool setArrayRet = attr.SetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo); IF_FALSE_LOGE_AND_RETURN_VAL(setArrayRet, GENERAL_ERROR); - sptr wrapper( + sptr wrapper( new (std::nothrow) SetExecutorPropertyCallbackService(callback)); IF_FALSE_LOGE_AND_RETURN_VAL(wrapper != nullptr, GENERAL_ERROR); - proxy->SetProperty(userId, request.authType, attr, wrapper); + auto ret = proxy->SetProperty(userId, static_cast(request.authType), attr.Serialize(), wrapper); + if (ret != SUCCESS) { + IAM_LOGE("SetProperty fail, ret:%{public}d", ret); + return (ResultCode)ret; + } return SUCCESS; } @@ -264,22 +308,29 @@ uint64_t UserAuthClientImpl::BeginAuthentication(const AuthParam &authParam, return BAD_CONTEXT_ID; } - sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); + sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; callback->OnResult(GENERAL_ERROR, extraInfo); return BAD_CONTEXT_ID; } - AuthParamInner authParamInner = { + uint64_t contextId = BAD_CONTEXT_ID; + IpcAuthParamInner ipcAuthParamInner = { .userId = authParam.userId, .challenge = authParam.challenge, - .authType = authParam.authType, - .authTrustLevel = authParam.authTrustLevel, - .authIntent = authParam.authIntent + .authType = static_cast(authParam.authType), + .authTrustLevel = static_cast(authParam.authTrustLevel), + .authIntent = static_cast(authParam.authIntent), }; - std::optional remoteAuthParam = authParam.remoteAuthParam; - return proxy->AuthUser(authParamInner, remoteAuthParam, wrapper); + IpcRemoteAuthParam ipcRemoteAuthParam = {}; + InitIpcRemoteAuthParam(authParam.remoteAuthParam, ipcRemoteAuthParam); + auto ret = proxy->AuthUser(ipcAuthParamInner, ipcRemoteAuthParam, wrapper, contextId); + if (ret != SUCCESS) { + IAM_LOGE("AuthUser fail, ret:%{public}d", ret); + return BAD_CONTEXT_ID; + } + return contextId; } uint64_t UserAuthClientImpl::BeginNorthAuthentication(int32_t apiVersion, const std::vector &challenge, @@ -309,14 +360,25 @@ uint64_t UserAuthClientImpl::BeginNorthAuthentication(int32_t apiVersion, const return BAD_CONTEXT_ID; } - sptr wrapper(new (std::nothrow) UserAuthCallbackService(northCallback)); + sptr wrapper(new (std::nothrow) UserAuthCallbackService(northCallback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; callback->OnResult(GENERAL_ERROR, extraInfo); return BAD_CONTEXT_ID; } - return proxy->Auth(apiVersion, challenge, authType, atl, wrapper); + uint64_t contextId = BAD_CONTEXT_ID; + IpcAuthParamInner authParamInner = { + .challenge = challenge, + .authType = static_cast(authType), + .authTrustLevel = static_cast(atl) + }; + auto ret = proxy->Auth(apiVersion, authParamInner, wrapper, contextId); + if (ret != SUCCESS) { + IAM_LOGE("Auth fail, ret:%{public}d", ret); + return BAD_CONTEXT_ID; + } + return contextId; } int32_t UserAuthClientImpl::CancelAuthentication(uint64_t contextId) @@ -350,14 +412,20 @@ uint64_t UserAuthClientImpl::BeginIdentification(const std::vector &cha return BAD_CONTEXT_ID; } - sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); + sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; callback->OnResult(GENERAL_ERROR, extraInfo); return BAD_CONTEXT_ID; } - return proxy->Identify(challenge, authType, wrapper); + uint64_t contextId = BAD_CONTEXT_ID; + auto ret = proxy->Identify(challenge, static_cast(authType), wrapper, contextId); + if (ret != SUCCESS) { + IAM_LOGE("Identify fail, ret:%{public}d", ret); + return BAD_CONTEXT_ID; + } + return contextId; } int32_t UserAuthClientImpl::CancelIdentification(uint64_t contextId) @@ -392,11 +460,12 @@ int32_t UserAuthClientImpl::SetGlobalConfigParam(const GlobalConfigParam ¶m) IAM_LOGE("proxy is nullptr"); return GENERAL_ERROR; } - - return proxy->SetGlobalConfigParam(param); + IpcGlobalConfigParam ipcGlobalConfigParam = {}; + InitIpcGlobalConfigParam(param, ipcGlobalConfigParam); + return proxy->SetGlobalConfigParam(ipcGlobalConfigParam); } -sptr UserAuthClientImpl::GetProxy() +sptr UserAuthClientImpl::GetProxy() { std::lock_guard lock(mutex_); if (proxy_ != nullptr) { @@ -413,7 +482,7 @@ sptr UserAuthClientImpl::GetProxy() return proxy_; } - proxy_ = iface_cast(obj); + proxy_ = iface_cast(obj); deathRecipient_ = dr; return proxy_; } @@ -444,6 +513,7 @@ void UserAuthClientImpl::UserAuthImplDeathRecipient::OnRemoteDied(const wptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); + sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; @@ -530,14 +600,24 @@ uint64_t UserAuthClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const Auth // modal const std::shared_ptr &modalCallback = Common::MakeShared(); - sptr wrapperModal(new (std::nothrow) ModalCallbackService(modalCallback)); + sptr wrapperModal(new (std::nothrow) ModalCallbackService(modalCallback)); if (wrapperModal == nullptr) { IAM_LOGE("failed to create wrapper for modal"); Attributes extraInfo; callback->OnResult(static_cast(ResultCode::GENERAL_ERROR), extraInfo); return BAD_CONTEXT_ID; } - return proxy->AuthWidget(apiVersion, authParam, widgetParam, wrapper, wrapperModal); + IpcAuthParamInner ipcAuthParamInner = {}; + IpcWidgetParamInner ipcWidgetParamInner = {}; + InitIpcAuthParam(authParam, ipcAuthParamInner); + InitIpcWidgetParam(widgetParam, ipcWidgetParamInner); + uint64_t contextId = BAD_CONTEXT_ID; + auto ret = proxy->AuthWidget(apiVersion, ipcAuthParamInner, ipcWidgetParamInner, wrapper, wrapperModal, contextId); + if (ret != SUCCESS) { + IAM_LOGE("AuthWidget fail, ret:%{public}d", ret); + return BAD_CONTEXT_ID; + } + return contextId; } int32_t UserAuthClientImpl::SetWidgetCallback(int32_t version, const std::shared_ptr &callback) @@ -553,7 +633,7 @@ int32_t UserAuthClientImpl::SetWidgetCallback(int32_t version, const std::shared return GENERAL_ERROR; } - sptr wrapper(new (std::nothrow) WidgetCallbackService(callback)); + sptr wrapper(new (std::nothrow) WidgetCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); return GENERAL_ERROR; @@ -571,7 +651,7 @@ int32_t UserAuthClientImpl::Notice(NoticeType noticeType, const std::string &eve } IAM_LOGI("UserAuthClientImpl::Notice noticeType:%{public}d, eventDat:%{public}s", static_cast(noticeType), eventData.c_str()); - return proxy->Notice(noticeType, eventData); + return proxy->Notice(static_cast(noticeType), eventData); } int32_t UserAuthClientImpl::GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState) @@ -583,59 +663,37 @@ int32_t UserAuthClientImpl::GetEnrolledState(int32_t apiVersion, AuthType authTy ACCESS_BIOMETRIC_PERMISSION })); } - int32_t ret = proxy->GetEnrolledState(apiVersion, authType, enrolledState); + IpcEnrolledState ipcEnrolledState = {}; + int32_t ret = proxy->GetEnrolledState(apiVersion, static_cast(authType), ipcEnrolledState); if (ret != SUCCESS) { IAM_LOGE("proxy GetEnrolledState failed"); return ret; } - return ret; + enrolledState.credentialCount = ipcEnrolledState.credentialCount; + enrolledState.credentialDigest = ipcEnrolledState.credentialDigest; + return SUCCESS; } -int32_t UserAuthClientImpl::RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) +int32_t UserAuthClientImpl::RegistUserAuthSuccessEventListener(const std::vector &authTypes, + const std::shared_ptr &listener) { IAM_LOGI("start"); - if (!listener) { - IAM_LOGE("listener is nullptr"); - return GENERAL_ERROR; - } auto proxy = GetProxy(); - if (!proxy) { - IAM_LOGE("proxy is nullptr"); - return GENERAL_ERROR; - } + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); - int32_t ret = proxy->RegistUserAuthSuccessEventListener(authType, listener); - if (ret != SUCCESS) { - IAM_LOGE("Regist userAuth success event listener failed"); - return ret; - } - - return SUCCESS; + return EventListenerCallbackManager::GetInstance().AddUserAuthSuccessEventListener(proxy, authTypes, listener); } -int32_t UserAuthClientImpl::UnRegistUserAuthSuccessEventListener(const sptr &listener) +int32_t UserAuthClientImpl::UnRegistUserAuthSuccessEventListener( + const std::shared_ptr &listener) { IAM_LOGI("start"); - if (!listener) { - IAM_LOGE("listener is nullptr"); - return GENERAL_ERROR; - } auto proxy = GetProxy(); - if (!proxy) { - IAM_LOGE("proxy is nullptr"); - return GENERAL_ERROR; - } + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); - int32_t ret = proxy->UnRegistUserAuthSuccessEventListener(listener); - if (ret != SUCCESS) { - IAM_LOGE("unRegist userAuth success event listener failed"); - return ret; - } - - return SUCCESS; + return EventListenerCallbackManager::GetInstance().RemoveUserAuthSuccessEventListener(proxy, listener); } int32_t UserAuthClientImpl::PrepareRemoteAuth(const std::string &networkId, @@ -654,7 +712,7 @@ int32_t UserAuthClientImpl::PrepareRemoteAuth(const std::string &networkId, return GENERAL_ERROR; } - sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); + sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); callback->OnResult(GENERAL_ERROR); @@ -663,6 +721,74 @@ int32_t UserAuthClientImpl::PrepareRemoteAuth(const std::string &networkId, return proxy->PrepareRemoteAuth(networkId, wrapper); } + +void UserAuthClientImpl::InitIpcRemoteAuthParam(const std::optional &remoteAuthParam, + IpcRemoteAuthParam &ipcRemoteAuthParam) +{ + ipcRemoteAuthParam.isHasRemoteAuthParam = false; + ipcRemoteAuthParam.isHasVerifierNetworkId = false; + ipcRemoteAuthParam.isHasCollectorNetworkId = false; + ipcRemoteAuthParam.isHasCollectorTokenId = false; + if (remoteAuthParam.has_value()) { + ipcRemoteAuthParam.isHasRemoteAuthParam = true; + if (remoteAuthParam.value().verifierNetworkId.has_value()) { + ipcRemoteAuthParam.isHasVerifierNetworkId = true; + ipcRemoteAuthParam.verifierNetworkId = remoteAuthParam.value().verifierNetworkId.value(); + } + if (remoteAuthParam.value().collectorNetworkId.has_value()) { + ipcRemoteAuthParam.isHasCollectorNetworkId = true; + ipcRemoteAuthParam.collectorNetworkId = remoteAuthParam.value().collectorNetworkId.value(); + } + if (remoteAuthParam.value().collectorTokenId.has_value()) { + ipcRemoteAuthParam.isHasCollectorTokenId = true; + ipcRemoteAuthParam.collectorTokenId = remoteAuthParam.value().collectorTokenId.value(); + } + } +} + +void UserAuthClientImpl::InitIpcGlobalConfigParam(const GlobalConfigParam &globalConfigParam, + IpcGlobalConfigParam &ipcGlobalConfigParam) +{ + ipcGlobalConfigParam.type = static_cast(globalConfigParam.type); + if (globalConfigParam.type == PIN_EXPIRED_PERIOD) { + ipcGlobalConfigParam.value.pinExpiredPeriod = globalConfigParam.value.pinExpiredPeriod; + } else if (globalConfigParam.type == ENABLE_STATUS) { + ipcGlobalConfigParam.value.enableStatus = globalConfigParam.value.enableStatus; + } + ipcGlobalConfigParam.userIds = globalConfigParam.userIds; + ipcGlobalConfigParam.authTypes.resize(globalConfigParam.authTypes.size()); + std::transform(globalConfigParam.authTypes.begin(), globalConfigParam.authTypes.end(), + ipcGlobalConfigParam.authTypes.begin(), [](AuthType authType) { + return static_cast(authType); + }); +} + +void UserAuthClientImpl::InitIpcAuthParam(const AuthParamInner &authParam, + IpcAuthParamInner &ipcAuthParamInner) +{ + ipcAuthParamInner.userId = authParam.userId; + ipcAuthParamInner.isUserIdSpecified = authParam.isUserIdSpecified; + ipcAuthParamInner.challenge = authParam.challenge; + ipcAuthParamInner.authType = static_cast(authParam.authType); + ipcAuthParamInner.authTypes.resize(authParam.authTypes.size()); + std::transform(authParam.authTypes.begin(), authParam.authTypes.end(), + ipcAuthParamInner.authTypes.begin(), [](AuthType authType) { + return static_cast(authType); + }); + ipcAuthParamInner.authTrustLevel = static_cast(authParam.authTrustLevel); + ipcAuthParamInner.authIntent = static_cast(authParam.authIntent); + ipcAuthParamInner.reuseUnlockResult.isReuse = authParam.reuseUnlockResult.isReuse; + ipcAuthParamInner.reuseUnlockResult.reuseDuration = authParam.reuseUnlockResult.reuseDuration; +} + +void UserAuthClientImpl::InitIpcWidgetParam(const WidgetParamInner &widgetParam, + IpcWidgetParamInner &ipcWidgetParamInner) +{ + ipcWidgetParamInner.title = widgetParam.title; + ipcWidgetParamInner.navigationButtonText = widgetParam.navigationButtonText; + ipcWidgetParamInner.windowMode = static_cast(widgetParam.windowMode); + ipcWidgetParamInner.hasContext = widgetParam.hasContext; +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/frameworks/native/client/src/user_auth_modal_inner_callback.cpp b/frameworks/native/client/src/user_auth_modal_inner_callback.cpp index db9582a7df5e8af115de26df1a8333ef347b294f..e85cae70ed696dfe8af722dfa5e783a3ae43b792 100644 --- a/frameworks/native/client/src/user_auth_modal_inner_callback.cpp +++ b/frameworks/native/client/src/user_auth_modal_inner_callback.cpp @@ -39,13 +39,13 @@ void UserAuthModalInnerCallback::SendCommand(uint64_t contextId, const std::stri bool UserAuthModalInnerCallback::IsModalInit() { - IAM_LOGI("get is modal init"); + IAM_LOGD("get is modal init"); return false; } bool UserAuthModalInnerCallback::IsModalDestroy() { - IAM_LOGI("get is modal on destroy"); + IAM_LOGD("get is modal on destroy"); return false; } diff --git a/frameworks/native/client/src/user_auth_napi_client_impl.cpp b/frameworks/native/client/src/user_auth_napi_client_impl.cpp index ace465cbe96409a72d50d977954523a97aa43f62..e24b26005976cf5b925e1168fc0d38f1438d94bd 100644 --- a/frameworks/native/client/src/user_auth_napi_client_impl.cpp +++ b/frameworks/native/client/src/user_auth_napi_client_impl.cpp @@ -24,12 +24,13 @@ #include "load_mode_client_util.h" #include "modal_callback_service.h" #include "user_auth_callback_service.h" +#include "user_auth_common_defines.h" #define LOG_TAG "USER_AUTH_SDK" namespace OHOS { namespace UserIam { namespace UserAuth { -sptr UserAuthNapiClientImpl::GetProxy() +sptr UserAuthNapiClientImpl::GetProxy() { std::lock_guard lock(mutex_); if (proxy_ != nullptr) { @@ -46,7 +47,7 @@ sptr UserAuthNapiClientImpl::GetProxy() return proxy_; } - proxy_ = iface_cast(obj); + proxy_ = iface_cast(obj); deathRecipient_ = dr; return proxy_; } @@ -130,7 +131,7 @@ uint64_t UserAuthNapiClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const return BAD_CONTEXT_ID; } - sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback, modalCallback)); + sptr wrapper(new (std::nothrow) UserAuthCallbackService(callback, modalCallback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; @@ -139,14 +140,24 @@ uint64_t UserAuthNapiClientImpl::BeginWidgetAuthInner(int32_t apiVersion, const } // modal - sptr wrapperModal(new (std::nothrow) ModalCallbackService(modalCallback)); + sptr wrapperModal(new (std::nothrow) ModalCallbackService(modalCallback)); if (wrapperModal == nullptr) { IAM_LOGE("failed to create wrapper for modal"); Attributes extraInfo; callback->OnResult(static_cast(ResultCode::GENERAL_ERROR), extraInfo); return BAD_CONTEXT_ID; } - return proxy->AuthWidget(apiVersion, authParam, widgetParam, wrapper, wrapperModal); + uint64_t contextId = BAD_CONTEXT_ID; + IpcAuthParamInner ipcAuthParam = {}; + IpcWidgetParamInner ipcWidgetParam = {}; + InitIpcAuthParam(authParam, ipcAuthParam); + InitIpcWidgetParam(widgetParam, ipcWidgetParam); + auto ret = proxy->AuthWidget(apiVersion, ipcAuthParam, ipcWidgetParam, wrapper, wrapperModal, contextId); + if (ret != SUCCESS) { + IAM_LOGE("AuthWidget fail, ret:%{public}d", ret); + return BAD_CONTEXT_ID; + } + return contextId; } int32_t UserAuthNapiClientImpl::CancelAuthentication(uint64_t contextId, int32_t cancelReason) @@ -160,6 +171,34 @@ int32_t UserAuthNapiClientImpl::CancelAuthentication(uint64_t contextId, int32_t return proxy->CancelAuthOrIdentify(contextId, cancelReason); } + +void UserAuthNapiClientImpl::InitIpcAuthParam(const AuthParamInner &authParam, + IpcAuthParamInner &ipcAuthParamInner) +{ + ipcAuthParamInner.userId = authParam.userId; + ipcAuthParamInner.isUserIdSpecified = authParam.isUserIdSpecified; + ipcAuthParamInner.challenge = authParam.challenge; + ipcAuthParamInner.authType = static_cast(authParam.authType); + ipcAuthParamInner.authTypes.resize(authParam.authTypes.size()); + std::transform(authParam.authTypes.begin(), authParam.authTypes.end(), + ipcAuthParamInner.authTypes.begin(), [](AuthType authType) { + return static_cast(authType); + }); + ipcAuthParamInner.authTrustLevel = static_cast(authParam.authTrustLevel); + ipcAuthParamInner.authIntent = static_cast(authParam.authIntent); + ipcAuthParamInner.reuseUnlockResult.isReuse = authParam.reuseUnlockResult.isReuse; + ipcAuthParamInner.reuseUnlockResult.reuseMode = authParam.reuseUnlockResult.reuseMode; + ipcAuthParamInner.reuseUnlockResult.reuseDuration = authParam.reuseUnlockResult.reuseDuration; +} + +void UserAuthNapiClientImpl::InitIpcWidgetParam(const WidgetParamInner &widgetParam, + IpcWidgetParamInner &ipcWidgetParamInner) +{ + ipcWidgetParamInner.title = widgetParam.title; + ipcWidgetParamInner.navigationButtonText = widgetParam.navigationButtonText; + ipcWidgetParamInner.windowMode = static_cast(widgetParam.windowMode); + ipcWidgetParamInner.hasContext = widgetParam.hasContext; +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/frameworks/native/client/src/user_idm_callback_service.cpp b/frameworks/native/client/src/user_idm_callback_service.cpp index ba7c7937b047163ef09959392882d9df88933f61..2a64412c6e90e3f005d1e2dda78ace0499bedfdf 100644 --- a/frameworks/native/client/src/user_idm_callback_service.cpp +++ b/frameworks/native/client/src/user_idm_callback_service.cpp @@ -43,25 +43,41 @@ IdmCallbackService::~IdmCallbackService() CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); } -void IdmCallbackService::OnResult(int32_t result, const Attributes &extraInfo) +int32_t IdmCallbackService::OnResult(int32_t resultCode, const std::vector &extraInfo) { - IAM_LOGI("start, result:%{public}d", result); + IAM_LOGI("start, result:%{public}d", resultCode); iamHitraceHelper_ = nullptr; if (idmClientCallback_ == nullptr) { IAM_LOGE("idm client callback is nullptr"); - return; + return GENERAL_ERROR; } - idmClientCallback_->OnResult(result, extraInfo); + Attributes attribute(extraInfo); + idmClientCallback_->OnResult(resultCode, attribute); + return SUCCESS; } -void IdmCallbackService::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) +int32_t IdmCallbackService::OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) { IAM_LOGI("start, module:%{public}d acquireInfo:%{public}d", module, acquireInfo); if (idmClientCallback_ == nullptr) { IAM_LOGE("idm client callback is nullptr"); - return; + return GENERAL_ERROR; } - idmClientCallback_->OnAcquireInfo(module, static_cast(acquireInfo), extraInfo); + Attributes attribute(extraInfo); + idmClientCallback_->OnAcquireInfo(module, static_cast(acquireInfo), attribute); + return SUCCESS; +} + +int32_t IdmCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t IdmCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } IdmGetCredInfoCallbackService::IdmGetCredInfoCallbackService( @@ -82,15 +98,38 @@ IdmGetCredInfoCallbackService::~IdmGetCredInfoCallbackService() CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); } -void IdmGetCredInfoCallbackService::OnCredentialInfos(int32_t result, const std::vector &credInfoList) +int32_t IdmGetCredInfoCallbackService::OnCredentialInfos(int32_t resultCode, + const std::vector &ipcCredInfoList) { - IAM_LOGI("start, cred info vector size:%{public}zu", credInfoList.size()); + IAM_LOGD("start, cred info vector size:%{public}zu", ipcCredInfoList.size()); if (getCredInfoCallback_ == nullptr) { IAM_LOGE("getCredInfoCallback is nullptr"); - return; + return GENERAL_ERROR; + } + + std::vector credInfoList; + for (auto &iter : ipcCredInfoList) { + CredentialInfo credentialInfo; + credentialInfo.authType = static_cast(iter.authType); + credentialInfo.pinType = static_cast(iter.pinType); + credentialInfo.credentialId = iter.credentialId; + credentialInfo.templateId = iter.templateId; + credInfoList.push_back(credentialInfo); } + getCredInfoCallback_->OnCredentialInfo(resultCode, credInfoList); + return SUCCESS; +} + +int32_t IdmGetCredInfoCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} - getCredInfoCallback_->OnCredentialInfo(result, credInfoList); +int32_t IdmGetCredInfoCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } IdmGetSecureUserInfoCallbackService::IdmGetSecureUserInfoCallbackService( @@ -111,15 +150,37 @@ IdmGetSecureUserInfoCallbackService::~IdmGetSecureUserInfoCallbackService() CallbackManager::GetInstance().RemoveCallback(reinterpret_cast(this)); } -void IdmGetSecureUserInfoCallbackService::OnSecureUserInfo(int32_t result, const SecUserInfo &secUserInfo) +int32_t IdmGetSecureUserInfoCallbackService::OnSecureUserInfo(int32_t resultCode, const IpcSecUserInfo &ipcSecUserInfo) { - IAM_LOGI("start, enrolled info vector size:%{public}zu", secUserInfo.enrolledInfo.size()); + IAM_LOGI("start, enrolled info vector size:%{public}zu", ipcSecUserInfo.enrolledInfo.size()); if (getSecInfoCallback_ == nullptr) { IAM_LOGE("getSecInfoCallback_ is nullptr"); - return; + return GENERAL_ERROR; + } + + SecUserInfo secUserInfo = {}; + secUserInfo.secureUid = ipcSecUserInfo.secureUid; + for (auto &iter : ipcSecUserInfo.enrolledInfo) { + EnrolledInfo enrolledInfo; + enrolledInfo.authType = static_cast(iter.authType); + enrolledInfo.enrolledId = iter.enrolledId; + secUserInfo.enrolledInfo.push_back(enrolledInfo); } + getSecInfoCallback_->OnSecUserInfo(resultCode, secUserInfo); + return SUCCESS; +} - getSecInfoCallback_->OnSecUserInfo(result, secUserInfo); +int32_t IdmGetSecureUserInfoCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t IdmGetSecureUserInfoCallbackService::CallbackExit([[maybe_unused]] uint32_t code, + [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/src/user_idm_client_impl.cpp b/frameworks/native/client/src/user_idm_client_impl.cpp index 2a61afbb8a4aa9308e64e15150df235206ddd547..2b75dc535073be6c2ce68a3ce60a01ad2e613434 100644 --- a/frameworks/native/client/src/user_idm_client_impl.cpp +++ b/frameworks/native/client/src/user_idm_client_impl.cpp @@ -18,7 +18,9 @@ #include "system_ability_definition.h" #include "callback_manager.h" +#include "event_listener_callback_service.h" #include "load_mode_client_util.h" +#include "iam_check.h" #include "iam_logger.h" #include "ipc_client_utils.h" #include "user_idm_callback_service.h" @@ -38,9 +40,9 @@ std::vector UserIdmClientImpl::OpenSession(int32_t userId) } std::vector challenge; - auto success = proxy->OpenSession(userId, challenge); - if (success != SUCCESS) { - IAM_LOGE("OpenSession ret = %{public}d", success); + auto ret = proxy->OpenSession(userId, challenge); + if (ret != SUCCESS) { + IAM_LOGE("OpenSession ret = %{public}d", ret); } return challenge; @@ -55,7 +57,10 @@ void UserIdmClientImpl::CloseSession(int32_t userId) return; } - proxy->CloseSession(userId); + auto ret = proxy->CloseSession(userId); + if (ret != SUCCESS) { + IAM_LOGE("CloseSession ret = %{public}d", ret); + } } void UserIdmClientImpl::AddCredential(int32_t userId, const CredentialParameters ¶, @@ -75,18 +80,22 @@ void UserIdmClientImpl::AddCredential(int32_t userId, const CredentialParameters return; } - sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); + sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; callback->OnResult(GENERAL_ERROR, extraInfo); return; } - UserIdmInterface::CredentialPara credPara = {}; - credPara.authType = para.authType; - credPara.pinType = para.pinType.value_or(PIN_SIX); + IpcCredentialPara credPara = {}; + credPara.authType = static_cast(para.authType); + credPara.pinType = static_cast(para.pinType.value_or(PIN_SIX)); credPara.token = std::move(para.token); - proxy->AddCredential(userId, credPara, wrapper, false); + auto ret = proxy->AddCredential(userId, credPara, wrapper, false); + if (ret != SUCCESS) { + IAM_LOGE("AddCredential fail, ret:%{public}d", ret); + return; + } } void UserIdmClientImpl::UpdateCredential(int32_t userId, const CredentialParameters ¶, @@ -108,18 +117,22 @@ void UserIdmClientImpl::UpdateCredential(int32_t userId, const CredentialParamet return; } - sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); + sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; callback->OnResult(GENERAL_ERROR, extraInfo); return; } - UserIdmInterface::CredentialPara credPara = {}; - credPara.authType = para.authType; - credPara.pinType = para.pinType.value_or(PIN_SIX); + IpcCredentialPara credPara = {}; + credPara.authType = static_cast(para.authType); + credPara.pinType = static_cast(para.pinType.value_or(PIN_SIX)); credPara.token = std::move(para.token); - proxy->UpdateCredential(userId, credPara, wrapper); + auto ret = proxy->UpdateCredential(userId, credPara, wrapper); + if (ret != SUCCESS) { + IAM_LOGE("UpdateCredential fail, ret:%{public}d", ret); + return; + } } int32_t UserIdmClientImpl::Cancel(int32_t userId) @@ -150,14 +163,18 @@ void UserIdmClientImpl::DeleteCredential(int32_t userId, uint64_t credentialId, return; } - sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); + sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; callback->OnResult(GENERAL_ERROR, extraInfo); return; } - proxy->DelCredential(userId, credentialId, authToken, wrapper); + auto ret = proxy->DelCredential(userId, credentialId, authToken, wrapper); + if (ret != SUCCESS) { + IAM_LOGE("DelCredential fail, ret:%{public}d", ret); + return; + } } void UserIdmClientImpl::DeleteUser(int32_t userId, const std::vector &authToken, @@ -176,14 +193,18 @@ void UserIdmClientImpl::DeleteUser(int32_t userId, const std::vector &a return; } - sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); + sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; callback->OnResult(GENERAL_ERROR, extraInfo); return; } - proxy->DelUser(userId, authToken, wrapper); + auto ret = proxy->DelUser(userId, authToken, wrapper); + if (ret != SUCCESS) { + IAM_LOGE("DelUser fail, ret:%{public}d", ret); + return; + } } int32_t UserIdmClientImpl::EraseUser(int32_t userId, const std::shared_ptr &callback) @@ -200,7 +221,7 @@ int32_t UserIdmClientImpl::EraseUser(int32_t userId, const std::shared_ptrOnResult(GENERAL_ERROR, extraInfo); return GENERAL_ERROR; } - sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); + sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; @@ -226,7 +247,7 @@ int32_t UserIdmClientImpl::GetCredentialInfo(int32_t userId, AuthType authType, return GENERAL_ERROR; } - sptr wrapper(new (std::nothrow) IdmGetCredInfoCallbackService(callback)); + sptr wrapper(new (std::nothrow) IdmGetCredInfoCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); std::vector infoList; @@ -254,7 +275,7 @@ int32_t UserIdmClientImpl::GetSecUserInfo(int32_t userId, const std::shared_ptr< return result; } - sptr wrapper( + sptr wrapper( new (std::nothrow) IdmGetSecureUserInfoCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); @@ -265,7 +286,7 @@ int32_t UserIdmClientImpl::GetSecUserInfo(int32_t userId, const std::shared_ptr< return proxy->GetSecInfo(userId, wrapper); } -sptr UserIdmClientImpl::GetProxy() +sptr UserIdmClientImpl::GetProxy() { std::lock_guard lock(mutex_); if (proxy_ != nullptr) { @@ -282,7 +303,7 @@ sptr UserIdmClientImpl::GetProxy() return proxy_; } - proxy_ = iface_cast(obj); + proxy_ = iface_cast(obj); deathRecipient_ = dr; return proxy_; } @@ -321,7 +342,7 @@ void UserIdmClientImpl::ClearRedundancyCredential(const std::shared_ptr wrapper(new (std::nothrow) IdmCallbackService(callback)); + sptr wrapper(new (std::nothrow) IdmCallbackService(callback)); if (wrapper == nullptr) { IAM_LOGE("failed to create wrapper"); Attributes extraInfo; @@ -329,7 +350,62 @@ void UserIdmClientImpl::ClearRedundancyCredential(const std::shared_ptrClearRedundancyCredential(wrapper); + auto ret = proxy->ClearRedundancyCredential(wrapper); + if (ret != SUCCESS) { + IAM_LOGE("ClearRedundancyCredential fail, ret:%{public}d", ret); + return; + } +} + +int32_t UserIdmClientImpl::RegistCredChangeEventListener(const std::vector &authTypes, + const std::shared_ptr &listener) +{ + IAM_LOGI("start"); + + auto proxy = GetProxy(); + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); + + return EventListenerCallbackManager::GetInstance().AddCredChangeEventListener(proxy, authTypes, listener); +} + +int32_t UserIdmClientImpl::UnRegistCredChangeEventListener(const std::shared_ptr &listener) +{ + IAM_LOGI("start"); + + auto proxy = GetProxy(); + IF_FALSE_LOGE_AND_RETURN_VAL(proxy != nullptr, GENERAL_ERROR); + + return EventListenerCallbackManager::GetInstance().RemoveCredChangeEventListener(proxy, listener); +} + +int32_t UserIdmClientImpl::GetCredentialInfoSync(int32_t userId, AuthType authType, + std::vector &credentialInfoList) +{ + IAM_LOGI("start, userId:%{public}d authType:%{public}d", userId, authType); + auto proxy = GetProxy(); + if (!proxy) { + IAM_LOGE("proxy is nullptr"); + return GENERAL_ERROR; + } + + std::vector ipcCredInfoList; + auto ret = proxy->GetCredentialInfoSync(userId, authType, ipcCredInfoList); + if (ret != SUCCESS) { + IAM_LOGE("GetCredentialInfoSync fail, ret:%{public}d", ret); + return GENERAL_ERROR; + } + + for (auto &iter : ipcCredInfoList) { + CredentialInfo credentialInfo; + credentialInfo.authType = static_cast(iter.authType); + credentialInfo.pinType = static_cast(iter.pinType); + credentialInfo.credentialId = iter.credentialId; + credentialInfo.templateId = iter.credentialId; + credentialInfoList.push_back(credentialInfo); + } + + IAM_LOGI("GetCredentialInfoSync success, credential num:%{public}zu", credentialInfoList.size()); + return SUCCESS; } void UserIdmClientImpl::UserIdmImplDeathRecipient::OnRemoteDied(const wptr &remote) @@ -340,6 +416,7 @@ void UserIdmClientImpl::UserIdmImplDeathRecipient::OnRemoteDied(const wptr(this)); } -void WidgetCallbackService::SendCommand(const std::string &cmdData) +int32_t WidgetCallbackService::SendCommand(const std::string &cmdData) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (widgetCallback_ == nullptr) { IAM_LOGE("both widget callback is nullptr"); - return; + return GENERAL_ERROR; } widgetCallback_->SendCommand(cmdData); iamHitraceHelper_= nullptr; + return SUCCESS; +} + +int32_t WidgetCallbackService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t WidgetCallbackService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/client/user_auth_client_map b/frameworks/native/client/user_auth_client_map index c111f630bdf6b9e655e9725eca8f9cc93c93596f..c2c807fbaced2873047f0dfb2dc063012ba931af 100644 --- a/frameworks/native/client/user_auth_client_map +++ b/frameworks/native/client/user_auth_client_map @@ -28,7 +28,6 @@ OHOS::UserIam::UserAuth::UserIdmClient::GetInstance*; OHOS::UserIam::UserAuth::Attributes*; OHOS::UserIam::UserAuth::UserAuthClientImpl::GetEnrolledState*; - OHOS::UserIam::UserAuth::AuthEventListenerStub::OnRemoteRequest*; OHOS::UserIam::UserAuth::UserAccessCtrlClient::GetInstance*; OHOS::UserIam::UserAuth::UserAuthNapiClientImpl::Instance*; OHOS::UserIam::UserAuth::UserAuthNapiClientImpl::BeginWidgetAuth*; diff --git a/frameworks/native/common/dfx/inc/hisysevent_adapter.h b/frameworks/native/common/dfx/inc/hisysevent_adapter.h index 27cc37f92fd94d8ff276f283365321ce96e23ab7..6472834e4da4294009d0178da14a4bfb552cd998 100644 --- a/frameworks/native/common/dfx/inc/hisysevent_adapter.h +++ b/frameworks/native/common/dfx/inc/hisysevent_adapter.h @@ -104,6 +104,16 @@ struct RemoteConnectFaultTrace { bool ack = false; }; +struct SaLoadDriverFailureTrace { + int32_t errCode = -1; +}; + +struct IsCredentialEnrolledMismatchTrace { + int32_t authType = 0; + bool preStatus = false; + bool updatedStatus = false; +}; + void ReportSystemFault(const std::string &timeString, const std::string &moduleName); void ReportSecurityTemplateChange(const TemplateChangeTrace &info); void ReportBehaviorCredManager(const UserCredManagerTrace &info); @@ -113,6 +123,8 @@ void ReportSecurityUserAuthFwk(const UserAuthFwkTrace &info); void ReportRemoteExecuteProc(const RemoteExecuteTrace &info); void ReportRemoteConnectOpen(const RemoteConnectOpenTrace &info); void ReportConnectFaultTrace(const RemoteConnectFaultTrace &info); +void ReportSaLoadDriverFailure(const SaLoadDriverFailureTrace &info); +void ReportIsCredentialEnrolledMismatch(const IsCredentialEnrolledMismatchTrace &info); } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/frameworks/native/common/dfx/src/hisysevent_adapter.cpp b/frameworks/native/common/dfx/src/hisysevent_adapter.cpp index ce3b913fc25e4ea13e67b9ca54b451bbcd123cf4..099bbc3acb7a65c82533413a2756f16f91bed37c 100644 --- a/frameworks/native/common/dfx/src/hisysevent_adapter.cpp +++ b/frameworks/native/common/dfx/src/hisysevent_adapter.cpp @@ -59,15 +59,18 @@ constexpr char STR_SOCKET_ID[] = "SOCKET_ID"; constexpr char STR_AUTH_FINISH_REASON[] = "AUTH_FINISH_REASON"; constexpr char STR_OPERATION_TIME[] = "OPERATION_TIME"; constexpr char STR_IS_BACKGROUND_APPLICATION[] = "IS_BACKGROUND_APPLICATION"; +constexpr char STR_ERROR_CODE[] = "ERROR_CODE"; +constexpr char STR_PREVIOUS_STATUS[] = "PREVIOUS_STATUS"; +constexpr char STR_UPDATED_STATUS[] = "UPDATED_STATUS"; static std::string MaskForStringId(const std::string &id) { - const int32_t MASK_WIDTH = 2; - const int32_t STRING_ID_LENGTH = 64; - if (id.length() != STRING_ID_LENGTH) { + const int32_t maskWidth = 2; + const int32_t stringIdLength = 64; + if (id.length() != stringIdLength) { return "****"; } - return id.substr(0, MASK_WIDTH) + "**" + id.substr(id.length() - MASK_WIDTH, id.length()); + return id.substr(0, maskWidth) + "**" + id.substr(id.length() - maskWidth, id.length()); } void ReportSystemFault(const std::string &timeString, const std::string &moduleName) @@ -218,6 +221,28 @@ void ReportConnectFaultTrace(const RemoteConnectFaultTrace &info) << ", messageSeq" << "ack:" << info.ack; ReportSystemFault(Common::GetNowTimeString(), ss.str()); } + +void ReportSaLoadDriverFailure(const SaLoadDriverFailureTrace &info) +{ + int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "SA_LOAD_DRIVER_FAILURE", + HiSysEvent::EventType::FAULT, + STR_ERROR_CODE, info.errCode); + if (ret != 0) { + IAM_LOGE("hisysevent write failed! ret %{public}d", ret); + } +} + +void ReportIsCredentialEnrolledMismatch(const IsCredentialEnrolledMismatchTrace &info) +{ + int32_t ret = HiSysEventWrite(HiSysEvent::Domain::USERIAM_FWK, "IS_CREDENTIAL_ENROLLED_MISMATCH", + HiSysEvent::EventType::STATISTIC, + STR_AUTH_TYPE, info.authType, + STR_PREVIOUS_STATUS, info.preStatus, + STR_UPDATED_STATUS, info.updatedStatus); + if (ret != 0) { + IAM_LOGE("hisysevent write failed! ret %{public}d", ret); + } +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/executors/include/framework/framework_executor_callback.h b/frameworks/native/executors/include/framework/framework_executor_callback.h index 79e020a1cfe8310076dedf5cd922e828605bd558..33052d24a20c7504da2100b1d1e62d9e38e8803f 100644 --- a/frameworks/native/executors/include/framework/framework_executor_callback.h +++ b/frameworks/native/executors/include/framework/framework_executor_callback.h @@ -26,7 +26,7 @@ #include "co_auth_client_callback.h" #include "executor.h" #include "iam_common_defines.h" -#include "executor_messenger_interface.h" +#include "iexecutor_messenger.h" namespace OHOS { namespace UserIam { diff --git a/frameworks/native/executors/src/async_command/async_command_base.cpp b/frameworks/native/executors/src/async_command/async_command_base.cpp index a030d5a941733161990535f6c2941adec6605cac..adc44347e4e0513c1bd68ae017e196bdf0042168 100644 --- a/frameworks/native/executors/src/async_command/async_command_base.cpp +++ b/frameworks/native/executors/src/async_command/async_command_base.cpp @@ -54,7 +54,7 @@ void AsyncCommandBase::OnHdiDisconnect() ResultCode AsyncCommandBase::StartProcess() { - IAM_LOGI("%{public}s start process", GetDescription()); + IAM_LOGD("%{public}s start process", GetDescription()); auto executor = executor_.lock(); if (executor == nullptr) { IAM_LOGE("%{public}s executor has been released, start process fail", GetDescription()); @@ -100,7 +100,7 @@ void AsyncCommandBase::OnAcquireInfo(int32_t acquire, const std::vector void AsyncCommandBase::OnAcquireInfoInner(int32_t acquire, const std::vector &extraInfo) { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); Attributes attr; bool setAcquireRet = attr.SetInt32Value(Attributes::ATTR_TIP_INFO, acquire); @@ -163,7 +163,7 @@ int32_t AsyncCommandBase::GetAuthType() void AsyncCommandBase::EndProcess() { - IAM_LOGI("%{public}s end process", GetDescription()); + IAM_LOGD("%{public}s end process", GetDescription()); auto executor = executor_.lock(); if (executor == nullptr) { IAM_LOGI( diff --git a/frameworks/native/executors/src/async_command/auth_command.cpp b/frameworks/native/executors/src/async_command/auth_command.cpp index b2d5357ea2ba706c606614593495d63a8b2e3b1b..d8d3e755a05675d249507bc9130a64e3e74a7cd2 100644 --- a/frameworks/native/executors/src/async_command/auth_command.cpp +++ b/frameworks/native/executors/src/async_command/auth_command.cpp @@ -37,7 +37,7 @@ AuthCommand::AuthCommand(std::weak_ptr executor, uint64_t scheduleId, ResultCode AuthCommand::SendRequest() { - IAM_LOGI("%{public}s send request start", GetDescription()); + IAM_LOGD("%{public}s send request start", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR); auto hdi = GetExecutorHdi(); @@ -55,7 +55,7 @@ ResultCode AuthCommand::SendRequest() std::vector extraInfo; bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo); IF_FALSE_LOGE_AND_RETURN_VAL(getExtraInfoRet == true, ResultCode::GENERAL_ERROR); - IAM_LOGI("%{public}s auth message len %{public}zu", GetDescription(), extraInfo.size()); + IAM_LOGD("%{public}s auth message len %{public}zu", GetDescription(), extraInfo.size()); int32_t authIntent; bool getAuthIntent = attributes_->GetInt32Value(Attributes::ATTR_AUTH_INTENTION, authIntent); @@ -69,13 +69,13 @@ ResultCode AuthCommand::SendRequest() ResultCode ret = hdi->Authenticate(scheduleId_, (AuthenticateParam) { tokenId, templateIdList, extraInfo, endAfterFirstFail, authIntent, userId}, shared_from_this()); - IAM_LOGI("%{public}s authenticate result %{public}d", GetDescription(), ret); + IAM_LOGD("%{public}s authenticate result %{public}d", GetDescription(), ret); return ret; } void AuthCommand::OnResultInner(ResultCode result, const std::vector &extraInfo) { - IAM_LOGI("%{public}s on result start", GetDescription()); + IAM_LOGD("%{public}s on result start", GetDescription()); std::vector nonConstExtraInfo(extraInfo.begin(), extraInfo.end()); auto authAttributes = Common::MakeShared(); @@ -91,7 +91,7 @@ void AuthCommand::OnResultInner(ResultCode result, const std::vector &e IAM_LOGE("%{public}s call finish fail", GetDescription()); return; } - IAM_LOGI("%{public}s call finish success result %{public}d", GetDescription(), result); + IAM_LOGD("%{public}s call finish success result %{public}d", GetDescription(), result); } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/executors/src/async_command/collect_command.cpp b/frameworks/native/executors/src/async_command/collect_command.cpp index 4911d692794cfe1126481520a177c637e40d584d..d03ccff01c9476e103c5b4387f377428260f7c5a 100644 --- a/frameworks/native/executors/src/async_command/collect_command.cpp +++ b/frameworks/native/executors/src/async_command/collect_command.cpp @@ -37,7 +37,7 @@ CollectCommand::CollectCommand(std::weak_ptr executor, uint64_t schedu ResultCode CollectCommand::SendRequest() { - IAM_LOGI("%{public}s send request start", GetDescription()); + IAM_LOGD("%{public}s send request start", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR); auto hdi = GetExecutorHdi(); @@ -49,17 +49,17 @@ ResultCode CollectCommand::SendRequest() std::vector extraInfo; bool getExtraInfoRet = attributes_->GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, extraInfo); IF_FALSE_LOGE_AND_RETURN_VAL(getExtraInfoRet == true, ResultCode::GENERAL_ERROR); - IAM_LOGI("%{public}s collect message len %{public}zu", GetDescription(), extraInfo.size()); + IAM_LOGD("%{public}s collect message len %{public}zu", GetDescription(), extraInfo.size()); IamHitraceHelper traceHelper("hdi collect"); ResultCode ret = hdi->Collect(scheduleId_, (CollectParam) { 0, collectorTokenId, extraInfo }, shared_from_this()); - IAM_LOGI("%{public}s collect result %{public}d", GetDescription(), ret); + IAM_LOGD("%{public}s collect result %{public}d", GetDescription(), ret); return ret; } void CollectCommand::OnResultInner(ResultCode result, const std::vector &extraInfo) { - IAM_LOGI("%{public}s on result start", GetDescription()); + IAM_LOGD("%{public}s on result start", GetDescription()); std::vector nonConstExtraInfo(extraInfo.begin(), extraInfo.end()); auto authAttributes = Common::MakeShared(); @@ -75,7 +75,7 @@ void CollectCommand::OnResultInner(ResultCode result, const std::vector IAM_LOGE("%{public}s call finish fail", GetDescription()); return; } - IAM_LOGI("%{public}s call finish success result %{public}d", GetDescription(), result); + IAM_LOGD("%{public}s call finish success result %{public}d", GetDescription(), result); } } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/executors/src/async_command/custom_command.cpp b/frameworks/native/executors/src/async_command/custom_command.cpp index 112c8b952e4c31236e2fff0ba90255dfc5b11379..0a49f6abc37e82165749e22809b91c96f1ebc6fc 100644 --- a/frameworks/native/executors/src/async_command/custom_command.cpp +++ b/frameworks/native/executors/src/async_command/custom_command.cpp @@ -41,7 +41,7 @@ CustomCommand::CustomCommand(std::weak_ptr executor, const Attributes ResultCode CustomCommand::SendRequest() { - IAM_LOGI("%{public}s send request start", GetDescription()); + IAM_LOGD("%{public}s send request start", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR); auto hdi = GetExecutorHdi(); @@ -63,13 +63,13 @@ ResultCode CustomCommand::SendRequest() return ret; } - IAM_LOGI("%{public}s send command result success", GetDescription()); + IAM_LOGD("%{public}s send command result success", GetDescription()); return ResultCode::SUCCESS; } void CustomCommand::OnResultInner(ResultCode result, const std::vector &extraInfo) { - IAM_LOGI("%{public}s on result start", GetDescription()); + IAM_LOGD("%{public}s on result start", GetDescription()); SetResult(result); } @@ -89,14 +89,14 @@ ResultCode CustomCommand::GetResult() IAM_LOGE("%{public}s get result before request send, error", GetDescription()); return ResultCode::GENERAL_ERROR; } - IAM_LOGI("%{public}s begin wait future", GetDescription()); + IAM_LOGD("%{public}s begin wait future", GetDescription()); static const std::chrono::seconds maxWaitTime(1); auto ret = future_.wait_for(maxWaitTime); if (ret != std::future_status::ready) { IAM_LOGE("%{public}s future timeout", GetDescription()); return ResultCode::TIMEOUT; } - IAM_LOGI("%{public}s get result %{public}d", GetDescription(), result_); + IAM_LOGD("%{public}s get result %{public}d", GetDescription(), result_); return result_; } diff --git a/frameworks/native/executors/src/async_command/enroll_command.cpp b/frameworks/native/executors/src/async_command/enroll_command.cpp index 31c2d3a65aa7adc6f9de95a7ee1c80364ded107a..8110f7eb651fdaca74557e906381a25188019a92 100644 --- a/frameworks/native/executors/src/async_command/enroll_command.cpp +++ b/frameworks/native/executors/src/async_command/enroll_command.cpp @@ -39,7 +39,7 @@ EnrollCommand::EnrollCommand(std::weak_ptr executor, uint64_t schedule ResultCode EnrollCommand::SendRequest() { - IAM_LOGI("%{public}s send request start", GetDescription()); + IAM_LOGD("%{public}s send request start", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR); auto hdi = GetExecutorHdi(); @@ -65,7 +65,7 @@ ResultCode EnrollCommand::SendRequest() void EnrollCommand::OnResultInner(ResultCode result, const std::vector &extraInfo) { - IAM_LOGI("%{public}s on result start", GetDescription()); + IAM_LOGD("%{public}s on result start", GetDescription()); TemplateChangeTrace info = {}; info.scheduleId = scheduleId_; info.executorType = GetAuthType(); diff --git a/frameworks/native/executors/src/async_command/identify_command.cpp b/frameworks/native/executors/src/async_command/identify_command.cpp index 70f9796ea4dc19459e89ba656d0781481685ca6e..5ca2b2be29960051758e114ebbff91207e50a76b 100644 --- a/frameworks/native/executors/src/async_command/identify_command.cpp +++ b/frameworks/native/executors/src/async_command/identify_command.cpp @@ -35,7 +35,7 @@ IdentifyCommand::IdentifyCommand(std::weak_ptr executor, uint64_t sche ResultCode IdentifyCommand::SendRequest() { - IAM_LOGI("%{public}s send request start", GetDescription()); + IAM_LOGD("%{public}s send request start", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(attributes_ != nullptr, ResultCode::GENERAL_ERROR); auto hdi = GetExecutorHdi(); @@ -57,7 +57,7 @@ ResultCode IdentifyCommand::SendRequest() void IdentifyCommand::OnResultInner(ResultCode result, const std::vector &extraInfo) { - IAM_LOGI("%{public}s on result start", GetDescription()); + IAM_LOGD("%{public}s on result start", GetDescription()); std::vector nonConstExtraInfo(extraInfo.begin(), extraInfo.end()); auto authAttributes = Common::MakeShared(); diff --git a/frameworks/native/executors/src/executor.cpp b/frameworks/native/executors/src/executor.cpp index d11935af56fba9d2ec6033fc3911d9b1949f2a51..7e4e11e7e40f15244b4c025c0fb5b6c154549a2f 100644 --- a/frameworks/native/executors/src/executor.cpp +++ b/frameworks/native/executors/src/executor.cpp @@ -138,7 +138,7 @@ void Executor::UnregisterExecutorCallback() void Executor::AddCommand(std::shared_ptr command) { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); IF_FALSE_LOGE_AND_RETURN(command != nullptr); std::lock_guard lock(mutex_); command2Respond_.insert(command); @@ -146,7 +146,7 @@ void Executor::AddCommand(std::shared_ptr command) void Executor::RemoveCommand(std::shared_ptr command) { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); std::lock_guard lock(mutex_); command2Respond_.erase(command); } diff --git a/frameworks/native/executors/src/framework/framework_executor_callback.cpp b/frameworks/native/executors/src/framework/framework_executor_callback.cpp index 9ebc150729269b1fc262574aa16baeceea3ab7d7..43db9e7fa23870a6002692e875125e3762e66dd7 100644 --- a/frameworks/native/executors/src/framework/framework_executor_callback.cpp +++ b/frameworks/native/executors/src/framework/framework_executor_callback.cpp @@ -62,7 +62,7 @@ ResultCode FrameworkExecutorCallback::OnBeginExecuteInner(uint64_t scheduleId, s commandAttrs.GetInt32Value(Attributes::ATTR_SCHEDULE_MODE, commandId); IF_FALSE_LOGE_AND_RETURN_VAL(getScheduleModeRet == true, ResultCode::GENERAL_ERROR); - IAM_LOGI("%{public}s start process cmd %{public}u", GetDescription(), commandId); + IAM_LOGD("%{public}s start process cmd %{public}u", GetDescription(), commandId); ResultCode ret = ResultCode::GENERAL_ERROR; switch (commandId) { case ENROLL: @@ -78,7 +78,7 @@ ResultCode FrameworkExecutorCallback::OnBeginExecuteInner(uint64_t scheduleId, s IAM_LOGE("command id %{public}u is not supported", commandId); } - IAM_LOGI("command id = %{public}u ret = %{public}d", commandId, ret); + IAM_LOGD("command id = %{public}u ret = %{public}d", commandId, ret); return ret; } @@ -98,7 +98,7 @@ ResultCode FrameworkExecutorCallback::OnEndExecuteInner(uint64_t scheduleId, con void FrameworkExecutorCallback::OnMessengerReady(const std::shared_ptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); std::lock_guard lock(mutex_); auto executor = executor_.lock(); if (executor == nullptr) { @@ -123,7 +123,7 @@ ResultCode FrameworkExecutorCallback::OnSetPropertyInner(const Attributes &prope bool getAuthPropertyModeRet = properties.GetUint32Value(Attributes::ATTR_PROPERTY_MODE, commandId); IF_FALSE_LOGE_AND_RETURN_VAL(getAuthPropertyModeRet == true, ResultCode::GENERAL_ERROR); - IAM_LOGI("%{public}s start process cmd %{public}u", GetDescription(), commandId); + IAM_LOGD("%{public}s start process cmd %{public}u", GetDescription(), commandId); ResultCode ret; if (commandId == PROPERTY_MODE_DEL) { ret = ProcessDeleteTemplateCommand(properties); @@ -171,7 +171,7 @@ int32_t FrameworkExecutorCallback::OnSendData(uint64_t scheduleId, const Attribu ResultCode FrameworkExecutorCallback::OnGetPropertyInner(std::shared_ptr conditions, std::shared_ptr values) { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(conditions != nullptr, ResultCode::GENERAL_ERROR); IF_FALSE_LOGE_AND_RETURN_VAL(values != nullptr, ResultCode::GENERAL_ERROR); uint32_t commandId = 0; @@ -184,7 +184,7 @@ ResultCode FrameworkExecutorCallback::OnGetPropertyInner(std::shared_ptr conditions, std::shared_ptr values) { - IAM_LOGI("start"); + IAM_LOGD("start"); IF_FALSE_LOGE_AND_RETURN_VAL(conditions != nullptr, ResultCode::GENERAL_ERROR); IF_FALSE_LOGE_AND_RETURN_VAL(values != nullptr, ResultCode::GENERAL_ERROR); auto executor = executor_.lock(); diff --git a/frameworks/native/ipc/BUILD.gn b/frameworks/native/ipc/BUILD.gn index 03e969adbad8c4a01c353c5b301e08823240b92a..a7b7b02c3e3fdd84d5f16cf56009c56792483e68 100644 --- a/frameworks/native/ipc/BUILD.gn +++ b/frameworks/native/ipc/BUILD.gn @@ -11,15 +11,46 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/idl_tool/idl.gni") import("//build/ohos.gni") config("userauth_client_ipc_config") { include_dirs = [ "inc", "common_defines", + "${target_gen_dir}", ] } +idl_gen_interface("auth_user_ipc_interface") { + sources = [ + "idl/ICoAuth.idl", + "idl/IUserAuth.idl", + "idl/IUserIdm.idl", + ] + + sources_common = [ "UserAuthTypes.idl" ] + + sources_callback = [ + "IExecutorCallback.idl", + "IExecutorMessenger.idl", + "IEventListenerCallback.idl", + "IGetExecutorPropertyCallback.idl", + "IIamCallback.idl", + "IIdmGetCredInfoCallback.idl", + "IIdmGetSecureUserInfoCallback.idl", + "IModalCallback.idl", + "ISetExecutorPropertyCallback.idl", + "IVerifyTokenCallback.idl", + "IWidgetCallback.idl", + ] + + log_domainid = "0xD002401" + log_tag = "USER_AUTH_SA" + subsystem_name = "useriam" + part_name = "user_auth_framework" +} + ohos_source_set("userauth_client_ipc") { sanitize = { integer_overflow = true @@ -37,19 +68,29 @@ ohos_source_set("userauth_client_ipc") { "../../../interfaces/inner_api", ] - sources = [ - "src/co_auth_proxy.cpp", - "src/executor_callback_stub.cpp", - "src/executor_messenger_proxy.cpp", - "src/modal_callback_stub.cpp", - "src/user_access_ctrl_callback_stub.cpp", - "src/user_auth_callback_stub.cpp", - "src/user_auth_event_listener_stub.cpp", - "src/user_auth_proxy.cpp", - "src/user_idm_callback_stub.cpp", - "src/user_idm_proxy.cpp", - "src/widget_callback_stub.cpp", - ] + output_file_path = get_target_outputs(":auth_user_ipc_interface") + sources = filter_include(output_file_path, [ "*co_auth_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*event_listener_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*executor_callback_stub.cpp" ]) + sources += + filter_include(output_file_path, [ "*executor_messenger_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*iam_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*user_idm_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*widget_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*modal_callback_stub.cpp" ]) + sources += + filter_include(output_file_path, [ "*verify_token_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*get_executor_property_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*set_executor_property_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_cred_info_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_secure_user_info_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_types.cpp" ]) configs = [ "../../../common:iam_log_config", @@ -59,6 +100,8 @@ ohos_source_set("userauth_client_ipc") { public_configs = [ ":userauth_client_ipc_config" ] remove_configs = [ "//build/config/compiler:no_exceptions" ] + deps = [ ":auth_user_ipc_interface" ] + external_deps = [ "c_utils:utils", "hilog:libhilog", @@ -86,20 +129,182 @@ ohos_source_set("userauth_service_ipc") { "../../../interfaces/inner_api", ] - sources = [ - "src/co_auth_stub.cpp", - "src/executor_callback_proxy.cpp", - "src/executor_messenger_stub.cpp", - "src/modal_callback_proxy.cpp", - "src/user_access_ctrl_callback_proxy.cpp", - "src/user_auth_callback_proxy.cpp", - "src/user_auth_event_listener_proxy.cpp", - "src/user_auth_stub.cpp", - "src/user_idm_callback_proxy.cpp", - "src/user_idm_stub.cpp", - "src/widget_callback_proxy.cpp", + output_file_path = get_target_outputs(":auth_user_ipc_interface") + sources = filter_include(output_file_path, [ "*co_auth_stub.cpp" ]) + sources += + filter_include(output_file_path, [ "*event_listener_callback_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*executor_callback_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*executor_messenger_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*modal_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*user_access_ctrl_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*iam_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*user_idm_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*widget_callback_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*verify_token_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*get_executor_property_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*set_executor_property_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_cred_info_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_secure_user_info_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_types.cpp" ]) + + configs = [ + "../../../common:iam_log_config", + "../../../common:iam_utils_config", + ] + + public_configs = [ ":userauth_client_ipc_config" ] + remove_configs = [ "//build/config/compiler:no_exceptions" ] + + deps = [ ":auth_user_ipc_interface" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + ] + + subsystem_name = "useriam" + part_name = "user_auth_framework" +} + +ohos_source_set("iam_inner_api") { + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + blocklist = "../../../cfi_blocklist.txt" + } + branch_protector_ret = "pac_ret" + include_dirs = [ + "inc", + "common_defines", + "../../../interfaces/inner_api", + ] + + output_file_path = get_target_outputs(":auth_user_ipc_interface") + sources = filter_include(output_file_path, [ "*.cpp" ]) + + configs = [ + "../../../common:iam_log_config", + "../../../common:iam_utils_config", + ] + + public_configs = [ ":userauth_client_ipc_config" ] + remove_configs = [ "//build/config/compiler:no_exceptions" ] + + deps = [ ":auth_user_ipc_interface" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", + ] + + subsystem_name = "useriam" + part_name = "user_auth_framework" +} + +ohos_source_set("userauth_client_ipc_fuzzer") { + branch_protector_ret = "pac_ret" + include_dirs = [ + "inc", + "common_defines", + "../../../interfaces/inner_api", + ] + + output_file_path = get_target_outputs(":auth_user_ipc_interface") + sources = filter_include(output_file_path, [ "*co_auth_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*event_listener_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*executor_callback_stub.cpp" ]) + sources += + filter_include(output_file_path, [ "*executor_messenger_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*user_auth_event_listener_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*iam_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*user_idm_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*widget_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*modal_callback_stub.cpp" ]) + sources += + filter_include(output_file_path, [ "*verify_token_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*get_executor_property_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*set_executor_property_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_cred_info_callback_stub.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_secure_user_info_callback_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_types.cpp" ]) + + configs = [ + "../../../common:iam_log_config", + "../../../common:iam_utils_config", + ] + + public_configs = [ ":userauth_client_ipc_config" ] + remove_configs = [ "//build/config/compiler:no_exceptions" ] + + deps = [ ":auth_user_ipc_interface" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_single", ] + subsystem_name = "useriam" + part_name = "user_auth_framework" +} + +ohos_source_set("userauth_service_ipc_fuzzer") { + branch_protector_ret = "pac_ret" + include_dirs = [ + "inc", + "common_defines", + "../../../interfaces/inner_api", + ] + + output_file_path = get_target_outputs(":auth_user_ipc_interface") + sources = filter_include(output_file_path, [ "*co_auth_stub.cpp" ]) + sources += + filter_include(output_file_path, [ "*event_listener_callback_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*executor_callback_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*executor_messenger_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*modal_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*user_access_ctrl_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*iam_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*user_idm_stub.cpp" ]) + sources += filter_include(output_file_path, [ "*widget_callback_proxy.cpp" ]) + sources += + filter_include(output_file_path, [ "*verify_token_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*get_executor_property_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*set_executor_property_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_cred_info_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, + [ "*idm_get_secure_user_info_callback_proxy.cpp" ]) + sources += filter_include(output_file_path, [ "*user_auth_types.cpp" ]) + configs = [ "../../../common:iam_log_config", "../../../common:iam_utils_config", @@ -108,6 +313,8 @@ ohos_source_set("userauth_service_ipc") { public_configs = [ ":userauth_client_ipc_config" ] remove_configs = [ "//build/config/compiler:no_exceptions" ] + deps = [ ":auth_user_ipc_interface" ] + external_deps = [ "c_utils:utils", "hilog:libhilog", diff --git a/frameworks/native/ipc/common_defines/co_auth_interface.h b/frameworks/native/ipc/common_defines/co_auth_interface.h index 05cfd869b578d8697c338dbe482cbc11f2de99d0..f93f93ecae791e573f3744948fbf0c810a1768cb 100644 --- a/frameworks/native/ipc/common_defines/co_auth_interface.h +++ b/frameworks/native/ipc/common_defines/co_auth_interface.h @@ -19,17 +19,16 @@ #include #include -#include "executor_callback_interface.h" +#include "iexecutor_callback.h" #include "iam_common_defines.h" -#include "co_auth_interface_ipc_interface_code.h" #include "iremote_broker.h" #include "refbase.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class CoAuthInterface : public IRemoteBroker { +class CoAuthInterface { public: struct ExecutorRegisterInfo { AuthType authType; @@ -42,10 +41,6 @@ public: std::string deviceUdid; std::vector signedRemoteExecutorInfo; }; - - virtual uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) = 0; - virtual void ExecutorUnregister(uint64_t executorIndex) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.CoAuth.ICoAuth"); }; } // namespace UserAuth } // namespace UserIam diff --git a/frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h deleted file mode 100644 index 89ad676464bba7ef5a55dd7d162bcc93c095857f..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/co_auth_interface_ipc_interface_code.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CO_AUTH_INTERFACE_IPC_INTERFACE_CODE_H -#define CO_AUTH_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 931 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum CoAuthInterfaceCode : uint32_t { - CO_AUTH_EXECUTOR_REGISTER = 0, - CO_AUTH_EXECUTOR_UNREGISTER = 1, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // CO_AUTH_INTERFACE_IPC_INTERFACE_CODE_H diff --git a/frameworks/native/ipc/common_defines/executor_callback_interface.h b/frameworks/native/ipc/common_defines/executor_callback_interface.h deleted file mode 100644 index 8bc5209e362cda30b3d3ba57f7a7c1bc84c8f749..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/executor_callback_interface.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_CALLBACK_INTERFACE_H -#define EXECUTOR_CALLBACK_INTERFACE_H - -#include - -#include "iremote_broker.h" - -#include "executor_messenger_interface.h" -#include "executor_callback_interface_ipc_interface_code.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ExecutorCallbackInterface : public IRemoteBroker { -public: - virtual void OnMessengerReady(sptr &messenger, - const std::vector &publicKey, const std::vector &templateIdList) = 0; - virtual int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) = 0; - virtual int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) = 0; - virtual int32_t OnSetProperty(const Attributes &properties) = 0; - virtual int32_t OnGetProperty(const Attributes &condition, Attributes &values) = 0; - virtual int32_t OnSendData(uint64_t scheduleId, const Attributes &data) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.AuthResPool.ExecutorCallback"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_CALLBACK_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/executor_callback_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/executor_callback_interface_ipc_interface_code.h deleted file mode 100644 index 67b773c9b9cafe5f1bc440a2bd39d063569f3503..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/executor_callback_interface_ipc_interface_code.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H -#define EXECUTOR_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 931 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum ExecutorCallbackInterfaceCode : uint32_t { - ON_MESSENGER_READY = 1, - ON_BEGIN_EXECUTE, - ON_END_EXECUTE, - ON_SET_PROPERTY, - ON_GET_PROPERTY, - ON_SEND_DATA, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H diff --git a/frameworks/native/ipc/common_defines/executor_messenger_interface.h b/frameworks/native/ipc/common_defines/executor_messenger_interface.h deleted file mode 100644 index 98e49cfe4765b529f02b4fe0514e74ce68ab797c..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/executor_messenger_interface.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_MESSENGER_INTERFACE_H -#define EXECUTOR_MESSENGER_INTERFACE_H - -#include "iremote_broker.h" - -#include "attributes.h" -#include "executor_messenger_interface_ipc_interface_code.h" -#include "iam_common_defines.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ExecutorMessengerInterface : public IRemoteBroker { -public: - virtual int32_t SendData(uint64_t scheduleId, ExecutorRole dstRole, - const std::vector &msg) = 0; - virtual int32_t Finish(uint64_t scheduleId, ResultCode resultCode, - const std::shared_ptr &finalResult) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.AuthResPool.IExecutor_Messenger"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_MESSENGER_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/executor_messenger_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/executor_messenger_interface_ipc_interface_code.h deleted file mode 100644 index e2c1df300663403b38ae74b989a083c8b84db56d..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/executor_messenger_interface_ipc_interface_code.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_MESSENGER_INTERFACE_IPC_INTERFACE_CODE_H -#define EXECUTOR_MESSENGER_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 931 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum ExecutorMessengerInterfaceCode : uint32_t { - CO_AUTH_SEND_DATA = 0, - CO_AUTH_FINISH, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_MESSENGER_INTERFACE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/iam_callback_interface.h b/frameworks/native/ipc/common_defines/iam_callback_interface.h deleted file mode 100644 index c0a22630828a7922f4b25b2694eee1b48d4e76e2..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/iam_callback_interface.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IAM_CALLBACK_INTERFACE_H -#define IAM_CALLBACK_INTERFACE_H - -#include - -#include "iremote_broker.h" - -#include "attributes.h" -#include "iam_common_defines.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class IamCallbackInterface : public IRemoteBroker { -public: - virtual void OnResult(int32_t result, const Attributes &extraInfo) = 0; - virtual void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) = 0; -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // IAM_CALLBACK_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/idm_callback_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/idm_callback_interface_ipc_interface_code.h deleted file mode 100644 index d57c3ed74144bd09e09921bcb0be9df88f342025..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/idm_callback_interface_ipc_interface_code.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IDM_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H -#define IDM_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 901 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum IdmCallbackInterfaceCode : uint32_t { - IDM_CALLBACK_ON_RESULT = 0, - IDM_CALLBACK_ON_ACQUIRE_INFO, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // IDM_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/idm_get_cred_info_callback_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/idm_get_cred_info_callback_interface_ipc_interface_code.h deleted file mode 100644 index 947f0891f80b067c61a98a3fe3922eaceba5b6c9..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/idm_get_cred_info_callback_interface_ipc_interface_code.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IDM_GET_CRED_INFO_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H -#define IDM_GET_CRED_INFO_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 901 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum IdmGetCredInfoCallbackInterfaceCode : uint32_t { - ON_GET_INFO = 0, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // IDM_GET_CRED_INFO_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/idm_get_secure_user_info_callback_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/idm_get_secure_user_info_callback_interface_ipc_interface_code.h deleted file mode 100644 index 2554e7aa53e548507f7f927a91894686b7598f1d..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/idm_get_secure_user_info_callback_interface_ipc_interface_code.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IDM_GET_SECURE_USER_INFO_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H -#define IDM_GET_SECURE_USER_INFO_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 901 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum IdmGetSecureUserInfoCallbackInterfaceCode : uint32_t { - ON_GET_SEC_INFO = 0, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // IDM_GET_SECURE_USER_INFO_CALLBACK_INTERFACE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/modal_callback_interface.h b/frameworks/native/ipc/common_defines/modal_callback_interface.h deleted file mode 100644 index f8376bc53fac93cee560b777fba1b0c547c8a7a0..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/modal_callback_interface.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MODAL_CALLBACK_INTERFACE_H -#define MODAL_CALLBACK_INTERFACE_H - -#include - -#include "iremote_broker.h" - -#include "iam_common_defines.h" -#include "user_auth_common_defines.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ModalCallbackInterface : public IRemoteBroker { -public: - virtual void SendCommand(uint64_t contextId, const std::string &cmdData) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.ModalCallback"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // MODAL_CALLBACK_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/user_access_ctrl_callback_interface.h b/frameworks/native/ipc/common_defines/user_access_ctrl_callback_interface.h deleted file mode 100644 index d2bcc1fd1cd339360b0b6c5662cb9d2e3cfbb4cd..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/user_access_ctrl_callback_interface.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_ACCESS_CTRL_CALLBACK_INTERFACE_H -#define USER_ACCESS_CTRL_CALLBACK_INTERFACE_H - -#include - -#include "iremote_broker.h" - -#include "attributes.h" -#include "iam_common_defines.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum UserAccessCtrlCallbackInterfaceCode : uint32_t { - ON_VERIFY_TOKEN_RESULT = 0, -}; - -class VerifyTokenCallbackInterface : public IRemoteBroker { -public: - /* - * returns token plaintext information. - */ - virtual void OnVerifyTokenResult(int32_t result, const Attributes &attributes) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAccessCtrl.VerifyTokenCallback"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_ACCESS_CTRL_CALLBACK_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/user_auth_callback_interface.h b/frameworks/native/ipc/common_defines/user_auth_callback_interface.h deleted file mode 100644 index f4aad05af3f5ac3a1ca897e67e60125d83dfc186..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/user_auth_callback_interface.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_CALLBACK_INTERFACE_H -#define USER_AUTH_CALLBACK_INTERFACE_H - -#include - -#include "iremote_broker.h" - -#include "attributes.h" -#include "iam_common_defines.h" -#include "iam_callback_interface.h" -#include "user_auth_common_defines.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserAuthCallbackInterface : public IamCallbackInterface { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.UserAuthCallback"); -}; - -class GetExecutorPropertyCallbackInterface : public IRemoteBroker { -public: - /* - * returns executor property information, such as remaining authentication times and remaining freezing time. - */ - virtual void OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.GetExecutorPropertyCallback"); -}; - -class SetExecutorPropertyCallbackInterface : public IRemoteBroker { -public: - /* - * returns a number value indicating whether the property setting was successful. - */ - virtual void OnSetExecutorPropertyResult(int32_t result) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.SetExecutorPropertyCallback"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_CALLBACK_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/user_auth_interface.h b/frameworks/native/ipc/common_defines/user_auth_interface.h deleted file mode 100644 index 37e3af8eca45d57d642c160cae11c4c44848dea8..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/user_auth_interface.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_INTERFACE_H -#define USER_AUTH_INTERFACE_H - -#include -#include - -#include "iremote_broker.h" -#include "refbase.h" - -#include "attributes.h" -#include "modal_callback_interface.h" -#include "user_access_ctrl_callback_interface.h" -#include "user_auth_callback_interface.h" -#include "user_auth_client_callback.h" -#include "user_auth_interface_ipc_interface_code.h" -#include "widget_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserAuthInterface : public IRemoteBroker { -public: - virtual int32_t GetAvailableStatus(int32_t apiVersion, int32_t userId, AuthType authType, - AuthTrustLevel authTrustLevel) = 0; - - virtual int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) = 0; - - virtual void GetProperty(int32_t userId, AuthType authType, - const std::vector &keys, sptr &callback) = 0; - - virtual void GetPropertyById(uint64_t credentialId, const std::vector &keys, - sptr &callback) = 0; - - virtual void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, - sptr &callback) = 0; - - virtual uint64_t AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, - sptr &callback) = 0; - - virtual uint64_t Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) = 0; - - virtual uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback, - sptr &modalCallback) = 0; - - virtual uint64_t Identify(const std::vector &challenge, AuthType authType, - sptr &callback) = 0; - - virtual int32_t CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) = 0; - - virtual int32_t GetVersion(int32_t &version) = 0; - - virtual int32_t Notice(NoticeType noticeType, const std::string &eventData) = 0; - - virtual int32_t RegisterWidgetCallback(int32_t version, sptr &callback) = 0; - - virtual int32_t GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState) = 0; - - virtual int32_t RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) = 0; - - virtual int32_t UnRegistUserAuthSuccessEventListener( - const sptr &listener) = 0; - - virtual int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) = 0; - - virtual int32_t PrepareRemoteAuth(const std::string &networkId, sptr &callback) = 0; - - virtual void VerifyAuthToken(const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.IUserAuth"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h deleted file mode 100644 index 8682b34f913ccd6816f4dc20c33cd528b24d9391..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/user_auth_interface_ipc_interface_code.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2023-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_INTERFACE_IPC_INTERFACE_CODE_H -#define USER_AUTH_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 921 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum UserAuthInterfaceCode : uint32_t { - USER_AUTH_GET_AVAILABLE_STATUS = 0, - USER_AUTH_GET_PROPERTY, - USER_AUTH_SET_PROPERTY, - USER_AUTH_AUTH, - USER_AUTH_AUTH_USER, - USER_AUTH_CANCEL_AUTH, - USER_AUTH_GET_VERSION, - USER_AUTH_ON_RESULT, - USER_AUTH_GET_EX_PROP, - USER_AUTH_SET_EX_PROP, - USER_AUTH_ACQUIRE_INFO, - USER_AUTH_IDENTIFY, - USER_AUTH_CANCEL_IDENTIFY, - USER_AUTH_ON_IDENTIFY_RESULT, - USER_AUTH_AUTH_WIDGET, - USER_AUTH_NOTICE, - USER_AUTH_ON_SEND_COMMAND, - USER_AUTH_REG_WIDGET_CB, - USER_AUTH_GET_ENROLLED_STATE, - USER_AUTH_REG_EVENT_LISTENER, - USER_AUTH_UNREG_EVENT_LISTENER, - USER_AUTH_EVENT_LISTENER_NOTIFY, - USER_AUTH_SET_CLOBAL_CONFIG_PARAM, - USER_AUTH_PREPARE_REMOTE_AUTH, - USER_AUTH_GET_PROPERTY_BY_ID, - USER_ACCESS_CTRL_VERIFY_AUTH_TOKEN, - USER_AUTH_AUTH_MODAL_SEND_COMMAND, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_INTERFACE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/user_idm_callback_interface.h b/frameworks/native/ipc/common_defines/user_idm_callback_interface.h deleted file mode 100644 index 2a04cd796401feed61bf44f69be220d5bbbed5d7..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/user_idm_callback_interface.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_IDM_CALLBACK_INTERFACE_H -#define USER_IDM_CALLBACK_INTERFACE_H - -#include - -#include "iremote_broker.h" - -#include "attributes.h" -#include "iam_common_defines.h" -#include "iam_callback_interface.h" -#include "idm_callback_interface_ipc_interface_code.h" -#include "idm_get_cred_info_callback_interface_ipc_interface_code.h" -#include "idm_get_secure_user_info_callback_interface_ipc_interface_code.h" -#include "user_idm_client_defines.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class IdmGetCredInfoCallbackInterface : public IRemoteBroker { -public: - /* - * return all registered credential information. - */ - virtual void OnCredentialInfos(int32_t result, const std::vector &credInfoList) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.useridm.IGetInfoCallback"); -}; - -class IdmGetSecureUserInfoCallbackInterface : public IRemoteBroker { -public: - /* - * return all registered security information. - */ - virtual void OnSecureUserInfo(int32_t result, const SecUserInfo &secUserInfo) = 0; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.useridm.IGetSecInfoCallback"); -}; - -class IdmCallbackInterface : public IamCallbackInterface { -public: - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.useridm.IIDMCallback"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_IDM_CALLBACK_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/user_idm_interface.h b/frameworks/native/ipc/common_defines/user_idm_interface.h deleted file mode 100644 index 1dfef0e18904ff6e6af93cf29c47cd4a89b56e37..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/user_idm_interface.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_IDM_INTERFACE_H -#define USER_IDM_INTERFACE_H - -#include - -#include "refbase.h" -#include "user_idm_callback_interface.h" -#include "user_idm_interface_ipc_interface_code.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserIdmInterface : public IRemoteBroker { -public: - struct CredentialPara { - AuthType authType {ALL}; - PinSubType pinType {PIN_SIX}; - std::vector token; - }; - - /* - * start an IDM operation to obtain challenge value, a challenge value of 0 indicates that open session failed. - * - * param userId user id. - * return challenge value. - */ - virtual int32_t OpenSession(int32_t userId, std::vector &challenge) = 0; - - /* - * end an IDM operation. - * - * param userId user id. - */ - virtual void CloseSession(int32_t userId) = 0; - - /* - * get authentication information. - * - * param userId current user id. - * param authType credential type. - * param callback returns all registered credential information of this type for the specific user. - */ - virtual int32_t GetCredentialInfo(int32_t userId, AuthType authType, - const sptr &callback) = 0; - - /* - * get user security ID. - * - * param userId current user id. - * param callback returns all registered security information for the specific user. - */ - virtual int32_t GetSecInfo(int32_t userId, const sptr &callback) = 0; - - /** - * add user credential information, pass in credential addition method and credential information - * (credential type, subtype, if adding user's non password credentials, pass in password authentication token), - * and get the result / acquire info callback. - * - * param userId user id. - * param credInfo Incoming credential addition method and credential information - * (credential type, subtype, password authentication token). - * param callback get results / acquire info callback. - */ - virtual void AddCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback, bool isUpdate) = 0; - /* - * update user credential information. - * - * param userId user id. - * param credInfo Incoming credential addition method and credential information - * (credential type, subtype, password authentication token). - * param callback update results / acquire info callback. - */ - virtual void UpdateCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback) = 0; - - /* - * Cancel entry and pass in user id. - * - * param userId user id. - */ - virtual int32_t Cancel(int32_t userId) = 0; - - /* - * enforce delete the user credential information, pass in the callback, - * and obtain the deletion result through the callback. - * - * param authToken user password authentication token. - * param callback get deletion result through callback. - */ - virtual int32_t EnforceDelUser(int32_t userId, const sptr &callback) = 0; - - /* - * delete all users credential information, pass in the user password authentication token and callback, - * and obtain the deletion result through the callback. - * - * param userId user id. - * param authToken user password authentication token. - * param callback get deletion result through callback. - */ - virtual void DelUser(int32_t userId, const std::vector authToken, - const sptr &callback) = 0; - - /* - * delete the user credential information, pass in the credential id, password authentication token and callback, - * and obtain the deletion result through the callback. - * Only deleting non password credentials is supported. - * - * param userId user id. - * param credentialId credential index. - * param authToken password authentication token. - * param callback get deletion result through callback. - */ - virtual void DelCredential(int32_t userId, uint64_t credentialId, - const std::vector &authToken, const sptr &callback) = 0; - - /* - * delete the user redundancy credential information, pass in callback, - * and obtain the deletion result through the callback. - * Only deleting the credential without account information is supported. - * - * param callback get deletion result through callback. - */ - virtual void ClearRedundancyCredential(const sptr &callback) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.useridm.IUserIDM"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_IDM_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/user_idm_interface_ipc_interface_code.h b/frameworks/native/ipc/common_defines/user_idm_interface_ipc_interface_code.h deleted file mode 100644 index 50c52b589e8f786cf396fdec615793113414da54..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/user_idm_interface_ipc_interface_code.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_IDM_INTERFACE_IPC_INTERFACE_CODE_H -#define USER_IDM_INTERFACE_IPC_INTERFACE_CODE_H - -/* SAID: 931 */ -namespace OHOS { -namespace UserIam { -namespace UserAuth { -enum UserIdmInterfaceCode : uint32_t { - USER_IDM_OPEN_SESSION = 0, - USER_IDM_CLOSE_SESSION, - USER_IDM_GET_CRED_INFO, - USER_IDM_GET_SEC_INFO, - USER_IDM_ADD_CREDENTIAL, - USER_IDM_UPDATE_CREDENTIAL, - USER_IDM_CANCEL, - USER_IDM_ENFORCE_DEL_USER, - USER_IDM_DEL_USER, - USER_IDM_DEL_CRED, - USER_IDM_CLEAR_REDUNDANCY_CRED, -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_IDM_INTERFACE_IPC_INTERFACE_CODE_H \ No newline at end of file diff --git a/frameworks/native/ipc/common_defines/widget_callback_interface.h b/frameworks/native/ipc/common_defines/widget_callback_interface.h deleted file mode 100644 index 50342d61bfc94a670f16c1e8b91a6809b9c49fd1..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/common_defines/widget_callback_interface.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WIDGET_CALLBACK_INTERFACE_H -#define WIDGET_CALLBACK_INTERFACE_H - -#include - -#include "iremote_broker.h" - -#include "iam_common_defines.h" -#include "user_auth_common_defines.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class WidgetCallbackInterface : public IRemoteBroker { -public: - virtual void SendCommand(const std::string &cmdData) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.WidgetCallback"); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // WIDGET_CALLBACK_INTERFACE_H \ No newline at end of file diff --git a/frameworks/native/ipc/idl/ICoAuth.idl b/frameworks/native/ipc/idl/ICoAuth.idl new file mode 100644 index 0000000000000000000000000000000000000000..4b708f98d27fa6ea24dd2762349c5c55159750d0 --- /dev/null +++ b/frameworks/native/ipc/idl/ICoAuth.idl @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import UserAuthTypes; +import IExecutorCallback; +option_stub_hooks on; + +interface OHOS.UserIam.UserAuth.ICoAuth { + void ExecutorRegister([in] IpcExecutorRegisterInfo ipcExecutorRegisterInfo, + [in] IExecutorCallback executorCallback, [out] unsigned long executorIndex); + + void ExecutorUnregister([in] unsigned long executorIndex); +} \ No newline at end of file diff --git a/frameworks/native/ipc/idl/IEventListenerCallback.idl b/frameworks/native/ipc/idl/IEventListenerCallback.idl new file mode 100644 index 0000000000000000000000000000000000000000..cf853bbc271321f3019371cb5daaf6cbf51b5c8a --- /dev/null +++ b/frameworks/native/ipc/idl/IEventListenerCallback.idl @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +option_stub_hooks on; + +interface OHOS.UserIam.UserAuth.IEventListenerCallback { + [oneway] void OnNotifyAuthSuccessEvent([in] int userId, [in] int authType, [in] int callerType, + [in] String callerName); + + [oneway] void OnNotifyCredChangeEvent([in] int userId, [in] int authType, [in] int eventType, + [in] unsigned long credentialId); +} \ No newline at end of file diff --git a/frameworks/native/ipc/idl/IExecutorCallback.idl b/frameworks/native/ipc/idl/IExecutorCallback.idl new file mode 100644 index 0000000000000000000000000000000000000000..5054130eba8052bb47d92b1ca00b66f353e0e02a --- /dev/null +++ b/frameworks/native/ipc/idl/IExecutorCallback.idl @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import IExecutorMessenger; +option_stub_hooks on; + +interface OHOS.UserIam.UserAuth.IExecutorCallback { + void OnMessengerReady([in] IExecutorMessenger messenger, [in] unsigned char[] publicKey, + [in] unsigned long[] templateIdList); + + void OnBeginExecute([in] unsigned long scheduleId, [in] unsigned char[] publicKey, + [in] unsigned char[] command); + + void OnEndExecute([in] unsigned long scheduleId, [in] unsigned char[] command); + + void OnSetProperty([in] unsigned char[] properties); + + void OnGetProperty([in] unsigned char[] condition, [out] unsigned char[] values); + + void OnSendData([in] unsigned long scheduleId, [in] unsigned char[] extraInfo); +} \ No newline at end of file diff --git a/frameworks/native/ipc/idl/IExecutorMessenger.idl b/frameworks/native/ipc/idl/IExecutorMessenger.idl new file mode 100644 index 0000000000000000000000000000000000000000..4870f8af0f711b23d583b66518b884caf35b8856 --- /dev/null +++ b/frameworks/native/ipc/idl/IExecutorMessenger.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +option_stub_hooks on; + +interface OHOS.UserIam.UserAuth.IExecutorMessenger { + void SendData([in] unsigned long scheduleId, [in] int dstRole, [in] unsigned char[] msg); + + void Finish([in] unsigned long scheduleId, [in] int resultCode, [in] unsigned char[] finalResult); +} \ No newline at end of file diff --git a/test/fuzztest/clients/useridmclientstub_fuzzer/user_idm_client_stub_fuzzer.h b/frameworks/native/ipc/idl/IGetExecutorPropertyCallback.idl similarity index 70% rename from test/fuzztest/clients/useridmclientstub_fuzzer/user_idm_client_stub_fuzzer.h rename to frameworks/native/ipc/idl/IGetExecutorPropertyCallback.idl index bd74840b5de33c10f2ecb1c2911e3b89cac77517..ce0a393b338a2f7e813ce71308492acba04c4d0e 100644 --- a/test/fuzztest/clients/useridmclientstub_fuzzer/user_idm_client_stub_fuzzer.h +++ b/frameworks/native/ipc/idl/IGetExecutorPropertyCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,8 @@ * limitations under the License. */ -#ifndef USER_IDM_CLIENT_STUB_FUZZ_TEST_H -#define USER_IDM_CLIENT_STUB_FUZZ_TEST_H +option_stub_hooks on; -#define FUZZ_PROJECT_NAME "UserIdmClientStubFuzzTest" - -#endif // USER_IDM_CLIENT_STUB_FUZZ_TEST_H +interface OHOS.UserIam.UserAuth.IGetExecutorPropertyCallback { + [oneway] void OnGetExecutorPropertyResult([in] int resultCode, [in] unsigned char[] attributes); +} \ No newline at end of file diff --git a/frameworks/native/ipc/idl/IIamCallback.idl b/frameworks/native/ipc/idl/IIamCallback.idl new file mode 100644 index 0000000000000000000000000000000000000000..28b639a7f40d0abdcc1b25b4e05cdd917d61aea2 --- /dev/null +++ b/frameworks/native/ipc/idl/IIamCallback.idl @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +option_stub_hooks on; + +interface OHOS.UserIam.UserAuth.IIamCallback { + [oneway] void OnResult([in] int resultCode, [in] unsigned char[] extraInfo); + + [oneway] void OnAcquireInfo([in] int module, [in] int acquireInfo, [in] unsigned char[] extraInfo); +} \ No newline at end of file diff --git a/test/fuzztest/clients/userauthcallbackstub_fuzzer/user_auth_callback_stub_fuzzer.h b/frameworks/native/ipc/idl/IIdmGetCredInfoCallback.idl similarity index 69% rename from test/fuzztest/clients/userauthcallbackstub_fuzzer/user_auth_callback_stub_fuzzer.h rename to frameworks/native/ipc/idl/IIdmGetCredInfoCallback.idl index ea09c886a03ba2612b7bd083c7f2ed65614f8c60..72a72b539200b90c20b241c2274ece0a53f68638 100644 --- a/test/fuzztest/clients/userauthcallbackstub_fuzzer/user_auth_callback_stub_fuzzer.h +++ b/frameworks/native/ipc/idl/IIdmGetCredInfoCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef USER_AUTH_CALLBACK_STUB_FUZZER_TEST_H -#define USER_AUTH_CALLBACK_STUB_FUZZER_TEST_H +import UserAuthTypes; +option_stub_hooks on; -#define FUZZ_PROJECT_NAME "UserAuthCallbackStubFuzzTest" - -#endif // USER_AUTH_CALLBACK_STUB_FUZZER_TEST_H +interface OHOS.UserIam.UserAuth.IIdmGetCredInfoCallback { + [oneway] void OnCredentialInfos([in] int resultCode, [in] IpcCredentialInfo[] credInfoList); +} \ No newline at end of file diff --git a/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.h b/frameworks/native/ipc/idl/IIdmGetSecureUserInfoCallback.idl similarity index 69% rename from test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.h rename to frameworks/native/ipc/idl/IIdmGetSecureUserInfoCallback.idl index dae9c06cbf998b681237d0df51af9cf716599e56..812f9837b50eb0efac2de79e8f3b9ee9e022570f 100644 --- a/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.h +++ b/frameworks/native/ipc/idl/IIdmGetSecureUserInfoCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,9 @@ * limitations under the License. */ -#ifndef EXECUTOR_CALLBACK_STUB_FUZZER_H -#define EXECUTOR_CALLBACK_STUB_FUZZER_H +import UserAuthTypes; +option_stub_hooks on; -#define FUZZ_PROJECT_NAME "ExecutorCallbackStubFuzzTest" - -#endif // EXECUTOR_CALLBACK_STUB_FUZZER_H +interface OHOS.UserIam.UserAuth.IIdmGetSecureUserInfoCallback { + [oneway] void OnSecureUserInfo([in] int resultCode, [in] IpcSecUserInfo secUserInfo); +} \ No newline at end of file diff --git a/test/fuzztest/clients/modalcallbackstub_fuzzer/modal_callback_stub_fuzzer.h b/frameworks/native/ipc/idl/IModalCallback.idl similarity index 78% rename from test/fuzztest/clients/modalcallbackstub_fuzzer/modal_callback_stub_fuzzer.h rename to frameworks/native/ipc/idl/IModalCallback.idl index 3883c9990488f998329326c10c310dbd35cd8093..b7d2a876f6958ec84d53d3cdc92e87e1568dffa8 100644 --- a/test/fuzztest/clients/modalcallbackstub_fuzzer/modal_callback_stub_fuzzer.h +++ b/frameworks/native/ipc/idl/IModalCallback.idl @@ -13,9 +13,8 @@ * limitations under the License. */ -#ifndef MODAL_CALLBACK_STUB_FUZZER_H -#define MODAL_CALLBACK_STUB_FUZZER_H +option_stub_hooks on; -#define FUZZ_PROJECT_NAME "ModalCallbackStubFuzzTest" - -#endif // MODAL_CALLBACK_STUB_FUZZER_H +interface OHOS.UserIam.UserAuth.IModalCallback { + [oneway] void SendCommand([in] unsigned long contextId, [in] String cmdData); +} \ No newline at end of file diff --git a/test/fuzztest/clients/widgetcallbackstub_fuzzer/widget_callback_stub_fuzzer.h b/frameworks/native/ipc/idl/ISetExecutorPropertyCallback.idl similarity index 78% rename from test/fuzztest/clients/widgetcallbackstub_fuzzer/widget_callback_stub_fuzzer.h rename to frameworks/native/ipc/idl/ISetExecutorPropertyCallback.idl index a140cd23778cff16d05e233d1061578ca4133b66..7d164885f3dd9978b367db16e2d76afe83446f91 100644 --- a/test/fuzztest/clients/widgetcallbackstub_fuzzer/widget_callback_stub_fuzzer.h +++ b/frameworks/native/ipc/idl/ISetExecutorPropertyCallback.idl @@ -13,9 +13,8 @@ * limitations under the License. */ -#ifndef WIDGET_CALLBACK_STUB_FUZZER_H -#define WIDGET_CALLBACK_STUB_FUZZER_H +option_stub_hooks on; -#define FUZZ_PROJECT_NAME "WidgetCallbackStubFuzzTest" - -#endif // WIDGET_CALLBACK_STUB_FUZZER_H +interface OHOS.UserIam.UserAuth.ISetExecutorPropertyCallback { + [oneway] void OnSetExecutorPropertyResult([in] int resultCode); +} \ No newline at end of file diff --git a/frameworks/native/ipc/idl/IUserAuth.idl b/frameworks/native/ipc/idl/IUserAuth.idl new file mode 100644 index 0000000000000000000000000000000000000000..969e2bf3c52df63963723e83fd510fbbf363ccda --- /dev/null +++ b/frameworks/native/ipc/idl/IUserAuth.idl @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import UserAuthTypes; +import IGetExecutorPropertyCallback; +import ISetExecutorPropertyCallback; +import IIamCallback; +import IWidgetCallback; +import IVerifyTokenCallback; +import IModalCallback; +import IEventListenerCallback; + +option_stub_hooks on; + +interface OHOS.UserIam.UserAuth.IUserAuth { + void GetAvailableStatus([in] int apiVersion, [in] int userId, [in] int authType, + [in] unsigned int authTrustLevel); + + void GetAvailableStatus([in] int apiVersion, [in] int authType, [in] unsigned int authTrustLevel); + + void GetProperty([in] int userId, [in] int authType, + [in] unsigned int[] keys, [in] IGetExecutorPropertyCallback getExecutorPropertyCallback); + + void GetPropertyById([in] unsigned long credentialId, [in] unsigned int[] keys, + [in] IGetExecutorPropertyCallback getExecutorPropertyCallback); + + void SetProperty([in] int userId, [in] int authType, [in] unsigned char[] attributes, + [in] ISetExecutorPropertyCallback setExecutorPropertyCallback); + + void AuthUser([in] IpcAuthParamInner ipcAuthParamInner, [in] IpcRemoteAuthParam ipcRemoteAuthParam, + [in] IIamCallback userAuthCallback, [out] unsigned long contextId); + + void Auth([in] int apiVersion, [in] IpcAuthParamInner ipcAuthParamInner, + [in] IIamCallback userAuthCallback, [out] unsigned long contextId); + + void AuthWidget([in] int apiVersion, [in] IpcAuthParamInner ipcAuthParamInner, + [in] IpcWidgetParamInner ipcWidgetParamInner, [in] IIamCallback userAuthCallback, + [in] IModalCallback modalCallback, [out] unsigned long contextId); + + void Identify([in] unsigned char[] challenge, [in] int authType, + [in] IIamCallback userAuthCallback, [out] unsigned long contextId); + + void CancelAuthOrIdentify([in] unsigned long contextId, [in] int cancelReason); + + void GetVersion([out] int version); + + void Notice([in] int noticeType, [in] String eventData); + + void RegisterWidgetCallback([in] int version, [in] IWidgetCallback widgetCallback); + + void GetEnrolledState([in] int apiVersion, [in] int authType, [out] IpcEnrolledState ipcEnrolledState); + + void RegistUserAuthSuccessEventListener([in] IEventListenerCallback listener); + + void UnRegistUserAuthSuccessEventListener([in] IEventListenerCallback listener); + + void SetGlobalConfigParam([in] IpcGlobalConfigParam ipcGlobalConfigParam); + + void PrepareRemoteAuth([in] String networkId, [in] IIamCallback userAuthCallback); + + void VerifyAuthToken([in] unsigned char[] tokenIn, [in] unsigned long allowableDuration, + [in] IVerifyTokenCallback verifyTokenCallback); +} \ No newline at end of file diff --git a/frameworks/native/ipc/idl/IUserIdm.idl b/frameworks/native/ipc/idl/IUserIdm.idl new file mode 100644 index 0000000000000000000000000000000000000000..24a6b004e120dcf68f6a9af2b33ac635fbbea358 --- /dev/null +++ b/frameworks/native/ipc/idl/IUserIdm.idl @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import UserAuthTypes; +import IIdmGetCredInfoCallback; +import IIdmGetSecureUserInfoCallback; +import IIamCallback; +import IEventListenerCallback; + +option_stub_hooks on; + +interface OHOS.UserIam.UserAuth.IUserIdm { + void OpenSession([in] int userId, [out] unsigned char[] challenge); + + void CloseSession([in] int userId); + + void GetCredentialInfo([in] int userId, [in] int authType, + [in] IIdmGetCredInfoCallback idmGetCredInfoCallback); + + void GetSecInfo([in] int userId, [in] IIdmGetSecureUserInfoCallback IdmGetSecureUserInfoCallback); + + void AddCredential([in] int userId, [in] IpcCredentialPara ipcCredentialPara, + [in] IIamCallback idmCallback, [in] boolean isUpdate); + + void UpdateCredential([in] int userId, [in] IpcCredentialPara ipcCredentialPara, + [in] IIamCallback idmCallback); + + void Cancel([in] int userId); + + void EnforceDelUser([in] int userId, [in] IIamCallback idmCallback); + + void DelUser([in] int userId, [in] unsigned char[] authToken, + [in] IIamCallback idmCallback); + + void DelCredential([in] int userId, [in] unsigned long credentialId, + [in] unsigned char[] authToken, [in] IIamCallback idmCallback); + + void ClearRedundancyCredential([in] IIamCallback idmCallback); + + void RegistCredChangeEventListener([in] IEventListenerCallback listener); + + void UnRegistCredChangeEventListener([in] IEventListenerCallback listener); + + void GetCredentialInfoSync([in] int userId, [in] int authType, + [out] IpcCredentialInfo[] credentialInfoList); +} \ No newline at end of file diff --git a/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.h b/frameworks/native/ipc/idl/IVerifyTokenCallback.idl similarity index 72% rename from test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.h rename to frameworks/native/ipc/idl/IVerifyTokenCallback.idl index 2d60932a698dc15a31f4762a253bfb46d42cdc8f..3cffad0612f0d0525cebfbd748add397ce8174f1 100644 --- a/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.h +++ b/frameworks/native/ipc/idl/IVerifyTokenCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,8 @@ * limitations under the License. */ -#ifndef USER_AUTH_STUB_FUZZER_H -#define USER_AUTH_STUB_FUZZER_H +option_stub_hooks on; -#define FUZZ_PROJECT_NAME "UserAuthStubFuzzTest" - -#endif // USER_AUTH_STUB_FUZZER_H +interface OHOS.UserIam.UserAuth.IVerifyTokenCallback { + [oneway] void OnVerifyTokenResult([in] int resultCode, [in] unsigned char[] extraInfo); +} \ No newline at end of file diff --git a/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.h b/frameworks/native/ipc/idl/IWidgetCallback.idl similarity index 75% rename from test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.h rename to frameworks/native/ipc/idl/IWidgetCallback.idl index 6328c6cc286943782767f7c16934caa0e4c20c3e..9c0f831773ce9f17bf9e6324a5b9ae48928712c6 100644 --- a/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.h +++ b/frameworks/native/ipc/idl/IWidgetCallback.idl @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,9 +13,8 @@ * limitations under the License. */ -#ifndef CO_AUTH_STUB_FUZZER_H -#define CO_AUTH_STUB_FUZZER_H +option_stub_hooks on; -#define FUZZ_PROJECT_NAME "CoAuthStubFuzzTest" - -#endif // Co_AUTH_STUB_FUZZER_H +interface OHOS.UserIam.UserAuth.IWidgetCallback { + [oneway] void SendCommand([in] String cmdData); +} \ No newline at end of file diff --git a/frameworks/native/ipc/idl/UserAuthTypes.idl b/frameworks/native/ipc/idl/UserAuthTypes.idl new file mode 100644 index 0000000000000000000000000000000000000000..50273566de61a2c01945b0d5fd404d1915ed3195 --- /dev/null +++ b/frameworks/native/ipc/idl/UserAuthTypes.idl @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package OHOS.userIam.UserAuth; + +/** + * @brief Remote auth parameter. + */ +struct IpcRemoteAuthParam { + /** Is with remote auth parameter */ + boolean isHasRemoteAuthParam; + /** Is with verifier network id */ + boolean isHasVerifierNetworkId; + /** verifier network id */ + String verifierNetworkId; + /** Is with collector network id */ + boolean isHasCollectorNetworkId; + /** collector network id */ + String collectorNetworkId; + /** Is with collector token id */ + boolean isHasCollectorTokenId; + /** collector token id */ + unsigned int collectorTokenId; +}; + +/** + * @brief Reuse unlock authentication result. + */ +struct IpcReuseUnlockResult { + /** Whether to reuse unlock result, ReuseUnlockResult is valid only when isReuse is true.*/ + boolean isReuse; + /** The mode for reusing unlock authentication result. */ + int reuseMode; + /** The allowable reuse duration.The value of duration should be between 0 and MAX_ALLOWABLE_REUSE_DURATION. */ + unsigned long reuseDuration; +}; + +/** + * @brief Global config value. + */ +struct IpcGlobalConfigValue { + /** Global config value of pin expired period.It's value should between 0 and 2^50. + * When pinExpiredPeriod <= 0, userAuth won't check pin expired period. */ + unsigned long pinExpiredPeriod; + /** Enable specified authType capability. */ + boolean enableStatus; +}; + +/** + * @brief Global config param. + */ +struct IpcGlobalConfigParam { + /** Global config type. */ + int type; + /** Global config value. */ + IpcGlobalConfigValue value; + /** Specified userIds. GlobalConfigParam will be effect for all userspaces when the array is empty. */ + int[] userIds; + /** Specified authTypes. Should not empty. */ + int[] authTypes; +}; + +/** + * @brief Define credential enrollment information. + */ +struct IpcEnrolledInfo { + /** Auth type supported by executor. */ + int authType; + /** Enrolled ID. */ + unsigned long enrolledId; +}; + +struct IpcExecutorRegisterInfo { + /** Auth type supported by executor. */ + int authType; + /** Role supported by executor. */ + int executorRole; + /** Multiple sensors index by executor. */ + unsigned int executorSensorHint; + /** Matcher supported by executor. */ + unsigned int executorMatcher; + /** Esl supported by executor. */ + int esl; + /** Max Acl supported by executor. */ + unsigned int maxTemplateAcl; + /** The pubKey of executor. */ + unsigned char[] publicKey; + /** Device udid of executor. */ + String deviceUdid; + /** The information of remote executor. */ + unsigned char[] signedRemoteExecutorInfo; +}; + +/** + * @brief Auth parameter. + */ +struct IpcAuthParamInner { + /** user id */ + int userId; + /** is userId specified */ + boolean isUserIdSpecified; + /** challenge value */ + unsigned char[] challenge; + /** Credential type for authentication. */ + int authType; + /** Credential type for authentication. */ + int[] authTypes; + /** Trust level of authentication result. */ + int authTrustLevel; + /** Reuse unlock authentication result. */ + IpcReuseUnlockResult reuseUnlockResult; + /** Auth intention. */ + int authIntent; +}; + +/** + * @brief EnrolledId digest and credential count. + */ +struct IpcEnrolledState { + /** The credential digest. */ + unsigned long credentialDigest; + /** The credential count */ + unsigned short credentialCount; +}; + +/** + * @brief Auth widget parameter. + */ +struct IpcWidgetParamInner { + /** Title of widget. */ + String title; + /** The description text of navigation button. */ + String navigationButtonText; + /** Full screen or not. */ + int windowMode; + /** Default has't context. */ + boolean hasContext; +}; + +/** + * @brief credential parameter. + */ +struct IpcCredentialPara { + /** Credential type for authentication. */ + int authType; + /* Auth subtype of PIN. */ + int pinType; + /** Auth token. */ + unsigned char[] token; +}; + +/** + * @brief User credential infomation returned. + */ +struct IpcCredentialInfo { + /* Auth type supported by executor. */ + int authType; + /* Auth subtype of PIN. */ + int pinType; + /* User credentialId is generated by idm to associate userId and templateId. */ + unsigned long credentialId; + /* User templateId is generated by executor to represent user characteristics. */ + unsigned long templateId; +}; + +/** + * @brief Define security user information. + */ +struct IpcSecUserInfo { + /** Security user ID. */ + unsigned long secureUid; + /** The user credential enrollment infomation. */ + IpcEnrolledInfo[] enrolledInfo; +}; \ No newline at end of file diff --git a/frameworks/native/ipc/inc/co_auth_proxy.h b/frameworks/native/ipc/inc/co_auth_proxy.h deleted file mode 100644 index 256322618a88892c1a8e3906356c77bd4bcbf0b2..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/co_auth_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CO_AUTH_PROXY_H -#define CO_AUTH_PROXY_H - -#include "co_auth_interface.h" -#include "iremote_proxy.h" -#include "message_parcel.h" -#include "nocopyable.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class CoAuthProxy : public IRemoteProxy, public NoCopyable { -public: - explicit CoAuthProxy(const sptr &impl); - ~CoAuthProxy() override = default; - uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) override; - void ExecutorUnregister(uint64_t executorIndex) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - int32_t WriteExecutorInfo(const ExecutorRegisterInfo &info, MessageParcel &data); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // CO_AUTH_PROXY_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/co_auth_stub.h b/frameworks/native/ipc/inc/co_auth_stub.h deleted file mode 100644 index c4a608a0722d62ba007c10434f31675fd575badb..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/co_auth_stub.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CO_AUTH_STUB_H -#define CO_AUTH_STUB_H - -#include "co_auth_interface.h" - -#include -#include - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class CoAuthStub : public IRemoteStub { -public: - CoAuthStub(); - ~CoAuthStub() override = default; - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t ExecutorRegisterStub(MessageParcel &data, MessageParcel &reply); - int32_t ExecutorUnregisterStub(MessageParcel &data, MessageParcel &reply); - int32_t ReadExecutorRegisterInfo(ExecutorRegisterInfo &executorInfo, MessageParcel &data); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // CO_AUTH_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/executor_callback_proxy.h b/frameworks/native/ipc/inc/executor_callback_proxy.h deleted file mode 100644 index 837e2162df96875a61ea43f145dc2d04bc950c54..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/executor_callback_proxy.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_CALLBACK_PROXY_H -#define EXECUTOR_CALLBACK_PROXY_H - -#include - -#include "executor_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ExecutorCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit ExecutorCallbackProxy(const sptr &impl) : IRemoteProxy(impl) - { - } - ~ExecutorCallbackProxy() override = default; - void OnMessengerReady(sptr &messenger, - const std::vector &publicKey, const std::vector &templateIdList) override; - int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) override; - int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) override; - int32_t OnSetProperty(const Attributes &properties) override; - int32_t OnGetProperty(const Attributes &condition, Attributes &values) override; - int32_t OnSendData(uint64_t scheduleId, const Attributes &data) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_CALLBACK_PROXY_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/executor_callback_stub.h b/frameworks/native/ipc/inc/executor_callback_stub.h deleted file mode 100644 index c89163888c9eed71b3a0e1590f1bcf0ef45e095e..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/executor_callback_stub.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_CALLBACK_STUB_H -#define EXECUTOR_CALLBACK_STUB_H - -#include "executor_callback_interface.h" -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ExecutorCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnMessengerReadyStub(MessageParcel &data, MessageParcel &reply); - int32_t OnBeginExecuteStub(MessageParcel &data, MessageParcel &reply); - int32_t OnEndExecuteStub(MessageParcel &data, MessageParcel &reply); - int32_t OnSetPropertyStub(MessageParcel &data, MessageParcel &reply); - int32_t OnGetPropertyStub(MessageParcel &data, MessageParcel &reply); - int32_t OnSendDataStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_CALLBACK_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/executor_messenger_proxy.h b/frameworks/native/ipc/inc/executor_messenger_proxy.h deleted file mode 100644 index 812e6b571be309d8c65cfdf71096cd9d7485adb5..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/executor_messenger_proxy.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_MESSENGER_PROXY_H -#define EXECUTOR_MESSENGER_PROXY_H - -#include "executor_messenger_interface.h" -#include "iremote_proxy.h" -#include "message_parcel.h" -#include "nocopyable.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ExecutorMessengerProxy : public IRemoteProxy, public NoCopyable { -public: - explicit ExecutorMessengerProxy(const sptr &impl); - ~ExecutorMessengerProxy() override = default; - int32_t SendData(uint64_t scheduleId, ExecutorRole dstRole, - const std::vector &msg) override; - int32_t Finish(uint64_t scheduleId, ResultCode resultCode, - const std::shared_ptr &finalResult) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_MESSENGER_PROXY_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/executor_messenger_stub.h b/frameworks/native/ipc/inc/executor_messenger_stub.h deleted file mode 100644 index 83ee9a6d9347edab0381301fa31ed2793e2620a6..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/executor_messenger_stub.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EXECUTOR_MESSENGER_STUB_H -#define EXECUTOR_MESSENGER_STUB_H - -#include "executor_messenger_interface.h" - -#include -#include - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ExecutorMessengerStub : public IRemoteStub { -public: - ExecutorMessengerStub(); - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t SendDataStub(MessageParcel &data, MessageParcel &reply); - int32_t FinishStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // EXECUTOR_MESSENGER_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/modal_callback_proxy.h b/frameworks/native/ipc/inc/modal_callback_proxy.h deleted file mode 100644 index cf50d4f9616a630259c1b27addcd7e88d19d14f5..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/modal_callback_proxy.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MODAL_CALLBACK_PROXY_H -#define MODAL_CALLBACK_PROXY_H - -#include - -#include "modal_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ModalCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit ModalCallbackProxy(const sptr &object) : IRemoteProxy(object) - { - } - ~ModalCallbackProxy() override = default; - void SendCommand(uint64_t contextId, const std::string &cmdData) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // MODAL_CALLBACK_PROXY_H diff --git a/frameworks/native/ipc/inc/modal_callback_stub.h b/frameworks/native/ipc/inc/modal_callback_stub.h deleted file mode 100644 index 7c5e8573d816e7ae732638d2fe9abd6edb8e1a1e..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/modal_callback_stub.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef MODAL_CALLBACK_STUB_H -#define MODAL_CALLBACK_STUB_H - -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" - -#include "modal_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class ModalCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnSendCommandStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // MODAL_CALLBACK_STUB_H diff --git a/frameworks/native/ipc/inc/user_access_ctrl_callback_proxy.h b/frameworks/native/ipc/inc/user_access_ctrl_callback_proxy.h deleted file mode 100644 index f8577529bb06647c15f195f3a965b24b95f0a2d3..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_access_ctrl_callback_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_ACCESS_CTRL_CALLBACK_PROXY_H -#define USER_ACCESS_CTRL_CALLBACK_PROXY_H - -#include - -#include "user_access_ctrl_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class VerifyTokenCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit VerifyTokenCallbackProxy(const sptr &object) - : IRemoteProxy(object) - { - } - ~VerifyTokenCallbackProxy() override = default; - void OnVerifyTokenResult(int32_t result, const Attributes &attributes) override; - -private: - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - static inline BrokerDelegator delegator_; -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_ACCESS_CTRL_CALLBACK_PROXY_H diff --git a/frameworks/native/ipc/inc/user_access_ctrl_callback_stub.h b/frameworks/native/ipc/inc/user_access_ctrl_callback_stub.h deleted file mode 100644 index 952e7b93ed4b3242703732db8fa2289cf6c3bfb9..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_access_ctrl_callback_stub.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_ACCESS_CTRL_CALLBACK_STUB_H -#define USER_ACCESS_CTRL_CALLBACK_STUB_H - -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" -#include "user_access_ctrl_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class VerifyTokenCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnVerifyTokenResultStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_ACCESS_CTRL_CALLBACK_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/user_auth_callback_proxy.h b/frameworks/native/ipc/inc/user_auth_callback_proxy.h deleted file mode 100644 index 15d966c658d920d3e5373b090a4fe7a5599b09d3..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_auth_callback_proxy.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_CALLBACK_PROXY_H -#define USER_AUTH_CALLBACK_PROXY_H - -#include - -#include "user_auth_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserAuthCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit UserAuthCallbackProxy(const sptr &object) : IRemoteProxy(object) - { - } - ~UserAuthCallbackProxy() override = default; - void OnResult(int32_t result, const Attributes &extraInfo) override; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; - -class GetExecutorPropertyCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit GetExecutorPropertyCallbackProxy(const sptr &object) - : IRemoteProxy(object) - { - } - ~GetExecutorPropertyCallbackProxy() override = default; - void OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; - -class SetExecutorPropertyCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit SetExecutorPropertyCallbackProxy(const sptr &object) - : IRemoteProxy(object) - { - } - ~SetExecutorPropertyCallbackProxy() override = default; - void OnSetExecutorPropertyResult(int32_t result) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_CALLBACK_PROXY_H diff --git a/frameworks/native/ipc/inc/user_auth_callback_stub.h b/frameworks/native/ipc/inc/user_auth_callback_stub.h deleted file mode 100644 index b9e88e17a2cf184aca1a0c40b17dd624e44be98a..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_auth_callback_stub.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_CALLBACK_STUB_H -#define USER_AUTH_CALLBACK_STUB_H - -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" -#include "user_auth_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserAuthCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnResultStub(MessageParcel &data, MessageParcel &reply); - int32_t OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply); -}; - -class GetExecutorPropertyCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnGetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply); -}; - -class SetExecutorPropertyCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnSetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_CALLBACK_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/user_auth_event_listener_proxy.h b/frameworks/native/ipc/inc/user_auth_event_listener_proxy.h deleted file mode 100644 index 24308bcea35a1f642950729dd050d60dc83a009c..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_auth_event_listener_proxy.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_EVENT_LISTERNR_PROXY_H -#define USER_AUTH_EVENT_LISTERNR_PROXY_H - -#include -#include "user_auth_client_callback.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class AuthEventListenerProxy : public IRemoteProxy, public NoCopyable { -public: - explicit AuthEventListenerProxy(const sptr &object) - : IRemoteProxy(object) - { - } - ~AuthEventListenerProxy() override = default; - void OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, - std::string &callerName) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_EVENT_LISTERNR_PROXY_H diff --git a/frameworks/native/ipc/inc/user_auth_proxy.h b/frameworks/native/ipc/inc/user_auth_proxy.h deleted file mode 100644 index f2b55071427b87192b374834553649dc9ad90e8c..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_auth_proxy.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_PROXY_H -#define USER_AUTH_PROXY_H - -#include "iremote_proxy.h" -#include "message_parcel.h" -#include "nocopyable.h" -#include "user_auth_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserAuthProxy : public IRemoteProxy, public NoCopyable { -public: - explicit UserAuthProxy(const sptr &object); - ~UserAuthProxy() override = default; - int32_t GetAvailableStatus(int32_t apiVersion, int32_t userId, AuthType authType, - AuthTrustLevel authTrustLevel) override; - int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) override; - void GetProperty(int32_t userId, AuthType authType, - const std::vector &keys, - sptr &callback) override; - void GetPropertyById(uint64_t credentialId, const std::vector &keys, - sptr &callback) override; - void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, - sptr &callback) override; - uint64_t AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, - sptr &callback) override; - uint64_t Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) override; - uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback, - sptr &modalCallback) override; - uint64_t Identify(const std::vector &challenge, AuthType authType, - sptr &callback) override; - int32_t CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) override; - int32_t GetVersion(int32_t &version) override; - int32_t Notice(NoticeType noticeType, const std::string &eventData) override; - int32_t RegisterWidgetCallback(int32_t version, sptr &callback) override; - int32_t GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState) override; - int32_t RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) override; - int32_t UnRegistUserAuthSuccessEventListener( - const sptr &listener) override; - int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) override; - int32_t PrepareRemoteAuth(const std::string &networkId, sptr &callback) override; - void VerifyAuthToken(const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback) override; - -private: - static inline BrokerDelegator delegator_; - bool WriteAuthParam(MessageParcel &data, const AuthParamInner &authParam); - bool WriteRemoteAuthParam(MessageParcel &data, const std::optional &remoteAuthParam); - bool WriteOptionalString(MessageParcel &data, const std::optional &str); - bool WriteOptionalUint32(MessageParcel &data, const std::optional &val); - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - bool WriteWidgetAuthParam(MessageParcel &data, const AuthParamInner &authParam); - bool WriteWidgetParam(MessageParcel &data, const WidgetParamInner &widgetParam); - ResultCode WriteGlobalConfigValue(MessageParcel &data, const GlobalConfigParam ¶m); - int32_t GetAvailableStatusInner(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel, - MessageParcel &data); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_PROXY_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/user_auth_stub.h b/frameworks/native/ipc/inc/user_auth_stub.h deleted file mode 100644 index 513249842095e51fc43e0ad73abd246b3b998a5f..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_auth_stub.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_STUB_H -#define USER_AUTH_STUB_H - -#include "user_auth_interface.h" - -#include -#include - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserAuthStub : public IRemoteStub { -public: - UserAuthStub(); - ~UserAuthStub() override = default; - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnRemoteRequestExt(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option); - int32_t GetAvailableStatusStub(MessageParcel &data, MessageParcel &reply); - int32_t GetPropertyStub(MessageParcel &data, MessageParcel &reply); - int32_t GetPropertyByIdStub(MessageParcel &data, MessageParcel &reply); - int32_t SetPropertyStub(MessageParcel &data, MessageParcel &reply); - int32_t AuthStub(MessageParcel &data, MessageParcel &reply); - int32_t AuthWidgetStub(MessageParcel &data, MessageParcel &reply); - int32_t AuthUserStub(MessageParcel &data, MessageParcel &reply); - int32_t IdentifyStub(MessageParcel &data, MessageParcel &reply); - int32_t CancelAuthOrIdentifyStub(MessageParcel &data, MessageParcel &reply); - int32_t GetVersionStub(MessageParcel &data, MessageParcel &reply); - int32_t NoticeStub(MessageParcel &data, MessageParcel &reply); - bool ReadWidgetAuthParam(MessageParcel &data, AuthParamInner &authParam); - bool ReadWidgetParam(MessageParcel &data, WidgetParamInner &widgetParam); - int32_t RegisterWidgetCallbackStub(MessageParcel &data, MessageParcel &reply); - int32_t GetEnrolledStateStub(MessageParcel &data, MessageParcel &reply); - int32_t RegistUserAuthSuccessEventListenerStub(MessageParcel &data, MessageParcel &reply); - int32_t UnRegistUserAuthSuccessEventListenerStub(MessageParcel &data, MessageParcel &reply); - int32_t SetGlobalConfigParamStub(MessageParcel &data, MessageParcel &reply); - int32_t PrepareRemoteAuthStub(MessageParcel &data, MessageParcel &reply); - bool ReadAuthParam(MessageParcel &data, AuthParamInner &authParam); - bool ReadRemoteAuthParam(MessageParcel &data, std::optional &remoteAuthParam); - bool ReadOptionalString(MessageParcel &data, std::optional &str); - bool ReadOptionalUint32(MessageParcel &data, std::optional &val); - ResultCode ReadGlobalConfigValue(MessageParcel &data, GlobalConfigParam ¶m); - int32_t VerifyAuthTokenStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/user_idm_callback_proxy.h b/frameworks/native/ipc/inc/user_idm_callback_proxy.h deleted file mode 100644 index eaf15016aa41c70adf6a605596d9f3aa365994d1..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_idm_callback_proxy.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_ASYNC_PROXY_H -#define USER_AUTH_ASYNC_PROXY_H - -#include - -#include "user_auth_callback_interface.h" -#include "user_idm_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class IdmCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit IdmCallbackProxy(const sptr &object) : IRemoteProxy(object) - { - } - ~IdmCallbackProxy() override = default; - void OnResult(int32_t result, const Attributes &extraInfo) override; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; - -private: - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - static inline BrokerDelegator delegator_; -}; - -class IdmGetCredentialInfoProxy : public IRemoteProxy, public NoCopyable { -public: - explicit IdmGetCredentialInfoProxy(const sptr &object) - : IRemoteProxy(object) - { - } - ~IdmGetCredentialInfoProxy() override = default; - void OnCredentialInfos(int32_t result, const std::vector &credInfoList) override; - -private: - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - static inline BrokerDelegator delegator_; -}; - -class IdmGetSecureUserInfoProxy : public IRemoteProxy, public NoCopyable { -public: - explicit IdmGetSecureUserInfoProxy(const sptr &object) - : IRemoteProxy(object) - { - } - ~IdmGetSecureUserInfoProxy() override = default; - void OnSecureUserInfo(int32_t result, const SecUserInfo &secUserInfo) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); - ResultCode WriteSecureUserInfo(MessageParcel &data, const SecUserInfo &secUserInfo); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_ASYNC_PROXY_H diff --git a/frameworks/native/ipc/inc/user_idm_callback_stub.h b/frameworks/native/ipc/inc/user_idm_callback_stub.h deleted file mode 100644 index acb77ec8ee57a0d4bb41c3bba051f008f1eaf8ce..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_idm_callback_stub.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_IDM_CALLBACK_STUB_H -#define USER_IDM_CALLBACK_STUB_H - -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" - -#include "user_idm_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class IdmCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnResultStub(MessageParcel &data, MessageParcel &reply); - int32_t OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply); -}; - -class IdmGetCredInfoCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnCredentialInfosStub(MessageParcel &data, MessageParcel &reply); - ResultCode ReadCredentialInfoList(MessageParcel &data, std::vector &credInfoList); -}; - -class IdmGetSecureUserInfoCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnSecureUserInfoStub(MessageParcel &data, MessageParcel &reply); - ResultCode ReadSecureUserInfo(MessageParcel &data, SecUserInfo &secUserInfo); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_IDM_CALLBACK_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/user_idm_proxy.h b/frameworks/native/ipc/inc/user_idm_proxy.h deleted file mode 100644 index 63f80b440f627a41e5645886948d7537251c97ad..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_idm_proxy.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_IDM_PROXY_H -#define USER_IDM_PROXY_H - -#include "iremote_proxy.h" -#include "message_parcel.h" -#include "nocopyable.h" -#include "user_idm_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserIdmProxy : public IRemoteProxy, public NoCopyable { -public: - explicit UserIdmProxy(const sptr &object); - ~UserIdmProxy() override = default; - int32_t OpenSession(int32_t userId, std::vector &challenge) override; - void CloseSession(int32_t userId) override; - int32_t GetCredentialInfo(int32_t userId, AuthType authType, - const sptr &callback) override; - int32_t GetSecInfo(int32_t userId, const sptr &callback) override; - void AddCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback, bool isUpdate) override; - void UpdateCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback) override; - int32_t Cancel(int32_t userId) override; - int32_t EnforceDelUser(int32_t userId, const sptr &callback) override; - void DelUser(int32_t userId, const std::vector authToken, - const sptr &callback) override; - void DelCredential(int32_t userId, uint64_t credentialId, - const std::vector &authToken, const sptr &callback) override; - void ClearRedundancyCredential(const sptr &callback) override; -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_IDM_PROXY_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/user_idm_stub.h b/frameworks/native/ipc/inc/user_idm_stub.h deleted file mode 100644 index 3c0f33d79bd97a674c270fa31f508f48adc22629..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/user_idm_stub.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_IDM_STUB_H -#define USER_IDM_STUB_H - -#include "user_idm_interface.h" - -#include -#include - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class UserIdmStub : public IRemoteStub { -public: - UserIdmStub(); - ~UserIdmStub() override = default; - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OpenSessionStub(MessageParcel &data, MessageParcel &reply); - int32_t CloseSessionStub(MessageParcel &data, MessageParcel &reply); - int32_t GetCredentialInfoStub(MessageParcel &data, MessageParcel &reply); - int32_t GetSecInfoStub(MessageParcel &data, MessageParcel &reply); - int32_t AddCredentialStub(MessageParcel &data, MessageParcel &reply); - int32_t UpdateCredentialStub(MessageParcel &data, MessageParcel &reply); - int32_t CancelStub(MessageParcel &data, MessageParcel &reply); - int32_t EnforceDelUserStub(MessageParcel &data, MessageParcel &reply); - int32_t DelUserStub(MessageParcel &data, MessageParcel &reply); - int32_t DelCredentialStub(MessageParcel &data, MessageParcel &reply); - int32_t ClearRedundancyCredentialStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_IDM_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/inc/widget_callback_proxy.h b/frameworks/native/ipc/inc/widget_callback_proxy.h deleted file mode 100644 index a65a785c2df648aefc9760f96077b77d28f4ecee..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/widget_callback_proxy.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WIDGET_CALLBACK_PROXY_H -#define WIDGET_CALLBACK_PROXY_H - -#include - -#include "widget_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class WidgetCallbackProxy : public IRemoteProxy, public NoCopyable { -public: - explicit WidgetCallbackProxy(const sptr &object) : IRemoteProxy(object) - { - } - ~WidgetCallbackProxy() override = default; - void SendCommand(const std::string &cmdData) override; - -private: - static inline BrokerDelegator delegator_; - bool SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // WIDGET_CALLBACK_PROXY_H diff --git a/frameworks/native/ipc/inc/widget_callback_stub.h b/frameworks/native/ipc/inc/widget_callback_stub.h deleted file mode 100644 index 0926cb8bb8ade238c5b61478114cb6922bb6e9aa..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/inc/widget_callback_stub.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WIDGET_CALLBACK_STUB_H -#define WIDGET_CALLBACK_STUB_H - -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" -#include "widget_callback_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class WidgetCallbackStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnSendCommandStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // WIDGET_CALLBACK_STUB_H \ No newline at end of file diff --git a/frameworks/native/ipc/src/co_auth_proxy.cpp b/frameworks/native/ipc/src/co_auth_proxy.cpp deleted file mode 100644 index e3b063aca75188f3020a97e86951cf24eb1ef1b7..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/co_auth_proxy.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "co_auth_proxy.h" - -#include - -#include "iam_common_defines.h" -#include "iam_logger.h" -#include "user_auth_common_defines.h" - -#define LOG_TAG "AUTH_EXECUTOR_MGR_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -CoAuthProxy::CoAuthProxy(const sptr &impl) : IRemoteProxy(impl) -{ -} - -int32_t CoAuthProxy::WriteExecutorInfo(const ExecutorRegisterInfo &info, MessageParcel &data) -{ - if (!data.WriteInt32(info.authType)) { - IAM_LOGE("failed to write authType"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(info.executorRole)) { - IAM_LOGE("failed to write executorRole"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint32(info.executorSensorHint)) { - IAM_LOGE("failed to write executorSensorHint"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint32(info.executorMatcher)) { - IAM_LOGE("failed to write executorMatcher"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint32(info.esl)) { - IAM_LOGE("failed to write esl"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint32(info.maxTemplateAcl)) { - IAM_LOGE("failed to write maxTemplateAcl"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUInt8Vector(info.publicKey)) { - IAM_LOGE("failed to write publicKey"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteString(info.deviceUdid)) { - IAM_LOGE("failed to write deviceUdid"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUInt8Vector(info.signedRemoteExecutorInfo)) { - IAM_LOGE("failed to write signedRemoteExecutorInfo"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -uint64_t CoAuthProxy::ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) -{ - IAM_LOGI("start"); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return BAD_CONTEXT_ID; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return BAD_CONTEXT_ID; - } - if (WriteExecutorInfo(info, data) != SUCCESS) { - IAM_LOGE("failed to write executor info"); - return BAD_CONTEXT_ID; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return BAD_CONTEXT_ID; - } - - bool ret = SendRequest(CoAuthInterfaceCode::CO_AUTH_EXECUTOR_REGISTER, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - return BAD_CONTEXT_ID; - } - uint64_t result = 0; - if (!reply.ReadUint64(result)) { - IAM_LOGE("failed to read result"); - return BAD_CONTEXT_ID; - } - return result; -} - -void CoAuthProxy::ExecutorUnregister(uint64_t executorIndex) -{ - IAM_LOGI("start"); - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(CoAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - - if (!data.WriteUint64(executorIndex)) { - IAM_LOGE("failed to write executorIndex"); - return; - } - - bool ret = SendRequest(CoAuthInterfaceCode::CO_AUTH_EXECUTOR_UNREGISTER, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - return; - } -} - -bool CoAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_SYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("failed to send request, result = %{public}d", result); - return false; - } - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/co_auth_stub.cpp b/frameworks/native/ipc/src/co_auth_stub.cpp deleted file mode 100644 index 10fc82a95dd335bc9f1f8eeb202073f9978544a5..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/co_auth_stub.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "co_auth_stub.h" - -#include - -#include "executor_callback_proxy.h" -#include "iam_logger.h" -#include "iam_common_defines.h" -#include "string_ex.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { - -// When true is passed into IRemoteStub, sa will process request serially. -CoAuthStub::CoAuthStub() : IRemoteStub(true) {}; - -int32_t CoAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - IAM_LOGD("CoAuthStub::OnRemoteRequest, cmd = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (CoAuthStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - switch (code) { - case CoAuthInterfaceCode::CO_AUTH_EXECUTOR_REGISTER: - return ExecutorRegisterStub(data, reply); - case CoAuthInterfaceCode::CO_AUTH_EXECUTOR_UNREGISTER: - return ExecutorUnregisterStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t CoAuthStub::ExecutorUnregisterStub(MessageParcel &data, MessageParcel &reply) -{ - uint64_t executorIndex; - if (!data.ReadUint64(executorIndex)) { - IAM_LOGE("failed to read executorIndex"); - return GENERAL_ERROR; - } - - ExecutorUnregister(executorIndex); - return SUCCESS; -} - -int32_t CoAuthStub::ExecutorRegisterStub(MessageParcel &data, MessageParcel &reply) -{ - ExecutorRegisterInfo executorInfo = {}; - if (ReadExecutorRegisterInfo(executorInfo, data) != SUCCESS) { - IAM_LOGE("read executorInfo failed"); - return READ_PARCEL_ERROR; - } - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("read remote object failed"); - return READ_PARCEL_ERROR; - } - sptr callback(new (std::nothrow) ExecutorCallbackProxy(obj)); - if (callback == nullptr) { - IAM_LOGE("executor callback is nullptr"); - return GENERAL_ERROR; - } - - uint64_t executorIndex = ExecutorRegister(executorInfo, callback); - if (executorIndex == INVALID_EXECUTOR_INDEX) { - IAM_LOGE("executor register failed"); - return GENERAL_ERROR; - } - if (!reply.WriteUint64(executorIndex)) { - IAM_LOGE("write ExecutorRegister result failed"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t CoAuthStub::ReadExecutorRegisterInfo(ExecutorRegisterInfo &executorInfo, MessageParcel &data) -{ - int32_t authType; - int32_t executorRole; - int32_t esl; - - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(executorRole)) { - IAM_LOGE("failed to read executorRole"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint32(executorInfo.executorSensorHint)) { - IAM_LOGE("failed to read executorSensorHint"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint32(executorInfo.executorMatcher)) { - IAM_LOGE("failed to read executorMatcher"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(esl)) { - IAM_LOGE("failed to read esl"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint32(executorInfo.maxTemplateAcl)) { - IAM_LOGE("failed to read maxTemplateAcl"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&executorInfo.publicKey)) { - IAM_LOGE("failed to read publicKey"); - return READ_PARCEL_ERROR; - } - if (!data.ReadString(executorInfo.deviceUdid)) { - IAM_LOGE("failed to read deviceUdid"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&executorInfo.signedRemoteExecutorInfo)) { - IAM_LOGE("failed to read signedRemoteExecutorInfo"); - return READ_PARCEL_ERROR; - } - - executorInfo.authType = static_cast(authType); - executorInfo.executorRole = static_cast(executorRole); - executorInfo.esl = static_cast(esl); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/executor_callback_proxy.cpp b/frameworks/native/ipc/src/executor_callback_proxy.cpp deleted file mode 100644 index 8994dd55bc1033e4fbacddd26f58fcce34ee7047..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/executor_callback_proxy.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_callback_proxy.h" - -#include "iam_logger.h" -#include "iam_common_defines.h" -#include "message_parcel.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -void ExecutorCallbackProxy::OnMessengerReady(sptr &messenger, - const std::vector &publicKey, const std::vector &templateIdList) -{ - if (messenger == nullptr) { - IAM_LOGE("messenger is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - - if (!data.WriteRemoteObject(messenger->AsObject())) { - IAM_LOGE("failed to write messenger failed"); - return; - } - if (!data.WriteUInt8Vector(publicKey)) { - IAM_LOGE("failed to write publicKey"); - return; - } - if (!data.WriteUInt64Vector(templateIdList)) { - IAM_LOGE("failed to write templateIdList"); - return; - } - - bool result = SendRequest(ExecutorCallbackInterfaceCode::ON_MESSENGER_READY, data, reply); - if (!result) { - IAM_LOGE("send request failed"); - return; - } -} - -int32_t ExecutorCallbackProxy::OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return GENERAL_ERROR; - } - if (!data.WriteUint64(scheduleId)) { - IAM_LOGE("write scheduleId failed"); - return GENERAL_ERROR; - } - if (!data.WriteUInt8Vector(publicKey)) { - IAM_LOGE("write publicKey failed"); - return GENERAL_ERROR; - } - auto attr = command.Serialize(); - if (!data.WriteUInt8Vector(attr)) { - IAM_LOGE("write command failed"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(ExecutorCallbackInterfaceCode::ON_BEGIN_EXECUTE, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("read request result failed"); - return GENERAL_ERROR; - } - return result; -} - -int32_t ExecutorCallbackProxy::OnEndExecute(uint64_t scheduleId, const Attributes &command) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return GENERAL_ERROR; - } - if (!data.WriteUint64(scheduleId)) { - IAM_LOGE("write scheduleId failed"); - return GENERAL_ERROR; - } - auto attr = command.Serialize(); - if (!data.WriteUInt8Vector(attr)) { - IAM_LOGE("write command failed"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(ExecutorCallbackInterfaceCode::ON_END_EXECUTE, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("read request result failed"); - return GENERAL_ERROR; - } - return result; -} - -int32_t ExecutorCallbackProxy::OnSetProperty(const Attributes &properties) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return GENERAL_ERROR; - } - auto attr = properties.Serialize(); - if (!data.WriteUInt8Vector(attr)) { - IAM_LOGE("write properties failed"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(ExecutorCallbackInterfaceCode::ON_SET_PROPERTY, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("read request result failed"); - return GENERAL_ERROR; - } - return result; -} - -int32_t ExecutorCallbackProxy::OnGetProperty(const Attributes &condition, Attributes &values) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return GENERAL_ERROR; - } - - if (!data.WriteUInt8Vector(condition.Serialize())) { - IAM_LOGE("write condition failed"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(ExecutorCallbackInterfaceCode::ON_GET_PROPERTY, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("read request result failed"); - return GENERAL_ERROR; - } - - std::vector attr; - if (!reply.ReadUInt8Vector(&attr)) { - IAM_LOGE("read reply values failed"); - return GENERAL_ERROR; - } - values = Attributes(attr); - return result; -} - -int32_t ExecutorCallbackProxy::OnSendData(uint64_t scheduleId, const Attributes &data) -{ - MessageParcel dataParcel; - MessageParcel reply; - - if (!dataParcel.WriteInterfaceToken(ExecutorCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return GENERAL_ERROR; - } - if (!dataParcel.WriteUint64(scheduleId)) { - IAM_LOGE("write scheduleId failed"); - return GENERAL_ERROR; - } - auto attr = data.Serialize(); - if (!dataParcel.WriteUInt8Vector(attr)) { - IAM_LOGE("write data failed"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(ExecutorCallbackInterfaceCode::ON_SEND_DATA, dataParcel, reply); - if (!ret) { - IAM_LOGE("send request failed"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("read request result failed"); - return GENERAL_ERROR; - } - return result; -} - -bool ExecutorCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("get remote failed"); - return false; - } - MessageOption option(MessageOption::TF_SYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("send request failed, code = %{public}u, result = %{public}d", code, result); - return false; - } - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/executor_callback_stub.cpp b/frameworks/native/ipc/src/executor_callback_stub.cpp deleted file mode 100644 index 2c717ea3c8c8ff4fd63b9126abad0f273dfd194b..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/executor_callback_stub.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_callback_stub.h" - -#include "executor_messenger_proxy.h" -#include "iam_common_defines.h" -#include "iam_logger.h" - -#define LOG_TAG "AUTH_EXECUTOR_MGR_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -int32_t ExecutorCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (ExecutorCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - switch (code) { - case ExecutorCallbackInterfaceCode::ON_MESSENGER_READY: - return OnMessengerReadyStub(data, reply); - case ExecutorCallbackInterfaceCode::ON_BEGIN_EXECUTE: - return OnBeginExecuteStub(data, reply); - case ExecutorCallbackInterfaceCode::ON_END_EXECUTE: - return OnEndExecuteStub(data, reply); - case ExecutorCallbackInterfaceCode::ON_SET_PROPERTY: - return OnSetPropertyStub(data, reply); - case ExecutorCallbackInterfaceCode::ON_GET_PROPERTY: - return OnGetPropertyStub(data, reply); - case ExecutorCallbackInterfaceCode::ON_SEND_DATA: - return OnSendDataStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t ExecutorCallbackStub::OnMessengerReadyStub(MessageParcel &data, MessageParcel &reply) -{ - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - - sptr messenger = iface_cast(obj); - if (messenger == nullptr) { - IAM_LOGE("executor messenger is nullptr"); - return GENERAL_ERROR; - } - - std::vector publicKey; - std::vector templateIds; - - if (!data.ReadUInt8Vector(&publicKey)) { - IAM_LOGE("failed to read publicKey"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt64Vector(&templateIds)) { - IAM_LOGE("failed to read templateIds"); - return READ_PARCEL_ERROR; - } - - OnMessengerReady(messenger, publicKey, templateIds); - return SUCCESS; -} - -int32_t ExecutorCallbackStub::OnBeginExecuteStub(MessageParcel &data, MessageParcel &reply) -{ - uint64_t scheduleId; - std::vector publicKey; - std::vector buffer; - - if (!data.ReadUint64(scheduleId)) { - IAM_LOGE("failed to read scheduleId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&publicKey)) { - IAM_LOGE("failed to read publicKey"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read command"); - return READ_PARCEL_ERROR; - } - Attributes commandAttrs(buffer); - - int32_t result = OnBeginExecute(scheduleId, publicKey, commandAttrs); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write OnBeginExecute result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t ExecutorCallbackStub::OnEndExecuteStub(MessageParcel &data, MessageParcel &reply) -{ - uint64_t scheduleId; - std::vector buffer; - - if (!data.ReadUint64(scheduleId)) { - IAM_LOGE("failed to read scheduleId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read command"); - return READ_PARCEL_ERROR; - } - Attributes consumerAttr(buffer); - - int32_t result = OnEndExecute(scheduleId, consumerAttr); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write OnEndExecute result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t ExecutorCallbackStub::OnSetPropertyStub(MessageParcel &data, MessageParcel &reply) -{ - std::vector buffer; - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read properties"); - return READ_PARCEL_ERROR; - } - Attributes properties(buffer); - - int32_t result = OnSetProperty(properties); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write OnSetProperty result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t ExecutorCallbackStub::OnGetPropertyStub(MessageParcel &data, MessageParcel &reply) -{ - std::vector buffer; - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read conditions"); - return READ_PARCEL_ERROR; - } - Attributes conditions(buffer); - Attributes values; - - int32_t result = OnGetProperty(conditions, values); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write OnGetProperty result"); - return WRITE_PARCEL_ERROR; - } - - std::vector replyBuffer = values.Serialize(); - if (!reply.WriteUInt8Vector(replyBuffer)) { - IAM_LOGE("failed to write replyBuffer"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t ExecutorCallbackStub::OnSendDataStub(MessageParcel &data, MessageParcel &reply) -{ - uint64_t scheduleId; - std::vector buffer; - - if (!data.ReadUint64(scheduleId)) { - IAM_LOGE("failed to read scheduleId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read data"); - return READ_PARCEL_ERROR; - } - Attributes dataAttr(buffer); - - int32_t result = OnSendData(scheduleId, dataAttr); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write OnSendData result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/executor_messenger_proxy.cpp b/frameworks/native/ipc/src/executor_messenger_proxy.cpp deleted file mode 100644 index eec52dd14d95850f99bcac0b63b9d32b5b65d0b6..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/executor_messenger_proxy.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_messenger_proxy.h" - -#include "iam_logger.h" - -#define LOG_TAG "AUTH_EXECUTOR_MGR_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -ExecutorMessengerProxy::ExecutorMessengerProxy(const sptr &impl) - : IRemoteProxy(impl) -{ -} - -int32_t ExecutorMessengerProxy::SendData(uint64_t scheduleId, - ExecutorRole dstRole, const std::vector &msg) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ExecutorMessengerProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(scheduleId)) { - IAM_LOGE("failed to write scheduleId"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(dstRole)) { - IAM_LOGE("failed to write dstRole"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUInt8Vector(msg)) { - IAM_LOGE("failed to write msg"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(ExecutorMessengerInterfaceCode::CO_AUTH_SEND_DATA, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - return GENERAL_ERROR; - } - int32_t result = 0; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -int32_t ExecutorMessengerProxy::Finish(uint64_t scheduleId, ResultCode resultCode, - const std::shared_ptr &finalResult) -{ - if (finalResult == nullptr) { - IAM_LOGE("finalResult is nullptr"); - return INVALID_PARAMETERS; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ExecutorMessengerProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(scheduleId)) { - IAM_LOGE("failed to write scheduleId"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(resultCode)) { - IAM_LOGE("failed to write resultCode"); - return WRITE_PARCEL_ERROR; - } - std::vector buffer = finalResult->Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("failed to write finalResult"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(ExecutorMessengerInterfaceCode::CO_AUTH_FINISH, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - return GENERAL_ERROR; - } - int32_t result = 0; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -bool ExecutorMessengerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_SYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("failed to send request, result = %{public}d", result); - return false; - } - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/executor_messenger_stub.cpp b/frameworks/native/ipc/src/executor_messenger_stub.cpp deleted file mode 100644 index 1d5bf9ac7c9b0a52c7fd5729da2f989b62c3b976..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/executor_messenger_stub.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_messenger_stub.h" - -#include - -#include "iam_check.h" -#include "iam_logger.h" -#include "iam_ptr.h" -#include "iam_common_defines.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { - -// When true is passed into IRemoteStub, sa will process request serially. -ExecutorMessengerStub::ExecutorMessengerStub() : IRemoteStub(true) {}; - -int32_t ExecutorMessengerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGD("ExecutorMessengerStub::OnRemoteRequest, cmd = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (ExecutorMessengerStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - switch (code) { - case ExecutorMessengerInterfaceCode::CO_AUTH_SEND_DATA: - return SendDataStub(data, reply); - case ExecutorMessengerInterfaceCode::CO_AUTH_FINISH: - return FinishStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t ExecutorMessengerStub::SendDataStub(MessageParcel &data, MessageParcel &reply) -{ - uint64_t scheduleId; - int32_t dstRole; - std::vector msg; - - if (!data.ReadUint64(scheduleId)) { - IAM_LOGE("read scheduleId failed"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(dstRole)) { - IAM_LOGE("read dstRole failed"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&msg)) { - IAM_LOGE("read msg failed"); - return GENERAL_ERROR; - } - - int32_t result = SendData(scheduleId, static_cast(dstRole), msg); - if (!reply.WriteInt32(result)) { - IAM_LOGE("write SendData result failed"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t ExecutorMessengerStub::FinishStub(MessageParcel &data, MessageParcel &reply) -{ - uint64_t scheduleId; - int32_t resultCode; - std::vector attributes; - - if (!data.ReadUint64(scheduleId)) { - IAM_LOGE("read scheduleId failed"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(resultCode)) { - IAM_LOGE("read resultCode failed"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&attributes)) { - IAM_LOGE("read attributes failed"); - return READ_PARCEL_ERROR; - } - auto finalResult = Common::MakeShared(attributes); - IF_FALSE_LOGE_AND_RETURN_VAL(finalResult != nullptr, WRITE_PARCEL_ERROR); - int32_t result = - Finish(scheduleId, static_cast(resultCode), finalResult); - if (!reply.WriteInt32(result)) { - IAM_LOGE("write Finish result failed"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/modal_callback_proxy.cpp b/frameworks/native/ipc/src/modal_callback_proxy.cpp deleted file mode 100644 index 43109fc231ab8790c28bb2854b1cc1e605fd7a2d..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/modal_callback_proxy.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "modal_callback_proxy.h" - -#include "iam_logger.h" -#include "iam_common_defines.h" -#include "user_auth_interface.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -void ModalCallbackProxy::SendCommand(uint64_t contextId, const std::string &cmdData) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(ModalCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return; - } - if (!data.WriteUint64(contextId)) { - IAM_LOGE("write context id failed"); - return; - } - if (!data.WriteString(cmdData)) { - IAM_LOGE("write cmd data failed"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_AUTH_MODAL_SEND_COMMAND, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - } -} - -bool ModalCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("get remote failed"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("send request failed, result = %{public}d", result); - return false; - } - IAM_LOGI("end"); - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/modal_callback_stub.cpp b/frameworks/native/ipc/src/modal_callback_stub.cpp deleted file mode 100644 index a3f8f442c4ec2705b0496689f16e2fbb5a6ded73..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/modal_callback_stub.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "modal_callback_stub.h" - -#include - -#include "iam_logger.h" -#include "user_auth_interface.h" - -#define LOG_TAG "USER_AUTH_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -int32_t ModalCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (ModalCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - switch (code) { - case UserAuthInterfaceCode::USER_AUTH_AUTH_MODAL_SEND_COMMAND: - return OnSendCommandStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t ModalCallbackStub::OnSendCommandStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - uint64_t contextId = data.ReadUint64(); - std::string cmdData = data.ReadString(); - SendCommand(contextId, cmdData); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_access_ctrl_callback_proxy.cpp b/frameworks/native/ipc/src/user_access_ctrl_callback_proxy.cpp deleted file mode 100644 index 1a6b6be7fcd61e4b074e874c9c1b5c65acc39dee..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_access_ctrl_callback_proxy.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_access_ctrl_callback_proxy.h" - -#include "iam_logger.h" -#include "user_access_ctrl_callback_interface.h" - -#define LOG_TAG "USER_ACCESS_CTRL_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -void VerifyTokenCallbackProxy::OnVerifyTokenResult(int32_t result, const Attributes &attributes) -{ - IAM_LOGI("start, result: %{public}d", result); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(VerifyTokenCallbackProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(result)) { - IAM_LOGE("write result failed"); - return; - } - auto buffer = attributes.Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("write buffer failed"); - return; - } - - bool ret = SendRequest(UserAccessCtrlCallbackInterfaceCode::ON_VERIFY_TOKEN_RESULT, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - } -} - - -bool VerifyTokenCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != SUCCESS) { - IAM_LOGE("failed to send request result = %{public}d", result); - return false; - } - - IAM_LOGI("end"); - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/frameworks/native/ipc/src/user_access_ctrl_callback_stub.cpp b/frameworks/native/ipc/src/user_access_ctrl_callback_stub.cpp deleted file mode 100644 index 491d06ee4fe16e2871903043bd8ba7df6aed7c99..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_access_ctrl_callback_stub.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_access_ctrl_callback_stub.h" - -#include "iam_logger.h" -#include "user_access_ctrl_callback_interface.h" - -#define LOG_TAG "USER_ACCESS_CTRL_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -int32_t VerifyTokenCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (VerifyTokenCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - if (code == UserAccessCtrlCallbackInterfaceCode::ON_VERIFY_TOKEN_RESULT) { - return OnVerifyTokenResultStub(data, reply); - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int32_t VerifyTokenCallbackStub::OnVerifyTokenResultStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t result; - std::vector buffer; - - if (!data.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read buffer"); - return READ_PARCEL_ERROR; - } - - Attributes attr(buffer); - OnVerifyTokenResult(result, attr); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_auth_callback_proxy.cpp b/frameworks/native/ipc/src/user_auth_callback_proxy.cpp deleted file mode 100644 index 07634443bff5040951b8f35f5c4158b0c9cdd5d7..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_auth_callback_proxy.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_callback_proxy.h" - -#include "iam_logger.h" -#include "iam_common_defines.h" -#include "user_auth_interface.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -void UserAuthCallbackProxy::OnResult(int32_t result, const Attributes &extraInfo) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return; - } - if (!data.WriteInt32(result)) { - IAM_LOGE("write result failed"); - return; - } - auto buffer = extraInfo.Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("write buffer failed"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_ON_RESULT, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - } -} - -void UserAuthCallbackProxy::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return; - } - if (!data.WriteInt32(module)) { - IAM_LOGE("write module failed"); - return; - } - if (!data.WriteInt32(acquireInfo)) { - IAM_LOGE("write acquireInfo failed"); - return; - } - auto buffer = extraInfo.Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("write buffer failed"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_ACQUIRE_INFO, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - } -} - -bool UserAuthCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("get remote failed"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("send request failed, result = %{public}d", result); - return false; - } - IAM_LOGI("end"); - return true; -} - -void GetExecutorPropertyCallbackProxy::OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(GetExecutorPropertyCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return; - } - if (!data.WriteInt32(result)) { - IAM_LOGE("write result failed"); - return; - } - auto buffer = attributes.Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("write buffer failed"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_GET_EX_PROP, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - } -} - -bool GetExecutorPropertyCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("get remote failed"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("send request failed, result = %{public}d", result); - return false; - } - IAM_LOGI("end"); - return true; -} - -void SetExecutorPropertyCallbackProxy::OnSetExecutorPropertyResult(int32_t result) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(SetExecutorPropertyCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return; - } - if (!data.WriteInt32(result)) { - IAM_LOGE("write result failed"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_SET_EX_PROP, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - } -} - -bool SetExecutorPropertyCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("get remote failed"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("send request failed, result = %{public}d", result); - return false; - } - IAM_LOGI("end"); - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_auth_callback_stub.cpp b/frameworks/native/ipc/src/user_auth_callback_stub.cpp deleted file mode 100644 index 82564f413531bc8453b1d824abcd00135557a4f1..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_auth_callback_stub.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_callback_stub.h" - -#include - -#include "iam_logger.h" -#include "user_auth_interface.h" - -#define LOG_TAG "USER_AUTH_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -int32_t UserAuthCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (UserAuthCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - switch (code) { - case UserAuthInterfaceCode::USER_AUTH_ON_RESULT: - return OnResultStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_ACQUIRE_INFO: - return OnAcquireInfoStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t UserAuthCallbackStub::OnResultStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t result; - std::vector buffer; - - if (!data.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read buffer"); - return READ_PARCEL_ERROR; - } - - Attributes extraInfo(buffer); - OnResult(result, extraInfo); - return SUCCESS; -} - -int32_t UserAuthCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t module; - int32_t acquireInfo; - std::vector buffer; - - if (!data.ReadInt32(module)) { - IAM_LOGE("failed to read module"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(acquireInfo)) { - IAM_LOGE("failed to read acquireInfo"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read buffer"); - return READ_PARCEL_ERROR; - } - - Attributes extraInfo(buffer); - OnAcquireInfo(module, acquireInfo, extraInfo); - return SUCCESS; -} - -int32_t GetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (GetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - if (code == UserAuthInterfaceCode::USER_AUTH_GET_EX_PROP) { - return OnGetExecutorPropertyResultStub(data, reply); - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int32_t GetExecutorPropertyCallbackStub::OnGetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t result; - std::vector buffer; - - if (!data.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read buffer"); - return READ_PARCEL_ERROR; - } - - Attributes attr(buffer); - OnGetExecutorPropertyResult(result, attr); - return SUCCESS; -} - -int32_t SetExecutorPropertyCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (SetExecutorPropertyCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - if (code == UserAuthInterfaceCode::USER_AUTH_SET_EX_PROP) { - return OnSetExecutorPropertyResultStub(data, reply); - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int32_t SetExecutorPropertyCallbackStub::OnSetExecutorPropertyResultStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t result; - - if (!data.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - OnSetExecutorPropertyResult(result); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_auth_event_listener_proxy.cpp b/frameworks/native/ipc/src/user_auth_event_listener_proxy.cpp deleted file mode 100644 index 099c3dc131e1e27fe8f5e7c9334e4101db58d35b..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_auth_event_listener_proxy.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_event_listener_proxy.h" - -#include "iam_logger.h" -#include "iam_common_defines.h" -#include "user_auth_interface.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -bool AuthEventListenerProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("get remote failed"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("send request failed, result = %{public}d", result); - return false; - } - IAM_LOGI("end"); - return true; -} - -void AuthEventListenerProxy::OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, - std::string &callerName) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(AuthEventListenerProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("write userId failed"); - return; - } - if (!data.WriteInt32(static_cast(authType))) { - IAM_LOGE("write authType failed"); - return; - } - if (!data.WriteString(callerName)) { - IAM_LOGE("write callerName failed"); - return; - } - if (!data.WriteInt32(callerType)) { - IAM_LOGE("write callerType failed"); - return; - } - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_EVENT_LISTENER_NOTIFY, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - } - return; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_auth_event_listener_stub.cpp b/frameworks/native/ipc/src/user_auth_event_listener_stub.cpp deleted file mode 100644 index 374f18fd624ec5960205200c7764e8f59367276b..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_auth_event_listener_stub.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_event_listener_stub.h" - -#include - -#include "iam_logger.h" -#include "user_auth_interface.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -int32_t AuthEventListenerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (AuthEventListenerStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - if (code == UserAuthInterfaceCode::USER_AUTH_EVENT_LISTENER_NOTIFY) { - return OnNotifyAuthSuccessEventStub(data, reply); - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -int32_t AuthEventListenerStub::OnNotifyAuthSuccessEventStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t userId = 0; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - int32_t authType = 0; - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - std::string callerName; - if (!data.ReadString(callerName)) { - IAM_LOGE("failed to read callerName"); - return READ_PARCEL_ERROR; - } - int32_t callerType = 0; - if (!data.ReadInt32(callerType)) { - IAM_LOGE("failed to read callerType"); - return READ_PARCEL_ERROR; - } - OnNotifyAuthSuccessEvent(userId, static_cast(authType), callerType, callerName); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_auth_proxy.cpp b/frameworks/native/ipc/src/user_auth_proxy.cpp deleted file mode 100644 index a65779d2a5bb463a1c537000f237ede469de6d18..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_auth_proxy.cpp +++ /dev/null @@ -1,990 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_proxy.h" - -#include -#include - -#include "iam_logger.h" - -#define LOG_TAG "USER_AUTH_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { - const uint32_t MAX_ATTR_COUNT = 512; -} // namespace - -UserAuthProxy::UserAuthProxy(const sptr &object) : IRemoteProxy(object) -{ -} - -int32_t UserAuthProxy::GetAvailableStatus(int32_t apiVersion, int32_t userId, AuthType authType, - AuthTrustLevel authTrustLevel) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - bool isSpecificUserId = true; - if (!data.WriteBool(isSpecificUserId)) { - IAM_LOGE("failed to write isSpecificUserId"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return WRITE_PARCEL_ERROR; - } - return GetAvailableStatusInner(apiVersion, authType, authTrustLevel, data); -} - -int32_t UserAuthProxy::GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) -{ - MessageParcel data; - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - bool isSpecificUserId = false; - if (!data.WriteBool(isSpecificUserId)) { - IAM_LOGE("failed to write isSpecificUserId"); - return WRITE_PARCEL_ERROR; - } - return GetAvailableStatusInner(apiVersion, authType, authTrustLevel, data); -} - -int32_t UserAuthProxy::GetAvailableStatusInner(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel, - MessageParcel &data) -{ - if (!data.WriteInt32(authType)) { - IAM_LOGE("failed to write authType"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint32(authTrustLevel)) { - IAM_LOGE("failed to write authTrustLevel"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(apiVersion)) { - IAM_LOGE("failed to write apiVersion"); - return WRITE_PARCEL_ERROR; - } - - MessageParcel reply; - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_GET_AVAILABLE_STATUS, data, reply); - if (!ret) { - IAM_LOGE("failed to send get available status IPC request"); - return GENERAL_ERROR; - } - int32_t result = SUCCESS; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -void UserAuthProxy::GetProperty(int32_t userId, AuthType authType, - const std::vector &keys, sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (keys.empty() || keys.size() > MAX_ATTR_COUNT) { - IAM_LOGE("the attribute key vector is bad param, key size:%{public}zu", keys.size()); - Attributes attr; - callback->OnGetExecutorPropertyResult(INVALID_PARAMETERS, attr); - return; - } - - std::vector attrKeys; - attrKeys.resize(keys.size()); - std::transform(keys.begin(), keys.end(), attrKeys.begin(), [](Attributes::AttributeKey key) { - return static_cast(key); - }); - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return; - } - if (!data.WriteInt32(authType)) { - IAM_LOGE("failed to write authType"); - return; - } - if (!data.WriteUInt32Vector(attrKeys)) { - IAM_LOGE("failed to write keys"); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY, data, reply); - if (!ret) { - IAM_LOGE("failed to send get property IPC request"); - Attributes attr; - callback->OnGetExecutorPropertyResult(GENERAL_ERROR, attr); - } -} - -void UserAuthProxy::GetPropertyById(uint64_t credentialId, const std::vector &keys, - sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (keys.empty() || keys.size() > MAX_ATTR_COUNT) { - IAM_LOGE("the attribute key vector is bad param, key size:%{public}zu", keys.size()); - Attributes attr; - callback->OnGetExecutorPropertyResult(INVALID_PARAMETERS, attr); - return; - } - - std::vector attrKeys; - attrKeys.resize(keys.size()); - std::transform(keys.begin(), keys.end(), attrKeys.begin(), [](Attributes::AttributeKey key) { - return static_cast(key); - }); - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteUint64(credentialId)) { - IAM_LOGE("failed to write credentialId"); - return; - } - if (!data.WriteUInt32Vector(attrKeys)) { - IAM_LOGE("failed to write keys"); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY_BY_ID, data, reply); - if (!ret) { - IAM_LOGE("failed to send get propertyById IPC request"); - Attributes attr; - callback->OnGetExecutorPropertyResult(GENERAL_ERROR, attr); - } -} - -void UserAuthProxy::SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, - sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return; - } - if (!data.WriteInt32(authType)) { - IAM_LOGE("failed to write authType"); - return; - } - auto buffer = attributes.Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("failed to write attributes"); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_SET_PROPERTY, data, reply); - if (!ret) { - IAM_LOGE("failed to send set property IPC request"); - callback->OnSetExecutorPropertyResult(GENERAL_ERROR); - } -} - -bool UserAuthProxy::WriteAuthParam(MessageParcel &data, const AuthParamInner &authParam) -{ - if (!data.WriteInt32(authParam.userId)) { - IAM_LOGE("failed to write userId"); - return false; - } - if (!data.WriteUInt8Vector(authParam.challenge)) { - IAM_LOGE("failed to write challenge"); - return false; - } - if (!data.WriteInt32(authParam.authType)) { - IAM_LOGE("failed to write authType"); - return false; - } - std::vector atList; - for (auto at : authParam.authTypes) { - atList.push_back(static_cast(at)); - } - if (!data.WriteInt32Vector(atList)) { - IAM_LOGE("failed to write authTypeList"); - return false; - } - if (!data.WriteUint32(authParam.authTrustLevel)) { - IAM_LOGE("failed to write authTrustLevel"); - return false; - } - if (!data.WriteUint32(authParam.authIntent)) { - IAM_LOGE("failed to write authIntent"); - return false; - } - - return true; -} - -bool UserAuthProxy::WriteRemoteAuthParam(MessageParcel &data, const std::optional &remoteAuthParam) -{ - if (!data.WriteBool(remoteAuthParam.has_value())) { - IAM_LOGE("failed to write remoteAuthParam has value"); - return false; - } - - if (!remoteAuthParam.has_value()) { - return true; - } - - if (!WriteOptionalString(data, remoteAuthParam.value().verifierNetworkId)) { - IAM_LOGE("failed to write verifierNetworkId"); - return false; - } - - if (!WriteOptionalString(data, remoteAuthParam.value().collectorNetworkId)) { - IAM_LOGE("failed to write collectorNetworkId"); - return false; - } - - if (!WriteOptionalUint32(data, remoteAuthParam.value().collectorTokenId)) { - IAM_LOGE("failed to write collectorTokenId"); - return false; - } - - return true; -} - -bool UserAuthProxy::WriteOptionalString(MessageParcel &data, const std::optional &str) -{ - if (!data.WriteBool(str.has_value())) { - IAM_LOGE("failed to write str has value"); - return false; - } - - if (str.has_value()) { - if (!data.WriteString(str.value())) { - IAM_LOGE("failed to write str"); - return false; - } - } - return true; -} - -bool UserAuthProxy::WriteOptionalUint32(MessageParcel &data, const std::optional &val) -{ - if (!data.WriteBool(val.has_value())) { - IAM_LOGE("failed to write val has value"); - return false; - } - - if (val.has_value()) { - if (!data.WriteUint32(val.value())) { - IAM_LOGE("failed to write val"); - return false; - } - } - - return true; -} - -uint64_t UserAuthProxy::Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return BAD_CONTEXT_ID; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return BAD_CONTEXT_ID; - } - if (!data.WriteInt32(apiVersion)) { - IAM_LOGE("failed to write apiVersion"); - return BAD_CONTEXT_ID; - } - AuthParamInner authParam = { - .userId = 0, - .challenge = challenge, - .authType = authType, - .authTrustLevel = authTrustLevel, - }; - if (!WriteAuthParam(data, authParam)) { - IAM_LOGE("failed to write auth param"); - return BAD_CONTEXT_ID; - } - - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return BAD_CONTEXT_ID; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_AUTH, data, reply); - if (!ret) { - IAM_LOGE("failed to send user auth IPC request"); - return BAD_CONTEXT_ID; - } - uint64_t result = BAD_CONTEXT_ID; - if (!reply.ReadUint64(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -uint64_t UserAuthProxy::AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback, - sptr &modalCallback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return BAD_CONTEXT_ID; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return BAD_CONTEXT_ID; - } - - if (!WriteWidgetAuthParam(data, authParam)) { - IAM_LOGE("failed to write widget auth param"); - return BAD_CONTEXT_ID; - } - - if (!WriteWidgetParam(data, widgetParam)) { - IAM_LOGE("failed to write widget param"); - return BAD_CONTEXT_ID; - } - - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return BAD_CONTEXT_ID; - } - - if (!data.WriteRemoteObject(modalCallback->AsObject())) { - IAM_LOGE("failed to write modal callback"); - return BAD_CONTEXT_ID; - } - - if (!data.WriteInt32(apiVersion)) { - IAM_LOGE("failed to write apiVersion"); - return BAD_CONTEXT_ID; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_AUTH_WIDGET, data, reply); - if (!ret) { - IAM_LOGE("failed to send auth widget IPC request"); - return BAD_CONTEXT_ID; - } - uint64_t result = BAD_CONTEXT_ID; - if (!reply.ReadUint64(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -bool UserAuthProxy::WriteWidgetAuthParam(MessageParcel &data, const AuthParamInner &authParam) -{ - if (!data.WriteInt32(authParam.userId)) { - IAM_LOGE("failed to write userId"); - return false; - } - if (!data.WriteBool(authParam.isUserIdSpecified)) { - IAM_LOGE("failed to write isUserIdSpecified"); - return false; - } - if (!data.WriteUInt8Vector(authParam.challenge)) { - IAM_LOGE("failed to write challenge"); - return false; - } - std::vector atList; - for (auto at : authParam.authTypes) { - atList.push_back(static_cast(at)); - } - if (!data.WriteInt32Vector(atList)) { - IAM_LOGE("failed to write authTypeList"); - return false; - } - if (!data.WriteUint32(authParam.authTrustLevel)) { - IAM_LOGE("failed to write authTrustLevel"); - return false; - } - if (!data.WriteBool(authParam.reuseUnlockResult.isReuse)) { - IAM_LOGE("failed to write isReuse unlock result"); - return false; - } - if (authParam.reuseUnlockResult.isReuse) { - if (!data.WriteUint32(authParam.reuseUnlockResult.reuseMode)) { - IAM_LOGE("failed to write reuseMode."); - return false; - } - if (!data.WriteUint64(authParam.reuseUnlockResult.reuseDuration)) { - IAM_LOGE("failed to write reuseDuration."); - return false; - } - } - return true; -} - -bool UserAuthProxy::WriteWidgetParam(MessageParcel &data, const WidgetParamInner &widgetParam) -{ - if (!data.WriteString(widgetParam.title)) { - IAM_LOGE("failed to write title"); - return false; - } - if (!data.WriteString(widgetParam.navigationButtonText)) { - IAM_LOGE("failed to write navigation button text"); - return false; - } - if (!data.WriteInt32(static_cast(widgetParam.windowMode))) { - IAM_LOGE("failed to write window mode"); - return false; - } - if (!data.WriteBool(widgetParam.hasContext)) { - IAM_LOGE("failed to write hasContext"); - return false; - } - return true; -} - -uint64_t UserAuthProxy::AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, - sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return BAD_CONTEXT_ID; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return BAD_CONTEXT_ID; - } - - if (!WriteAuthParam(data, param)) { - IAM_LOGE("failed to write auth param"); - return BAD_CONTEXT_ID; - } - - if (!WriteRemoteAuthParam(data, remoteAuthParam)) { - IAM_LOGE("failed to write remote auth param"); - return BAD_CONTEXT_ID; - } - - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return BAD_CONTEXT_ID; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_AUTH_USER, data, reply); - if (!ret) { - IAM_LOGE("failed to send auth user IPC request"); - return BAD_CONTEXT_ID; - } - uint64_t result = BAD_CONTEXT_ID; - if (!reply.ReadUint64(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -uint64_t UserAuthProxy::Identify(const std::vector &challenge, AuthType authType, - sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return BAD_CONTEXT_ID; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return BAD_CONTEXT_ID; - } - if (!data.WriteUInt8Vector(challenge)) { - IAM_LOGE("failed to write challenge"); - return BAD_CONTEXT_ID; - } - if (!data.WriteInt32(authType)) { - IAM_LOGE("failed to write authType"); - return BAD_CONTEXT_ID; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return BAD_CONTEXT_ID; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_IDENTIFY, data, reply); - if (!ret) { - IAM_LOGE("failed to send auth identify IPC request"); - return BAD_CONTEXT_ID; - } - uint64_t result = BAD_CONTEXT_ID; - if (!reply.ReadUint64(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -int32_t UserAuthProxy::CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return GENERAL_ERROR; - } - if (!data.WriteUint64(contextId)) { - IAM_LOGE("failed to write contextId"); - return GENERAL_ERROR; - } - if (!data.WriteInt32(cancelReason)) { - IAM_LOGE("failed to write cancelReason"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_CANCEL_AUTH, data, reply); - if (!ret) { - IAM_LOGE("failed to send cancel auth IPC request"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -int32_t UserAuthProxy::GetVersion(int32_t &version) -{ - version = 0; - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_GET_VERSION, data, reply); - if (!ret) { - IAM_LOGE("failed to send get version IPC request"); - return GENERAL_ERROR; - } - if (!reply.ReadInt32(version)) { - IAM_LOGE("failed to read version"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -bool UserAuthProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_SYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("failed to send request, result = %{public}d", result); - return false; - } - return true; -} - -int32_t UserAuthProxy::Notice(NoticeType noticeType, const std::string &eventData) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return ResultCode::WRITE_PARCEL_ERROR; - } - - int32_t type = static_cast(noticeType); - if (!data.WriteInt32(type)) { - IAM_LOGE("failed to write noticeType"); - return ResultCode::WRITE_PARCEL_ERROR; - } - if (!data.WriteString(eventData)) { - IAM_LOGE("failed to write eventData"); - return ResultCode::WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_NOTICE, data, reply); - if (!ret) { - IAM_LOGE("failed to send user notice IPC request"); - return ResultCode::GENERAL_ERROR; - } - int32_t result = ResultCode::GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return ResultCode::READ_PARCEL_ERROR; - } - return result; -} - -int32_t UserAuthProxy::RegisterWidgetCallback(int32_t version, sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return GENERAL_ERROR; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return GENERAL_ERROR; - } - - if (!data.WriteInt32(version)) { - IAM_LOGE("failed to write version"); - return WRITE_PARCEL_ERROR; - } - - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_REG_WIDGET_CB, data, reply); - if (!ret) { - IAM_LOGE("failed to send register widget callback IPC request"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -int32_t UserAuthProxy::GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - - if (!data.WriteInt32(apiVersion)) { - IAM_LOGE("failed to write apiVersion"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(authType)) { - IAM_LOGE("failed to write authType"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_GET_ENROLLED_STATE, data, reply); - if (!ret) { - IAM_LOGE("get enrolled state failed to send request"); - return GENERAL_ERROR; - } - - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - if (result != SUCCESS) { - IAM_LOGE("failed to get enrolled state"); - return result; - } - uint64_t credentialDigest; - if (!reply.ReadUint64(credentialDigest)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - uint16_t credentialCount; - if (!reply.ReadUint16(credentialCount)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - enrolledState.credentialDigest = credentialDigest; - enrolledState.credentialCount = credentialCount; - return SUCCESS; -} - -int32_t UserAuthProxy::RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) -{ - if (listener == nullptr) { - IAM_LOGE("listener is nullptr"); - return GENERAL_ERROR; - } - - MessageParcel data; - MessageParcel reply; - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - - std::vector authTypeList; - for (auto &iter : authType) { - authTypeList.emplace_back(static_cast(iter)); - } - - if (!data.WriteInt32Vector(authTypeList)) { - IAM_LOGE("failed to write authType"); - return WRITE_PARCEL_ERROR; - } - - if (!data.WriteRemoteObject(listener->AsObject())) { - IAM_LOGE("failed to write listener"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_REG_EVENT_LISTENER, data, reply); - if (!ret) { - IAM_LOGE("failed to send register event listener callback IPC request"); - return GENERAL_ERROR; - } - - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -int32_t UserAuthProxy::UnRegistUserAuthSuccessEventListener(const sptr &listener) -{ - if (listener == nullptr) { - IAM_LOGE("listener is nullptr"); - return GENERAL_ERROR; - } - - MessageParcel data; - MessageParcel reply; - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - - if (!data.WriteRemoteObject(listener->AsObject())) { - IAM_LOGE("failed to write listener"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_UNREG_EVENT_LISTENER, data, reply); - if (!ret) { - IAM_LOGE("failed to send register event listener callback IPC request"); - return GENERAL_ERROR; - } - - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -ResultCode UserAuthProxy::WriteGlobalConfigValue(MessageParcel &data, const GlobalConfigParam ¶m) -{ - switch (param.type) { - case GlobalConfigType::PIN_EXPIRED_PERIOD: - if (!data.WriteInt64(param.value.pinExpiredPeriod)) { - IAM_LOGE("failed to write GlobalConfigParam pinExpiredPeriod"); - return WRITE_PARCEL_ERROR; - } - break; - case GlobalConfigType::ENABLE_STATUS : - if (!data.WriteBool(param.value.enableStatus)) { - IAM_LOGE("failed to write GlobalConfigParam enableStatus"); - return WRITE_PARCEL_ERROR; - } - break; - default: - IAM_LOGE("GlobalConfigType not support."); - return INVALID_PARAMETERS; - } - return SUCCESS; -} - - -int32_t UserAuthProxy::SetGlobalConfigParam(const GlobalConfigParam ¶m) -{ - MessageParcel data; - MessageParcel reply; - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(param.type)) { - IAM_LOGE("failed to write GlobalConfigParam type"); - return WRITE_PARCEL_ERROR; - } - int32_t result = WriteGlobalConfigValue(data, param); - if (result != SUCCESS) { - IAM_LOGE("failed to WriteGlobalConfigValue"); - return result; - } - if (!data.WriteInt32Vector(param.userIds)) { - IAM_LOGE("failed to write userIds"); - return WRITE_PARCEL_ERROR; - } - std::vector authTypeList; - for (const auto &authType : param.authTypes) { - authTypeList.push_back(static_cast(authType)); - } - if (!data.WriteInt32Vector(authTypeList)) { - IAM_LOGE("failed to write authTypeList"); - return WRITE_PARCEL_ERROR; - } - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_SET_CLOBAL_CONFIG_PARAM, data, reply); - if (!ret) { - IAM_LOGE("failed to set global config param IPC request"); - return GENERAL_ERROR; - } - result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -int32_t UserAuthProxy::PrepareRemoteAuth(const std::string &networkId, sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return GENERAL_ERROR; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return GENERAL_ERROR; - } - if (!data.WriteString(networkId)) { - IAM_LOGE("failed to write networkId"); - return GENERAL_ERROR; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return GENERAL_ERROR; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH, data, reply); - if (!ret) { - IAM_LOGE("failed to send prepare remote auth IPC request"); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - return result; -} - -void UserAuthProxy::VerifyAuthToken(const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - Attributes extraInfo; - - if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - callback->OnVerifyTokenResult(WRITE_PARCEL_ERROR, extraInfo); - return; - } - if (!data.WriteUInt8Vector(tokenIn)) { - IAM_LOGE("failed to write tokenIn"); - callback->OnVerifyTokenResult(WRITE_PARCEL_ERROR, extraInfo); - return; - } - if (!data.WriteUint64(allowableDuration)) { - IAM_LOGE("failed to write allowableDuration"); - callback->OnVerifyTokenResult(WRITE_PARCEL_ERROR, extraInfo); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - callback->OnVerifyTokenResult(WRITE_PARCEL_ERROR, extraInfo); - return; - } - - bool ret = SendRequest(UserAuthInterfaceCode::USER_ACCESS_CTRL_VERIFY_AUTH_TOKEN, data, reply); - if (!ret) { - IAM_LOGE("failed to send verify token IPC request"); - callback->OnVerifyTokenResult(GENERAL_ERROR, extraInfo); - } -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_auth_stub.cpp b/frameworks/native/ipc/src/user_auth_stub.cpp deleted file mode 100644 index cb84a38f6241fe4f2a8191a58a3d48e705ed309b..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_auth_stub.cpp +++ /dev/null @@ -1,948 +0,0 @@ -/* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_stub.h" - -#include -#include - -#include "iam_logger.h" -#include "iam_scope_guard.h" -#include "iam_common_defines.h" -#include "modal_callback_proxy.h" -#include "user_access_ctrl_callback_proxy.h" -#include "user_auth_callback_proxy.h" -#include "user_auth_event_listener_proxy.h" -#include "widget_callback_proxy.h" -#include "user_auth_common_defines.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { - const uint32_t MAX_ATTR_COUNT = 512; -} // namespace - -// When true is passed into IRemoteStub, sa will process request serially. -UserAuthStub::UserAuthStub() : IRemoteStub(true) {}; - -int32_t UserAuthStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - IAM_LOGD("cmd = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (UserAuthStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - switch (code) { - case UserAuthInterfaceCode::USER_AUTH_GET_AVAILABLE_STATUS: - return GetAvailableStatusStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY: - return GetPropertyStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_SET_PROPERTY: - return SetPropertyStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_AUTH: - return AuthStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_AUTH_WIDGET: - return AuthWidgetStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_AUTH_USER: - return AuthUserStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_CANCEL_AUTH: - return CancelAuthOrIdentifyStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_IDENTIFY: - return IdentifyStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_CANCEL_IDENTIFY: - return CancelAuthOrIdentifyStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_GET_VERSION: - return GetVersionStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_NOTICE: - return NoticeStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_REG_WIDGET_CB: - return RegisterWidgetCallbackStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_GET_ENROLLED_STATE: - return GetEnrolledStateStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_REG_EVENT_LISTENER: - return RegistUserAuthSuccessEventListenerStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_UNREG_EVENT_LISTENER: - return UnRegistUserAuthSuccessEventListenerStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_SET_CLOBAL_CONFIG_PARAM: - return SetGlobalConfigParamStub(data, reply); - case UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH: - return PrepareRemoteAuthStub(data, reply); - default: - return OnRemoteRequestExt(code, data, reply, option); - } -} - -int32_t UserAuthStub::OnRemoteRequestExt(uint32_t code, MessageParcel &data, - MessageParcel &reply, MessageOption &option) -{ - switch (code) { - case UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY_BY_ID: - return GetPropertyByIdStub(data, reply); - case UserAuthInterfaceCode::USER_ACCESS_CTRL_VERIFY_AUTH_TOKEN: - return VerifyAuthTokenStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t UserAuthStub::GetAvailableStatusStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t authType; - uint32_t authTrustLevel; - int32_t apiVersion; - int32_t userId; - bool isSpecificUserId = false; - if (!data.ReadBool(isSpecificUserId)) { - IAM_LOGE("failed to read isSpecificUserId"); - return READ_PARCEL_ERROR; - } - if (isSpecificUserId && !data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint32(authTrustLevel)) { - IAM_LOGE("failed to read authTrustLevel"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(apiVersion)) { - IAM_LOGE("failed to read apiVersion"); - return READ_PARCEL_ERROR; - } - - int32_t result = GENERAL_ERROR; - if (isSpecificUserId) { - result = GetAvailableStatus(apiVersion, userId, static_cast(authType), - static_cast(authTrustLevel)); - } else { - result = GetAvailableStatus(apiVersion, static_cast(authType), - static_cast(authTrustLevel)); - } - - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write GetAvailableStatus result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::GetPropertyStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - int32_t authType; - std::vector keys; - - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt32Vector(&keys)) { - IAM_LOGE("failed to read attribute keys"); - return READ_PARCEL_ERROR; - } - std::vector attrKeys; - if (keys.empty()) { - IAM_LOGE("the attribute key vector is empty"); - return GENERAL_ERROR; - } - if (keys.size() > MAX_ATTR_COUNT) { - IAM_LOGE("the attribute key vector size exceed limit"); - return GENERAL_ERROR; - } - attrKeys.resize(keys.size()); - std::transform(keys.begin(), keys.end(), attrKeys.begin(), [](uint32_t key) { - return static_cast(key); - }); - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("GetExecutorPropertyCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - GetProperty(userId, static_cast(authType), attrKeys, callback); - return SUCCESS; -} - -int32_t UserAuthStub::GetPropertyByIdStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - uint64_t credentialId; - std::vector keys; - - if (!data.ReadUint64(credentialId)) { - IAM_LOGE("failed to read credentialId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt32Vector(&keys)) { - IAM_LOGE("failed to read attribute keys"); - return READ_PARCEL_ERROR; - } - std::vector attrKeys; - if (keys.empty()) { - IAM_LOGE("the attribute key vector is empty"); - return GENERAL_ERROR; - } - if (keys.size() > MAX_ATTR_COUNT) { - IAM_LOGE("the attribute key vector size exceed limit"); - return GENERAL_ERROR; - } - attrKeys.resize(keys.size()); - std::transform(keys.begin(), keys.end(), attrKeys.begin(), [](uint32_t key) { - return static_cast(key); - }); - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("GetExecutorPropertyCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - GetPropertyById(credentialId, attrKeys, callback); - return SUCCESS; -} - -int32_t UserAuthStub::SetPropertyStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - int32_t authType; - std::vector attr; - - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&attr)) { - IAM_LOGE("failed to read attributes"); - return READ_PARCEL_ERROR; - } - Attributes attributes(attr); - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("SetExecutorPropertyCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - SetProperty(userId, static_cast(authType), attributes, callback); - return SUCCESS; -} - -int32_t UserAuthStub::AuthStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t apiVersion; - if (!data.ReadInt32(apiVersion)) { - IAM_LOGE("failed to read apiVersion"); - return READ_PARCEL_ERROR; - } - - AuthParamInner authParam; - if (!ReadAuthParam(data, authParam)) { - IAM_LOGE("failed to read auth param"); - return READ_PARCEL_ERROR; - } - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("UserAuthCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - uint64_t contextId = Auth(apiVersion, authParam.challenge, authParam.authType, authParam.authTrustLevel, - callback); - if (!reply.WriteUint64(contextId)) { - IAM_LOGE("failed to write AuthUser result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::AuthWidgetStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - AuthParamInner authParam; - WidgetParamInner widgetParam; - if (!ReadWidgetAuthParam(data, authParam)) { - IAM_LOGE("failed to read widget auth param"); - return ResultCode::READ_PARCEL_ERROR; - } - - if (!ReadWidgetParam(data, widgetParam)) { - IAM_LOGE("failed to read widget param"); - return ResultCode::READ_PARCEL_ERROR; - } - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return ResultCode::READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("UserAuthCallbackInterface is nullptr"); - return ResultCode::GENERAL_ERROR; - } - - sptr objModal = data.ReadRemoteObject(); - if (objModal == nullptr) { - IAM_LOGE("failed to read remote object for modal callback"); - return ResultCode::READ_PARCEL_ERROR; - } - sptr modalCallback = iface_cast(objModal); - - int32_t apiVersion; - if (!data.ReadInt32(apiVersion)) { - IAM_LOGE("failed to read apiVersion"); - return ResultCode::READ_PARCEL_ERROR; - } - - uint64_t contextId = AuthWidget(apiVersion, authParam, widgetParam, callback, modalCallback); - if (!reply.WriteUint64(contextId)) { - IAM_LOGE("failed to write contextId"); - return ResultCode::WRITE_PARCEL_ERROR; - } - return ResultCode::SUCCESS; -} - -bool UserAuthStub::ReadWidgetAuthParam(MessageParcel &data, AuthParamInner &authParam) -{ - if (!data.ReadInt32(authParam.userId)) { - IAM_LOGE("failed to read userId"); - return false; - } - if (!data.ReadBool(authParam.isUserIdSpecified)) { - IAM_LOGE("failed to read isUserIdSpecified"); - return false; - } - if (!data.ReadUInt8Vector(&authParam.challenge)) { - IAM_LOGE("failed to read challenge"); - return false; - } - std::vector atList; - if (!data.ReadInt32Vector(&atList)) { - IAM_LOGE("failed to read authTypeList"); - return false; - } - for (auto at : atList) { - authParam.authTypes.push_back(static_cast(at)); - } - - uint32_t authTrustLevel; - if (!data.ReadUint32(authTrustLevel)) { - IAM_LOGE("failed to read authTrustLevel"); - return false; - } - authParam.authTrustLevel = static_cast(authTrustLevel); - - if (!data.ReadBool(authParam.reuseUnlockResult.isReuse)) { - IAM_LOGE("failed to read isReuse unlock result"); - return false; - } - authParam.reuseUnlockResult.reuseDuration = 0; - uint32_t reuseMode = AUTH_TYPE_IRRELEVANT; - if (authParam.reuseUnlockResult.isReuse) { - if (!data.ReadUint32(reuseMode)) { - IAM_LOGE("failed to read reuseMode"); - return false; - } - if (!data.ReadUint64(authParam.reuseUnlockResult.reuseDuration)) { - IAM_LOGE("failed to read reuseDuration"); - return false; - } - } - authParam.reuseUnlockResult.reuseMode = static_cast(reuseMode); - return true; -} - -bool UserAuthStub::ReadWidgetParam(MessageParcel &data, WidgetParamInner &widgetParam) -{ - if (!data.ReadString(widgetParam.title)) { - IAM_LOGE("failed to read title"); - return false; - } - if (!data.ReadString(widgetParam.navigationButtonText)) { - IAM_LOGE("failed to read navigationButtonText"); - return false; - } - int32_t winMode; - if (!data.ReadInt32(winMode)) { - IAM_LOGE("failed to read window mode"); - return false; - } - widgetParam.windowMode = static_cast(winMode); - if (!data.ReadBool(widgetParam.hasContext)) { - IAM_LOGE("failed to read hasContext"); - return false; - } - return true; -} - -int32_t UserAuthStub::AuthUserStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - AuthParamInner authParam; - if (!ReadAuthParam(data, authParam)) { - IAM_LOGE("failed to read auth param"); - return READ_PARCEL_ERROR; - } - - std::optional remoteAuthParam; - if (!ReadRemoteAuthParam(data, remoteAuthParam)) { - IAM_LOGE("failed to read auth param"); - return READ_PARCEL_ERROR; - } - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("UserAuthCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - uint64_t contextId = AuthUser(authParam, remoteAuthParam, callback); - if (!reply.WriteUint64(contextId)) { - IAM_LOGE("failed to write AuthUser result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::IdentifyStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - std::vector challenge; - int32_t authType; - - if (!data.ReadUInt8Vector(&challenge)) { - IAM_LOGE("failed to read challenge"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("UserAuthCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - uint64_t contextId = Identify(challenge, static_cast(authType), callback); - if (!reply.WriteUint64(contextId)) { - IAM_LOGE("failed to write Identify result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::CancelAuthOrIdentifyStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - uint64_t contextId; - - if (!data.ReadUint64(contextId)) { - IAM_LOGE("failed to read contextId"); - return READ_PARCEL_ERROR; - } - - int32_t cancelReason; - - if (!data.ReadInt32(cancelReason)) { - IAM_LOGE("failed to read cancelReason"); - return READ_PARCEL_ERROR; - } - - int32_t result = CancelAuthOrIdentify(contextId, cancelReason); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write CancelAuthOrIdentify result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::GetVersionStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t version; - int32_t result = GetVersion(version); - if (!reply.WriteInt32(version)) { - IAM_LOGE("failed to write GetVersion version"); - return WRITE_PARCEL_ERROR; - } - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write GetVersion result"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::NoticeStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t type; - if (!data.ReadInt32(type)) { - IAM_LOGE("failed to read type"); - return ResultCode::READ_PARCEL_ERROR; - } - NoticeType noticeType = static_cast(type); - if (noticeType != WIDGET_NOTICE) { - IAM_LOGE("NoticeStub unsupport notice type"); - return ResultCode::GENERAL_ERROR; - } - std::string eventData; - if (!data.ReadString(eventData)) { - IAM_LOGE("failed to read eventData"); - return ResultCode::READ_PARCEL_ERROR; - } - - int32_t result = Notice(noticeType, eventData); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write notice result"); - return ResultCode::WRITE_PARCEL_ERROR; - } - IAM_LOGI("noticeStub success"); - return ResultCode::SUCCESS; -} - -int32_t UserAuthStub::RegisterWidgetCallbackStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t version; - if (!data.ReadInt32(version)) { - IAM_LOGE("failed to read version"); - return READ_PARCEL_ERROR; - } - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("RegisterWidgetCallbackStub is nullptr"); - return GENERAL_ERROR; - } - int32_t result = RegisterWidgetCallback(version, callback); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write register widget callback result"); - return WRITE_PARCEL_ERROR; - } - IAM_LOGI("RegisterWidgetCallbackStub success"); - return SUCCESS; -} - -int32_t UserAuthStub::GetEnrolledStateStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t apiVersion; - if (!data.ReadInt32(apiVersion)) { - IAM_LOGE("failed to read apiVersion"); - return READ_PARCEL_ERROR; - } - - int32_t authType; - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - EnrolledState enrolledState = {}; - int32_t ret = GetEnrolledState(apiVersion, static_cast(authType), enrolledState); - if (!reply.WriteInt32(ret)) { - IAM_LOGE("failed to write ret"); - return WRITE_PARCEL_ERROR; - } - if (!reply.WriteUint64(enrolledState.credentialDigest)) { - IAM_LOGE("failed to write credentialDigest"); - return WRITE_PARCEL_ERROR; - } - if (!reply.WriteUint16(enrolledState.credentialCount)) { - IAM_LOGE("failed to write credentialCount"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::RegistUserAuthSuccessEventListenerStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - std::vector authType; - if (!data.ReadInt32Vector(&authType)) { - IAM_LOGE("failed to read authTypeList"); - return READ_PARCEL_ERROR; - } - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr listener = iface_cast(obj); - if (listener == nullptr) { - IAM_LOGE("authEventListener listener is nullptr"); - return GENERAL_ERROR; - } - std::vector authTypeList; - for (auto &iter : authType) { - authTypeList.emplace_back(static_cast(iter)); - } - int32_t result = RegistUserAuthSuccessEventListener(authTypeList, listener); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write regist event listener result"); - return WRITE_PARCEL_ERROR; - } - IAM_LOGI("RegistUserAuthSuccessEventListenerStub success"); - return SUCCESS; -} - -int32_t UserAuthStub::UnRegistUserAuthSuccessEventListenerStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr listener = iface_cast(obj); - if (listener == nullptr) { - IAM_LOGE("authEventListener listener is nullptr"); - return GENERAL_ERROR; - } - int32_t result = UnRegistUserAuthSuccessEventListener(listener); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write regist event listener result"); - return WRITE_PARCEL_ERROR; - } - IAM_LOGI("UnRegistUserAuthSuccessEventListener success"); - return SUCCESS; -} - -ResultCode UserAuthStub::ReadGlobalConfigValue(MessageParcel &data, GlobalConfigParam ¶m) -{ - switch (param.type) { - case GlobalConfigType::PIN_EXPIRED_PERIOD: - if (!data.ReadInt64(param.value.pinExpiredPeriod)) { - IAM_LOGE("failed to read GlobalConfigParam pinExpiredPeriod"); - return READ_PARCEL_ERROR; - } - break; - case GlobalConfigType::ENABLE_STATUS : - if (!data.ReadBool(param.value.enableStatus)) { - IAM_LOGE("failed to read GlobalConfigParam enableStatus"); - return READ_PARCEL_ERROR; - } - break; - default: - IAM_LOGE("GlobalConfigType not support."); - return INVALID_PARAMETERS; - } - return SUCCESS; -} - -int32_t UserAuthStub::SetGlobalConfigParamStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - GlobalConfigParam globalConfigParam = {}; - int32_t globalConfigType; - if (!data.ReadInt32(globalConfigType)) { - IAM_LOGE("failed to read globalConfigType"); - return READ_PARCEL_ERROR; - } - globalConfigParam.type = static_cast(globalConfigType); - int32_t ret = ReadGlobalConfigValue(data, globalConfigParam); - if (ret != SUCCESS) { - IAM_LOGE("failed to ReadGlobalConfigValue"); - return ret; - } - if (!data.ReadInt32Vector(&globalConfigParam.userIds)) { - IAM_LOGE("failed to read userIds"); - return READ_PARCEL_ERROR; - } - std::vector authTypeList; - if (!data.ReadInt32Vector(&authTypeList)) { - IAM_LOGE("failed to read authTypeList"); - return READ_PARCEL_ERROR; - } - for (const auto &authType : authTypeList) { - globalConfigParam.authTypes.push_back(static_cast(authType)); - } - ret = SetGlobalConfigParam(globalConfigParam); - if (!reply.WriteInt32(ret)) { - IAM_LOGE("failed to write ret"); - return WRITE_PARCEL_ERROR; - } - return SUCCESS; -} - -int32_t UserAuthStub::PrepareRemoteAuthStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - std::string networkId; - if (!data.ReadString(networkId)) { - IAM_LOGE("failed to read networkId"); - return READ_PARCEL_ERROR; - } - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("UserAuthCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - int32_t result = PrepareRemoteAuth(networkId, callback); - if (!reply.WriteInt32(result)) { - IAM_LOGE("failed to write PrepareRemoteAuth result"); - return WRITE_PARCEL_ERROR; - } - - return SUCCESS; -} - -bool UserAuthStub::ReadAuthParam(MessageParcel &data, AuthParamInner &authParam) -{ - if (!data.ReadInt32(authParam.userId)) { - IAM_LOGE("failed to read userId"); - return false; - } - if (!data.ReadUInt8Vector(&authParam.challenge)) { - IAM_LOGE("failed to read challenge"); - return false; - } - int32_t authTypeInt; - if (!data.ReadInt32(authTypeInt)) { - IAM_LOGE("failed to read authType"); - return false; - } - authParam.authType = static_cast(authTypeInt); - - std::vector authTypeInts; - if (!data.ReadInt32Vector(&authTypeInts)) { - IAM_LOGE("failed to read authTypeInts"); - return false; - } - - for (auto val : authTypeInts) { - authParam.authTypes.push_back(static_cast(val)); - } - - uint32_t authTrustLevelUint; - if (!data.ReadUint32(authTrustLevelUint)) { - IAM_LOGE("failed to read authTrustLevel"); - return false; - } - authParam.authTrustLevel = static_cast(authTrustLevelUint); - - uint32_t authIntent; - if (!data.ReadUint32(authIntent)) { - IAM_LOGE("failed to write authIntent"); - return false; - } - authParam.authIntent = static_cast(authIntent); - - return true; -} - -bool UserAuthStub::ReadRemoteAuthParam(MessageParcel &data, std::optional &remoteAuthParam) -{ - bool hasRemoteAuthParam; - if (!data.ReadBool(hasRemoteAuthParam)) { - IAM_LOGE("failed to read hasRemoteAuthParam"); - return false; - } - - if (!hasRemoteAuthParam) { - remoteAuthParam = std::nullopt; - return true; - } - remoteAuthParam = RemoteAuthParam{}; - - if (!ReadOptionalString(data, remoteAuthParam->verifierNetworkId)) { - IAM_LOGE("failed to read verifierNetworkId"); - return false; - } - - if (!ReadOptionalString(data, remoteAuthParam->collectorNetworkId)) { - IAM_LOGE("failed to read collectorNetworkId"); - return false; - } - - if (!ReadOptionalUint32(data, remoteAuthParam->collectorTokenId)) { - IAM_LOGE("failed to read collectorTokenId"); - return false; - } - - return true; -} - -bool UserAuthStub::ReadOptionalString(MessageParcel &data, std::optional &str) -{ - bool hasStr; - if (!data.ReadBool(hasStr)) { - IAM_LOGE("failed to read hasStr"); - return false; - } - - if (hasStr) { - std::string readStr; - if (!data.ReadString(readStr)) { - IAM_LOGE("failed to read value"); - return false; - } - str = readStr; - } else { - str = std::nullopt; - } - return true; -} -bool UserAuthStub::ReadOptionalUint32(MessageParcel &data, std::optional &val) -{ - bool hasVal; - if (!data.ReadBool(hasVal)) { - IAM_LOGE("failed to read hasVal"); - return false; - } - - if (hasVal) { - uint32_t readValue; - if (!data.ReadUint32(readValue)) { - IAM_LOGE("failed to read data"); - return false; - } - val = readValue; - } else { - val = std::nullopt; - } - return true; -} - -int32_t UserAuthStub::VerifyAuthTokenStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - std::vector tokenIn = {}; - uint64_t allowableDuration = 0; - if (!data.ReadUInt8Vector(&tokenIn)) { - IAM_LOGE("failed to read tokenIn"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint64(allowableDuration)) { - IAM_LOGE("failed to read allowableDuration"); - return READ_PARCEL_ERROR; - } - - sptr obj = data.ReadRemoteObject(); - if (obj == nullptr) { - IAM_LOGE("failed to read remote object"); - return READ_PARCEL_ERROR; - } - sptr callback = iface_cast(obj); - if (callback == nullptr) { - IAM_LOGE("VerifyTokenCallbackInterface is nullptr"); - return GENERAL_ERROR; - } - - VerifyAuthToken(tokenIn, allowableDuration, callback); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_idm_callback_proxy.cpp b/frameworks/native/ipc/src/user_idm_callback_proxy.cpp deleted file mode 100644 index 276f9fe2a28c5e82f2dc8cfd764da413ce299073..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_idm_callback_proxy.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_callback_proxy.h" - -#include "iam_logger.h" -#include "iam_common_defines.h" -#include "user_idm_interface.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -void IdmCallbackProxy::OnResult(int32_t result, const Attributes &extraInfo) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(IdmCallbackProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(result)) { - IAM_LOGE("failed to write result"); - return; - } - auto buffer = extraInfo.Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("failed to write buffer"); - return; - } - - bool ret = SendRequest(IdmCallbackInterfaceCode::IDM_CALLBACK_ON_RESULT, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - } -} - -void IdmCallbackProxy::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(IdmCallbackProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(module)) { - IAM_LOGE("failed to write module"); - return; - } - if (!data.WriteInt32(acquireInfo)) { - IAM_LOGE("failed to write acquire"); - return; - } - auto buffer = extraInfo.Serialize(); - if (!data.WriteUInt8Vector(buffer)) { - IAM_LOGE("failed to write buffer"); - return; - } - - bool ret = SendRequest(IdmCallbackInterfaceCode::IDM_CALLBACK_ON_ACQUIRE_INFO, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - } -} - -bool IdmCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != SUCCESS) { - IAM_LOGE("failed to send request, result = %{public}d", result); - return false; - } - - IAM_LOGI("end"); - return true; -} - -void IdmGetCredentialInfoProxy::OnCredentialInfos(int32_t result, const std::vector &credInfoList) -{ - IAM_LOGI("start, cred info vector size: %{public}zu", credInfoList.size()); - - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(IdmGetCredentialInfoProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(result)) { - IAM_LOGE("failed to write result"); - return; - } - if (!data.WriteUint32(credInfoList.size())) { - IAM_LOGE("failed to write credInfoList size"); - return; - } - for (const auto &info : credInfoList) { - if (!data.WriteUint64(info.credentialId)) { - IAM_LOGE("failed to write credentialId"); - return; - } - if (!data.WriteInt32(info.authType)) { - IAM_LOGE("failed to write authType"); - return; - } - if (!data.WriteInt32(info.pinType.value_or(static_cast(0)))) { - IAM_LOGE("failed to write pinSubType"); - return; - } - if (!data.WriteUint64(info.templateId)) { - IAM_LOGE("failed to write templateId"); - return; - } - } - - bool ret = SendRequest(IdmGetCredInfoCallbackInterfaceCode::ON_GET_INFO, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - } -} - -bool IdmGetCredentialInfoProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != SUCCESS) { - IAM_LOGE("failed to send request result = %{public}d", result); - return false; - } - - IAM_LOGI("end"); - return true; -} - -ResultCode IdmGetSecureUserInfoProxy::WriteSecureUserInfo(MessageParcel &data, const SecUserInfo &secUserInfo) - -{ - IAM_LOGI("start"); - if (!data.WriteUint64(secUserInfo.secureUid)) { - IAM_LOGE("failed to write secureUid"); - return WRITE_PARCEL_ERROR; - } - uint32_t enrolledInfoLen = secUserInfo.enrolledInfo.size(); - IAM_LOGI("write enrolled info vector len: %{public}u", enrolledInfoLen); - if (!data.WriteUint32(enrolledInfoLen)) { - IAM_LOGE("failed to write enrolledInfoLen"); - return WRITE_PARCEL_ERROR; - } - for (const auto &info : secUserInfo.enrolledInfo) { - if (!data.WriteInt32(info.authType)) { - IAM_LOGE("failed to write authType"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteUint64(info.enrolledId)) { - IAM_LOGE("failed to write enrolledId"); - return WRITE_PARCEL_ERROR; - } - } - return SUCCESS; -} - -void IdmGetSecureUserInfoProxy::OnSecureUserInfo(int32_t result, const SecUserInfo &secUserInfo) -{ - IAM_LOGI("start"); - - MessageParcel data; - MessageParcel reply; - if (!data.WriteInterfaceToken(IdmGetSecureUserInfoProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(result)) { - IAM_LOGE("failed to write result"); - return; - } - if (WriteSecureUserInfo(data, secUserInfo) != SUCCESS) { - IAM_LOGE("WriteSecureUserInfo fail"); - return; - } - - bool ret = SendRequest(IdmGetSecureUserInfoCallbackInterfaceCode::ON_GET_SEC_INFO, data, reply); - if (!ret) { - IAM_LOGE("failed to send request"); - } -} - -bool IdmGetSecureUserInfoProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_ASYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != SUCCESS) { - IAM_LOGE("failed to send request result = %{public}d", result); - return false; - } - - IAM_LOGI("end"); - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/frameworks/native/ipc/src/user_idm_callback_stub.cpp b/frameworks/native/ipc/src/user_idm_callback_stub.cpp deleted file mode 100644 index afc82213e85e3bddced6f407ce97476be23fe06d..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_idm_callback_stub.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_callback_stub.h" - -#include "iam_logger.h" -#include "user_idm_client_defines.h" - -#define LOG_TAG "USER_IDM_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { - const uint32_t INFO_VECTOR_LENGTH_LIMIT = 100; -} // namespace - -int32_t IdmCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (IdmCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - switch (code) { - case IdmCallbackInterfaceCode::IDM_CALLBACK_ON_RESULT: - return OnResultStub(data, reply); - case IdmCallbackInterfaceCode::IDM_CALLBACK_ON_ACQUIRE_INFO: - return OnAcquireInfoStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t IdmCallbackStub::OnResultStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t result; - std::vector buffer; - - if (!data.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read buffer"); - return READ_PARCEL_ERROR; - } - - Attributes extraInfo(buffer); - OnResult(result, extraInfo); - return SUCCESS; -} - -int32_t IdmCallbackStub::OnAcquireInfoStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t module; - int32_t acquireInfo; - std::vector buffer; - - if (!data.ReadInt32(module)) { - IAM_LOGE("failed to read module"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(acquireInfo)) { - IAM_LOGE("failed to read acquireInfo"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUInt8Vector(&buffer)) { - IAM_LOGE("failed to read buffer"); - return READ_PARCEL_ERROR; - } - - Attributes extraInfo(buffer); - OnAcquireInfo(module, acquireInfo, extraInfo); - return SUCCESS; -} - -int32_t IdmGetCredInfoCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (IdmGetCredInfoCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - if (code == IdmGetCredInfoCallbackInterfaceCode::ON_GET_INFO) { - return OnCredentialInfosStub(data, reply); - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -ResultCode IdmGetCredInfoCallbackStub::ReadCredentialInfoList(MessageParcel &data, - std::vector &credInfoList) -{ - IAM_LOGI("start"); - uint32_t credInfosLen = 0; - if (!data.ReadUint32(credInfosLen)) { - IAM_LOGE("read credInfosLen fail"); - return READ_PARCEL_ERROR; - } - IAM_LOGI("read cred info vector len: %{public}u", credInfosLen); - if (credInfosLen > INFO_VECTOR_LENGTH_LIMIT) { - IAM_LOGE("the cred info vector size exceed limit"); - return GENERAL_ERROR; - } - for (uint32_t i = 0; i < credInfosLen; ++i) { - CredentialInfo info = {}; - int32_t authType; - int32_t pinType = 0; - if (!data.ReadUint64(info.credentialId)) { - IAM_LOGE("failed to read credentialId"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - if (!data.ReadInt32(pinType)) { - IAM_LOGE("failed to read pinSubType"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint64(info.templateId)) { - IAM_LOGE("failed to read templateId"); - return READ_PARCEL_ERROR; - } - info.authType = static_cast(authType); - info.pinType = static_cast(pinType); - credInfoList.push_back(info); - } - return SUCCESS; -} - -int32_t IdmGetCredInfoCallbackStub::OnCredentialInfosStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t result = GENERAL_ERROR; - if (!data.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - std::vector credInfoList; - if (ReadCredentialInfoList(data, credInfoList) != SUCCESS) { - IAM_LOGE("ReadCredentialInfoList fail"); - credInfoList.clear(); - } - OnCredentialInfos(result, credInfoList); - return SUCCESS; -} - -int32_t IdmGetSecureUserInfoCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (IdmGetSecureUserInfoCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - if (code == IdmGetSecureUserInfoCallbackInterfaceCode::ON_GET_SEC_INFO) { - return OnSecureUserInfoStub(data, reply); - } - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); -} - -ResultCode IdmGetSecureUserInfoCallbackStub::ReadSecureUserInfo(MessageParcel &data, SecUserInfo &secUserInfo) -{ - IAM_LOGI("start"); - uint32_t enrolledInfoLen; - if (!data.ReadUint64(secUserInfo.secureUid)) { - IAM_LOGE("failed to read secureUid"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint32(enrolledInfoLen)) { - IAM_LOGE("failed to read enrolledInfoLen"); - return READ_PARCEL_ERROR; - } - IAM_LOGI("read enrolled info vector len: %{public}u", enrolledInfoLen); - if (enrolledInfoLen > INFO_VECTOR_LENGTH_LIMIT) { - IAM_LOGE("the enrolled info vector size exceed limit"); - return GENERAL_ERROR; - } - secUserInfo.enrolledInfo.resize(enrolledInfoLen); - for (uint32_t i = 0; i < enrolledInfoLen; ++i) { - int32_t authType; - uint64_t enrolledId; - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - if (!data.ReadUint64(enrolledId)) { - IAM_LOGE("failed to read enrolledId"); - return READ_PARCEL_ERROR; - } - secUserInfo.enrolledInfo[i] = {static_cast(authType), enrolledId}; - } - return SUCCESS; -} - -int32_t IdmGetSecureUserInfoCallbackStub::OnSecureUserInfoStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - int32_t result = GENERAL_ERROR; - if (!data.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - return READ_PARCEL_ERROR; - } - SecUserInfo secUserInfo = {}; - if (ReadSecureUserInfo(data, secUserInfo) != SUCCESS) { - IAM_LOGE("ReadSecureUserInfo fail"); - secUserInfo.secureUid = 0; - secUserInfo.enrolledInfo.clear(); - } - - OnSecureUserInfo(result, secUserInfo); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_idm_proxy.cpp b/frameworks/native/ipc/src/user_idm_proxy.cpp deleted file mode 100644 index 88f4922c7263d29b031d8858cf3571dd32e94523..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_idm_proxy.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_proxy.h" - -#include - -#include "iam_logger.h" - -#define LOG_TAG "USER_IDM_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -UserIdmProxy::UserIdmProxy(const sptr &object) : IRemoteProxy(object) -{ -} - -int32_t UserIdmProxy::OpenSession(int32_t userId, std::vector &challenge) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserIdmInterfaceCode::USER_IDM_OPEN_SESSION, data, reply); - if (!ret) { - return GENERAL_ERROR; - } - if (!reply.ReadUInt8Vector(&challenge)) { - IAM_LOGE("failed to read challenge"); - return READ_PARCEL_ERROR; - } - return SUCCESS; -} - -void UserIdmProxy::CloseSession(int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return; - } - - SendRequest(UserIdmInterfaceCode::USER_IDM_CLOSE_SESSION, data, reply); -} - -int32_t UserIdmProxy::GetCredentialInfo(int32_t userId, AuthType authType, - const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return GENERAL_ERROR; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(authType)) { - IAM_LOGE("failed to write authType"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserIdmInterfaceCode::USER_IDM_GET_CRED_INFO, data, reply); - if (!ret) { - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -int32_t UserIdmProxy::GetSecInfo(int32_t userId, const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return GENERAL_ERROR; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserIdmInterfaceCode::USER_IDM_GET_SEC_INFO, data, reply); - if (!ret) { - SecUserInfo secUserInfo = {}; - callback->OnSecureUserInfo(GENERAL_ERROR, secUserInfo); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -void UserIdmProxy::AddCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback, bool isUpdate) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return; - } - if (!data.WriteInt32(credPara.authType)) { - IAM_LOGE("failed to write authType"); - return; - } - if (!data.WriteInt32(credPara.pinType)) { - IAM_LOGE("failed to write pinSubType"); - return; - } - if (!data.WriteUInt8Vector(credPara.token)) { - IAM_LOGE("failed to write token"); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - SendRequest(UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL, data, reply); -} - -void UserIdmProxy::UpdateCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return; - } - if (!data.WriteInt32(credPara.authType)) { - IAM_LOGE("failed to write authType"); - return; - } - if (!data.WriteInt32(credPara.pinType)) { - IAM_LOGE("failed to write pinSubType"); - return; - } - if (!data.WriteUInt8Vector(credPara.token)) { - IAM_LOGE("failed to write token"); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - bool ret = SendRequest(UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL, data, reply); - if (!ret) { - Attributes extraInfo; - callback->OnResult(GENERAL_ERROR, extraInfo); - } -} - -int32_t UserIdmProxy::Cancel(int32_t userId) -{ - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserIdmInterfaceCode::USER_IDM_CANCEL, data, reply); - if (!ret) { - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -int32_t UserIdmProxy::EnforceDelUser(int32_t userId, const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return GENERAL_ERROR; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return WRITE_PARCEL_ERROR; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return WRITE_PARCEL_ERROR; - } - - bool ret = SendRequest(UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER, data, reply); - if (!ret) { - Attributes attr; - callback->OnResult(GENERAL_ERROR, attr); - return GENERAL_ERROR; - } - int32_t result = GENERAL_ERROR; - if (!reply.ReadInt32(result)) { - IAM_LOGE("failed to read result"); - } - return result; -} - -void UserIdmProxy::DelUser(int32_t userId, const std::vector authToken, - const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return; - } - if (!data.WriteUInt8Vector(authToken)) { - IAM_LOGE("failed to write authToken"); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - SendRequest(UserIdmInterfaceCode::USER_IDM_DEL_USER, data, reply); -} - -void UserIdmProxy::DelCredential(int32_t userId, uint64_t credentialId, - const std::vector &authToken, const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - if (!data.WriteInt32(userId)) { - IAM_LOGE("failed to write userId"); - return; - } - if (!data.WriteUint64(credentialId)) { - IAM_LOGE("failed to write credentialId"); - return; - } - if (!data.WriteUInt8Vector(authToken)) { - IAM_LOGE("failed to write authToken"); - return; - } - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - SendRequest(UserIdmInterfaceCode::USER_IDM_DEL_CRED, data, reply); -} - -void UserIdmProxy::ClearRedundancyCredential(const sptr &callback) -{ - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return; - } - MessageParcel data; - MessageParcel reply; - - if (!data.WriteInterfaceToken(UserIdmProxy::GetDescriptor())) { - IAM_LOGE("failed to write descriptor"); - return; - } - - if (!data.WriteRemoteObject(callback->AsObject())) { - IAM_LOGE("failed to write callback"); - return; - } - - SendRequest(UserIdmInterfaceCode::USER_IDM_CLEAR_REDUNDANCY_CRED, data, reply); -} - -bool UserIdmProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("failed to get remote"); - return false; - } - MessageOption option(MessageOption::TF_SYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("failed to send request, result = %{public}d", result); - return false; - } - return true; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/user_idm_stub.cpp b/frameworks/native/ipc/src/user_idm_stub.cpp deleted file mode 100644 index a3059a1f4bdc43a62d85d6085b81c5063912f9cf..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/user_idm_stub.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_stub.h" - -#include - -#include "iam_logger.h" -#include "iam_scope_guard.h" -#include "iam_common_defines.h" -#include "user_idm_callback_proxy.h" - -#define LOG_TAG "USER_AUTH_SA" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { - -// When true is passed into IRemoteStub, sa will process request serially. -UserIdmStub::UserIdmStub() : IRemoteStub(true) {}; - -int32_t UserIdmStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) -{ - IAM_LOGI("cmd = %{public}u, flags= %{public}d", code, option.GetFlags()); - if (data.ReadInterfaceToken() != UserIdmInterface::GetDescriptor()) { - IAM_LOGE("failed to match descriptor"); - return GENERAL_ERROR; - } - - switch (code) { - case UserIdmInterfaceCode::USER_IDM_OPEN_SESSION: - return OpenSessionStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_CLOSE_SESSION: - return CloseSessionStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_GET_CRED_INFO: - return GetCredentialInfoStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_GET_SEC_INFO: - return GetSecInfoStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL: - return AddCredentialStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL: - return UpdateCredentialStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_CANCEL: - return CancelStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER: - return EnforceDelUserStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_DEL_USER: - return DelUserStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_DEL_CRED: - return DelCredentialStub(data, reply); - case UserIdmInterfaceCode::USER_IDM_CLEAR_REDUNDANCY_CRED: - return ClearRedundancyCredentialStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t UserIdmStub::OpenSessionStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - std::vector challenge; - int32_t ret = OpenSession(userId, challenge); - if (ret != SUCCESS) { - return ret; - } - - if (!reply.WriteUInt8Vector(challenge)) { - IAM_LOGE("failed to write challenge"); - return WRITE_PARCEL_ERROR; - } - - return SUCCESS; -} - -int32_t UserIdmStub::CloseSessionStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - CloseSession(userId); - return SUCCESS; -} - -int32_t UserIdmStub::GetCredentialInfoStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - int32_t authType; - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return ERR_INVALID_VALUE; - } - - int32_t ret = GetCredentialInfo(userId, static_cast(authType), callback); - static_cast(reply.WriteInt32(ret)); - return SUCCESS; -} - -int32_t UserIdmStub::GetSecInfoStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - sptr callback = - iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return ERR_INVALID_VALUE; - } - - int32_t ret = GetSecInfo(userId, callback); - static_cast(reply.WriteInt32(ret)); - return SUCCESS; -} - -int32_t UserIdmStub::AddCredentialStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - int32_t authType; - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - - int32_t authSubType; - if (!data.ReadInt32(authSubType)) { - IAM_LOGE("failed to read authSubType"); - return READ_PARCEL_ERROR; - } - - std::vector token; - if (!data.ReadUInt8Vector(&token)) { - IAM_LOGE("failed to read token"); - return READ_PARCEL_ERROR; - } - - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return READ_PARCEL_ERROR; - } - if (authType == PIN && !token.empty()) { - IAM_LOGI("auth type is pin, clear token"); - token.clear(); - } - CredentialPara credPara = {}; - credPara.authType = static_cast(authType); - credPara.pinType = static_cast(authSubType); - credPara.token = token; - AddCredential(userId, credPara, callback, false); - return SUCCESS; -} - -int32_t UserIdmStub::UpdateCredentialStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - int32_t authType; - if (!data.ReadInt32(authType)) { - IAM_LOGE("failed to read authType"); - return READ_PARCEL_ERROR; - } - - int32_t authSubType; - if (!data.ReadInt32(authSubType)) { - IAM_LOGE("failed to read authSubType"); - return READ_PARCEL_ERROR; - } - std::vector token = {}; - if (!data.ReadUInt8Vector(&token)) { - IAM_LOGE("failed to read token"); - return READ_PARCEL_ERROR; - } - - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return GENERAL_ERROR; - } - - CredentialPara credPara = {}; - credPara.authType = static_cast(authType); - credPara.pinType = static_cast(authSubType); - credPara.token = token; - UpdateCredential(userId, credPara, callback); - return SUCCESS; -} - -int32_t UserIdmStub::CancelStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - int32_t ret = Cancel(userId); - static_cast(reply.WriteInt32(ret)); - return SUCCESS; -} - -int32_t UserIdmStub::EnforceDelUserStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return READ_PARCEL_ERROR; - } - - int32_t ret = EnforceDelUser(userId, callback); - static_cast(reply.WriteInt32(ret)); - return SUCCESS; -} - -int32_t UserIdmStub::DelUserStub(MessageParcel &data, [[maybe_unused]] MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - std::vector authToken = {}; - if (!data.ReadUInt8Vector(&authToken)) { - IAM_LOGE("failed to read authToken"); - return READ_PARCEL_ERROR; - } - - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return READ_PARCEL_ERROR; - } - - DelUser(userId, authToken, callback); - return SUCCESS; -} - -int32_t UserIdmStub::DelCredentialStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - int32_t userId; - if (!data.ReadInt32(userId)) { - IAM_LOGE("failed to read userId"); - return READ_PARCEL_ERROR; - } - - uint64_t credentialId; - if (!data.ReadUint64(credentialId)) { - IAM_LOGE("failed to read credentialId"); - return READ_PARCEL_ERROR; - } - - std::vector authToken; - if (!data.ReadUInt8Vector(&authToken)) { - IAM_LOGE("failed to read authToken"); - return READ_PARCEL_ERROR; - } - - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return GENERAL_ERROR; - } - - DelCredential(userId, credentialId, authToken, callback); - return SUCCESS; -} - -int32_t UserIdmStub::ClearRedundancyCredentialStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("enter"); - ON_SCOPE_EXIT(IAM_LOGI("leave")); - - sptr callback = iface_cast(data.ReadRemoteObject()); - if (callback == nullptr) { - IAM_LOGE("callback is nullptr"); - return READ_PARCEL_ERROR; - } - - ClearRedundancyCredential(callback); - - return SUCCESS; -} - -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/ipc/src/widget_callback_stub.cpp b/frameworks/native/ipc/src/widget_callback_stub.cpp deleted file mode 100644 index f7e6168d4dbe8621fa95f4057cfe62fd23b4a89d..0000000000000000000000000000000000000000 --- a/frameworks/native/ipc/src/widget_callback_stub.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "widget_callback_stub.h" - -#include - -#include "iam_logger.h" -#include "user_auth_interface.h" - -#define LOG_TAG "USER_AUTH_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -int32_t WidgetCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IAM_LOGI("code = %{public}u, flags = %{public}d", code, option.GetFlags()); - if (WidgetCallbackStub::GetDescriptor() != data.ReadInterfaceToken()) { - IAM_LOGE("descriptor is not matched"); - return GENERAL_ERROR; - } - - switch (code) { - case UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND: - return OnSendCommandStub(data, reply); - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); - } -} - -int32_t WidgetCallbackStub::OnSendCommandStub(MessageParcel &data, MessageParcel &reply) -{ - IAM_LOGI("start"); - std::string cmdData = data.ReadString(); - SendCommand(cmdData); - return SUCCESS; -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/hisysevent.yaml b/hisysevent.yaml index 2af5fa85140b3940a1cbf1ce25823271d28acbcd..8c70b2c03b7e3c5103221937ef3343a57c0efb13 100644 --- a/hisysevent.yaml +++ b/hisysevent.yaml @@ -95,4 +95,14 @@ USERIAM_REMOTE_CONNECT: OPERATION_RESULT: {type: INT32, desc: operation result} TIME_SPAN: {type: UINT64, desc: time span} NETWORK_ID: {type: STRING, desc: network id} - SOCKET_ID: {type: STRING, desc: socket id} \ No newline at end of file + SOCKET_ID: {type: STRING, desc: socket id} + +SA_LOAD_DRIVER_FAILURE: + __BASE: {type: FAULT, level: CRITICAL, tag: UserAuth, desc: user auth Sa load Driver fail} + ERROR_CODE: {type: INT32, desc: error code} + +IS_CREDENTIAL_ENROLLED_MISMATCH: + __BASE: {type: STATISTIC, level: CRITICAL, tag: UserAuth, desc: credential judgement system param mismatches actual credential} + AUTH_TYPE: {type: INT32, desc: auth type} + PREVIOUS_STATUS: {type: BOOL, desc: system param value before update} + UPDATED_STATUS: {type: BOOL, desc: system param value updated} \ No newline at end of file diff --git a/interfaces/inner_api/iam_common_defines.h b/interfaces/inner_api/iam_common_defines.h index 81c08d4f41d3b2528c7c4f4d5cf3fc967193da5f..1f49f8ce4583d1f47289665a5244483e10cf75c8 100644 --- a/interfaces/inner_api/iam_common_defines.h +++ b/interfaces/inner_api/iam_common_defines.h @@ -45,6 +45,8 @@ constexpr uint32_t MAX_TOKEN_ALLOWABLE_DURATION = 24 * 60 * 60 * 1000; */ constexpr uint32_t MAX_AUTH_TYPE_SIZE = 5; enum AuthType : int32_t { + /** Default authType. */ + INVALID_AUTH_TYPE = -1, /** All authentication types. */ ALL = 0, /** Pin authentication. */ @@ -63,6 +65,8 @@ enum AuthType : int32_t { * @brief Defines pin auth's subtype. */ enum PinSubType : int32_t { + /** Default pin sub type. */ + DEFAULT_PIN_SUB_TYPE = 0, /** Digit password with fixed length of six. */ PIN_SIX = 10000, /** Digit password with unfixed length. */ diff --git a/interfaces/inner_api/user_auth_client.h b/interfaces/inner_api/user_auth_client.h index 1c3ee32577719ce5836a36773a9d7a9ba1b98185..42ca06dfcfbb5dc17d43a927b4dc870d80513287 100644 --- a/interfaces/inner_api/user_auth_client.h +++ b/interfaces/inner_api/user_auth_client.h @@ -115,14 +115,15 @@ public: virtual int32_t CancelIdentification(uint64_t contextId) = 0; /** - * @brief Regist authentication success event listener, support repeated registration. + * @brief Regist authentication success event listener, support repeated registration. Note that you need to listen + * useriam process status, and if the process is restarted abnormally, need to re-register the listener. * - * @param authType Auth type list supported by executor, auth type include PIN, FACE, FINGERPRINT. + * @param authTypes Auth type list supported by executor, auth type include PIN, FACE, FINGERPRINT. * @param listener Callback of authentication success event. * @return Return regist result(0:success; other:failed). */ - virtual int32_t RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) = 0; + virtual int32_t RegistUserAuthSuccessEventListener(const std::vector &authTypes, + const std::shared_ptr &listener) = 0; /** * @brief unRegist authentication success event listener. @@ -131,7 +132,7 @@ public: * @return Return unregist result(0:success; other:failed). */ virtual int32_t UnRegistUserAuthSuccessEventListener( - const sptr &listener) = 0; + const std::shared_ptr &listener) = 0; /** * @brief Set global config param. diff --git a/interfaces/inner_api/user_auth_client_callback.h b/interfaces/inner_api/user_auth_client_callback.h index 36dcb5c32fbe2a7730a43a33b20972e3681e647b..6ff80fa18eea6c25912e4e4bb4c3b5f6e7ee79c5 100644 --- a/interfaces/inner_api/user_auth_client_callback.h +++ b/interfaces/inner_api/user_auth_client_callback.h @@ -25,7 +25,6 @@ #define USER_AUTH_CLIENT_CALLBACK_H #include "attributes.h" -#include "iremote_broker.h" #include "user_auth_client_defines.h" namespace OHOS { @@ -93,19 +92,18 @@ public: virtual void OnResult(int32_t result, const Attributes &extraInfo) = 0; }; -class AuthEventListenerInterface : public IRemoteBroker { +class AuthSuccessEventListener { public: /** * @brief Notify the event of authencation success. * * @param userId The id of user who initiates authentication. - * @param authtype The authentication auth type{@link AuthType}. + * @param authType The authentication auth type{@link AuthType}. * @param callerType The caller type who initiates authentication. * @param callerName The caller name who initiates authentication. */ - virtual void OnNotifyAuthSuccessEvent(int32_t userId, AuthType authtype, int32_t callerType, - std::string &callerName) = 0; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.UserIam.UserAuth.EventListenerCallback"); + virtual void OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, + const std::string &callerName) = 0; }; class PrepareRemoteAuthCallback { diff --git a/interfaces/inner_api/user_auth_event_listener_stub.h b/interfaces/inner_api/user_auth_event_listener_stub.h deleted file mode 100644 index d1a9f26d8dab2fc43e4f1eedd5283f21628122db..0000000000000000000000000000000000000000 --- a/interfaces/inner_api/user_auth_event_listener_stub.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_AUTH_EVENT_LISTENER_STUB_H -#define USER_AUTH_EVENT_LISTENER_STUB_H - -#include "iremote_stub.h" -#include "message_parcel.h" -#include "nocopyable.h" -#include "user_auth_client_callback.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -class AuthEventListenerStub : public IRemoteStub, public NoCopyable { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; - -private: - int32_t OnNotifyAuthSuccessEventStub(MessageParcel &data, MessageParcel &reply); -}; -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS -#endif // USER_AUTH_EVENT_LISTENER_STUB_H \ No newline at end of file diff --git a/interfaces/inner_api/user_idm_client.h b/interfaces/inner_api/user_idm_client.h index 1f94168a1ee376b666df5bb15ecc880931f357f9..b142e01462ace4457e082137524abf71ec3675e4 100644 --- a/interfaces/inner_api/user_idm_client.h +++ b/interfaces/inner_api/user_idm_client.h @@ -158,6 +158,36 @@ public: * @return Return delete userInfo success or not(0:success; other:failed). */ virtual void ClearRedundancyCredential(const std::shared_ptr &callback) = 0; + + /** + * @brief Regist cred change event listener, support repeated registration. Note that you need to listen useriam + * process status, and if the process is restarted abnormally, need to re-register the listener. + * + * @param authTypes Auth type list supported by executor, auth type include PIN, FACE, FINGERPRINT. + * @param listener Callback of cred change success event. + * @return Return regist result(0:success; other:failed). + */ + virtual int32_t RegistCredChangeEventListener(const std::vector &authTypes, + const std::shared_ptr &listener) = 0; + + /** + * @brief unRegist cred change event listener. + * + * @param listener Callback of cred change event. + * @return Return unregist result(0:success; other:failed). + */ + virtual int32_t UnRegistCredChangeEventListener(const std::shared_ptr &listener) = 0; + + /** + * @brief get user's credential information. + * + * @param userId System userId, generated by account subsystem. + * @param authType Authtype supported by executor. + * @param credentialInfoList credentialInfo result. + * @return Return get credentialInfo success or not(0:success; other:failed). + */ + virtual int32_t GetCredentialInfoSync(int32_t userId, AuthType authType, + std::vector &credentialInfoList) = 0; }; } // namespace UserAuth } // namespace UserIam diff --git a/interfaces/inner_api/user_idm_client_callback.h b/interfaces/inner_api/user_idm_client_callback.h index b854b03edab6b8289915959c970406e35cdf4cf3..4a39e166142156c7c7596be7ea0a2b56c7569cec 100644 --- a/interfaces/inner_api/user_idm_client_callback.h +++ b/interfaces/inner_api/user_idm_client_callback.h @@ -72,6 +72,20 @@ public: */ virtual void OnResult(int32_t result, const Attributes &extraInfo) = 0; }; + +class CredChangeEventListener { +public: + /** + * @brief Notify the event of cred change. + * + * @param userId The id of user who change cred. + * @param authType The authentication auth type{@link AuthType}. + * @param eventType eventType of cred change, such as addCred and updateCred. + * @param credentialId The credentialId generated during credChange process. + */ + virtual void OnNotifyCredChangeEvent(int32_t userId, AuthType authType, CredChangeEventType eventType, + uint64_t credentialId) = 0; +}; } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/interfaces/inner_api/user_idm_client_defines.h b/interfaces/inner_api/user_idm_client_defines.h index c9ff0beef7b3abada1c600ac64376bca4ec90593..d55f21a1962c90f77d630ea0d7be8b5ced6608a6 100644 --- a/interfaces/inner_api/user_idm_client_defines.h +++ b/interfaces/inner_api/user_idm_client_defines.h @@ -77,6 +77,24 @@ struct CredentialParameters { /** Auth token. */ std::vector token {}; }; + +/** + * @brief Cred change event type. + */ +enum CredChangeEventType : int32_t { + /** Cred change type is invalid. */ + INVALID_EVENT_TYPE = -1, + /** Cred change type is add credential. */ + ADD_CRED = 1, + /** Cred change type is update credential. */ + UPDATE_CRED = 2, + /** Cred change type is delete credential. */ + DEL_CRED = 3, + /** Cred change type is delete user. */ + DEL_USER = 4, + /** Cred change type is enforce delete user. */ + ENFORCE_DEL_USER = 5, +}; } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/services/base/BUILD.gn b/services/base/BUILD.gn index c71140c50d1025e4ee23bf3b53740889a198aed0..c8bb87834e937a368be8a8cfc86fef56e655832c 100644 --- a/services/base/BUILD.gn +++ b/services/base/BUILD.gn @@ -47,6 +47,7 @@ ohos_source_set("userauth_service_base") { "access_token:libaccesstoken_sdk", "c_utils:utils", "drivers_interface_user_auth:libuser_auth_proxy_3.0", + "hdf_core:libhdf_utils", "hilog:libhilog", "init:libbegetutil", "ipc:ipc_core", diff --git a/services/base/src/finite_state_machine_impl.cpp b/services/base/src/finite_state_machine_impl.cpp index 1cedf42eee3463d0385707f89716381282a5d588..c394a67b7fdc7392c71685e5a7f0c6d7d4da06c7 100644 --- a/services/base/src/finite_state_machine_impl.cpp +++ b/services/base/src/finite_state_machine_impl.cpp @@ -48,7 +48,7 @@ void FiniteStateMachineImpl::Schedule(uint32_t event) return; } pendingEvents_.Push(event); - IAM_LOGI("fsm %{public}s new schedule event input:%{public}u", name_.c_str(), event); + IAM_LOGD("fsm %{public}s new schedule event input:%{public}u", name_.c_str(), event); threadHandler_->PostTask([self = weak_from_this(), this]() { if (auto machine = self.lock(); machine != nullptr) { Inner inner(machine); @@ -64,7 +64,7 @@ void FiniteStateMachineImpl::ScheduleInner(FiniteStateMachine &machine) uint32_t event = 0; bool result = pendingEvents_.Pop(event); if (!result) { - IAM_LOGI("fsm %{public}s pop event fail", name_.c_str()); + IAM_LOGD("fsm %{public}s pop event fail", name_.c_str()); break; } diff --git a/services/context/BUILD.gn b/services/context/BUILD.gn index 7e1676d3ff761048ebcd799f02125abb9e628426..45953159b3e0a0b626c7fb34d8fb7e2e292ff0c9 100644 --- a/services/context/BUILD.gn +++ b/services/context/BUILD.gn @@ -81,6 +81,7 @@ ohos_source_set("userauth_service_context") { "access_token:libaccesstoken_sdk", "c_utils:utils", "drivers_interface_user_auth:libuser_auth_proxy_3.0", + "hdf_core:libhdf_utils", "hilog:libhilog", "hitrace:hitrace_meter", "init:libbegetutil", diff --git a/services/context/inc/context_callback.h b/services/context/inc/context_callback.h index 6884ccaae6be37139d090d72e2e9c6e99a523fd2..c926cb7b6cc7831dd03f2285ee4dde31a56911fb 100644 --- a/services/context/inc/context_callback.h +++ b/services/context/inc/context_callback.h @@ -25,7 +25,7 @@ #include "context.h" #include "iam_defines.h" -#include "iam_callback_interface.h" +#include "iiam_callback.h" #include "user_auth_common_defines.h" namespace OHOS { @@ -69,7 +69,7 @@ private: class ContextCallback { public: - static std::shared_ptr NewInstance(sptr iamCallback, + static std::shared_ptr NewInstance(sptr iamCallback, OperationType operationType); static std::shared_ptr NewDummyInstance(OperationType operationType); virtual ~ContextCallback() = default; @@ -96,7 +96,7 @@ public: virtual void SetTraceAuthFinishReason(const std::string &authFinishReason) = 0; virtual void SetTraceIsBackgroundApplication(bool isBackgroundApplication) = 0; virtual void ProcessAuthResult(int32_t tip, const std::vector &extraInfo) = 0; - virtual sptr GetIamCallback() = 0; + virtual sptr GetIamCallback() = 0; virtual std::string GetCallerName() = 0; }; } // namespace UserAuth diff --git a/services/context/inc/remote_executor_stub.h b/services/context/inc/remote_executor_stub.h index 55820161b58ddf30f90243077152f9f7414ec11f..09194e9ab9d6d1162c6a9838c362d4928b0fb87b 100644 --- a/services/context/inc/remote_executor_stub.h +++ b/services/context/inc/remote_executor_stub.h @@ -20,7 +20,7 @@ #include "attributes.h" #include "co_auth_client_defines.h" -#include "executor_callback_interface.h" +#include "iexecutor_callback.h" #include "hisysevent_adapter.h" #include "nocopyable.h" #include "remote_connect_manager.h" @@ -43,7 +43,7 @@ public: int32_t OnMessage(ExecutorRole dstRole, const std::vector &msg); int32_t ContinueSchedule(ResultCode resultCode, const std::shared_ptr &finalResult); - // ExecutorCallbackInterface + // IExecutorCallback int32_t ProcBeginExecuteRequest(Attributes &attr, RemoteExecuteTrace &trace); private: diff --git a/services/context/inc/remote_iam_callback.h b/services/context/inc/remote_iam_callback.h index ff180560c0f2f5846e372e4a8249c1a125263bd8..7aac0e983672ed7178776b49dbfa98d42ab5d237 100644 --- a/services/context/inc/remote_iam_callback.h +++ b/services/context/inc/remote_iam_callback.h @@ -17,18 +17,18 @@ #define REMOTE_IAM_CALLBACK_H #include "attributes.h" -#include "iam_callback_interface.h" +#include "iiam_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class RemoteIamCallback : public IamCallbackInterface { +class RemoteIamCallback : public IIamCallback { public: RemoteIamCallback(std::string &connectionName); ~RemoteIamCallback() override; - void OnResult(int32_t result, const Attributes &extraInfo) override; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; + int32_t OnResult(int32_t resultCode, const std::vector &extraInfo) override; + int32_t OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) override; sptr AsObject() override; diff --git a/services/context/inc/widget_client.h b/services/context/inc/widget_client.h index 5d62ea20d60bd5575b7e1557fe9328ce9ac558ce..924b7effeb4629d6c2d0714848ac9940c5d1e0f0 100644 --- a/services/context/inc/widget_client.h +++ b/services/context/inc/widget_client.h @@ -22,8 +22,8 @@ #include #include "authentication_impl.h" -#include "modal_callback_interface.h" -#include "widget_callback_interface.h" +#include "imodal_callback.h" +#include "iwidget_callback.h" #include "widget_json.h" #include "widget_schedule_node.h" @@ -39,7 +39,7 @@ public: void SetWidgetContextId(uint64_t contextId); void SetWidgetParam(const WidgetParamInner ¶m); void SetAuthTypeList(const std::vector &authTypeList); - void SetWidgetCallback(const sptr &callback); + void SetWidgetCallback(const sptr &callback); void SetAuthTokenId(uint32_t tokenId); uint32_t GetAuthTokenId() const; @@ -60,7 +60,7 @@ public: void SetChallenge(const std::vector &challenge); void SetCallingBundleName(const std::string &callingBundleName); - void SetModalCallback(const sptr &callback); + void SetModalCallback(const sptr &callback); void LaunchModal(const std::string &commandData); void ReleaseModal(); @@ -76,13 +76,13 @@ private: uint64_t widgetContextId_ {0}; WidgetParamInner widgetParam_ {}; std::vector authTypeList_ {}; - sptr widgetCallback_ {nullptr}; + sptr widgetCallback_ {nullptr}; std::string pinSubType_ {""}; std::string sensorInfo_ {""}; uint32_t authTokenId_ {0}; std::vector challenge_ {}; std::string callingBundleName_ {""}; - sptr modalCallback_ {nullptr}; + sptr modalCallback_ {nullptr}; }; } // namespace UserAuth } // namespace UserIam diff --git a/services/context/inc/widget_context.h b/services/context/inc/widget_context.h index e02be173b8be4a75746853f1c01cbcb22328c5c0..61ac3a5ce015a59c767c9a2ce34cd7c73210a499 100644 --- a/services/context/inc/widget_context.h +++ b/services/context/inc/widget_context.h @@ -32,7 +32,7 @@ #include "context_death_recipient.h" #include "context_factory.h" #include "in_process_call_wrapper.h" -#include "iam_callback_interface.h" +#include "iiam_callback.h" #include "nocopyable.h" #include "widget_json.h" #include "widget_schedule_node.h" @@ -102,7 +102,7 @@ private: bool DisconnectExtension(); void End(const ResultCode &resultCode); std::shared_ptr GetAuthContextCallback(AuthType authType, AuthTrustLevel authTrustLevel, - sptr &callback); + sptr &callback); void StopAllRunTask(const ResultCode &resultCode); std::string BuildStartCommand(const WidgetRotatePara &widgetRotatePara); void BuildStartPinSubType(WidgetCmdParameters &widgetCmdParameters); diff --git a/services/context/src/base_context.cpp b/services/context/src/base_context.cpp index 0963ae7cdfdc66a386cb6edf28d42cea979c0579..5867ea5849c7d13871756cdf04ca6de35e417d44 100644 --- a/services/context/src/base_context.cpp +++ b/services/context/src/base_context.cpp @@ -42,7 +42,7 @@ BaseContext::BaseContext(const std::string &type, uint64_t contextId, std::share BaseContext::~BaseContext() { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); RemoveDeathRecipient(callback_); UnSubscribeAppState(); } @@ -82,7 +82,7 @@ std::string BaseContext::GetCallerName() const bool BaseContext::Start() { std::lock_guard guard(mutex_); - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); if (hasStarted_) { IAM_LOGI("%{public}s context has started, cannot start again", GetDescription()); return false; @@ -93,7 +93,7 @@ bool BaseContext::Start() bool BaseContext::Stop() { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); return OnStop(); } @@ -117,7 +117,7 @@ void BaseContext::OnScheduleStarted() void BaseContext::OnScheduleProcessed(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg) { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); IF_FALSE_LOGE_AND_RETURN(callback_ != nullptr); callback_->OnAcquireInfo(src, moduleType, acquireMsg); } diff --git a/services/context/src/context_appstate_observer.cpp b/services/context/src/context_appstate_observer.cpp index fec093b1aeb5309cc09bd8353484eee729d2fd78..0b2c395d57696c49f9f7871932c5f9605e271b94 100644 --- a/services/context/src/context_appstate_observer.cpp +++ b/services/context/src/context_appstate_observer.cpp @@ -33,7 +33,7 @@ namespace { sptr ContextAppStateObserverManager::GetAppManagerInstance() { - IAM_LOGI("start"); + IAM_LOGD("start"); sptr systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (systemAbilityManager == nullptr) { @@ -53,7 +53,7 @@ sptr ContextAppStateObserverManager::GetAppManagerInstance() void ContextAppStateObserverManager::SubscribeAppState(const std::shared_ptr &callback, const uint64_t contextId) { - IAM_LOGI("start"); + IAM_LOGD("start"); IF_FALSE_LOGE_AND_RETURN(callback != nullptr); const std::string bundleName = callback->GetCallerName(); @@ -90,7 +90,7 @@ void ContextAppStateObserverManager::SubscribeAppState(const std::shared_ptr(contextId_)); auto bundleName = appStateData.bundleName; auto state = static_cast(appStateData.state); int32_t userId = appStateData.uid / CONVERT_UID_TO_USERID; - IAM_LOGI("OnAppStateChanged, userId:%{public}d, bundleName:%{public}s, state:%{public}d", userId, - bundleName.c_str(), state); + IAM_LOGI("OnAppStateChanged, contextId: ****%{public}hx, userId:%{public}d, bundleName:%{public}s, " + "state:%{public}d", static_cast(contextId_), userId, bundleName.c_str(), state); if (bundleName.compare(bundleName_) == 0 && state == ApplicationState::APP_STATE_BACKGROUND) { ProcAppStateChanged(userId); @@ -191,12 +190,11 @@ void ContextAppStateObserver::OnAppStateChanged(const AppStateData &appStateData void ContextAppStateObserver::OnForegroundApplicationChanged(const AppStateData &appStateData) { - IAM_LOGI("start, contextId: ****%{public}hx", static_cast(contextId_)); auto bundleName = appStateData.bundleName; auto state = static_cast(appStateData.state); int32_t userId = appStateData.uid / CONVERT_UID_TO_USERID; - IAM_LOGI("OnForegroundApplicationChanged, userId:%{public}d, bundleName:%{public}s, state:%{public}d", userId, - bundleName.c_str(), state); + IAM_LOGI("OnForegroundApplicationChanged, contextId: ****%{public}hx, userId:%{public}d, bundleName:%{public}s, " + "state:%{public}d", static_cast(contextId_), userId, bundleName.c_str(), state); if (bundleName.compare(bundleName_) == 0 && state == ApplicationState::APP_STATE_BACKGROUND) { ProcAppStateChanged(userId); diff --git a/services/context/src/context_callback_impl.cpp b/services/context/src/context_callback_impl.cpp index e81db8d4d9471484d68ab36fc55c346d3f045261..16410bc6f9441bd3f9052b2b59e53c6a6fda7962 100644 --- a/services/context/src/context_callback_impl.cpp +++ b/services/context/src/context_callback_impl.cpp @@ -16,7 +16,7 @@ #include -#include "auth_event_listener_manager.h" +#include "event_listener_manager.h" #include "iam_check.h" #include "iam_common_defines.h" #include "iam_logger.h" @@ -28,13 +28,13 @@ namespace OHOS { namespace UserIam { namespace UserAuth { -ContextCallbackImpl::ContextCallbackImpl(sptr iamCallback, OperationType operationType) +ContextCallbackImpl::ContextCallbackImpl(sptr iamCallback, OperationType operationType) : iamCallback_(iamCallback) { metaData_.operationType = operationType; metaData_.startTime = std::chrono::steady_clock::now(); std::ostringstream ss; - ss << "IDM(operation:" << operationType << ")"; + ss << "IAM(operation:" << operationType << ")"; iamHitraceHelper_ = Common::MakeShared(ss.str()); } @@ -56,7 +56,7 @@ void ContextCallbackImpl::OnAcquireInfo(ExecutorRole src, int32_t moduleType, ProcessAuthResult(acquireInfo, extraInfo); } - iamCallback_->OnAcquireInfo(moduleType, acquireInfo, attr); + iamCallback_->OnAcquireInfo(moduleType, acquireInfo, acquireMsg); } void ContextCallbackImpl::ProcessAuthResult(int32_t tip, const std::vector &extraInfo) @@ -110,7 +110,7 @@ void ContextCallbackImpl::OnResult(int32_t resultCode, const Attributes &finalRe metaData_.endTime = std::chrono::steady_clock::now(); if (iamCallback_ != nullptr) { - iamCallback_->OnResult(resultCode, finalResult); + iamCallback_->OnResult(resultCode, finalResult.Serialize()); } HandleAuthSuccessResult(resultCode, finalResult); @@ -239,7 +239,7 @@ void ContextCallbackImpl::SetCleaner(Context::ContextStopCallback callback) stopCallback_ = callback; } -sptr ContextCallbackImpl::GetIamCallback() +sptr ContextCallbackImpl::GetIamCallback() { return iamCallback_; } @@ -272,7 +272,7 @@ void ContextCallbackNotifyListener::Process(const MetaData &metaData, TraceFlag } } -std::shared_ptr ContextCallback::NewInstance(sptr iamCallback, +std::shared_ptr ContextCallback::NewInstance(sptr iamCallback, OperationType operationType) { if (iamCallback == nullptr) { @@ -282,20 +282,22 @@ std::shared_ptr ContextCallback::NewInstance(sptr(iamCallback, operationType); } -class IamDummyCallback : public IamCallbackInterface, public NoCopyable { +class IamDummyCallback : public IIamCallback, public NoCopyable { public: explicit IamDummyCallback() = default; ~IamDummyCallback() override = default; - void OnResult(int32_t result, const Attributes &extraInfo) override + int32_t OnResult(int32_t resultCode, const std::vector &extraInfo) override { - static_cast(result); + static_cast(resultCode); static_cast(extraInfo); + return SUCCESS; } - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override + int32_t OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) override { static_cast(module); static_cast(acquireInfo); static_cast(extraInfo); + return SUCCESS; } sptr AsObject() override { @@ -306,7 +308,7 @@ public: std::shared_ptr ContextCallback::NewDummyInstance(OperationType operationType) { - sptr iamDummyCallback(new (std::nothrow) IamDummyCallback()); + sptr iamDummyCallback(new (std::nothrow) IamDummyCallback()); if (iamDummyCallback == nullptr) { IAM_LOGE("iamDummyCallback is nullptr"); return nullptr; diff --git a/services/context/src/context_callback_impl.h b/services/context/src/context_callback_impl.h index f8f70d5607a3ef325dc8ecc94d4bfa5510620f10..b82b522f45f1945f47c78fd25dad26dc082ee102 100644 --- a/services/context/src/context_callback_impl.h +++ b/services/context/src/context_callback_impl.h @@ -26,7 +26,7 @@ namespace UserIam { namespace UserAuth { class ContextCallbackImpl : public ContextCallback, public NoCopyable { public: - explicit ContextCallbackImpl(sptr iamCallback, OperationType operationType); + explicit ContextCallbackImpl(sptr iamCallback, OperationType operationType); ~ContextCallbackImpl() override = default; void OnResult(int32_t resultCode, const Attributes &finalResult) override; void OnAcquireInfo(ExecutorRole src, int32_t moduleType, const std::vector &acquireMsg) override; @@ -51,12 +51,12 @@ public: void SetTraceIsBackgroundApplication(bool isBackgroundApplication) override; void SetCleaner(Context::ContextStopCallback callback) override; void ProcessAuthResult(int32_t tip, const std::vector &extraInfo) override; - sptr GetIamCallback() override; + sptr GetIamCallback() override; std::string GetCallerName() override; private: void HandleAuthSuccessResult(int32_t resultCode, const Attributes &finalResult); - sptr iamCallback_ {nullptr}; + sptr iamCallback_ {nullptr}; Context::ContextStopCallback stopCallback_ {nullptr}; ContextCallbackNotifyListener::MetaData metaData_; std::shared_ptr iamHitraceHelper_; diff --git a/services/context/src/context_death_recipient.cpp b/services/context/src/context_death_recipient.cpp index 26561fb1424a638f79fe10383db168a9dd85dd4a..8ace63319a4331c418d100ac47aa51ec13d55eec 100644 --- a/services/context/src/context_death_recipient.cpp +++ b/services/context/src/context_death_recipient.cpp @@ -27,10 +27,10 @@ namespace UserIam { namespace UserAuth { void ContextDeathRecipientManager::AddDeathRecipient(std::shared_ptr &callback, uint64_t contextId) { - IAM_LOGI("start"); + IAM_LOGD("start"); IF_FALSE_LOGE_AND_RETURN(callback != nullptr); - const sptr iamCallback = callback->GetIamCallback(); + const sptr iamCallback = callback->GetIamCallback(); if (iamCallback == nullptr) { IAM_LOGE("callback_ is nullptr"); return; @@ -48,13 +48,13 @@ void ContextDeathRecipientManager::AddDeathRecipient(std::shared_ptr(contextId)); + IAM_LOGD("AddDeathRecipient success, contextId:****%{public}hx", static_cast(contextId)); return; } void ContextDeathRecipientManager::RemoveDeathRecipient(std::shared_ptr &callback) { - IAM_LOGI("start"); + IAM_LOGD("start"); IF_FALSE_LOGE_AND_RETURN(callback != nullptr); if (deathRecipient_ == nullptr) { @@ -62,7 +62,7 @@ void ContextDeathRecipientManager::RemoveDeathRecipient(std::shared_ptr iamCallback = callback->GetIamCallback(); + const sptr iamCallback = callback->GetIamCallback(); if (iamCallback == nullptr) { IAM_LOGE("callback_ is nullptr"); return; @@ -76,14 +76,14 @@ void ContextDeathRecipientManager::RemoveDeathRecipient(std::shared_ptrRemoveDeathRecipient(deathRecipient_); deathRecipient_ = nullptr; - IAM_LOGI("RemoveDeathRecipient success"); + IAM_LOGD("RemoveDeathRecipient success"); return; } ContextDeathRecipient::ContextDeathRecipient(uint64_t contextId) : contextId_(contextId) { - IAM_LOGI("start"); + IAM_LOGD("start"); } void ContextDeathRecipient::OnRemoteDied(const wptr &remote) diff --git a/services/context/src/context_helper.cpp b/services/context/src/context_helper.cpp index cc7fe9fdcabf71872559abefc98c9847f5d69f08..f55935d29f3ec088b96cfd09aa5bf77962320767 100644 --- a/services/context/src/context_helper.cpp +++ b/services/context/src/context_helper.cpp @@ -30,7 +30,7 @@ ContextHelper::Cleaner::Cleaner(const std::shared_ptr &context) void ContextHelper::Cleaner::operator()() { - IAM_LOGI("start"); + IAM_LOGD("start"); if (contextId_ == 0) { IAM_LOGD("invalid context Id"); } diff --git a/services/context/src/remote_auth_service.cpp b/services/context/src/remote_auth_service.cpp index 55d23657bc0b2881b0d77b5cfec5c842518d904b..e2dd64c43a764b86d1a3a35d999786ab0ad89c3f 100644 --- a/services/context/src/remote_auth_service.cpp +++ b/services/context/src/remote_auth_service.cpp @@ -180,7 +180,7 @@ uint64_t RemoteAuthServiceImpl::StartRemoteAuthContext(Authentication::Authentic std::shared_ptr RemoteAuthServiceImpl::GetRemoteAuthContextCallback(std::string connectionName, Authentication::AuthenticationPara para) { - sptr callback(new RemoteIamCallback(connectionName)); + sptr callback(new RemoteIamCallback(connectionName)); IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL); diff --git a/services/context/src/remote_iam_callback.cpp b/services/context/src/remote_iam_callback.cpp index 15cac885007c208d3169ae606577d8993d5de412..97ce923e4d8067b5438959aac079dfa3dd1abff9 100644 --- a/services/context/src/remote_iam_callback.cpp +++ b/services/context/src/remote_iam_callback.cpp @@ -32,51 +32,54 @@ RemoteIamCallback::~RemoteIamCallback() { } -void RemoteIamCallback::OnResult(int32_t result, const Attributes &extraInfo) +int32_t RemoteIamCallback::OnResult(int32_t resultCode, const std::vector &extraInfo) { - IAM_LOGI("result: %{public}d", result); + IAM_LOGI("result: %{public}d", resultCode); - std::shared_ptr request = Common::MakeShared(extraInfo.Serialize()); - IF_FALSE_LOGE_AND_RETURN(request != nullptr); + std::shared_ptr request = Common::MakeShared(extraInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, GENERAL_ERROR); bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_RESULT); - IF_FALSE_LOGE_AND_RETURN(setMsgTypeRet); + IF_FALSE_LOGE_AND_RETURN_VAL(setMsgTypeRet, GENERAL_ERROR); - bool setResultRet = request->SetInt32Value(Attributes::ATTR_RESULT, result); - IF_FALSE_LOGE_AND_RETURN(setResultRet); + bool setResultRet = request->SetInt32Value(Attributes::ATTR_RESULT, resultCode); + IF_FALSE_LOGE_AND_RETURN_VAL(setResultRet, GENERAL_ERROR); MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, REMOTE_AUTH_INVOKER_CONTEXT_ENDPOINT_NAME, request, msgCallback); - IF_FALSE_LOGE_AND_RETURN(sendMsgRet == ResultCode::SUCCESS); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == ResultCode::SUCCESS, GENERAL_ERROR); IAM_LOGI("success"); + return SUCCESS; } -void RemoteIamCallback::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) +int32_t RemoteIamCallback::OnAcquireInfo(int32_t module, int32_t acquireInfo, + const std::vector &extraInfo) { IAM_LOGI("module: %{public}d, acquireInfo: %{public}d", module, acquireInfo); - std::shared_ptr request = Common::MakeShared(extraInfo.Serialize()); - IF_FALSE_LOGE_AND_RETURN(request != nullptr); + std::shared_ptr request = Common::MakeShared(extraInfo); + IF_FALSE_LOGE_AND_RETURN_VAL(request != nullptr, GENERAL_ERROR); bool setMsgTypeRet = request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_TIP); - IF_FALSE_LOGE_AND_RETURN(setMsgTypeRet); + IF_FALSE_LOGE_AND_RETURN_VAL(setMsgTypeRet, GENERAL_ERROR); bool setModuleRet = request->SetInt32Value(Attributes::ATTR_DEST_ROLE, module); - IF_FALSE_LOGE_AND_RETURN(setModuleRet); + IF_FALSE_LOGE_AND_RETURN_VAL(setModuleRet, GENERAL_ERROR); bool setAcquireInfoRet = request->SetInt32Value(Attributes::ATTR_TIP_INFO, acquireInfo); - IF_FALSE_LOGE_AND_RETURN(setAcquireInfoRet); + IF_FALSE_LOGE_AND_RETURN_VAL(setAcquireInfoRet, GENERAL_ERROR); MsgCallback msgCallback = [](const std::shared_ptr &) { IAM_LOGI("message sent"); }; ResultCode sendMsgRet = RemoteConnectionManager::GetInstance().SendMessage(connectionName_, endPointName_, REMOTE_AUTH_INVOKER_CONTEXT_ENDPOINT_NAME, request, msgCallback); - IF_FALSE_LOGE_AND_RETURN(sendMsgRet == ResultCode::SUCCESS); + IF_FALSE_LOGE_AND_RETURN_VAL(sendMsgRet == ResultCode::SUCCESS, GENERAL_ERROR); IAM_LOGI("success"); + return SUCCESS; } sptr RemoteIamCallback::AsObject() diff --git a/services/context/src/simple_auth_context.cpp b/services/context/src/simple_auth_context.cpp index f48fdff05b5392f844b9d0bb0d1f12061003470b..a5919d8d5d17bac92bf2933aa11b99535aae0810 100644 --- a/services/context/src/simple_auth_context.cpp +++ b/services/context/src/simple_auth_context.cpp @@ -31,6 +31,7 @@ namespace OHOS { namespace UserIam { namespace UserAuth { + constexpr int32_t RESULT_NOT_FOUND = VENDOR_ERROR_CODE_BEGIN + 0x6; std::optional> SimpleAuthContext::GetPropertyTemplateIds( Authentication::AuthResultInfo &resultInfo) { @@ -71,7 +72,7 @@ std::optional> SimpleAuthContext::GetPropertyTemplateIds( ResultCode SimpleAuthContext::GetPropertyForAuthResult(Authentication::AuthResultInfo &resultInfo) { - IAM_LOGI("start"); + IAM_LOGD("start"); IF_FALSE_LOGE_AND_RETURN_VAL(scheduleList_.size() == 1, GENERAL_ERROR); auto scheduleNode = scheduleList_[0]; IF_FALSE_LOGE_AND_RETURN_VAL(scheduleNode != nullptr, GENERAL_ERROR); @@ -163,7 +164,7 @@ std::string SimpleAuthContext::GetCallerName() const bool SimpleAuthContext::OnStart() { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); IF_FALSE_LOGE_AND_RETURN_VAL(auth_ != nullptr, false); bool startRet = auth_->Start(scheduleList_, shared_from_this()); if (!startRet) { @@ -214,7 +215,11 @@ bool SimpleAuthContext::OnStop() bool cancelRet = auth_->Cancel(); if (!cancelRet) { IAM_LOGE("%{public}s auth stop fail", GetDescription()); - SetLatestError(auth_->GetLatestError()); + int32_t resultCode = auth_->GetLatestError(); + if (resultCode == RESULT_NOT_FOUND) { + resultCode = INVALID_CONTEXT_ID; + } + SetLatestError(resultCode); return cancelRet; } return true; @@ -266,7 +271,7 @@ bool SimpleAuthContext::SetCredentialDigest(const Authentication::AuthResultInfo void SimpleAuthContext::InvokeResultCallback(const Authentication::AuthResultInfo &resultInfo) const { - IAM_LOGI("%{public}s start", GetDescription()); + IAM_LOGD("%{public}s start", GetDescription()); IF_FALSE_LOGE_AND_RETURN(callback_ != nullptr); Attributes finalResult; bool setResultCodeRet = finalResult.SetInt32Value(Attributes::ATTR_RESULT_CODE, resultInfo.result); @@ -287,10 +292,10 @@ void SimpleAuthContext::InvokeResultCallback(const Authentication::AuthResultInf if (resultInfo.result == SUCCESS) { bool setUserIdRet = finalResult.SetInt32Value(Attributes::ATTR_USER_ID, resultInfo.userId); IF_FALSE_LOGE_AND_RETURN(setUserIdRet == true); - IAM_LOGI("matched userId: %{public}d.", resultInfo.userId); bool setCredentialIdRet = finalResult.SetUint64Value(Attributes::ATTR_CREDENTIAL_ID, resultInfo.credentialId); IF_FALSE_LOGE_AND_RETURN(setCredentialIdRet == true); - IAM_LOGI("matched credentialId: %{public}s.", GET_MASKED_STRING(resultInfo.credentialId).c_str()); + IAM_LOGI("matched userId: %{public}d, credentialId: %{public}s.", resultInfo.userId, + GET_MASKED_STRING(resultInfo.credentialId).c_str()); bool setExpiredRet = finalResult.SetInt64Value(Attributes::ATTR_PIN_EXPIRED_INFO, resultInfo.pinExpiredInfo); IF_FALSE_LOGE_AND_RETURN(setExpiredRet == true); } diff --git a/services/context/src/trace.cpp b/services/context/src/trace.cpp index 1979285411f826d11abd9b8e11f9ed467b01f997..e0a6cc6226d7659c6a9e44b68e565e171dba6f5c 100644 --- a/services/context/src/trace.cpp +++ b/services/context/src/trace.cpp @@ -162,7 +162,7 @@ void Trace::ProcessUserAuthEvent(const ContextCallbackNotifyListener::MetaData & UserAuthTrace info = {}; CopyMetaDataToTraceInfo(metaData, info); ReportUserAuth(info); - IAM_LOGI("start to process user auth event"); + IAM_LOGD("start to process user auth event"); } void Trace::ProcessUserAuthFwkEvent(const ContextCallbackNotifyListener::MetaData &metaData, TraceFlag flag) @@ -208,7 +208,7 @@ void Trace::ProcessUserAuthFwkEvent(const ContextCallbackNotifyListener::MetaDat metaData.startTime).count()); securityInfo.authtimeSpan = timeSpan; ReportSecurityUserAuthFwk(securityInfo); - IAM_LOGI("start to process user auth fwk event"); + IAM_LOGD("start to process user auth fwk event"); } } // namespace UserAuth } // namespace UserIam diff --git a/services/context/src/ui_extension_ability_connection.cpp b/services/context/src/ui_extension_ability_connection.cpp index 07327462ef8a0f3f8f5d8b02eedc815d3434b5c9..5fe822f2ed7ad92f964fabcb0878f30767e75457 100644 --- a/services/context/src/ui_extension_ability_connection.cpp +++ b/services/context/src/ui_extension_ability_connection.cpp @@ -28,7 +28,7 @@ namespace UserAuth { void UIExtensionAbilityConnection::OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr &remoteObject, int32_t resultCode) { - IAM_LOGI("on ability connected"); + IAM_LOGD("on ability connected"); std::lock_guard lock(mutex_); if (!isConnectionRelease_) { IAM_LOGE("connection already release"); diff --git a/services/context/src/widget_client.cpp b/services/context/src/widget_client.cpp index 8e6a5ec4604fe01fcfb2786714b6ed17d4d4b214..902bad774c34e7b61a12aad3b7a37eb21fe43f3b 100644 --- a/services/context/src/widget_client.cpp +++ b/services/context/src/widget_client.cpp @@ -23,7 +23,7 @@ #include "iam_para2str.h" #include "iam_time.h" #include "nlohmann/json.hpp" -#include "widget_callback_interface.h" +#include "iwidget_callback.h" #include "hisysevent_adapter.h" #define LOG_TAG "USER_AUTH_SA" @@ -127,7 +127,7 @@ void WidgetClient::SendCommand(const WidgetCommand &command) } nlohmann::json root = command; std::string cmdData = root.dump(); - IAM_LOGI("SendCommand cmdData"); + IAM_LOGD("SendCommand cmdData"); widgetCallback_->SendCommand(cmdData); } @@ -199,7 +199,7 @@ void WidgetClient::SetAuthTypeList(const std::vector &authTypeList) authTypeList_ = authTypeList; } -void WidgetClient::SetWidgetCallback(const sptr &callback) +void WidgetClient::SetWidgetCallback(const sptr &callback) { widgetCallback_ = callback; } @@ -217,7 +217,7 @@ uint32_t WidgetClient::GetAuthTokenId() const void WidgetClient::Reset() { - IAM_LOGI("WidgetClient Reset"); + IAM_LOGD("WidgetClient Reset"); widgetParam_.title.clear(); widgetParam_.navigationButtonText.clear(); widgetParam_.windowMode = WindowModeType::DIALOG_BOX; @@ -335,7 +335,7 @@ void WidgetClient::SetCallingBundleName(const std::string &callingBundleName) callingBundleName_ = callingBundleName; } -void WidgetClient::SetModalCallback(const sptr &callback) +void WidgetClient::SetModalCallback(const sptr &callback) { IAM_LOGI("set modal callback"); modalCallback_ = callback; diff --git a/services/context/src/widget_context.cpp b/services/context/src/widget_context.cpp index 98849deb8f14ca191bdef3b959ae0d494329d49d..4f0cb9d350356578d1fcf75596f7233c9e38a7c3 100644 --- a/services/context/src/widget_context.cpp +++ b/services/context/src/widget_context.cpp @@ -74,14 +74,14 @@ WidgetContext::WidgetContext(uint64_t contextId, const ContextFactory::AuthWidge WidgetContext::~WidgetContext() { - IAM_LOGI("release WidgetContext"); + IAM_LOGD("release WidgetContext"); RemoveDeathRecipient(callerCallback_); UnSubscribeAppState(); } bool WidgetContext::Start() { - IAM_LOGI("%{public}s start", description_.c_str()); + IAM_LOGD("%{public}s start", description_.c_str()); std::lock_guard lock(mutex_); if (hasStarted_) { IAM_LOGI("%{public}s context has started, cannot start again", description_.c_str()); @@ -153,13 +153,13 @@ bool WidgetContext::BuildSchedule() } std::shared_ptr WidgetContext::GetAuthContextCallback(AuthType authType, - AuthTrustLevel authTrustLevel, sptr &iamCallback) + AuthTrustLevel authTrustLevel, sptr &iamCallback) { auto widgetCallback = ContextCallback::NewInstance(iamCallback, TRACE_AUTH_USER_SECURITY); if (widgetCallback == nullptr) { IAM_LOGE("failed to construct context callback"); Attributes extraInfo; - iamCallback->OnResult(ResultCode::GENERAL_ERROR, extraInfo); + iamCallback->OnResult(ResultCode::GENERAL_ERROR, extraInfo.Serialize()); return nullptr; } widgetCallback->SetTraceCallerName(para_.callerName); @@ -177,7 +177,7 @@ std::shared_ptr WidgetContext::BuildTask(const std::vector &ch auto userId = para_.userId; auto tokenId = WidgetClient::Instance().GetAuthTokenId(); IAM_LOGI("Real userId: %{public}d, Real tokenId: %{public}s", userId, GET_MASKED_STRING(tokenId).c_str()); - sptr iamCallback(new (std::nothrow) WidgetContextCallbackImpl(weak_from_this(), + sptr iamCallback(new (std::nothrow) WidgetContextCallbackImpl(weak_from_this(), static_cast(authType))); IF_FALSE_LOGE_AND_RETURN_VAL(iamCallback != nullptr, nullptr); auto widgetCallback = GetAuthContextCallback(authType, authTrustLevel, iamCallback); @@ -259,13 +259,13 @@ void WidgetContext::AuthResult(int32_t resultCode, int32_t authType, const Attri IF_FALSE_LOGE_AND_RETURN(schedule_ != nullptr); IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); callerCallback_->SetTraceAuthType(authTypeTmp); - IAM_LOGI("call schedule:"); + IAM_LOGD("call schedule:"); if (resultCode == ResultCode::SUCCESS || resultCode == ResultCode::COMPLEXITY_CHECK_FAILED) { finalResult.GetUint8ArrayValue(Attributes::ATTR_SIGNATURE, authResultInfo_.token); finalResult.GetUint64Value(Attributes::ATTR_CREDENTIAL_DIGEST, authResultInfo_.credentialDigest); finalResult.GetUint16Value(Attributes::ATTR_CREDENTIAL_COUNT, authResultInfo_.credentialCount); authResultInfo_.authType = authTypeTmp; - IAM_LOGI("widget token size: %{public}zu.", authResultInfo_.token.size()); + IAM_LOGD("widget token size: %{public}zu.", authResultInfo_.token.size()); if (resultCode != ResultCode::SUCCESS) { SetLatestError(resultCode); } @@ -279,7 +279,7 @@ void WidgetContext::AuthResult(int32_t resultCode, int32_t authType, const Attri void WidgetContext::AuthTipInfo(int32_t tipType, int32_t authType, const Attributes &extraInfo) { - IAM_LOGI("recv tip: %{public}d, authType: %{public}d", tipType, authType); + IAM_LOGD("recv tip: %{public}d, authType: %{public}d", tipType, authType); std::lock_guard lock(mutex_); std::vector tipInfo; bool getTipInfoRet = extraInfo.GetUint8ArrayValue(Attributes::ATTR_EXTRA_INFO, tipInfo); @@ -441,7 +441,7 @@ void WidgetContext::SuccessAuth(AuthType authType) int32_t WidgetContext::ConnectExtensionAbility(const AAFwk::Want &want, const std::string commandStr) { - IAM_LOGI("ConnectExtensionAbility start"); + IAM_LOGD("ConnectExtensionAbility start"); if (connection_ != nullptr) { IAM_LOGE("invalid connection_"); return ERR_INVALID_OPERATION; @@ -548,7 +548,7 @@ bool WidgetContext::DisconnectExtension() void WidgetContext::End(const ResultCode &resultCode) { - IAM_LOGI("in End, resultCode: %{public}d", static_cast(resultCode)); + IAM_LOGD("in End, resultCode: %{public}d", static_cast(resultCode)); StopAllRunTask(resultCode); IF_FALSE_LOGE_AND_RETURN(callerCallback_ != nullptr); Attributes attr; @@ -589,7 +589,7 @@ void WidgetContext::StopAllRunTask(const ResultCode &resultCode) { std::lock_guard lock(mutex_); for (auto &taskInfo : runTaskInfoList_) { - IAM_LOGI("stop task"); + IAM_LOGD("stop task"); if (taskInfo.task == nullptr) { IAM_LOGE("task is null"); continue; @@ -598,7 +598,7 @@ void WidgetContext::StopAllRunTask(const ResultCode &resultCode) } runTaskInfoList_.clear(); if (resultCode != ResultCode::SUCCESS) { - IAM_LOGI("Try to disconnect extesnion"); + IAM_LOGI("Try to disconnect extension"); if (!DisconnectExtension()) { IAM_LOGE("failed to release launch widget."); } diff --git a/services/context/src/widget_context_callback_impl.cpp b/services/context/src/widget_context_callback_impl.cpp index 1f0d5ad374174c9cd9412f29295f85633ace5292..8af59fbe1feb32b7ce519d9e263f1d8c0d9122b8 100644 --- a/services/context/src/widget_context_callback_impl.cpp +++ b/services/context/src/widget_context_callback_impl.cpp @@ -32,22 +32,30 @@ WidgetContextCallbackImpl::WidgetContextCallbackImpl(std::weak_ptr &extraInfo) { std::lock_guard lock(mutex_); auto widgetContext = widgetContext_.lock(); if (widgetContext != nullptr) { - widgetContext->AuthResult(result, authType_, extraInfo); + Attributes attributes(extraInfo); + widgetContext->AuthResult(resultCode, authType_, attributes); + return SUCCESS; } + + return GENERAL_ERROR; } -void WidgetContextCallbackImpl::OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) +int32_t WidgetContextCallbackImpl::OnAcquireInfo(int32_t module, int32_t acquireInfo, + const std::vector &extraInfo) { std::lock_guard lock(mutex_); auto widgetContext = widgetContext_.lock(); if (widgetContext != nullptr) { - widgetContext->AuthTipInfo(acquireInfo, authType_, extraInfo); + Attributes attributes(extraInfo); + widgetContext->AuthTipInfo(acquireInfo, authType_, attributes); + return SUCCESS; } + return GENERAL_ERROR; } sptr WidgetContextCallbackImpl::AsObject() diff --git a/services/context/src/widget_context_callback_impl.h b/services/context/src/widget_context_callback_impl.h index 1aa24bb953e54f7e357965d6b5044ff5c4b85eb9..739fe4109b32128232ae5c4cc018cc50c25ecb9c 100644 --- a/services/context/src/widget_context_callback_impl.h +++ b/services/context/src/widget_context_callback_impl.h @@ -21,18 +21,18 @@ #include "iam_hitrace_helper.h" #include "iam_defines.h" -#include "iam_callback_interface.h" +#include "iiam_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { class WidgetContext; -class WidgetContextCallbackImpl : public IamCallbackInterface, public NoCopyable { +class WidgetContextCallbackImpl : public IIamCallback, public NoCopyable { public: WidgetContextCallbackImpl(std::weak_ptr widgetContext, int32_t authType); ~WidgetContextCallbackImpl() override = default; - void OnResult(int32_t result, const Attributes &extraInfo) override; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override; + int32_t OnResult(int32_t resultCode, const std::vector &extraInfo) override; + int32_t OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) override; sptr AsObject() override; private: diff --git a/services/core/BUILD.gn b/services/core/BUILD.gn index d9f198545363a686ed1193e308770d3c2abfd3d2..185cb305c3370bc76669d60f838fce1f8c8fd951 100644 --- a/services/core/BUILD.gn +++ b/services/core/BUILD.gn @@ -56,12 +56,12 @@ ohos_source_set("userauth_service_core") { remove_configs = [ "//build/config/compiler:no_exceptions" ] sources = [ - "src/auth_event_listener_manager.cpp", "src/authentication_impl.cpp", "src/credential_info_impl.cpp", "src/driver_state_manager.cpp", "src/enrolled_info_impl.cpp", "src/enrollment_impl.cpp", + "src/event_listener_manager.cpp", "src/identification_impl.cpp", "src/ipc_common.cpp", "src/remote_executor_proxy.cpp", @@ -96,6 +96,7 @@ ohos_source_set("userauth_service_core") { "c_utils:utils", "device_manager:devicemanagersdk", "drivers_interface_user_auth:libuser_auth_proxy_3.0", + "hdf_core:libhdf_utils", "hdf_core:libhdi", "hilog:libhilog", "hitrace:hitrace_meter", diff --git a/services/core/inc/auth_event_listener_manager.h b/services/core/inc/event_listener_manager.h similarity index 42% rename from services/core/inc/auth_event_listener_manager.h rename to services/core/inc/event_listener_manager.h index 85632492d140ae2cef5053fb420705317fe21df2..3497e586de2f3138d23a626bc477d46baff361a7 100644 --- a/services/core/inc/auth_event_listener_manager.h +++ b/services/core/inc/event_listener_manager.h @@ -13,10 +13,13 @@ * limitations under the License. */ -#ifndef IAM_AUTH_EVENT_LISTENER_MANAGER_H -#define IAM_AUTH_EVENT_LISTENER_MANAGER_H +#ifndef IAM_EVENT_LISTENER_MANAGER_H +#define IAM_EVENT_LISTENER_MANAGER_H -#include "user_auth_interface.h" +#include "iuser_auth.h" +#include "iuser_idm.h" +#include "user_idm_client_defines.h" +#include "event_listener_callback_stub.h" #include #include #include @@ -25,58 +28,57 @@ namespace OHOS { namespace UserIam { namespace UserAuth { using DeathRecipient = IRemoteObject::DeathRecipient; -class AuthEventListenerManager { +class EventListenerManager { public: - static AuthEventListenerManager &GetInstance(); - int32_t RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener); - int32_t UnRegistUserAuthSuccessEventListener(const sptr &listener); - void OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, std::string &callerName); - int32_t AddDeathRecipient(const sptr &listener); - int32_t RemoveDeathRecipient(const sptr &listener); - std::map, sptr> GetDeathRecipientMap(); + EventListenerManager() = default; + ~EventListenerManager() = default; + int32_t RegistEventListener(const sptr &listener); + int32_t UnRegistEventListener(const sptr &listener); + int32_t AddDeathRecipient(EventListenerManager *manager, const sptr &listener); + int32_t RemoveDeathRecipient(const sptr &listener); + std::map, sptr> GetListenerDeathRecipientMap(); protected: - class AuthEventListenerDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable { + class EventListenerDeathRecipient : public IRemoteObject::DeathRecipient, public NoCopyable { public: - AuthEventListenerDeathRecipient() = default; - ~AuthEventListenerDeathRecipient() override = default; + EventListenerDeathRecipient(EventListenerManager *manager); + ~EventListenerDeathRecipient() override = default; void OnRemoteDied(const wptr &remote) override; + + private: + EventListenerManager *eventListenerManager_; }; - AuthEventListenerManager() = default; - ~AuthEventListenerManager() = default; - void AddAuthSuccessEventListener(AuthType authType, const sptr &listener); - void RemoveAuthSuccessEventListener(AuthType authType, const sptr &listener); - std::set> GetListenerSet(AuthType authType); std::recursive_mutex mutex_; - std::map>> eventListenerMap_; - std::map, sptr> deathRecipientMap_; + std::map, sptr> listenerDeathRecipientMap_; private: - struct FinderSet { - explicit FinderSet(sptr remoteObject) : remoteObject_(remoteObject) - { - } - bool operator()(sptr listener) - { - return listener->AsObject() == remoteObject_; - } - sptr remoteObject_ {nullptr}; - }; - struct FinderMap { explicit FinderMap(sptr remoteObject) : remoteObject_(remoteObject) { } - bool operator()(std::map, sptr>::value_type &pair) + bool operator()(std::map, sptr>::value_type &pair) { return pair.first->AsObject() == remoteObject_; } sptr remoteObject_ {nullptr}; }; }; + +class AuthEventListenerManager : public EventListenerManager { +public: + static AuthEventListenerManager &GetInstance(); + void OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, + const std::string &callerName); +}; + +class CredChangeEventListenerManager : public EventListenerManager { +public: + static CredChangeEventListenerManager &GetInstance(); + void OnNotifyCredChangeEvent(int32_t userId, AuthType authType, CredChangeEventType eventType, + uint64_t credentialId); +}; } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_AUTH_EVENT_LISTENER_MANAGER_H \ No newline at end of file +#endif // IAM_EVENT_LISTENER_MANAGER_H \ No newline at end of file diff --git a/services/core/inc/remote_executor_proxy.h b/services/core/inc/remote_executor_proxy.h index b2841a124a1c4ac60a05cdc5438b7fe03497e674..978f4128181158cb1a824bfae9419f15c306e14c 100644 --- a/services/core/inc/remote_executor_proxy.h +++ b/services/core/inc/remote_executor_proxy.h @@ -21,7 +21,7 @@ #include "attributes.h" #include "co_auth_client_callback.h" #include "co_auth_client_defines.h" -#include "executor_callback_interface.h" +#include "iexecutor_callback.h" #include "remote_connect_manager.h" #include "remote_msg_util.h" @@ -40,7 +40,7 @@ public: const std::shared_ptr &request, std::shared_ptr &reply); void OnConnectStatus(const std::string &connectionName, ConnectStatus connectStatus); - // ExecutorCallbackInterface + // IExecutorCallback void OnMessengerReady(const std::shared_ptr &messenger, const std::vector &publicKey, const std::vector &templateIdList); int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command); @@ -50,7 +50,7 @@ public: void OnErrorFinish(uint64_t scheduleId); private: - // ExecutorMessengerInterface + // ExecutorMessenger int32_t ProcSendDataMsg(Attributes &data); int32_t ProcFinishMsg(Attributes &data); diff --git a/services/core/inc/resource_node.h b/services/core/inc/resource_node.h index 6c02f182c0355b831ae9f090e3d019f836420f07..cfed733f35f3c2c8144b05278106fa58b3f921a2 100644 --- a/services/core/inc/resource_node.h +++ b/services/core/inc/resource_node.h @@ -20,8 +20,9 @@ #include #include +#include "attributes.h" #include "co_auth_interface.h" -#include "executor_callback_interface.h" +#include "iexecutor_callback.h" #include "iam_common_defines.h" namespace OHOS { @@ -51,7 +52,7 @@ public: virtual void DetachFromDriver() = 0; static std::shared_ptr MakeNewResource(const ExecutorRegisterInfo &info, - const std::shared_ptr &callback, std::vector &templateIdList, + const std::shared_ptr &callback, std::vector &templateIdList, std::vector &fwkPublicKey); }; } // namespace UserAuth diff --git a/services/core/src/enrollment_impl.cpp b/services/core/src/enrollment_impl.cpp index a38b36e0c83932949fa358a62a619a060fb74ff8..923a4cf498bdf3d791bb6ff13f2f78d6d0642ebf 100644 --- a/services/core/src/enrollment_impl.cpp +++ b/services/core/src/enrollment_impl.cpp @@ -15,6 +15,7 @@ #include "enrollment_impl.h" #include "credential_info_impl.h" +#include "event_listener_manager.h" #include "hdi_wrapper.h" #include "iam_hitrace_helper.h" #include "iam_logger.h" @@ -216,14 +217,18 @@ bool EnrollmentImpl::Update(const std::vector &scheduleResult, uint64_t void EnrollmentImpl::PublishPinEvent(uint64_t credentialId) { - if (enrollPara_.authType != PIN) { - return; - } - IAM_LOGI("begin to publish pin event"); - if (isUpdate_) { + if (!isUpdate_ && enrollPara_.authType != PIN) { + CredChangeEventListenerManager::GetInstance().OnNotifyCredChangeEvent(enrollPara_.userId, + enrollPara_.authType, ADD_CRED, credentialId); + } else if (!isUpdate_ && enrollPara_.authType == PIN) { + PublishEventAdapter::GetInstance().PublishCreatedEvent(enrollPara_.userId, scheduleId_); + CredChangeEventListenerManager::GetInstance().OnNotifyCredChangeEvent(enrollPara_.userId, + enrollPara_.authType, ADD_CRED, credentialId); + } else if (isUpdate_ && enrollPara_.authType == PIN) { PublishEventAdapter::GetInstance().CachePinUpdateParam(enrollPara_.userId, scheduleId_, credentialId); } else { - PublishEventAdapter::GetInstance().PublishCreatedEvent(enrollPara_.userId, scheduleId_); + CredChangeEventListenerManager::GetInstance().OnNotifyCredChangeEvent(enrollPara_.userId, + enrollPara_.authType, UPDATE_CRED, credentialId); } } diff --git a/services/core/src/auth_event_listener_manager.cpp b/services/core/src/event_listener_manager.cpp similarity index 43% rename from services/core/src/auth_event_listener_manager.cpp rename to services/core/src/event_listener_manager.cpp index 752f2bb908d252bd45c85222ce757e39352e5986..109aaac312e59efaaa209bda01055010697f0967 100644 --- a/services/core/src/auth_event_listener_manager.cpp +++ b/services/core/src/event_listener_manager.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "auth_event_listener_manager.h" +#include "event_listener_manager.h" #include @@ -27,34 +27,20 @@ namespace OHOS { namespace UserIam { namespace UserAuth { using DeathRecipient = IRemoteObject::DeathRecipient; -AuthEventListenerManager &AuthEventListenerManager::GetInstance() -{ - IAM_LOGI("start"); - static AuthEventListenerManager authEventListenerManager; - return authEventListenerManager; -} - -int32_t AuthEventListenerManager::RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) +int32_t EventListenerManager::RegistEventListener(const sptr &listener) { IAM_LOGI("start"); IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, GENERAL_ERROR); std::lock_guard lock(mutex_); - int32_t result = AddDeathRecipient(listener); + int32_t result = AddDeathRecipient(this, listener); if (result != SUCCESS) { IAM_LOGE("AddDeathRecipient fail"); - return result; - } - - for (const auto &iter : authType) { - AddAuthSuccessEventListener(iter, listener); } - IAM_LOGI("RegistUserAuthSuccessEventListener success"); - return SUCCESS; + return result; } -int32_t AuthEventListenerManager::UnRegistUserAuthSuccessEventListener(const sptr &listener) +int32_t EventListenerManager::UnRegistEventListener(const sptr &listener) { IAM_LOGI("start"); IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, GENERAL_ERROR); @@ -63,67 +49,12 @@ int32_t AuthEventListenerManager::UnRegistUserAuthSuccessEventListener(const spt int32_t result = RemoveDeathRecipient(listener); if (result != SUCCESS) { IAM_LOGE("RemoveDeathRecipient fail"); - return result; } - - RemoveAuthSuccessEventListener(AuthType::PIN, listener); - RemoveAuthSuccessEventListener(AuthType::FACE, listener); - RemoveAuthSuccessEventListener(AuthType::FINGERPRINT, listener); - IAM_LOGI("UnRegistUserAuthSuccessEventListener success"); - return SUCCESS; + return result; } -void AuthEventListenerManager::AddAuthSuccessEventListener(AuthType authType, - const sptr &listener) -{ - IAM_LOGI("AddAuthSuccessEventListener, authType:%{public}d", static_cast(authType)); - auto iter = std::find_if(eventListenerMap_[authType].begin(), eventListenerMap_[authType].end(), - FinderSet(listener->AsObject())); - if (iter != eventListenerMap_[authType].end()) { - IAM_LOGE("listener is already registed"); - return; - } - eventListenerMap_[authType].insert(listener); - IAM_LOGI("AddAuthSuccessEventListener success"); -} - -void AuthEventListenerManager::RemoveAuthSuccessEventListener(AuthType authType, - const sptr &listener) -{ - IAM_LOGI("RemoveAuthSuccessEventListener, authType:%{public}d", static_cast(authType)); - auto iter = std::find_if(eventListenerMap_[authType].begin(), eventListenerMap_[authType].end(), - FinderSet(listener->AsObject())); - if (iter == eventListenerMap_[authType].end()) { - IAM_LOGE("listener is not registed"); - return; - } - eventListenerMap_[authType].erase(listener); - IAM_LOGI("RemoveAuthSuccessEventListener success"); -} - -std::set> AuthEventListenerManager::GetListenerSet(AuthType authType) -{ - std::lock_guard lock(mutex_); - std::set> listenerSet(eventListenerMap_[authType]); - return listenerSet; -} - -void AuthEventListenerManager::OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, - std::string &callerName) -{ - IAM_LOGI("start"); - std::set> listenerSetTemp = GetListenerSet(authType); - for (auto &iter : listenerSetTemp) { - if (iter != nullptr) { - iter->OnNotifyAuthSuccessEvent(userId, authType, callerType, callerName); - IAM_LOGI("OnNotifyAuthSuccessEvent, userId: %{public}d, authType: %{public}d, callerName: %{public}s, " - "callerType: %{public}d", - userId, static_cast(authType), callerName.c_str(), callerType); - } - } -} - -int32_t AuthEventListenerManager::AddDeathRecipient(const sptr &listener) +int32_t EventListenerManager::AddDeathRecipient(EventListenerManager *manager, + const sptr &listener) { IAM_LOGI("start"); IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, GENERAL_ERROR); @@ -134,24 +65,25 @@ int32_t AuthEventListenerManager::AddDeathRecipient(const sptrAsObject())); - if (iter != deathRecipientMap_.end()) { + auto iter = std::find_if(listenerDeathRecipientMap_.begin(), listenerDeathRecipientMap_.end(), + FinderMap(listener->AsObject())); + if (iter != listenerDeathRecipientMap_.end()) { IAM_LOGE("deathRecipient is already registed"); return SUCCESS; } - sptr dr(new (std::nothrow) AuthEventListenerDeathRecipient()); + sptr dr(new (std::nothrow) EventListenerDeathRecipient(manager)); if ((dr == nullptr) || (!obj->AddDeathRecipient(dr))) { IAM_LOGE("AddDeathRecipient failed"); return GENERAL_ERROR; } - deathRecipientMap_.emplace(listener, dr); - IAM_LOGI("AddDeathRecipient success"); + listenerDeathRecipientMap_.emplace(listener, dr); + IAM_LOGI("AddDeathRecipient success, listenerSize:%{public}zu", listenerDeathRecipientMap_.size()); return SUCCESS; } -int32_t AuthEventListenerManager::RemoveDeathRecipient(const sptr &listener) +int32_t EventListenerManager::RemoveDeathRecipient(const sptr &listener) { IAM_LOGI("start"); IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, GENERAL_ERROR); @@ -162,8 +94,9 @@ int32_t AuthEventListenerManager::RemoveDeathRecipient(const sptrAsObject())); - if (iter == deathRecipientMap_.end()) { + auto iter = std::find_if(listenerDeathRecipientMap_.begin(), listenerDeathRecipientMap_.end(), + FinderMap(listener->AsObject())); + if (iter == listenerDeathRecipientMap_.end()) { IAM_LOGE("deathRecipient is not registed"); return SUCCESS; } @@ -175,38 +108,78 @@ int32_t AuthEventListenerManager::RemoveDeathRecipient(const sptrRemoveDeathRecipient(deathRecipient); - deathRecipientMap_.erase(listener); - IAM_LOGI("RemoveDeathRecipient success"); + listenerDeathRecipientMap_.erase(iter); + IAM_LOGI("RemoveDeathRecipient success, listenerSize:%{public}zu", listenerDeathRecipientMap_.size()); return SUCCESS; } -std::map, sptr> AuthEventListenerManager::GetDeathRecipientMap() +std::map, sptr> EventListenerManager::GetListenerDeathRecipientMap() { IAM_LOGI("start"); std::lock_guard lock(mutex_); - return deathRecipientMap_; + return listenerDeathRecipientMap_; } -void AuthEventListenerManager::AuthEventListenerDeathRecipient::OnRemoteDied(const wptr &remote) +EventListenerManager::EventListenerDeathRecipient::EventListenerDeathRecipient(EventListenerManager *manager) + : eventListenerManager_(manager) {} + +void EventListenerManager::EventListenerDeathRecipient::OnRemoteDied(const wptr &remote) { IAM_LOGI("start"); - if (remote == nullptr) { - IAM_LOGE("remote is nullptr"); + if (remote == nullptr || eventListenerManager_ == nullptr) { + IAM_LOGE("remote or manager is nullptr"); return; } - std::map, sptr> deathRecipientMap = - AuthEventListenerManager::GetInstance().GetDeathRecipientMap(); + auto deathRecipientMap = eventListenerManager_->GetListenerDeathRecipientMap(); for (auto &iter : deathRecipientMap) { if (iter.first != nullptr && remote == iter.first->AsObject()) { - int32_t result = AuthEventListenerManager::GetInstance().UnRegistUserAuthSuccessEventListener(iter.first); + int32_t result = eventListenerManager_->UnRegistEventListener(iter.first); if (result != SUCCESS) { - IAM_LOGE("UnRegistUserAuthSuccessEventListener fail"); + IAM_LOGE("UnRegistEventListener fail"); return; } } } } + +AuthEventListenerManager &AuthEventListenerManager::GetInstance() +{ + IAM_LOGI("start"); + static AuthEventListenerManager authEventListenerManager; + return authEventListenerManager; +} + +void AuthEventListenerManager::OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, + const std::string &callerName) +{ + IAM_LOGI("start"); + auto listenerSetTemp = GetListenerDeathRecipientMap(); + for (auto &iter : listenerSetTemp) { + if (iter.first != nullptr) { + iter.first->OnNotifyAuthSuccessEvent(userId, authType, callerType, callerName); + } + } +} + +CredChangeEventListenerManager &CredChangeEventListenerManager::GetInstance() +{ + IAM_LOGI("start"); + static CredChangeEventListenerManager credChangeEventListenerManager; + return credChangeEventListenerManager; +} + +void CredChangeEventListenerManager::OnNotifyCredChangeEvent(int32_t userId, AuthType authType, + CredChangeEventType eventType, uint64_t credentialId) +{ + IAM_LOGI("start"); + auto listenerSetTemp = GetListenerDeathRecipientMap(); + for (auto &iter : listenerSetTemp) { + if (iter.first != nullptr) { + iter.first->OnNotifyCredChangeEvent(userId, authType, eventType, credentialId); + } + } +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/services/core/src/ipc_common.cpp b/services/core/src/ipc_common.cpp index 30d3b6f14ce029b0433fc419e4eded6f1e3991fd..e6bbb66f6bf2b9ed072f67d2b3bc97f670b0f2c6 100644 --- a/services/core/src/ipc_common.cpp +++ b/services/core/src/ipc_common.cpp @@ -43,15 +43,13 @@ namespace PermissionString { const std::string SUPPORT_USER_AUTH = "ohos.permission.SUPPORT_USER_AUTH"; const std::string USE_USER_ACCESS_MANAGER = "ohos.permission.USE_USER_ACCESS_MANAGER"; const std::string USER_AUTH_FROM_BACKGROUND = "ohos.permission.USER_AUTH_FROM_BACKGROUND"; + const std::string ENTERPRISE_DEVICE_MGR = "ohos.permission.MANAGE_EDM_POLICY"; } namespace { const std::vector> enforceUserIdmWhiteLists = { {3058, "accountmgr"}, }; - const std::vector> EDM_WHITE_LIST = { - {3057, "edm"}, - }; } int32_t IpcCommon::GetCallingUserId(IPCObjectStub &stub, int32_t &userId) @@ -214,7 +212,7 @@ bool IpcCommon::CheckPermission(IPCObjectStub &stub, Permission permission) case USER_AUTH_FROM_BACKGROUND: return CheckDirectCallerAndFirstCallerIfSet(stub, PermissionString::USER_AUTH_FROM_BACKGROUND); case ENTERPRISE_DEVICE_MGR: - return CheckNativeCallingProcessWhiteList(stub, permission); + return CheckDirectCaller(stub, PermissionString::ENTERPRISE_DEVICE_MGR); default: IAM_LOGE("failed to check permission"); return false; @@ -224,10 +222,10 @@ bool IpcCommon::CheckPermission(IPCObjectStub &stub, Permission permission) uint32_t IpcCommon::GetAccessTokenId(IPCObjectStub &stub) { uint32_t tokenId = stub.GetFirstTokenID(); - IAM_LOGI("get first caller tokenId: %{public}s", GET_MASKED_STRING(tokenId).c_str()); + IAM_LOGD("get first caller tokenId: %{public}s", GET_MASKED_STRING(tokenId).c_str()); if (tokenId == 0) { tokenId = stub.GetCallingTokenID(); - IAM_LOGI("no first caller, get direct caller tokenId: %{public}s", GET_MASKED_STRING(tokenId).c_str()); + IAM_LOGD("no first caller, get direct caller tokenId: %{public}s", GET_MASKED_STRING(tokenId).c_str()); } return tokenId; } @@ -235,7 +233,7 @@ uint32_t IpcCommon::GetAccessTokenId(IPCObjectStub &stub) uint32_t IpcCommon::GetTokenId(IPCObjectStub &stub) { uint32_t tokenId = stub.GetCallingTokenID(); - IAM_LOGI("get tokenId: %{public}s", GET_MASKED_STRING(tokenId).c_str()); + IAM_LOGD("get tokenId: %{public}s", GET_MASKED_STRING(tokenId).c_str()); return tokenId; } @@ -244,8 +242,6 @@ std::vector> IpcCommon::GetWhiteLists(Permission switch (permission) { case ENFORCE_USER_IDM: return enforceUserIdmWhiteLists; - case ENTERPRISE_DEVICE_MGR: - return EDM_WHITE_LIST; default: IAM_LOGE("the permission has no white lists"); return {}; diff --git a/services/core/src/publish_event_adapter.cpp b/services/core/src/publish_event_adapter.cpp index e78b67ab123dd2eb76fe0b38cfa70c6dfe90e269..e4382ddee04ff16228876adf50af0e12302fb881 100644 --- a/services/core/src/publish_event_adapter.cpp +++ b/services/core/src/publish_event_adapter.cpp @@ -16,6 +16,7 @@ #include "publish_event_adapter.h" #include "common_event_manager.h" +#include "event_listener_manager.h" #include "iam_logger.h" #ifndef LOG_LABEL @@ -86,6 +87,7 @@ void PublishEventAdapter::PublishUpdatedEvent(int32_t userId, uint64_t credentia IAM_LOGE("Bad Parameter!"); return; } + CredChangeEventListenerManager::GetInstance().OnNotifyCredChangeEvent(userId, PIN, UPDATE_CRED, credentialId); EventFwk::Want want; want.SetAction(USER_PIN_UPDATED_EVENT); want.SetParam(TAG_SCHEDULEID, std::to_string(scheduleId_)); diff --git a/services/core/src/resource_node_impl.cpp b/services/core/src/resource_node_impl.cpp index d1a70f6f638587c95ccbbee1942907bcc4131804..c939da9d69274d7b2eb4bdd9b67cc08576a3f1bb 100644 --- a/services/core/src/resource_node_impl.cpp +++ b/services/core/src/resource_node_impl.cpp @@ -34,7 +34,7 @@ namespace UserIam { namespace UserAuth { class ResourceNodeImpl : public ResourceNode, public NoCopyable { public: - ResourceNodeImpl(ExecutorRegisterInfo info, std::shared_ptr callback); + ResourceNodeImpl(ExecutorRegisterInfo info, std::shared_ptr callback); ~ResourceNodeImpl() override; uint64_t GetExecutorIndex() const override; @@ -63,13 +63,13 @@ private: static void DeleteExecutorFromDriver(uint64_t executorIndex); ExecutorRegisterInfo info_; - std::shared_ptr callback_; + std::shared_ptr callback_; uint64_t executorIndex_ {0}; std::recursive_mutex mutex_; bool addedToDriver_ {false}; }; -ResourceNodeImpl::ResourceNodeImpl(ExecutorRegisterInfo info, std::shared_ptr callback) +ResourceNodeImpl::ResourceNodeImpl(ExecutorRegisterInfo info, std::shared_ptr callback) : info_(std::move(info)), callback_(std::move(callback)) { @@ -141,46 +141,51 @@ std::string ResourceNodeImpl::GetExecutorDeviceUdid() const int32_t ResourceNodeImpl::BeginExecute(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ != nullptr) { - return callback_->OnBeginExecute(scheduleId, publicKey, command); + return callback_->OnBeginExecute(scheduleId, publicKey, command.Serialize()); } return GENERAL_ERROR; } int32_t ResourceNodeImpl::EndExecute(uint64_t scheduleId, const Attributes &command) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ != nullptr) { - return callback_->OnEndExecute(scheduleId, command); + return callback_->OnEndExecute(scheduleId, command.Serialize()); } return GENERAL_ERROR; } int32_t ResourceNodeImpl::SetProperty(const Attributes &properties) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ != nullptr) { - return callback_->OnSetProperty(properties); + return callback_->OnSetProperty(properties.Serialize()); } return GENERAL_ERROR; } int32_t ResourceNodeImpl::GetProperty(const Attributes &condition, Attributes &values) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ != nullptr) { - return callback_->OnGetProperty(condition, values); + std::vector attribute; + auto ret = callback_->OnGetProperty(condition.Serialize(), attribute); + if (ret == SUCCESS) { + values = Attributes(attribute); + } + return ret; } return GENERAL_ERROR; } int32_t ResourceNodeImpl::SendData(uint64_t scheduleId, const Attributes &data) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (callback_ != nullptr) { - return callback_->OnSendData(scheduleId, data); + return callback_->OnSendData(scheduleId, data.Serialize()); } return GENERAL_ERROR; } @@ -249,7 +254,7 @@ void ResourceNodeImpl::DeleteExecutorFromDriver(uint64_t executorIndex) } std::shared_ptr ResourceNode::MakeNewResource(const ExecutorRegisterInfo &info, - const std::shared_ptr &callback, std::vector &templateIdList, + const std::shared_ptr &callback, std::vector &templateIdList, std::vector &fwkPublicKey) { auto node = Common::MakeShared(info, callback); diff --git a/services/core/src/schedule_node_builder.cpp b/services/core/src/schedule_node_builder.cpp index 9fa9b31332fcebfb4e99ced457c5527d8680b2a8..a9c226162f0506f67e83d87485e8e655ab8fa6f3 100644 --- a/services/core/src/schedule_node_builder.cpp +++ b/services/core/src/schedule_node_builder.cpp @@ -142,7 +142,7 @@ std::shared_ptr ScheduleNodeBuilder::Build() IAM_LOGE("checkParameters error"); return nullptr; } - IAM_LOGI("scheduleNode builder start to build"); + IAM_LOGD("scheduleNode builder start to build"); info_.collector = collector_; info_.verifier = verifier_; return Common::MakeShared(info_); @@ -171,7 +171,7 @@ bool ScheduleNodeBuilder::CheckExecutors(const std::shared_ptr &co } if (collector->GetAuthType() != verifier->GetAuthType()) { - IAM_LOGE("collector_ && verifier authtype mismatch"); + IAM_LOGE("collector_ && verifier authType mismatch"); return false; } diff --git a/services/core/src/schedule_node_helper.cpp b/services/core/src/schedule_node_helper.cpp index 38de0b7c0665a43de93a751db0b05c473d81edad..44efb0a642b949ae21ce2208d3a9e53ecbafd201 100644 --- a/services/core/src/schedule_node_helper.cpp +++ b/services/core/src/schedule_node_helper.cpp @@ -67,7 +67,7 @@ bool ScheduleNodeHelper::ScheduleInfoToScheduleNode(const HdiScheduleInfo &info, return false; } - IAM_LOGI("collectorMessage size: %{public}zu, verifierMessage size %{public}zu", + IAM_LOGD("collectorMessage size: %{public}zu, verifierMessage size %{public}zu", collectorMessage.size(), verifierMessage.size()); auto builder = ScheduleNode::Builder::New(collector, verifier); diff --git a/services/core/src/schedule_node_impl.cpp b/services/core/src/schedule_node_impl.cpp index 54aac5886df46d10ea1e264f5678224d981f1a72..7885f55bd8c2bc45fbc7ab79e264f7c38ba92a11 100644 --- a/services/core/src/schedule_node_impl.cpp +++ b/services/core/src/schedule_node_impl.cpp @@ -367,7 +367,7 @@ void ScheduleNodeImpl::ProcessBeginVerifier(FiniteStateMachine &machine, uint32_ machine.Schedule(E_VERIFY_STARTED_FAILED); return; } - IAM_LOGI("start verify success"); + IAM_LOGD("start verify success"); machine.Schedule(E_VERIFY_STARTED_SUCCESS); } @@ -382,7 +382,7 @@ void ScheduleNodeImpl::ProcessBeginCollector(FiniteStateMachine &machine, uint32 return; } if (collector == verifier) { - IAM_LOGI("all in one schedule, just wait the result"); + IAM_LOGD("all in one schedule, just wait the result"); machine.Schedule(E_COLLECT_STARTED_SUCCESS); return; } @@ -397,7 +397,7 @@ void ScheduleNodeImpl::ProcessBeginCollector(FiniteStateMachine &machine, uint32 machine.Schedule(E_COLLECT_STARTED_FAILED); return; } - IAM_LOGI("start collect success"); + IAM_LOGD("start collect success"); machine.Schedule(E_COLLECT_STARTED_SUCCESS); NotifyCollectorReady(); } @@ -500,7 +500,7 @@ void ScheduleNodeImpl::OnScheduleFinished(FiniteStateMachine &machine, uint32_t iamHitraceHelper_ = nullptr; int32_t result = fwkResultCode_.value_or(executorResultCode_); - IAM_LOGI("schedule result = %{public}d", result); + IAM_LOGD("schedule result = %{public}d", result); callback->OnScheduleStoped(result, scheduleResult_); ClearScheduleCallback(); } diff --git a/services/ipc/BUILD.gn b/services/ipc/BUILD.gn index e8b8affc7396cc73b4d69e23d28cacc85b458b45..848207599fddc29e40d24cff32c7c62a90eb2e0c 100644 --- a/services/ipc/BUILD.gn +++ b/services/ipc/BUILD.gn @@ -65,6 +65,7 @@ ohos_source_set("userauth_services_ipc") { "device_manager:devicemanagersdk", "drivers_interface_user_auth:libuser_auth_proxy_3.0", "dsoftbus:softbus_client", + "hdf_core:libhdf_utils", "hdf_core:libhdi", "hilog:libhilog", "hitrace:hitrace_meter", diff --git a/services/ipc/inc/co_auth_service.h b/services/ipc/inc/co_auth_service.h index 256bf28ba9ea3fa7e19973176b0a64ba63d76194..7e5710a6f60d5cd960e97969aa9a7ca87b3417c5 100644 --- a/services/ipc/inc/co_auth_service.h +++ b/services/ipc/inc/co_auth_service.h @@ -17,9 +17,11 @@ #define CO_AUTH_SERVICE_H #include "co_auth_stub.h" +#include "co_auth_interface.h" #include +#include "resource_node_pool.h" #include #include #include "system_ability_listener.h" @@ -27,6 +29,7 @@ namespace OHOS { namespace UserIam { namespace UserAuth { +using ExecutorRegisterInfo = CoAuthInterface::ExecutorRegisterInfo; class CoAuthService : public SystemAbility, public CoAuthStub { public: static constexpr uint32_t DEFER_TIME = 100; @@ -36,14 +39,17 @@ public: CoAuthService(); ~CoAuthService() override = default; int Dump(int fd, const std::vector &args) override; - uint64_t ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) override; - void ExecutorUnregister(uint64_t executorIndex) override; + int32_t ExecutorRegister(const IpcExecutorRegisterInfo &ipcExecutorRegisterInfo, + const sptr &executorCallback, uint64_t &executorIndex) override; + int32_t ExecutorUnregister(uint64_t executorIndex) override; void SetIsReady(bool isReady); void SetAccessTokenReady(bool isReady); void OnDriverStart(); void OnDriverStop(); ResultCode RegisterAccessTokenListener(); ResultCode UnRegisterAccessTokenListener(); + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; protected: void OnStart() override; @@ -51,10 +57,15 @@ protected: private: static void AddExecutorDeathRecipient(uint64_t executorIndex, AuthType authType, ExecutorRole role, - std::shared_ptr callback); + std::shared_ptr callback); void AuthServiceInit(); void NotifyFwkReady(); bool IsFwkReady(); + int32_t ProcExecutorRegisterSuccess(std::shared_ptr &resourceNode, + const std::shared_ptr &callback, std::vector &templateIdList, + std::vector &fwkPublicKey); + void InitExecutorRegisterInfo(const IpcExecutorRegisterInfo &ipcExecutorRegisterInfo, + ExecutorRegisterInfo &executorRegisterInfo); static std::shared_ptr instance_; std::recursive_mutex mutex_; diff --git a/services/ipc/inc/executor_messenger_service.h b/services/ipc/inc/executor_messenger_service.h index 769c1226f87eb808727c92c06a98b6091d17c644..b2235d585e6d1609836ee922276ce42162cd8303 100644 --- a/services/ipc/inc/executor_messenger_service.h +++ b/services/ipc/inc/executor_messenger_service.h @@ -25,10 +25,12 @@ namespace UserAuth { class ExecutorMessengerService : public ExecutorMessengerStub { public: static sptr GetInstance(); - int32_t SendData(uint64_t scheduleId, ExecutorRole dstRole, + int32_t SendData(uint64_t scheduleId, int32_t dstRole, const std::vector &msg) override; - int32_t Finish(uint64_t scheduleId, ResultCode resultCode, - const std::shared_ptr &finalResult) override; + int32_t Finish(uint64_t scheduleId, int32_t resultCode, + const std::vector &finalResult) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; private: explicit ExecutorMessengerService(); diff --git a/services/ipc/inc/user_auth_service.h b/services/ipc/inc/user_auth_service.h index 8afe6b0081ec07db22b5a591102e86caeab6be36..655d270485ad135efb013ff896b7c1fb26d19638 100644 --- a/services/ipc/inc/user_auth_service.h +++ b/services/ipc/inc/user_auth_service.h @@ -39,36 +39,38 @@ public: UserAuthService(); ~UserAuthService() override = default; - int32_t GetAvailableStatus(int32_t apiVersion, int32_t userId, AuthType authType, - AuthTrustLevel authTrustLevel) override; - int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) override; - void GetProperty(int32_t userId, AuthType authType, - const std::vector &keys, - sptr &callback) override; - void GetPropertyById(uint64_t credentialId, const std::vector &keys, - sptr &callback) override; - void SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, - sptr &callback) override; - uint64_t AuthUser(AuthParamInner ¶m, std::optional &remoteAuthParam, - sptr &callback) override; - uint64_t Auth(int32_t apiVersion, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) override; - uint64_t AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, const WidgetParamInner &widgetParam, - sptr &callback, sptr &modalCallback) override; - uint64_t Identify(const std::vector &challenge, AuthType authType, - sptr &callback) override; + int32_t GetAvailableStatus(int32_t apiVersion, int32_t userId, int32_t authType, + uint32_t authTrustLevel) override; + int32_t GetAvailableStatus(int32_t apiVersion, int32_t authType, uint32_t authTrustLevel) override; + int32_t GetProperty(int32_t userId, int32_t authType, const std::vector &keys, + const sptr &getExecutorPropertyCallback) override; + int32_t GetPropertyById(uint64_t credentialId, const std::vector &keys, + const sptr &getExecutorPropertyCallback) override; + int32_t SetProperty(int32_t userId, int32_t authType, const std::vector &attributes, + const sptr &setExecutorPropertyCallback) override; + int32_t AuthUser(const IpcAuthParamInner &ipcAuthParamInner, const IpcRemoteAuthParam &ipcRemoteAuthParam, + const sptr &userAuthCallback, uint64_t &contextId) override; + int32_t Auth(int32_t apiVersion, const IpcAuthParamInner &ipcAuthParamInner, + const sptr &userAuthCallback, uint64_t &contextI) override; + int32_t AuthWidget(int32_t apiVersion, const IpcAuthParamInner &ipcAuthParamInner, + const IpcWidgetParamInner &ipcWidgetParamInner, const sptr &userAuthCallback, + const sptr &modalCallback, uint64_t &contextId) override; + int32_t Identify(const std::vector &challenge, int32_t authType, + const sptr &userAuthCallback, uint64_t &contextId) override; int32_t CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) override; int32_t GetVersion(int32_t &version) override; - int32_t Notice(NoticeType noticeType, const std::string &eventData) override; - int32_t RegisterWidgetCallback(int32_t version, sptr &callback) override; - int32_t GetEnrolledState(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState) override; - int32_t RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) override; - int32_t UnRegistUserAuthSuccessEventListener(const sptr &listener) override; - int32_t SetGlobalConfigParam(const GlobalConfigParam ¶m) override; - int32_t PrepareRemoteAuth(const std::string &networkId, sptr &callback) override; - void VerifyAuthToken(const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback) override; + int32_t Notice(int32_t noticeType, const std::string &eventData) override; + int32_t RegisterWidgetCallback(int32_t version, const sptr &widgetCallback) override; + int32_t GetEnrolledState(int32_t apiVersion, int32_t authType, IpcEnrolledState &ipcEnrolledState) override; + int32_t RegistUserAuthSuccessEventListener(const sptr &listener) override; + int32_t UnRegistUserAuthSuccessEventListener(const sptr &listener) override; + int32_t SetGlobalConfigParam(const IpcGlobalConfigParam &ipcGlobalConfigParam) override; + int32_t PrepareRemoteAuth(const std::string &networkId, + const sptr &userAuthCallback) override; + int32_t VerifyAuthToken(const std::vector &tokenIn, uint64_t allowableDuration, + const sptr &verifyTokenCallback) override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; protected: void OnStart() override; @@ -77,9 +79,9 @@ protected: private: std::shared_ptr GetAuthContextCallback(int32_t apiVersion, const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, - sptr &callback); + const sptr &callback); std::shared_ptr GetAuthContextCallback(int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback); + const WidgetParamInner &widgetParam, const sptr &callback); bool CheckAuthTrustLevel(AuthTrustLevel authTrustLevel); bool CheckSingeFaceOrFinger(const std::vector &authType); bool CheckPrivatePinEnroll(const std::vector &authType, std::vector &validType); @@ -103,7 +105,6 @@ private: AuthTrustLevel authTrustLevel); bool CheckAuthPermissionAndParam(AuthType authType, AuthTrustLevel authTrustLevel, const std::shared_ptr &contextCallback, Attributes &extraInfo); - bool CheckAuthTypeIsValid(std::vector authType); int32_t CheckWindowMode(const WidgetParamInner &widgetParam); int32_t CheckValidSolution(int32_t userId, const AuthParamInner &authParam, const WidgetParamInner &widgetParam, std::vector &validType); @@ -114,7 +115,7 @@ private: std::vector &uint32Keys); void FillGetPropertyValue(AuthType authType, const std::vector &keys, Attributes &values); bool CompleteRemoteAuthParam(RemoteAuthParam &remoteAuthParam, const std::string &localNetworkId); - int32_t PrepareRemoteAuthInner(const std::string &networkId, sptr &callback); + int32_t PrepareRemoteAuthInner(const std::string &networkId, const sptr &callback); int32_t DoPrepareRemoteAuth(const std::string &networkId); int32_t GetAvailableStatusInner(int32_t apiVersion, int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel); @@ -124,8 +125,20 @@ private: void ProcessPinExpired(int32_t ret, const AuthParamInner &authParam, std::vector &validType, ContextFactory::AuthWidgetContextPara ¶); void ProcessWidgetSessionExclusive(); - void GetPropertyInner(AuthType authType, const std::vector &keys, - sptr &callback, std::vector &templateIds); + int32_t GetPropertyInner(AuthType authType, const std::vector &keys, + const sptr &callback, std::vector &templateIds); + int32_t StartAuth(int32_t apiVersion, Authentication::AuthenticationPara ¶, + std::shared_ptr &contextCallback, uint64_t &contextId); + int32_t StartAuthUser(AuthParamInner &authParam, std::optional &remoteAuthParam, + Authentication::AuthenticationPara ¶, std::shared_ptr &contextCallback, + uint64_t &contextId); + int32_t StartAuthWidget(AuthParamInner &authParam, WidgetParamInner &widgetParam, + ContextFactory::AuthWidgetContextPara ¶, std::shared_ptr &contextCallback, + const sptr &modalCallback, uint64_t &contextId); + void InitAuthParam(const IpcAuthParamInner &ipcAuthParam, AuthParamInner &authParam); + void InitRemoteAuthParam(const IpcRemoteAuthParam &ipcRemoteAuthParam, + std::optional &remoteAuthParam); + void InitWidgetParam(const IpcWidgetParamInner &ipcWidgetParam, WidgetParamInner &widgetParam); static std::mutex mutex_; static std::shared_ptr instance_; }; diff --git a/services/ipc/inc/user_idm_service.h b/services/ipc/inc/user_idm_service.h index 16213f9bdef98c8ee9d5482f2340be4c48785a32..6b3dc96f76561ae47972ae574a0d803baed67c20 100644 --- a/services/ipc/inc/user_idm_service.h +++ b/services/ipc/inc/user_idm_service.h @@ -28,6 +28,7 @@ #include "context.h" #include "context_factory.h" #include "credential_info_interface.h" +#include "user_idm_client_defines.h" namespace OHOS { namespace UserIam { @@ -39,21 +40,28 @@ public: ~UserIdmService() override = default; int Dump(int fd, const std::vector &args) override; int32_t OpenSession(int32_t userId, std::vector &challenge) override; - void CloseSession(int32_t userId) override; - int32_t GetCredentialInfo(int32_t userId, AuthType authType, - const sptr &callback) override; - int32_t GetSecInfo(int32_t userId, const sptr &callback) override; - void AddCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback, bool isUpdate) override; - void UpdateCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback) override; + int32_t CloseSession(int32_t userId) override; + int32_t GetCredentialInfo(int32_t userId, int32_t authType, + const sptr &idmGetCredInfoCallbac) override; + int32_t GetSecInfo(int32_t userId, + const sptr &idmGetSecureUserInfoCallback) override; + int32_t AddCredential(int32_t userId, const IpcCredentialPara &ipcCredentialPara, + const sptr &IdmCallback, bool isUpdate) override; + int32_t UpdateCredential(int32_t userId, const IpcCredentialPara &ipcCredentialPara, + const sptr &IdmCallback) override; int32_t Cancel(int32_t userId) override; - int32_t EnforceDelUser(int32_t userId, const sptr &callback) override; - void DelUser(int32_t userId, const std::vector authToken, - const sptr &callback) override; - void DelCredential(int32_t userId, uint64_t credentialId, const std::vector &authToken, - const sptr &callback) override; - void ClearRedundancyCredential(const sptr &callback) override; + int32_t EnforceDelUser(int32_t userId, const sptr &IdmCallback) override; + int32_t DelUser(int32_t userId, const std::vector &authToken, + const sptr &IdmCallback) override; + int32_t DelCredential(int32_t userId, uint64_t credentialId, const std::vector &authToken, + const sptr &IdmCallback) override; + int32_t ClearRedundancyCredential(const sptr &IdmCallback) override; + int32_t RegistCredChangeEventListener(const sptr &listener) override; + int32_t UnRegistCredChangeEventListener(const sptr &listener) override; + int32_t GetCredentialInfoSync(int32_t userId, int32_t authType, + std::vector &ipcCredentialInfoList)override; + int32_t CallbackEnter([[maybe_unused]] uint32_t code) override; + int32_t CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) override; protected: void OnStart() override; @@ -69,7 +77,7 @@ private: int32_t ClearRedundancyCredentialInner(const std::string &callerName, int32_t callerType); void SetAuthTypeTrace(const std::vector> &credInfos, const std::shared_ptr &contextCallback); - void StartEnroll(Enrollment::EnrollmentPara ¶, + int32_t StartEnroll(Enrollment::EnrollmentPara ¶, const std::shared_ptr &contextCallback, Attributes &extraInfo, bool needSubscribeAppState); void PublishCommonEvent(int32_t userId, uint64_t credentialId, AuthType authType); std::mutex mutex_; diff --git a/services/ipc/src/co_auth_service.cpp b/services/ipc/src/co_auth_service.cpp index 0d2359da85a91dc04817f01479b5208e7fb9fe12..d46f3be93ba3985e2a868001ade66b1f85990f43 100644 --- a/services/ipc/src/co_auth_service.cpp +++ b/services/ipc/src/co_auth_service.cpp @@ -38,7 +38,6 @@ #include "parameter.h" #include "relative_timer.h" #include "remote_connect_manager.h" -#include "resource_node_pool.h" #include "service_init_manager.h" #include "system_param_manager.h" #include "template_cache_manager.h" @@ -72,7 +71,8 @@ std::shared_ptr CoAuthService::GetInstance() return instance_; } -CoAuthService::CoAuthService() : SystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, true) +CoAuthService::CoAuthService() + : SystemAbility(SUBSYS_USERIAM_SYS_ABILITY_AUTHEXECUTORMGR, true), CoAuthStub(true) { IAM_LOGI("CoAuthService init"); DriverStateManager::GetInstance().RegisterDriverStartCallback([]() { @@ -133,7 +133,7 @@ bool CoAuthService::IsFwkReady() } void CoAuthService::AddExecutorDeathRecipient(uint64_t executorIndex, AuthType authType, ExecutorRole role, - std::shared_ptr callback) + std::shared_ptr callback) { IF_FALSE_LOGE_AND_RETURN(callback != nullptr); auto obj = callback->AsObject(); @@ -156,88 +156,104 @@ void CoAuthService::AddExecutorDeathRecipient(uint64_t executorIndex, AuthType a })); } -uint64_t CoAuthService::ExecutorRegister(const ExecutorRegisterInfo &info, sptr &callback) +int32_t CoAuthService::ProcExecutorRegisterSuccess(std::shared_ptr &resourceNode, + const std::shared_ptr &callback, std::vector &templateIdList, + std::vector &fwkPublicKey) +{ + IAM_LOGI("start"); + uint64_t executorIndex = resourceNode->GetExecutorIndex(); + auto handler = ThreadHandler::GetSingleThreadInstance(); + std::weak_ptr weakNode = resourceNode; + IF_FALSE_LOGE_AND_RETURN_VAL(handler != nullptr, GENERAL_ERROR); + handler->PostTask([callback, fwkPublicKey, templateIdList, weakNode, executorIndex]() { + auto resourceNode = weakNode.lock(); + IF_FALSE_LOGE_AND_RETURN(resourceNode != nullptr); + sptr messenger = ExecutorMessengerService::GetInstance(); + callback->OnMessengerReady(messenger, fwkPublicKey, templateIdList); + IAM_LOGI("register successful, executorType is %{public}d, executorRole is %{public}d, " + "executorIndex is ****%{public}hx", + resourceNode->GetAuthType(), resourceNode->GetExecutorRole(), static_cast(executorIndex)); + LoadModeHandler::GetInstance().OnExecutorRegistered(resourceNode->GetAuthType(), + resourceNode->GetExecutorRole()); + AddExecutorDeathRecipient(executorIndex, resourceNode->GetAuthType(), resourceNode->GetExecutorRole(), + callback); + IAM_LOGI("update template cache after register success"); + TemplateCacheManager::GetInstance().UpdateTemplateCache(resourceNode->GetAuthType()); + }); + + return SUCCESS; +} + +int32_t CoAuthService::ExecutorRegister(const IpcExecutorRegisterInfo &ipcExecutorRegisterInfo, + const sptr &executorCallback, uint64_t &executorIndex) { IAM_LOGI("register resource node begin"); + executorIndex = INVALID_EXECUTOR_INDEX; Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - if (callback == nullptr) { + if (executorCallback == nullptr) { IAM_LOGE("executor callback is nullptr"); - return INVALID_EXECUTOR_INDEX; + return INVALID_PARAMETERS; } std::lock_guard guard(mutex_); if (!IsFwkReady()) { IAM_LOGE("framework is not ready"); - return INVALID_EXECUTOR_INDEX; + return GENERAL_ERROR; } if (!IpcCommon::CheckPermission(*this, ACCESS_AUTH_RESPOOL)) { IAM_LOGE("failed to check permission"); - return INVALID_EXECUTOR_INDEX; + return CHECK_PERMISSION_FAILED; } std::vector templateIdList; std::vector fwkPublicKey; - auto executorCallback = Common::SptrToStdSharedPtr(callback); - auto resourceNode = ResourceNode::MakeNewResource(info, executorCallback, templateIdList, fwkPublicKey); + ExecutorRegisterInfo executorRegisterInfo = {}; + InitExecutorRegisterInfo(ipcExecutorRegisterInfo, executorRegisterInfo); + sptr tempCallBack = executorCallback; + auto callback = Common::SptrToStdSharedPtr(tempCallBack); + auto resourceNode = ResourceNode::MakeNewResource(executorRegisterInfo, callback, + templateIdList, fwkPublicKey); if (resourceNode == nullptr) { IAM_LOGE("create resource node failed"); - return INVALID_EXECUTOR_INDEX; + return GENERAL_ERROR; } if (!ResourceNodePool::Instance().Insert(resourceNode)) { IAM_LOGE("insert resource node failed"); - return INVALID_EXECUTOR_INDEX; + return GENERAL_ERROR; } - - uint64_t executorIndex = resourceNode->GetExecutorIndex(); - auto handler = ThreadHandler::GetSingleThreadInstance(); - std::weak_ptr weakNode = resourceNode; - IF_FALSE_LOGE_AND_RETURN_VAL(handler != nullptr, GENERAL_ERROR); - handler->PostTask([executorCallback, fwkPublicKey, templateIdList, weakNode, executorIndex]() { - auto resourceNode = weakNode.lock(); - IF_FALSE_LOGE_AND_RETURN(resourceNode != nullptr); - sptr messenger = ExecutorMessengerService::GetInstance(); - executorCallback->OnMessengerReady(messenger, fwkPublicKey, templateIdList); - IAM_LOGI("register successful, executorType is %{public}d, executorRole is %{public}d, " - "executorIndex is ****%{public}hx", - resourceNode->GetAuthType(), resourceNode->GetExecutorRole(), static_cast(executorIndex)); - LoadModeHandler::GetInstance().OnExecutorRegistered(resourceNode->GetAuthType(), - resourceNode->GetExecutorRole()); - AddExecutorDeathRecipient(executorIndex, resourceNode->GetAuthType(), resourceNode->GetExecutorRole(), - executorCallback); - IAM_LOGI("update template cache after register success"); - TemplateCacheManager::GetInstance().UpdateTemplateCache(resourceNode->GetAuthType()); - }); - return executorIndex; + executorIndex = resourceNode->GetExecutorIndex(); + return ProcExecutorRegisterSuccess(resourceNode, callback, templateIdList, fwkPublicKey); } -void CoAuthService::ExecutorUnregister(uint64_t executorIndex) +int32_t CoAuthService::ExecutorUnregister(uint64_t executorIndex) { IAM_LOGI("delete resource node begin"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); std::lock_guard guard(mutex_); if (!IsFwkReady()) { IAM_LOGE("framework is not ready"); - return; + return SUCCESS; } if (!IpcCommon::CheckPermission(*this, ACCESS_AUTH_RESPOOL)) { IAM_LOGE("failed to check permission"); - return; + return CHECK_PERMISSION_FAILED; } { auto resourceNode = ResourceNodePool::Instance().Select(executorIndex).lock(); - IF_FALSE_LOGE_AND_RETURN(resourceNode != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(resourceNode != nullptr, GENERAL_ERROR); LoadModeHandler::GetInstance().OnExecutorUnregistered(resourceNode->GetAuthType(), resourceNode->GetExecutorRole()); } if (!ResourceNodePool::Instance().Delete(executorIndex)) { IAM_LOGE("delete resource node failed"); - return; + return GENERAL_ERROR; } IAM_LOGI("delete resource node success, executorIndex is ****%{public}hx", static_cast(executorIndex)); + return SUCCESS; } void CoAuthService::OnDriverStart() @@ -362,6 +378,32 @@ void CoAuthService::NotifyFwkReady() LoadModeHandler::GetInstance().OnFwkReady(); } } + +void CoAuthService::InitExecutorRegisterInfo(const IpcExecutorRegisterInfo &ipcExecutorRegisterInfo, + ExecutorRegisterInfo &executorRegisterInfo) +{ + executorRegisterInfo.authType = static_cast(ipcExecutorRegisterInfo.authType); + executorRegisterInfo.executorRole = static_cast(ipcExecutorRegisterInfo.executorRole); + executorRegisterInfo.executorSensorHint = ipcExecutorRegisterInfo.executorSensorHint; + executorRegisterInfo.executorMatcher = ipcExecutorRegisterInfo.executorMatcher; + executorRegisterInfo.esl = static_cast(ipcExecutorRegisterInfo.esl); + executorRegisterInfo.maxTemplateAcl = ipcExecutorRegisterInfo.maxTemplateAcl; + executorRegisterInfo.publicKey = ipcExecutorRegisterInfo.publicKey; + executorRegisterInfo.deviceUdid = ipcExecutorRegisterInfo.deviceUdid; + executorRegisterInfo.signedRemoteExecutorInfo = ipcExecutorRegisterInfo.signedRemoteExecutorInfo; +} + +int32_t CoAuthService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t CoAuthService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/services/ipc/src/executor_messenger_service.cpp b/services/ipc/src/executor_messenger_service.cpp index 8a342b227d13996863129331c8b05c731a87b6b8..bd68cba3adca7161a9e69be86c38ab40d7b97712 100644 --- a/services/ipc/src/executor_messenger_service.cpp +++ b/services/ipc/src/executor_messenger_service.cpp @@ -19,6 +19,7 @@ #include "iam_logger.h" #include "iam_common_defines.h" +#include "iam_ptr.h" #define LOG_TAG "USER_AUTH_SA" @@ -39,14 +40,14 @@ sptr ExecutorMessengerService::GetInstance() return instance; } -int32_t ExecutorMessengerService::SendData(uint64_t scheduleId, ExecutorRole dstRole, const std::vector &msg) +int32_t ExecutorMessengerService::SendData(uint64_t scheduleId, int32_t dstRole, const std::vector &msg) { auto scheduleNode = ContextPool::Instance().SelectScheduleNodeByScheduleId(scheduleId); if (scheduleNode == nullptr) { IAM_LOGE("selected schedule node is nullptr"); return GENERAL_ERROR; } - bool result = scheduleNode->SendMessage(dstRole, msg); + bool result = scheduleNode->SendMessage(static_cast(dstRole), msg); if (!result) { IAM_LOGE("continue schedule failed"); return GENERAL_ERROR; @@ -54,21 +55,40 @@ int32_t ExecutorMessengerService::SendData(uint64_t scheduleId, ExecutorRole dst return SUCCESS; } -int32_t ExecutorMessengerService::Finish(uint64_t scheduleId, ResultCode resultCode, - const std::shared_ptr &finalResult) +int32_t ExecutorMessengerService::Finish(uint64_t scheduleId, int32_t resultCode, + const std::vector &finalResult) { auto scheduleNode = ContextPool::Instance().SelectScheduleNodeByScheduleId(scheduleId); if (scheduleNode == nullptr) { IAM_LOGE("selected schedule node is nullptr"); return GENERAL_ERROR; } - bool result = scheduleNode->ContinueSchedule(resultCode, finalResult); + + auto attributes = Common::MakeShared(finalResult); + if (attributes == nullptr) { + IAM_LOGE("failed to create attributes"); + return GENERAL_ERROR; + } + + bool result = scheduleNode->ContinueSchedule(static_cast(resultCode), attributes); if (!result) { IAM_LOGE("continue schedule failed"); return GENERAL_ERROR; } return SUCCESS; } + +int32_t ExecutorMessengerService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t ExecutorMessengerService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/services/ipc/src/user_auth_service.cpp b/services/ipc/src/user_auth_service.cpp index d1c7c07a102a022e89dcd8071ab44c8c2a99344e..189614eabc553ffb947a4676bc37e9e7ca00587a 100644 --- a/services/ipc/src/user_auth_service.cpp +++ b/services/ipc/src/user_auth_service.cpp @@ -20,7 +20,7 @@ #include "accesstoken_kit.h" #include "auth_common.h" -#include "auth_event_listener_manager.h" +#include "event_listener_manager.h" #include "auth_widget_helper.h" #include "context_factory.h" #include "context_helper.h" @@ -68,7 +68,7 @@ int32_t GetTemplatesByAuthType(int32_t userId, AuthType authType, std::vector UserAuthService::GetInstance() } UserAuthService::UserAuthService() - : SystemAbility(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH, true) + : SystemAbility(SUBSYS_USERIAM_SYS_ABILITY_USERAUTH, true), UserAuthStub(true) {} void UserAuthService::OnStart() @@ -185,28 +185,29 @@ bool UserAuthService::CheckAuthTrustLevel(AuthTrustLevel authTrustLevel) return true; } -int32_t UserAuthService::GetAvailableStatus(int32_t apiVersion, int32_t userId, AuthType authType, - AuthTrustLevel authTrustLevel) +int32_t UserAuthService::GetAvailableStatus(int32_t apiVersion, int32_t userId, int32_t authType, + uint32_t authTrustLevel) { - IAM_LOGI("start with userId"); + IAM_LOGD("start with userId"); if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) { IAM_LOGE("failed to check permission"); return CHECK_PERMISSION_FAILED; } - return GetAvailableStatusInner(apiVersion, userId, authType, authTrustLevel); + return GetAvailableStatusInner(apiVersion, userId, static_cast(authType), + static_cast(authTrustLevel)); } -int32_t UserAuthService::GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) +int32_t UserAuthService::GetAvailableStatus(int32_t apiVersion, int32_t authType, uint32_t authTrustLevel) { - IAM_LOGI("start without userId"); + IAM_LOGD("start without userId"); if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION) && !IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION)) { IAM_LOGE("failed to check permission"); return CHECK_PERMISSION_FAILED; } - if (apiVersion <= API_VERSION_8 && authType == PIN) { + if (apiVersion <= API_VERSION_8 && static_cast(authType) == PIN) { IAM_LOGE("authType not support"); return TYPE_NOT_SUPPORT; } @@ -215,7 +216,8 @@ int32_t UserAuthService::GetAvailableStatus(int32_t apiVersion, AuthType authTyp IAM_LOGE("failed to get userId"); return GENERAL_ERROR; } - return GetAvailableStatusInner(apiVersion, userId, authType, authTrustLevel); + return GetAvailableStatusInner(apiVersion, userId, static_cast(authType), + static_cast(authTrustLevel)); } int32_t UserAuthService::GetAvailableStatusInner(int32_t apiVersion, int32_t userId, AuthType authType, @@ -284,15 +286,15 @@ std::shared_ptr UserAuthService::GetResourseNode(AuthType authType return resourceNode; } -void UserAuthService::GetPropertyInner(AuthType authType, const std::vector &keys, - sptr &callback, std::vector &templateIds) +int32_t UserAuthService::GetPropertyInner(AuthType authType, const std::vector &keys, + const sptr &getExecutorPropertyCallback, std::vector &templateIds) { Attributes values; auto resourceNode = GetResourseNode(authType); if (resourceNode == nullptr) { IAM_LOGE("resourceNode is nullptr"); - callback->OnGetExecutorPropertyResult(GENERAL_ERROR, values); - return; + getExecutorPropertyCallback->OnGetExecutorPropertyResult(GENERAL_ERROR, values.Serialize()); + return SUCCESS; } std::vector uint32Keys; @@ -308,54 +310,60 @@ void UserAuthService::GetPropertyInner(AuthType authType, const std::vectorOnGetExecutorPropertyResult(result, values); + getExecutorPropertyCallback->OnGetExecutorPropertyResult(result, values.Serialize()); + return SUCCESS; } -void UserAuthService::GetProperty(int32_t userId, AuthType authType, - const std::vector &keys, sptr &callback) +int32_t UserAuthService::GetProperty(int32_t userId, int32_t authType, + const std::vector &keys, const sptr &getExecutorPropertyCallback) { - IAM_LOGI("start"); + IAM_LOGD("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorPropertyCallback != nullptr, INVALID_PARAMETERS); Attributes values; if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) { IAM_LOGE("failed to check permission"); - callback->OnGetExecutorPropertyResult(CHECK_PERMISSION_FAILED, values); - return; + getExecutorPropertyCallback->OnGetExecutorPropertyResult(CHECK_PERMISSION_FAILED, values.Serialize()); + return SUCCESS; } + std::vector attrKeys; + attrKeys.resize(keys.size()); + std::transform(keys.begin(), keys.end(), attrKeys.begin(), [](uint32_t key) { + return static_cast(key); + }); std::vector templateIds; - if (IsTemplateIdListRequired(keys)) { - int32_t ret = GetTemplatesByAuthType(userId, authType, templateIds); + if (IsTemplateIdListRequired(attrKeys)) { + int32_t ret = GetTemplatesByAuthType(userId, static_cast(authType), templateIds); if (ret != SUCCESS) { IAM_LOGE("get templates fail, ret:%{public}d, userId:%{public}d, authType:%{public}d", ret, userId, authType); - callback->OnGetExecutorPropertyResult(GENERAL_ERROR, values); - return; + getExecutorPropertyCallback->OnGetExecutorPropertyResult(GENERAL_ERROR, values.Serialize()); + return SUCCESS; } if (templateIds.size() == 0) { IAM_LOGE("template id list is required, but templateIds size is 0"); - callback->OnGetExecutorPropertyResult(NOT_ENROLLED, values); - return; + getExecutorPropertyCallback->OnGetExecutorPropertyResult(NOT_ENROLLED, values.Serialize()); + return SUCCESS; } } - GetPropertyInner(authType, keys, callback, templateIds); + return GetPropertyInner(static_cast(authType), attrKeys, getExecutorPropertyCallback, templateIds); } -void UserAuthService::GetPropertyById(uint64_t credentialId, const std::vector &keys, - sptr &callback) +int32_t UserAuthService::GetPropertyById(uint64_t credentialId, const std::vector &keys, + const sptr &getExecutorPropertyCallback) { - IAM_LOGI("start"); + IAM_LOGD("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(getExecutorPropertyCallback != nullptr, INVALID_PARAMETERS); Attributes values; if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) { IAM_LOGE("failed to check permission"); - callback->OnGetExecutorPropertyResult(CHECK_PERMISSION_FAILED, values); - return; + getExecutorPropertyCallback->OnGetExecutorPropertyResult(CHECK_PERMISSION_FAILED, values.Serialize()); + return SUCCESS; } std::shared_ptr credInfo; @@ -363,70 +371,77 @@ void UserAuthService::GetPropertyById(uint64_t credentialId, const std::vectorOnGetExecutorPropertyResult(ret, values); - return; + getExecutorPropertyCallback->OnGetExecutorPropertyResult(ret, values.Serialize()); + return SUCCESS; } if (credInfo == nullptr) { IAM_LOGE("credential is nullptr"); - callback->OnGetExecutorPropertyResult(GENERAL_ERROR, values); - return; + getExecutorPropertyCallback->OnGetExecutorPropertyResult(GENERAL_ERROR, values.Serialize()); + return SUCCESS; } + std::vector attrKeys; + attrKeys.resize(keys.size()); + std::transform(keys.begin(), keys.end(), attrKeys.begin(), [](uint32_t key) { + return static_cast(key); + }); AuthType authType = credInfo->GetAuthType(); templateIds.push_back(credInfo->GetTemplateId()); - GetPropertyInner(authType, keys, callback, templateIds); + return GetPropertyInner(authType, attrKeys, getExecutorPropertyCallback, templateIds); } -void UserAuthService::SetProperty(int32_t userId, AuthType authType, const Attributes &attributes, - sptr &callback) +int32_t UserAuthService::SetProperty(int32_t userId, int32_t authType, const std::vector &attributes, + const sptr &setExecutorPropertyCallback) { - IAM_LOGI("start"); + IAM_LOGD("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - if (callback == nullptr) { + if (setExecutorPropertyCallback == nullptr) { IAM_LOGE("callback is nullptr"); - return; + return INVALID_PARAMETERS; } if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) { IAM_LOGE("permission check failed"); - callback->OnSetExecutorPropertyResult(CHECK_PERMISSION_FAILED); - return; + setExecutorPropertyCallback->OnSetExecutorPropertyResult(CHECK_PERMISSION_FAILED); + return CHECK_PERMISSION_FAILED; } std::vector> authTypeNodes; - GetResourceNodeByTypeAndRole(authType, ALL_IN_ONE, authTypeNodes); + GetResourceNodeByTypeAndRole(static_cast(authType), ALL_IN_ONE, authTypeNodes); if (authTypeNodes.size() != 1) { IAM_LOGE("auth type %{public}d resource node num %{public}zu is not expected", authType, authTypeNodes.size()); - callback->OnSetExecutorPropertyResult(GENERAL_ERROR); - return; + setExecutorPropertyCallback->OnSetExecutorPropertyResult(GENERAL_ERROR); + return SUCCESS; } auto resourceNode = authTypeNodes[0].lock(); if (resourceNode == nullptr) { IAM_LOGE("resourceNode is nullptr"); - callback->OnSetExecutorPropertyResult(GENERAL_ERROR); - return; + setExecutorPropertyCallback->OnSetExecutorPropertyResult(GENERAL_ERROR); + return SUCCESS; } - int32_t result = resourceNode->SetProperty(attributes); + const Attributes properties(attributes); + int32_t result = resourceNode->SetProperty(properties); if (result != SUCCESS) { IAM_LOGE("set property failed, result = %{public}d", result); } - callback->OnSetExecutorPropertyResult(result); + setExecutorPropertyCallback->OnSetExecutorPropertyResult(result); + return result; } std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t apiVersion, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback) + AuthTrustLevel authTrustLevel, const sptr &userAuthCallback) { - if (callback == nullptr) { + if (userAuthCallback == nullptr) { IAM_LOGE("callback is nullptr"); return nullptr; } - auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL); + auto contextCallback = ContextCallback::NewInstance(userAuthCallback, TRACE_AUTH_USER_ALL); if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); Attributes extraInfo; - callback->OnResult(GENERAL_ERROR, extraInfo); + userAuthCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); return nullptr; } contextCallback->SetTraceAuthType(authType); @@ -458,54 +473,66 @@ int32_t UserAuthService::CheckAuthPermissionAndParam(int32_t authType, const int return SUCCESS; } -uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector &challenge, - AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) +int32_t UserAuthService::StartAuth(int32_t apiVersion, Authentication::AuthenticationPara ¶, + std::shared_ptr &contextCallback, uint64_t &contextId) { IAM_LOGI("start"); - auto contextCallback = GetAuthContextCallback(apiVersion, challenge, authType, authTrustLevel, callback); + contextId = StartAuthContext(apiVersion, para, contextCallback, true); + if (contextId == BAD_CONTEXT_ID) { + IAM_LOGE("StartAuthContext fail"); + return GENERAL_ERROR; + } + return SUCCESS; +} + +int32_t UserAuthService::Auth(int32_t apiVersion, const IpcAuthParamInner &ipcAuthParamInner, + const sptr &userAuthCallback, uint64_t &contextId) +{ + IAM_LOGI("start"); + auto contextCallback = GetAuthContextCallback(apiVersion, ipcAuthParamInner.challenge, + static_cast(ipcAuthParamInner.authType), + static_cast(ipcAuthParamInner.authTrustLevel), userAuthCallback); if (contextCallback == nullptr) { IAM_LOGE("contextCallback is nullptr"); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } std::string callerName = ""; Attributes extraInfo; - int32_t callerType = Security::AccessToken::TOKEN_INVALID; - if ((!IpcCommon::GetCallerName(*this, callerName, callerType))) { + Authentication::AuthenticationPara para = {}; + if ((!IpcCommon::GetCallerName(*this, para.callerName, para.callerType))) { IAM_LOGE("get bundle name fail"); contextCallback->SetTraceAuthFinishReason("UserAuthService Auth GetCallerName fail"); contextCallback->OnResult(GENERAL_ERROR, extraInfo); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } - contextCallback->SetTraceCallerName(callerName); - contextCallback->SetTraceCallerType(callerType); - int32_t checkRet = CheckAuthPermissionAndParam(authType, callerType, callerName, authTrustLevel); + contextCallback->SetTraceCallerName(para.callerName); + contextCallback->SetTraceCallerType(para.callerType); + int32_t checkRet = CheckAuthPermissionAndParam(static_cast(ipcAuthParamInner.authType), para.callerType, + para.callerName, static_cast(ipcAuthParamInner.authTrustLevel)); if (checkRet != SUCCESS) { IAM_LOGE("check auth permission and param fail"); contextCallback->SetTraceAuthFinishReason("UserAuthService Auth CheckAuthPermissionAndParam fail"); contextCallback->OnResult(checkRet, extraInfo); - return BAD_CONTEXT_ID; + return checkRet; } int32_t userId = INVALID_USER_ID; if (IpcCommon::GetCallingUserId(*this, userId) != SUCCESS) { IAM_LOGE("get callingUserId failed"); contextCallback->SetTraceAuthFinishReason("UserAuthService Auth GetCallingUserId fail"); contextCallback->OnResult(GENERAL_ERROR, extraInfo); - return BAD_CONTEXT_ID; + return CHECK_PERMISSION_FAILED; } contextCallback->SetTraceUserId(userId); - Authentication::AuthenticationPara para = {}; para.tokenId = IpcCommon::GetAccessTokenId(*this); para.userId = userId; - para.authType = authType; - para.atl = authTrustLevel; - para.challenge = std::move(challenge); + para.authType = static_cast(ipcAuthParamInner.authType); + para.atl = static_cast(ipcAuthParamInner.authTrustLevel); + para.challenge = std::move(ipcAuthParamInner.challenge); para.endAfterFirstFail = true; - para.callerName = callerName; - para.callerType = callerType; para.sdkVersion = apiVersion; para.authIntent = AuthIntent::DEFAULT; para.isOsAccountVerified = IpcCommon::IsOsAccountVerified(userId); - return StartAuthContext(apiVersion, para, contextCallback, true); + return StartAuth(apiVersion, para, contextCallback, contextId); } uint64_t UserAuthService::StartAuthContext(int32_t apiVersion, Authentication::AuthenticationPara para, @@ -577,16 +604,48 @@ bool UserAuthService::CheckAuthPermissionAndParam(AuthType authType, AuthTrustLe return true; } -uint64_t UserAuthService::AuthUser(AuthParamInner &authParam, std::optional &remoteAuthParam, - sptr &callback) +int32_t UserAuthService::StartAuthUser(AuthParamInner &authParam, std::optional &remoteAuthParam, + Authentication::AuthenticationPara ¶, std::shared_ptr &contextCallback, uint64_t &contextId) +{ + Attributes extraInfo; + if (!remoteAuthParam.has_value()) { + bool needSubscribeAppState = !IpcCommon::CheckPermission(*this, USER_AUTH_FROM_BACKGROUND); + contextId = StartAuthContext(INNER_API_VERSION_10000, para, contextCallback, needSubscribeAppState); + if (contextId == BAD_CONTEXT_ID) { + IAM_LOGE("StartAuthContext fail"); + return GENERAL_ERROR; + } + return SUCCESS; + } + + ResultCode failReason = GENERAL_ERROR; + contextId = AuthRemoteUser(authParam, para, remoteAuthParam.value(), contextCallback, failReason); + if (contextId == BAD_CONTEXT_ID) { + contextCallback->SetTraceAuthFinishReason("UserAuthService AuthRemoteUser fail"); + contextCallback->OnResult(failReason, extraInfo); + return failReason; + } + + IAM_LOGI("success"); + return SUCCESS; +} + +int32_t UserAuthService::AuthUser(const IpcAuthParamInner &ipcAuthParamInner, + const IpcRemoteAuthParam &ipcRemoteAuthParam, const sptr &userAuthCallback, + uint64_t &contextId) { - IAM_LOGI("start, %{public}s", GetAuthParamStr(authParam, remoteAuthParam).c_str()); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); + contextId = BAD_CONTEXT_ID; + AuthParamInner authParam = {}; + std::optional remoteAuthParam = std::nullopt; + InitAuthParam(ipcAuthParamInner, authParam); + InitRemoteAuthParam(ipcRemoteAuthParam, remoteAuthParam); + IAM_LOGI("start, %{public}s", GetAuthParamStr(authParam, remoteAuthParam).c_str()); auto contextCallback = GetAuthContextCallback(INNER_API_VERSION_10000, authParam.challenge, authParam.authType, - authParam.authTrustLevel, callback); + authParam.authTrustLevel, userAuthCallback); if (contextCallback == nullptr) { IAM_LOGE("contextCallback is nullptr"); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } contextCallback->SetTraceIsRemoteAuth(remoteAuthParam.has_value()); contextCallback->SetTraceUserId(authParam.userId); @@ -596,13 +655,13 @@ uint64_t UserAuthService::AuthUser(AuthParamInner &authParam, std::optionalSetTraceAuthFinishReason("UserAuthService AuthUser GetCallerName fail"); contextCallback->OnResult(GENERAL_ERROR, extraInfo); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } contextCallback->SetTraceCallerName(para.callerName); contextCallback->SetTraceCallerType(para.callerType); if (CheckAuthPermissionAndParam(authParam.authType, authParam.authTrustLevel, contextCallback, extraInfo) == false) { - return BAD_CONTEXT_ID; + return CHECK_PERMISSION_FAILED; } para.tokenId = IpcCommon::GetAccessTokenId(*this); para.userId = authParam.userId; @@ -613,21 +672,7 @@ uint64_t UserAuthService::AuthUser(AuthParamInner &authParam, std::optionalSetTraceAuthFinishReason("UserAuthService AuthRemoteUser fail"); - contextCallback->OnResult(failReason, extraInfo); - return BAD_CONTEXT_ID; - } - - IAM_LOGI("success"); - return contextId; + return StartAuthUser(authParam, remoteAuthParam, para, contextCallback, contextId); } int32_t UserAuthService::DoPrepareRemoteAuth(const std::string &networkId) @@ -648,7 +693,8 @@ int32_t UserAuthService::DoPrepareRemoteAuth(const std::string &networkId) return SUCCESS; } -int32_t UserAuthService::PrepareRemoteAuthInner(const std::string &networkId, sptr &callback) +int32_t UserAuthService::PrepareRemoteAuthInner(const std::string &networkId, + const sptr &callback) { if (networkId.empty()) { IAM_LOGE("networkId is empty"); @@ -674,7 +720,7 @@ int32_t UserAuthService::PrepareRemoteAuthInner(const std::string &networkId, sp auto service = UserAuthService::GetInstance(); if (service == nullptr) { IAM_LOGE("service is nullptr"); - callback->OnResult(GENERAL_ERROR, attr); + callback->OnResult(GENERAL_ERROR, attr.Serialize()); return; } @@ -683,13 +729,14 @@ int32_t UserAuthService::PrepareRemoteAuthInner(const std::string &networkId, sp IAM_LOGE("failed to prepare remote auth"); } - callback->OnResult(ret, attr); + callback->OnResult(ret, attr.Serialize()); }); return SUCCESS; } -int32_t UserAuthService::PrepareRemoteAuth(const std::string &networkId, sptr &callback) +int32_t UserAuthService::PrepareRemoteAuth(const std::string &networkId, + const sptr &callback) { IAM_LOGI("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); @@ -702,7 +749,7 @@ int32_t UserAuthService::PrepareRemoteAuth(const std::string &networkId, sptrOnResult(ret, attr); + callback->OnResult(ret, attr.Serialize()); } IAM_LOGI("end"); @@ -768,46 +815,46 @@ uint64_t UserAuthService::AuthRemoteUser(AuthParamInner &authParam, Authenticati para, remoteAuthContextParam, contextCallback, dummyLastError); } -uint64_t UserAuthService::Identify(const std::vector &challenge, AuthType authType, - sptr &callback) +int32_t UserAuthService::Identify(const std::vector &challenge, int32_t authType, + const sptr &userAuthCallback, uint64_t &contextId) { IAM_LOGI("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - - if (callback == nullptr) { + contextId = BAD_CONTEXT_ID; + if (userAuthCallback == nullptr) { IAM_LOGE("callback is nullptr"); - return BAD_CONTEXT_ID; + return INVALID_PARAMETERS; } Attributes extraInfo; - auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY); + auto contextCallback = ContextCallback::NewInstance(userAuthCallback, TRACE_IDENTIFY); if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); - callback->OnResult(GENERAL_ERROR, extraInfo); - return BAD_CONTEXT_ID; + userAuthCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } - if (authType == PIN) { + if (static_cast(authType) == PIN) { IAM_LOGE("type not support %{public}d", authType); contextCallback->SetTraceAuthFinishReason("UserAuthService Identify IsAuthTypeEnable fail"); contextCallback->OnResult(TYPE_NOT_SUPPORT, extraInfo); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) { IAM_LOGE("failed to check permission"); contextCallback->SetTraceAuthFinishReason("UserAuthService Identify CheckPermission fail"); contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo); - return BAD_CONTEXT_ID; + return CHECK_PERMISSION_FAILED; } Identification::IdentificationPara para = {}; para.tokenId = IpcCommon::GetAccessTokenId(*this); - para.authType = authType; + para.authType = static_cast(authType); para.challenge = std::move(challenge); auto context = ContextFactory::CreateIdentifyContext(para, contextCallback); if (!ContextPool::Instance().Insert(context)) { IAM_LOGE("failed to insert context"); contextCallback->SetTraceAuthFinishReason("UserAuthService Identify insert context fail"); contextCallback->OnResult(GENERAL_ERROR, extraInfo); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } contextCallback->SetCleaner(ContextHelper::Cleaner(context)); @@ -816,14 +863,15 @@ uint64_t UserAuthService::Identify(const std::vector &challenge, AuthTy IAM_LOGE("failed to start identify"); contextCallback->SetTraceAuthFinishReason("UserAuthService Identify start context fail"); contextCallback->OnResult(context->GetLatestError(), extraInfo); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } - return context->GetContextId(); + contextId = context->GetContextId(); + return SUCCESS; } int32_t UserAuthService::CancelAuthOrIdentify(uint64_t contextId, int32_t cancelReason) { - IAM_LOGI("start"); + IAM_LOGD("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); bool checkRet = !IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION) && !IpcCommon::CheckPermission(*this, ACCESS_BIOMETRIC_PERMISSION); @@ -875,10 +923,11 @@ int32_t UserAuthService::CheckAuthWidgetType(const std::vector &authTy IAM_LOGE("invalid authType size:%{public}zu", authType.size()); return INVALID_PARAMETERS; } - for (auto &type : authType) { - if ((type != AuthType::PIN) && (type != AuthType::FACE) && (type != AuthType::FINGERPRINT) && - (type != AuthType::PRIVATE_PIN)) { - IAM_LOGE("unsupport auth type %{public}d", type); + const std::set WIDGET_AUTH_TYPE_VALID_SET = {AuthType::PIN, AuthType::FACE, AuthType::FINGERPRINT, + AuthType::PRIVATE_PIN}; + for (const auto &iter : authType) { + if (WIDGET_AUTH_TYPE_VALID_SET.find(iter) == WIDGET_AUTH_TYPE_VALID_SET.end()) { + IAM_LOGE("authType check fail:%{public}d", static_cast(iter)); return TYPE_NOT_SUPPORT; } } @@ -1165,15 +1214,47 @@ void UserAuthService::ProcessPinExpired(int32_t ret, const AuthParamInner &authP } } -uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback, - sptr &modalCallback) +int32_t UserAuthService::StartAuthWidget(AuthParamInner &authParam, WidgetParamInner &widgetParam, + ContextFactory::AuthWidgetContextPara ¶, std::shared_ptr &contextCallback, + const sptr &modalCallback, uint64_t &contextId) +{ + IAM_LOGI("start"); + Attributes extraInfo; + std::vector validType; + int32_t checkRet = CheckValidSolution(para.userId, authParam, widgetParam, validType); + if (checkRet != SUCCESS && checkRet != PIN_EXPIRED) { + IAM_LOGE("check valid solution failed"); + contextCallback->SetTraceAuthFinishReason("UserAuthService AuthWidget CheckValidSolution fail"); + contextCallback->OnResult(checkRet, extraInfo); + return checkRet; + } + ProcessPinExpired(checkRet, authParam, validType, para); + ProcessWidgetSessionExclusive(); + if (modalCallback != nullptr && widgetParam.hasContext) { + WidgetClient::Instance().SetModalCallback(modalCallback); + } + + contextId = StartWidgetContext(contextCallback, authParam, widgetParam, validType, para); + if (contextId == BAD_CONTEXT_ID) { + IAM_LOGE("StartWidgetContext fail"); + return GENERAL_ERROR; + } + return SUCCESS; +} + +int32_t UserAuthService::AuthWidget(int32_t apiVersion, const IpcAuthParamInner &ipcAuthParamInner, + const IpcWidgetParamInner &ipcWidgetParamInner, const sptr &userAuthCallback, + const sptr &modalCallback, uint64_t &contextId) { - IAM_LOGI("start %{public}d authTrustLevel:%{public}u", apiVersion, authParam.authTrustLevel); - auto contextCallback = GetAuthContextCallback(apiVersion, authParam, widgetParam, callback); + IAM_LOGI("start %{public}d authTrustLevel:%{public}u", apiVersion, ipcAuthParamInner.authTrustLevel); + AuthParamInner authParam = {}; + WidgetParamInner widgetParam = {}; + InitAuthParam(ipcAuthParamInner, authParam); + InitWidgetParam(ipcWidgetParamInner, widgetParam); + auto contextCallback = GetAuthContextCallback(apiVersion, authParam, widgetParam, userAuthCallback); if (contextCallback == nullptr) { IAM_LOGE("contextCallback is nullptr"); - return BAD_CONTEXT_ID; + return GENERAL_ERROR; } ContextFactory::AuthWidgetContextPara para; para.sdkVersion = apiVersion; @@ -1182,36 +1263,25 @@ uint64_t UserAuthService::AuthWidget(int32_t apiVersion, const AuthParamInner &a if (checkRet != SUCCESS) { contextCallback->SetTraceAuthFinishReason("UserAuthService AuthWidget GetCallerInfo fail"); contextCallback->OnResult(checkRet, extraInfo); - return BAD_CONTEXT_ID; + return checkRet; } checkRet = CheckAuthPermissionAndParam(authParam, widgetParam, para.isBackgroundApplication); if (checkRet != SUCCESS) { IAM_LOGE("check permission and auth widget param failed"); contextCallback->SetTraceAuthFinishReason("UserAuthService AuthWidget CheckAuthPermissionAndParam fail"); contextCallback->OnResult(checkRet, extraInfo); - return BAD_CONTEXT_ID; + return checkRet; } if (AuthWidgetHelper::CheckReuseUnlockResult(para, authParam, extraInfo) == SUCCESS) { IAM_LOGE("check reuse unlock result success"); contextCallback->SetTraceAuthFinishReason("UserAuthService AuthWidget CheckReuseUnlockResult success"); contextCallback->OnResult(SUCCESS, extraInfo); - return REUSE_AUTH_RESULT_CONTEXT_ID; - } - std::vector validType; - checkRet = CheckValidSolution(para.userId, authParam, widgetParam, validType); - if (checkRet != SUCCESS && checkRet != PIN_EXPIRED) { - IAM_LOGE("check valid solution failed"); - contextCallback->SetTraceAuthFinishReason("UserAuthService AuthWidget CheckValidSolution fail"); - contextCallback->OnResult(checkRet, extraInfo); - return BAD_CONTEXT_ID; - } - ProcessPinExpired(checkRet, authParam, validType, para); - ProcessWidgetSessionExclusive(); - if (modalCallback != nullptr && widgetParam.hasContext) { - WidgetClient::Instance().SetModalCallback(modalCallback); + contextId = REUSE_AUTH_RESULT_CONTEXT_ID; + return SUCCESS; } - return StartWidgetContext(contextCallback, authParam, widgetParam, validType, para); + + return StartAuthWidget(authParam, widgetParam, para, contextCallback, modalCallback, contextId); } void UserAuthService::ProcessWidgetSessionExclusive() @@ -1241,7 +1311,8 @@ bool UserAuthService::Insert2ContextPool(const std::shared_ptr &context } std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t apiVersion, - const AuthParamInner &authParam, const WidgetParamInner &widgetParam, sptr &callback) + const AuthParamInner &authParam, const WidgetParamInner &widgetParam, + const sptr &callback) { if (callback == nullptr) { IAM_LOGE("callback is nullptr"); @@ -1251,7 +1322,7 @@ std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); Attributes extraInfo; - callback->OnResult(ResultCode::GENERAL_ERROR, extraInfo); + callback->OnResult(ResultCode::GENERAL_ERROR, extraInfo.Serialize()); return nullptr; } contextCallback->SetTraceSdkVersion(apiVersion); @@ -1282,7 +1353,7 @@ std::shared_ptr UserAuthService::GetAuthContextCallback(int32_t return contextCallback; } -int32_t UserAuthService::Notice(NoticeType noticeType, const std::string &eventData) +int32_t UserAuthService::Notice(int32_t noticeType, const std::string &eventData) { IAM_LOGI("start"); if (!IpcCommon::CheckPermission(*this, IS_SYSTEM_APP)) { @@ -1294,10 +1365,10 @@ int32_t UserAuthService::Notice(NoticeType noticeType, const std::string &eventD IAM_LOGE("failed to check permission"); return ResultCode::CHECK_PERMISSION_FAILED; } - return WidgetClient::Instance().OnNotice(noticeType, eventData); + return WidgetClient::Instance().OnNotice(static_cast(noticeType), eventData); } -int32_t UserAuthService::RegisterWidgetCallback(int32_t version, sptr &callback) +int32_t UserAuthService::RegisterWidgetCallback(int32_t version, const sptr &widgetCallback) { if (!IpcCommon::CheckPermission(*this, IS_SYSTEM_APP)) { IAM_LOGE("the caller is not a system application"); @@ -1316,17 +1387,17 @@ int32_t UserAuthService::RegisterWidgetCallback(int32_t version, sptr authType) -{ - if (authType.empty()) { - return false; - } - for (const auto &iter : authType) { - if (iter != AuthType::PIN && iter != AuthType::FACE && iter != AuthType::FINGERPRINT && - iter != AuthType::PRIVATE_PIN) { - return false; - } - } - return true; -} - -int32_t UserAuthService::RegistUserAuthSuccessEventListener(const std::vector &authType, - const sptr &listener) +int32_t UserAuthService::RegistUserAuthSuccessEventListener(const sptr &listener) { IAM_LOGI("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS); - if (!CheckAuthTypeIsValid(authType)) { - IAM_LOGE("failed to check authType"); - return INVALID_PARAMETERS; - } - if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION)) { IAM_LOGE("failed to check permission"); return CHECK_PERMISSION_FAILED; } - int32_t result = AuthEventListenerManager::GetInstance().RegistUserAuthSuccessEventListener(authType, listener); + int32_t result = AuthEventListenerManager::GetInstance().RegistEventListener(listener); if (result != SUCCESS) { IAM_LOGE("failed to regist auth event listener"); return result; @@ -1405,8 +1456,7 @@ int32_t UserAuthService::RegistUserAuthSuccessEventListener(const std::vector &listener) +int32_t UserAuthService::UnRegistUserAuthSuccessEventListener(const sptr &listener) { IAM_LOGI("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); @@ -1417,7 +1467,7 @@ int32_t UserAuthService::UnRegistUserAuthSuccessEventListener( return CHECK_PERMISSION_FAILED; } - int32_t result = AuthEventListenerManager::GetInstance().UnRegistUserAuthSuccessEventListener(listener); + int32_t result = AuthEventListenerManager::GetInstance().UnRegistEventListener(listener); if (result != SUCCESS) { IAM_LOGE("failed to unregist auth event listener"); return result; @@ -1426,42 +1476,42 @@ int32_t UserAuthService::UnRegistUserAuthSuccessEventListener( return SUCCESS; } -int32_t UserAuthService::SetGlobalConfigParam(const GlobalConfigParam ¶m) +int32_t UserAuthService::SetGlobalConfigParam(const IpcGlobalConfigParam &ipcGlobalConfigParam) { IAM_LOGI("start, GlobalConfigType is %{public}d, userIds size %{public}zu, authTypes size %{public}zu", - param.type, param.userIds.size(), param.authTypes.size()); + ipcGlobalConfigParam.type, ipcGlobalConfigParam.userIds.size(), ipcGlobalConfigParam.authTypes.size()); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); if (!IpcCommon::CheckPermission(*this, ACCESS_USER_AUTH_INTERNAL_PERMISSION) || !IpcCommon::CheckPermission(*this, ENTERPRISE_DEVICE_MGR)) { IAM_LOGE("failed to check permission"); return CHECK_PERMISSION_FAILED; } - if (param.userIds.size() > MAX_USER || param.authTypes.size() > MAX_AUTH_TYPE_SIZE || - param.authTypes.size() == 0) { + if (ipcGlobalConfigParam.userIds.size() > MAX_USER || ipcGlobalConfigParam.authTypes.size() > MAX_AUTH_TYPE_SIZE || + ipcGlobalConfigParam.authTypes.size() == 0) { IAM_LOGE("bad global config param"); return INVALID_PARAMETERS; } HdiGlobalConfigParam paramConfig = {}; - switch (param.type) { + switch (static_cast(ipcGlobalConfigParam.type)) { case GlobalConfigType::PIN_EXPIRED_PERIOD: - if (param.authTypes.size() != 1 || param.authTypes[0] != PIN) { + if (ipcGlobalConfigParam.authTypes.size() != 1 || ipcGlobalConfigParam.authTypes[0] != PIN) { IAM_LOGE("bad authTypes for PIN_EXPIRED_PERIOD"); return INVALID_PARAMETERS; } - paramConfig.value.pinExpiredPeriod = param.value.pinExpiredPeriod; + paramConfig.value.pinExpiredPeriod = ipcGlobalConfigParam.value.pinExpiredPeriod; break; case GlobalConfigType::ENABLE_STATUS: - paramConfig.value.enableStatus = param.value.enableStatus; + paramConfig.value.enableStatus = ipcGlobalConfigParam.value.enableStatus; break; default: IAM_LOGE("bad global config type"); return INVALID_PARAMETERS; } - paramConfig.type = static_cast(param.type); - paramConfig.userIds = param.userIds; - for (const auto authType : param.authTypes) { - paramConfig.authTypes.push_back(authType); + paramConfig.type = static_cast(ipcGlobalConfigParam.type); + paramConfig.userIds = ipcGlobalConfigParam.userIds; + for (const auto authType : ipcGlobalConfigParam.authTypes) { + paramConfig.authTypes.push_back(static_cast(authType)); } auto hdi = HdiWrapper::GetHdiInstance(); if (hdi == nullptr) { @@ -1558,36 +1608,36 @@ bool UserAuthService::GetAuthTokenAttr(const HdiUserAuthTokenPlain &tokenPlain, return true; } -void UserAuthService::VerifyAuthToken(const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback) +int32_t UserAuthService::VerifyAuthToken(const std::vector &tokenIn, uint64_t allowableDuration, + const sptr &verifyTokenCallback) { IAM_LOGI("start, duration:%{public}" PRIu64 ", tokenIn size:%{public}zu.", allowableDuration, tokenIn.size()); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(verifyTokenCallback != nullptr, INVALID_PARAMETERS); Attributes extraInfo; if (tokenIn.size() == 0 || tokenIn.data() == nullptr || allowableDuration > MAX_TOKEN_ALLOWABLE_DURATION) { IAM_LOGE("bad parameter"); - callback->OnVerifyTokenResult(INVALID_PARAMETERS, extraInfo); - return; + verifyTokenCallback->OnVerifyTokenResult(INVALID_PARAMETERS, extraInfo.Serialize()); + return INVALID_PARAMETERS; } if (!IpcCommon::CheckPermission(*this, USE_USER_ACCESS_MANAGER)) { IAM_LOGE("failed to check permission"); - callback->OnVerifyTokenResult(CHECK_PERMISSION_FAILED, extraInfo); - return; + verifyTokenCallback->OnVerifyTokenResult(CHECK_PERMISSION_FAILED, extraInfo.Serialize()); + return CHECK_PERMISSION_FAILED; } if (IpcCommon::GetDirectCallerType(*this) != Security::AccessToken::TOKEN_NATIVE && !IpcCommon::CheckPermission(*this, IS_SYSTEM_APP)) { IAM_LOGE("caller is not systemApp."); - callback->OnVerifyTokenResult(CHECK_SYSTEM_APP_FAILED, extraInfo); - return; + verifyTokenCallback->OnVerifyTokenResult(CHECK_SYSTEM_APP_FAILED, extraInfo.Serialize()); + return CHECK_SYSTEM_APP_FAILED; } auto hdi = HdiWrapper::GetHdiInstance(); if (hdi == nullptr) { IAM_LOGE("hdi interface is nullptr"); - callback->OnVerifyTokenResult(GENERAL_ERROR, extraInfo); - return; + verifyTokenCallback->OnVerifyTokenResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } HdiUserAuthTokenPlain tokenPlain = {}; @@ -1595,15 +1645,74 @@ void UserAuthService::VerifyAuthToken(const std::vector &tokenIn, uint6 int32_t result = hdi->VerifyAuthToken(tokenIn, allowableDuration, tokenPlain, rootSecret); if (result != SUCCESS) { IAM_LOGE("VerifyAuthToken failed result:%{public}d", result); - callback->OnVerifyTokenResult(result, extraInfo); - return; + verifyTokenCallback->OnVerifyTokenResult(result, extraInfo.Serialize()); + return result; } if (!GetAuthTokenAttr(tokenPlain, rootSecret, extraInfo)) { IAM_LOGE("GetAuthTokenAttr failed"); - callback->OnVerifyTokenResult(GENERAL_ERROR, extraInfo); - return; + verifyTokenCallback->OnVerifyTokenResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } - callback->OnVerifyTokenResult(SUCCESS, extraInfo); + verifyTokenCallback->OnVerifyTokenResult(SUCCESS, extraInfo.Serialize()); + return SUCCESS; +} + +void UserAuthService::InitAuthParam(const IpcAuthParamInner &ipcAuthParam, AuthParamInner &authParam) +{ + authParam.userId = ipcAuthParam.userId; + authParam.isUserIdSpecified = ipcAuthParam.isUserIdSpecified; + authParam.challenge = ipcAuthParam.challenge; + authParam.authType = static_cast(ipcAuthParam.authType); + authParam.authTypes.resize(ipcAuthParam.authTypes.size()); + std::transform(ipcAuthParam.authTypes.begin(), ipcAuthParam.authTypes.end(), + authParam.authTypes.begin(), [](int32_t authType) { + return static_cast(authType); + }); + authParam.authTrustLevel = static_cast(ipcAuthParam.authTrustLevel); + authParam.authIntent = static_cast(ipcAuthParam.authIntent); + authParam.reuseUnlockResult.isReuse = ipcAuthParam.reuseUnlockResult.isReuse; + authParam.reuseUnlockResult.reuseMode = static_cast(ipcAuthParam.reuseUnlockResult.reuseMode); + authParam.reuseUnlockResult.reuseDuration = ipcAuthParam.reuseUnlockResult.reuseDuration; +} + +void UserAuthService::InitRemoteAuthParam(const IpcRemoteAuthParam &ipcRemoteAuthParam, + std::optional &remoteAuthParam) +{ + if (ipcRemoteAuthParam.isHasRemoteAuthParam) { + remoteAuthParam = RemoteAuthParam{}; + remoteAuthParam->verifierNetworkId = std::nullopt; + remoteAuthParam->collectorNetworkId = std::nullopt; + remoteAuthParam->collectorTokenId = std::nullopt; + if (ipcRemoteAuthParam.isHasVerifierNetworkId) { + remoteAuthParam->verifierNetworkId = ipcRemoteAuthParam.verifierNetworkId; + } + if (ipcRemoteAuthParam.isHasCollectorNetworkId) { + remoteAuthParam->collectorNetworkId = ipcRemoteAuthParam.collectorNetworkId; + } + if (ipcRemoteAuthParam.isHasCollectorTokenId) { + remoteAuthParam->collectorTokenId = ipcRemoteAuthParam.collectorTokenId; + } + } +} + +void UserAuthService::InitWidgetParam(const IpcWidgetParamInner &ipcWidgetParam, WidgetParamInner &widgetParam) +{ + widgetParam.title = ipcWidgetParam.title; + widgetParam.navigationButtonText = ipcWidgetParam.navigationButtonText; + widgetParam.windowMode = static_cast(ipcWidgetParam.windowMode); + widgetParam.hasContext = ipcWidgetParam.hasContext; +} + +int32_t UserAuthService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t UserAuthService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/services/ipc/src/user_idm_service.cpp b/services/ipc/src/user_idm_service.cpp index c3fd36b56a60bc60cca9bf078903e0929785cb67..87fdae505336345d5f616ebccd96c60d29f0a996 100644 --- a/services/ipc/src/user_idm_service.cpp +++ b/services/ipc/src/user_idm_service.cpp @@ -21,7 +21,9 @@ #include "context_appstate_observer.h" #include "context_helper.h" #include "context_pool.h" +#include "event_listener_manager.h" #include "hdi_wrapper.h" +#include "iam_callback_proxy.h" #include "iam_check.h" #include "iam_logger.h" #include "iam_para2str.h" @@ -35,7 +37,6 @@ #include "resource_node_pool.h" #include "resource_node_utils.h" #include "service_init_manager.h" -#include "user_idm_callback_proxy.h" #include "user_idm_database.h" #include "user_idm_session_controller.h" #include "xcollie_helper.h" @@ -47,7 +48,8 @@ namespace UserIam { namespace UserAuth { REGISTER_SYSTEM_ABILITY_BY_ID(UserIdmService, SUBSYS_USERIAM_SYS_ABILITY_USERIDM, true); constexpr int32_t USERIAM_IPC_THREAD_NUM = 4; -UserIdmService::UserIdmService(int32_t systemAbilityId, bool runOnCreate) : SystemAbility(systemAbilityId, runOnCreate) +UserIdmService::UserIdmService(int32_t systemAbilityId, bool runOnCreate) + : SystemAbility(systemAbilityId, runOnCreate), UserIdmStub(true) { } @@ -93,24 +95,26 @@ int32_t UserIdmService::OpenSession(int32_t userId, std::vector &challe return SUCCESS; } -void UserIdmService::CloseSession(int32_t userId) +int32_t UserIdmService::CloseSession(int32_t userId) { IAM_LOGI("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) { IAM_LOGE("failed to check permission"); - return; + return CHECK_PERMISSION_FAILED; } if (!UserIdmSessionController::Instance().CloseSession(userId)) { IAM_LOGE("failed to get close session"); + return GENERAL_ERROR; } + return SUCCESS; } int32_t UserIdmService::GetCredentialInfoInner(int32_t userId, AuthType authType, std::vector &credInfoList) { - IAM_LOGI("start"); + IAM_LOGD("start"); if (!IpcCommon::CheckPermission(*this, USE_USER_IDM_PERMISSION)) { IAM_LOGE("failed to check permission"); return CHECK_PERMISSION_FAILED; @@ -143,8 +147,8 @@ int32_t UserIdmService::GetCredentialInfoInner(int32_t userId, AuthType authType return SUCCESS; } -int32_t UserIdmService::GetCredentialInfo(int32_t userId, AuthType authType, - const sptr &callback) +int32_t UserIdmService::GetCredentialInfo(int32_t userId, int32_t authType, + const sptr &callback) { Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); if (callback == nullptr) { @@ -152,14 +156,27 @@ int32_t UserIdmService::GetCredentialInfo(int32_t userId, AuthType authType, return INVALID_PARAMETERS; } + std::vector ipcCredInfoList; std::vector credInfoList; - int32_t ret = GetCredentialInfoInner(userId, authType, credInfoList); + int32_t ret = GetCredentialInfoInner(userId, static_cast(authType), credInfoList); if (ret != SUCCESS) { IAM_LOGE("GetCredentialInfoInner fail, ret: %{public}d", ret); credInfoList.clear(); } - callback->OnCredentialInfos(ret, credInfoList); + + for (auto &iter : credInfoList) { + IpcCredentialInfo ipcCredInfo; + ipcCredInfo.authType = static_cast(iter.authType); + ipcCredInfo.pinType = static_cast(iter.pinType.value_or(PIN_SIX)); + ipcCredInfo.credentialId = iter.credentialId; + ipcCredInfo.templateId = iter.templateId; + ipcCredInfoList.push_back(ipcCredInfo); + } + auto retCode = callback->OnCredentialInfos(ret, ipcCredInfoList); + if (retCode != SUCCESS) { + IAM_LOGE("OnCredentialInfos fail, ret: %{public}d", retCode); + } return ret; } @@ -193,7 +210,7 @@ int32_t UserIdmService::GetSecInfoInner(int32_t userId, SecUserInfo &secUserInfo return SUCCESS; } -int32_t UserIdmService::GetSecInfo(int32_t userId, const sptr &callback) +int32_t UserIdmService::GetSecInfo(int32_t userId, const sptr &callback) { Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); if (callback == nullptr) { @@ -201,6 +218,7 @@ int32_t UserIdmService::GetSecInfo(int32_t userId, const sptrOnSecureUserInfo(ret, secUserInfo); + for (auto &iter : secUserInfo.enrolledInfo) { + IpcEnrolledInfo ipcEnrolledInfo; + ipcEnrolledInfo.authType = static_cast(iter.authType); + ipcEnrolledInfo.enrolledId = iter.enrolledId; + ipcSecUserInfo.enrolledInfo.push_back(ipcEnrolledInfo); + } + ipcSecUserInfo.secureUid = secUserInfo.secureUid; + auto retCode = callback->OnSecureUserInfo(ret, ipcSecUserInfo); + if (retCode != SUCCESS) { + IAM_LOGE("OnSecureUserInfo fail, ret: %{public}d", retCode); + } return ret; } -void UserIdmService::StartEnroll(Enrollment::EnrollmentPara ¶, +int32_t UserIdmService::StartEnroll(Enrollment::EnrollmentPara ¶, const std::shared_ptr &contextCallback, Attributes &extraInfo, bool needSubscribeAppState) { + if (!para.isUpdate && para.authType == PIN && !para.token.empty()) { + IAM_LOGI("auth type is pin, clear token"); + para.token.clear(); + } + auto context = ContextFactory::CreateEnrollContext(para, contextCallback, needSubscribeAppState); if (context == nullptr || !ContextPool::Instance().Insert(context)) { IAM_LOGE("failed to insert context"); contextCallback->OnResult(GENERAL_ERROR, extraInfo); - return; + return GENERAL_ERROR; } contextCallback->SetTraceRequestContextId(context->GetContextId()); auto cleaner = ContextHelper::Cleaner(context); @@ -229,22 +262,24 @@ void UserIdmService::StartEnroll(Enrollment::EnrollmentPara ¶, if (!context->Start()) { IAM_LOGE("failed to start enroll"); contextCallback->OnResult(context->GetLatestError(), extraInfo); + return GENERAL_ERROR; } + return SUCCESS; } -void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback, bool isUpdate) +int32_t UserIdmService::AddCredential(int32_t userId, const IpcCredentialPara &ipcCredentialPara, + const sptr &idmCallback, bool isUpdate) { Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(idmCallback != nullptr, INVALID_PARAMETERS); Attributes extraInfo; - auto contextCallback = ContextCallback::NewInstance(callback, + auto contextCallback = ContextCallback::NewInstance(idmCallback, isUpdate ? TRACE_UPDATE_CREDENTIAL : TRACE_ADD_CREDENTIAL); if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); - callback->OnResult(GENERAL_ERROR, extraInfo); - return; + idmCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } std::string callerName = ""; int32_t callerType = Security::AccessToken::TOKEN_INVALID; @@ -252,56 +287,58 @@ void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPar contextCallback->SetTraceCallerName(callerName); contextCallback->SetTraceCallerType(callerType); contextCallback->SetTraceUserId(userId); - contextCallback->SetTraceAuthType(credPara.authType); + contextCallback->SetTraceAuthType(static_cast(ipcCredentialPara.authType)); if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) { IAM_LOGE("failed to check permission"); contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo); - return; + return CHECK_PERMISSION_FAILED; } std::lock_guard lock(mutex_); CancelCurrentEnrollIfExist(); Enrollment::EnrollmentPara para = {}; - para.authType = credPara.authType; + para.authType = static_cast(ipcCredentialPara.authType); para.userId = userId; - para.pinType = credPara.pinType; + para.pinType = static_cast(ipcCredentialPara.pinType); para.tokenId = IpcCommon::GetAccessTokenId(*this); - para.token = credPara.token; + para.token = ipcCredentialPara.token; para.isUpdate = isUpdate; para.sdkVersion = INNER_API_VERSION_10000; para.callerName = callerName; para.callerType = callerType; bool needSubscribeAppState = !IpcCommon::CheckPermission(*this, USER_AUTH_FROM_BACKGROUND); - StartEnroll(para, contextCallback, extraInfo, needSubscribeAppState); + return StartEnroll(para, contextCallback, extraInfo, needSubscribeAppState); } -void UserIdmService::UpdateCredential(int32_t userId, const CredentialPara &credPara, - const sptr &callback) +int32_t UserIdmService::UpdateCredential(int32_t userId, const IpcCredentialPara &ipcCredentialPara, + const sptr &idmCallback) { Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - if (callback == nullptr) { + if (idmCallback == nullptr) { IAM_LOGE("callback is nullptr"); - return; + return INVALID_PARAMETERS; } std::vector> credInfos; - int32_t ret = UserIdmDatabase::Instance().GetCredentialInfo(userId, credPara.authType, credInfos); + int32_t ret = UserIdmDatabase::Instance().GetCredentialInfo(userId, + static_cast(ipcCredentialPara.authType), credInfos); if (ret != SUCCESS) { - IAM_LOGE("get credential fail, ret:%{public}d, userId:%{public}d, authType:%{public}d", ret, - userId, credPara.authType); + IAM_LOGE("get credential fail, ret:%{public}d, userId:%{public}d, authType:%{public}d", + ret, userId, ipcCredentialPara.authType); Attributes extraInfo; - callback->OnResult(GENERAL_ERROR, extraInfo); - return; + idmCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } if (credInfos.empty()) { - IAM_LOGE("current userid %{public}d has no credential for type %{public}u", userId, credPara.authType); + IAM_LOGE("current userid %{public}d has no credential for type %{public}u", + userId, ipcCredentialPara.authType); Attributes extraInfo; - callback->OnResult(NOT_ENROLLED, extraInfo); - return; + idmCallback->OnResult(NOT_ENROLLED, extraInfo.Serialize()); + return SUCCESS; } - AddCredential(userId, credPara, callback, true); + return AddCredential(userId, ipcCredentialPara, idmCallback, true); } int32_t UserIdmService::Cancel(int32_t userId) @@ -347,17 +384,17 @@ int32_t UserIdmService::CancelCurrentEnroll() return ret; } -int32_t UserIdmService::EnforceDelUser(int32_t userId, const sptr &callback) +int32_t UserIdmService::EnforceDelUser(int32_t userId, const sptr &idmCallback) { IAM_LOGI("to delete userid: %{public}d", userId); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, INVALID_PARAMETERS); + IF_FALSE_LOGE_AND_RETURN_VAL(idmCallback != nullptr, INVALID_PARAMETERS); Attributes extraInfo; - auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ENFORCE_DELETE_USER); + auto contextCallback = ContextCallback::NewInstance(idmCallback, TRACE_ENFORCE_DELETE_USER); if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); - callback->OnResult(GENERAL_ERROR, extraInfo); + idmCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); return GENERAL_ERROR; } std::string callerName = ""; @@ -400,18 +437,18 @@ int32_t UserIdmService::EnforceDelUser(int32_t userId, const sptr authToken, - const sptr &callback) +int32_t UserIdmService::DelUser(int32_t userId, const std::vector &authToken, + const sptr &idmCallback) { Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(idmCallback != nullptr, INVALID_PARAMETERS); Attributes extraInfo; - auto contextCallback = ContextCallback::NewInstance(callback, TRACE_DELETE_USER); + auto contextCallback = ContextCallback::NewInstance(idmCallback, TRACE_DELETE_USER); if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); - callback->OnResult(GENERAL_ERROR, extraInfo); - return; + idmCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } std::string callerName = ""; int32_t callerType = Security::AccessToken::TOKEN_INVALID; @@ -423,7 +460,7 @@ void UserIdmService::DelUser(int32_t userId, const std::vector authToke if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) { IAM_LOGE("failed to check permission"); contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo); - return; + return CHECK_PERMISSION_FAILED; } std::lock_guard lock(mutex_); @@ -435,13 +472,13 @@ void UserIdmService::DelUser(int32_t userId, const std::vector authToke if (ret != SUCCESS) { IAM_LOGE("failed to delete user"); contextCallback->OnResult(ret, extraInfo); - return; + return ret; } ContextAppStateObserverManager::GetInstance().RemoveScreenLockState(userId); if (!extraInfo.SetUint8ArrayValue(Attributes::ATTR_OLD_ROOT_SECRET, rootSecret)) { IAM_LOGE("set rootsecret to extraInfo failed"); contextCallback->OnResult(ret, extraInfo); - return; + return ret; } SetAuthTypeTrace(credInfos, contextCallback); contextCallback->OnResult(ret, extraInfo); @@ -453,20 +490,22 @@ void UserIdmService::DelUser(int32_t userId, const std::vector authToke IAM_LOGI("delete user end"); PublishEventAdapter::GetInstance().PublishDeletedEvent(userId); PublishEventAdapter::GetInstance().PublishCredentialUpdatedEvent(userId, PIN, 0); + CredChangeEventListenerManager::GetInstance().OnNotifyCredChangeEvent(userId, PIN, DEL_USER, 0); + return SUCCESS; } -void UserIdmService::DelCredential(int32_t userId, uint64_t credentialId, - const std::vector &authToken, const sptr &callback) +int32_t UserIdmService::DelCredential(int32_t userId, uint64_t credentialId, + const std::vector &authToken, const sptr &idmCallback) { Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(idmCallback != nullptr, INVALID_PARAMETERS); Attributes extraInfo; - auto contextCallback = ContextCallback::NewInstance(callback, TRACE_DELETE_CREDENTIAL); + auto contextCallback = ContextCallback::NewInstance(idmCallback, TRACE_DELETE_CREDENTIAL); if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); - callback->OnResult(GENERAL_ERROR, extraInfo); - return; + idmCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } std::string callerName = ""; int32_t callerType = Security::AccessToken::TOKEN_INVALID; @@ -478,7 +517,7 @@ void UserIdmService::DelCredential(int32_t userId, uint64_t credentialId, if (!IpcCommon::CheckPermission(*this, MANAGE_USER_IDM_PERMISSION)) { IAM_LOGE("failed to check permission"); contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo); - return; + return CHECK_PERMISSION_FAILED; } std::lock_guard lock(mutex_); @@ -489,7 +528,7 @@ void UserIdmService::DelCredential(int32_t userId, uint64_t credentialId, if (ret != SUCCESS) { IAM_LOGE("failed to delete CredentialInfo"); contextCallback->OnResult(ret, extraInfo); - return; + return ret; } if (oldInfo != nullptr) { contextCallback->SetTraceAuthType(oldInfo->GetAuthType()); @@ -506,6 +545,8 @@ void UserIdmService::DelCredential(int32_t userId, uint64_t credentialId, if (oldInfo != nullptr) { PublishCommonEvent(userId, credentialId, oldInfo->GetAuthType()); } + + return SUCCESS; } int UserIdmService::Dump(int fd, const std::vector &args) @@ -588,6 +629,7 @@ int32_t UserIdmService::EnforceDelUserInner(int32_t userId, std::shared_ptr &callback) +int32_t UserIdmService::ClearRedundancyCredential(const sptr &idmCallback) { IAM_LOGI("start"); Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); - IF_FALSE_LOGE_AND_RETURN(callback != nullptr); + IF_FALSE_LOGE_AND_RETURN_VAL(idmCallback != nullptr, INVALID_PARAMETERS); Attributes extraInfo; - auto contextCallback = ContextCallback::NewInstance(callback, TRACE_DELETE_REDUNDANCY); + auto contextCallback = ContextCallback::NewInstance(idmCallback, TRACE_DELETE_REDUNDANCY); if (contextCallback == nullptr) { IAM_LOGE("failed to construct context callback"); - callback->OnResult(GENERAL_ERROR, extraInfo); - return; + idmCallback->OnResult(GENERAL_ERROR, extraInfo.Serialize()); + return GENERAL_ERROR; } std::string callerName = ""; @@ -658,7 +700,7 @@ void UserIdmService::ClearRedundancyCredential(const sptr if (!IpcCommon::CheckPermission(*this, CLEAR_REDUNDANCY_PERMISSION)) { IAM_LOGE("failed to check permission"); contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo); - return; + return CHECK_PERMISSION_FAILED; } std::lock_guard lock(mutex_); @@ -669,6 +711,37 @@ void UserIdmService::ClearRedundancyCredential(const sptr IAM_LOGE("clearRedundancyCredentialInner fail, ret:%{public}d, ", ret); } contextCallback->OnResult(ret, extraInfo); + return ret; +} + +int32_t UserIdmService::GetCredentialInfoSync(int32_t userId, int32_t authType, + std::vector &ipcCredentialInfoList) +{ + IAM_LOGI("start"); + Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); + std::vector credentialInfoList; + int32_t ret = GetCredentialInfoInner(userId, static_cast(authType), credentialInfoList); + if (ret == NOT_ENROLLED) { + credentialInfoList.clear(); + ret = SUCCESS; + } + + if (ret != SUCCESS) { + IAM_LOGE("GetCredentialInfoInner fail, ret: %{public}d", ret); + credentialInfoList.clear(); + } + + for (auto &iter : credentialInfoList) { + IpcCredentialInfo ipcCredInfo; + ipcCredInfo.authType = static_cast(iter.authType); + ipcCredInfo.pinType = static_cast(iter.pinType.value_or(PIN_SIX)); + ipcCredInfo.credentialId = iter.credentialId; + ipcCredInfo.templateId = iter.templateId; + ipcCredentialInfoList.push_back(ipcCredInfo); + } + + IAM_LOGI("GetCredentialInfoSync success, credential num:%{public}zu", ipcCredentialInfoList.size()); + return ret; } void UserIdmService::PublishCommonEvent(int32_t userId, uint64_t credentialId, AuthType authType) @@ -681,6 +754,61 @@ void UserIdmService::PublishCommonEvent(int32_t userId, uint64_t credentialId, A } PublishEventAdapter::GetInstance().PublishCredentialUpdatedEvent(userId, authType, credentialInfos.size()); PublishEventAdapter::GetInstance().PublishUpdatedEvent(userId, credentialId); + if (authType != PIN) { + CredChangeEventListenerManager::GetInstance().OnNotifyCredChangeEvent( + userId, authType, DEL_CRED, credentialId); + } +} + +int32_t UserIdmService::RegistCredChangeEventListener(const sptr &listener) +{ + IAM_LOGI("start"); + Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); + IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS); + + if (!IpcCommon::CheckPermission(*this, USE_USER_IDM_PERMISSION)) { + IAM_LOGE("failed to check permission"); + return CHECK_PERMISSION_FAILED; + } + + int32_t result = CredChangeEventListenerManager::GetInstance().RegistEventListener(listener); + if (result != SUCCESS) { + IAM_LOGE("failed to regist cred change event listener"); + return result; + } + + return SUCCESS; +} + +int32_t UserIdmService::UnRegistCredChangeEventListener(const sptr &listener) +{ + IAM_LOGI("start"); + Common::XCollieHelper xcollie(__FUNCTION__, Common::API_CALL_TIMEOUT); + IF_FALSE_LOGE_AND_RETURN_VAL(listener != nullptr, INVALID_PARAMETERS); + + if (!IpcCommon::CheckPermission(*this, USE_USER_IDM_PERMISSION)) { + IAM_LOGE("failed to check permission"); + return CHECK_PERMISSION_FAILED; + } + + int32_t result = CredChangeEventListenerManager::GetInstance().UnRegistEventListener(listener); + if (result != SUCCESS) { + IAM_LOGE("failed to unregist cred change event listener"); + return result; + } + return SUCCESS; +} + +int32_t UserIdmService::CallbackEnter([[maybe_unused]] uint32_t code) +{ + IAM_LOGI("start, code:%{public}u", code); + return SUCCESS; +} + +int32_t UserIdmService::CallbackExit([[maybe_unused]] uint32_t code, [[maybe_unused]] int32_t result) +{ + IAM_LOGI("leave, code:%{public}u, result:%{public}d", code, result); + return SUCCESS; } } // namespace UserAuth } // namespace UserIam diff --git a/services/load_mode/inc/load_mode_handler_dynamic.h b/services/load_mode/inc/load_mode_handler_dynamic.h index c5ea3760913a27d915c3a8b3d35de0da98ffce65..f511a5e7329f8dfe8ddd7cb13f23bcdca95549ae 100644 --- a/services/load_mode/inc/load_mode_handler_dynamic.h +++ b/services/load_mode/inc/load_mode_handler_dynamic.h @@ -52,8 +52,8 @@ public: void SubscribeCommonEventServiceListener(); private: - bool AnyUserHasPinCredential(); - void RefreshIsPinEnrolled(); + std::optional AnyUserHasPinCredential(); + void RefreshIsPinEnrolled(bool shouldReportBigData); void RefreshIsPinFunctionReady(); bool isSubscribed_ = false; diff --git a/services/load_mode/src/driver_load_manager.cpp b/services/load_mode/src/driver_load_manager.cpp index d6a100c5b8d247011c77534c2fb59740b78a271f..a80f94a416c36746e892b7996ffa260feadea15d 100644 --- a/services/load_mode/src/driver_load_manager.cpp +++ b/services/load_mode/src/driver_load_manager.cpp @@ -15,6 +15,7 @@ #include "driver_load_manager.h" +#include "hisysevent_adapter.h" #include "idevmgr_hdi.h" #include "iam_check.h" @@ -97,6 +98,9 @@ bool DriverLoadManager::LoadDriver() int32_t loadDriverRet = devMgr->LoadDevice(SERVICE_NAME); if (loadDriverRet != 0) { IAM_LOGE("load %{public}s service failed, ret:%{public}d", SERVICE_NAME, loadDriverRet); + SaLoadDriverFailureTrace saLoadDriverFailureTraceInfo = {}; + saLoadDriverFailureTraceInfo.errCode = loadDriverRet; + UserIam::UserAuth::ReportSaLoadDriverFailure(saLoadDriverFailureTraceInfo); return false; } return true; diff --git a/services/load_mode/src/load_mode_handler_dynamic.cpp b/services/load_mode/src/load_mode_handler_dynamic.cpp index 617bd9b60e2c3584086e1446fdccb34b3b92a872..cab96a49ff72ce52fbb2c0b81f90cffd50aa814d 100644 --- a/services/load_mode/src/load_mode_handler_dynamic.cpp +++ b/services/load_mode/src/load_mode_handler_dynamic.cpp @@ -19,7 +19,7 @@ #include "driver_load_manager.h" #include "driver_state_manager.h" -#include "iam_logger.h" +#include "hisysevent_adapter.h" #include "os_account_manager.h" #include "relative_timer.h" #include "service_unload_manager.h" @@ -109,6 +109,7 @@ void LoadModeHandlerDynamic::OnCommonEventSaStart() void LoadModeHandlerDynamic::StartSubscribe() { + IAM_LOGI("start"); std::lock_guard lock(mutex_); if (isSubscribed_) { return; @@ -126,14 +127,14 @@ void LoadModeHandlerDynamic::StartSubscribe() IF_FALSE_LOGE_AND_RETURN(pinAuthServiceListener_ != nullptr); - IAM_LOGI("init load mode handler dynamic success"); isSubscribed_ = true; + IAM_LOGI("start subscribe success"); } void LoadModeHandlerDynamic::OnFwkReady() { IAM_LOGI("fwk ready"); - RefreshIsPinEnrolled(); + RefreshIsPinEnrolled(true); SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, TRUE_STR); bool isStopSa = false; ServiceUnloadManager::GetInstance().OnFwkReady(isStopSa); @@ -206,16 +207,16 @@ void LoadModeHandlerDynamic::OnCredentialUpdated(AuthType authType) return; } IAM_LOGI("on credential updated authType %{public}d", authType); - RefreshIsPinEnrolled(); + RefreshIsPinEnrolled(false); } -bool LoadModeHandlerDynamic::AnyUserHasPinCredential() +std::optional LoadModeHandlerDynamic::AnyUserHasPinCredential() { std::vector osAccountInfo; ErrCode errCode = AccountSA::OsAccountManager::QueryAllCreatedOsAccounts(osAccountInfo); if (errCode != ERR_OK) { IAM_LOGE("QueryAllCreatedOsAccounts fail, errCode = %{public}d", errCode); - return false; + return std::nullopt; } for (auto &info : osAccountInfo) { @@ -225,6 +226,9 @@ bool LoadModeHandlerDynamic::AnyUserHasPinCredential() if (getCredRet != SUCCESS) { // it's possible that the user has no credential IAM_LOGI("failed to get credential info ret %{public}d", getCredRet); + if (getCredRet == INVALID_HDI_INTERFACE) { + return std::nullopt; + } continue; } @@ -237,11 +241,29 @@ bool LoadModeHandlerDynamic::AnyUserHasPinCredential() return false; } -void LoadModeHandlerDynamic::RefreshIsPinEnrolled() +void LoadModeHandlerDynamic::RefreshIsPinEnrolled(bool shouldReportBigData) { std::lock_guard lock(mutex_); - isPinEnrolled_ = AnyUserHasPinCredential(); + auto ret = AnyUserHasPinCredential(); + if (!ret.has_value()) { + IAM_LOGE("fail to refresh isPinEnrolled"); + return; + } + + isPinEnrolled_ = *ret; IAM_LOGI("is pin enrolled %{public}s", isPinEnrolled_ ? TRUE_STR : FALSE_STR); + if (shouldReportBigData) { + bool isPinEnrolled = SystemParamManager::GetInstance().GetParam(IS_PIN_ENROLLED_KEY, FALSE_STR) == TRUE_STR; + if (isPinEnrolled_ != isPinEnrolled) { + bool preStatus = isPinEnrolled; + bool updatedStatus = isPinEnrolled_; + IsCredentialEnrolledMismatchTrace isCredentialEnrolledMismatchTraceInfo = {}; + isCredentialEnrolledMismatchTraceInfo.authType = AuthType::PIN; + isCredentialEnrolledMismatchTraceInfo.preStatus = preStatus; + isCredentialEnrolledMismatchTraceInfo.updatedStatus = updatedStatus; + UserIam::UserAuth::ReportIsCredentialEnrolledMismatch(isCredentialEnrolledMismatchTraceInfo); + } + } SystemParamManager::GetInstance().SetParam(IS_PIN_ENROLLED_KEY, isPinEnrolled_ ? TRUE_STR : FALSE_STR); } diff --git a/services/load_mode/src/service_unload_manager.cpp b/services/load_mode/src/service_unload_manager.cpp index e44116743313bbae17311f785efb05b10d099742..44659612be21ca736e072c599928ae7ff16e75ae 100644 --- a/services/load_mode/src/service_unload_manager.cpp +++ b/services/load_mode/src/service_unload_manager.cpp @@ -150,6 +150,7 @@ void ServiceUnloadManager::OnFwkReady(bool &isStopSa) { std::lock_guard lock(mutex_); isStopSa = false; + isPinEnrolled_ = SystemParamManager::GetInstance().GetParam(IS_PIN_ENROLLED_KEY, FALSE_STR) == TRUE_STR; if (isPinEnrolled_) { IAM_LOGI("fwk ready, isPinEnrolled is true, sa should be running"); return; diff --git a/services/remote_connect/inc/device_manager_util.h b/services/remote_connect/inc/device_manager_util.h index 86cc3c1fadede273f0dedee3b9d503c564a479e4..78d0cc14c749277ff09cd5dd1fbdfe9fdacf39a4 100644 --- a/services/remote_connect/inc/device_manager_util.h +++ b/services/remote_connect/inc/device_manager_util.h @@ -20,7 +20,6 @@ #include #include -#define LOG_TAG "USER_AUTH_SA" namespace OHOS { namespace UserIam { namespace UserAuth { diff --git a/test/fuzztest/clients/BUILD.gn b/test/fuzztest/clients/BUILD.gn index 4ada3e9e9f4895ffe6c3614a855072c799a585d3..317228344a730d6eeeba1fb754721acdceaf334c 100644 --- a/test/fuzztest/clients/BUILD.gn +++ b/test/fuzztest/clients/BUILD.gn @@ -18,13 +18,8 @@ group("iam_clients_fuzztest") { testonly = true deps = [ "coauthclient_fuzzer:CoAuthClientFuzzTest", - "executorcallbackstub_fuzzer:ExecutorCallbackStubFuzzTest", - "modalcallbackstub_fuzzer:ModalCallbackStubFuzzTest", "useraccessctrlclient_fuzzer:UserAccessCtrlClientFuzzTest", - "userauthcallbackstub_fuzzer:UserAuthCallbackStubFuzzTest", "userauthclient_fuzzer:UserAuthClientFuzzTest", "useridmclient_fuzzer:UserIdmClientFuzzTest", - "useridmclientstub_fuzzer:UserIdmClientStubFuzzTest", - "widgetcallbackstub_fuzzer:WidgetCallbackStubFuzzTest", ] } diff --git a/test/fuzztest/clients/coauthclient_fuzzer/BUILD.gn b/test/fuzztest/clients/coauthclient_fuzzer/BUILD.gn index 1afd9afd6c02dd030b3cd8cba18b303e4ad7c066..54386ed321e12df64790615cb9bce2fd18b97145 100644 --- a/test/fuzztest/clients/coauthclient_fuzzer/BUILD.gn +++ b/test/fuzztest/clients/coauthclient_fuzzer/BUILD.gn @@ -42,6 +42,7 @@ ohos_fuzztest("CoAuthClientFuzzTest") { "../../../../frameworks/native/client/src/auth_message_impl.cpp", "../../../../frameworks/native/client/src/callback_manager_impl.cpp", "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", + "../../../../frameworks/native/client/src/event_listener_callback_service.cpp", "../../../../frameworks/native/client/src/executor_callback_service.cpp", "../../../../frameworks/native/client/src/executor_messenger_client.cpp", "../../../../frameworks/native/client/src/ipc_client_utils.cpp", @@ -57,10 +58,10 @@ ohos_fuzztest("CoAuthClientFuzzTest") { ] deps = [ + "../../../../frameworks/native/ipc:userauth_client_ipc_fuzzer", "../../common_fuzzer:attributes_fuzzer", "../../common_fuzzer:dfx_fuzzer", "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", ] remove_configs = [ "//build/config/compiler:no_exceptions" ] diff --git a/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp b/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp index 10958769fc980d3d74ea778a0d4f5c23ff098369..9129243fed2bd5988e8a5e1d13a60874b395fbff 100644 --- a/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp +++ b/test/fuzztest/clients/coauthclient_fuzzer/co_auth_client_fuzzer.cpp @@ -83,9 +83,9 @@ public: } }; -class DummyExecutorMessengerInterface final : public ExecutorMessengerInterface { +class DummyExecutorMessenger final : public IExecutorMessenger { public: - int32_t SendData(uint64_t scheduleId, ExecutorRole dstRole, + int32_t SendData(uint64_t scheduleId, int32_t dstRole, const std::vector &msg) override { IAM_LOGI("start"); @@ -95,7 +95,7 @@ public: return SUCCESS; } - int32_t Finish(uint64_t scheduleId, ResultCode resultCode, const std::shared_ptr &finalResult) override + int32_t Finish(uint64_t scheduleId, int32_t resultCode, const std::vector &finalResult) override { IAM_LOGI("start"); static_cast(scheduleId); @@ -144,12 +144,12 @@ auto g_ExecutorCallbackService = Common::MakeShared(Common::MakeShared()); auto g_ExecutorMessengerClient = - Common::MakeShared(new (std::nothrow) DummyExecutorMessengerInterface()); + Common::MakeShared(new (std::nothrow) DummyExecutorMessenger()); void FuzzExecutorCallbackServiceOnMessengerReady(Parcel &parcel) { IAM_LOGI("start"); - sptr messenger(new (std::nothrow) DummyExecutorMessengerInterface()); + sptr messenger(new (std::nothrow) DummyExecutorMessenger()); std::vector publicKey; Common::FillFuzzUint8Vector(parcel, publicKey); std::vector templateIdList; @@ -170,7 +170,7 @@ void FuzzExecutorCallbackServiceOnBeginExecute(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes command(attr); if (g_ExecutorCallbackService != nullptr) { - g_ExecutorCallbackService->OnBeginExecute(scheduleId, publicKey, command); + g_ExecutorCallbackService->OnBeginExecute(scheduleId, publicKey, command.Serialize()); } IAM_LOGI("end"); } @@ -183,7 +183,7 @@ void FuzzExecutorCallbackServiceOnEndExecute(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes command(attr); if (g_ExecutorCallbackService != nullptr) { - g_ExecutorCallbackService->OnEndExecute(scheduleId, command); + g_ExecutorCallbackService->OnEndExecute(scheduleId, command.Serialize()); } IAM_LOGI("end"); } @@ -195,7 +195,7 @@ void FuzzExecutorCallbackServiceOnSetProperty(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes properties(attr); if (g_ExecutorCallbackService != nullptr) { - g_ExecutorCallbackService->OnSetProperty(properties); + g_ExecutorCallbackService->OnSetProperty(properties.Serialize()); } IAM_LOGI("end"); } @@ -206,9 +206,9 @@ void FuzzExecutorCallbackServiceOnGetProperty(Parcel &parcel) std::vector attr; Common::FillFuzzUint8Vector(parcel, attr); Attributes condition(attr); - Attributes values; + std::vector values; if (g_ExecutorCallbackService != nullptr) { - g_ExecutorCallbackService->OnGetProperty(condition, values); + g_ExecutorCallbackService->OnGetProperty(condition.Serialize(), values); } IAM_LOGI("end"); } @@ -219,7 +219,7 @@ void FuzzExecutorCallbackServiceOnSendData(Parcel &parcel) uint64_t scheduleId = parcel.ReadUint64(); Attributes data; if (g_ExecutorCallbackService != nullptr) { - g_ExecutorCallbackService->OnSendData(scheduleId, data); + g_ExecutorCallbackService->OnSendData(scheduleId, data.Serialize()); } IAM_LOGI("end"); } diff --git a/test/fuzztest/clients/executorcallbackstub_fuzzer/BUILD.gn b/test/fuzztest/clients/executorcallbackstub_fuzzer/BUILD.gn deleted file mode 100644 index 6c7f0deb5c60cd4d78050600789293f30d43a439..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/executorcallbackstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") - -ohos_fuzztest("ExecutorCallbackStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../executorcallbackstub_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - include_dirs = [ - "../../../../interfaces/inner_api", - "../../../../frameworks/js/napi/user_auth/inc", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/client/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ - "../../../../frameworks/native/client/src/auth_message_impl.cpp", - "../../../../frameworks/native/client/src/callback_manager_impl.cpp", - "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/executor_callback_service.cpp", - "../../../../frameworks/native/client/src/executor_messenger_client.cpp", - "../../../../frameworks/native/client/src/ipc_client_utils.cpp", - "../../../../frameworks/native/client/src/load_mode_client_util.cpp", - "../../../../frameworks/native/client/src/modal_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/user_auth_modal_inner_callback.cpp", - "../../../../frameworks/native/client/src/user_auth_napi_client_impl.cpp", - "../../../../frameworks/native/client/src/user_idm_callback_service.cpp", - "../../../../frameworks/native/client/src/user_idm_client_impl.cpp", - "../../../../frameworks/native/client/src/widget_callback_service.cpp", - "executor_callback_stub_fuzzer.cpp", - ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:dfx_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", - ] - - remove_configs = [ "//build/config/compiler:no_exceptions" ] - - external_deps = [ - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_context", - "ability_runtime:napi_base_context", - "ability_runtime:ui_extension", - "access_token:libaccesstoken_sdk", - "ace_engine:ace_uicontent", - "c_utils:utils", - "hilog:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_single", - "napi:ace_napi", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/clients/executorcallbackstub_fuzzer/corpus/init b/test/fuzztest/clients/executorcallbackstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/executorcallbackstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.cpp b/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.cpp deleted file mode 100644 index bcfd20747bd432542f7f72cd32aad49c7581edf9..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/executorcallbackstub_fuzzer/executor_callback_stub_fuzzer.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_callback_stub_fuzzer.h" - -#include "parcel.h" - -#include "co_auth_client.h" -#include "executor_callback_service.h" -#include "executor_messenger_client.h" -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "iam_ptr.h" - -#define LOG_TAG "USER_AUTH_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t EXECUTOR_CALLBACK_CODE_MIN = 0; -constexpr uint32_t EXECUTOR_CALLBACK_CODE_MAX = 7; -const std::u16string EXECUTOR_CALLBACK_INTERFACE_TOKEN = u"ohos.UserIam.AuthResPool.ExecutorCallback"; - -class DummyExecutorRegisterCallback final : public ExecutorRegisterCallback { -public: - void OnMessengerReady(const std::shared_ptr &messenger, - const std::vector &publicKey, const std::vector &templateIds) - { - IAM_LOGI("start"); - static_cast(messenger); - static_cast(publicKey); - static_cast(templateIds); - } - - int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &commandAttrs) - { - IAM_LOGI("start"); - static_cast(scheduleId); - static_cast(publicKey); - static_cast(commandAttrs); - return SUCCESS; - } - - int32_t OnEndExecute(uint64_t scheduleId, const Attributes &commandAttrs) - { - IAM_LOGI("start"); - static_cast(scheduleId); - static_cast(commandAttrs); - return SUCCESS; - } - - int32_t OnSetProperty(const Attributes &properties) - { - IAM_LOGI("start"); - static_cast(properties); - return SUCCESS; - } - - int32_t OnGetProperty(const Attributes &conditions, Attributes &results) - { - IAM_LOGI("start"); - static_cast(conditions); - static_cast(results); - return SUCCESS; - } - - int32_t OnSendData(uint64_t scheduleId, const Attributes &data) - { - IAM_LOGI("start"); - static_cast(scheduleId); - static_cast(data); - return SUCCESS; - } -}; - -auto g_ExecutorCallbackService = - Common::MakeShared(Common::MakeShared()); - -bool ExecutorCallbackStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - for (uint32_t code = EXECUTOR_CALLBACK_CODE_MIN; code < EXECUTOR_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(EXECUTOR_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_ExecutorCallbackService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(EXECUTOR_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_ExecutorCallbackService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - OHOS::UserIam::UserAuth::ExecutorCallbackStubFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/clients/executorcallbackstub_fuzzer/project.xml b/test/fuzztest/clients/executorcallbackstub_fuzzer/project.xml deleted file mode 100644 index ed7b1e1916ab236253f7dea6e0045a400d865e1b..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/executorcallbackstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 2000 - - 300 - - 4096 - - diff --git a/test/fuzztest/clients/modalcallbackstub_fuzzer/BUILD.gn b/test/fuzztest/clients/modalcallbackstub_fuzzer/BUILD.gn deleted file mode 100644 index 0d090f3f936e9650e1f46bb684d84c82e9e442d4..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/modalcallbackstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") - -ohos_fuzztest("ModalCallbackStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../modalcallbackstub_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - include_dirs = [ - "../../../../interfaces/inner_api", - "../../../../frameworks/js/napi/user_auth/inc", - "../../../../frameworks/native/client/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/common/dfx/inc", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ - "../../../../frameworks/native/client/src/auth_message_impl.cpp", - "../../../../frameworks/native/client/src/callback_manager_impl.cpp", - "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/executor_callback_service.cpp", - "../../../../frameworks/native/client/src/executor_messenger_client.cpp", - "../../../../frameworks/native/client/src/ipc_client_utils.cpp", - "../../../../frameworks/native/client/src/load_mode_client_util.cpp", - "../../../../frameworks/native/client/src/modal_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/user_auth_modal_inner_callback.cpp", - "../../../../frameworks/native/client/src/user_idm_callback_service.cpp", - "../../../../frameworks/native/client/src/user_idm_client_impl.cpp", - "../../../../frameworks/native/client/src/widget_callback_service.cpp", - "modal_callback_stub_fuzzer.cpp", - ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:dfx_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", - ] - - remove_configs = [ "//build/config/compiler:no_exceptions" ] - - external_deps = [ - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_context", - "ability_runtime:napi_base_context", - "ability_runtime:ui_extension", - "access_token:libaccesstoken_sdk", - "ace_engine:ace_uicontent", - "hilog:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_single", - "napi:ace_napi", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "user_auth_framework:userauth_client", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/clients/modalcallbackstub_fuzzer/corpus/init b/test/fuzztest/clients/modalcallbackstub_fuzzer/corpus/init deleted file mode 100644 index 65af8ee8d11bf23407ea34d4de49f7cbb6a2b791..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/modalcallbackstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/clients/modalcallbackstub_fuzzer/modal_callback_stub_fuzzer.cpp b/test/fuzztest/clients/modalcallbackstub_fuzzer/modal_callback_stub_fuzzer.cpp deleted file mode 100644 index 0e90e04b2705a972569d8b8d8af802318895c14a..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/modalcallbackstub_fuzzer/modal_callback_stub_fuzzer.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "modal_callback_stub_fuzzer.h" - -#include "parcel.h" - -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "iam_ptr.h" -#include "modal_callback_service.h" - -#define LOG_TAG "USER_AUTH_SA" - -using namespace std; - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t MODAL_CALLBACK_CODE_MIN = 0; -constexpr uint32_t MODAL_CALLBACK_CODE_MAX = 100; -const std::u16string MODAL_CALLBACK_INTERFACE_TOKEN = u"ohos.UserIam.UserAuth.ModalCallback"; - -class DummyUserAuthModalClientCallback final : public UserAuthModalClientCallback { -public: - void SendCommand(uint64_t contextId, const std::string &cmdData) - { - IAM_LOGI("start"); - static_cast(contextId); - static_cast(cmdData); - } - bool IsModalInit() - { - IAM_LOGI("start"); - return false; - } - bool IsModalDestroy() - { - IAM_LOGI("start"); - return false; - } - -private: - void CancelAuthentication(uint64_t contextId, int32_t cancelReason) - { - IAM_LOGI("start"); - static_cast(contextId); - static_cast(cancelReason); - } -}; - -bool ModalCallbackStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - auto service = - Common::MakeShared(Common::MakeShared()); - for (uint32_t code = MODAL_CALLBACK_CODE_MIN; code < MODAL_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(MODAL_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)service->OnRemoteRequest(code, data, reply, optionSync); - // Async - (void)service->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - OHOS::UserIam::UserAuth::ModalCallbackStubFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/clients/modalcallbackstub_fuzzer/project.xml b/test/fuzztest/clients/modalcallbackstub_fuzzer/project.xml deleted file mode 100644 index 66e1dcac475475fb101b6f8670ec699e6e9696aa..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/modalcallbackstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/clients/useraccessctrlclient_fuzzer/BUILD.gn b/test/fuzztest/clients/useraccessctrlclient_fuzzer/BUILD.gn index 7fae2d819bbd7a68492f0609fa7840aefc0cdfb2..5ad2650f88cba3cd573d593804f2b6256512dc4c 100644 --- a/test/fuzztest/clients/useraccessctrlclient_fuzzer/BUILD.gn +++ b/test/fuzztest/clients/useraccessctrlclient_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("UserAccessCtrlClientFuzzTest") { "../../../../frameworks/native/client/src/auth_message_impl.cpp", "../../../../frameworks/native/client/src/callback_manager_impl.cpp", "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", + "../../../../frameworks/native/client/src/event_listener_callback_service.cpp", "../../../../frameworks/native/client/src/executor_callback_service.cpp", "../../../../frameworks/native/client/src/executor_messenger_client.cpp", "../../../../frameworks/native/client/src/ipc_client_utils.cpp", @@ -58,10 +59,10 @@ ohos_fuzztest("UserAccessCtrlClientFuzzTest") { ] deps = [ + "../../../../frameworks/native/ipc:userauth_client_ipc_fuzzer", "../../common_fuzzer:attributes_fuzzer", "../../common_fuzzer:dfx_fuzzer", "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", ] remove_configs = [ "//build/config/compiler:no_exceptions" ] diff --git a/test/fuzztest/clients/userauthcallbackstub_fuzzer/BUILD.gn b/test/fuzztest/clients/userauthcallbackstub_fuzzer/BUILD.gn deleted file mode 100644 index 3dd9d52375e482e747cbb4f3ec4d0f5787fff9a5..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/userauthcallbackstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,89 +0,0 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") - -ohos_fuzztest("UserAuthCallbackStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../userauthcallbackstub_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - include_dirs = [ - "../../../../interfaces/inner_api", - "../../../../frameworks/js/napi/user_auth/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/common/dfx/inc", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ - "../../../../frameworks/native/client/src/auth_message_impl.cpp", - "../../../../frameworks/native/client/src/callback_manager_impl.cpp", - "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/executor_callback_service.cpp", - "../../../../frameworks/native/client/src/executor_messenger_client.cpp", - "../../../../frameworks/native/client/src/ipc_client_utils.cpp", - "../../../../frameworks/native/client/src/load_mode_client_util.cpp", - "../../../../frameworks/native/client/src/modal_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/user_auth_modal_inner_callback.cpp", - "../../../../frameworks/native/client/src/user_idm_callback_service.cpp", - "../../../../frameworks/native/client/src/user_idm_client_impl.cpp", - "../../../../frameworks/native/client/src/widget_callback_service.cpp", - "user_auth_callback_stub_fuzzer.cpp", - ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:dfx_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", - ] - - remove_configs = [ "//build/config/compiler:no_exceptions" ] - - external_deps = [ - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_context", - "ability_runtime:napi_base_context", - "ability_runtime:ui_extension", - "access_token:libaccesstoken_sdk", - "ace_engine:ace_uicontent", - "hilog:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_single", - "napi:ace_napi", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "user_auth_framework:userauth_client", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/clients/userauthcallbackstub_fuzzer/corpus/init b/test/fuzztest/clients/userauthcallbackstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/userauthcallbackstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/clients/userauthcallbackstub_fuzzer/project.xml b/test/fuzztest/clients/userauthcallbackstub_fuzzer/project.xml deleted file mode 100644 index ed7b1e1916ab236253f7dea6e0045a400d865e1b..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/userauthcallbackstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 2000 - - 300 - - 4096 - - diff --git a/test/fuzztest/clients/userauthcallbackstub_fuzzer/user_auth_callback_stub_fuzzer.cpp b/test/fuzztest/clients/userauthcallbackstub_fuzzer/user_auth_callback_stub_fuzzer.cpp deleted file mode 100644 index baab018188a5cff0dd6a64a5f77484f507ab0693..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/userauthcallbackstub_fuzzer/user_auth_callback_stub_fuzzer.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_callback_stub_fuzzer.h" - -#include "parcel.h" - -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "iam_ptr.h" -#include "user_auth_callback_service.h" - -#define LOG_TAG "USER_AUTH_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t USER_AUTH_CALLBACK_CODE_MIN = 7; -constexpr uint32_t USER_AUTH_CALLBACK_CODE_MAX = 12; -const std::u16string USER_AUTH_CALLBACK_INTERFACE_TOKEN = u"ohos.UserIam.UserAuth.UserAuthCallback"; -constexpr uint32_t GET_PROPERTY_CALLBACK_CODE_MIN = 8; -constexpr uint32_t GET_PROPERTY_CALLBACK_CODE_MAX = 10; -const std::u16string GET_PROPERTY_CALLBACK_INTERFACE_TOKEN = u"ohos.UserIam.UserAuth.GetExecutorPropertyCallback"; -constexpr uint32_t SET_PROPERTY_CALLBACK_CODE_MIN = 9; -constexpr uint32_t SET_PROPERTY_CALLBACK_CODE_MAX = 11; -const std::u16string SET_PROPERTY_CALLBACK_INTERFACE_TOKEN = u"ohos.UserIam.UserAuth.SetExecutorPropertyCallback"; - -class DummyGetPropCallback final : public GetPropCallback { -public: - void OnResult(int32_t result, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(result); - static_cast(extraInfo); - } -}; - -class DummySetPropCallback final : public SetPropCallback { -public: - void OnResult(int32_t result, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(result); - static_cast(extraInfo); - } -}; - -class DummyAuthenticationCallback final : public AuthenticationCallback { -public: - void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(module); - static_cast(acquireInfo); - static_cast(extraInfo); - } - - void OnResult(int32_t result, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(result); - static_cast(extraInfo); - } -}; - -class DummyIdentificationCallback final : public IdentificationCallback { -public: - void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(module); - static_cast(acquireInfo); - static_cast(extraInfo); - } - - void OnResult(int32_t result, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(result); - static_cast(extraInfo); - } -}; - -auto g_UserAuthCallbackService = - Common::MakeShared(Common::MakeShared()); - -auto g_GetPropCallbackService = - Common::MakeShared(Common::MakeShared()); - -auto g_SetPropCallbackService = - Common::MakeShared(Common::MakeShared()); - -bool SetPropCallbackStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - for (uint32_t code = SET_PROPERTY_CALLBACK_CODE_MIN; code < SET_PROPERTY_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(SET_PROPERTY_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_SetPropCallbackService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(SET_PROPERTY_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_SetPropCallbackService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} - -bool GetPropCallbackStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - for (uint32_t code = GET_PROPERTY_CALLBACK_CODE_MIN; code < GET_PROPERTY_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(GET_PROPERTY_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_GetPropCallbackService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(GET_PROPERTY_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_GetPropCallbackService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} - -bool UserAuthCallbackStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - for (uint32_t code = USER_AUTH_CALLBACK_CODE_MIN; code < USER_AUTH_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(USER_AUTH_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_UserAuthCallbackService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(USER_AUTH_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)g_UserAuthCallbackService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - OHOS::UserIam::UserAuth::UserAuthCallbackStubFuzzTest(data, size); - OHOS::UserIam::UserAuth::GetPropCallbackStubFuzzTest(data, size); - OHOS::UserIam::UserAuth::SetPropCallbackStubFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/clients/userauthclient_fuzzer/BUILD.gn b/test/fuzztest/clients/userauthclient_fuzzer/BUILD.gn index be928a7cdd537123b14f97bc6f00df9c921277ef..fd5e13c1a674e5702678fbfec0bb0e977d674494 100644 --- a/test/fuzztest/clients/userauthclient_fuzzer/BUILD.gn +++ b/test/fuzztest/clients/userauthclient_fuzzer/BUILD.gn @@ -41,6 +41,7 @@ ohos_fuzztest("UserAuthClientFuzzTest") { "../../../../frameworks/native/client/src/auth_message_impl.cpp", "../../../../frameworks/native/client/src/callback_manager_impl.cpp", "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", + "../../../../frameworks/native/client/src/event_listener_callback_service.cpp", "../../../../frameworks/native/client/src/executor_callback_service.cpp", "../../../../frameworks/native/client/src/executor_messenger_client.cpp", "../../../../frameworks/native/client/src/ipc_client_utils.cpp", @@ -57,10 +58,10 @@ ohos_fuzztest("UserAuthClientFuzzTest") { ] deps = [ + "../../../../frameworks/native/ipc:userauth_client_ipc_fuzzer", "../../common_fuzzer:attributes_fuzzer", "../../common_fuzzer:dfx_fuzzer", "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", ] remove_configs = [ "//build/config/compiler:no_exceptions" ] diff --git a/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp b/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp index 8348bd1f07681e110e66ae091c873bd482d16f24..985b7547699004aacf9e94ee0d47c757d3e65f10 100644 --- a/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp +++ b/test/fuzztest/clients/userauthclient_fuzzer/user_auth_client_fuzzer.cpp @@ -107,6 +107,18 @@ public: } }; +class DummyAuthSuccessEventListener final : public AuthSuccessEventListener { +public: + void OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, const std::string &callerName) + { + IAM_LOGI("start"); + static_cast(userId); + static_cast(authType); + static_cast(callerType); + static_cast(callerName); + } +}; + void FuzzClientGetEnrolledState(Parcel &parcel) { IAM_LOGI("start"); @@ -228,7 +240,7 @@ void FuzzClientRegistUserAuthSuccessEventListener(Parcel &parcel) authTypeList.push_back(AuthType::PIN); authTypeList.push_back(AuthType::FACE); authTypeList.push_back(AuthType::FINGERPRINT); - sptr listener = {}; + auto listener = Common::MakeShared(); UserAuthClientImpl::Instance().RegistUserAuthSuccessEventListener(authTypeList, listener); IAM_LOGI("end"); } @@ -236,7 +248,7 @@ void FuzzClientRegistUserAuthSuccessEventListener(Parcel &parcel) void FuzzClientUnRegistUserAuthSuccessEventListener(Parcel &Parcel) { IAM_LOGI("start"); - sptr listener = {}; + auto listener = Common::MakeShared(); UserAuthClientImpl::Instance().UnRegistUserAuthSuccessEventListener(listener); IAM_LOGI("end"); } @@ -338,7 +350,7 @@ void FuzzUserAuthCallbackServiceOnResult(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes extraInfo(attr); if (g_UserAuthCallbackService != nullptr) { - g_UserAuthCallbackService->OnResult(result, extraInfo); + g_UserAuthCallbackService->OnResult(result, extraInfo.Serialize()); } IAM_LOGI("end"); } @@ -352,7 +364,7 @@ void FuzzUserAuthCallbackServiceOnAcquireInfo(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes extraInfo(attr); if (g_UserAuthCallbackService != nullptr) { - g_UserAuthCallbackService->OnAcquireInfo(result, acquireInfo, extraInfo); + g_UserAuthCallbackService->OnAcquireInfo(result, acquireInfo, extraInfo.Serialize()); } IAM_LOGI("end"); } @@ -365,7 +377,7 @@ void FuzzGetPropCallbackServiceOnPropResult(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes extraInfo(attr); if (g_GetPropCallbackService != nullptr) { - g_GetPropCallbackService->OnGetExecutorPropertyResult(result, extraInfo); + g_GetPropCallbackService->OnGetExecutorPropertyResult(result, extraInfo.Serialize()); } IAM_LOGI("end"); } diff --git a/test/fuzztest/clients/useridmclient_fuzzer/BUILD.gn b/test/fuzztest/clients/useridmclient_fuzzer/BUILD.gn index 43238ab39c2c4fd7d03f17974463f3a8736652c7..bd03c67a9dd9c1994e2c3db5a981f21949269aa6 100644 --- a/test/fuzztest/clients/useridmclient_fuzzer/BUILD.gn +++ b/test/fuzztest/clients/useridmclient_fuzzer/BUILD.gn @@ -42,6 +42,7 @@ ohos_fuzztest("UserIdmClientFuzzTest") { "../../../../frameworks/native/client/src/auth_message_impl.cpp", "../../../../frameworks/native/client/src/callback_manager_impl.cpp", "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", + "../../../../frameworks/native/client/src/event_listener_callback_service.cpp", "../../../../frameworks/native/client/src/executor_callback_service.cpp", "../../../../frameworks/native/client/src/executor_messenger_client.cpp", "../../../../frameworks/native/client/src/ipc_client_utils.cpp", @@ -57,10 +58,10 @@ ohos_fuzztest("UserIdmClientFuzzTest") { ] deps = [ + "../../../../frameworks/native/ipc:userauth_client_ipc_fuzzer", "../../common_fuzzer:attributes_fuzzer", "../../common_fuzzer:dfx_fuzzer", "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", ] remove_configs = [ "//build/config/compiler:no_exceptions" ] diff --git a/test/fuzztest/clients/useridmclient_fuzzer/user_idm_client_fuzzer.cpp b/test/fuzztest/clients/useridmclient_fuzzer/user_idm_client_fuzzer.cpp index 206e6818ef45a83fd42e1e9635dd3cd989f2ec91..3fe00576526a78c7440a1cfbe315057cb5d94671 100644 --- a/test/fuzztest/clients/useridmclient_fuzzer/user_idm_client_fuzzer.cpp +++ b/test/fuzztest/clients/useridmclient_fuzzer/user_idm_client_fuzzer.cpp @@ -67,6 +67,19 @@ public: } }; +class DummyCredChangeEventListener final : public CredChangeEventListener { +public: + void OnNotifyCredChangeEvent(int32_t userId, AuthType authType, CredChangeEventType eventType, + uint64_t credentialId) + { + IAM_LOGI("start"); + static_cast(userId); + static_cast(authType); + static_cast(eventType); + static_cast(credentialId); + } +}; + void FuzzClientOpenSession(Parcel &parcel) { IAM_LOGI("start"); @@ -182,6 +195,26 @@ void FuzzClientClearRedundancyCredential(Parcel &parcel) IAM_LOGI("end"); } +void FuzzClientRegistCredChangeEventListener(Parcel &parcel) +{ + IAM_LOGI("start"); + std::vector authTypeList; + authTypeList.push_back(AuthType::PIN); + authTypeList.push_back(AuthType::FACE); + authTypeList.push_back(AuthType::FINGERPRINT); + auto listener = Common::MakeShared(); + UserIdmClient::GetInstance().RegistCredChangeEventListener(authTypeList, listener); + IAM_LOGI("end"); +} + +void FuzzClientUnRegistCredChangeEventListener(Parcel &Parcel) +{ + IAM_LOGI("start"); + auto listener = Common::MakeShared(); + UserIdmClient::GetInstance().UnRegistCredChangeEventListener(listener); + IAM_LOGI("end"); +} + auto g_IdmCallbackService = Common::MakeShared(Common::MakeShared()); @@ -199,7 +232,7 @@ void FuzzIdmCallbackServiceOnResult(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes extraInfo(attr); if (g_IdmCallbackService != nullptr) { - g_IdmCallbackService->OnResult(result, extraInfo); + g_IdmCallbackService->OnResult(result, extraInfo.Serialize()); } IAM_LOGI("end"); } @@ -213,7 +246,7 @@ void FuzzIdmCallbackServiceOnAcquireInfo(Parcel &parcel) Common::FillFuzzUint8Vector(parcel, attr); Attributes extraInfo(attr); if (g_IdmCallbackService != nullptr) { - g_IdmCallbackService->OnAcquireInfo(module, acquireInfo, extraInfo); + g_IdmCallbackService->OnAcquireInfo(module, acquireInfo, extraInfo.Serialize()); } IAM_LOGI("end"); } @@ -221,12 +254,12 @@ void FuzzIdmCallbackServiceOnAcquireInfo(Parcel &parcel) void FuzzCallbackServiceOnCredentialInfos(Parcel &parcel) { IAM_LOGI("start"); - CredentialInfo info = {}; + IpcCredentialInfo info = {}; info.authType = static_cast(parcel.ReadInt32()); info.credentialId = parcel.ReadUint64(); info.templateId = parcel.ReadUint64(); info.pinType = static_cast(parcel.ReadInt32()); - std::vector credInfoList = {info}; + std::vector credInfoList = {info}; int32_t result = parcel.ReadInt32(); if (g_IdmGetCredInfoCallbackService != nullptr) { g_IdmGetCredInfoCallbackService->OnCredentialInfos(result, credInfoList); @@ -237,12 +270,12 @@ void FuzzCallbackServiceOnCredentialInfos(Parcel &parcel) void FuzzCallbackServiceOnSecureUserInfo(Parcel &parcel) { IAM_LOGI("start"); - SecUserInfo secUserInfo = {}; + IpcSecUserInfo secUserInfo = {}; secUserInfo.secureUid = parcel.ReadUint64(); - EnrolledInfo info = {}; - info.authType = static_cast(parcel.ReadInt32()); + IpcEnrolledInfo info = {}; + info.authType = parcel.ReadInt32(); info.enrolledId = parcel.ReadUint64(); - secUserInfo.enrolledInfo = {info}; + secUserInfo.enrolledInfo.push_back(info); int32_t result = parcel.ReadInt32(); if (g_IdmGetSecureUserInfoCallbackService != nullptr) { @@ -251,6 +284,17 @@ void FuzzCallbackServiceOnSecureUserInfo(Parcel &parcel) IAM_LOGI("end"); } +void FuzzClientGetCredentialInfoSync(Parcel &parcel) +{ + IAM_LOGI("start"); + int32_t userId = parcel.ReadInt32(); + auto authType = static_cast(parcel.ReadInt32()); + std::vector credentialInfoList; + UserIdmClient::GetInstance().GetCredentialInfoSync(userId, authType, credentialInfoList); + IAM_LOGI("end"); +} + + using FuzzFunc = decltype(FuzzClientOpenSession); FuzzFunc *g_fuzzFuncs[] = { FuzzClientOpenSession, @@ -268,6 +312,9 @@ FuzzFunc *g_fuzzFuncs[] = { FuzzCallbackServiceOnCredentialInfos, FuzzCallbackServiceOnSecureUserInfo, FuzzClientClearRedundancyCredential, + FuzzClientRegistCredChangeEventListener, + FuzzClientUnRegistCredChangeEventListener, + FuzzClientGetCredentialInfoSync, }; void UserIdmClientFuzzTest(const uint8_t *data, size_t size) diff --git a/test/fuzztest/clients/useridmclientstub_fuzzer/BUILD.gn b/test/fuzztest/clients/useridmclientstub_fuzzer/BUILD.gn deleted file mode 100644 index e7d74f9cb97e442e8c88025d74f69f9e3dc03812..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/useridmclientstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") - -ohos_fuzztest("UserIdmClientStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../useridmclientstub_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - include_dirs = [ - "../../../../interfaces/inner_api", - "../../../../frameworks/js/napi/user_auth/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/common/dfx/inc", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ - "../../../../frameworks/native/client/src/auth_message_impl.cpp", - "../../../../frameworks/native/client/src/callback_manager_impl.cpp", - "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/executor_callback_service.cpp", - "../../../../frameworks/native/client/src/executor_messenger_client.cpp", - "../../../../frameworks/native/client/src/ipc_client_utils.cpp", - "../../../../frameworks/native/client/src/load_mode_client_util.cpp", - "../../../../frameworks/native/client/src/modal_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/user_auth_modal_inner_callback.cpp", - "../../../../frameworks/native/client/src/user_idm_callback_service.cpp", - "../../../../frameworks/native/client/src/user_idm_client_impl.cpp", - "../../../../frameworks/native/client/src/widget_callback_service.cpp", - "user_idm_client_stub_fuzzer.cpp", - ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:dfx_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", - ] - - remove_configs = [ "//build/config/compiler:no_exceptions" ] - - external_deps = [ - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_context", - "ability_runtime:napi_base_context", - "ability_runtime:ui_extension", - "access_token:libaccesstoken_sdk", - "ace_engine:ace_uicontent", - "c_utils:utils", - "hilog:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_single", - "napi:ace_napi", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "user_auth_framework:userauth_client", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/clients/useridmclientstub_fuzzer/corpus/init b/test/fuzztest/clients/useridmclientstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/useridmclientstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/clients/useridmclientstub_fuzzer/project.xml b/test/fuzztest/clients/useridmclientstub_fuzzer/project.xml deleted file mode 100644 index ed7b1e1916ab236253f7dea6e0045a400d865e1b..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/useridmclientstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 2000 - - 300 - - 4096 - - diff --git a/test/fuzztest/clients/useridmclientstub_fuzzer/user_idm_client_stub_fuzzer.cpp b/test/fuzztest/clients/useridmclientstub_fuzzer/user_idm_client_stub_fuzzer.cpp deleted file mode 100644 index 897da76a6e0245c2ff2d57254db0b2845d8d3cd8..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/useridmclientstub_fuzzer/user_idm_client_stub_fuzzer.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_client_stub_fuzzer.h" - -#include "parcel.h" - -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "iam_ptr.h" -#include "user_idm_client.h" -#include "user_idm_callback_service.h" - -#define LOG_TAG "USER_AUTH_SDK" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t IDM_CALLBACK_CODE_MIN = 0; -constexpr uint32_t IDM_CALLBACK_CODE_MAX = 3; -const std::u16string IDM_CALLBACK_INTERFACE_TOKEN = u"ohos.useridm.IIDMCallback"; -constexpr uint32_t GET_CREDINFO_CALLBACK_CODE_MIN = 0; -constexpr uint32_t GET_CREDINFO_CALLBACK_CODE_MAX = 2; -const std::u16string GET_CREDINFO_CALLBACK_TOKEN = u"ohos.useridm.IGetInfoCallback"; -constexpr uint32_t GET_SECURE_USERINFO_CALLBACK_CODE_MIN = 0; -constexpr uint32_t GET_SECURE_USERINFO_CALLBACK_CODE_MAX = 2; -const std::u16string GET_SECURE_USERINFO_CALLBACK_TOKEN = u"ohos.useridm.IGetSecInfoCallback"; -class DummyUserIdmClientCallback final : public UserIdmClientCallback { -public: - void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(module); - static_cast(acquireInfo); - static_cast(extraInfo); - } - - void OnResult(int32_t result, const Attributes &extraInfo) - { - IAM_LOGI("start"); - static_cast(result); - static_cast(extraInfo); - } -}; - -class DummyGetCredentialInfoCallback final : public GetCredentialInfoCallback { -public: - void OnCredentialInfo(int32_t result, const std::vector &infoList) - { - IAM_LOGI("start"); - static_cast(result); - static_cast(infoList); - } -}; - -class DummyGetSecUserInfoCallback final : public GetSecUserInfoCallback { -public: - void OnSecUserInfo(int32_t result, const SecUserInfo &info) - { - IAM_LOGI("start"); - static_cast(result); - static_cast(info); - } -}; - -bool FuzzIdmCallbackStub(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - IAM_LOGI("%{public}s:rawData is null.", __func__); - return false; - } - auto idmCallbackService = - Common::MakeShared(Common::MakeShared()); - if (idmCallbackService == nullptr) { - IAM_LOGI("%{public}s:new idmCallbackService failed.", __func__); - return false; - } - for (uint32_t code = IDM_CALLBACK_CODE_MIN; code < IDM_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(IDM_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)idmCallbackService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(IDM_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)idmCallbackService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} - -bool FuzzIdmGetInfoCallbackStub(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - IAM_LOGI("%{public}s:rawData is null.", __func__); - return false; - } - auto idmGetCredInfoCallbackService = - Common::MakeShared(Common::MakeShared()); - if (idmGetCredInfoCallbackService == nullptr) { - IAM_LOGI("%{public}s:new idmGetCredInfoCallbackService failed.", __func__); - return false; - } - for (uint32_t code = GET_CREDINFO_CALLBACK_CODE_MIN; code < GET_CREDINFO_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(GET_CREDINFO_CALLBACK_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)idmGetCredInfoCallbackService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(GET_CREDINFO_CALLBACK_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)idmGetCredInfoCallbackService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} - -bool FuzzIdmGetSecureUserInfoCallbackstub(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - IAM_LOGI("%{public}s:rawData is null.", __func__); - return false; - } - auto idmGetSecureUserInfoCallbackService = - Common::MakeShared(Common::MakeShared()); - if (idmGetSecureUserInfoCallbackService == nullptr) { - IAM_LOGI("%{public}s:new idmGetSecureUserInfoCallbackService failed.", __func__); - return false; - } - for (uint32_t code = GET_SECURE_USERINFO_CALLBACK_CODE_MIN; code < GET_SECURE_USERINFO_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(GET_SECURE_USERINFO_CALLBACK_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)idmGetSecureUserInfoCallbackService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(GET_SECURE_USERINFO_CALLBACK_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)idmGetSecureUserInfoCallbackService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} - -void UserIdmClientFuzzTest(const uint8_t *data, size_t size) -{ - FuzzIdmCallbackStub(data, size); - FuzzIdmGetInfoCallbackStub(data, size); - FuzzIdmGetSecureUserInfoCallbackstub(data, size); - return; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - OHOS::UserIam::UserAuth::UserIdmClientFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/clients/widgetcallbackstub_fuzzer/BUILD.gn b/test/fuzztest/clients/widgetcallbackstub_fuzzer/BUILD.gn deleted file mode 100644 index 850843d36b1ab89052a81151bf1c886982b2d4ef..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/widgetcallbackstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,90 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/ohos.gni") -import("//build/test.gni") - -ohos_fuzztest("WidgetCallbackStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../widgetcallbackstub_fuzzer" - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - include_dirs = [ - "../../../../interfaces/inner_api", - "../../../../frameworks/js/napi/user_auth/inc", - "../../../../frameworks/native/client/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/common/dfx/inc", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ - "../../../../frameworks/native/client/src/auth_message_impl.cpp", - "../../../../frameworks/native/client/src/callback_manager_impl.cpp", - "../../../../frameworks/native/client/src/co_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/executor_callback_service.cpp", - "../../../../frameworks/native/client/src/executor_messenger_client.cpp", - "../../../../frameworks/native/client/src/ipc_client_utils.cpp", - "../../../../frameworks/native/client/src/load_mode_client_util.cpp", - "../../../../frameworks/native/client/src/modal_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_callback_service.cpp", - "../../../../frameworks/native/client/src/user_auth_client_impl.cpp", - "../../../../frameworks/native/client/src/user_auth_modal_inner_callback.cpp", - "../../../../frameworks/native/client/src/user_idm_callback_service.cpp", - "../../../../frameworks/native/client/src/user_idm_client_impl.cpp", - "../../../../frameworks/native/client/src/widget_callback_service.cpp", - "widget_callback_stub_fuzzer.cpp", - ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:dfx_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_client_ipc_fuzzer", - ] - - remove_configs = [ "//build/config/compiler:no_exceptions" ] - - external_deps = [ - "ability_runtime:ability_context_native", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_context", - "ability_runtime:napi_base_context", - "ability_runtime:ui_extension", - "access_token:libaccesstoken_sdk", - "ace_engine:ace_uicontent", - "hilog:libhilog", - "init:libbeget_proxy", - "init:libbegetutil", - "ipc:ipc_single", - "napi:ace_napi", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "user_auth_framework:userauth_client", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/clients/widgetcallbackstub_fuzzer/corpus/init b/test/fuzztest/clients/widgetcallbackstub_fuzzer/corpus/init deleted file mode 100644 index 65af8ee8d11bf23407ea34d4de49f7cbb6a2b791..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/widgetcallbackstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2025 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/clients/widgetcallbackstub_fuzzer/project.xml b/test/fuzztest/clients/widgetcallbackstub_fuzzer/project.xml deleted file mode 100644 index 66e1dcac475475fb101b6f8670ec699e6e9696aa..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/widgetcallbackstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/clients/widgetcallbackstub_fuzzer/widget_callback_stub_fuzzer.cpp b/test/fuzztest/clients/widgetcallbackstub_fuzzer/widget_callback_stub_fuzzer.cpp deleted file mode 100644 index 9427a0bf04037d2cea05b693c34e6cb7ad5c9cc2..0000000000000000000000000000000000000000 --- a/test/fuzztest/clients/widgetcallbackstub_fuzzer/widget_callback_stub_fuzzer.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "widget_callback_stub_fuzzer.h" - -#include "parcel.h" - -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "iam_ptr.h" -#include "widget_callback_service.h" - -#define LOG_TAG "USER_AUTH_SA" - -using namespace std; - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t WIDGET_CALLBACK_CODE_MIN = 0; -constexpr uint32_t WIDGET_CALLBACK_CODE_MAX = 100; -const std::u16string WIDGET_CALLBACK_INTERFACE_TOKEN = u"ohos.UserIam.UserAuth.WidgetCallback"; - -class DummyIUserAuthWidgetCallback final : public IUserAuthWidgetCallback { -public: - void SendCommand(const std::string &cmdData) - { - IAM_LOGI("start"); - static_cast(cmdData); - } -}; - -bool WidgetCallbackStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - auto service = - Common::MakeShared(Common::MakeShared()); - for (uint32_t code = WIDGET_CALLBACK_CODE_MIN; code < WIDGET_CALLBACK_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(WIDGET_CALLBACK_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)service->OnRemoteRequest(code, data, reply, optionSync); - // Async - (void)service->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - OHOS::UserIam::UserAuth::WidgetCallbackStubFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/common_fuzzer/BUILD.gn b/test/fuzztest/common_fuzzer/BUILD.gn index 8a56425e2b46fead6de3d76813f0fe43488e40f5..72cb5d15cef83e18d331d93424b1cb500653b303 100644 --- a/test/fuzztest/common_fuzzer/BUILD.gn +++ b/test/fuzztest/common_fuzzer/BUILD.gn @@ -69,48 +69,6 @@ ohos_source_set("dfx_fuzzer") { part_name = "user_auth_framework" } -ohos_source_set("userauth_client_ipc_fuzzer") { - branch_protector_ret = "pac_ret" - include_dirs = [ - "../../../frameworks/native/ipc/inc", - "../../../frameworks/native/ipc/common_defines", - "../../../interfaces/inner_api", - ] - - sources = [ - "../../../frameworks/native/ipc/src/co_auth_proxy.cpp", - "../../../frameworks/native/ipc/src/executor_callback_stub.cpp", - "../../../frameworks/native/ipc/src/executor_messenger_proxy.cpp", - "../../../frameworks/native/ipc/src/modal_callback_stub.cpp", - "../../../frameworks/native/ipc/src/user_access_ctrl_callback_stub.cpp", - "../../../frameworks/native/ipc/src/user_auth_callback_stub.cpp", - "../../../frameworks/native/ipc/src/user_auth_event_listener_stub.cpp", - "../../../frameworks/native/ipc/src/user_auth_proxy.cpp", - "../../../frameworks/native/ipc/src/user_idm_callback_stub.cpp", - "../../../frameworks/native/ipc/src/user_idm_proxy.cpp", - "../../../frameworks/native/ipc/src/widget_callback_stub.cpp", - ] - - configs = [ - "../../../common:iam_log_config", - "../../../common:iam_utils_config", - ] - - public_configs = - [ "../../../frameworks/native/ipc:userauth_client_ipc_config" ] - remove_configs = [ "//build/config/compiler:no_exceptions" ] - - external_deps = [ - "c_utils:utils", - "hicollie:libhicollie", - "hilog:libhilog", - "ipc:ipc_single", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} - ohos_source_set("userauth_service_base_fuzzer") { branch_protector_ret = "pac_ret" include_dirs = [ "../../../services/base/inc" ] @@ -161,12 +119,12 @@ ohos_source_set("userauth_service_core_fuzzer") { remove_configs = [ "//build/config/compiler:no_exceptions" ] sources = [ - "../../../services/core/src/auth_event_listener_manager.cpp", "../../../services/core/src/authentication_impl.cpp", "../../../services/core/src/credential_info_impl.cpp", "../../../services/core/src/driver_state_manager.cpp", "../../../services/core/src/enrolled_info_impl.cpp", "../../../services/core/src/enrollment_impl.cpp", + "../../../services/core/src/event_listener_manager.cpp", "../../../services/core/src/identification_impl.cpp", "../../../services/core/src/publish_event_adapter_mock.cpp", "../../../services/core/src/remote_executor_proxy.cpp", @@ -317,48 +275,6 @@ ohos_source_set("userauth_service_context_fuzzer") { part_name = "user_auth_framework" } -ohos_source_set("userauth_service_ipc_fuzzer") { - branch_protector_ret = "pac_ret" - include_dirs = [ - "../../../frameworks/native/ipc/inc", - "../../../frameworks/native/ipc/common_defines", - "../../../interfaces/inner_api", - ] - - sources = [ - "../../../frameworks/native/ipc/src/co_auth_stub.cpp", - "../../../frameworks/native/ipc/src/executor_callback_proxy.cpp", - "../../../frameworks/native/ipc/src/executor_messenger_stub.cpp", - "../../../frameworks/native/ipc/src/modal_callback_proxy.cpp", - "../../../frameworks/native/ipc/src/user_access_ctrl_callback_proxy.cpp", - "../../../frameworks/native/ipc/src/user_auth_callback_proxy.cpp", - "../../../frameworks/native/ipc/src/user_auth_event_listener_proxy.cpp", - "../../../frameworks/native/ipc/src/user_auth_stub.cpp", - "../../../frameworks/native/ipc/src/user_idm_callback_proxy.cpp", - "../../../frameworks/native/ipc/src/user_idm_stub.cpp", - "../../../frameworks/native/ipc/src/widget_callback_proxy.cpp", - ] - - configs = [ - "../../../common:iam_log_config", - "../../../common:iam_utils_config", - ] - - public_configs = - [ "../../../frameworks/native/ipc:userauth_client_ipc_config" ] - remove_configs = [ "//build/config/compiler:no_exceptions" ] - - external_deps = [ - "c_utils:utils", - "hicollie:libhicollie", - "hilog:libhilog", - "ipc:ipc_single", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} - ohos_source_set("userauth_service_remote_connect_fuzzer") { include_dirs = [ "inc" ] @@ -429,12 +345,15 @@ ohos_source_set("userauth_services_ipc_fuzzer") { "../dummy/mock_ipc_common.cpp", ] + public_configs = + [ "../../../frameworks/native/ipc:userauth_client_ipc_config" ] + deps = [ + "../../../frameworks/native/ipc:userauth_service_ipc_fuzzer", "../common_fuzzer:attributes_fuzzer", "../common_fuzzer:dfx_fuzzer", "../common_fuzzer:iam_utils_fuzzer", "../common_fuzzer:userauth_service_context_fuzzer", - "../common_fuzzer:userauth_service_ipc_fuzzer", "../common_fuzzer:userauth_service_remote_connect_fuzzer", ] diff --git a/test/fuzztest/dummy/dummy_executor_callback_interface.h b/test/fuzztest/dummy/dummy_executor_callback_interface.h index 65cf794566751161bf266d5192bca20e838023e6..7d7b7c2f21b7df532b76206b272d32f52917cbb8 100644 --- a/test/fuzztest/dummy/dummy_executor_callback_interface.h +++ b/test/fuzztest/dummy/dummy_executor_callback_interface.h @@ -16,7 +16,7 @@ #ifndef DUMMY_EXECUTOR_CALLBACK_INTERFACE_H #define DUMMY_EXECUTOR_CALLBACK_INTERFACE_H -#include "executor_callback_interface.h" +#include "iexecutor_callback.h" #undef private @@ -24,28 +24,31 @@ namespace OHOS { namespace UserIam { namespace UserAuth { namespace { -class DummyExecutorCallbackInterface : public ExecutorCallbackInterface { +class DummyExecutorCallbackInterface : public IExecutorCallback { public: - void OnMessengerReady(sptr &messenger, - const std::vector &publicKey, const std::vector &templateIdList){}; + int32_t OnMessengerReady(const sptr &messenger, + const std::vector &publicKey, const std::vector &templateIdList) + { + return 0; + }; int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) + const std::vector &command) { return 0; }; - int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) + int32_t OnEndExecute(uint64_t scheduleId, const std::vector &command) { return 0; }; - int32_t OnSetProperty(const Attributes &properties) + int32_t OnSetProperty(const std::vector &properties) { return 0; }; - int32_t OnGetProperty(const Attributes &condition, Attributes &values) + int32_t OnGetProperty(const std::vector &condition, std::vector &values) { return 0; }; - int32_t OnSendData(uint64_t scheduleId, const Attributes &data) + int32_t OnSendData(uint64_t scheduleId, const std::vector &data) { return 0; }; diff --git a/test/fuzztest/dummy/dummy_iam_callback_interface.h b/test/fuzztest/dummy/dummy_iam_callback_interface.h index a8f1cb3d79aac5f021ef821e4c3b0a8f04946828..75460136b8cde8687b1a78eca3ed2d77296bfd74 100644 --- a/test/fuzztest/dummy/dummy_iam_callback_interface.h +++ b/test/fuzztest/dummy/dummy_iam_callback_interface.h @@ -16,7 +16,7 @@ #ifndef DUMMY_IAM_CALLBACK_INTERFACE_H #define DUMMY_IAM_CALLBACK_INTERFACE_H -#include "iam_callback_interface.h" +#include "iiam_callback.h" #undef private @@ -24,11 +24,15 @@ namespace OHOS { namespace UserIam { namespace UserAuth { namespace { -class DummyIamCallbackInterface : public IamCallbackInterface { - void OnResult(int32_t result, const Attributes &extraInfo) override - {}; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override - {}; +class DummyIamCallbackInterface : public IIamCallback { + int32_t OnResult(int32_t result, const std::vector &extraInfo) override + { + return 0; + }; + int32_t OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) override + { + return 0; + }; sptr AsObject() override { return nullptr; diff --git a/test/fuzztest/dummy/dummy_resource_node.h b/test/fuzztest/dummy/dummy_resource_node.h index f6ee7bae4fad85711bc7dcaf08b6abfc0531b6cc..bfad02aac9e59bbcf2c7632146a57666fbb7844b 100644 --- a/test/fuzztest/dummy/dummy_resource_node.h +++ b/test/fuzztest/dummy/dummy_resource_node.h @@ -93,14 +93,14 @@ public: {}; static std::shared_ptr MakeNewResource(const ExecutorRegisterInfo &info, - const std::shared_ptr &callback, std::vector &templateIdList, + const std::shared_ptr &callback, std::vector &templateIdList, std::vector &fwkPublicKey) { return nullptr; }; static std::shared_ptr CreateWithExecuteIndex(uint64_t executorId, AuthType authType, - ExecutorRole executorRole, ExecutorCallbackInterface &callback) + ExecutorRole executorRole, IExecutorCallback &callback) { auto node = std::make_shared(); return node; diff --git a/test/fuzztest/services/BUILD.gn b/test/fuzztest/services/BUILD.gn index 3810147e855ee4a6d7c82ac691bd56923dd2764b..ed2ce2c8ff000e115d6a22e0a1e5e6fce1c21028 100644 --- a/test/fuzztest/services/BUILD.gn +++ b/test/fuzztest/services/BUILD.gn @@ -18,7 +18,6 @@ group("iam_services_fuzztest") { testonly = true deps = [ "coauthservice_fuzzer:CoAuthServiceFuzzTest", - "coauthstub_fuzzer:CoAuthStubFuzzTest", "context/contextcallbackimpl_fuzzer:ContextCallbackImplFuzzTest", "context/contextpoolimpl_fuzzer:ContextPoolImplFuzzTest", "context/remoteauthcontext_fuzzer:RemoteAuthContextFuzzTest", @@ -27,8 +26,6 @@ group("iam_services_fuzztest") { "softbus_fuzzer:SoftBusFuzzTest", "templatecachemanager_fuzzer:TemplateCacheManagerFuzzTest", "userauthservice_fuzzer:UserAuthServiceFuzzTest", - "userauthstub_fuzzer:UserAuthStubFuzzTest", "useridmservice_fuzzer:UserIdmServiceFuzzTest", - "useridmstub_fuzzer:UserIdmStubFuzzTest", ] } diff --git a/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp b/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp index 23d93e7f9db610d9a41f3e1af8c4818a68369ca9..5dabe6ff90ff468e29305e9768d807e78a11ac5c 100644 --- a/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp +++ b/test/fuzztest/services/coauthservice_fuzzer/co_auth_service_fuzzer.cpp @@ -20,7 +20,7 @@ #include "co_auth_service.h" #include "executor_messenger_service.h" -#include "executor_callback_interface.h" +#include "iexecutor_callback.h" #include "mock_ipc_common.h" #include "iam_fuzz_test.h" #include "iam_logger.h" @@ -44,7 +44,7 @@ std::u16string cmd[] = {u"-h", u"-lc", u"-ls", u"-c", u"-c [base system]", u"-s" u"-e", u"--net", u"--storage", u"-p", u"-p [pid]", u"--cpuusage [pid]", u"cified pid", u"--cpufreq", u"--mem [pid]", u"--zip", u"--mem-smaps pid [-v]"}; -class CoAuthServiceFuzzer : public ExecutorCallbackInterface { +class CoAuthServiceFuzzer : public IExecutorCallback { public: CoAuthServiceFuzzer(int32_t onBeginExecuteResult, int32_t onEndExecuteResult, int32_t onSetPropertyResult, int32_t onGetPropertyResult, int32_t onSendDataResult) @@ -58,39 +58,39 @@ public: virtual ~CoAuthServiceFuzzer() = default; - void OnMessengerReady(sptr &messenger, + int32_t OnMessengerReady(const sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) override { IAM_LOGI("start"); - return; + return SUCCESS; } int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) override + const std::vector &command) override { IAM_LOGI("start"); return onBeginExecuteResult_; } - int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) override + int32_t OnEndExecute(uint64_t scheduleId, const std::vector &command) override { IAM_LOGI("start"); return onEndExecuteResult_; } - int32_t OnSetProperty(const Attributes &properties) override + int32_t OnSetProperty(const std::vector &properties) override { IAM_LOGI("start"); return onSetPropertyResult_; } - int32_t OnGetProperty(const Attributes &condition, Attributes &values) override + int32_t OnGetProperty(const std::vector &condition, std::vector &values) override { IAM_LOGI("start"); return onGetPropertyResult_; } - int32_t OnSendData(uint64_t scheduleId, const Attributes &data) override + int32_t OnSendData(uint64_t scheduleId, const std::vector &data) override { IAM_LOGI("start"); return onSendDataResult_; @@ -110,7 +110,7 @@ private: int32_t onSendDataResult_; }; -void FillFuzzExecutorRegisterInfo(Parcel &parcel, ExecutorRegisterInfo &executorInfo) +void FillFuzzExecutorRegisterInfo(Parcel &parcel, IpcExecutorRegisterInfo &executorInfo) { executorInfo.authType = static_cast(parcel.ReadInt32()); executorInfo.executorRole = static_cast(parcel.ReadInt32()); @@ -127,15 +127,16 @@ sptr executorMessengerService = ExecutorMessengerServi void FuzzRegister(Parcel &parcel) { IAM_LOGI("FuzzRegister begin"); - ExecutorRegisterInfo executorInfo; + IpcExecutorRegisterInfo executorInfo; FillFuzzExecutorRegisterInfo(parcel, executorInfo); - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) + callback = sptr(new (std::nothrow) CoAuthServiceFuzzer(parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadInt32())); } - g_coAuthService->ExecutorRegister(executorInfo, callback); + uint64_t executorIndex = 0; + g_coAuthService->ExecutorRegister(executorInfo, callback, executorIndex); IAM_LOGI("FuzzRegister end"); } @@ -177,7 +178,7 @@ void FuzzFinish(Parcel &parcel) auto finalResult = Common::MakeShared(); if (executorMessengerService != nullptr) { - executorMessengerService->Finish(scheduleId, resultCode, finalResult); + executorMessengerService->Finish(scheduleId, resultCode, finalResult->Serialize()); } IAM_LOGI("FuzzFinish end"); } diff --git a/test/fuzztest/services/coauthstub_fuzzer/BUILD.gn b/test/fuzztest/services/coauthstub_fuzzer/BUILD.gn deleted file mode 100644 index c588b0a37911b7822ab8f51c344ae356e5938de8..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/coauthstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/test.gni") - -ohos_fuzztest("CoAuthStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../coauthstub_fuzzer" - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - include_dirs = [ - "../../../../services/base/inc", - "../../../../services/core/inc", - "../../../../services/core/src", - "../../../../services/context/inc", - "../../../../services/ipc/inc", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ "co_auth_stub_fuzzer.cpp" ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:iam_utils_fuzzer", - "../../common_fuzzer:userauth_services_ipc_fuzzer", - ] - - external_deps = [ - "c_utils:utils", - "drivers_interface_user_auth:libuser_auth_proxy_3.0", - "eventhandler:libeventhandler", - "hdf_core:libhdi", - "hilog:libhilog", - "ipc:ipc_single", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.cpp b/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.cpp deleted file mode 100644 index a500574fd1a369f95da08fb75e1d53fd8f5caa96..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/coauthstub_fuzzer/co_auth_stub_fuzzer.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "co_auth_stub_fuzzer.h" - -#include -#include -#include - -#include "parcel.h" - -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "co_auth_service.h" -#include "executor_messenger_service.h" - -#define LOG_TAG "USER_AUTH_SA" - -using namespace std; - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t CO_AUTH_CODE_MIN = 0; -constexpr uint32_t CO_AUTH_CODE_MAX = 6; -const std::u16string CO_AUTH_INTERFACE_TOKEN = u"ohos.CoAuth.ICoAuth"; -constexpr uint32_t EXECUTOR_MESSENGER_CODE_MIN = 0; -constexpr uint32_t EXECUTOR_MESSENGER_CODE_MAX = 3; -const std::u16string EXECUTOR_MESSENGER_INTERFACE_TOKEN = u"ohos.UserIam.AuthResPool.IExecutor_Messenger"; - -bool FuzzCoAuthStub(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - CoAuthService coAuthService; - for (uint32_t code = CO_AUTH_CODE_MIN; code < CO_AUTH_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(CO_AUTH_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)coAuthService.OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(CO_AUTH_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)coAuthService.OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} - -bool FuzzExecutorMessengerStub(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - sptr executorMessengerService = ExecutorMessengerService::GetInstance(); - - if (executorMessengerService == nullptr) { - IAM_LOGE("executor messenger service is null"); - return false; - } - - for (uint32_t code = EXECUTOR_MESSENGER_CODE_MIN; code < EXECUTOR_MESSENGER_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(EXECUTOR_MESSENGER_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)executorMessengerService->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(EXECUTOR_MESSENGER_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)executorMessengerService->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} - -void CoAuthStubFuzzTest(const uint8_t *data, size_t size) -{ - FuzzCoAuthStub(data, size); - FuzzExecutorMessengerStub(data, size); - return; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::UserIam::UserAuth::CoAuthStubFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/coauthstub_fuzzer/corpus/init b/test/fuzztest/services/coauthstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/coauthstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/coauthstub_fuzzer/project.xml b/test/fuzztest/services/coauthstub_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/coauthstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/services/context/remoteauthcontext_fuzzer/remote_auth_context_fuzzer.cpp b/test/fuzztest/services/context/remoteauthcontext_fuzzer/remote_auth_context_fuzzer.cpp index 4b40caea8bda657c37c9b11872c4f1dec34f0116..01a4e6d9eb9b6483dbaf502681d0656c2fa8a8ac 100644 --- a/test/fuzztest/services/context/remoteauthcontext_fuzzer/remote_auth_context_fuzzer.cpp +++ b/test/fuzztest/services/context/remoteauthcontext_fuzzer/remote_auth_context_fuzzer.cpp @@ -179,11 +179,11 @@ void RemoteIamCallbackFuzzTest(Parcel &parcel) auto remoteCallback = MakeShared(connectionName); int32_t result = parcel.ReadInt32(); Attributes extraInfo; - remoteCallback->OnResult(result, extraInfo); + remoteCallback->OnResult(result, extraInfo.Serialize()); int32_t module = parcel.ReadInt32(); int32_t acquireInfo = parcel.ReadInt32(); - remoteCallback->OnAcquireInfo(module, acquireInfo, extraInfo); + remoteCallback->OnAcquireInfo(module, acquireInfo, extraInfo.Serialize()); remoteCallback->AsObject(); IAM_LOGI("end"); diff --git a/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp b/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp index 9f7a52bec029716bfe53d10bcdf660e88eb83a5e..960b56add8a0dfa01daf68296d1521a7dbecc790 100644 --- a/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp +++ b/test/fuzztest/services/servicecore_fuzzer/src/resource_node_fuzzer.cpp @@ -26,19 +26,20 @@ namespace OHOS { namespace UserIam { namespace UserAuth { namespace { -class DummyExecutorCallbackInterface final : public ExecutorCallbackInterface { +class DummyExecutorCallbackInterface final : public IExecutorCallback { public: - void OnMessengerReady(sptr &messenger, + int32_t OnMessengerReady(const sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) override { IAM_LOGI("start"); static_cast(messenger); static_cast(publicKey); static_cast(templateIdList); + return SUCCESS; } int32_t OnBeginExecute(uint64_t scheduleId, const std::vector &publicKey, - const Attributes &command) override + const std::vector &command) override { IAM_LOGI("start"); static_cast(scheduleId); @@ -47,7 +48,7 @@ public: return SUCCESS; } - int32_t OnEndExecute(uint64_t scheduleId, const Attributes &command) override + int32_t OnEndExecute(uint64_t scheduleId, const std::vector &command) override { IAM_LOGI("start"); static_cast(scheduleId); @@ -55,14 +56,14 @@ public: return SUCCESS; } - int32_t OnSetProperty(const Attributes &properties) override + int32_t OnSetProperty(const std::vector &properties) override { IAM_LOGI("start"); static_cast(properties); return SUCCESS; } - int32_t OnGetProperty(const Attributes &condition, Attributes &values) override + int32_t OnGetProperty(const std::vector &condition, std::vector &values) override { IAM_LOGI("start"); static_cast(condition); @@ -70,7 +71,7 @@ public: return SUCCESS; } - int32_t OnSendData(uint64_t scheduleId, const Attributes &data) override + int32_t OnSendData(uint64_t scheduleId, const std::vector &data) override { IAM_LOGI("start"); static_cast(scheduleId); diff --git a/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp b/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp index 0965ede14df645c8529d22fa04d768ef339e72c2..179283781bcbcbf2bb28bea167d58180dc4efc51 100644 --- a/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp +++ b/test/fuzztest/services/userauthservice_fuzzer/user_auth_service_fuzzer.cpp @@ -25,7 +25,6 @@ #include "iam_logger.h" #include "user_auth_service.h" #include "user_auth_common_defines.h" -#include "user_auth_event_listener_stub.h" #include "dummy_iam_callback_interface.h" #undef private @@ -43,25 +42,25 @@ namespace OHOS { namespace UserIam { namespace UserAuth { namespace { -class DummyUserAuthCallback : public UserAuthCallbackInterface { +class DummyUserAuthCallback : public IIamCallback { public: ~DummyUserAuthCallback() override = default; - void OnAcquireInfo(int32_t module, int32_t acquireInfo, const Attributes &extraInfo) override + int32_t OnAcquireInfo(int32_t module, int32_t acquireInfo, const std::vector &extraInfo) override { IAM_LOGI("start"); static_cast(module); static_cast(acquireInfo); static_cast(extraInfo); - return; + return SUCCESS; } - void OnResult(int32_t result, const Attributes &extraInfo) override + int32_t OnResult(int32_t result, const std::vector &extraInfo) override { IAM_LOGI("start"); static_cast(result); static_cast(extraInfo); - return; + return SUCCESS; } sptr AsObject() override @@ -71,14 +70,14 @@ public: } }; -class DummyGetExecutorPropertyCallback : public GetExecutorPropertyCallbackInterface { +class DummyGetExecutorPropertyCallback : public IGetExecutorPropertyCallback { public: ~DummyGetExecutorPropertyCallback() override = default; - void OnGetExecutorPropertyResult(int32_t result, const Attributes &attributes) override + int32_t OnGetExecutorPropertyResult(int32_t result, const std::vector &attributes) override { IAM_LOGI("start"); - return; + return SUCCESS; } sptr AsObject() override @@ -88,14 +87,14 @@ public: } }; -class DummySetExecutorPropertyCallback : public SetExecutorPropertyCallbackInterface { +class DummySetExecutorPropertyCallback : public ISetExecutorPropertyCallback { public: ~DummySetExecutorPropertyCallback() override = default; - void OnSetExecutorPropertyResult(int32_t result) override + int32_t OnSetExecutorPropertyResult(int32_t resultCode) override { IAM_LOGI("start"); - return; + return SUCCESS; } sptr AsObject() override @@ -105,11 +104,12 @@ public: } }; -class DummyWidgetCallback : public WidgetCallbackInterface { +class DummyWidgetCallback : public IWidgetCallback { public: - void SendCommand(const std::string &cmdData) override + int32_t SendCommand(const std::string &cmdData) override { IAM_LOGI("start"); + return SUCCESS; } sptr AsObject() override @@ -119,7 +119,7 @@ public: } }; -class DummyAuthEventListener : public AuthEventListenerInterface { +class DummyAuthEventListener : public IEventListenerCallback { public: ~DummyAuthEventListener() override = default; @@ -129,22 +129,28 @@ public: return tmp; } - void OnNotifyAuthSuccessEvent(int32_t userId, AuthType authType, int32_t callerType, - std::string &callerName) override + int32_t OnNotifyAuthSuccessEvent(int32_t userId, int32_t authType, int32_t callerType, + const std::string &callerName) override { - IAM_LOGI("notify: userId: %{public}d, authType: %{public}d, callerName: %{public}s," - "callerType: %{public}d", userId, static_cast(authType), callerName.c_str(), callerType); + IAM_LOGI("start"); + return SUCCESS; + } + int32_t OnNotifyCredChangeEvent(int32_t userId, int32_t authType, int32_t eventType, + uint64_t credentialId) override + { + IAM_LOGI("start"); + return SUCCESS; } }; -class DummyVerifyTokenCallback : public VerifyTokenCallbackInterface { +class DummyVerifyTokenCallback : public IVerifyTokenCallback { public: ~DummyVerifyTokenCallback() override = default; - void OnVerifyTokenResult(int32_t result, const Attributes &attributes) override + int32_t OnVerifyTokenResult(int32_t result, const std::vector &attributes) override { IAM_LOGI("start"); - return; + return SUCCESS; } sptr AsObject() override @@ -160,8 +166,8 @@ void FuzzGetEnrolledState(Parcel &parcel) { IAM_LOGI("begin"); int32_t apiVersion = parcel.ReadInt32(); - AuthType authType = static_cast(parcel.ReadInt32()); - EnrolledState enrolledState = {}; + int32_t authType = parcel.ReadInt32(); + IpcEnrolledState enrolledState = {}; g_userAuthService.GetEnrolledState(apiVersion, authType, enrolledState); IAM_LOGI("end"); } @@ -171,10 +177,9 @@ void FuzzGetAvailableStatusOtherScene(Parcel &parcel) IAM_LOGI("begin"); int32_t apiVersion = 8; int32_t pin = 1; - AuthType authType = static_cast(pin); - AuthTrustLevel authTrustLevel = static_cast(parcel.ReadInt32()); + int32_t authTrustLevel = parcel.ReadInt32(); int32_t userId = parcel.ReadInt32(); - g_userAuthService.GetAvailableStatus(apiVersion, userId, authType, authTrustLevel); + g_userAuthService.GetAvailableStatus(apiVersion, userId, pin, authTrustLevel); IAM_LOGI("end"); } @@ -182,8 +187,8 @@ void FuzzGetAvailableStatus(Parcel &parcel) { IAM_LOGI("begin"); int32_t apiVersion = parcel.ReadInt32(); - AuthType authType = static_cast(parcel.ReadInt32()); - AuthTrustLevel authTrustLevel = static_cast(parcel.ReadInt32()); + int32_t authType = parcel.ReadInt32(); + int32_t authTrustLevel = parcel.ReadInt32(); int32_t userId = parcel.ReadInt32(); g_userAuthService.GetAvailableStatus(apiVersion, userId, authType, authTrustLevel); FuzzGetAvailableStatusOtherScene(parcel); @@ -195,17 +200,17 @@ void FuzzGetProperty(Parcel &parcel) IAM_LOGI("begin"); constexpr uint32_t maxDataLen = 50; int32_t userId = parcel.ReadInt32(); - AuthType authType = static_cast(parcel.ReadInt32()); - std::vector keys; + int32_t authType = parcel.ReadInt32(); + std::vector keys; uint32_t keysLen = parcel.ReadUint32() % maxDataLen; keys.reserve(keysLen); for (uint32_t i = 0; i < keysLen; i++) { - keys.emplace_back(static_cast(parcel.ReadInt32())); + keys.emplace_back(parcel.ReadUint32()); } - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) DummyGetExecutorPropertyCallback()); + callback = sptr(new (std::nothrow) DummyGetExecutorPropertyCallback()); } g_userAuthService.GetProperty(userId, authType, keys, callback); IAM_LOGI("end"); @@ -219,12 +224,12 @@ void FuzzSetProperty(Parcel &parcel) vector attributesRaw; FillFuzzUint8Vector(parcel, attributesRaw); Attributes attributes(attributesRaw); - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (nothrow) DummySetExecutorPropertyCallback()); + callback = sptr(new (nothrow) DummySetExecutorPropertyCallback()); } - g_userAuthService.SetProperty(userId, authType, attributes, callback); + g_userAuthService.SetProperty(userId, authType, attributes.Serialize(), callback); IAM_LOGI("end"); } @@ -234,13 +239,16 @@ void FuzzAuth(Parcel &parcel) int32_t apiVersion = parcel.ReadInt32(); std::vector challenge; FillFuzzUint8Vector(parcel, challenge); - AuthType authType = static_cast(parcel.ReadInt32()); - AuthTrustLevel authTrustLevel = static_cast(parcel.ReadInt32()); - sptr callback(nullptr); + IpcAuthParamInner ipcAuthParamInner = {}; + ipcAuthParamInner.challenge = challenge; + ipcAuthParamInner.authType = parcel.ReadInt32(); + ipcAuthParamInner.authTrustLevel = parcel.ReadInt32(); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) DummyUserAuthCallback()); + callback = sptr(new (std::nothrow) DummyUserAuthCallback()); } - g_userAuthService.Auth(apiVersion, challenge, authType, authTrustLevel, callback); + uint64_t contextId = 0; + g_userAuthService.Auth(apiVersion, ipcAuthParamInner, callback, contextId); IAM_LOGI("end"); } @@ -249,18 +257,21 @@ void FuzzAuthUser(Parcel &parcel) IAM_LOGI("begin"); std::vector challenge; FillFuzzUint8Vector(parcel, challenge); - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (nothrow) DummyUserAuthCallback()); + callback = sptr(new (nothrow) DummyUserAuthCallback()); } - AuthParamInner param = { + IpcAuthParamInner param = { .userId = parcel.ReadInt32(), .challenge = challenge, - .authType = static_cast(parcel.ReadInt32()), - .authTrustLevel = static_cast(parcel.ReadInt32()), + .authType = parcel.ReadInt32(), + .authTrustLevel = parcel.ReadInt32(), }; - std::optional remoteAuthParam = std::nullopt; - g_userAuthService.AuthUser(param, remoteAuthParam, callback); + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = false, + }; + uint64_t contextId = 0; + g_userAuthService.AuthUser(param, remoteAuthParam, callback, contextId); IAM_LOGI("end"); } @@ -269,12 +280,13 @@ void FuzzIdentify(Parcel &parcel) IAM_LOGI("begin"); std::vector challenge; FillFuzzUint8Vector(parcel, challenge); - AuthType authType = static_cast(parcel.ReadInt32()); - sptr callback(nullptr); + int32_t authType = parcel.ReadInt32(); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (nothrow) DummyUserAuthCallback()); + callback = sptr(new (nothrow) DummyUserAuthCallback()); } - g_userAuthService.Identify(challenge, authType, callback); + uint64_t contextId = 0; + g_userAuthService.Identify(challenge, authType, callback, contextId); IAM_LOGI("end"); } @@ -299,31 +311,29 @@ void FuzzAuthWidget(Parcel &parcel) { IAM_LOGI("begin"); int32_t apiVersion = parcel.ReadInt32(); - AuthParamInner authParam; - WidgetParamInner widgetParam; + IpcAuthParamInner authParam; + IpcWidgetParamInner widgetParam; FillFuzzUint8Vector(parcel, authParam.challenge); std::vector atList; - parcel.ReadInt32Vector(&atList); - for (auto at : atList) { - authParam.authTypes.push_back(static_cast(at)); - } - authParam.authTrustLevel = static_cast(parcel.ReadInt32()); - sptr callback(nullptr); + parcel.ReadInt32Vector(&authParam.authTypes); + authParam.authTrustLevel = parcel.ReadInt32(); + sptr callback(nullptr); widgetParam.title = parcel.ReadString(); widgetParam.navigationButtonText = parcel.ReadString(); - widgetParam.windowMode = static_cast(parcel.ReadInt32()); + widgetParam.windowMode = parcel.ReadInt32(); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) DummyUserAuthCallback()); + callback = sptr(new (std::nothrow) DummyUserAuthCallback()); } - sptr testModalCallback(nullptr); - g_userAuthService.AuthWidget(apiVersion, authParam, widgetParam, callback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + g_userAuthService.AuthWidget(apiVersion, authParam, widgetParam, callback, testModalCallback, contextId); IAM_LOGI("end"); } void FuzzNotice(Parcel &parcel) { IAM_LOGI("begin"); - NoticeType noticeType = static_cast(parcel.ReadInt32()); + int32_t noticeType = parcel.ReadInt32(); std::string eventData = parcel.ReadString(); g_userAuthService.Notice(noticeType, eventData); IAM_LOGI("end"); @@ -333,9 +343,9 @@ void FuzzRegisterWidgetCallback(Parcel &parcel) { IAM_LOGI("begin"); int32_t version = parcel.ReadInt32(); - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) DummyWidgetCallback()); + callback = sptr(new (std::nothrow) DummyWidgetCallback()); } g_userAuthService.RegisterWidgetCallback(version, callback); IAM_LOGI("end"); @@ -344,19 +354,12 @@ void FuzzRegisterWidgetCallback(Parcel &parcel) void FuzzRegistUserAuthSuccessEventListener(Parcel &parcel) { IAM_LOGI("begin"); - std::vector authType; - std::vector authTypeList; - parcel.ReadInt32Vector(&authType); - for (const auto &iter : authType) { - authTypeList.push_back(static_cast(iter)); - } - - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) DummyAuthEventListener()); + callback = sptr(new (std::nothrow) DummyAuthEventListener()); } - g_userAuthService.RegistUserAuthSuccessEventListener(authTypeList, callback); + g_userAuthService.RegistUserAuthSuccessEventListener(callback); g_userAuthService.UnRegistUserAuthSuccessEventListener(callback); IAM_LOGI("end"); } @@ -364,9 +367,9 @@ void FuzzRegistUserAuthSuccessEventListener(Parcel &parcel) void FuzzSetGlobalConfigParam(Parcel &parcel) { IAM_LOGI("start"); - GlobalConfigParam param = {}; + IpcGlobalConfigParam param = {}; param.value.pinExpiredPeriod = parcel.ReadUint64(); - param.type = static_cast(parcel.ReadInt32()); + param.type = parcel.ReadInt32(); g_userAuthService.SetGlobalConfigParam(param); IAM_LOGI("end"); } @@ -375,9 +378,9 @@ void FuzzPrepareRemoteAuth(Parcel &parcel) { IAM_LOGI("begin"); std::string networkId = parcel.ReadString(); - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (nothrow) DummyUserAuthCallback()); + callback = sptr(new (nothrow) DummyUserAuthCallback()); } g_userAuthService.PrepareRemoteAuth(networkId, callback); IAM_LOGI("end"); @@ -431,7 +434,7 @@ void FuzzGetAuthContextCallback(Parcel &parcel) int32_t apiVersion = parcel.ReadInt32(); AuthParamInner authParam = {}; WidgetParamInner widgetParam = {}; - sptr callback = sptr(new (nothrow) DummyUserAuthCallback); + sptr callback = sptr(new (nothrow) DummyUserAuthCallback); g_userAuthService.GetAuthContextCallback(apiVersion, authParam, widgetParam, callback); authParam.authTypes = {PIN, FACE, FINGERPRINT}; ReuseUnlockResult reuseUnlockResult = {}; @@ -487,7 +490,7 @@ void FuzzAuthRemoteUser(Parcel &parcel) }; Authentication::AuthenticationPara para = {}; RemoteAuthParam remoteAuthParam = {}; - sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); + sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); std::shared_ptr contextCallback = ContextCallback::NewInstance(iamCallback, TRACE_ADD_CREDENTIAL); ResultCode failReason = SUCCESS; g_userAuthService.AuthRemoteUser(authParam, para, remoteAuthParam, contextCallback, failReason); @@ -523,7 +526,7 @@ void FuzzFillGetPropertyKeys(Parcel &parcel) void FuzzStartWidgetContext(Parcel &parcel) { IAM_LOGI("begin"); - sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); + sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); std::shared_ptr contextCallback = ContextCallback::NewInstance(iamCallback, TRACE_ADD_CREDENTIAL); AuthParamInner authParam = {}; WidgetParamInner widgetParam = {}; @@ -538,7 +541,7 @@ void FuzzStartRemoteAuthInvokerContext(Parcel &parcel) IAM_LOGI("begin"); AuthParamInner authParam = {}; RemoteAuthInvokerContextParam param = {}; - sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); + sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); std::shared_ptr contextCallback = ContextCallback::NewInstance(iamCallback, TRACE_ADD_CREDENTIAL); g_userAuthService.StartRemoteAuthInvokerContext(authParam, param, contextCallback); IAM_LOGI("end"); @@ -549,7 +552,7 @@ void FuzzStartAuthContext(Parcel &parcel) IAM_LOGI("begin"); int32_t apiVersion = parcel.ReadInt32(); Authentication::AuthenticationPara para; - sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); + sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); std::shared_ptr contextCallback = ContextCallback::NewInstance(iamCallback, TRACE_ADD_CREDENTIAL); g_userAuthService.StartAuthContext(apiVersion, para, contextCallback, true); IAM_LOGI("end"); @@ -560,16 +563,16 @@ void FuzzGetPropertyById(Parcel &parcel) IAM_LOGI("begin"); constexpr uint32_t maxDataLen = 50; uint64_t credentialId = parcel.ReadUint64(); - std::vector keys; + std::vector keys; uint32_t keysLen = parcel.ReadUint32() % maxDataLen; keys.reserve(keysLen); for (uint32_t i = 0; i < keysLen; i++) { - keys.emplace_back(static_cast(parcel.ReadInt32())); + keys.emplace_back(parcel.ReadUint32()); } - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) DummyGetExecutorPropertyCallback()); + callback = sptr(new (std::nothrow) DummyGetExecutorPropertyCallback()); } g_userAuthService.GetPropertyById(credentialId, keys, callback); IAM_LOGI("end"); @@ -581,9 +584,9 @@ void FuzzVerifyAuthToken(Parcel &parcel) uint64_t allowableDuration = parcel.ReadUint64(); std::vector tokenIn = {}; Common::FillFuzzUint8Vector(parcel, tokenIn); - sptr callback(nullptr); + sptr callback(nullptr); if (parcel.ReadBool()) { - callback = sptr(new (std::nothrow) DummyVerifyTokenCallback()); + callback = sptr(new (std::nothrow) DummyVerifyTokenCallback()); } g_userAuthService.VerifyAuthToken(tokenIn, allowableDuration, callback); IAM_LOGI("end"); diff --git a/test/fuzztest/services/userauthstub_fuzzer/BUILD.gn b/test/fuzztest/services/userauthstub_fuzzer/BUILD.gn deleted file mode 100644 index 7b6c27faab2046eeb8756a1c0b6175f82e48ecfa..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/userauthstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/test.gni") - -ohos_fuzztest("UserAuthStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../userauthstub_fuzzer" - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - include_dirs = [ - "../../../../services/base/inc", - "../../../../services/core/inc", - "../../../../services/core/src", - "../../../../services/context/inc", - "../../../../services/ipc/inc", - "../../../../services/remote_connect/inc", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ "user_auth_stub_fuzzer.cpp" ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_services_ipc_fuzzer", - ] - - external_deps = [ - "ability_runtime:ability_context_native", - "ability_runtime:abilitykit_native", - "ability_runtime:app_manager", - "ability_runtime:extension_manager", - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "drivers_interface_user_auth:libuser_auth_proxy_3.0", - "eventhandler:libeventhandler", - "hdf_core:libhdi", - "hilog:libhilog", - "ipc:ipc_single", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/services/userauthstub_fuzzer/corpus/init b/test/fuzztest/services/userauthstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/userauthstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/userauthstub_fuzzer/project.xml b/test/fuzztest/services/userauthstub_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/userauthstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.cpp b/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.cpp deleted file mode 100644 index 6befa593d4bb8603a623118d2b6f44f32df8486b..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/userauthstub_fuzzer/user_auth_stub_fuzzer.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_stub_fuzzer.h" - -#include -#include -#include - -#include "parcel.h" - -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "user_auth_service.h" - -#define LOG_TAG "USER_AUTH_SA" - -using namespace std; - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t USER_AUTH_CODE_MIN = 0; -constexpr uint32_t USER_AUTH_CODE_MAX = 26; -const std::u16string USER_AUTH_INTERFACE_TOKEN = u"ohos.UserIam.UserAuth.IUserAuth"; - -bool UserAuthStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - auto service = UserAuthService::GetInstance(); - for (uint32_t code = USER_AUTH_CODE_MIN; code < USER_AUTH_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(USER_AUTH_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)service->OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(USER_AUTH_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)service->OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::UserIam::UserAuth::UserAuthStubFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/useridmservice_fuzzer/user_idm_service_fuzzer.cpp b/test/fuzztest/services/useridmservice_fuzzer/user_idm_service_fuzzer.cpp index 22b118b4daee47847aa10bef532008ab10c99f3b..2bf6406e9fd44d11078d05cc80aee3fdeafec218 100644 --- a/test/fuzztest/services/useridmservice_fuzzer/user_idm_service_fuzzer.cpp +++ b/test/fuzztest/services/useridmservice_fuzzer/user_idm_service_fuzzer.cpp @@ -19,11 +19,11 @@ #include "parcel.h" #include "securec.h" +#include "iam_callback_proxy.h" #include "iam_fuzz_test.h" #include "iam_logger.h" #include "iam_ptr.h" #include "user_idm_service.h" -#include "user_idm_callback_proxy.h" #include "dummy_iam_callback_interface.h" #undef private @@ -42,12 +42,12 @@ std::u16string cmd[] = {u"-h", u"-lc", u"-ls", u"-c", u"-c [base system]", u"-s" u"-e", u"--net", u"--storage", u"-p", u"-p [pid]", u"--cpuusage [pid]", u"cified pid", u"--cpufreq", u"--mem [pid]", u"--zip", u"--mem-smaps pid [-v]"}; -class DummyIdmGetCredentialInfoCallback : public IdmGetCredInfoCallbackInterface { +class DummyIdmGetCredentialInfoCallback : public IIdmGetCredInfoCallback { public: - void OnCredentialInfos(int32_t result, const std::vector &credInfoList) override + int32_t OnCredentialInfos(int32_t result, const std::vector &credInfoList) override { IAM_LOGI("start"); - return; + return SUCCESS; } sptr AsObject() override @@ -57,12 +57,12 @@ public: } }; -class DummyIdmGetSecureUserInfoCallback : public IdmGetSecureUserInfoCallbackInterface { +class DummyIdmGetSecureUserInfoCallback : public IIdmGetSecureUserInfoCallback { public: - void OnSecureUserInfo(int32_t result, const SecUserInfo &secUserInfo) override + int32_t OnSecureUserInfo(int32_t result, const IpcSecUserInfo &secUserInfo) override { IAM_LOGI("start"); - return; + return SUCCESS; } sptr AsObject() override @@ -72,18 +72,18 @@ public: } }; -class DummyIdmCallback : public IdmCallbackInterface { +class DummyIdmCallback : public IIamCallback { public: - void OnResult(int32_t result, const Attributes &reqRet) override + int32_t OnResult(int32_t result, const std::vector &reqRet) override { IAM_LOGI("start"); - return; + return SUCCESS; } - void OnAcquireInfo(int32_t module, int32_t acquire, const Attributes &reqRet) override + int32_t OnAcquireInfo(int32_t module, int32_t acquire, const std::vector &reqRet) override { IAM_LOGI("start"); - return; + return SUCCESS; } sptr AsObject() override @@ -93,6 +93,30 @@ public: } }; +class DummyCredChangeEventListener : public IEventListenerCallback { +public: + ~DummyCredChangeEventListener() override = default; + + sptr AsObject() override + { + sptr tmp(nullptr); + return tmp; + } + + int32_t OnNotifyAuthSuccessEvent(int32_t userId, int32_t authType, int32_t callerType, + const std::string &callerName) override + { + IAM_LOGI("start"); + return SUCCESS; + } + int32_t OnNotifyCredChangeEvent(int32_t userId, int32_t authType, int32_t eventType, + uint64_t credentialId) override + { + IAM_LOGI("start"); + return SUCCESS; + } +}; + int32_t GetFuzzOptionalUserId(Parcel &parcel) { if (parcel.ReadBool()) { @@ -101,29 +125,29 @@ int32_t GetFuzzOptionalUserId(Parcel &parcel) return 0; } -sptr GetFuzzIdmGetCredentialInfoCallback(Parcel &parcel) +sptr GetFuzzIdmGetCredentialInfoCallback(Parcel &parcel) { - sptr tmp(nullptr); + sptr tmp(nullptr); if (parcel.ReadBool()) { - tmp = sptr(new (std::nothrow) DummyIdmGetCredentialInfoCallback()); + tmp = sptr(new (std::nothrow) DummyIdmGetCredentialInfoCallback()); } return tmp; } -sptr GetFuzzIdmGetSecureUserInfoCallback(Parcel &parcel) +sptr GetFuzzIdmGetSecureUserInfoCallback(Parcel &parcel) { - sptr tmp(nullptr); + sptr tmp(nullptr); if (parcel.ReadBool()) { - tmp = sptr(new (std::nothrow) DummyIdmGetSecureUserInfoCallback()); + tmp = sptr(new (std::nothrow) DummyIdmGetSecureUserInfoCallback()); } return tmp; } -sptr GetFuzzIdmCallback(Parcel &parcel) +sptr GetFuzzIdmCallback(Parcel &parcel) { - sptr tmp(nullptr); + sptr tmp(nullptr); if (parcel.ReadBool()) { - tmp = sptr(new (std::nothrow) DummyIdmCallback()); + tmp = sptr(new (std::nothrow) DummyIdmCallback()); } return tmp; } @@ -152,8 +176,8 @@ void FuzzGetCredentialInfo(Parcel &parcel) { IAM_LOGI("begin"); int32_t userId = GetFuzzOptionalUserId(parcel); - AuthType authType = static_cast(parcel.ReadUint32()); - sptr callback = GetFuzzIdmGetCredentialInfoCallback(parcel); + int32_t authType = parcel.ReadUint32(); + sptr callback = GetFuzzIdmGetCredentialInfoCallback(parcel); g_UserIdmService.GetCredentialInfo(userId, authType, callback); IAM_LOGI("end"); } @@ -162,7 +186,7 @@ void FuzzGetSecInfo(Parcel &parcel) { IAM_LOGI("begin"); int32_t userId = GetFuzzOptionalUserId(parcel); - sptr callback = GetFuzzIdmGetSecureUserInfoCallback(parcel); + sptr callback = GetFuzzIdmGetSecureUserInfoCallback(parcel); g_UserIdmService.GetSecInfo(userId, callback); IAM_LOGI("end"); } @@ -171,11 +195,11 @@ void FuzzAddCredential(Parcel &parcel) { IAM_LOGI("begin"); int32_t userId = parcel.ReadInt32(); - UserIdmInterface::CredentialPara para = {}; - para.authType = static_cast(parcel.ReadInt32()); - para.pinType = static_cast(parcel.ReadInt32()); + IpcCredentialPara para = {}; + para.authType = parcel.ReadInt32(); + para.pinType = parcel.ReadInt32(); FillFuzzUint8Vector(parcel, para.token); - sptr callback = GetFuzzIdmCallback(parcel); + sptr callback = GetFuzzIdmCallback(parcel); g_UserIdmService.AddCredential(userId, para, callback, false); IAM_LOGI("end"); } @@ -184,11 +208,11 @@ void FuzzUpdateCredential(Parcel &parcel) { IAM_LOGI("begin"); int32_t userId = parcel.ReadInt32(); - UserIdmInterface::CredentialPara para = {}; - para.authType = static_cast(parcel.ReadInt32()); - para.pinType = static_cast(parcel.ReadInt32()); + IpcCredentialPara para = {}; + para.authType = parcel.ReadInt32(); + para.pinType = parcel.ReadInt32(); FillFuzzUint8Vector(parcel, para.token); - sptr callback = GetFuzzIdmCallback(parcel); + sptr callback = GetFuzzIdmCallback(parcel); g_UserIdmService.UpdateCredential(userId, para, callback); IAM_LOGI("end"); } @@ -205,7 +229,7 @@ void FuzzEnforceDelUser(Parcel &parcel) { IAM_LOGI("begin"); int32_t userId = parcel.ReadInt32(); - sptr callback = GetFuzzIdmCallback(parcel); + sptr callback = GetFuzzIdmCallback(parcel); g_UserIdmService.EnforceDelUser(userId, callback); IAM_LOGI("end"); } @@ -216,7 +240,7 @@ void FuzzDelUser(Parcel &parcel) int32_t userId = parcel.ReadInt32(); std::vector authToken; FillFuzzUint8Vector(parcel, authToken); - sptr callback = GetFuzzIdmCallback(parcel); + sptr callback = GetFuzzIdmCallback(parcel); g_UserIdmService.DelUser(userId, authToken, callback); IAM_LOGI("end"); } @@ -249,7 +273,7 @@ void DelCredential(Parcel &parcel) uint64_t credentialId = parcel.ReadUint64(); std::vector authToken; FillFuzzUint8Vector(parcel, authToken); - sptr callback = GetFuzzIdmCallback(parcel); + sptr callback = GetFuzzIdmCallback(parcel); g_UserIdmService.DelCredential(userId, credentialId, authToken, callback); IAM_LOGI("end"); } @@ -257,7 +281,7 @@ void DelCredential(Parcel &parcel) void FuzzClearRedundancyCredential(Parcel &parcel) { IAM_LOGI("begin"); - sptr callback = GetFuzzIdmCallback(parcel); + sptr callback = GetFuzzIdmCallback(parcel); g_UserIdmService.ClearRedundancyCredential(callback); IAM_LOGI("end"); } @@ -275,7 +299,7 @@ void FuzzEnforceDelUserInner(Parcel &parcel) { IAM_LOGI("begin"); int32_t userId = 100; - sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); + sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); std::shared_ptr callbackForTrace = ContextCallback::NewInstance(iamCallback, TRACE_ENFORCE_DELETE_USER); std::string changeReasonTrace = parcel.ReadString(); @@ -295,13 +319,36 @@ void FuzzStartEnroll(Parcel &parcel) { IAM_LOGI("begin"); Enrollment::EnrollmentPara para = {}; - sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); + sptr iamCallback = sptr(new (nothrow) DummyIamCallbackInterface); std::shared_ptr contextCallback = ContextCallback::NewInstance(iamCallback, TRACE_ADD_CREDENTIAL); Attributes extraInfo; g_UserIdmService.StartEnroll(para, contextCallback, extraInfo, true); IAM_LOGI("end"); } +void FuzzRegistCredChangeEventListener(Parcel &parcel) +{ + IAM_LOGI("begin"); + sptr callback(nullptr); + if (parcel.ReadBool()) { + callback = sptr(new (std::nothrow) DummyCredChangeEventListener()); + } + + g_UserIdmService.RegistCredChangeEventListener(callback); + g_UserIdmService.UnRegistCredChangeEventListener(callback); + IAM_LOGI("end"); +} + +void FuzzGetCredentialInfoSync(Parcel &parcel) +{ + IAM_LOGI("begin"); + int32_t userId = parcel.ReadInt32(); + auto authType = static_cast(parcel.ReadInt32()); + std::vector credentialInfoList; + g_UserIdmService.GetCredentialInfoSync(userId, authType, credentialInfoList); + IAM_LOGI("end"); +} + using FuzzFunc = decltype(FuzzOpenSession); FuzzFunc *g_fuzzFuncs[] = { FuzzOpenSession, @@ -320,6 +367,8 @@ FuzzFunc *g_fuzzFuncs[] = { FuzzEnforceDelUserInner, FuzzCancelCurrentEnroll, FuzzStartEnroll, + FuzzRegistCredChangeEventListener, + FuzzGetCredentialInfoSync, }; void UserIdmFuzzTest(const uint8_t *data, size_t size) diff --git a/test/fuzztest/services/useridmstub_fuzzer/BUILD.gn b/test/fuzztest/services/useridmstub_fuzzer/BUILD.gn deleted file mode 100644 index 60dcb68bbb416c426df4bc644531780965e20a30..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/useridmstub_fuzzer/BUILD.gn +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright (c) 2023-2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/test.gni") - -ohos_fuzztest("UserIdmStubFuzzTest") { - branch_protector_ret = "pac_ret" - module_out_path = "user_auth_framework/user_auth" - fuzz_config_file = "../useridmstub_fuzzer" - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - include_dirs = [ - "../../../../services/base/inc", - "../../../../services/core/inc", - "../../../../services/core/src", - "../../../../services/context/inc", - "../../../../services/ipc/inc", - "../../../../services/remote_connect/inc", - "../../../../frameworks/native/ipc/inc", - "../../../../frameworks/native/ipc/common_defines", - "../../../../common/utils", - "../../../../common/logs", - ] - - sources = [ "user_idm_stub_fuzzer.cpp" ] - - deps = [ - "../../common_fuzzer:attributes_fuzzer", - "../../common_fuzzer:iam_test_fuzzer", - "../../common_fuzzer:userauth_services_ipc_fuzzer", - ] - - external_deps = [ - "ability_runtime:ability_context_native", - "ability_runtime:abilitykit_native", - "ability_runtime:app_manager", - "ability_runtime:extension_manager", - "access_token:libaccesstoken_sdk", - "c_utils:utils", - "drivers_interface_user_auth:libuser_auth_proxy_3.0", - "eventhandler:libeventhandler", - "hdf_core:libhdi", - "hilog:libhilog", - "ipc:ipc_single", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - ] - - subsystem_name = "useriam" - part_name = "user_auth_framework" -} diff --git a/test/fuzztest/services/useridmstub_fuzzer/corpus/init b/test/fuzztest/services/useridmstub_fuzzer/corpus/init deleted file mode 100644 index e4ceac1bcd4e3b3427eb63cea0c28304064333cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/useridmstub_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/useridmstub_fuzzer/project.xml b/test/fuzztest/services/useridmstub_fuzzer/project.xml deleted file mode 100644 index 4fdbc407f205680885fa42663163b5c987f123a6..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/useridmstub_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/services/useridmstub_fuzzer/user_idm_stub_fuzzer.cpp b/test/fuzztest/services/useridmstub_fuzzer/user_idm_stub_fuzzer.cpp deleted file mode 100644 index 1d6a770826d17cb51f1916f0cf3629cf4f41b2c4..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/useridmstub_fuzzer/user_idm_stub_fuzzer.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_stub_fuzzer.h" - -#include -#include -#include - -#include "parcel.h" - -#include "iam_fuzz_test.h" -#include "iam_logger.h" -#include "user_idm_service.h" - -#define LOG_TAG "USER_AUTH_SA" - -using namespace std; - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -namespace { -constexpr uint32_t USER_IDM_CODE_MIN = 0; -constexpr uint32_t USER_IDM_CODE_MAX = 100; -const std::u16string USER_IDM_INTERFACE_TOKEN = u"ohos.useridm.IUserIDM"; - -bool UserIdmStubFuzzTest(const uint8_t *rawData, size_t size) -{ - IAM_LOGI("start"); - if (rawData == nullptr) { - return false; - } - - UserIdmService userIdmService(SUBSYS_USERIAM_SYS_ABILITY_USERIDM, true); - for (uint32_t code = USER_IDM_CODE_MIN; code < USER_IDM_CODE_MAX; code++) { - MessageParcel data; - MessageParcel reply; - MessageOption optionSync = MessageOption::TF_SYNC; - MessageOption optionAsync = MessageOption::TF_ASYNC; - // Sync - data.WriteInterfaceToken(USER_IDM_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)userIdmService.OnRemoteRequest(code, data, reply, optionSync); - // Async - data.WriteInterfaceToken(USER_IDM_INTERFACE_TOKEN); - data.WriteBuffer(rawData, size); - data.RewindRead(0); - (void)userIdmService.OnRemoteRequest(code, data, reply, optionAsync); - } - return true; -} -} // namespace -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - /* Run your code on data */ - OHOS::UserIam::UserAuth::UserIdmStubFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/useridmstub_fuzzer/user_idm_stub_fuzzer.h b/test/fuzztest/services/useridmstub_fuzzer/user_idm_stub_fuzzer.h deleted file mode 100644 index 3bbda2b77a2f06dc64aedecb67cc18174ecc0dc6..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/useridmstub_fuzzer/user_idm_stub_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef USER_IDM_STUB_FUZZER_H -#define USER_IDM_STUB_FUZZER_H - -#define FUZZ_PROJECT_NAME "UserIdmStubFuzzTest" - -#endif // USER_IDM_STUB_FUZZER_H diff --git a/test/unittest/executors/auth_command_unit_test.cpp b/test/unittest/executors/auth_command_unit_test.cpp index 9fe76d12e37403618cc812f9766dc8cb4aebc799..64be8cddbb885fc108d545b9eb018d061530fa8c 100644 --- a/test/unittest/executors/auth_command_unit_test.cpp +++ b/test/unittest/executors/auth_command_unit_test.cpp @@ -260,6 +260,25 @@ HWTEST_F(AuthCommandUnitTest, AuthCommand_MixTest_003, TestSize.Level0) command->OnAcquireInfo(testAcquire, testExtraInfo); command->OnAcquireInfo(testAcquire, testExtraInfo); } + +HWTEST_F(AuthCommandUnitTest, AuthCommand_MixTest_004, TestSize.Level0) +{ + auto messenger = MakeShared(); + ASSERT_NE(messenger, nullptr); + auto executor = Common::MakeShared(nullptr, nullptr, 3); + ASSERT_NE(executor, nullptr); + Attributes attr; + + uint64_t testScheduleId = 0; + auto command = Common::MakeShared(executor, testScheduleId, attr, nullptr); + int destRole = 0; + std::vector msg = {}; + command->OnMessage(destRole, msg); + command->OnHdiDisconnect(); + command->GetAuthType(); + command->EndProcess(); + command->GetExecutorHdi(); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/test/unittest/executors/enroll_command_unit_test.cpp b/test/unittest/executors/enroll_command_unit_test.cpp index 33a00f24e7a8f30c3ef6668bf9ac62dde4a6ef0e..f79b9e1971068f68b3d25c532d69b7ee5f081b79 100644 --- a/test/unittest/executors/enroll_command_unit_test.cpp +++ b/test/unittest/executors/enroll_command_unit_test.cpp @@ -20,6 +20,8 @@ #include "iam_logger.h" #include "iam_mem.h" #include "iam_ptr.h" +#include "collect_command.h" +#include "async_command_base.h" #include "executor.h" #include "mock_iexecutor_messenger.h" @@ -261,6 +263,22 @@ HWTEST_F(EnrollCommandUnitTest, EnrollCommand_MixTest_003, TestSize.Level0) command->OnAcquireInfo(testAcquire, testExtraInfo); command->OnAcquireInfo(testAcquire, testExtraInfo); } + +HWTEST_F(EnrollCommandUnitTest, CollectCommand_MixTest_001, TestSize.Level0) +{ + uint16_t hdiId = 3; + auto executor = Common::MakeShared(nullptr, nullptr, hdiId); + ASSERT_NE(executor, nullptr); + + uint64_t scheduleId = 0; + Attributes attributes; + std::shared_ptr executorMessenger = {}; + CollectCommand collectCommand = { executor, scheduleId, attributes, executorMessenger }; + collectCommand.SendRequest(); + ResultCode result = ResultCode::SUCCESS; + std::vector extraInfo = {}; + collectCommand.OnResultInner(result, extraInfo); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/test/unittest/inner_api/BUILD.gn b/test/unittest/inner_api/BUILD.gn index 6e9c7125a6c246d489a94ee71d1b3f3b80ad60c9..102a2393621e5d1ad062bc20a4ce7c00ac0fcef0 100644 --- a/test/unittest/inner_api/BUILD.gn +++ b/test/unittest/inner_api/BUILD.gn @@ -38,6 +38,7 @@ ohos_unittest("iam_inner_api_test") { "../../../frameworks/native/client/src/auth_message_impl.cpp", "../../../frameworks/native/client/src/callback_manager_impl.cpp", "../../../frameworks/native/client/src/co_auth_client_impl.cpp", + "../../../frameworks/native/client/src/event_listener_callback_service.cpp", "../../../frameworks/native/client/src/executor_callback_service.cpp", "../../../frameworks/native/client/src/executor_messenger_client.cpp", "../../../frameworks/native/client/src/load_mode_client_util.cpp", @@ -54,29 +55,15 @@ ohos_unittest("iam_inner_api_test") { "mocks/mock_ipc_client_utils.cpp", "src/callback_manager_impl_test.cpp", "src/co_auth_client_test.cpp", - "src/co_auth_proxy_test.cpp", - "src/executor_callback_proxy_test.cpp", "src/executor_callback_service_test.cpp", - "src/executor_callback_stub_test.cpp", "src/executor_messenger_client_test.cpp", - "src/executor_messenger_proxy_test.cpp", - "src/executor_messenger_stub_test.cpp", "src/user_access_ctrl_client_test.cpp", - "src/user_auth_callback_proxy_test.cpp", "src/user_auth_callback_service_test.cpp", - "src/user_auth_callback_stub_test.cpp", "src/user_auth_client_test.cpp", - "src/user_auth_event_listener_stub_test.cpp", "src/user_auth_napi_client_test.cpp", - "src/user_auth_proxy_test.cpp", - "src/user_idm_callback_proxy_test.cpp", "src/user_idm_callback_service_test.cpp", - "src/user_idm_callback_stub_test.cpp", "src/user_idm_client_test.cpp", - "src/user_idm_proxy_test.cpp", - "src/widget_callback_proxy_test.cpp", "src/widget_callback_service_test.cpp", - "src/widget_callback_stub_test.cpp", ] configs = [ @@ -89,8 +76,7 @@ ohos_unittest("iam_inner_api_test") { deps = [ "../../../frameworks/native/common:attributes", "../../../frameworks/native/common:dfx", - "../../../frameworks/native/ipc:userauth_client_ipc", - "../../../frameworks/native/ipc:userauth_service_ipc", + "../../../frameworks/native/ipc:iam_inner_api", ] external_deps = [ diff --git a/test/unittest/inner_api/mocks/mock_executor_callback_service.h b/test/unittest/inner_api/mocks/mock_executor_callback_service.h index 88087ed43ab40fda1d50c5ad9aaff100d77be166..07f077c28635cbebe464b020d6f4eee5f900818d 100644 --- a/test/unittest/inner_api/mocks/mock_executor_callback_service.h +++ b/test/unittest/inner_api/mocks/mock_executor_callback_service.h @@ -25,14 +25,16 @@ namespace UserIam { namespace UserAuth { class MockExecutorCallbackService final : public ExecutorCallbackStub { public: - MOCK_METHOD3(OnMessengerReady, void(sptr &messenger, + MOCK_METHOD3(OnMessengerReady, int32_t(const sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList)); MOCK_METHOD3(OnBeginExecute, int32_t(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command)); - MOCK_METHOD2(OnEndExecute, int32_t(uint64_t scheduleId, const Attributes &command)); - MOCK_METHOD1(OnSetProperty, int32_t(const Attributes &properties)); - MOCK_METHOD2(OnGetProperty, int32_t(const Attributes &condition, Attributes &values)); - MOCK_METHOD2(OnSendData, int32_t(uint64_t scheduleId, const Attributes &data)); + MOCK_METHOD2(OnEndExecute, int32_t(uint64_t scheduleId, const std::vector &command)); + MOCK_METHOD1(OnSetProperty, int32_t(const std::vector &properties)); + MOCK_METHOD2(OnGetProperty, int32_t(const std::vector &condition, std::vector &values)); + MOCK_METHOD2(OnSendData, int32_t(uint64_t scheduleId, const std::vector &data)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/inner_api/mocks/mock_executor_messenger_service.h b/test/unittest/inner_api/mocks/mock_executor_messenger_service.h index 55191404f1891868cf81d188cf286faf88b8c9e1..fd9f1fdac98534a23bce39f05271d19a92044196 100644 --- a/test/unittest/inner_api/mocks/mock_executor_messenger_service.h +++ b/test/unittest/inner_api/mocks/mock_executor_messenger_service.h @@ -26,9 +26,11 @@ namespace UserIam { namespace UserAuth { class MockExecutorMessengerService final : public ExecutorMessengerStub { public: - MOCK_METHOD3(SendData, int32_t(uint64_t scheduleId, ExecutorRole dstRole, const std::vector &msg)); - MOCK_METHOD3(Finish, int32_t(uint64_t scheduleId, ResultCode resultCode, - const std::shared_ptr &finalResult)); + MOCK_METHOD3(SendData, int32_t(uint64_t scheduleId, int32_t dstRole, const std::vector &msg)); + MOCK_METHOD3(Finish, int32_t(uint64_t scheduleId, int32_t resultCode, + const std::vector &finalResult)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/inner_api/mocks/mock_user_access_ctrl_callback_service.h b/test/unittest/inner_api/mocks/mock_user_access_ctrl_callback_service.h index 12cc72c0ec084f637fed90875c02d12cb2e429e4..d1c9d99c571d9621e92ff2982d5c68a7c948ed99 100644 --- a/test/unittest/inner_api/mocks/mock_user_access_ctrl_callback_service.h +++ b/test/unittest/inner_api/mocks/mock_user_access_ctrl_callback_service.h @@ -18,14 +18,16 @@ #include -#include "user_access_ctrl_callback_stub.h" +#include "verify_token_callback_stub.h" namespace OHOS { namespace UserIam { namespace UserAuth { class MockVerifyTokenCallbackService final : public VerifyTokenCallbackStub { public: - MOCK_METHOD2(OnVerifyTokenResult, void(int32_t result, const Attributes &extraInfo)); + MOCK_METHOD2(OnVerifyTokenResult, int32_t(int32_t result, const std::vector &extraInfo)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/inner_api/mocks/mock_user_auth_callback_service.h b/test/unittest/inner_api/mocks/mock_user_auth_callback_service.h index 39811a807f921a9ceada29add625274ecba39025..93f1909086e0da79af15704cb7806e4f6569f904 100644 --- a/test/unittest/inner_api/mocks/mock_user_auth_callback_service.h +++ b/test/unittest/inner_api/mocks/mock_user_auth_callback_service.h @@ -18,32 +18,34 @@ #include -#include "user_auth_callback_stub.h" -#include "user_auth_event_listener_stub.h" +#include "iam_callback_stub.h" +#include "get_executor_property_callback_stub.h" +#include "set_executor_property_callback_stub.h" +#include "iam_callback_stub.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockUserAuthCallbackService final : public UserAuthCallbackStub { +class MockUserAuthCallbackService final : public IamCallbackStub { public: - MOCK_METHOD2(OnResult, void(int32_t result, const Attributes &extraInfo)); - MOCK_METHOD3(OnAcquireInfo, void(int32_t module, int32_t acquireInfo, const Attributes &extraInfo)); + MOCK_METHOD2(OnResult, int32_t(int32_t resultCode, const std::vector &extraInfo)); + MOCK_METHOD3(OnAcquireInfo, int32_t(int32_t module, int32_t acquireInfo, const std::vector &extraInfo)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; class MockGetExecutorPropertyCallbackService final : public GetExecutorPropertyCallbackStub { public: - MOCK_METHOD2(OnGetExecutorPropertyResult, void(int32_t result, const Attributes &attributes)); + MOCK_METHOD2(OnGetExecutorPropertyResult, int32_t(int32_t resultCode, const std::vector &attributes)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; class MockSetExecutorPropertyCallbackService final : public SetExecutorPropertyCallbackStub { public: - MOCK_METHOD1(OnSetExecutorPropertyResult, void(int32_t result)); -}; - -class MockAuthEventListenerService final : public AuthEventListenerStub { -public: - MOCK_METHOD4(OnNotifyAuthSuccessEvent, void(int32_t userId, AuthType authtype, int32_t callerType, - std::string &callerName)); + MOCK_METHOD1(OnSetExecutorPropertyResult, int32_t(int32_t resultCode)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/inner_api/mocks/mock_user_auth_client_callback.h b/test/unittest/inner_api/mocks/mock_user_auth_client_callback.h index 87c38c88f6c74d26d1829a05b61b983d59407adf..321e6d4c2e8a7aca5d7e2af64d06a7e8db10636d 100644 --- a/test/unittest/inner_api/mocks/mock_user_auth_client_callback.h +++ b/test/unittest/inner_api/mocks/mock_user_auth_client_callback.h @@ -44,6 +44,12 @@ class MockSetPropCallback final : public SetPropCallback { public: MOCK_METHOD2(OnResult, void(int32_t result, const Attributes &extraInfo)); }; + +class MockAuthSuccessEventListener final : public AuthSuccessEventListener { +public: + MOCK_METHOD4(OnNotifyAuthSuccessEvent, void(int32_t userId, AuthType authType, int32_t callerType, + const std::string &callerName)); +}; } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/test/unittest/inner_api/mocks/mock_user_idm_callback_service.h b/test/unittest/inner_api/mocks/mock_user_idm_callback_service.h index 64639d0d93d16f241d6bdfb86e984bfd053c08d1..d8785fbe1d18a66990a5fe62c794f54dee44f3ad 100644 --- a/test/unittest/inner_api/mocks/mock_user_idm_callback_service.h +++ b/test/unittest/inner_api/mocks/mock_user_idm_callback_service.h @@ -18,25 +18,31 @@ #include -#include "user_idm_callback_stub.h" +#include "iam_callback_stub.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockIdmCallbackService final : public IdmCallbackStub { +class MockIdmCallbackService final : public IamCallbackStub { public: - MOCK_METHOD2(OnResult, void(int32_t result, const Attributes &extraInfo)); - MOCK_METHOD3(OnAcquireInfo, void(int32_t module, int32_t acquireInfo, const Attributes &extraInfo)); + MOCK_METHOD2(OnResult, int32_t(int32_t resultCode, const std::vector &extraInfo)); + MOCK_METHOD3(OnAcquireInfo, int32_t(int32_t module, int32_t acquireInfo, const std::vector &extraInfo)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; class MockIdmGetCredInfoCallbackService final : public IdmGetCredInfoCallbackStub { public: - MOCK_METHOD2(OnCredentialInfos, void(int32_t result, const std::vector &credInfoList)); + MOCK_METHOD2(OnCredentialInfos, int32_t(int32_t result, const std::vector &credInfoList)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; class MockIdmGetSecureUserInfoCallbackService final : public IdmGetSecureUserInfoCallbackStub { public: - MOCK_METHOD2(OnSecureUserInfo, void(int32_t result, const SecUserInfo &secUserInfo)); + MOCK_METHOD2(OnSecureUserInfo, int32_t(int32_t resultCodeCode, const IpcSecUserInfo &secUserInfo)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/inner_api/mocks/mock_user_idm_client_callback.h b/test/unittest/inner_api/mocks/mock_user_idm_client_callback.h index b55973d89a61786ad3148743b339ca81de355aaa..3d4d6132994eae0ae4daf74ec9af0ea4bf1691a6 100644 --- a/test/unittest/inner_api/mocks/mock_user_idm_client_callback.h +++ b/test/unittest/inner_api/mocks/mock_user_idm_client_callback.h @@ -38,6 +38,12 @@ public: MOCK_METHOD2(OnResult, void(int32_t result, const Attributes &extraInfo)); MOCK_METHOD3(OnAcquireInfo, void(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo)); }; + +class MockCredChangeEventListener final : public CredChangeEventListener { +public: + MOCK_METHOD4(OnNotifyCredChangeEvent, void(int32_t userId, AuthType authType, CredChangeEventType eventType, + uint64_t credentialId)); +}; } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/test/unittest/inner_api/mocks/mock_widget_callback_service_test.h b/test/unittest/inner_api/mocks/mock_widget_callback_service_test.h index c95272fa9044a20208a11b714c5d02b47d648810..a1c2eb2558b28f692b2907195c1d49ea55271077 100644 --- a/test/unittest/inner_api/mocks/mock_widget_callback_service_test.h +++ b/test/unittest/inner_api/mocks/mock_widget_callback_service_test.h @@ -25,7 +25,9 @@ namespace UserIam { namespace UserAuth { class MockWidgetCallbackService final : public WidgetCallbackStub { public: - MOCK_METHOD1(SendCommand, void(const std::string &cmdData)); + MOCK_METHOD1(SendCommand, int32_t(const std::string &cmdData)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/inner_api/src/co_auth_client_test.cpp b/test/unittest/inner_api/src/co_auth_client_test.cpp index 61d60ee93744be7a87da712c0b5331090419e7c1..443c85f4a338d5379acf90640bb3542208915ce2 100644 --- a/test/unittest/inner_api/src/co_auth_client_test.cpp +++ b/test/unittest/inner_api/src/co_auth_client_test.cpp @@ -61,18 +61,19 @@ HWTEST_F(CoAuthClientTest, CoAuthClientRegister_001, TestSize.Level0) auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, ExecutorRegister(_, _)).Times(1); + EXPECT_CALL(*service, ExecutorRegister(_, _, _)).Times(1); ON_CALL(*service, ExecutorRegister) .WillByDefault( - [&testInfo, &testExecutorIndex](const CoAuthInterface::ExecutorRegisterInfo &info, - sptr &callback) { + [&testInfo, &testExecutorIndex](const IpcExecutorRegisterInfo &info, + const sptr &callback, uint64_t &executorIndex) { EXPECT_EQ(testInfo.authType, info.authType); EXPECT_EQ(testInfo.executorRole, info.executorRole); EXPECT_EQ(testInfo.executorSensorHint, info.executorSensorHint); EXPECT_EQ(testInfo.executorMatcher, info.executorMatcher); EXPECT_EQ(testInfo.esl, info.esl); EXPECT_THAT(testInfo.publicKey, ElementsAreArray(info.publicKey)); - return testExecutorIndex; + executorIndex = testExecutorIndex; + return SUCCESS; } ); @@ -106,6 +107,8 @@ void CoAuthClientTest::CallRemoteObject(const std::shared_ptr MessageOption &option) { service->OnRemoteRequest(code, data, reply, option); uint64_t executorIndex = 0; + int32_t ret = 0; + EXPECT_TRUE(reply.ReadInt32(ret)); EXPECT_TRUE(reply.ReadUint64(executorIndex)); EXPECT_EQ(executorIndex, testExecutorIndex); return OHOS::NO_ERROR; diff --git a/test/unittest/inner_api/src/co_auth_proxy_test.cpp b/test/unittest/inner_api/src/co_auth_proxy_test.cpp deleted file mode 100644 index 08933aaae35c844745f69e05223e0dfd1acee422..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/co_auth_proxy_test.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "co_auth_proxy_test.h" - -#include "iam_ptr.h" -#include "co_auth_proxy.h" -#include "executor_callback_service.h" -#include "mock_remote_object.h" -#include "mock_co_auth_service.h" -#include "mock_executor_register_callback.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void CoAuthProxyTest::SetUpTestCase() -{ -} - -void CoAuthProxyTest::TearDownTestCase() -{ -} - -void CoAuthProxyTest::SetUp() -{ -} - -void CoAuthProxyTest::TearDown() -{ -} - -HWTEST_F(CoAuthProxyTest, CoAuthProxyExecutorRegister, TestSize.Level0) -{ - CoAuthInterface::ExecutorRegisterInfo testInfo = {}; - testInfo.authType = PIN; - testInfo.executorRole = COLLECTOR; - testInfo.executorSensorHint = 11; - testInfo.executorMatcher = 22; - testInfo.esl = ESL1; - testInfo.publicKey = {1, 2, 3, 4}; - - uint64_t testExecutorIndex = 73265; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto executorCallback = Common::MakeShared(); - sptr testCallback(new (std::nothrow) ExecutorCallbackService(executorCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, ExecutorRegister(_, _)) - .Times(Exactly(1)) - .WillOnce( - [&testInfo, &testExecutorIndex](const CoAuthInterface::ExecutorRegisterInfo &info, - sptr &callback) { - EXPECT_EQ(testInfo.authType, info.authType); - EXPECT_EQ(testInfo.executorRole, info.executorRole); - EXPECT_EQ(testInfo.executorSensorHint, info.executorSensorHint); - EXPECT_EQ(testInfo.executorMatcher, info.executorMatcher); - EXPECT_EQ(testInfo.esl, info.esl); - EXPECT_THAT(testInfo.publicKey, ElementsAreArray(info.publicKey)); - return testExecutorIndex; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return OHOS::NO_ERROR; - }); - proxy->ExecutorRegister(testInfo, testCallback); -} - -HWTEST_F(CoAuthProxyTest, CoAuthProxyExecutorUnRegister, TestSize.Level0) -{ - uint64_t testExecutorIndex = 73265; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, ExecutorUnregister(_)) - .Times(Exactly(1)) - .WillOnce( - [&testExecutorIndex](uint64_t executorIndex) { - return; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return OHOS::NO_ERROR; - }); - proxy->ExecutorUnregister(testExecutorIndex); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/inner_api/src/executor_callback_proxy_test.cpp b/test/unittest/inner_api/src/executor_callback_proxy_test.cpp deleted file mode 100644 index 34af1af5f40d197669632bcdd13d87fb2e03e30c..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/executor_callback_proxy_test.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_callback_proxy_test.h" - -#include "iam_ptr.h" -#include "executor_callback_proxy.h" -#include "mock_executor_messenger_service.h" -#include "mock_remote_object.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void ExecutorCallbackProxyTest::SetUpTestCase() -{ -} - -void ExecutorCallbackProxyTest::TearDownTestCase() -{ -} - -void ExecutorCallbackProxyTest::SetUp() -{ -} - -void ExecutorCallbackProxyTest::TearDown() -{ -} - -HWTEST_F(ExecutorCallbackProxyTest, TestOnMessengerReady_001, TestSize.Level0) -{ - sptr messenger(nullptr); - std::vector publicKey; - std::vector templateIdList; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - proxy->OnMessengerReady(messenger, publicKey, templateIdList); -} - -HWTEST_F(ExecutorCallbackProxyTest, TestOnMessengerReady_002, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorCallbackInterfaceCode::ON_MESSENGER_READY); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - sptr messenger(new (std::nothrow) MockExecutorMessengerService()); - EXPECT_NE(messenger, nullptr); - std::vector publicKey; - std::vector templateIdList; - proxy->OnMessengerReady(messenger, publicKey, templateIdList); -} - -HWTEST_F(ExecutorCallbackProxyTest, TestOnBeginExecute_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorCallbackInterfaceCode::ON_BEGIN_EXECUTE); - EXPECT_TRUE(reply.WriteInt32(SUCCESS)); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - uint64_t scheduleId = 321562; - std::vector publicKey; - Attributes command; - - EXPECT_EQ(proxy->OnBeginExecute(scheduleId, publicKey, command), SUCCESS); -} - -HWTEST_F(ExecutorCallbackProxyTest, TestOnEndExecute_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorCallbackInterfaceCode::ON_END_EXECUTE); - EXPECT_TRUE(reply.WriteInt32(SUCCESS)); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - uint64_t scheduleId = 321562; - Attributes command; - EXPECT_EQ(proxy->OnEndExecute(scheduleId, command), SUCCESS); -} - -HWTEST_F(ExecutorCallbackProxyTest, TestOnSetProperty_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorCallbackInterfaceCode::ON_SET_PROPERTY); - EXPECT_TRUE(reply.WriteInt32(SUCCESS)); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - Attributes properties; - EXPECT_EQ(proxy->OnSetProperty(properties), SUCCESS); -} - -HWTEST_F(ExecutorCallbackProxyTest, TestOnGetProperty_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .Times(2) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorCallbackInterfaceCode::ON_GET_PROPERTY); - EXPECT_TRUE(reply.WriteInt32(SUCCESS)); - return OHOS::NO_ERROR; - } - ) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorCallbackInterfaceCode::ON_GET_PROPERTY); - return GENERAL_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - Attributes condition; - Attributes values; - EXPECT_EQ(proxy->OnGetProperty(condition, values), SUCCESS); - EXPECT_EQ(proxy->OnGetProperty(condition, values), GENERAL_ERROR); -} - -HWTEST_F(ExecutorCallbackProxyTest, TestOnSendData_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorCallbackInterfaceCode::ON_SEND_DATA); - EXPECT_TRUE(reply.WriteInt32(SUCCESS)); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - uint64_t scheduleId = 321562; - Attributes command; - EXPECT_EQ(proxy->OnSendData(scheduleId, command), SUCCESS); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/executor_callback_service_test.cpp b/test/unittest/inner_api/src/executor_callback_service_test.cpp index 591ce6ebe327768b0d4b4e53d7ff0c88b678b95d..51eb1f22785e5d8d41733377d255dff100cb5014 100644 --- a/test/unittest/inner_api/src/executor_callback_service_test.cpp +++ b/test/unittest/inner_api/src/executor_callback_service_test.cpp @@ -43,7 +43,7 @@ void ExecutorCallbackServiceTest::TearDown() HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerReady001, TestSize.Level0) { - sptr testMessenger(nullptr); + sptr testMessenger(nullptr); std::vector testPublicKey = {1, 2, 3, 4}; std::vector testTemplateIdList = {12, 13, 14, 15}; @@ -55,7 +55,7 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerRead HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerReady002, TestSize.Level0) { - sptr testMessenger(nullptr); + sptr testMessenger(nullptr); std::vector testPublicKey = {1, 2, 3, 4}; std::vector testTemplateIdList = {12, 13, 14, 15}; @@ -86,7 +86,7 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnBeginExecute0 std::shared_ptr testCallback = nullptr; auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnBeginExecute(testScheduleId, testPublicKey, testCommand); + int32_t result = service->OnBeginExecute(testScheduleId, testPublicKey, testCommand.Serialize()); EXPECT_EQ(result, GENERAL_ERROR); } @@ -110,7 +110,7 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnBeginExecute0 ); auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnBeginExecute(testScheduleId, testPublicKey, testCommand); + int32_t result = service->OnBeginExecute(testScheduleId, testPublicKey, testCommand.Serialize()); EXPECT_EQ(result, SUCCESS); } @@ -122,7 +122,7 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnEndExecute001 std::shared_ptr testCallback = nullptr; auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnEndExecute(testScheduleId, testCommand); + int32_t result = service->OnEndExecute(testScheduleId, testCommand.Serialize()); EXPECT_EQ(result, GENERAL_ERROR); } @@ -143,7 +143,7 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnEndExecute002 ); auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnEndExecute(testScheduleId, testCommand); + int32_t result = service->OnEndExecute(testScheduleId, testCommand.Serialize()); EXPECT_EQ(result, SUCCESS); } @@ -154,7 +154,7 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnSetProperty00 std::shared_ptr testCallback = nullptr; auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnSetProperty(testProperties); + int32_t result = service->OnSetProperty(testProperties.Serialize()); EXPECT_EQ(result, GENERAL_ERROR); } @@ -173,26 +173,26 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnSetProperty00 ); auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnSetProperty(testProperties); + int32_t result = service->OnSetProperty(testProperties.Serialize()); EXPECT_EQ(result, SUCCESS); } HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnGetProperty001, TestSize.Level0) { Attributes testCondition; - Attributes testValues; + std::vector testValues; std::shared_ptr testCallback = nullptr; auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnGetProperty(testCondition, testValues); + int32_t result = service->OnGetProperty(testCondition.Serialize(), testValues); EXPECT_EQ(result, GENERAL_ERROR); } HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnGetProperty002, TestSize.Level0) { Attributes testCondition; - Attributes testValues; + std::vector testValues; int32_t testCode = 544857; auto testCallback = Common::MakeShared(); @@ -207,10 +207,11 @@ HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnGetProperty00 ); auto service = Common::MakeShared(testCallback); EXPECT_NE(service, nullptr); - int32_t result = service->OnGetProperty(testCondition, testValues); + int32_t result = service->OnGetProperty(testCondition.Serialize(), testValues); EXPECT_EQ(result, SUCCESS); int32_t code = 0; - EXPECT_TRUE(testValues.GetInt32Value(Attributes::ATTR_RESULT_CODE, code)); + Attributes attribute(testValues); + EXPECT_TRUE(attribute.GetInt32Value(Attributes::ATTR_RESULT_CODE, code)); EXPECT_EQ(code, testCode); } } // namespace UserAuth diff --git a/test/unittest/inner_api/src/executor_callback_stub_test.cpp b/test/unittest/inner_api/src/executor_callback_stub_test.cpp deleted file mode 100644 index c0bb620604199c90e9c542445cf53cbc84c193c7..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/executor_callback_stub_test.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_callback_stub_test.h" - -#include "message_parcel.h" - -#include "iam_ptr.h" -#include "mock_executor_callback_service.h" -#include "mock_executor_messenger_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void ExecutorCallbackStubTest::SetUpTestCase() -{ -} - -void ExecutorCallbackStubTest::TearDownTestCase() -{ -} - -void ExecutorCallbackStubTest::SetUp() -{ -} - -void ExecutorCallbackStubTest::TearDown() -{ -} - -HWTEST_F(ExecutorCallbackStubTest, TestOnMessengerReadyStub_001, TestSize.Level0) -{ - sptr messenger(new (std::nothrow) MockExecutorMessengerService()); - EXPECT_NE(messenger, nullptr); - std::vector publicKey; - std::vector templateIdList; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorCallbackInterfaceCode::ON_MESSENGER_READY; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteRemoteObject(messenger->AsObject())); - EXPECT_TRUE(data.WriteUInt8Vector(publicKey)); - EXPECT_TRUE(data.WriteUInt64Vector(templateIdList)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnMessengerReady(_, _, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(ExecutorCallbackStubTest, TestOnBeginExecuteStub_001, TestSize.Level0) -{ - uint64_t scheduleId = 231527; - std::vector publicKey; - std::vector command; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorCallbackInterfaceCode::ON_BEGIN_EXECUTE; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(scheduleId)); - EXPECT_TRUE(data.WriteUInt8Vector(publicKey)); - EXPECT_TRUE(data.WriteUInt8Vector(command)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnBeginExecute(_, _, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(ExecutorCallbackStubTest, TestOnEndExecuteStub_001, TestSize.Level0) -{ - uint64_t scheduleId = 231527; - std::vector command; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorCallbackInterfaceCode::ON_END_EXECUTE; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(scheduleId)); - EXPECT_TRUE(data.WriteUInt8Vector(command)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnEndExecute(_, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(ExecutorCallbackStubTest, TestOnSetPropertyStub_001, TestSize.Level0) -{ - std::vector properties; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorCallbackInterfaceCode::ON_SET_PROPERTY; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUInt8Vector(properties)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnSetProperty(_)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(ExecutorCallbackStubTest, TestOnGetPropertyStub_001, TestSize.Level0) -{ - std::vector condition; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorCallbackInterfaceCode::ON_GET_PROPERTY; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUInt8Vector(condition)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnGetProperty(_, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(ExecutorCallbackStubTest, TestOnSendDataStub_001, TestSize.Level0) -{ - uint64_t scheduleId = 231527; - std::vector command; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorCallbackInterfaceCode::ON_SEND_DATA; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(scheduleId)); - EXPECT_TRUE(data.WriteUInt8Vector(command)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnSendData(_, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/executor_messenger_client_test.cpp b/test/unittest/inner_api/src/executor_messenger_client_test.cpp index 424474a430ee1803b6f2ae994f2ada0a6439da4b..54ef9af2dc6090bc3cce142a867dce9435696c49 100644 --- a/test/unittest/inner_api/src/executor_messenger_client_test.cpp +++ b/test/unittest/inner_api/src/executor_messenger_client_test.cpp @@ -49,7 +49,7 @@ HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestSendData001, Te std::shared_ptr testMsg = AuthMessage::As(message); EXPECT_NE(testMsg, nullptr); - sptr testMessenger(nullptr); + sptr testMessenger(nullptr); auto service = Common::MakeShared(testMessenger); EXPECT_NE(service, nullptr); int32_t result = service->SendData(testScheduleId, testDstRole, testMsg); @@ -83,7 +83,7 @@ HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestSendData003, Te EXPECT_CALL(*testMessenger, SendData(_, _, _)).Times(1); ON_CALL(*testMessenger, SendData) .WillByDefault( - [&testScheduleId, &testDstRole, &message](uint64_t scheduleId, ExecutorRole dstRole, + [&testScheduleId, &testDstRole, &message](uint64_t scheduleId, int32_t dstRole, const std::vector &msg) { EXPECT_EQ(scheduleId, testScheduleId); EXPECT_THAT(msg, ElementsAreArray(message)); @@ -102,7 +102,7 @@ HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestFinish001, Test int32_t testResultCode = FAIL; Attributes finalResult; - sptr testMessenger(nullptr); + sptr testMessenger(nullptr); auto service = Common::MakeShared(testMessenger); EXPECT_NE(service, nullptr); int32_t result = service->Finish(testScheduleId, testResultCode, finalResult); @@ -120,8 +120,8 @@ HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestFinish002, Test EXPECT_CALL(*testMessenger, Finish(_, _, _)).Times(1); ON_CALL(*testMessenger, Finish) .WillByDefault( - [&testScheduleId, &testResultCode](uint64_t scheduleId, ResultCode resultCode, - const std::shared_ptr &finalResult) { + [&testScheduleId, &testResultCode](uint64_t scheduleId, int32_t resultCode, + const std::vector &finalResult) { EXPECT_EQ(scheduleId, testScheduleId); EXPECT_EQ(resultCode, testResultCode); return SUCCESS; diff --git a/test/unittest/inner_api/src/executor_messenger_proxy_test.cpp b/test/unittest/inner_api/src/executor_messenger_proxy_test.cpp deleted file mode 100644 index e429b9d55b77614cc0494e553b2713ff6d56c27c..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/executor_messenger_proxy_test.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_messenger_proxy_test.h" - -#include "executor_messenger_proxy.h" -#include "iam_ptr.h" -#include "mock_remote_object.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void ExecutorMessengerProxyTest::SetUpTestCase() -{ -} - -void ExecutorMessengerProxyTest::TearDownTestCase() -{ -} - -void ExecutorMessengerProxyTest::SetUp() -{ -} - -void ExecutorMessengerProxyTest::TearDown() -{ -} - -HWTEST_F(ExecutorMessengerProxyTest, TestSendData_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorMessengerInterfaceCode::CO_AUTH_SEND_DATA); - EXPECT_TRUE(reply.WriteInt32(SUCCESS)); - return OHOS::NO_ERROR; - } - ); - - uint64_t scheduleId = 6598; - ExecutorRole dstRole = COLLECTOR; - std::vector message = {1, 2, 4, 6}; - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - EXPECT_EQ(proxy->SendData(scheduleId, dstRole, message), SUCCESS); -} - -HWTEST_F(ExecutorMessengerProxyTest, TestFinish_001, TestSize.Level0) -{ - uint64_t scheduleId = 6598; - ResultCode resultCode = SUCCESS; - std::shared_ptr finalResult = nullptr; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - EXPECT_EQ(proxy->Finish(scheduleId, resultCode, finalResult), INVALID_PARAMETERS); -} - -HWTEST_F(ExecutorMessengerProxyTest, TestFinish_002, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, ExecutorMessengerInterfaceCode::CO_AUTH_FINISH); - EXPECT_TRUE(reply.WriteInt32(SUCCESS)); - return OHOS::NO_ERROR; - } - ); - - uint64_t scheduleId = 6598; - ResultCode resultCode = SUCCESS; - std::shared_ptr finalResult = Common::MakeShared(); - EXPECT_NE(finalResult, nullptr); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - EXPECT_EQ(proxy->Finish(scheduleId, resultCode, finalResult), SUCCESS); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/executor_messenger_stub_test.cpp b/test/unittest/inner_api/src/executor_messenger_stub_test.cpp deleted file mode 100644 index d9dfbbc2a812404707f0d0b161e108011ba2ca27..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/executor_messenger_stub_test.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "executor_messenger_stub_test.h" - -#include "message_parcel.h" - -#include "iam_ptr.h" -#include "mock_executor_messenger_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void ExecutorMessengerStubTest::SetUpTestCase() -{ -} - -void ExecutorMessengerStubTest::TearDownTestCase() -{ -} - -void ExecutorMessengerStubTest::SetUp() -{ -} - -void ExecutorMessengerStubTest::TearDown() -{ -} - -HWTEST_F(ExecutorMessengerStubTest, TestSendDataStub_001, TestSize.Level0) -{ - uint64_t scheduleId = 6598; - ExecutorRole dstRole = COLLECTOR; - std::vector message = {1, 2, 4, 6}; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorMessengerInterfaceCode::CO_AUTH_SEND_DATA; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorMessengerInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(scheduleId)); - EXPECT_TRUE(data.WriteInt32(dstRole)); - EXPECT_TRUE(data.WriteUInt8Vector(message)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, SendData(_, _, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(ExecutorMessengerStubTest, TestFinishStub_001, TestSize.Level0) -{ - uint64_t scheduleId = 6598; - ResultCode resultCode = SUCCESS; - std::vector finalResult = {1, 2, 4, 6}; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = ExecutorMessengerInterfaceCode::CO_AUTH_FINISH; - - EXPECT_TRUE(data.WriteInterfaceToken(ExecutorMessengerInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(scheduleId)); - EXPECT_TRUE(data.WriteInt32(resultCode)); - EXPECT_TRUE(data.WriteUInt8Vector(finalResult)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, Finish(_, _, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/user_access_ctrl_client_test.cpp b/test/unittest/inner_api/src/user_access_ctrl_client_test.cpp index 119e27470f58d6cef7efb05252f3d2829eefc0fb..120f8b6926f2ff7d9975de7174da228e348d4b83 100644 --- a/test/unittest/inner_api/src/user_access_ctrl_client_test.cpp +++ b/test/unittest/inner_api/src/user_access_ctrl_client_test.cpp @@ -15,6 +15,7 @@ #include "user_access_ctrl_client_test.h" +#include "iam_common_defines.h" #include "iam_ptr.h" #include "user_access_ctrl_client.h" #include "user_access_ctrl_client_impl.h" @@ -64,9 +65,10 @@ HWTEST_F(UserAccessCtrlClientTest, UserAccessCtrlClientVerifyAuthToken002, TestS .WillByDefault( [&testTokenIn, &testAllowableDuration, &testCallback] (const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback) { + const sptr &callback) { EXPECT_EQ(testTokenIn, tokenIn); EXPECT_EQ(testAllowableDuration, allowableDuration); + return SUCCESS; } ); diff --git a/test/unittest/inner_api/src/user_auth_callback_proxy_test.cpp b/test/unittest/inner_api/src/user_auth_callback_proxy_test.cpp deleted file mode 100644 index 1b634c309e9a46fc96c2afbe6f53b3702ec006f9..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/user_auth_callback_proxy_test.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_callback_proxy_test.h" - -#include "iam_ptr.h" -#include "mock_remote_object.h" -#include "user_auth_callback_proxy.h" -#include "user_auth_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserAuthCallbackProxyTest::SetUpTestCase() -{ -} - -void UserAuthCallbackProxyTest::TearDownTestCase() -{ -} - -void UserAuthCallbackProxyTest::SetUp() -{ -} - -void UserAuthCallbackProxyTest::TearDown() -{ -} - -HWTEST_F(UserAuthCallbackProxyTest, TestOnResult_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, UserAuthInterfaceCode::USER_AUTH_ON_RESULT); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - int32_t result = 0; - Attributes extraInfo; - proxy->OnResult(result, extraInfo); -} - -HWTEST_F(UserAuthCallbackProxyTest, TestOnAcquireInfo_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, UserAuthInterfaceCode::USER_AUTH_ACQUIRE_INFO); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - int32_t module = 12; - int32_t acquireInfo = 20; - Attributes extraInfo; - proxy->OnAcquireInfo(module, acquireInfo, extraInfo); -} - -HWTEST_F(UserAuthCallbackProxyTest, TestOnGetExecutorPropertyResult_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, UserAuthInterfaceCode::USER_AUTH_GET_EX_PROP); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - int32_t result = 0; - Attributes attributes; - proxy->OnGetExecutorPropertyResult(result, attributes); -} - -HWTEST_F(UserAuthCallbackProxyTest, TestOnSetExecutorPropertyResult_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, static_cast(UserAuthInterfaceCode::USER_AUTH_SET_EX_PROP)); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - int32_t result = 0; - proxy->OnSetExecutorPropertyResult(result); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/user_auth_callback_service_test.cpp b/test/unittest/inner_api/src/user_auth_callback_service_test.cpp index 42855c9fde1d78c88f15894a1599da62663621bf..780cf68c1fbbe4ef787fbe404e3c2f601ca3aea8 100644 --- a/test/unittest/inner_api/src/user_auth_callback_service_test.cpp +++ b/test/unittest/inner_api/src/user_auth_callback_service_test.cpp @@ -52,8 +52,8 @@ HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest001, TestSize.L std::shared_ptr authCallback = nullptr; auto service = Common::MakeShared(authCallback); EXPECT_NE(service, nullptr); - service->OnResult(testResult, testExtraInfo); - service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo); + service->OnResult(testResult, testExtraInfo.Serialize()); + service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo.Serialize()); } HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest002, TestSize.Level0) @@ -83,8 +83,8 @@ HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest002, TestSize.L ); auto service = Common::MakeShared(authCallback); EXPECT_NE(service, nullptr); - service->OnResult(testResult, testExtraInfo); - service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo); + service->OnResult(testResult, testExtraInfo.Serialize()); + service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo.Serialize()); } HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest003, TestSize.Level0) @@ -114,8 +114,8 @@ HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest003, TestSize.L ); auto service = Common::MakeShared(identifyCallback); EXPECT_NE(service, nullptr); - service->OnResult(testResult, testExtraInfo); - service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo); + service->OnResult(testResult, testExtraInfo.Serialize()); + service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo.Serialize()); } HWTEST_F(UserAuthCallbackServiceTest, GetExecutorPropertyCallbackServiceTest001, TestSize.Level0) @@ -126,7 +126,7 @@ HWTEST_F(UserAuthCallbackServiceTest, GetExecutorPropertyCallbackServiceTest001, std::shared_ptr getPropCallback = nullptr; auto service = Common::MakeShared(getPropCallback); EXPECT_NE(service, nullptr); - service->OnGetExecutorPropertyResult(testResult, testAttr); + service->OnGetExecutorPropertyResult(testResult, testAttr.Serialize()); } HWTEST_F(UserAuthCallbackServiceTest, GetExecutorPropertyCallbackServiceTest002, TestSize.Level0) @@ -145,7 +145,7 @@ HWTEST_F(UserAuthCallbackServiceTest, GetExecutorPropertyCallbackServiceTest002, ); auto service = Common::MakeShared(getPropCallback); EXPECT_NE(service, nullptr); - service->OnGetExecutorPropertyResult(testResult, testAttr); + service->OnGetExecutorPropertyResult(testResult, testAttr.Serialize()); } HWTEST_F(UserAuthCallbackServiceTest, SetExecutorPropertyCallbackServiceTest001, TestSize.Level0) diff --git a/test/unittest/inner_api/src/user_auth_callback_stub_test.cpp b/test/unittest/inner_api/src/user_auth_callback_stub_test.cpp deleted file mode 100644 index 3c9c5d2e9853f21f0162ef5585421902c953766e..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/user_auth_callback_stub_test.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_callback_stub_test.h" - -#include "message_parcel.h" - -#include "iam_ptr.h" -#include "mock_user_auth_callback_service.h" -#include "user_auth_interface.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserAuthCallbackStubTest::SetUpTestCase() -{ -} - -void UserAuthCallbackStubTest::TearDownTestCase() -{ -} - -void UserAuthCallbackStubTest::SetUp() -{ -} - -void UserAuthCallbackStubTest::TearDown() -{ -} - -HWTEST_F(UserAuthCallbackStubTest, TestOnResultStub_001, TestSize.Level0) -{ - int32_t result = 0; - std::vector extraInfo = {1, 2, 3, 4}; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_ON_RESULT; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - EXPECT_TRUE(data.WriteUInt8Vector(extraInfo)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnResult(_, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserAuthCallbackStubTest, TestOnAcquireInfoStub_001, TestSize.Level0) -{ - int32_t module = 10; - int32_t acquireInfo = 20; - std::vector extraInfo = {1, 2, 3, 4}; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_ACQUIRE_INFO; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(module)); - EXPECT_TRUE(data.WriteInt32(acquireInfo)); - EXPECT_TRUE(data.WriteUInt8Vector(extraInfo)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnAcquireInfo(_, _, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserAuthCallbackStubTest, TestOnGetExecutorPropertyResultStub_001, TestSize.Level0) -{ - int32_t result = 0; - std::vector extraInfo = {1, 2, 3, 4}; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_EX_PROP; - - EXPECT_TRUE(data.WriteInterfaceToken(GetExecutorPropertyCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - EXPECT_TRUE(data.WriteUInt8Vector(extraInfo)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnGetExecutorPropertyResult(_, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserAuthCallbackStubTest, TestOnSetExecutorPropertyResultStub_001, TestSize.Level0) -{ - int32_t result = 0; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_SET_EX_PROP; - - EXPECT_TRUE(data.WriteInterfaceToken(SetExecutorPropertyCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnSetExecutorPropertyResult(_)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/user_auth_client_test.cpp b/test/unittest/inner_api/src/user_auth_client_test.cpp index f3a1fe2df4dfbb6cd4891ad3610f0b6b471af5ae..3301ac9fc5182cddd1b3c56ce53e32027352dc24 100644 --- a/test/unittest/inner_api/src/user_auth_client_test.cpp +++ b/test/unittest/inner_api/src/user_auth_client_test.cpp @@ -67,10 +67,10 @@ HWTEST_F(UserAuthClientTest, UserAuthClientGetEnrolledState002, TestSize.Level0) EXPECT_CALL(*service, GetEnrolledState(_, _, _)).Times(1); ON_CALL(*service, GetEnrolledState) .WillByDefault( - [&testApiVersion, &testAuthType, &credentialDigest, &credentialCount](int32_t apiVersion, AuthType authType, - EnrolledState &enrolledState) { + [&testApiVersion, &testAuthType, &credentialDigest, &credentialCount](int32_t apiVersion, int32_t authType, + IpcEnrolledState &enrolledState) { EXPECT_EQ(apiVersion, testApiVersion); - EXPECT_EQ(authType, testAuthType); + EXPECT_EQ(authType, static_cast(testAuthType)); enrolledState.credentialDigest = credentialDigest; enrolledState.credentialCount = credentialCount; @@ -111,8 +111,8 @@ HWTEST_F(UserAuthClientTest, UserAuthClientGetAvailableStatus002, TestSize.Level EXPECT_CALL(*service, GetAvailableStatus(_, _, _, _)).Times(1); ON_CALL(*service, GetAvailableStatus) .WillByDefault( - [&testApiVersion, &testAuthType, &testAtl](int32_t apiVersion, int32_t userId, AuthType authType, - AuthTrustLevel authTrustLevel) { + [&testApiVersion, &testAuthType, &testAtl](int32_t apiVersion, int32_t userId, int32_t authType, + uint32_t authTrustLevel) { return SUCCESS; } ); @@ -157,16 +157,23 @@ HWTEST_F(UserAuthClientTest, UserAuthClientGetProperty002, TestSize.Level0) EXPECT_CALL(*service, GetProperty(_, _, _, _)).Times(1); ON_CALL(*service, GetProperty) .WillByDefault( - [&testUserId, &testRequest](int32_t userId, AuthType authType, - const std::vector &keys, - sptr &callback) { + [&testUserId, &testRequest](int32_t userId, int32_t authType, + const std::vector &keys, const sptr &callback) { EXPECT_EQ(userId, testUserId); - EXPECT_EQ(authType, testRequest.authType); - EXPECT_THAT(keys, ElementsAreArray(testRequest.keys)); + EXPECT_EQ(authType, static_cast(testRequest.authType)); + std::vector attrkeys; + attrkeys.resize(testRequest.keys.size()); + std::transform(testRequest.keys.begin(), testRequest.keys.end(), attrkeys.begin(), + [](Attributes::AttributeKey key) { + return static_cast(key); + }); + + EXPECT_THAT(keys, ElementsAreArray(attrkeys)); if (callback != nullptr) { Attributes extraInfo; - callback->OnGetExecutorPropertyResult(SUCCESS, extraInfo); + callback->OnGetExecutorPropertyResult(SUCCESS, extraInfo.Serialize()); } + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -208,13 +215,14 @@ HWTEST_F(UserAuthClientTest, UserAuthClientSetProperty002, TestSize.Level0) EXPECT_CALL(*service, SetProperty(_, _, _, _)).Times(1); ON_CALL(*service, SetProperty) .WillByDefault( - [&testUserId, &testRequest](int32_t userId, AuthType authType, const Attributes &attributes, - sptr &callback) { + [&testUserId, &testRequest](int32_t userId, int32_t authType, const std::vector &attributes, + const sptr &callback) { EXPECT_EQ(userId, testUserId); - EXPECT_EQ(authType, testRequest.authType); + EXPECT_EQ(authType, static_cast(testRequest.authType)); if (callback != nullptr) { callback->OnSetExecutorPropertyResult(SUCCESS); } + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -261,21 +269,22 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginNorthAuthentication002, TestSize auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, Auth(_, _, _, _, _)).Times(1); + EXPECT_CALL(*service, Auth(_, _, _, _)).Times(1); ON_CALL(*service, Auth) .WillByDefault( [&testApiVersion, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t apiVersion, - const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, - sptr &callback) { + const IpcAuthParamInner &ipcAuthParamInner, const sptr &callback, + uint64_t &contextId) { EXPECT_EQ(apiVersion, testApiVersion); - EXPECT_THAT(challenge, ElementsAreArray(testChallenge)); - EXPECT_EQ(authType, testAuthType); - EXPECT_EQ(authTrustLevel, testAtl); + EXPECT_THAT(ipcAuthParamInner.challenge, ElementsAreArray(testChallenge)); + EXPECT_EQ(ipcAuthParamInner.authType, static_cast(testAuthType)); + EXPECT_EQ(ipcAuthParamInner.authTrustLevel, testAtl); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } - return testContextId; + contextId = testContextId; + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -326,20 +335,22 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication002, TestSize.Leve auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthUser(_, _, _)).Times(1); + EXPECT_CALL(*service, AuthUser(_, _, _, _)).Times(1); ON_CALL(*service, AuthUser) .WillByDefault( - [&testAuthParam, &testContextId](AuthParamInner &authParam, - std::optional &remoteAuthParam, sptr &callback) { + [&testAuthParam, &testContextId](const IpcAuthParamInner &authParam, + const IpcRemoteAuthParam &remoteAuthParam, const sptr &callback, + uint64_t &contextId) { EXPECT_EQ(authParam.userId, testAuthParam.userId); EXPECT_THAT(authParam.challenge, ElementsAreArray(testAuthParam.challenge)); EXPECT_EQ(authParam.authType, testAuthParam.authType); EXPECT_EQ(authParam.authTrustLevel, testAuthParam.authTrustLevel); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } - return testContextId; + contextId = testContextId; + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -445,18 +456,19 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginIdentification_1002, TestSize.Le auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, Identify(_, _, _)).Times(1); + EXPECT_CALL(*service, Identify(_, _, _, _)).Times(1); ON_CALL(*service, Identify) .WillByDefault( [&testChallenge, &testAuthType, &testContextId](const std::vector &challenge, - AuthType authType, sptr &callback) { + int32_t authType, const sptr &callback, uint64_t &contextId) { EXPECT_THAT(challenge, ElementsAreArray(testChallenge)); - EXPECT_EQ(authType, testAuthType); + EXPECT_EQ(authType, static_cast(testAuthType)); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } - return testContextId; + contextId = testContextId; + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -563,8 +575,8 @@ HWTEST_F(UserAuthClientTest, UserAuthClientGetVersion003, TestSize.Level0) int32_t version; EXPECT_EQ(UserAuthClientImpl::Instance().GetVersion(version), GENERAL_ERROR); - EXPECT_EQ(UserAuthClientImpl::Instance().GetVersion(version), GENERAL_ERROR); - EXPECT_EQ(UserAuthClientImpl::Instance().GetVersion(version), GENERAL_ERROR); + EXPECT_EQ(UserAuthClientImpl::Instance().GetVersion(version), SUCCESS); + EXPECT_EQ(UserAuthClientImpl::Instance().GetVersion(version), SUCCESS); EXPECT_NE(dr, nullptr); sptr remote(nullptr); @@ -594,7 +606,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth002, TestSize.Level0) WidgetParam widgetParam; std::shared_ptr testCallback = nullptr; uint64_t widgetAuth = UserAuthClientImpl::Instance().BeginWidgetAuth(apiVersion, authParam, - widgetParam, testCallback); + widgetParam, testCallback); EXPECT_EQ(widgetAuth, 0); } @@ -609,23 +621,25 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth003, TestSize.Level0) auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); - uint64_t testContextVersion = 1; + uint64_t testContextId = 1; auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthWidget(_, _, _, _, _)).WillRepeatedly(Return(true)); + EXPECT_CALL(*service, AuthWidget(_, _, _, _, _, _)).Times(1); ON_CALL(*service, AuthWidget) .WillByDefault( - [&testVersion, &testParam, &testWidgetParamInner, &testContextVersion](int32_t apiVersion, - const AuthParamInner &authParam, const WidgetParamInner &widgetParam, - sptr &callback, sptr &modalCallback) { + [&testVersion, &testParam, &testWidgetParamInner, &testContextId](int32_t apiVersion, + const IpcAuthParamInner &authParam, const IpcWidgetParamInner &widgetParam, + const sptr &callback, const sptr &modalCallback, + uint64_t &contextId) { EXPECT_EQ(apiVersion, testVersion); - EXPECT_EQ(authParam.authTypes, testParam.authTypes); + EXPECT_EQ(authParam.authTypes[0], static_cast(testParam.authTypes[0])); EXPECT_EQ(widgetParam.title, testWidgetParamInner.title); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(static_cast(ResultCode::GENERAL_ERROR), extraInfo); + callback->OnResult(static_cast(ResultCode::SUCCESS), extraInfo.Serialize()); } - return testContextVersion; + contextId = testContextId; + return SUCCESS; } ); @@ -633,11 +647,13 @@ HWTEST_F(UserAuthClientTest, UserAuthClientBeginWidgetAuth003, TestSize.Level0) sptr dr(nullptr); CallRemoteObject(service, obj, dr); WidgetAuthParam testAuthParam = {}; + testAuthParam.challenge = {0}; + testAuthParam.authTypes = {ALL}; WidgetParam testWidgetParam = {}; testWidgetParam.title = "title"; uint64_t widgetAuth = UserAuthClientImpl::Instance().BeginWidgetAuth(testVersion, testAuthParam, testWidgetParam, testCallback); - EXPECT_EQ(widgetAuth, testContextVersion); + EXPECT_EQ(widgetAuth, testContextId); dr->OnRemoteDied(obj); IpcClientUtils::ResetObj(); } @@ -665,15 +681,14 @@ HWTEST_F(UserAuthClientTest, UserAuthClientSetWidgetCallback003, TestSize.Level0 auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); - uint64_t testContextVersion = 1; auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, RegisterWidgetCallback(_, _)).WillRepeatedly(Return(true)); + EXPECT_CALL(*service, RegisterWidgetCallback(_, _)).Times(1); ON_CALL(*service, RegisterWidgetCallback) .WillByDefault( - [&testVersion, &testContextVersion](int32_t version, sptr &callback) { + [&testVersion](int32_t version, const sptr &callback) { EXPECT_EQ(version, testVersion); - return testContextVersion; + return SUCCESS; } ); @@ -681,7 +696,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientSetWidgetCallback003, TestSize.Level0 sptr dr(nullptr); CallRemoteObject(service, obj, dr); uint64_t widgetAuth = UserAuthClientImpl::Instance().SetWidgetCallback(testVersion, testCallback); - EXPECT_EQ(widgetAuth, testContextVersion); + EXPECT_EQ(widgetAuth, SUCCESS); dr->OnRemoteDied(obj); IpcClientUtils::ResetObj(); } @@ -726,15 +741,15 @@ HWTEST_F(UserAuthClientTest, UserAuthClientRegistUserAuthSuccessEventListener001 authTypeList.push_back(AuthType::FACE); authTypeList.push_back(AuthType::FINGERPRINT); - sptr testCallback = new MockAuthEventListenerService(); + auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, RegistUserAuthSuccessEventListener(_, _)).Times(1); + EXPECT_CALL(*service, RegistUserAuthSuccessEventListener(_)).Times(1); ON_CALL(*service, RegistUserAuthSuccessEventListener) .WillByDefault( - [](const std::vector &authType, const sptr &callback) { + [](const sptr &callback) { return SUCCESS; } ); @@ -765,7 +780,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientRegistUserAuthSuccessEventListener003 authTypeList.push_back(AuthType::FACE); authTypeList.push_back(AuthType::FINGERPRINT); - sptr testCallback = new MockAuthEventListenerService(); + auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); int32_t ret = UserAuthClientImpl::Instance().RegistUserAuthSuccessEventListener(authTypeList, testCallback); @@ -774,7 +789,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientRegistUserAuthSuccessEventListener003 HWTEST_F(UserAuthClientTest, UserAuthClientUnRegistUserAuthSuccessEventListener001, TestSize.Level0) { - sptr testCallback = new MockAuthEventListenerService(); + auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); auto service = Common::MakeShared(); @@ -782,7 +797,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientUnRegistUserAuthSuccessEventListener0 EXPECT_CALL(*service, UnRegistUserAuthSuccessEventListener(_)).Times(1); ON_CALL(*service, UnRegistUserAuthSuccessEventListener) .WillByDefault( - [](const sptr &callback) { + [](const sptr &callback) { return SUCCESS; } ); @@ -803,7 +818,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientUnRegistUserAuthSuccessEventListener0 HWTEST_F(UserAuthClientTest, UserAuthClientUnRegistUserAuthSuccessEventListener003, TestSize.Level0) { - sptr testCallback = new MockAuthEventListenerService(); + auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); int32_t ret = UserAuthClientImpl::Instance().UnRegistUserAuthSuccessEventListener(testCallback); @@ -825,8 +840,7 @@ HWTEST_F(UserAuthClientTest, UserAuthClientSetGlobalConfigParam002, TestSize.Lev sptr obj(new (std::nothrow) MockRemoteObject()); sptr dr(nullptr); CallRemoteObject(service, obj, dr); - - EXPECT_EQ(UserAuthClient::GetInstance().SetGlobalConfigParam(param), INVALID_PARAMETERS); + param.type = ENABLE_STATUS; EXPECT_EQ(UserAuthClient::GetInstance().SetGlobalConfigParam(param), SUCCESS); EXPECT_NE(dr, nullptr); @@ -873,14 +887,21 @@ HWTEST_F(UserAuthClientTest, UserAuthClientGetPropertyById002, TestSize.Level0) EXPECT_CALL(*service, GetPropertyById(_, _, _)).Times(1); ON_CALL(*service, GetPropertyById) .WillByDefault( - [&testCredentialId, &testKeys](uint64_t credentialId, const std::vector &keys, - sptr &callback) { + [&testCredentialId, &testKeys](uint64_t credentialId, const std::vector &keys, + const sptr &callback) { EXPECT_EQ(credentialId, testCredentialId); - EXPECT_THAT(keys, ElementsAreArray(testKeys)); + std::vector attrkeys; + attrkeys.resize(testKeys.size()); + std::transform(testKeys.begin(), testKeys.end(), attrkeys.begin(), [](Attributes::AttributeKey key) { + return static_cast(key); + }); + + EXPECT_THAT(keys, ElementsAreArray(attrkeys)); if (callback != nullptr) { Attributes extraInfo; - callback->OnGetExecutorPropertyResult(SUCCESS, extraInfo); + callback->OnGetExecutorPropertyResult(SUCCESS, extraInfo.Serialize()); } + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); diff --git a/test/unittest/inner_api/src/user_auth_event_listener_stub_test.cpp b/test/unittest/inner_api/src/user_auth_event_listener_stub_test.cpp index 7fee2ee20ccafa0e90efac1277573d490142128a..67c65adff14232ef5aa4ab4cf52e2312879befa8 100644 --- a/test/unittest/inner_api/src/user_auth_event_listener_stub_test.cpp +++ b/test/unittest/inner_api/src/user_auth_event_listener_stub_test.cpp @@ -13,13 +13,14 @@ * limitations under the License. */ -#include "user_auth_event_listener_stub.h" +#include "user_auth_event_listener_callback_stub.h" #include #include "iam_logger.h" #include "mock_user_auth_callback_service.h" -#include "user_auth_interface.h" +#include "iuser_auth.h" +#include "user_auth_interface_ipc_interface_code.h" using namespace testing; using namespace testing::ext; diff --git a/test/unittest/inner_api/src/user_auth_napi_client_test.cpp b/test/unittest/inner_api/src/user_auth_napi_client_test.cpp index befc1cc413a43d75b563540a8816e923284d0412..99ccd1f29eeb3cf627455241c50c992601c0b964 100644 --- a/test/unittest/inner_api/src/user_auth_napi_client_test.cpp +++ b/test/unittest/inner_api/src/user_auth_napi_client_test.cpp @@ -66,23 +66,25 @@ HWTEST_F(UserAuthNapiClientTest, UserAuthNapiClientBeginWidgetAuth002, TestSize. auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); - uint64_t testContextVersion = 1; + uint64_t testContextId = 1; auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthWidget(_, _, _, _, _)).WillRepeatedly(Return(true)); + EXPECT_CALL(*service, AuthWidget(_, _, _, _, _, _)).Times(1); ON_CALL(*service, AuthWidget) .WillByDefault( - [&testVersion, &testParam, &testWidgetParamInner, &testContextVersion](int32_t apiVersion, - const AuthParamInner &authParam, const WidgetParamInner &widgetParam, - sptr &callback, sptr &modalCallback) { + [&testVersion, &testParam, &testWidgetParamInner, &testContextId](int32_t apiVersion, + const IpcAuthParamInner &authParam, const IpcWidgetParamInner &widgetParam, + const sptr &callback, const sptr &modalCallback, + uint64_t &contextId) { EXPECT_EQ(apiVersion, testVersion); - EXPECT_EQ(authParam.authTypes, testParam.authTypes); + EXPECT_EQ(authParam.authTypes[0], static_cast(testParam.authTypes[0])); EXPECT_EQ(widgetParam.title, testWidgetParamInner.title); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(static_cast(ResultCode::GENERAL_ERROR), extraInfo); + callback->OnResult(static_cast(ResultCode::GENERAL_ERROR), extraInfo.Serialize()); } - return testContextVersion; + contextId = testContextId; + return SUCCESS; } ); @@ -90,12 +92,14 @@ HWTEST_F(UserAuthNapiClientTest, UserAuthNapiClientBeginWidgetAuth002, TestSize. sptr dr(nullptr); CallRemoteObject(service, obj, dr); AuthParamInner testAuthParam = {}; + testAuthParam.challenge = {0}; + testAuthParam.authTypes = {ALL}; UserAuthNapiClientImpl::WidgetParamNapi testWidgetParam = {}; testWidgetParam.title = "title"; std::shared_ptr testModalCallback = Common::MakeShared(); uint64_t widgetAuth = UserAuthNapiClientImpl::Instance().BeginWidgetAuth(testVersion, testAuthParam, testWidgetParam, testCallback, testModalCallback); - EXPECT_EQ(widgetAuth, testContextVersion); + EXPECT_EQ(widgetAuth, testContextId); dr->OnRemoteDied(obj); IpcClientUtils::ResetObj(); } @@ -126,23 +130,25 @@ HWTEST_F(UserAuthNapiClientTest, UserAuthNapiClientBeginWidgetAuth004, TestSize. auto testCallback = Common::MakeShared(); EXPECT_NE(testCallback, nullptr); - uint64_t testContextVersion = 1; + uint64_t testContextId = 1; auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthWidget(_, _, _, _, _)).WillRepeatedly(Return(true)); + EXPECT_CALL(*service, AuthWidget(_, _, _, _, _, _)).Times(1); ON_CALL(*service, AuthWidget) .WillByDefault( - [&testVersion, &testParam, &testWidgetParamInner, &testContextVersion](int32_t apiVersion, - const AuthParamInner &authParam, const WidgetParamInner &widgetParam, - sptr &callback, sptr &modalCallback) { + [&testVersion, &testParam, &testWidgetParamInner, &testContextId](int32_t apiVersion, + const IpcAuthParamInner &authParam, const IpcWidgetParamInner &widgetParam, + const sptr &callback, const sptr &modalCallback, + uint64_t &contextId) { EXPECT_EQ(apiVersion, testVersion); - EXPECT_EQ(authParam.authTypes, testParam.authTypes); + EXPECT_EQ(authParam.authTypes[0], static_cast(testParam.authTypes[0])); EXPECT_EQ(widgetParam.title, testWidgetParamInner.title); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(static_cast(ResultCode::GENERAL_ERROR), extraInfo); + callback->OnResult(static_cast(ResultCode::GENERAL_ERROR), extraInfo.Serialize()); } - return testContextVersion; + contextId = testContextId; + return SUCCESS; } ); @@ -150,12 +156,14 @@ HWTEST_F(UserAuthNapiClientTest, UserAuthNapiClientBeginWidgetAuth004, TestSize. sptr dr(nullptr); CallRemoteObject(service, obj, dr); AuthParamInner testAuthParam = {}; + testAuthParam.challenge = {0}; + testAuthParam.authTypes = {ALL}; UserAuthNapiClientImpl::WidgetParamNapi testWidgetParam = {}; testWidgetParam.title = "title"; std::shared_ptr testModalCallback = Common::MakeShared(); uint64_t widgetAuth = UserAuthNapiClientImpl::Instance().BeginWidgetAuth(testVersion, testAuthParam, testWidgetParam, testCallback, testModalCallback); - EXPECT_EQ(widgetAuth, testContextVersion); + EXPECT_EQ(widgetAuth, testContextId); dr->OnRemoteDied(obj); IpcClientUtils::ResetObj(); } diff --git a/test/unittest/inner_api/src/user_auth_proxy_test.cpp b/test/unittest/inner_api/src/user_auth_proxy_test.cpp deleted file mode 100644 index b100d4082dadc43c88f8564c91efe883ea10846e..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/user_auth_proxy_test.cpp +++ /dev/null @@ -1,1056 +0,0 @@ -/* - * Copyright (C) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_proxy_test.h" - -#include "iam_ptr.h" -#include "user_auth_proxy.h" -#include "mock_modal_callback.h" -#include "mock_remote_object.h" -#include "mock_user_auth_service.h" -#include "mock_user_access_ctrl_callback_service.h" -#include "mock_user_access_ctrl_client_callback.h" -#include "mock_user_auth_client_callback.h" -#include "mock_user_auth_callback_service.h" -#include "mock_iuser_auth_widget_callback.h" -#include "modal_callback_service.h" -#include "user_auth_callback_service.h" -#include "user_access_ctrl_callback_service.h" -#include "widget_callback_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserAuthProxyTest::SetUpTestCase() -{ -} - -void UserAuthProxyTest::TearDownTestCase() -{ -} - -void UserAuthProxyTest::SetUp() -{ -} - -void UserAuthProxyTest::TearDown() -{ -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetEnrolledState001, TestSize.Level0) -{ - int32_t testApiVersion = 0; - AuthType testAuthType = FACE; - uint16_t credentialDigest = 23962; - uint16_t credentialCount = 1; - EnrolledState enrolledState; - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, GetEnrolledState(_, _, _)) - .Times(Exactly(1)) - .WillOnce([testApiVersion, testAuthType, credentialDigest, credentialCount](int32_t apiVersion, - AuthType authType, EnrolledState &enrolledState) { - EXPECT_EQ(testApiVersion, apiVersion); - EXPECT_EQ(testAuthType, authType); - enrolledState.credentialDigest = credentialDigest; - enrolledState.credentialCount = credentialCount; - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->GetEnrolledState(testApiVersion, testAuthType, enrolledState), SUCCESS); - EXPECT_EQ(credentialDigest, enrolledState.credentialDigest); - EXPECT_EQ(credentialCount, enrolledState.credentialCount); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetEnrolledState002, TestSize.Level0) -{ - int32_t testApiVersion = 0; - AuthType testAuthType = FACE; - uint16_t credentialDigest = 23962; - uint16_t credentialCount = 1; - EnrolledState enrolledState; - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, GetEnrolledState(_, _, _)) - .Times(Exactly(1)) - .WillOnce([testApiVersion, testAuthType, credentialDigest, credentialCount](int32_t apiVersion, - AuthType authType, EnrolledState &enrolledState) { - EXPECT_EQ(testApiVersion, apiVersion); - EXPECT_EQ(testAuthType, authType); - enrolledState.credentialDigest = credentialDigest; - enrolledState.credentialCount = credentialCount; - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - reply.WriteInt32(GENERAL_ERROR); - return SUCCESS; - }); - EXPECT_EQ(proxy->GetEnrolledState(testApiVersion, testAuthType, enrolledState), SUCCESS); - EXPECT_EQ(credentialDigest, enrolledState.credentialDigest); - EXPECT_EQ(credentialCount, enrolledState.credentialCount); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetAvailableStatus, TestSize.Level0) -{ - static const int32_t testApiVersion = 0; - static const AuthType testAuthType = FACE; - static const AuthTrustLevel testAuthTrustLevel = ATL3; - static const int32_t testUserId = 100; - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, GetAvailableStatus(_, _, _, _)) - .Times(Exactly(1)) - .WillOnce([](int32_t apiVersion, int32_t userId, AuthType authType, AuthTrustLevel authTrustLevel) { - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(2); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->GetAvailableStatus(testApiVersion, testUserId, testAuthType, testAuthTrustLevel), SUCCESS); - EXPECT_EQ(proxy->GetAvailableStatus(testApiVersion, testAuthType, testAuthTrustLevel), SUCCESS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetProperty001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const AuthType testAuthType = FACE; - std::vector testKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getPropCallback = Common::MakeShared(); - EXPECT_NE(getPropCallback, nullptr); - sptr testCallback( - new (std::nothrow) GetExecutorPropertyCallbackService(getPropCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, GetProperty(_, _, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](std::optional userId, AuthType authType, - const std::vector &keys, sptr &callback) { - EXPECT_TRUE(userId.has_value()); - EXPECT_EQ(userId.value(), testUserId); - EXPECT_EQ(authType, testAuthType); - EXPECT_THAT(keys, ElementsAre(Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE)); - EXPECT_EQ(callback, testCallback); - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->GetProperty(testUserId, testAuthType, testKeys, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetProperty002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const AuthType testAuthType = FACE; - std::vector testKeys = {}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - proxy->GetProperty(testUserId, testAuthType, testKeys, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetProperty003, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const AuthType testAuthType = FACE; - std::vector testKeys = {}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getPropCallback = Common::MakeShared(); - EXPECT_NE(getPropCallback, nullptr); - sptr testCallback( - new (std::nothrow) GetExecutorPropertyCallbackService(getPropCallback)); - proxy->GetProperty(testUserId, testAuthType, testKeys, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetProperty004, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const AuthType testAuthType = FACE; - std::vector testKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE}; - testKeys.resize(513); - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getPropCallback = Common::MakeShared(); - EXPECT_NE(getPropCallback, nullptr); - sptr testCallback( - new (std::nothrow) GetExecutorPropertyCallbackService(getPropCallback)); - proxy->GetProperty(testUserId, testAuthType, testKeys, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxySetProperty001, TestSize.Level0) -{ - static const AuthType testAuthType = FACE; - - Attributes testAttr; - EXPECT_EQ(testAttr.SetInt32Value(Attributes::ATTR_RESULT_CODE, 1), true); - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto setPropCallback = Common::MakeShared(); - EXPECT_NE(setPropCallback, nullptr); - sptr testCallback( - new (std::nothrow) SetExecutorPropertyCallbackService(setPropCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, SetProperty(_, _, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t userId, AuthType authType, - const Attributes &attributes, sptr &callback) { - EXPECT_EQ(userId, 0); - EXPECT_EQ(authType, testAuthType); - int32_t resultCode; - EXPECT_EQ(attributes.GetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode), true); - EXPECT_EQ(resultCode, 1); - EXPECT_EQ(callback, testCallback); - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->SetProperty(0, testAuthType, testAttr, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxySetProperty002, TestSize.Level0) -{ - static const AuthType testAuthType = FACE; - - Attributes testAttr; - EXPECT_EQ(testAttr.SetInt32Value(Attributes::ATTR_RESULT_CODE, 1), true); - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - proxy->SetProperty(0, testAuthType, testAttr, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuth001, TestSize.Level0) -{ - static const int32_t testApiVersion = 0; - static const AuthType testAuthType = FACE; - static const AuthTrustLevel testAtl = ATL1; - const std::vector testChallenge = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto authCallback = Common::MakeShared(); - EXPECT_NE(authCallback, nullptr); - sptr testCallback(new (std::nothrow) UserAuthCallbackService(authCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, Auth(_, _, _, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t apiVersion, const std::vector &challenge, - AuthType authType, AuthTrustLevel authTrustLevel, sptr &callback) { - EXPECT_EQ(apiVersion, testApiVersion); - EXPECT_THAT(challenge, ElementsAre(1, 2, 3, 4)); - EXPECT_EQ(authType, testAuthType); - EXPECT_EQ(authTrustLevel, testAtl); - EXPECT_EQ(callback, testCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->Auth(testApiVersion, testChallenge, testAuthType, testAtl, testCallback), SUCCESS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuth002, TestSize.Level0) -{ - static const int32_t testApiVersion = 0; - static const AuthType testAuthType = FACE; - static const AuthTrustLevel testAtl = ATL1; - const std::vector testChallenge = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - EXPECT_EQ(proxy->Auth(testApiVersion, testChallenge, testAuthType, testAtl, testCallback), BAD_CONTEXT_ID); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser001, TestSize.Level0) -{ - AuthParamInner testAuthParamInner = { - .userId = 200, - .challenge = {1, 2, 3, 4}, - .authType = FACE, - .authTrustLevel = ATL1, - }; - std::optional testRemoteAuthParam = std::nullopt; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto authCallback = Common::MakeShared(); - EXPECT_NE(authCallback, nullptr); - sptr testCallback(new (std::nothrow) UserAuthCallbackService(authCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthUser(_, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback, &testAuthParamInner](AuthParamInner &authParam, - std::optional &remoteAuthParam, sptr &callback) { - EXPECT_EQ(authParam.userId, testAuthParamInner.userId); - EXPECT_THAT(authParam.challenge, ElementsAre(1, 2, 3, 4)); - EXPECT_EQ(authParam.authType, testAuthParamInner.authType); - EXPECT_EQ(authParam.authTrustLevel, testAuthParamInner.authTrustLevel); - EXPECT_EQ(callback, testCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->AuthUser(testAuthParamInner, testRemoteAuthParam, testCallback), SUCCESS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser002, TestSize.Level0) -{ - AuthParamInner testAuthParamInner = { - .userId = 200, - .challenge = {1, 2, 3, 4}, - .authType = FACE, - .authTrustLevel = ATL1, - }; - RemoteAuthParam param = {}; - param.verifierNetworkId = "123"; - param.collectorNetworkId = "1233324321423412344134"; - param.collectorTokenId = 1233; - std::optional testRemoteAuthParam = param; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - EXPECT_EQ(proxy->AuthUser(testAuthParamInner, testRemoteAuthParam, testCallback), BAD_CONTEXT_ID); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser003, TestSize.Level0) -{ - AuthParamInner testAuthParamInner = { - .userId = 200, - .challenge = {1, 2, 3, 4}, - .authType = FACE, - .authTrustLevel = ATL1, - }; - RemoteAuthParam param = {}; - param.verifierNetworkId = "123"; - param.collectorNetworkId = "1233324321423412344134"; - param.collectorTokenId = 1233; - std::optional testRemoteAuthParam = param; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto authCallback = Common::MakeShared(); - EXPECT_NE(authCallback, nullptr); - sptr testCallback(new (std::nothrow) UserAuthCallbackService(authCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AuthUser(_, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback, &testAuthParamInner](AuthParamInner &authParam, - std::optional &remoteAuthParam, sptr &callback) { - EXPECT_EQ(authParam.userId, testAuthParamInner.userId); - EXPECT_THAT(authParam.challenge, ElementsAre(1, 2, 3, 4)); - EXPECT_EQ(authParam.authType, testAuthParamInner.authType); - EXPECT_EQ(authParam.authTrustLevel, testAuthParamInner.authTrustLevel); - EXPECT_EQ(callback, testCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->AuthUser(testAuthParamInner, testRemoteAuthParam, testCallback), SUCCESS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthUser004, TestSize.Level0) -{ - AuthParamInner testAuthParamInner = { - .userId = 200, - .challenge = {1, 2, 3, 4}, - .authType = FACE, - .authTrustLevel = ATL1, - }; - RemoteAuthParam param = {}; - param.collectorNetworkId = "1233324321423412344134"; - param.collectorTokenId = 1233; - std::optional testRemoteAuthParam = param; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto authCallback = Common::MakeShared(); - EXPECT_NE(authCallback, nullptr); - sptr testCallback(new (std::nothrow) UserAuthCallbackService(authCallback)); - EXPECT_EQ(proxy->AuthUser(testAuthParamInner, testRemoteAuthParam, testCallback), BAD_CONTEXT_ID); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyCancelAuthOrIdentify, TestSize.Level0) -{ - static const uint64_t testContextId = 200; - static const int32_t testCancelReason = 0; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, CancelAuthOrIdentify(_, _)) - .Times(Exactly(1)) - .WillOnce([](uint64_t contextId, int32_t cancelReason) { - EXPECT_EQ(contextId, testContextId); - EXPECT_EQ(cancelReason, testCancelReason); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->CancelAuthOrIdentify(testContextId, testCancelReason); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyIdentify001, TestSize.Level0) -{ - static const AuthType testAuthType = FACE; - const std::vector testChallenge = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto identifyCallback = Common::MakeShared(); - EXPECT_NE(identifyCallback, nullptr); - sptr testCallback(new (std::nothrow) UserAuthCallbackService(identifyCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, Identify(_, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](const std::vector &challenge, AuthType authType, - sptr &callback) { - EXPECT_THAT(challenge, ElementsAre(1, 2, 3, 4)); - EXPECT_EQ(authType, testAuthType); - EXPECT_EQ(callback, testCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->Identify(testChallenge, testAuthType, testCallback), SUCCESS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyIdentify002, TestSize.Level0) -{ - static const AuthType testAuthType = FACE; - const std::vector testChallenge = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - EXPECT_EQ(proxy->Identify(testChallenge, testAuthType, testCallback), BAD_CONTEXT_ID); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget001, TestSize.Level0) -{ - static const int32_t testApiVersion = 0; - AuthParamInner authParam; - WidgetParamInner widgetParam; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto identifyCallback = Common::MakeShared(); - EXPECT_NE(identifyCallback, nullptr); - sptr testCallback = - new (std::nothrow) UserAuthCallbackService(identifyCallback); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - sptr testModalCallback = new MockModalCallback(); - EXPECT_NE(testModalCallback, nullptr); - auto *mockModalCallback = static_cast(testModalCallback.GetRefPtr()); - EXPECT_NE(mockModalCallback, nullptr); - EXPECT_CALL(*mockModalCallback, SendCommand(_, _)).Times(0); - EXPECT_CALL(*service, AuthWidget(_, _, _, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback, &testModalCallback](int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback, - sptr &modalCallback) { - EXPECT_EQ(apiVersion, testApiVersion); - EXPECT_EQ(callback, testCallback); - EXPECT_EQ(modalCallback, testModalCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->AuthWidget(testApiVersion, authParam, widgetParam, testCallback, testModalCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget002, TestSize.Level0) -{ - static const int32_t testApiVersion = 0; - AuthParamInner authParam; - WidgetParamInner widgetParam; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - sptr testModalCallback(nullptr); - proxy->AuthWidget(testApiVersion, authParam, widgetParam, testCallback, testModalCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyAuthWidget003, TestSize.Level0) -{ - static const int32_t testApiVersion = 0; - AuthParamInner authParam; - authParam.authTypes.push_back(PIN); - authParam.reuseUnlockResult.isReuse = true; - WidgetParamInner widgetParam; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto identifyCallback = Common::MakeShared(); - EXPECT_NE(identifyCallback, nullptr); - sptr testCallback = - new (std::nothrow) UserAuthCallbackService(identifyCallback); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - sptr testModalCallback = new MockModalCallback(); - EXPECT_NE(testModalCallback, nullptr); - auto *mockModalCallback = static_cast(testModalCallback.GetRefPtr()); - EXPECT_NE(mockModalCallback, nullptr); - EXPECT_CALL(*mockModalCallback, SendCommand(_, _)).Times(0); - EXPECT_CALL(*service, AuthWidget(_, _, _, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback, &testModalCallback](int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback, - sptr &modalCallback) { - EXPECT_EQ(apiVersion, testApiVersion); - EXPECT_EQ(callback, testCallback); - EXPECT_EQ(modalCallback, testModalCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->AuthWidget(testApiVersion, authParam, widgetParam, testCallback, testModalCallback), SUCCESS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyNotice001, TestSize.Level0) -{ - static const NoticeType testNoticeType = NoticeType::WIDGET_NOTICE; - static const std::string testEventData = "notice"; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, Notice(_, _)) - .Times(Exactly(1)) - .WillOnce([](NoticeType noticeType, const std::string &eventData) { - EXPECT_EQ(noticeType, testNoticeType); - EXPECT_EQ(eventData, testEventData); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->Notice(testNoticeType, testEventData); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyRegisterWidgetCallback001, TestSize.Level0) -{ - static const int32_t testVersion = 0; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - auto identifyCallback = Common::MakeShared(); - EXPECT_NE(identifyCallback, nullptr); - sptr testCallback = - new (std::nothrow) WidgetCallbackService(identifyCallback); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, RegisterWidgetCallback(_, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t version, sptr &callback) { - EXPECT_EQ(version, testVersion); - EXPECT_EQ(callback, testCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->RegisterWidgetCallback(testVersion, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyRegisterWidgetCallback002, TestSize.Level0) -{ - static const int32_t testVersion = 0; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr callback(nullptr); - EXPECT_EQ(proxy->RegisterWidgetCallback(testVersion, callback), GENERAL_ERROR); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyRegistUserAuthSuccessEventListener001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - sptr testCallback = new (std::nothrow) MockAuthEventListenerService(); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, RegistUserAuthSuccessEventListener(_, _)) - .Times(Exactly(1)) - .WillOnce([](const std::vector &authType, const sptr &callback) { - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - std::vector authTypeList; - authTypeList.push_back(AuthType::PIN); - authTypeList.push_back(AuthType::FACE); - authTypeList.push_back(AuthType::FINGERPRINT); - proxy->RegistUserAuthSuccessEventListener(authTypeList, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyRegistUserAuthSuccessEventListener002, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - std::vector authTypeList; - authTypeList.push_back(AuthType::PIN); - authTypeList.push_back(AuthType::FACE); - authTypeList.push_back(AuthType::FINGERPRINT); - EXPECT_EQ(proxy->RegistUserAuthSuccessEventListener(authTypeList, nullptr), GENERAL_ERROR); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyUnRegistUserAuthSuccessEventListener001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - sptr testCallback = new (std::nothrow) MockAuthEventListenerService(); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, UnRegistUserAuthSuccessEventListener(_)) - .Times(Exactly(1)) - .WillOnce([](const sptr &callback) { - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->UnRegistUserAuthSuccessEventListener(testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyUnRegistUserAuthSuccessEventListener002, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - EXPECT_EQ(proxy->UnRegistUserAuthSuccessEventListener(nullptr), GENERAL_ERROR); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxySetGlobalConfigParam001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - GlobalConfigParam param = {}; - EXPECT_EQ(proxy->SetGlobalConfigParam(param), INVALID_PARAMETERS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxySetGlobalConfigParam002, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, SetGlobalConfigParam(_)) - .Times(Exactly(1)) - .WillOnce([](const GlobalConfigParam ¶m) { - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return GENERAL_ERROR; - }); - GlobalConfigParam param = {}; - param.type = PIN_EXPIRED_PERIOD; - param.value.pinExpiredPeriod = 1; - EXPECT_EQ(proxy->SetGlobalConfigParam(param), GENERAL_ERROR); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxySetGlobalConfigParam003, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, SetGlobalConfigParam(_)) - .Times(Exactly(1)) - .WillOnce([](const GlobalConfigParam ¶m) { - return GENERAL_ERROR; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - GlobalConfigParam param = {}; - param.type = ENABLE_STATUS; - param.value.enableStatus = true; - EXPECT_EQ(proxy->SetGlobalConfigParam(param), GENERAL_ERROR); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetPropertyById001, TestSize.Level0) -{ - static const uint64_t testCredentialId = 1; - std::vector testKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getPropCallback = Common::MakeShared(); - EXPECT_NE(getPropCallback, nullptr); - sptr testCallback( - new (std::nothrow) GetExecutorPropertyCallbackService(getPropCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, GetPropertyById(_, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](uint64_t credentialId, - const std::vector &keys, sptr &callback) { - EXPECT_EQ(credentialId, testCredentialId); - EXPECT_THAT(keys, ElementsAre(Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE)); - EXPECT_EQ(callback, testCallback); - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->GetPropertyById(testCredentialId, testKeys, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetPropertyById002, TestSize.Level0) -{ - static const uint64_t testCredentialId = 1; - std::vector testKeys = {}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - proxy->GetPropertyById(testCredentialId, testKeys, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetPropertyById003, TestSize.Level0) -{ - static const uint64_t testCredentialId = 1; - std::vector testKeys = {}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getPropCallback = Common::MakeShared(); - EXPECT_NE(getPropCallback, nullptr); - sptr testCallback( - new (std::nothrow) GetExecutorPropertyCallbackService(getPropCallback)); - proxy->GetPropertyById(testCredentialId, testKeys, testCallback); -} - - -HWTEST_F(UserAuthProxyTest, UserAuthProxyGetPropertyById004, TestSize.Level0) -{ - static const uint64_t testCredentialId = 1; - std::vector testKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE}; - testKeys.resize(513); - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getPropCallback = Common::MakeShared(); - EXPECT_NE(getPropCallback, nullptr); - sptr testCallback( - new (std::nothrow) GetExecutorPropertyCallbackService(getPropCallback)); - proxy->GetPropertyById(testCredentialId, testKeys, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyPrepareRemoteAuth001, TestSize.Level0) -{ - const std::string networkId = "123456"; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto authCallback = Common::MakeShared(); - EXPECT_NE(authCallback, nullptr); - sptr testCallback(new (std::nothrow) UserAuthCallbackService(authCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, PrepareRemoteAuth(_, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](const std::string &networkId, sptr &callback) { - EXPECT_EQ(callback, testCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->PrepareRemoteAuth(networkId, testCallback), SUCCESS); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyPrepareRemoteAuth002, TestSize.Level0) -{ - const std::string networkId = "123456"; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - sptr testCallback(nullptr); - EXPECT_EQ(proxy->PrepareRemoteAuth(networkId, testCallback), GENERAL_ERROR); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyPrepareRemoteAuth003, TestSize.Level0) -{ - const std::string networkId = "123456"; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto authCallback = Common::MakeShared(); - EXPECT_NE(authCallback, nullptr); - sptr testCallback(new (std::nothrow) UserAuthCallbackService(authCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, PrepareRemoteAuth(_, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](const std::string &networkId, sptr &callback) { - EXPECT_EQ(callback, testCallback); - return 0; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return GENERAL_ERROR; - }); - EXPECT_EQ(proxy->PrepareRemoteAuth(networkId, testCallback), GENERAL_ERROR); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyVerifyAuthToken001, TestSize.Level0) -{ - std::vector testTokenIn = {}; - uint64_t testAllowableDuration = 0; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - auto callback = Common::MakeShared(); - EXPECT_NE(callback, nullptr); - sptr testCallback = - new (std::nothrow) VerifyTokenCallbackService(callback); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, VerifyAuthToken(_, _, _)).Times(Exactly(1)); - ON_CALL(*service, VerifyAuthToken) - .WillByDefault( - [&testTokenIn, &testAllowableDuration, &testCallback] - (const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback) { - EXPECT_EQ(testTokenIn, tokenIn); - EXPECT_EQ(testAllowableDuration, allowableDuration); - } - ); - - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->VerifyAuthToken(testTokenIn, testAllowableDuration, testCallback); -} - -HWTEST_F(UserAuthProxyTest, UserAuthProxyVerifyAuthToken002, TestSize.Level0) -{ - std::vector testTokenIn = {}; - uint64_t testAllowableDuration = 0; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - sptr testCallback = new (std::nothrow) VerifyTokenCallbackService(nullptr); - proxy->VerifyAuthToken(testTokenIn, testAllowableDuration, testCallback); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/inner_api/src/user_idm_callback_proxy_test.cpp b/test/unittest/inner_api/src/user_idm_callback_proxy_test.cpp deleted file mode 100644 index 16bb388bbb344542684f89ef80da3cb34c242561..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/user_idm_callback_proxy_test.cpp +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_callback_proxy_test.h" - -#include "iam_ptr.h" -#include "mock_remote_object.h" -#include "mock_user_idm_callback_service.h" -#include "user_idm_callback_proxy.h" -#include "widget_callback_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserIdmCallbackProxyTest::SetUpTestCase() -{ -} - -void UserIdmCallbackProxyTest::TearDownTestCase() -{ -} - -void UserIdmCallbackProxyTest::SetUp() -{ -} - -void UserIdmCallbackProxyTest::TearDown() -{ -} - -HWTEST_F(UserIdmCallbackProxyTest, TestOnResult_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, IdmCallbackInterfaceCode::IDM_CALLBACK_ON_RESULT); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - int32_t result = 0; - Attributes extraInfo; - proxy->OnResult(result, extraInfo); -} - -HWTEST_F(UserIdmCallbackProxyTest, TestOnAcquireInfo_001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, IdmCallbackInterfaceCode::IDM_CALLBACK_ON_ACQUIRE_INFO); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - int32_t module = 10; - int32_t acquireInfo = 20; - Attributes extraInfo; - proxy->OnAcquireInfo(module, acquireInfo, extraInfo); -} - -HWTEST_F(UserIdmCallbackProxyTest, TestOnCredentialInfos_001, TestSize.Level0) -{ - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnCredentialInfos(_, _)) - .WillOnce( - [](int32_t result, const std::vector &credInfoList) { - EXPECT_EQ(credInfoList.size(), 3); - EXPECT_EQ(credInfoList[0].authType, PIN); - EXPECT_EQ(credInfoList[1].authType, FACE); - EXPECT_EQ(credInfoList[2].authType, FINGERPRINT); - EXPECT_EQ(credInfoList[0].credentialId, 10); - EXPECT_EQ(credInfoList[1].credentialId, 100); - EXPECT_EQ(credInfoList[2].credentialId, 1000); - } - ); - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - CredentialInfo info1 = {PIN, PIN_SIX, 10, 20}; - CredentialInfo info2 = {FACE, std::nullopt, 100, 200}; - CredentialInfo info3 = {FINGERPRINT, std::nullopt, 1000, 2000}; - std::vector credInfoList = {info1, info2, info3}; - proxy->OnCredentialInfos(SUCCESS, credInfoList); -} - -HWTEST_F(UserIdmCallbackProxyTest, TestOnSecureUserInfo_001, TestSize.Level0) -{ - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnSecureUserInfo(_, _)) - .WillOnce( - [](int32_t result, const SecUserInfo &secUserInfo) { - EXPECT_EQ(secUserInfo.secureUid, 1000); - EXPECT_EQ(secUserInfo.enrolledInfo.size(), 2); - EXPECT_EQ(secUserInfo.enrolledInfo[0].authType, FACE); - EXPECT_EQ(secUserInfo.enrolledInfo[0].enrolledId, 10); - EXPECT_EQ(secUserInfo.enrolledInfo[1].authType, FINGERPRINT); - EXPECT_EQ(secUserInfo.enrolledInfo[1].enrolledId, 20); - } - ); - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return OHOS::NO_ERROR; - } - ); - - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - - SecUserInfo secUserInfo = {}; - secUserInfo.secureUid = 1000; - secUserInfo.enrolledInfo = {{FACE, 10}, {FINGERPRINT, 20}}; - proxy->OnSecureUserInfo(SUCCESS, secUserInfo); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/user_idm_callback_service_test.cpp b/test/unittest/inner_api/src/user_idm_callback_service_test.cpp index 670b6ac4592f8583b2dd6ce58fb4c32d44803144..69b873d1ad880be27919f9346e150b48fce2a8e4 100644 --- a/test/unittest/inner_api/src/user_idm_callback_service_test.cpp +++ b/test/unittest/inner_api/src/user_idm_callback_service_test.cpp @@ -52,8 +52,8 @@ HWTEST_F(UserIdmCallbackServiceTest, UserIdmCallbackServiceTest001, TestSize.Lev std::shared_ptr idmClientCallback = nullptr; auto service = Common::MakeShared(idmClientCallback); EXPECT_NE(service, nullptr); - service->OnResult(testResult, testExtraInfo); - service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo); + service->OnResult(testResult, testExtraInfo.Serialize()); + service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo.Serialize()); } HWTEST_F(UserIdmCallbackServiceTest, UserIdmCallbackServiceTest002, TestSize.Level0) @@ -83,13 +83,13 @@ HWTEST_F(UserIdmCallbackServiceTest, UserIdmCallbackServiceTest002, TestSize.Lev ); auto service = Common::MakeShared(idmClientCallback); EXPECT_NE(service, nullptr); - service->OnResult(testResult, testExtraInfo); - service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo); + service->OnResult(testResult, testExtraInfo.Serialize()); + service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo.Serialize()); } HWTEST_F(UserIdmCallbackServiceTest, IdmGetCredInfoCallbackServiceTest001, TestSize.Level0) { - std::vector credInfoList; + std::vector credInfoList; std::shared_ptr getCredInfoCallback = nullptr; auto service = Common::MakeShared(getCredInfoCallback); @@ -99,10 +99,10 @@ HWTEST_F(UserIdmCallbackServiceTest, IdmGetCredInfoCallbackServiceTest001, TestS HWTEST_F(UserIdmCallbackServiceTest, IdmGetCredInfoCallbackServiceTest002, TestSize.Level0) { - CredentialInfo info1 = {PIN, PIN_SIX, 10, 20}; - CredentialInfo info2 = {FACE, std::nullopt, 100, 200}; - CredentialInfo info3 = {FINGERPRINT, std::nullopt, 1000, 2000}; - std::vector credInfoList = {info1, info2, info3}; + IpcCredentialInfo info1 = {PIN, PIN_SIX, 10, 20}; + IpcCredentialInfo info2 = {FACE, 0, 100, 200}; + IpcCredentialInfo info3 = {FINGERPRINT, 0, 1000, 2000}; + std::vector credInfoList = {info1, info2, info3}; auto getCredInfoCallback = Common::MakeShared(); EXPECT_NE(getCredInfoCallback, nullptr); @@ -123,7 +123,7 @@ HWTEST_F(UserIdmCallbackServiceTest, IdmGetCredInfoCallbackServiceTest002, TestS HWTEST_F(UserIdmCallbackServiceTest, IdmGetSecureUserInfoCallbackServiceTest001, TestSize.Level0) { - SecUserInfo secUserInfo = {}; + IpcSecUserInfo secUserInfo = {}; std::shared_ptr getSecInfoCallback = nullptr; auto service = Common::MakeShared(getSecInfoCallback); EXPECT_NE(service, nullptr); @@ -149,7 +149,7 @@ HWTEST_F(UserIdmCallbackServiceTest, IdmGetSecureUserInfoCallbackServiceTest002, auto service = Common::MakeShared(getSecInfoCallback); EXPECT_NE(service, nullptr); - SecUserInfo secUserInfo = {}; + IpcSecUserInfo secUserInfo = {}; secUserInfo.secureUid = 1000; secUserInfo.enrolledInfo = {{FACE, 10}, {FINGERPRINT, 20}}; service->OnSecureUserInfo(SUCCESS, secUserInfo); diff --git a/test/unittest/inner_api/src/user_idm_callback_stub_test.cpp b/test/unittest/inner_api/src/user_idm_callback_stub_test.cpp deleted file mode 100644 index a03d5c35eb5cb9474c99182563b22da6d3433c79..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/user_idm_callback_stub_test.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_callback_stub_test.h" - -#include "message_parcel.h" - -#include "iam_ptr.h" -#include "mock_user_idm_callback_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserIdmCallbackStubTest::SetUpTestCase() -{ -} - -void UserIdmCallbackStubTest::TearDownTestCase() -{ -} - -void UserIdmCallbackStubTest::SetUp() -{ -} - -void UserIdmCallbackStubTest::TearDown() -{ -} - -HWTEST_F(UserIdmCallbackStubTest, TestOnResultStub_001, TestSize.Level0) -{ - int32_t result = 0; - std::vector extraInfo = {1, 2, 3, 4}; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = IdmCallbackInterfaceCode::IDM_CALLBACK_ON_RESULT; - - EXPECT_TRUE(data.WriteInterfaceToken(IdmCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - EXPECT_TRUE(data.WriteUInt8Vector(extraInfo)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnResult(_, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserIdmCallbackStubTest, TestOnAcquireInfoStub_001, TestSize.Level0) -{ - int32_t module = 10; - int32_t acquireInfo = 20; - std::vector extraInfo = {1, 2, 3, 4}; - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = IdmCallbackInterfaceCode::IDM_CALLBACK_ON_ACQUIRE_INFO; - - EXPECT_TRUE(data.WriteInterfaceToken(IdmCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(module)); - EXPECT_TRUE(data.WriteInt32(acquireInfo)); - EXPECT_TRUE(data.WriteUInt8Vector(extraInfo)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnAcquireInfo(_, _, _)).Times(1); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserIdmCallbackStubTest, TestOnCredentialInfosStub_001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = IdmGetCredInfoCallbackInterfaceCode::ON_GET_INFO; - int32_t result = 0; - - EXPECT_TRUE(data.WriteInterfaceToken(IdmGetCredInfoCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnCredentialInfos(_, _)) - .WillOnce( - [](int32_t result, const std::vector &credInfoList) { - EXPECT_EQ(credInfoList.size(), 0); - } - ); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserIdmCallbackStubTest, TestOnCredentialInfosStub_002, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = IdmGetCredInfoCallbackInterfaceCode::ON_GET_INFO; - int32_t result = 0; - - EXPECT_TRUE(data.WriteInterfaceToken(IdmGetCredInfoCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - EXPECT_TRUE(data.WriteUint32(1000)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnCredentialInfos(_, _)) - .WillOnce( - [](int32_t result, const std::vector &credInfoList) { - EXPECT_EQ(credInfoList.size(), 0); - } - ); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserIdmCallbackStubTest, TestOnSecureUserInfoStub_001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = IdmGetSecureUserInfoCallbackInterfaceCode::ON_GET_SEC_INFO; - int32_t result = 0; - - EXPECT_TRUE(data.WriteInterfaceToken(IdmGetSecureUserInfoCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnSecureUserInfo(_, _)) - .WillOnce( - [](int32_t result, const SecUserInfo &secUserInfo) { - EXPECT_EQ(secUserInfo.secureUid, 0); - EXPECT_EQ(secUserInfo.enrolledInfo.size(), 0); - } - ); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(UserIdmCallbackStubTest, TestOnSecureUserInfoStub_002, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = IdmGetSecureUserInfoCallbackInterfaceCode::ON_GET_SEC_INFO; - int32_t result = 0; - - EXPECT_TRUE(data.WriteInterfaceToken(IdmGetSecureUserInfoCallbackInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(result)); - EXPECT_TRUE(data.WriteUint64(20)); - EXPECT_TRUE(data.WriteUint32(1000)); - - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OnSecureUserInfo(_, _)) - .WillOnce( - [](int32_t result, const SecUserInfo &secUserInfo) { - EXPECT_EQ(secUserInfo.secureUid, 0); - EXPECT_EQ(secUserInfo.enrolledInfo.size(), 0); - } - ); - - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS diff --git a/test/unittest/inner_api/src/user_idm_client_test.cpp b/test/unittest/inner_api/src/user_idm_client_test.cpp index 248aa69c5168f1b3e196df795703310393f21f2c..c2c55d4f93bfadfe8c9b011325bd3e8ed926d892 100644 --- a/test/unittest/inner_api/src/user_idm_client_test.cpp +++ b/test/unittest/inner_api/src/user_idm_client_test.cpp @@ -96,7 +96,7 @@ HWTEST_F(UserIdmClientTest, UserIdmClientCloseSession002, TestSize.Level0) .WillByDefault( [&testUserId](int32_t userId) { EXPECT_EQ(userId, testUserId); - return; + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -170,16 +170,17 @@ HWTEST_F(UserIdmClientTest, UserIdmClientAddCredential002, TestSize.Level0) EXPECT_CALL(*service, AddCredential(_, _, _, _)).Times(1); ON_CALL(*service, AddCredential) .WillByDefault( - [&testUserId, &testPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara, - const sptr &callback, bool isUpdate) { + [&testUserId, &testPara](int32_t userId, const IpcCredentialPara &credPara, + const sptr &callback, bool isUpdate) { EXPECT_EQ(userId, testUserId); EXPECT_EQ(credPara.authType, testPara.authType); EXPECT_THAT(credPara.token, ElementsAreArray(testPara.token)); EXPECT_EQ(isUpdate, false); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -222,8 +223,8 @@ HWTEST_F(UserIdmClientTest, UserIdmClientUpdateCredential002, TestSize.Level0) EXPECT_CALL(*service, UpdateCredential(_, _, _)).Times(1); ON_CALL(*service, UpdateCredential) .WillByDefault( - [&testUserId, &testPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara, - const sptr &callback) { + [&testUserId, &testPara](int32_t userId, const IpcCredentialPara &credPara, + const sptr &callback) { EXPECT_EQ(userId, testUserId); EXPECT_EQ(credPara.authType, testPara.authType); EXPECT_TRUE(testPara.pinType.has_value()); @@ -231,8 +232,9 @@ HWTEST_F(UserIdmClientTest, UserIdmClientUpdateCredential002, TestSize.Level0) EXPECT_THAT(credPara.token, ElementsAreArray(testPara.token)); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -309,14 +311,15 @@ HWTEST_F(UserIdmClientTest, UserIdmClientDeleteCredential002, TestSize.Level0) ON_CALL(*service, DelCredential) .WillByDefault( [&testUserId, &testCredentialId, &testAuthToken](int32_t userId, uint64_t credentialId, - const std::vector &authToken, const sptr &callback) { + const std::vector &authToken, const sptr &callback) { EXPECT_EQ(userId, testUserId); EXPECT_EQ(credentialId, testCredentialId); EXPECT_THAT(authToken, ElementsAreArray(testAuthToken)); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -357,13 +360,14 @@ HWTEST_F(UserIdmClientTest, UserIdmClientDeleteUser002, TestSize.Level0) ON_CALL(*service, DelUser) .WillByDefault( [&testUserId, &testAuthToken](int32_t userId, const std::vector authToken, - const sptr &callback) { + const sptr &callback) { EXPECT_EQ(userId, testUserId); EXPECT_THAT(authToken, ElementsAreArray(testAuthToken)); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } + return SUCCESS; } ); sptr obj(new (std::nothrow) MockRemoteObject()); @@ -403,11 +407,11 @@ HWTEST_F(UserIdmClientTest, UserIdmClientEraseUser002, TestSize.Level0) EXPECT_CALL(*service, EnforceDelUser(_, _)).Times(1); ON_CALL(*service, EnforceDelUser) .WillByDefault( - [&testUserId](int32_t userId, const sptr &callback) { + [&testUserId](int32_t userId, const sptr &callback) { EXPECT_EQ(userId, testUserId); if (callback != nullptr) { Attributes extraInfo; - callback->OnResult(SUCCESS, extraInfo); + callback->OnResult(SUCCESS, extraInfo.Serialize()); } return SUCCESS; } @@ -452,12 +456,12 @@ HWTEST_F(UserIdmClientTest, UserIdmClientGetCredentialInfo002, TestSize.Level0) EXPECT_CALL(*service, GetCredentialInfo(_, _, _)).Times(1); ON_CALL(*service, GetCredentialInfo) .WillByDefault( - [&testUserId, &testAuthType](int32_t userId, AuthType authType, - const sptr &callback) { + [&testUserId, &testAuthType](int32_t userId, int32_t authType, + const sptr &callback) { EXPECT_EQ(userId, testUserId); - EXPECT_EQ(authType, testAuthType); + EXPECT_EQ(authType, static_cast(testAuthType)); if (callback != nullptr) { - std::vector credInfoList; + std::vector credInfoList; callback->OnCredentialInfos(SUCCESS, credInfoList); } return SUCCESS; @@ -500,7 +504,7 @@ HWTEST_F(UserIdmClientTest, UserIdmClientGetSecUserInfo002, TestSize.Level0) EXPECT_CALL(*service, GetSecInfo(_, _)).Times(1); ON_CALL(*service, GetSecInfo) .WillByDefault( - [&testUserId](int32_t userId, const sptr &callback) { + [&testUserId](int32_t userId, const sptr &callback) { EXPECT_EQ(userId, testUserId); EXPECT_NE(callback, nullptr); return SUCCESS; @@ -525,6 +529,97 @@ HWTEST_F(UserIdmClientTest, UserIdmClientImplClearRedundancyCredential, TestSize EXPECT_NO_THROW(UserIdmClient::GetInstance().ClearRedundancyCredential(testCallback)); } +HWTEST_F(UserIdmClientTest, UserIdmClientRegistCredChangeEventListener001, TestSize.Level0) +{ + std::vector authTypeList; + authTypeList.push_back(AuthType::PIN); + authTypeList.push_back(AuthType::FACE); + authTypeList.push_back(AuthType::FINGERPRINT); + + auto testCallback = Common::MakeShared(); + EXPECT_NE(testCallback, nullptr); + + auto service = Common::MakeShared(); + EXPECT_NE(service, nullptr); + EXPECT_CALL(*service, RegistCredChangeEventListener(_)).Times(1); + ON_CALL(*service, RegistCredChangeEventListener) + .WillByDefault( + [](const sptr &callback) { + return SUCCESS; + } + ); + sptr obj(new (std::nothrow) MockRemoteObject()); + sptr dr(nullptr); + CallRemoteObject(service, obj, dr); + int32_t ret = UserIdmClient::GetInstance().RegistCredChangeEventListener(authTypeList, testCallback); + EXPECT_EQ(ret, SUCCESS); + dr->OnRemoteDied(obj); + IpcClientUtils::ResetObj(); +} + +HWTEST_F(UserIdmClientTest, UserIdmClientRegistCredChangeEventListener002, TestSize.Level0) +{ + std::vector authTypeList; + authTypeList.push_back(AuthType::PIN); + authTypeList.push_back(AuthType::FACE); + authTypeList.push_back(AuthType::FINGERPRINT); + + int32_t ret = UserIdmClient::GetInstance().RegistCredChangeEventListener(authTypeList, nullptr); + EXPECT_EQ(ret, GENERAL_ERROR); +} + +HWTEST_F(UserIdmClientTest, UserIdmClientRegistCredChangeEventListener003, TestSize.Level0) +{ + std::vector authTypeList; + authTypeList.push_back(AuthType::PIN); + authTypeList.push_back(AuthType::FACE); + authTypeList.push_back(AuthType::FINGERPRINT); + + auto testCallback = Common::MakeShared(); + EXPECT_NE(testCallback, nullptr); + + int32_t ret = UserIdmClient::GetInstance().RegistCredChangeEventListener(authTypeList, testCallback); + EXPECT_EQ(ret, GENERAL_ERROR); +} + +HWTEST_F(UserIdmClientTest, UserIdmClientUnRegistCredChangeEventListener001, TestSize.Level0) +{ + auto testCallback = Common::MakeShared(); + EXPECT_NE(testCallback, nullptr); + + auto service = Common::MakeShared(); + EXPECT_NE(service, nullptr); + EXPECT_CALL(*service, UnRegistCredChangeEventListener(_)).Times(1); + ON_CALL(*service, UnRegistCredChangeEventListener) + .WillByDefault( + [](const sptr &callback) { + return SUCCESS; + } + ); + sptr obj(new (std::nothrow) MockRemoteObject()); + sptr dr(nullptr); + CallRemoteObject(service, obj, dr); + int32_t ret = UserIdmClient::GetInstance().UnRegistCredChangeEventListener(testCallback); + EXPECT_EQ(ret, SUCCESS); + dr->OnRemoteDied(obj); + IpcClientUtils::ResetObj(); +} + +HWTEST_F(UserIdmClientTest, UserIdmClientUnRegistCredChangeEventListener002, TestSize.Level0) +{ + int32_t ret = UserIdmClient::GetInstance().UnRegistCredChangeEventListener(nullptr); + EXPECT_EQ(ret, GENERAL_ERROR); +} + +HWTEST_F(UserIdmClientTest, UserIdmClientUnRegistCredChangeEventListener003, TestSize.Level0) +{ + auto testCallback = Common::MakeShared(); + EXPECT_NE(testCallback, nullptr); + + int32_t ret = UserIdmClient::GetInstance().UnRegistCredChangeEventListener(testCallback); + EXPECT_EQ(ret, GENERAL_ERROR); +} + void UserIdmClientTest::CallRemoteObject(const std::shared_ptr service, const sptr &obj, sptr &dr) { @@ -545,6 +640,48 @@ void UserIdmClientTest::CallRemoteObject(const std::shared_ptr credentialInfoList; + int32_t ret = UserIdmClient::GetInstance().GetCredentialInfoSync(testUserId, testAuthType, credentialInfoList); + EXPECT_EQ(ret, GENERAL_ERROR); + + IpcClientUtils::ResetObj(); + ret = UserIdmClient::GetInstance().GetCredentialInfoSync(testUserId, testAuthType, credentialInfoList); + EXPECT_EQ(ret, GENERAL_ERROR); +} + +HWTEST_F(UserIdmClientTest, UserIdmClientGetCredentialInfoSync002, TestSize.Level0) +{ + int32_t testUserId = 200; + AuthType testAuthType = PIN; + std::vector credentialInfoList; + + auto service = Common::MakeShared(); + EXPECT_NE(service, nullptr); + EXPECT_CALL(*service, GetCredentialInfoSync(_, _, _)).Times(1); + ON_CALL(*service, GetCredentialInfoSync) + .WillByDefault( + [&testUserId, &testAuthType](int32_t userId, int32_t authType, + std::vector &credentialInfoList) { + EXPECT_EQ(userId, testUserId); + EXPECT_EQ(authType, testAuthType); + return SUCCESS; + } + ); + sptr obj(new (std::nothrow) MockRemoteObject()); + sptr dr(nullptr); + CallRemoteObject(service, obj, dr); + + int32_t ret = UserIdmClient::GetInstance().GetCredentialInfoSync(testUserId, testAuthType, credentialInfoList); + EXPECT_EQ(ret, SUCCESS); + EXPECT_NE(dr, nullptr); + dr->OnRemoteDied(obj); + IpcClientUtils::ResetObj(); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/inner_api/src/user_idm_proxy_test.cpp b/test/unittest/inner_api/src/user_idm_proxy_test.cpp deleted file mode 100644 index 3d550311be32dbf822e570439c87ef31f9b46748..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/user_idm_proxy_test.cpp +++ /dev/null @@ -1,478 +0,0 @@ -/* - * Copyright (C) 2022 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_proxy_test.h" - -#include "iam_ptr.h" -#include "user_idm_proxy.h" -#include "mock_remote_object.h" -#include "mock_user_idm_service.h" -#include "mock_user_idm_client_callback.h" -#include "user_idm_callback_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserIdmProxyTest::SetUpTestCase() -{ -} - -void UserIdmProxyTest::TearDownTestCase() -{ -} - -void UserIdmProxyTest::SetUp() -{ -} - -void UserIdmProxyTest::TearDown() -{ -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyOpenSession, TestSize.Level0) -{ - static const int32_t testUserId = 200; - std::vector testChallenge; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, OpenSession(_, _)) - .Times(Exactly(1)) - .WillOnce([](int32_t userId, std::vector &challenge) { - EXPECT_EQ(testUserId, userId); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->OpenSession(testUserId, testChallenge); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyCloseSession, TestSize.Level0) -{ - static const int32_t testUserId = 200; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, CloseSession(_)) - .Times(Exactly(1)) - .WillOnce([](int32_t userId) { - EXPECT_EQ(testUserId, userId); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->CloseSession(testUserId); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyGetCredentialInfo001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const AuthType testAuthType = PIN; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getCredInfoCallback = Common::MakeShared(); - EXPECT_NE(getCredInfoCallback, nullptr); - sptr testCallback( - new (std::nothrow) IdmGetCredInfoCallbackService(getCredInfoCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, GetCredentialInfo(_, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t userId, AuthType authType, - const sptr &callback) { - EXPECT_EQ(testUserId, userId); - EXPECT_EQ(testAuthType, authType); - EXPECT_EQ(testCallback, callback); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->GetCredentialInfo(testUserId, testAuthType, testCallback), SUCCESS); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyGetCredentialInfo002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const AuthType testAuthType = PIN; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - EXPECT_EQ(proxy->GetCredentialInfo(testUserId, testAuthType, nullptr), GENERAL_ERROR); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyGetSecInfo001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto getSecInfoCallback = Common::MakeShared(); - EXPECT_NE(getSecInfoCallback, nullptr); - sptr testCallback( - new (std::nothrow) IdmGetSecureUserInfoCallbackService(getSecInfoCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, GetSecInfo(_, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t userId, const sptr &callback) { - EXPECT_EQ(testUserId, userId); - EXPECT_EQ(testCallback, callback); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->GetSecInfo(testUserId, testCallback), SUCCESS); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyGetSecInfo002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - EXPECT_EQ(proxy->GetSecInfo(testUserId, nullptr), GENERAL_ERROR); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyAddCredential001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - UserIdmInterface::CredentialPara testCredPara = {}; - testCredPara.authType = FACE; - testCredPara.pinType = PIN_SIX; - testCredPara.token = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto idmCallback = Common::MakeShared(); - EXPECT_NE(idmCallback, nullptr); - sptr testCallback(new (std::nothrow) IdmCallbackService(idmCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, AddCredential(_, _, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara, - const sptr &callback, bool isUpdate) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(credPara.authType, testCredPara.authType); - EXPECT_EQ(credPara.pinType, testCredPara.pinType); - EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token)); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->AddCredential(testUserId, testCredPara, testCallback, false); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyAddCredential002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - UserIdmInterface::CredentialPara testCredPara = {}; - testCredPara.authType = FACE; - testCredPara.pinType = PIN_SIX; - testCredPara.token = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - proxy->AddCredential(testUserId, testCredPara, nullptr, false); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyUpdateCredential001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - UserIdmInterface::CredentialPara testCredPara = {}; - testCredPara.authType = FACE; - testCredPara.pinType = PIN_SIX; - testCredPara.token = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto idmCallback = Common::MakeShared(); - EXPECT_NE(idmCallback, nullptr); - sptr testCallback(new (std::nothrow) IdmCallbackService(idmCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, UpdateCredential(_, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara, - const sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(credPara.authType, testCredPara.authType); - EXPECT_EQ(credPara.pinType, testCredPara.pinType); - EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token)); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->UpdateCredential(testUserId, testCredPara, testCallback); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyUpdateCredential002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - UserIdmInterface::CredentialPara testCredPara = {}; - testCredPara.authType = FACE; - testCredPara.pinType = PIN_SIX; - testCredPara.token = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - proxy->UpdateCredential(testUserId, testCredPara, nullptr); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyCancel, TestSize.Level0) -{ - static const int32_t testUserId = 200; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, Cancel(_)) - .Times(Exactly(1)) - .WillOnce([](int32_t userId) { - EXPECT_EQ(testUserId, userId); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->Cancel(testUserId); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyEnforceDelUser001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto idmCallback = Common::MakeShared(); - EXPECT_NE(idmCallback, nullptr); - sptr testCallback(new (std::nothrow) IdmCallbackService(idmCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, EnforceDelUser(_, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t userId, const sptr &callback) { - EXPECT_EQ(testUserId, userId); - EXPECT_EQ(testCallback, callback); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - EXPECT_EQ(proxy->EnforceDelUser(testUserId, testCallback), SUCCESS); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyEnforceDelUser002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - EXPECT_EQ(proxy->EnforceDelUser(testUserId, nullptr), GENERAL_ERROR); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyDelUser001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const std::vector testAuthToken = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto idmCallback = Common::MakeShared(); - EXPECT_NE(idmCallback, nullptr); - sptr testCallback(new (std::nothrow) IdmCallbackService(idmCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, DelUser(_, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t userId, const std::vector authToken, - const sptr &callback) { - EXPECT_EQ(testUserId, userId); - EXPECT_THAT(testAuthToken, ElementsAre(1, 2, 3, 4)); - EXPECT_EQ(testCallback, callback); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->DelUser(testUserId, testAuthToken, testCallback); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyDelUser002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const std::vector testAuthToken = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - proxy->DelUser(testUserId, testAuthToken, nullptr); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyDelCredential001, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const uint64_t testCredentialId = 300; - static const std::vector testAuthToken = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto idmCallback = Common::MakeShared(); - EXPECT_NE(idmCallback, nullptr); - sptr testCallback(new (std::nothrow) IdmCallbackService(idmCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, DelCredential(_, _, _, _)) - .Times(Exactly(1)) - .WillOnce([&testCallback](int32_t userId, uint64_t credentialId, const std::vector &authToken, - const sptr &callback) { - EXPECT_EQ(testUserId, userId); - EXPECT_EQ(testCredentialId, credentialId); - EXPECT_THAT(testAuthToken, ElementsAre(1, 2, 3, 4)); - EXPECT_EQ(testCallback, callback); - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->DelCredential(testUserId, testCredentialId, testAuthToken, testCallback); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyDelCredential002, TestSize.Level0) -{ - static const int32_t testUserId = 200; - static const uint64_t testCredentialId = 300; - static const std::vector testAuthToken = {1, 2, 3, 4}; - - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - proxy->DelCredential(testUserId, testCredentialId, testAuthToken, nullptr); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyClearRedundancyCredential001, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto idmCallback = Common::MakeShared(); - EXPECT_NE(idmCallback, nullptr); - sptr testCallback(new (std::nothrow) IdmCallbackService(idmCallback)); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, ClearRedundancyCredential(_)) - .Times(Exactly(1)) - .WillOnce([&testCallback](const sptr &callback) { - return SUCCESS; - }); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1); - ON_CALL(*obj, SendRequest) - .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - service->OnRemoteRequest(code, data, reply, option); - return SUCCESS; - }); - proxy->ClearRedundancyCredential(testCallback); -} - -HWTEST_F(UserIdmProxyTest, UserIdmProxyClearRedundancyCredential002, TestSize.Level0) -{ - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); - auto idmCallback = Common::MakeShared(); - proxy->ClearRedundancyCredential(nullptr); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/inner_api/src/widget_callback_stub_test.cpp b/test/unittest/inner_api/src/widget_callback_stub_test.cpp deleted file mode 100644 index ac131deaa094aae979be3b0fa48278f5b42ee38e..0000000000000000000000000000000000000000 --- a/test/unittest/inner_api/src/widget_callback_stub_test.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "widget_callback_stub_test.h" - -#include "iam_ptr.h" -#include "mock_widget_callback_service_test.h" -#include "user_auth_interface_ipc_interface_code.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void WidgetCallbackStubTest::SetUpTestCase() -{ -} - -void WidgetCallbackStubTest::TearDownTestCase() -{ -} - -void WidgetCallbackStubTest::SetUp() -{ -} - -void WidgetCallbackStubTest::TearDown() -{ -} - -HWTEST_F(WidgetCallbackStubTest, WidgetCallbackStubOnRemoteRequest001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND; - EXPECT_TRUE(data.WriteInterfaceToken(WidgetCallbackInterface::GetDescriptor())); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_CALL(*service, SendCommand(_)).Times(1); - EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} - -HWTEST_F(WidgetCallbackStubTest, WidgetCallbackStubOnRemoteRequest002, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = 0; - EXPECT_TRUE(data.WriteInterfaceToken(WidgetCallbackInterface::GetDescriptor())); - auto service = Common::MakeShared(); - EXPECT_NE(service, nullptr); - EXPECT_NE(service->OnRemoteRequest(code, data, reply, option), SUCCESS); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/services/BUILD.gn b/test/unittest/services/BUILD.gn index 320b6a8d3434dccbc798f9fcaa8e0bdeb29ffbed..74f88527dbe98883f0e733301b77404ee3798078 100644 --- a/test/unittest/services/BUILD.gn +++ b/test/unittest/services/BUILD.gn @@ -80,12 +80,12 @@ ohos_unittest("iam_services_test") { "../../../services/context/src/widget_context.cpp", "../../../services/context/src/widget_context_callback_impl.cpp", "../../../services/context/src/widget_json.cpp", - "../../../services/core/src/auth_event_listener_manager.cpp", "../../../services/core/src/authentication_impl.cpp", "../../../services/core/src/credential_info_impl.cpp", "../../../services/core/src/driver_state_manager.cpp", "../../../services/core/src/enrolled_info_impl.cpp", "../../../services/core/src/enrollment_impl.cpp", + "../../../services/core/src/event_listener_manager.cpp", "../../../services/core/src/identification_impl.cpp", "../../../services/core/src/publish_event_adapter_mock.cpp", "../../../services/core/src/remote_executor_proxy.cpp", @@ -127,25 +127,28 @@ ohos_unittest("iam_services_test") { "mocks/mock_ipc_common.cpp", "mocks/mock_iuser_auth_interface.cpp", "src/attributes_test.cpp", - "src/auth_event_listener_manager_test.cpp", "src/auth_widget_helper_test.cpp", "src/authentication_impl_test.cpp", "src/co_auth_service_test.cpp", - "src/co_auth_stub_test.cpp", "src/context_appstate_observer_test.cpp", "src/context_callback_impl_test.cpp", "src/context_factory_test.cpp", "src/context_pool_test.cpp", "src/credential_info_test.cpp", + "src/driver_state_manager_test.cpp", "src/enroll_context_test.cpp", "src/enrolled_info_test.cpp", "src/enrollment_impl_test.cpp", + "src/event_listener_manager_test.cpp", "src/executor_messenger_service_test.cpp", + "src/hisysevent_adapter_test.cpp", "src/identification_impl_test.cpp", "src/identify_context_test.cpp", "src/ipc_common_test.cpp", "src/keygurad_status_listener_test.cpp", "src/relative_timer_test.cpp", + "src/remote_auth_context_test.cpp", + "src/remote_auth_invoker_context_test.cpp", "src/resource_node_pool_test.cpp", "src/resource_node_test.cpp", "src/resource_node_utils_test.cpp", @@ -158,16 +161,18 @@ ohos_unittest("iam_services_test") { "src/soft_bus_manager_test.cpp", "src/soft_bus_server_socket_test.cpp", "src/state_machine_test.cpp", + "src/system_ability_listener_test.cpp", + "src/system_param_manager_test.cpp", "src/template_cache_manager_test.cpp", + "src/thread_handler_impl_test.cpp", + "src/thread_handler_manager_test.cpp", "src/ui_extension_ability_connection_test.cpp", "src/update_pin_param_test.cpp", "src/user_auth_service_test_part01.cpp", "src/user_auth_service_test_part02.cpp", - "src/user_auth_stub_test.cpp", "src/user_idm_database_test.cpp", "src/user_idm_service_test.cpp", "src/user_idm_session_controller_test.cpp", - "src/user_idm_stub_test.cpp", "src/user_info_test.cpp", "src/widget_client_test.cpp", "src/widget_context_callback_impl_test.cpp", @@ -204,6 +209,7 @@ ohos_unittest("iam_services_test") { "googletest:gmock", "hdf_core:libhdi", "hilog:libhilog", + "hisysevent:libhisysevent", "hitrace:hitrace_meter", "init:libbeget_proxy", "init:libbegetutil", diff --git a/test/unittest/services/inc/driver_state_manager_test.h b/test/unittest/services/inc/driver_state_manager_test.h new file mode 100644 index 0000000000000000000000000000000000000000..ba973830ecd0bd54cf3b0e2429349e4b1ddec280 --- /dev/null +++ b/test/unittest/services/inc/driver_state_manager_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef IAM_DRIVER_STATE_MANAGER_TEST_H +#define IAM_DRIVER_STATE_MANAGER_TEST_H + +#include +#include + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class DriverStateManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // IAM_DRIVER_STATE_MANAGER_TEST_H \ No newline at end of file diff --git a/test/unittest/services/inc/auth_event_listener_manager_test.h b/test/unittest/services/inc/event_listener_manager_test.h similarity index 83% rename from test/unittest/services/inc/auth_event_listener_manager_test.h rename to test/unittest/services/inc/event_listener_manager_test.h index fa89f26cf15842cd7be49de4d177ddd1cfc60a74..720b77c913b178986c4f388c34b8329fc0f95570 100644 --- a/test/unittest/services/inc/auth_event_listener_manager_test.h +++ b/test/unittest/services/inc/event_listener_manager_test.h @@ -12,15 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef AUTH_EVENT_LISTENER_MANAGER_TEST -#define AUTH_EVENT_LISTENER_MANAGER_TEST +#ifndef EVENT_LISTENER_MANAGER_TEST +#define EVENT_LISTENER_MANAGER_TEST #include namespace OHOS { namespace UserIam { namespace UserAuth { -class AuthEventListenerManagerTest : public testing::Test { +class EventListenerManagerTest : public testing::Test { public: static void SetUpTestCase(); @@ -34,4 +34,4 @@ public: } // namespace UserIam } // namespace OHOS -#endif // AUTH_EVENT_LISTENER_MANAGER_TEST \ No newline at end of file +#endif // EVENT_LISTENER_MANAGER_TEST \ No newline at end of file diff --git a/test/unittest/inner_api/inc/co_auth_proxy_test.h b/test/unittest/services/inc/hisysevent_adapter_test.h similarity index 81% rename from test/unittest/inner_api/inc/co_auth_proxy_test.h rename to test/unittest/services/inc/hisysevent_adapter_test.h index 1b835db99d585837f4cc0c5a362d3fa556d3be76..2a490a2de3fd114715575a728bcea03bc2ef9dbd 100644 --- a/test/unittest/inner_api/inc/co_auth_proxy_test.h +++ b/test/unittest/services/inc/hisysevent_adapter_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,16 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#ifndef CO_AUTH_PROXY_TEST_H -#define CO_AUTH_PROXY_TEST_H +#ifndef HISYSEVENT_ADAPTER_TEST +#define HISYSEVENT_ADAPTER_TEST #include namespace OHOS { namespace UserIam { namespace UserAuth { -class CoAuthProxyTest : public testing::Test { +class HiSysEventAdapterTest : public testing::Test { public: static void SetUpTestCase(); @@ -34,4 +33,5 @@ public: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // CO_AUTH_PROXY_TEST_H \ No newline at end of file + +#endif // HISYSEVENT_ADAPTER_TEST diff --git a/test/unittest/services/inc/remote_auth_context_test.h b/test/unittest/services/inc/remote_auth_context_test.h new file mode 100644 index 0000000000000000000000000000000000000000..846530915aa0459c7d58f2a4350b3bf390834c30 --- /dev/null +++ b/test/unittest/services/inc/remote_auth_context_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef IAM_REMOTE_AUTH_CONTEXT_TEST_H +#define IAM_REMOTE_AUTH_CONTEXT_TEST_H + +#include +#include + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteAuthContextTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // IAM_REMOTE_AUTH_CONTEXT_TEST_H \ No newline at end of file diff --git a/test/unittest/services/inc/remote_auth_invoker_context_test.h b/test/unittest/services/inc/remote_auth_invoker_context_test.h new file mode 100644 index 0000000000000000000000000000000000000000..6fa65d1b3040e497607910a78ee5cfa1072b0777 --- /dev/null +++ b/test/unittest/services/inc/remote_auth_invoker_context_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef IAM_REMOTE_AUTH_INVOKER_CONTEXT_TEST_H +#define IAM_REMOTE_AUTH_INVOKER_CONTEXT_TEST_H + +#include +#include + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class RemoteAuthInvokerContextTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // IAM_REMOTE_AUTH_INVOKER_CONTEXT_TEST_H \ No newline at end of file diff --git a/test/unittest/inner_api/inc/user_auth_proxy_test.h b/test/unittest/services/inc/system_ability_listener_test.h similarity index 79% rename from test/unittest/inner_api/inc/user_auth_proxy_test.h rename to test/unittest/services/inc/system_ability_listener_test.h index cf5fd69a30c15c97a1d649ffe3f179269c9be96e..0e0fd729aa02c052678fccb77d3d51cf3d7aa072 100644 --- a/test/unittest/inner_api/inc/user_auth_proxy_test.h +++ b/test/unittest/services/inc/system_ability_listener_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,16 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#ifndef USER_AUTH_PROXY_TEST_H -#define USER_AUTH_PROXY_TEST_H +#ifndef SYSTEM_ABILITY_LISTENER_TEST +#define SYSTEM_ABILITY_LISTENER_TEST #include namespace OHOS { namespace UserIam { namespace UserAuth { -class UserAuthProxyTest : public testing::Test { +class SystemAbilityListenerTest : public testing::Test { public: static void SetUpTestCase(); @@ -34,4 +33,5 @@ public: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // USER_AUTH_PROXY_TEST_H \ No newline at end of file + +#endif // SYSTEM_ABILITY_LISTENER_TEST diff --git a/test/unittest/services/inc/system_param_manager_test.h b/test/unittest/services/inc/system_param_manager_test.h new file mode 100644 index 0000000000000000000000000000000000000000..4116f544efa4b77a8153d97b188fb27f0c0d7144 --- /dev/null +++ b/test/unittest/services/inc/system_param_manager_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef IAM_SYSTEM_PARAM_MANAGER_TEST_H +#define IAM_SYSTEM_PARAM_MANAGER_TEST_H + +#include +#include + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class SystemParamManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // IAM_SYSTEM_PARAM_MANAGER_TEST_H \ No newline at end of file diff --git a/test/unittest/inner_api/inc/user_idm_proxy_test.h b/test/unittest/services/inc/thread_handler_impl_test.h similarity index 79% rename from test/unittest/inner_api/inc/user_idm_proxy_test.h rename to test/unittest/services/inc/thread_handler_impl_test.h index 75a9d9311d1d26680f57e1787ad84882d59c53a5..226b48cf3e813c2ed768486f80aaedfa26908c7b 100644 --- a/test/unittest/inner_api/inc/user_idm_proxy_test.h +++ b/test/unittest/services/inc/thread_handler_impl_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -12,16 +12,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#ifndef USER_IDM_PROXY_TEST_H -#define USER_IDM_PROXY_TEST_H +#ifndef IAM_THREAD_HANDLER_IMPL_TEST_H +#define IAM_THREAD_HANDLER_IMPL_TEST_H #include namespace OHOS { namespace UserIam { namespace UserAuth { -class UserIdmProxyTest : public testing::Test { +class ThreadHandlerImplTest : public testing::Test { public: static void SetUpTestCase(); @@ -34,4 +33,5 @@ public: } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // USER_IDM_PROXY_TEST_H \ No newline at end of file + +#endif // IAM_THREAD_HANDLER_IMPL_TEST_H \ No newline at end of file diff --git a/test/unittest/services/inc/thread_handler_manager_test.h b/test/unittest/services/inc/thread_handler_manager_test.h new file mode 100644 index 0000000000000000000000000000000000000000..659cacbe38f932ba8b5d8fa27f43be10b8e78f3e --- /dev/null +++ b/test/unittest/services/inc/thread_handler_manager_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef IAM_THREAD_HANDLER_MANAGER_TEST_H +#define IAM_THREAD_HANDLER_MANAGER_TEST_H + +#include +#include + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +class ThreadHandlerManagerTest : public testing::Test { +public: + static void SetUpTestCase(); + + static void TearDownTestCase(); + + void SetUp() override; + + void TearDown() override; +}; +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS +#endif // IAM_THREAD_HANDLER_MANAGER_TEST_H \ No newline at end of file diff --git a/test/unittest/services/mocks/mock_co_auth_service.h b/test/unittest/services/mocks/mock_co_auth_service.h index 695ca45a15670b850ddfcd776de6bb95b9c2b4f5..ced6880fcd057b97fb0d4eb5304e789a3e95aa5b 100644 --- a/test/unittest/services/mocks/mock_co_auth_service.h +++ b/test/unittest/services/mocks/mock_co_auth_service.h @@ -25,9 +25,11 @@ namespace UserIam { namespace UserAuth { class MockCoAuthService final : public CoAuthStub { public: - MOCK_METHOD2(ExecutorRegister, uint64_t(const ExecutorRegisterInfo &info, - sptr &callback)); - MOCK_METHOD1(ExecutorUnregister, void(uint64_t executorIndex)); + MOCK_METHOD3(ExecutorRegister, int32_t(const IpcExecutorRegisterInfo &ipcExecutorRegisterInfo, + const sptr &executorCallback, uint64_t &executorIndex)); + MOCK_METHOD1(ExecutorUnregister, int32_t(uint64_t executorIndex)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_context.h b/test/unittest/services/mocks/mock_context.h index 159ec5fd4a4bcfbac1f6c8680b2384dc28dbd361..d4bef94f26e07bb7b8eca226d3824fa551f0ee09 100644 --- a/test/unittest/services/mocks/mock_context.h +++ b/test/unittest/services/mocks/mock_context.h @@ -32,7 +32,7 @@ using namespace OHOS::AppExecFwk; class MockContextCallback : public ContextCallback { public: virtual ~MockContextCallback() = default; - MOCK_METHOD2(NewInstance, std::shared_ptr(sptr iamCallback, + MOCK_METHOD2(NewInstance, std::shared_ptr(sptr iamCallback, OperationType operationType)); MOCK_METHOD2(OnResult, void(int32_t resultCode, const Attributes &finalResult)); MOCK_METHOD3( @@ -51,7 +51,7 @@ public: MOCK_METHOD1(SetTraceReuseUnlockResultDuration, void(uint64_t reuseUnlockResultDuration)); MOCK_METHOD1(SetCleaner, void(Context::ContextStopCallback callback)); MOCK_METHOD2(ProcessAuthResult, void(int32_t tip, const std::vector &extraInfo)); - MOCK_METHOD0(GetIamCallback, sptr()); + MOCK_METHOD0(GetIamCallback, sptr()); MOCK_METHOD0(GetCallerName, std::string()); MOCK_METHOD1(SetTraceCallerType, void(int32_t callerType)); MOCK_METHOD1(SetTraceIsRemoteAuth, void(bool isRemoteAuth)); diff --git a/test/unittest/services/mocks/mock_auth_event_listener.h b/test/unittest/services/mocks/mock_event_listener.h similarity index 52% rename from test/unittest/services/mocks/mock_auth_event_listener.h rename to test/unittest/services/mocks/mock_event_listener.h index ee8cd1fa4ead957335baa99722f2bc83f7dfd5a6..583986d0bbfb3b3757132e46a70257790a774995 100644 --- a/test/unittest/services/mocks/mock_auth_event_listener.h +++ b/test/unittest/services/mocks/mock_event_listener.h @@ -12,32 +12,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#ifndef IAM_MOCK_AUTH_EVENT_LISTENER_INTERFACE_H -#define IAM_MOCK_AUTH_EVENT_LISTENER_INTERFACE_H +#ifndef IAM_MOCK_EVENT_LISTENER_INTERFACE_H +#define IAM_MOCK_EVENT_LISTENER_INTERFACE_H #include +#include "event_listener_callback_stub.h" #include "user_auth_client_callback.h" -#include "user_auth_event_listener_stub.h" +#include "iam_common_defines.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockAuthEventListener final : public AuthEventListenerInterface { +class MockEventListener final : public IEventListenerCallback { public: MOCK_METHOD0(AsObject, sptr()); - MOCK_METHOD4(OnNotifyAuthSuccessEvent, void(int32_t userId, AuthType authtype, int32_t callerType, - std::string &callerName)); + MOCK_METHOD4(OnNotifyAuthSuccessEvent, int32_t(int32_t userId, int32_t authType, int32_t callerType, + const std::string &callerName)); + MOCK_METHOD4(OnNotifyCredChangeEvent, int32_t(int32_t userId, int32_t authType, int32_t eventType, + uint64_t credentialId)); }; -class MockAuthEventListenerService final : public IRemoteStub { +class MockEventListenerService final : public IRemoteStub { public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD4(OnNotifyAuthSuccessEvent, void(int32_t userId, AuthType authtype, int32_t callerType, - std::string &callerName)); + MOCK_METHOD4(OnNotifyAuthSuccessEvent, int32_t(int32_t userId, int32_t authType, int32_t callerType, + const std::string &callerName)); + MOCK_METHOD4(OnNotifyCredChangeEvent, int32_t(int32_t userId, int32_t authType, int32_t eventType, + uint64_t credentialId)); }; } // namespace UserAuth } // namespace UserIam } // namespace OHOS -#endif // IAM_MOCK_AUTH_EVENT_LISTENER_INTERFACE_H \ No newline at end of file +#endif // IAM_MOCK_EVENT_LISTENER_INTERFACE_H \ No newline at end of file diff --git a/test/unittest/services/mocks/mock_executor_callback.h b/test/unittest/services/mocks/mock_executor_callback.h index 70c1e9fe8c5d187baf1a3737b8f83ce096a597d4..56d026e11b3a716f61ae6f3ed236c930801b0881 100644 --- a/test/unittest/services/mocks/mock_executor_callback.h +++ b/test/unittest/services/mocks/mock_executor_callback.h @@ -18,23 +18,25 @@ #include #include "iremote_stub.h" -#include "executor_callback_interface.h" +#include "iexecutor_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockExecutorCallback final : public IRemoteStub { +class MockExecutorCallback final : public IRemoteStub { public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD3(OnMessengerReady, void(sptr &messenger, + MOCK_METHOD3(OnMessengerReady, int32_t(const sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList)); MOCK_METHOD3(OnBeginExecute, - int32_t(uint64_t scheduleId, const std::vector &publicKey, const Attributes &command)); - MOCK_METHOD2(OnEndExecute, int32_t(uint64_t scheduleId, const Attributes &command)); - MOCK_METHOD1(OnSetProperty, int32_t(const Attributes &properties)); - MOCK_METHOD2(OnGetProperty, int32_t(const Attributes &condition, Attributes &values)); - MOCK_METHOD2(OnSendData, int32_t(uint64_t scheduleId, const Attributes &data)); + int32_t(uint64_t scheduleId, const std::vector &publicKey, const std::vector &command)); + MOCK_METHOD2(OnEndExecute, int32_t(uint64_t scheduleId, const std::vector &command)); + MOCK_METHOD1(OnSetProperty, int32_t(const std::vector &properties)); + MOCK_METHOD2(OnGetProperty, int32_t(const std::vector &condition, std::vector &values)); + MOCK_METHOD2(OnSendData, int32_t(uint64_t scheduleId, const std::vector &data)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_modal_callback.h b/test/unittest/services/mocks/mock_modal_callback.h index 244b07fefa9650298274e40119d53a2729897ccb..a008a1c0b6a63494a9537edbe22b74a9ddf9b75b 100644 --- a/test/unittest/services/mocks/mock_modal_callback.h +++ b/test/unittest/services/mocks/mock_modal_callback.h @@ -18,16 +18,18 @@ #include #include -#include "modal_callback_interface.h" +#include "imodal_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockModalCallback final : public IRemoteStub { +class MockModalCallback final : public IRemoteStub { public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD2(SendCommand, void(uint64_t contextId, const std::string &cmdData)); + MOCK_METHOD2(SendCommand, int32_t(uint64_t contextId, const std::string &cmdData)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_resource_node.h b/test/unittest/services/mocks/mock_resource_node.h index 88ed7e7feaa0bcb781879cf54e09d4555b9c4ff1..4feb2a641a728964fbccd5ec80ae57a70aa85fed 100644 --- a/test/unittest/services/mocks/mock_resource_node.h +++ b/test/unittest/services/mocks/mock_resource_node.h @@ -60,7 +60,7 @@ public: } static std::shared_ptr CreateWithExecuteIndex(uint64_t executorId, AuthType authType, - ExecutorRole executorRole, ExecutorCallbackInterface &callback) + ExecutorRole executorRole, IExecutorCallback &callback) { using namespace testing; auto node = std::make_shared(); @@ -77,10 +77,10 @@ public: ON_CALL(*node, BeginExecute) .WillByDefault( [&callback](uint64_t scheduleId, const std::vector &publicKey, const Attributes &command) { - return callback.OnBeginExecute(scheduleId, publicKey, command); + return callback.OnBeginExecute(scheduleId, publicKey, command.Serialize()); }); ON_CALL(*node, EndExecute).WillByDefault([&callback](uint64_t scheduleId, const Attributes &command) { - return callback.OnEndExecute(scheduleId, command); + return callback.OnEndExecute(scheduleId, command.Serialize()); }); return node; diff --git a/test/unittest/services/mocks/mock_user_access_ctrl_callback.h b/test/unittest/services/mocks/mock_user_access_ctrl_callback.h index 1fcf6fa529636b51ed5d48044029f441fcd4bf81..ff190ccbd3c4685f0bfec7faa77dd144c7779f59 100644 --- a/test/unittest/services/mocks/mock_user_access_ctrl_callback.h +++ b/test/unittest/services/mocks/mock_user_access_ctrl_callback.h @@ -18,16 +18,16 @@ #include #include -#include "user_access_ctrl_callback_interface.h" +#include "iverify_token_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockVerifyTokenCallback final : public IRemoteStub { +class MockVerifyTokenCallback final : public IRemoteStub { public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD2(OnVerifyTokenResult, void(int32_t result, const Attributes &extraInfo)); + MOCK_METHOD2(OnVerifyTokenResult, int32_t(int32_t result, const std::vector &extraInfo)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_user_auth_callback.h b/test/unittest/services/mocks/mock_user_auth_callback.h index 518b596b55bb38b7b6f03990828748a5dd458a8d..82acc1bf5f630c6b33858bcb4825916fedcd0c05 100644 --- a/test/unittest/services/mocks/mock_user_auth_callback.h +++ b/test/unittest/services/mocks/mock_user_auth_callback.h @@ -18,31 +18,39 @@ #include #include -#include "user_auth_callback_interface.h" +#include "iiam_callback.h" +#include "iget_executor_property_callback.h" +#include "iset_executor_property_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockUserAuthCallback final : public IRemoteStub { +class MockUserAuthCallback final : public IRemoteStub { public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD2(OnResult, void(int32_t result, const Attributes &extraInfo)); - MOCK_METHOD3(OnAcquireInfo, void(int32_t module, int32_t acquireInfo, const Attributes &extraInfo)); + MOCK_METHOD2(OnResult, int32_t(int32_t resultCode, const std::vector &extraInfo)); + MOCK_METHOD3(OnAcquireInfo, int32_t(int32_t module, int32_t acquireInfo, const std::vector &extraInfo)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; -class MockGetExecutorPropertyCallback final : public IRemoteStub { +class MockGetExecutorPropertyCallback final : public IRemoteStub { public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD2(OnGetExecutorPropertyResult, void(int32_t result, const Attributes &attributes)); + MOCK_METHOD2(OnGetExecutorPropertyResult, int32_t(int32_t resultCode, const std::vector &attributes)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; -class MockSetExecutorPropertyCallback final : public IRemoteStub { +class MockSetExecutorPropertyCallback final : public IRemoteStub { public: MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); - MOCK_METHOD1(OnSetExecutorPropertyResult, void(int32_t result)); + MOCK_METHOD1(OnSetExecutorPropertyResult, int32_t(int32_t result)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_user_auth_service.h b/test/unittest/services/mocks/mock_user_auth_service.h index 2216dce1223afb99db652d2fd5656d42fc3358b7..6c6c5c7d8c8adf92acf59e89ad3836dc6ec810eb 100644 --- a/test/unittest/services/mocks/mock_user_auth_service.h +++ b/test/unittest/services/mocks/mock_user_auth_service.h @@ -25,51 +25,52 @@ namespace UserIam { namespace UserAuth { class MockUserAuthService final : public UserAuthStub { public: - MOCK_METHOD3(GetEnrolledState, int32_t(int32_t apiVersion, AuthType authType, EnrolledState &enrolledState)); + MOCK_METHOD3(GetEnrolledState, int32_t(int32_t apiVersion, int32_t authType, IpcEnrolledState &ipcEnrolledState)); - MOCK_METHOD4(GetAvailableStatus, int32_t(int32_t apiVersion, int32_t userId, AuthType authType, - AuthTrustLevel authTrustLevel)); + MOCK_METHOD4(GetAvailableStatus, int32_t(int32_t apiVersion, int32_t userId, int32_t authType, + uint32_t authTrustLevel)); - int32_t GetAvailableStatus(int32_t apiVersion, AuthType authType, AuthTrustLevel authTrustLevel) + int32_t GetAvailableStatus(int32_t apiVersion, int32_t authType, uint32_t authTrustLevel) { return 0; } - MOCK_METHOD4(GetProperty, - void(int32_t userId, AuthType authType, const std::vector &keys, - sptr &callback)); + MOCK_METHOD4(GetProperty, int32_t(int32_t userId, int32_t authType, const std::vector &keys, + const sptr &getExecutorPropertyCallback)); - MOCK_METHOD3(GetPropertyById, void(uint64_t credentialId, const std::vector &keys, - sptr &callback)); + MOCK_METHOD3(GetPropertyById, int32_t(uint64_t credentialId, const std::vector &keys, + const sptr &getExecutorPropertyCallback)); - MOCK_METHOD4(SetProperty, void(int32_t userId, AuthType authType, const Attributes &attributes, - sptr &callback)); + MOCK_METHOD4(SetProperty, int32_t(int32_t userId, int32_t authType, const std::vector &attributes, + const sptr &setExecutorPropertyCallback)); - MOCK_METHOD3(AuthUser, uint64_t(AuthParamInner ¶m, std::optional &remoteAuthParam, - sptr &callback)); + MOCK_METHOD4(AuthUser, int32_t(const IpcAuthParamInner &ipcAuthParamInner, + const IpcRemoteAuthParam &ipcRemoteAuthParam, const sptr &userAuthCallback, + uint64_t &contextId)); - MOCK_METHOD5(Auth, - uint64_t(int32_t apiVersion, const std::vector &challenge, AuthType authType, - AuthTrustLevel authTrustLevel, sptr &callback)); + MOCK_METHOD4(Auth, int32_t(int32_t apiVersion, const IpcAuthParamInner &ipcAuthParamInner, + const sptr &userAuthCallback, uint64_t &contextI)); - MOCK_METHOD5(AuthWidget, uint64_t(int32_t apiVersion, const AuthParamInner &authParam, - const WidgetParamInner &widgetParam, sptr &callback, - sptr &modalCallback)); + MOCK_METHOD6(AuthWidget, int32_t(int32_t apiVersion, const IpcAuthParamInner &ipcAuthParamInner, + const IpcWidgetParamInner &ipcWidgetParamInner, const sptr &userAuthCallback, + const sptr &modalCallback, uint64_t &contextId)); - MOCK_METHOD3(Identify, - uint64_t(const std::vector &challenge, AuthType authType, sptr &callback)); + MOCK_METHOD4(Identify, int32_t(const std::vector &challenge, int32_t authType, + const sptr &userAuthCallback, uint64_t &contextId)); MOCK_METHOD2(CancelAuthOrIdentify, int32_t(uint64_t contextId, int32_t cancelReason)); MOCK_METHOD1(GetVersion, int32_t(int32_t &version)); - MOCK_METHOD2(Notice, int32_t(NoticeType noticeType, const std::string &eventData)); - MOCK_METHOD2(RegisterWidgetCallback, int32_t(int32_t version, sptr &callback)); - MOCK_METHOD2(RegistUserAuthSuccessEventListener, int32_t(const std::vector &authType, - const sptr &callback)); - MOCK_METHOD1(UnRegistUserAuthSuccessEventListener, int32_t(const sptr &callback)); - MOCK_METHOD1(SetGlobalConfigParam, int32_t(const GlobalConfigParam ¶m)); - MOCK_METHOD2(PrepareRemoteAuth, int32_t(const std::string &networkId, sptr &callback)); - MOCK_METHOD3(VerifyAuthToken, void(const std::vector &tokenIn, uint64_t allowableDuration, - const sptr &callback)); + MOCK_METHOD2(Notice, int32_t(int32_t noticeType, const std::string &eventData)); + MOCK_METHOD2(RegisterWidgetCallback, int32_t(int32_t version, const sptr &widgetCallback)); + MOCK_METHOD1(RegistUserAuthSuccessEventListener, int32_t(const sptr &listener)); + MOCK_METHOD1(UnRegistUserAuthSuccessEventListener, int32_t(const sptr &listener)); + MOCK_METHOD1(SetGlobalConfigParam, int32_t(const IpcGlobalConfigParam &ipcGlobalConfigParam)); + MOCK_METHOD2(PrepareRemoteAuth, int32_t(const std::string &networkId, + const sptr &userAuthCallback)); + MOCK_METHOD3(VerifyAuthToken, int32_t(const std::vector &tokenIn, uint64_t allowableDuration, + const sptr &verifyTokenCallback)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_user_idm_callback.h b/test/unittest/services/mocks/mock_user_idm_callback.h index c9abf721335cafbc3d9c88cd09ba4940de807520..71e36d1d0de3097605aa5c9e6b19414208c2d0f4 100644 --- a/test/unittest/services/mocks/mock_user_idm_callback.h +++ b/test/unittest/services/mocks/mock_user_idm_callback.h @@ -20,31 +20,39 @@ #include #include -#include "user_idm_callback_interface.h" +#include "iiam_callback.h" +#include "iidm_get_cred_info_callback.h" +#include "iidm_get_secure_user_info_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockIdmGetCredentialInfoCallback final : public IRemoteStub { +class MockIdmGetCredentialInfoCallback final : public IRemoteStub { public: - MOCK_METHOD2(OnCredentialInfos, void(int32_t result, const std::vector &credInfoList)); + MOCK_METHOD2(OnCredentialInfos, int32_t(int32_t result, const std::vector &credInfoList)); MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; -class MockIdmGetSecureUserInfoCallback final : public IRemoteStub { +class MockIdmGetSecureUserInfoCallback final : public IRemoteStub { public: - MOCK_METHOD2(OnSecureUserInfo, void(int32_t result, const SecUserInfo &secUserInfo)); + MOCK_METHOD2(OnSecureUserInfo, int32_t(int32_t resultCodeCode, const IpcSecUserInfo &secUserInfo)); MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; -class MockIdmCallback final : public IRemoteStub { +class MockIdmCallback final : public IRemoteStub { public: - MOCK_METHOD2(OnResult, void(int32_t result, const Attributes &extraInfo)); - MOCK_METHOD3(OnAcquireInfo, void(int32_t module, int32_t acquire, const Attributes &extraInfo)); + MOCK_METHOD2(OnResult, int32_t(int32_t resultCode, const std::vector &extraInfo)); + MOCK_METHOD3(OnAcquireInfo, int32_t(int32_t module, int32_t acquire, const std::vector &extraInfo)); MOCK_METHOD4(OnRemoteRequest, int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_user_idm_service.h b/test/unittest/services/mocks/mock_user_idm_service.h index 4cf097d0dd0872e98683f43b36b9498061ee0a6c..c09d8f246f7f151f06595eaaeb7ab3cdf4b775a1 100644 --- a/test/unittest/services/mocks/mock_user_idm_service.h +++ b/test/unittest/services/mocks/mock_user_idm_service.h @@ -26,21 +26,28 @@ namespace UserAuth { class MockUserIdmService final : public UserIdmStub { public: MOCK_METHOD2(OpenSession, int32_t(int32_t userId, std::vector &challenge)); - MOCK_METHOD1(CloseSession, void(int32_t userId)); - MOCK_METHOD3(GetCredentialInfo, int32_t(int32_t userId, AuthType authType, - const sptr &callback)); - MOCK_METHOD2(GetSecInfo, int32_t(int32_t userId, const sptr &callback)); - MOCK_METHOD4(AddCredential, void(int32_t userId, const CredentialPara &credPara, - const sptr &callback, bool isUpdate)); - MOCK_METHOD3(UpdateCredential, void(int32_t userId, const CredentialPara &credPara, - const sptr &callback)); + MOCK_METHOD1(CloseSession, int32_t(int32_t userId)); + MOCK_METHOD3(GetCredentialInfo, int32_t(int32_t userId, int32_t authType, + const sptr &idmGetCredInfoCallbac)); + MOCK_METHOD2(GetSecInfo, int32_t(int32_t userId, + const sptr &idmGetSecureUserInfoCallback)); + MOCK_METHOD4(AddCredential, int32_t(int32_t userId, const IpcCredentialPara &ipcCredentialPara, + const sptr &IdmCallback, bool isUpdate)); + MOCK_METHOD3(UpdateCredential, int32_t(int32_t userId, const IpcCredentialPara &ipcCredentialPara, + const sptr &IdmCallback)); MOCK_METHOD1(Cancel, int32_t(int32_t userId)); - MOCK_METHOD2(EnforceDelUser, int32_t(int32_t userId, const sptr &callback)); - MOCK_METHOD3(DelUser, void(int32_t userId, const std::vector authToken, - const sptr &callback)); - MOCK_METHOD4(DelCredential, void(int32_t userId, uint64_t credentialId, - const std::vector &authToken, const sptr &callback)); - MOCK_METHOD1(ClearRedundancyCredential, void(const sptr &callback)); + MOCK_METHOD2(EnforceDelUser, int32_t(int32_t userId, const sptr &IdmCallback)); + MOCK_METHOD3(DelUser, int32_t(int32_t userId, const std::vector &authToken, + const sptr &IdmCallback)); + MOCK_METHOD4(DelCredential, int32_t(int32_t userId, uint64_t credentialId, const std::vector &authToken, + const sptr &IdmCallback)); + MOCK_METHOD1(ClearRedundancyCredential, int32_t(const sptr &IdmCallback)); + MOCK_METHOD1(RegistCredChangeEventListener, int32_t(const sptr &callback)); + MOCK_METHOD1(UnRegistCredChangeEventListener, int32_t(const sptr &callback)); + MOCK_METHOD3(GetCredentialInfoSync, int32_t(int32_t userId, int32_t authType, + std::vector &ipcCredentialInfoList)); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/mocks/mock_widget_callback_interface.h b/test/unittest/services/mocks/mock_widget_callback_interface.h index 43e0af8ef80600f7d6978e3e734b189c11ef83df..f696d33a87351310d585d3ba843d05ccc7d5f5e2 100644 --- a/test/unittest/services/mocks/mock_widget_callback_interface.h +++ b/test/unittest/services/mocks/mock_widget_callback_interface.h @@ -17,15 +17,17 @@ #include -#include "widget_callback_interface.h" +#include "iwidget_callback.h" namespace OHOS { namespace UserIam { namespace UserAuth { -class MockWidgetCallbackInterface final : public WidgetCallbackInterface { +class MockIWidgetCallback final : public IWidgetCallback { public: - MOCK_METHOD1(SendCommand, void(const std::string &cmdData)); + MOCK_METHOD1(SendCommand, int32_t(const std::string &cmdData)); MOCK_METHOD0(AsObject, sptr()); + MOCK_METHOD1(CallbackEnter, int32_t(uint32_t code)); + MOCK_METHOD2(CallbackExit, int32_t(uint32_t code, int32_t result)); }; } // namespace UserAuth } // namespace UserIam diff --git a/test/unittest/services/src/co_auth_service_test.cpp b/test/unittest/services/src/co_auth_service_test.cpp index 9ce4635710b8bace8363f55970785b120d110b4f..369fbe80dfd27b3270fdda2f4d11944566223c91 100644 --- a/test/unittest/services/src/co_auth_service_test.cpp +++ b/test/unittest/services/src/co_auth_service_test.cpp @@ -54,12 +54,12 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTest001, TestSize.Level0) sptr testCallback(new (std::nothrow) MockExecutorCallback()); EXPECT_NE(testCallback, nullptr); - CoAuthInterface::ExecutorRegisterInfo info = {}; - info.authType = FINGERPRINT; - info.executorRole = SCHEDULER; + IpcExecutorRegisterInfo info = {}; + info.authType = static_cast(FINGERPRINT); + info.executorRole = static_cast(SCHEDULER); info.executorSensorHint = 0; info.executorMatcher = 0; - info.esl = ESL1; + info.esl = static_cast(ESL1); info.publicKey = {'a', 'b', 'c', 'd'}; auto service = Common::MakeShared(); @@ -70,9 +70,10 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTest001, TestSize.Level0) EXPECT_NE(mockHdi, nullptr); std::promise promise; EXPECT_CALL(*testCallback, OnMessengerReady(_, _, _)).Times(1).WillOnce( - [&promise](sptr &messenger, + [&promise](const sptr &messenger, const std::vector &publicKey, const std::vector &templateIdList) { promise.set_value(); + return SUCCESS; } ); EXPECT_CALL(*mockHdi, AddExecutor(_, _, _, _)) @@ -86,13 +87,14 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTest001, TestSize.Level0) } ); IpcCommon::AddPermission(ACCESS_AUTH_RESPOOL); - sptr callbackInterface = testCallback; - uint64_t executorIndex = service->ExecutorRegister(info, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t executorIndex = 0; + EXPECT_EQ(service->ExecutorRegister(info, callbackInterface, executorIndex), GENERAL_ERROR); EXPECT_EQ(executorIndex, 0); - executorIndex = service->ExecutorRegister(info, callbackInterface); + EXPECT_EQ(service->ExecutorRegister(info, callbackInterface, executorIndex), SUCCESS); EXPECT_NE(executorIndex, 0); promise.get_future().get(); - service->ExecutorUnregister(executorIndex); + EXPECT_EQ(service->ExecutorUnregister(executorIndex), SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -101,9 +103,10 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTest002, TestSize.Level0) auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); - CoAuthInterface::ExecutorRegisterInfo info = {}; - sptr testCallback(nullptr); - uint64_t executorIndex = service->ExecutorRegister(info, testCallback); + IpcExecutorRegisterInfo info = {}; + sptr testCallback(nullptr); + uint64_t executorIndex = 0; + EXPECT_EQ(service->ExecutorRegister(info, testCallback, executorIndex), INVALID_PARAMETERS); EXPECT_EQ(executorIndex, 0); } @@ -112,22 +115,23 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTestExecutorRegister001, TestSize.Level sptr testCallback(new (std::nothrow) MockExecutorCallback()); EXPECT_NE(testCallback, nullptr); - CoAuthInterface::ExecutorRegisterInfo info = {}; - info.authType = FINGERPRINT; - info.executorRole = SCHEDULER; + IpcExecutorRegisterInfo info = {}; + info.authType = static_cast(FINGERPRINT); + info.executorRole = static_cast(SCHEDULER); info.executorSensorHint = 0; info.executorMatcher = 0; - info.esl = ESL1; + info.esl = static_cast(ESL1); info.publicKey = {'a', 'b', 'c', 'd'}; auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); service->SetIsReady(false); service->SetAccessTokenReady(false); - sptr callbackInterface = testCallback; - uint64_t executorIndex = service->ExecutorRegister(info, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t executorIndex = 0; + EXPECT_EQ(service->ExecutorRegister(info, callbackInterface, executorIndex), GENERAL_ERROR); EXPECT_EQ(executorIndex, INVALID_EXECUTOR_INDEX); - service->ExecutorUnregister(executorIndex); + EXPECT_EQ(service->ExecutorUnregister(executorIndex), SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -136,22 +140,23 @@ HWTEST_F(CoAuthServiceTest, CoAuthServiceTestExecutorRegister002, TestSize.Level sptr testCallback(new (std::nothrow) MockExecutorCallback()); EXPECT_NE(testCallback, nullptr); - CoAuthInterface::ExecutorRegisterInfo info = {}; - info.authType = FINGERPRINT; - info.executorRole = SCHEDULER; + IpcExecutorRegisterInfo info = {}; + info.authType = static_cast(FINGERPRINT); + info.executorRole = static_cast(SCHEDULER); info.executorSensorHint = 0; info.executorMatcher = 0; - info.esl = ESL1; + info.esl = static_cast(ESL1); info.publicKey = {'a', 'b', 'c', 'd'}; auto service = Common::MakeShared(); EXPECT_NE(service, nullptr); service->SetIsReady(true); service->SetAccessTokenReady(true); - sptr callbackInterface = testCallback; - uint64_t executorIndex = service->ExecutorRegister(info, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t executorIndex = 0; + EXPECT_EQ(service->ExecutorRegister(info, callbackInterface, executorIndex), CHECK_PERMISSION_FAILED); EXPECT_EQ(executorIndex, INVALID_EXECUTOR_INDEX); - service->ExecutorUnregister(executorIndex); + EXPECT_EQ(service->ExecutorUnregister(executorIndex), CHECK_PERMISSION_FAILED); IpcCommon::DeleteAllPermission(); } diff --git a/test/unittest/services/src/co_auth_stub_test.cpp b/test/unittest/services/src/co_auth_stub_test.cpp deleted file mode 100644 index ebc6d18a24d8ac4ac8e014b5299feea675a61b73..0000000000000000000000000000000000000000 --- a/test/unittest/services/src/co_auth_stub_test.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "co_auth_stub_test.h" - -#include "mock_executor_callback.h" -#include "mock_co_auth_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void CoAuthStubTest::SetUpTestCase() -{ -} - -void CoAuthStubTest::TearDownTestCase() -{ -} - -void CoAuthStubTest::SetUp() -{ -} - -void CoAuthStubTest::TearDown() -{ -} - -HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - - CoAuthInterface::ExecutorRegisterInfo testInfo = {}; - testInfo.authType = PIN; - testInfo.executorRole = SCHEDULER; - testInfo.executorSensorHint = 0; - testInfo.executorMatcher = 0; - testInfo.esl = ESL1; - testInfo.maxTemplateAcl = 0; - testInfo.publicKey = {'a', 'b', 'c', 'd'}; - - uint64_t testContextId = 124545; - - sptr callback(new (std::nothrow) MockExecutorCallback()); - EXPECT_NE(callback, nullptr); - MockCoAuthService service; - EXPECT_CALL(service, ExecutorRegister(_, _)).Times(0); - ON_CALL(service, ExecutorRegister) - .WillByDefault( - [&testInfo, &testContextId](const CoAuthInterface::ExecutorRegisterInfo &info, - sptr &callback) { - EXPECT_EQ(info.authType, testInfo.authType); - EXPECT_EQ(info.executorRole, testInfo.executorRole); - EXPECT_EQ(info.executorSensorHint, testInfo.executorSensorHint); - EXPECT_EQ(info.executorMatcher, testInfo.executorMatcher); - EXPECT_EQ(info.esl, testInfo.esl); - EXPECT_THAT(info.publicKey, ElementsAreArray(testInfo.publicKey)); - return testContextId; - } - ); - - EXPECT_TRUE(data.WriteInterfaceToken(CoAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testInfo.authType)); - EXPECT_TRUE(data.WriteInt32(testInfo.executorRole)); - EXPECT_TRUE(data.WriteUint32(testInfo.executorSensorHint)); - EXPECT_TRUE(data.WriteUint32(testInfo.executorMatcher)); - EXPECT_TRUE(data.WriteInt32(testInfo.esl)); - EXPECT_TRUE(data.WriteUint32(testInfo.maxTemplateAcl)); - EXPECT_TRUE(data.WriteUInt8Vector(testInfo.publicKey)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - uint32_t code = CoAuthInterfaceCode::CO_AUTH_EXECUTOR_REGISTER; - MessageOption option(MessageOption::TF_SYNC); - - EXPECT_NE(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - uint64_t contextId = -1; - EXPECT_FALSE(reply.ReadUint64(contextId)); - EXPECT_NE(contextId, testContextId); -} - -HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister002, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - - uint32_t code = CoAuthInterfaceCode::CO_AUTH_EXECUTOR_REGISTER; - MessageOption option(MessageOption::TF_SYNC); - - MockCoAuthService service; - EXPECT_EQ(GENERAL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister003, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - - EXPECT_TRUE(data.WriteInterfaceToken(CoAuthInterface::GetDescriptor())); - uint32_t code = CoAuthInterfaceCode::CO_AUTH_EXECUTOR_REGISTER; - MessageOption option(MessageOption::TF_SYNC); - - MockCoAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister004, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - - CoAuthInterface::ExecutorRegisterInfo testInfo = {}; - testInfo.authType = PIN; - testInfo.executorRole = SCHEDULER; - testInfo.executorSensorHint = 0; - testInfo.executorMatcher = 0; - testInfo.esl = ESL1; - testInfo.maxTemplateAcl = 0; - testInfo.publicKey = {'a', 'b', 'c', 'd'}; - - uint64_t testContextId = 124545; - - sptr callback(new (std::nothrow) MockExecutorCallback()); - EXPECT_NE(callback, nullptr); - MockCoAuthService service; - EXPECT_CALL(service, ExecutorRegister(_, _)).Times(0); - ON_CALL(service, ExecutorRegister) - .WillByDefault( - [&testInfo, &testContextId](const CoAuthInterface::ExecutorRegisterInfo &info, - sptr &callback) { - EXPECT_EQ(info.authType, testInfo.authType); - EXPECT_EQ(info.executorRole, testInfo.executorRole); - EXPECT_EQ(info.executorSensorHint, testInfo.executorSensorHint); - EXPECT_EQ(info.executorMatcher, testInfo.executorMatcher); - EXPECT_EQ(info.esl, testInfo.esl); - EXPECT_THAT(info.publicKey, ElementsAreArray(testInfo.publicKey)); - return INVALID_EXECUTOR_INDEX; - } - ); - - EXPECT_TRUE(data.WriteInterfaceToken(CoAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testInfo.authType)); - EXPECT_TRUE(data.WriteInt32(testInfo.executorRole)); - EXPECT_TRUE(data.WriteUint32(testInfo.executorSensorHint)); - EXPECT_TRUE(data.WriteUint32(testInfo.executorMatcher)); - EXPECT_TRUE(data.WriteInt32(testInfo.esl)); - EXPECT_TRUE(data.WriteUint32(testInfo.maxTemplateAcl)); - EXPECT_TRUE(data.WriteUInt8Vector(testInfo.publicKey)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - uint32_t code = CoAuthInterfaceCode::CO_AUTH_EXECUTOR_REGISTER; - MessageOption option(MessageOption::TF_SYNC); - - EXPECT_NE(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorUnRegister001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - uint64_t testExecutorIndex = 6; - data.WriteUint64(testExecutorIndex); - sptr callback(new (std::nothrow) MockExecutorCallback()); - EXPECT_NE(callback, nullptr); - MockCoAuthService service; - EXPECT_CALL(service, ExecutorUnregister(_)).Times(0); - ON_CALL(service, ExecutorUnregister) - .WillByDefault([](uint64_t executorIndex) { - return; - } - ); - EXPECT_TRUE(data.WriteUint64(testExecutorIndex)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - uint32_t code = CoAuthInterfaceCode::CO_AUTH_EXECUTOR_UNREGISTER; - MessageOption option(MessageOption::TF_SYNC); - - EXPECT_NE(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/services/src/context_callback_impl_test.cpp b/test/unittest/services/src/context_callback_impl_test.cpp index 2b19f8286cafd79309ce13711c952b5c4e9f03cd..b38fe4f4d5d6352af825ca1d599640dc590ef096 100644 --- a/test/unittest/services/src/context_callback_impl_test.cpp +++ b/test/unittest/services/src/context_callback_impl_test.cpp @@ -57,14 +57,14 @@ void ContextCallbackImplTest::TearDown() HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthNull, TestSize.Level0) { - sptr callback(nullptr); + sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ASSERT_EQ(contextCallback, nullptr); } HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserIdmNull, TestSize.Level0) { - sptr callback(nullptr); + sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ASSERT_EQ(contextCallback, nullptr); } @@ -79,11 +79,12 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuth, TestSize.Level0) ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnResult(_, _)) .Times(Exactly(1)) - .WillOnce([&testResult, &testAttr](int32_t result, const Attributes &reqRet) { + .WillOnce([&testResult, &testAttr](int32_t result, const std::vector &reqRet) { EXPECT_TRUE(testResult == result); - EXPECT_TRUE(&reqRet == testAttr.get()); + EXPECT_TRUE(reqRet == testAttr->Serialize()); + return SUCCESS; }); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, {}); @@ -109,7 +110,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserIdmOnResult, TestSize.L ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnResult(_, _)).Times(1); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); @@ -138,7 +139,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthOnAcquireInfo_001, sptr mockCallback(new (nothrow) MockIdmCallback()); ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_BEHAVIOR); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); @@ -166,7 +167,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthOnAcquireInfo_002, sptr mockCallback(new (nothrow) MockIdmCallback()); ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_SECURITY); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); @@ -194,7 +195,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthOnAcquireInfo_003, sptr mockCallback(new (nothrow) MockIdmCallback()); ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_SECURITY); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); @@ -219,7 +220,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthOnAcquireInfo_004, sptr mockCallback(new (nothrow) MockIdmCallback()); ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_SECURITY); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); @@ -247,7 +248,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthOnAcquireInfo_005, sptr mockCallback(new (nothrow) MockIdmCallback()); ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_SECURITY); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); @@ -275,7 +276,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthOnAcquireInfo_006, sptr mockCallback(new (nothrow) MockIdmCallback()); ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_SECURITY); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); @@ -303,7 +304,7 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuthOnAcquireInfo_007, sptr mockCallback(new (nothrow) MockIdmCallback()); ASSERT_TRUE(mockCallback != nullptr); EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1); - sptr callback = mockCallback; + sptr callback = mockCallback; auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_SECURITY); ASSERT_NE(contextCallback, nullptr); contextCallback->OnAcquireInfo(static_cast(0), 0, testMsg); diff --git a/test/unittest/services/src/context_factory_test.cpp b/test/unittest/services/src/context_factory_test.cpp index 6ab7904abdfe48fe7de771b7a1a0b1971ea542d1..a604381f0faf366ed413e9bf13a7322ce30a30df 100644 --- a/test/unittest/services/src/context_factory_test.cpp +++ b/test/unittest/services/src/context_factory_test.cpp @@ -56,7 +56,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_001, TestSize.Level0 auto factory = ContextFactory::GetInstance(); ASSERT_NE(factory, nullptr); std::vector challenge; - sptr callback(new (std::nothrow) MockUserAuthCallback()); + sptr callback(new (std::nothrow) MockUserAuthCallback()); ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL); Authentication::AuthenticationPara para = {}; @@ -72,7 +72,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_002, TestSize.Level0 ASSERT_NE(factory, nullptr); std::vector challenge; // Error: callback is null - sptr callback(nullptr); + sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER_ALL); Authentication::AuthenticationPara para = {}; auto context = factory->CreateSimpleAuthContext(para, contextCallback, true); @@ -84,7 +84,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_001, TestSize.Level0) auto factory = ContextFactory::GetInstance(); ASSERT_NE(factory, nullptr); std::vector challenge; - sptr callback(new (std::nothrow) MockUserAuthCallback()); + sptr callback(new (std::nothrow) MockUserAuthCallback()); ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY); Identification::IdentificationPara para = {}; @@ -100,7 +100,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_002, TestSize.Level0) ASSERT_NE(factory, nullptr); std::vector challenge; // Error: callback is null - sptr callback(nullptr); + sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY); Identification::IdentificationPara para = {}; auto context = factory->CreateIdentifyContext(para, contextCallback); @@ -112,7 +112,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_001, TestSize.Lev auto factory = ContextFactory::GetInstance(); ASSERT_NE(factory, nullptr); std::vector token; - sptr callback(new (std::nothrow) MockIdmCallback()); + sptr callback(new (std::nothrow) MockIdmCallback()); ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); Enrollment::EnrollmentPara para = {}; @@ -128,7 +128,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_002, TestSize.Lev ASSERT_NE(factory, nullptr); std::vector token; // Error: callback is null - sptr callback(nullptr); + sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); Enrollment::EnrollmentPara para = {}; auto context = factory->CreateEnrollContext(para, contextCallback, true); @@ -140,7 +140,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateWidgetAuthContext_001, TestSize auto factory = ContextFactory::GetInstance(); ASSERT_NE(factory, nullptr); std::vector token; - sptr callback(nullptr); + sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); EXPECT_EQ(ContextFactory::CreateWidgetAuthContext(contextCallback), nullptr); } @@ -150,7 +150,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateWidgetContext_001, TestSize.Lev auto factory = ContextFactory::GetInstance(); ASSERT_NE(factory, nullptr); std::vector token; - sptr callback(new (std::nothrow) MockIdmCallback()); + sptr callback(new (std::nothrow) MockIdmCallback()); ASSERT_NE(callback, nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ContextFactory::AuthWidgetContextPara para = {}; @@ -163,7 +163,7 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateWidgetContext_002, TestSize.Lev auto factory = ContextFactory::GetInstance(); ASSERT_NE(factory, nullptr); std::vector token; - sptr callback(nullptr); + sptr callback(nullptr); auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL); ContextFactory::AuthWidgetContextPara para = {}; auto context = factory->CreateWidgetContext(para, contextCallback); diff --git a/frameworks/native/ipc/src/widget_callback_proxy.cpp b/test/unittest/services/src/driver_state_manager_test.cpp similarity index 35% rename from frameworks/native/ipc/src/widget_callback_proxy.cpp rename to test/unittest/services/src/driver_state_manager_test.cpp index 2d2aca83167e2926a45828064fd6c4b339a9c74b..23ed3e0683b48dc691bf514fff206e454f660995 100644 --- a/frameworks/native/ipc/src/widget_callback_proxy.cpp +++ b/test/unittest/services/src/driver_state_manager_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,55 +13,61 @@ * limitations under the License. */ -#include "widget_callback_proxy.h" +#include "driver_state_manager_test.h" + +#include "driver_state_manager.h" #include "iam_logger.h" -#include "iam_common_defines.h" -#include "user_auth_interface.h" +#include "securec.h" #define LOG_TAG "USER_AUTH_SA" namespace OHOS { namespace UserIam { namespace UserAuth { -void WidgetCallbackProxy::SendCommand(const std::string &cmdData) +using namespace testing; +using namespace testing::ext; + +void DriverStateManagerTest::SetUpTestCase() +{ +} + +void DriverStateManagerTest::TearDownTestCase() +{ +} + +void DriverStateManagerTest::SetUp() +{ +} + +void DriverStateManagerTest::TearDown() { - IAM_LOGI("start"); +} - MessageParcel data; - MessageParcel reply; +HWTEST_F(DriverStateManagerTest, StartSubscribeTest, TestSize.Level0) +{ + EXPECT_NO_THROW(DriverStateManager::GetInstance().StartSubscribe()); + EXPECT_NO_THROW(DriverStateManager::GetInstance().StartSubscribe()); +} - if (!data.WriteInterfaceToken(WidgetCallbackProxy::GetDescriptor())) { - IAM_LOGE("write descriptor failed"); - return; - } - if (!data.WriteString(cmdData)) { - IAM_LOGE("write cmd data failed"); - return; - } - bool ret = SendRequest(UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND, data, reply); - if (!ret) { - IAM_LOGE("send request failed"); - } +HWTEST_F(DriverStateManagerTest, OnDriverManagerAddTest, TestSize.Level0) +{ + EXPECT_NO_THROW(DriverStateManager::GetInstance().OnDriverManagerAdd()); +} + +HWTEST_F(DriverStateManagerTest, OnDriverStartTest, TestSize.Level0) +{ + EXPECT_NO_THROW(DriverStateManager::GetInstance().OnDriverStart()); + EXPECT_NO_THROW(DriverStateManager::GetInstance().OnDriverStart()); } -bool WidgetCallbackProxy::SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply) +HWTEST_F(DriverStateManagerTest, OnDriverStopTest, TestSize.Level0) { - IAM_LOGI("start code = %{public}u", code); - sptr remote = Remote(); - if (remote == nullptr) { - IAM_LOGE("get remote failed"); - return false; - } - MessageOption option(MessageOption::TF_SYNC); - int32_t result = remote->SendRequest(code, data, reply, option); - if (result != OHOS::NO_ERROR) { - IAM_LOGE("send request failed, result = %{public}d", result); - return false; - } - IAM_LOGI("end"); - return true; + EXPECT_NO_THROW(DriverStateManager::GetInstance().OnDriverStop()); + EXPECT_NO_THROW(DriverStateManager::GetInstance().OnDriverStop()); + EXPECT_NO_THROW(DriverStateManager::GetInstance().OnDriverStart()); + EXPECT_NO_THROW(DriverStateManager::GetInstance().OnDriverStart()); } } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/services/src/event_listener_manager_test.cpp b/test/unittest/services/src/event_listener_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3ad2f658e76e2b5ff591e5bb3685fc458ee8d6f3 --- /dev/null +++ b/test/unittest/services/src/event_listener_manager_test.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "event_listener_manager_test.h" +#include "event_listener_manager.h" + +#include "gtest/gtest.h" +#include "mock_event_listener.h" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +using namespace testing; +using namespace testing::ext; + +void EventListenerManagerTest::SetUpTestCase() +{ +} + +void EventListenerManagerTest::TearDownTestCase() +{ +} + +void EventListenerManagerTest::SetUp() +{ +} + +void EventListenerManagerTest::TearDown() +{ +} + +HWTEST_F(EventListenerManagerTest, EventListenerManagerTestRegistEventListener, TestSize.Level0) +{ + sptr testCallback = new MockEventListener(); + EXPECT_EQ(AuthEventListenerManager::GetInstance().RegistEventListener(nullptr), GENERAL_ERROR); + EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().RegistEventListener(testCallback)); + + EXPECT_EQ(CredChangeEventListenerManager::GetInstance().RegistEventListener(nullptr), + GENERAL_ERROR); + EXPECT_NO_THROW(CredChangeEventListenerManager::GetInstance().RegistEventListener(testCallback)); +} + +HWTEST_F(EventListenerManagerTest, EventListenerManagerTestUnRegistEventListener, TestSize.Level0) +{ + sptr testCallback = new MockEventListener(); + EXPECT_EQ(AuthEventListenerManager::GetInstance().UnRegistEventListener(nullptr), GENERAL_ERROR); + EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().UnRegistEventListener(testCallback)); + + EXPECT_EQ(CredChangeEventListenerManager::GetInstance().UnRegistEventListener(nullptr), GENERAL_ERROR); + EXPECT_NO_THROW(CredChangeEventListenerManager::GetInstance().UnRegistEventListener(testCallback)); +} + +HWTEST_F(EventListenerManagerTest, EventListenerManagerTestRemoveDeathRecipient, TestSize.Level0) +{ + sptr testCallback = new MockEventListener(); + EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().RemoveDeathRecipient(testCallback)); + EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().RemoveDeathRecipient(nullptr)); + EXPECT_NO_THROW(CredChangeEventListenerManager::GetInstance().RemoveDeathRecipient(testCallback)); + EXPECT_NO_THROW(CredChangeEventListenerManager::GetInstance().RemoveDeathRecipient(nullptr)); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/services/src/executor_messenger_service_test.cpp b/test/unittest/services/src/executor_messenger_service_test.cpp index 6028ad681bde719fcc0c2213f035a87209a0be96..46ee5934d4d84b1151b637c37dfb5caf81a62e17 100644 --- a/test/unittest/services/src/executor_messenger_service_test.cpp +++ b/test/unittest/services/src/executor_messenger_service_test.cpp @@ -58,7 +58,7 @@ HWTEST_F(ExecutorMessengerServiceTest, ExecutorMessengerServiceTest002, TestSize uint64_t testContextId = 78545; ExecutorRole testDstRole = VERIFIER; ResultCode testResultCode = FAIL; - std::shared_ptr testFinalResult = nullptr; + std::vector testFinalResult; std::vector testMsg = {1, 2, 3, 4}; auto service = ExecutorMessengerService::GetInstance(); diff --git a/test/unittest/inner_api/src/widget_callback_proxy_test.cpp b/test/unittest/services/src/hisysevent_adapter_test.cpp similarity index 41% rename from test/unittest/inner_api/src/widget_callback_proxy_test.cpp rename to test/unittest/services/src/hisysevent_adapter_test.cpp index 80b9c60c1fddcf2400b85680294891ca1c386d57..6f8a9bb69ad6681280f07dae50569d69233d92ac 100644 --- a/test/unittest/inner_api/src/widget_callback_proxy_test.cpp +++ b/test/unittest/services/src/hisysevent_adapter_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,12 +13,18 @@ * limitations under the License. */ -#include "widget_callback_proxy_test.h" +#include "hisysevent_adapter_test.h" -#include "iam_ptr.h" -#include "mock_remote_object.h" -#include "widget_callback_proxy.h" -#include "user_auth_interface.h" +#include "hisysevent_adapter.h" + +#include + +#include "hisysevent.h" +#include "iam_logger.h" +#include "iam_para2str.h" +#include "iam_time.h" + +#define LOG_TAG "USER_AUTH_SA" namespace OHOS { namespace UserIam { @@ -26,40 +32,40 @@ namespace UserAuth { using namespace testing; using namespace testing::ext; -void WidgetCallbackProxyTest::SetUpTestCase() +void HiSysEventAdapterTest::SetUpTestCase() { } -void WidgetCallbackProxyTest::TearDownTestCase() +void HiSysEventAdapterTest::TearDownTestCase() { } -void WidgetCallbackProxyTest::SetUp() +void HiSysEventAdapterTest::SetUp() { } -void WidgetCallbackProxyTest::TearDown() +void HiSysEventAdapterTest::TearDown() { } -HWTEST_F(WidgetCallbackProxyTest, WidgetCallbackStubOnRemoteRequest001, TestSize.Level0) +HWTEST_F(HiSysEventAdapterTest, ReportRemoteExecuteProcTest001, TestSize.Level3) { - sptr obj(new (std::nothrow) MockRemoteObject()); - EXPECT_NE(obj, nullptr); - EXPECT_CALL(*obj, SendRequest(_, _, _, _)) - .WillOnce( - [](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - EXPECT_EQ(code, UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND); - return OHOS::NO_ERROR; - } - ); + RemoteExecuteTrace trace = {}; + EXPECT_NO_THROW(ReportRemoteExecuteProc(trace)); +} - auto proxy = Common::MakeShared(obj); - EXPECT_NE(proxy, nullptr); +HWTEST_F(HiSysEventAdapterTest, ReportSaLoadDriverFailureTest001, TestSize.Level3) +{ + SaLoadDriverFailureTrace trace = {}; + EXPECT_NO_THROW(ReportSaLoadDriverFailure(trace)); +} - std::string cmdData = "cmd"; - proxy->SendCommand(cmdData); +HWTEST_F(HiSysEventAdapterTest, ReportIsCredentialEnrolledMismatchTest001, TestSize.Level3) +{ + IsCredentialEnrolledMismatchTrace trace = {}; + EXPECT_NO_THROW(ReportIsCredentialEnrolledMismatch(trace)); } + } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/services/src/ipc_common_test.cpp b/test/unittest/services/src/ipc_common_test.cpp index 1cf3d02b9c4d933651558bc210a8eeb5d434e390..3ea291f6082bd08565f7759e4d21b1fb1a3ab4c5 100644 --- a/test/unittest/services/src/ipc_common_test.cpp +++ b/test/unittest/services/src/ipc_common_test.cpp @@ -17,9 +17,10 @@ #include "widget_schedule_node_impl.h" #include +#include "iam_callback_proxy.h" #include "iam_check.h" #include "widget_json.h" -#include "widget_callback_interface.h" +#include "iwidget_callback.h" #include "mock_authentication.h" #include "mock_context.h" @@ -28,7 +29,6 @@ #include "mock_resource_node.h" #include "mock_schedule_node.h" #include "schedule_node_impl.h" -#include "user_auth_callback_proxy.h" #include "widget_schedule_node.h" diff --git a/test/unittest/services/src/remote_auth_context_test.cpp b/test/unittest/services/src/remote_auth_context_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7e42d31af31b5ec9ea915869d11c1ac05a461976 --- /dev/null +++ b/test/unittest/services/src/remote_auth_context_test.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "remote_auth_context_test.h" + +#include "attributes.h" +#include "context_pool.h" +#include "context_callback_impl.h" +#include "simple_auth_context.h" +#include "iam_common_defines.h" +#include "iam_logger.h" +#include "iam_ptr.h" +#include "remote_auth_context.h" +#include "remote_auth_invoker_context.h" +#include "remote_iam_callback.h" +#include "context_appstate_observer.h" +#include "auth_widget_helper.h" +#include "remote_auth_service.h" +#include "mock_context.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +using namespace testing; +using namespace testing::ext; + +void RemoteAuthContextTest::SetUpTestCase() +{ +} + +void RemoteAuthContextTest::TearDownTestCase() +{ +} + +void RemoteAuthContextTest::SetUp() +{ +} + +void RemoteAuthContextTest::TearDown() +{ +} + +HWTEST_F(RemoteAuthContextTest, RemoteAuthContextTest, TestSize.Level0) +{ + IAM_LOGI("RemoteAuthContextTest start"); + uint64_t contextId = 100; + std::shared_ptr auth; + RemoteAuthContextParam param; + param.authType = ALL; + std::string connectionName = "test"; + std::string collectorNetworkId = "1"; + param.connectionName = connectionName; + param.collectorNetworkId = collectorNetworkId; + param.executorInfoMsg = {}; + std::shared_ptr contextCallback = Common::MakeShared(); + auto remoteAuthContext1 = Common::MakeShared( + contextId, auth, param, contextCallback + ); + EXPECT_NE(remoteAuthContext1, nullptr); + std::vector executorInfoMsg = {7, 8, 9}; + param.executorInfoMsg = executorInfoMsg; + auto remoteAuthContext2 = Common::MakeShared( + contextId, auth, param, contextCallback + ); + EXPECT_NE(remoteAuthContext2, nullptr); + bool needSetupConnection = true; + std::optional cancelTimerId = 10; + remoteAuthContext2->cancelTimerId_ = cancelTimerId; + remoteAuthContext2->needSetupConnection_ = needSetupConnection; + IAM_LOGI("RemoteAuthContextTest end"); +} + +HWTEST_F(RemoteAuthContextTest, OnStartTest, TestSize.Level0) +{ + IAM_LOGI("OnStartTest start"); + uint64_t contextId = 100; + std::shared_ptr auth; + RemoteAuthContextParam param; + param.authType = ALL; + std::string connectionName = "test2"; + std::string collectorNetworkId = "2"; + param.connectionName = connectionName; + param.collectorNetworkId = collectorNetworkId; + param.executorInfoMsg = {}; + std::shared_ptr contextCallback = Common::MakeShared(); + std::vector executorInfoMsg = {7, 8, 9}; + param.executorInfoMsg = executorInfoMsg; + auto remoteAuthContext = Common::MakeShared( + contextId, auth, param, contextCallback + ); + EXPECT_NE(remoteAuthContext, nullptr); + bool result = remoteAuthContext->OnStart(); + EXPECT_EQ(result, false); + bool needSetupConnection = true; + std::optional cancelTimerId = 10; + remoteAuthContext->cancelTimerId_ = cancelTimerId; + remoteAuthContext->needSetupConnection_ = needSetupConnection; + result = remoteAuthContext->OnStart(); + EXPECT_EQ(result, true); + IAM_LOGI("OnStartTest end"); +} + +HWTEST_F(RemoteAuthContextTest, StartAuthDelayedTest, TestSize.Level1) +{ + IAM_LOGI("StartAuthDelayedTest start"); + uint64_t contextId = 100; + std::shared_ptr auth; + RemoteAuthContextParam param; + param.authType = ALL; + std::string connectionName = "test3"; + std::string collectorNetworkId = "3"; + param.connectionName = connectionName; + param.collectorNetworkId = collectorNetworkId; + param.executorInfoMsg = {}; + std::shared_ptr contextCallback = Common::MakeShared(); + std::vector executorInfoMsg = {6, 8, 9}; + param.executorInfoMsg = executorInfoMsg; + auto remoteAuthContext = Common::MakeShared( + contextId, auth, param, contextCallback + ); + EXPECT_NE(remoteAuthContext, nullptr); + bool needSetupConnection = true; + remoteAuthContext->needSetupConnection_ = needSetupConnection; + remoteAuthContext->OnStart(); + EXPECT_NO_THROW(remoteAuthContext->StartAuthDelayed()); + IAM_LOGI("StartAuthDelayedTest end"); +} + +HWTEST_F(RemoteAuthContextTest, SendQueryExecutorInfoMsgTest, TestSize.Level2) +{ + IAM_LOGI("SendQueryExecutorInfoMsgTest start"); + uint64_t contextId = 100; + std::shared_ptr auth; + RemoteAuthContextParam param; + param.authType = ALL; + std::string connectionName = "test4"; + std::string collectorNetworkId = "4"; + param.connectionName = connectionName; + param.collectorNetworkId = collectorNetworkId; + param.executorInfoMsg = {}; + std::shared_ptr contextCallback = Common::MakeShared(); + std::vector executorInfoMsg = {6, 8, 7}; + param.executorInfoMsg = executorInfoMsg; + auto remoteAuthContext = Common::MakeShared( + contextId, auth, param, contextCallback + ); + EXPECT_NE(remoteAuthContext, nullptr); + bool needSetupConnection = true; + remoteAuthContext->needSetupConnection_ = needSetupConnection; + bool result = remoteAuthContext->SendQueryExecutorInfoMsg(); + EXPECT_EQ(result, false); + IAM_LOGI("SendQueryExecutorInfoMsgTest end"); +} + +HWTEST_F(RemoteAuthContextTest, OnConnectStatusTest, TestSize.Level0) +{ + IAM_LOGI("OnConnectStatusTest start"); + uint64_t contextId = 100; + std::shared_ptr auth; + RemoteAuthContextParam param; + param.authType = ALL; + std::string connectionName = "test5"; + std::string collectorNetworkId = "5"; + param.connectionName = connectionName; + param.collectorNetworkId = collectorNetworkId; + param.executorInfoMsg = {}; + std::shared_ptr contextCallback = Common::MakeShared(); + std::vector executorInfoMsg = {6, 5, 7}; + param.executorInfoMsg = executorInfoMsg; + auto remoteAuthContext = Common::MakeShared( + contextId, auth, param, contextCallback + ); + EXPECT_NO_THROW(remoteAuthContext->OnConnectStatus(connectionName, ConnectStatus::DISCONNECTED)); + EXPECT_NO_THROW(remoteAuthContext->OnConnectStatus(connectionName, ConnectStatus::CONNECTED)); + IAM_LOGI("OnConnectStatusTest end"); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS + \ No newline at end of file diff --git a/test/unittest/services/src/remote_auth_invoker_context_test.cpp b/test/unittest/services/src/remote_auth_invoker_context_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f6e17f5d20447db2e2cdce8bc2283de70426f31e --- /dev/null +++ b/test/unittest/services/src/remote_auth_invoker_context_test.cpp @@ -0,0 +1,145 @@ + +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "remote_auth_invoker_context_test.h" + +#include "attributes.h" +#include "context_pool.h" +#include "context_callback_impl.h" +#include "simple_auth_context.h" +#include "iam_common_defines.h" +#include "iam_logger.h" +#include "iam_ptr.h" +#include "remote_auth_context.h" +#include "remote_auth_invoker_context.h" +#include "remote_iam_callback.h" +#include "context_appstate_observer.h" +#include "auth_widget_helper.h" +#include "remote_auth_service.h" +#include "mock_context.h" +#include "mock_iuser_auth_interface.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +using namespace testing; +using namespace testing::ext; + +void RemoteAuthInvokerContextTest::SetUpTestCase() +{ +} + +void RemoteAuthInvokerContextTest::TearDownTestCase() +{ +} + +void RemoteAuthInvokerContextTest::SetUp() +{ +} + +void RemoteAuthInvokerContextTest::TearDown() +{ +} + +HWTEST_F(RemoteAuthInvokerContextTest, OnMessageTest, TestSize.Level1) +{ + IAM_LOGI("OnMessageTest start"); + uint64_t contextId = 100; + AuthParamInner authParam = {}; + RemoteAuthInvokerContextParam param = {}; + std::string connectionName = "test5"; + std::string collectorNetworkId = "5"; + std::shared_ptr contextCallback = Common::MakeShared(); + auto remoteAuthInvokerContext = Common::MakeShared( + contextId, authParam, param, contextCallback + ); + std::string srcEndPoint = "start"; + auto request = Common::MakeShared(); + auto reply = Common::MakeShared(); + request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_TIP); + EXPECT_NO_THROW(remoteAuthInvokerContext->OnMessage(connectionName, srcEndPoint, request, reply)); + request->SetInt32Value(Attributes::ATTR_MSG_TYPE, SEND_REMOTE_AUTH_RESULT); + EXPECT_NO_THROW(remoteAuthInvokerContext->OnMessage(connectionName, srcEndPoint, request, reply)); + request->SetInt32Value(Attributes::ATTR_MSG_TYPE, START_REMOTE_AUTH); + std::optional cancelTimerId = 10; + remoteAuthInvokerContext->cancelTimerId_ = cancelTimerId; + EXPECT_NO_THROW(remoteAuthInvokerContext->OnMessage(connectionName, srcEndPoint, request, reply)); + IAM_LOGI("OnMessageTest end"); +} + +HWTEST_F(RemoteAuthInvokerContextTest, OnConnectStatusTest, TestSize.Level1) +{ + IAM_LOGI("OnConnectStatusTest start"); + uint64_t contextId = 100; + AuthParamInner authParam = {}; + RemoteAuthInvokerContextParam param = {}; + std::string connectionName = "test6"; + std::string collectorNetworkId = "6"; + std::shared_ptr contextCallback = Common::MakeShared(); + auto remoteAuthInvokerContext = Common::MakeShared( + contextId, authParam, param, contextCallback + ); + EXPECT_NO_THROW(remoteAuthInvokerContext->OnConnectStatus(connectionName, ConnectStatus::DISCONNECTED)); + EXPECT_NO_THROW(remoteAuthInvokerContext->OnConnectStatus(connectionName, ConnectStatus::CONNECTED)); + IAM_LOGI("OnConnectStatusTest end"); +} + +HWTEST_F(RemoteAuthInvokerContextTest, ProcAuthResultMsgInnerTest, TestSize.Level1) +{ + IAM_LOGI("ProcAuthResultMsgInner start"); + uint64_t contextId = 100; + AuthParamInner authParam = {}; + RemoteAuthInvokerContextParam param = {}; + std::string connectionName = "test7"; + std::string collectorNetworkId = "7"; + std::shared_ptr contextCallback = Common::MakeShared(); + auto remoteAuthInvokerContext = Common::MakeShared( + contextId, authParam, param, contextCallback + ); + auto message = Common::MakeShared(); + message->SetInt32Value(Attributes::ATTR_RESULT, ResultCode::GENERAL_ERROR); + message->SetInt32Value(Attributes::ATTR_SIGNED_AUTH_RESULT, true); + int32_t resultCode; + Attributes attr; + auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); + EXPECT_NE(mockHdi, nullptr); + EXPECT_CALL(*mockHdi, GetAuthResultFromMessage(_, _, _)) + .WillOnce([](const std::string &remoteUdid, const std::vector &message, + HdiAuthResultInfo &authResultInfo) { + authResultInfo.result = ResultCode::FAIL; + return 0; + }) + .WillOnce([](const std::string &remoteUdid, const std::vector &message, + HdiAuthResultInfo &authResultInfo) { + authResultInfo.result = ResultCode::LOCKED; + return 0; + }) + .WillRepeatedly([](const std::string &remoteUdid, const std::vector &message, + HdiAuthResultInfo &authResultInfo) { + authResultInfo.result = ResultCode::SUCCESS; + return 0; + }); + EXPECT_NO_THROW(remoteAuthInvokerContext->ProcAuthResultMsgInner(*message, resultCode, attr)); + EXPECT_NO_THROW(remoteAuthInvokerContext->ProcAuthResultMsgInner(*message, resultCode, attr)); + EXPECT_NO_THROW(remoteAuthInvokerContext->ProcAuthResultMsgInner(*message, resultCode, attr)); + IAM_LOGI("ProcAuthResultMsgInner end"); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS + \ No newline at end of file diff --git a/test/unittest/services/src/resource_node_test.cpp b/test/unittest/services/src/resource_node_test.cpp index 0283ec118b95455467801c0b63eb5aa175ac41ec..31bcbfd6fdb7ddecf1ad8dcc7c4ee7492287da31 100644 --- a/test/unittest/services/src/resource_node_test.cpp +++ b/test/unittest/services/src/resource_node_test.cpp @@ -121,7 +121,7 @@ HWTEST_F(ResourceNodeTest, ResourceNodeTest001, TestSize.Level0) ExecutorRegisterInfo info = {}; std::vector templateIdList; std::vector fwkPublicKey; - std::shared_ptr testCallback = nullptr; + std::shared_ptr testCallback = nullptr; auto node = ResourceNode::MakeNewResource(info, testCallback, templateIdList, fwkPublicKey); EXPECT_NE(node, nullptr); diff --git a/test/unittest/services/src/soft_bus_base_socket_test.cpp b/test/unittest/services/src/soft_bus_base_socket_test.cpp index 6603c1310494611ad0fcc4310d29ded33c477a5c..2747945695ec39d68e89ca35793141c724b8985e 100644 --- a/test/unittest/services/src/soft_bus_base_socket_test.cpp +++ b/test/unittest/services/src/soft_bus_base_socket_test.cpp @@ -126,52 +126,192 @@ HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestRemoveMsgCallback, TestSize delete baseSocket; } -HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetMsgCallback, TestSize.Level0) +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetConnectName, TestSize.Level0) { int32_t socketId = 1; BaseSocketTest *baseSocket = new BaseSocketTest(socketId); uint32_t messageSeq = 123; + const std::string connectionName = "connectionName"; + MsgCallback callback; + uint32_t timerId = 456; + BaseSocket::CallbackInfo callbackInfo = { + .connectionName = connectionName, + .msgCallback = callback, + .timerId = timerId, + .sendTime = std::chrono::steady_clock::now() + }; + baseSocket->callbackMap_.insert(std::pair(messageSeq, callbackInfo)); + EXPECT_NO_THROW(baseSocket->BaseSocket::GetConnectionName(messageSeq)); + EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq)); + delete baseSocket; +} + +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetMsgCallback_001, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + uint32_t messageSeq = 123; + const std::string connectionName = "connectionName"; + MsgCallback callback; + uint32_t timerId = 456; + BaseSocket::CallbackInfo callbackInfo = { + .connectionName = connectionName, + .msgCallback = callback, + .timerId = timerId, + .sendTime = std::chrono::steady_clock::now() + }; + baseSocket->callbackMap_.insert(std::pair(messageSeq, callbackInfo)); EXPECT_NO_THROW(baseSocket->GetMsgCallback(messageSeq)); + EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq)); delete baseSocket; } -HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestPrintTransferDuration, TestSize.Level0) +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestPrintTransferDuration_001, TestSize.Level0) { int32_t socketId = 1; BaseSocketTest *baseSocket = new BaseSocketTest(socketId); uint32_t messageSeq = 123; + const std::string connectionName = "connectionName"; + MsgCallback callback; + uint32_t timerId = 456; + BaseSocket::CallbackInfo callbackInfo = { + .connectionName = connectionName, + .msgCallback = callback, + .timerId = timerId, + .sendTime = std::chrono::steady_clock::now() + }; + baseSocket->callbackMap_.insert(std::pair(messageSeq, callbackInfo)); EXPECT_NO_THROW(baseSocket->PrintTransferDuration(messageSeq)); + EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq)); delete baseSocket; } -HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetReplyTimer, TestSize.Level0) +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetReplyTimer_001, TestSize.Level0) { int32_t socketId = 1; BaseSocketTest *baseSocket = new BaseSocketTest(socketId); uint32_t messageSeq = 123; + const std::string connectionName = "connectionName"; + MsgCallback callback; + uint32_t timerId = 456; + BaseSocket::CallbackInfo callbackInfo = { + .connectionName = connectionName, + .msgCallback = callback, + .timerId = timerId, + .sendTime = std::chrono::steady_clock::now() + }; + baseSocket->callbackMap_.insert(std::pair(messageSeq, callbackInfo)); EXPECT_NO_THROW(baseSocket->GetReplyTimer(messageSeq)); + EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq)); delete baseSocket; } -HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStartReplyTimer, TestSize.Level0) +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStartReplyTimer_001, TestSize.Level0) { int32_t socketId = 1; BaseSocketTest *baseSocket = new BaseSocketTest(socketId); uint32_t messageSeq = 123; + const std::string connectionName = "connectionName"; + MsgCallback callback; + uint32_t timerId = 456; + BaseSocket::CallbackInfo callbackInfo = { + .connectionName = connectionName, + .msgCallback = callback, + .timerId = timerId, + .sendTime = std::chrono::steady_clock::now() + }; + baseSocket->callbackMap_.insert(std::pair(messageSeq, callbackInfo)); EXPECT_NO_THROW(baseSocket->StartReplyTimer(messageSeq)); + EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq)); delete baseSocket; } -HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStopReplyTimer, TestSize.Level0) +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStopReplyTimer_001, TestSize.Level0) { int32_t socketId = 1; BaseSocketTest *baseSocket = new BaseSocketTest(socketId); uint32_t messageSeq = 123; + const std::string connectionName = "connectionName"; + MsgCallback callback; + uint32_t timerId = 456; + BaseSocket::CallbackInfo callbackInfo = { + .connectionName = connectionName, + .msgCallback = callback, + .timerId = timerId, + .sendTime = std::chrono::steady_clock::now() + }; + baseSocket->callbackMap_.insert(std::pair(messageSeq, callbackInfo)); EXPECT_NO_THROW(baseSocket->StopReplyTimer(messageSeq)); + EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq)); delete baseSocket; } -HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestReplyTimerTimeOut, TestSize.Level0) +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestReplyTimerTimeOut_001, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + uint32_t messageSeq = 123; + const std::string connectionName = "connectionName"; + MsgCallback callback; + uint32_t timerId = 456; + BaseSocket::CallbackInfo callbackInfo = { + .connectionName = connectionName, + .msgCallback = callback, + .timerId = timerId, + .sendTime = std::chrono::steady_clock::now() + }; + baseSocket->callbackMap_.insert(std::pair(messageSeq, callbackInfo)); + EXPECT_NO_THROW(baseSocket->ReplyTimerTimeOut(messageSeq)); + EXPECT_NO_THROW(baseSocket->RemoveMsgCallback(messageSeq)); + delete baseSocket; +} + +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetMsgCallback_002, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + uint32_t messageSeq = 123; + EXPECT_NO_THROW(baseSocket->GetMsgCallback(messageSeq)); + delete baseSocket; +} + +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestPrintTransferDuration_002, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + uint32_t messageSeq = 123; + EXPECT_NO_THROW(baseSocket->PrintTransferDuration(messageSeq)); + delete baseSocket; +} + +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestGetReplyTimer_002, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + uint32_t messageSeq = 123; + EXPECT_NO_THROW(baseSocket->GetReplyTimer(messageSeq)); + delete baseSocket; +} + +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStartReplyTimer_002, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + uint32_t messageSeq = 123; + EXPECT_NO_THROW(baseSocket->StartReplyTimer(messageSeq)); + delete baseSocket; +} + +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestStopReplyTimer_002, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + uint32_t messageSeq = 123; + EXPECT_NO_THROW(baseSocket->StopReplyTimer(messageSeq)); + delete baseSocket; +} + +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestReplyTimerTimeOut_002, TestSize.Level0) { int32_t socketId = 1; BaseSocketTest *baseSocket = new BaseSocketTest(socketId); @@ -277,6 +417,18 @@ HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcessMessage_001, TestSiz delete baseSocket; } +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcessMessage_002, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + std::shared_ptr softBusMessage = Common::MakeShared(0, "", "", "", nullptr); + std::shared_ptr attributes = Common::MakeShared(); + ASSERT_NE(attributes, nullptr); + softBusMessage->messageVersion_ = DEFAULT_MESSAGE_VERSION + 1; + EXPECT_NO_THROW(baseSocket->ProcessMessage(softBusMessage, attributes)); + delete baseSocket; +} + HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_001, TestSize.Level0) { int32_t socketId = 1; @@ -369,6 +521,25 @@ HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_007, TestSi delete baseSocket; } +HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestProcDataReceive_008, TestSize.Level0) +{ + int32_t socketId = 1; + BaseSocketTest *baseSocket = new BaseSocketTest(socketId); + const std::string connectionName = "connectionName"; + const std::string srcEndPoint = "srcEndPoint"; + const std::string destEndPoint = "destEndPoint"; + std::shared_ptr attributes = Common::MakeShared(); + ASSERT_NE(attributes, nullptr); + attributes->SetInt32Value(Attributes::ATTR_MSG_TYPE, 1); + attributes->SetBoolValue(Attributes::ATTR_MSG_ACK, true); + std::shared_ptr softBusMessage = Common::MakeShared(0, connectionName, srcEndPoint, + destEndPoint, attributes); + softBusMessage->isAck_ = true; + ResultCode result = baseSocket->ProcDataReceive(socketId, softBusMessage); + ASSERT_EQ(result, 2); + delete baseSocket; +} + HWTEST_F(SoftBusBaseSocketTest, SoftBusBaseSocketTestParseMessage_004, TestSize.Level0) { std::shared_ptr softBusMessage = Common::MakeShared(0, "", "", "", nullptr); diff --git a/test/unittest/services/src/soft_bus_manager_test.cpp b/test/unittest/services/src/soft_bus_manager_test.cpp index 78a3e9d3bb79a48531ceec7fe2899adb44f7f4cd..ae797bf21caeabe4128b5b2c144cbf9b0846c9d3 100644 --- a/test/unittest/services/src/soft_bus_manager_test.cpp +++ b/test/unittest/services/src/soft_bus_manager_test.cpp @@ -229,8 +229,49 @@ HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnServerBytes_003, TestSize.Level SoftBusManager::GetInstance().ClearServerSocket(); SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); + SoftBusManager::GetInstance().OnClientBytes(socketId, nullptr, dataLen); + SoftBusManager::GetInstance().OnServerBytes(socketId, nullptr, dataLen); }); } + +HWTEST_F(SoftBusManagerTest, SoftBusManagerTestOnClientBytes_001, TestSize.Level0) +{ + int32_t socketId = -2; + const void *data = new char[10]; + uint32_t dataLen = 3; + static const int32_t MAX_ONBYTES_RECEIVED_DATA_LEN = 1024 * 1024 * 10; + std::string connectionName = "testConnection1"; + const std::string networkId = "networkId1"; + EXPECT_NO_THROW({ + SoftBusManager::GetInstance().ClearServerSocket(); + SoftBusManager::GetInstance().OnClientBytes(socketId, data, dataLen); + SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); + }); + socketId = 0; + SoftBusManager::GetInstance().OnClientBytes(socketId, data, dataLen); + SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); + socketId = 100; + SoftBusManager::GetInstance().OnClientBytes(socketId, data, dataLen); + SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); + dataLen = 0; + SoftBusManager::GetInstance().OnClientBytes(socketId, data, dataLen); + SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); + dataLen = MAX_ONBYTES_RECEIVED_DATA_LEN + 1; + SoftBusManager::GetInstance().OnClientBytes(socketId, data, dataLen); + SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); + dataLen = 3; + SoftBusManager::GetInstance().OnClientBytes(socketId, data, dataLen); + SoftBusManager::GetInstance().OnServerBytes(socketId, data, dataLen); + while (connectionName.length() <= 257) { + connectionName += "testConnection1"; + } + SoftBusManager::GetInstance().ClientSocketInit(connectionName, networkId); + SoftBusManager::GetInstance().DoServiceSocketInit(); + SoftBusManager::GetInstance().RegistDeviceManagerListener(); + SoftBusManager::GetInstance().RegistDeviceManagerListener(); + SoftBusManager::GetInstance().DeviceInit(); + SoftBusManager::GetInstance().DeviceUnInit(); +} } // namespace UserAuth } // namespace UserIam } // namespace OHOS diff --git a/test/unittest/services/src/system_ability_listener_test.cpp b/test/unittest/services/src/system_ability_listener_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8029e05a7c996bd21e975c7af053b440112ac684 --- /dev/null +++ b/test/unittest/services/src/system_ability_listener_test.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "system_ability_listener_test.h" + +#include "system_ability_listener.h" + +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +using namespace testing; +using namespace testing::ext; + +void SystemAbilityListenerTest::SetUpTestCase() +{ +} + +void SystemAbilityListenerTest::TearDownTestCase() +{ +} + +void SystemAbilityListenerTest::SetUp() +{ +} + +void SystemAbilityListenerTest::TearDown() +{ +} + +HWTEST_F(SystemAbilityListenerTest, OnAddSystemAbilityTest001, TestSize.Level3) +{ + std::string name = ""; + int32_t systemAbilityId = 1; + SystemAbilityListener listener(name, systemAbilityId, []() {}, []() {}); + + std::string deviceId = ""; + EXPECT_NO_THROW(listener.OnAddSystemAbility(systemAbilityId, deviceId)); +} + +HWTEST_F(SystemAbilityListenerTest, OnAddSystemAbilityTest002, TestSize.Level3) +{ + std::string name = ""; + int32_t systemAbilityId = 1; + SystemAbilityListener listener(name, systemAbilityId, []() {}, []() {}); + + std::string deviceId = ""; + int32_t otherSystemAbilityId = 2; + EXPECT_NO_THROW(listener.OnAddSystemAbility(otherSystemAbilityId, deviceId)); +} + +HWTEST_F(SystemAbilityListenerTest, OnRemoveSystemAbilityTest001, TestSize.Level3) +{ + std::string name = ""; + int32_t systemAbilityId = 1; + SystemAbilityListener listener(name, systemAbilityId, []() {}, []() {}); + + std::string deviceId = ""; + int32_t otherSystemAbilityId = 2; + EXPECT_NO_THROW(listener.OnRemoveSystemAbility(otherSystemAbilityId, deviceId)); +} + +HWTEST_F(SystemAbilityListenerTest, OnRemoveSystemAbilityTest002, TestSize.Level3) +{ + std::string name = ""; + int32_t systemAbilityId = 1; + SystemAbilityListener listener(name, systemAbilityId, []() {}, []() {}); + + std::string deviceId = ""; + EXPECT_NO_THROW(listener.OnRemoveSystemAbility(systemAbilityId, deviceId)); +} + +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS diff --git a/test/unittest/services/src/system_param_manager_test.cpp b/test/unittest/services/src/system_param_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1d10bacc53bb0905c9b631355be5b077905e7a73 --- /dev/null +++ b/test/unittest/services/src/system_param_manager_test.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "system_param_manager_test.h" + +#include "system_param_manager.h" + +#include "iam_logger.h" +#include "securec.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +using namespace testing; +using namespace testing::ext; + +void SystemParamManagerTest::SetUpTestCase() +{ +} + +void SystemParamManagerTest::TearDownTestCase() +{ +} + +void SystemParamManagerTest::SetUp() +{ +} + +void SystemParamManagerTest::TearDown() +{ +} + +HWTEST_F(SystemParamManagerTest, SetAndGetParamTest_001, TestSize.Level0) +{ + std::string oldParamStr = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, TRUE_STR); + bool newParamVal = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR) == + TRUE_STR; + EXPECT_EQ(newParamVal, true); + SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, oldParamStr); +} + +HWTEST_F(SystemParamManagerTest, SetAndGetParamTest_002, TestSize.Level0) +{ + const std::string UNKNOWN_PARAM = "useriam.unknownParam"; + bool getParamVal = SystemParamManager::GetInstance().GetParam(UNKNOWN_PARAM, FALSE_STR) == + TRUE_STR; + EXPECT_EQ(getParamVal, false); + SystemParamManager::GetInstance().SetParam(UNKNOWN_PARAM, FALSE_STR); + SystemParamManager::GetInstance().SetParam(UNKNOWN_PARAM, FALSE_STR); +} + +HWTEST_F(SystemParamManagerTest, SetParamTwiceTest, TestSize.Level0) +{ + std::string oldParamStr = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + SystemParamManager::GetInstance().SetParamTwice(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR, TRUE_STR); + bool newParamVal = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR) == + TRUE_STR; + EXPECT_EQ(newParamVal, true); + SystemParamManager::GetInstance().SetParamTwice(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR, TRUE_STR); + SystemParamManager::GetInstance().SetParamTwice(IS_CREDENTIAL_CHECKED_KEY, TRUE_STR, TRUE_STR); + SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, oldParamStr); +} + +HWTEST_F(SystemParamManagerTest, WatchParamTest_001, TestSize.Level0) +{ + SystemParamManager::GetInstance().WatchParam(IS_CREDENTIAL_CHECKED_KEY, [](const std::string &value) { + IAM_LOGI("%{public}s changed, value %{public}s", IS_CREDENTIAL_CHECKED_KEY, value.c_str()); + }); + SystemParamManager::GetInstance().WatchParam(IS_CREDENTIAL_CHECKED_KEY, [](const std::string &value) { + IAM_LOGI("%{public}s changed again, value %{public}s", IS_CREDENTIAL_CHECKED_KEY, value.c_str()); + }); + std::string oldParamStr = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, TRUE_STR); + bool newParamVal = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR) == + TRUE_STR; + EXPECT_EQ(newParamVal, true); + SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, oldParamStr); +} + +HWTEST_F(SystemParamManagerTest, WatchParamTest_002, TestSize.Level0) +{ + SystemParamManager::GetInstance().WatchParam(IS_CREDENTIAL_CHECKED_KEY, [](const std::string &value) { + IAM_LOGI("%{public}s changed, value %{public}s", IS_CREDENTIAL_CHECKED_KEY, value.c_str()); + }); + SystemParamManager::GetInstance().WatchParam(IS_CREDENTIAL_CHECKED_KEY, [](const std::string &value) { + IAM_LOGI("%{public}s changed, value %{public}s", IS_CREDENTIAL_CHECKED_KEY, value.c_str()); + }); + std::string oldParamStr = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, TRUE_STR); + bool newParamVal = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR) == + TRUE_STR; + EXPECT_EQ(newParamVal, true); + SystemParamManager::GetInstance().SetParam(IS_CREDENTIAL_CHECKED_KEY, oldParamStr); +} + +HWTEST_F(SystemParamManagerTest, OnParamChangeTest_001, TestSize.Level0) +{ + std::string oldParamStr = SystemParamManager::GetInstance().GetParam(IS_CREDENTIAL_CHECKED_KEY, FALSE_STR); + EXPECT_NO_THROW(SystemParamManager::GetInstance().OnParamChange(IS_CREDENTIAL_CHECKED_KEY, TRUE_STR)); + EXPECT_NO_THROW(SystemParamManager::GetInstance().OnParamChange(IS_CREDENTIAL_CHECKED_KEY, oldParamStr)); +} + +HWTEST_F(SystemParamManagerTest, OnParamChangeTest_002, TestSize.Level0) +{ + const std::string UNKNOWN_PARAM_CHANGE = "useriam.unknownParamChange"; + EXPECT_NO_THROW(SystemParamManager::GetInstance().OnParamChange(UNKNOWN_PARAM_CHANGE, TRUE_STR)); + EXPECT_NO_THROW(SystemParamManager::GetInstance().OnParamChange(UNKNOWN_PARAM_CHANGE, FALSE_STR)); +} +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS + \ No newline at end of file diff --git a/test/unittest/services/src/auth_event_listener_manager_test.cpp b/test/unittest/services/src/thread_handler_impl_test.cpp similarity index 35% rename from test/unittest/services/src/auth_event_listener_manager_test.cpp rename to test/unittest/services/src/thread_handler_impl_test.cpp index 97f2b3fd53cd63cf94375bd3ef23f5dc160dee96..bb66061f7b28b388f0958dfc2a63d7f9a31ec11d 100644 --- a/test/unittest/services/src/auth_event_listener_manager_test.cpp +++ b/test/unittest/services/src/thread_handler_impl_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023 Huawei Device Co., Ltd. + * Copyright (C) 2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,11 +13,21 @@ * limitations under the License. */ -#include "auth_event_listener_manager_test.h" -#include "auth_event_listener_manager.h" +#include "thread_handler_impl_test.h" -#include "gtest/gtest.h" -#include "mock_auth_event_listener.h" +#include "thread_handler_impl.h" + +#include +#include +#include +#include + +#include "nocopyable.h" +#include "thread_handler_manager.h" + +#include "iam_logger.h" + +#define LOG_TAG "USER_AUTH_SA" namespace OHOS { namespace UserIam { @@ -25,41 +35,57 @@ namespace UserAuth { using namespace testing; using namespace testing::ext; -void AuthEventListenerManagerTest::SetUpTestCase() +void ThreadHandlerImplTest::SetUpTestCase() { } -void AuthEventListenerManagerTest::TearDownTestCase() +void ThreadHandlerImplTest::TearDownTestCase() { } -void AuthEventListenerManagerTest::SetUp() +void ThreadHandlerImplTest::SetUp() { } -void AuthEventListenerManagerTest::TearDown() +void ThreadHandlerImplTest::TearDown() { } -HWTEST_F(AuthEventListenerManagerTest, AuthEventListenerManagerTestAddAuthSuccessEventListener, TestSize.Level0) +HWTEST_F(ThreadHandlerImplTest, PostTaskTest001, TestSize.Level3) { - sptr testCallback = new MockAuthEventListener(); - AuthType authType = AuthType::PIN; - EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().AddAuthSuccessEventListener(authType, testCallback)); + std::string name = ""; + ThreadHandlerImpl impl(name, false); + EXPECT_NO_THROW(impl.PostTask([]() {})); } -HWTEST_F(AuthEventListenerManagerTest, AuthEventListenerManagerTestRemoveAuthSuccessEventListener, TestSize.Level0) +HWTEST_F(ThreadHandlerImplTest, PostTaskTest002, TestSize.Level3) { - sptr testCallback = new MockAuthEventListener(); - AuthType authType = AuthType::PIN; - EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().RemoveAuthSuccessEventListener(authType, testCallback)); + std::string name = ""; + ThreadHandlerImpl impl(name, true); + EXPECT_NO_THROW(impl.PostTask([]() {})); } -HWTEST_F(AuthEventListenerManagerTest, AuthEventListenerManagerTestRemoveDeathRecipient, TestSize.Level0) +HWTEST_F(ThreadHandlerImplTest, EnsureTaskTest001, TestSize.Level3) { - sptr testCallback = new MockAuthEventListener(); - EXPECT_NO_THROW(AuthEventListenerManager::GetInstance().RemoveDeathRecipient(testCallback)); + std::string name = ""; + ThreadHandlerImpl impl(name, true); + EXPECT_NO_THROW(impl.EnsureTask([]() {})); } + +HWTEST_F(ThreadHandlerImplTest, SuspendTest001, TestSize.Level3) +{ + std::string name = ""; + ThreadHandlerImpl impl(name, true); + EXPECT_NO_THROW(impl.Suspend()); +} + +HWTEST_F(ThreadHandlerImplTest, SuspendTest002, TestSize.Level3) +{ + std::string name = ""; + ThreadHandlerImpl impl(name, false); + EXPECT_NO_THROW(impl.Suspend()); +} + } // namespace UserAuth } // namespace UserIam -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/test/unittest/services/src/thread_handler_manager_test.cpp b/test/unittest/services/src/thread_handler_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..667e8dbbbe8a9c6046484b8187ef9faaf4063064 --- /dev/null +++ b/test/unittest/services/src/thread_handler_manager_test.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "thread_handler_manager_test.h" + +#include "thread_handler_manager.h" + +#include + +#include "iam_check.h" +#include "iam_logger.h" +#include "iam_ptr.h" +#include "thread_handler_impl.h" +#include "thread_handler_singleton_impl.h" + +#define LOG_TAG "USER_AUTH_SA" + +namespace OHOS { +namespace UserIam { +namespace UserAuth { +using namespace testing; +using namespace testing::ext; + +void ThreadHandlerManagerTest::SetUpTestCase() +{ +} + +void ThreadHandlerManagerTest::TearDownTestCase() +{ +} + +void ThreadHandlerManagerTest::SetUp() +{ +} + +void ThreadHandlerManagerTest::TearDown() +{ +} + +HWTEST_F(ThreadHandlerManagerTest, CreateThreadHandlerTest001, TestSize.Level3) +{ + std::string name = ""; + EXPECT_EQ(ThreadHandlerManager::GetInstance().CreateThreadHandler(name), true); + EXPECT_EQ(ThreadHandlerManager::GetInstance().CreateThreadHandler(name), false); +} + +HWTEST_F(ThreadHandlerManagerTest, DestroyThreadHandlerTest001, TestSize.Level3) +{ + std::string name = ""; + EXPECT_NO_THROW(ThreadHandlerManager::GetInstance().DestroyThreadHandler(name)); + + ThreadHandlerManager::GetInstance().CreateThreadHandler(name); + EXPECT_NO_THROW(ThreadHandlerManager::GetInstance().DestroyThreadHandler(name)); +} + +HWTEST_F(ThreadHandlerManagerTest, DestroyThreadHandlerTest002, TestSize.Level3) +{ + EXPECT_NO_THROW(ThreadHandlerManager::GetInstance().DestroyThreadHandler(SINGLETON_THREAD_NAME)); +} + +HWTEST_F(ThreadHandlerManagerTest, DeleteThreadHandlerTest002, TestSize.Level3) +{ + std::string name = ""; + ThreadHandlerManager::GetInstance().CreateThreadHandler(name); + EXPECT_NO_THROW(ThreadHandlerManager::GetInstance().DeleteThreadHandler(name)); +} + +HWTEST_F(ThreadHandlerManagerTest, GetThreadHandlerTest001, TestSize.Level3) +{ + std::string name = ""; + EXPECT_EQ(ThreadHandlerManager::GetInstance().GetThreadHandler(name), nullptr); +} + +HWTEST_F(ThreadHandlerManagerTest, PostTaskTest001, TestSize.Level3) +{ + std::string name = ""; + EXPECT_NO_THROW(ThreadHandlerManager::GetInstance().PostTask(name, []() {})); +} + +HWTEST_F(ThreadHandlerManagerTest, PostTaskTest002, TestSize.Level3) +{ + std::string name = ""; + ThreadHandlerManager::GetInstance().CreateThreadHandler(name); + EXPECT_NO_THROW(ThreadHandlerManager::GetInstance().PostTask(name, []() {})); +} + +} // namespace UserAuth +} // namespace UserIam +} // namespace OHOS diff --git a/test/unittest/services/src/ui_extension_ability_connection_test.cpp b/test/unittest/services/src/ui_extension_ability_connection_test.cpp index 5c3174108d1c544cceb67aab885aa2fd5aafb868..78badf587cdde1f967310e2af532ee3692e7ba76 100644 --- a/test/unittest/services/src/ui_extension_ability_connection_test.cpp +++ b/test/unittest/services/src/ui_extension_ability_connection_test.cpp @@ -18,12 +18,12 @@ #include +#include "iam_callback_proxy.h" #include "mock_authentication.h" #include "mock_context.h" #include "mock_remote_object.h" #include "mock_resource_node.h" #include "mock_schedule_node.h" -#include "user_auth_callback_proxy.h" using namespace testing; using namespace testing::ext; diff --git a/test/unittest/services/src/user_auth_service_test_part01.cpp b/test/unittest/services/src/user_auth_service_test_part01.cpp index ef4e4abe67bf7e8925b7233fca024e51278500b2..6adf70284908565cb6e76e34336ab9787b63b97f 100644 --- a/test/unittest/services/src/user_auth_service_test_part01.cpp +++ b/test/unittest/services/src/user_auth_service_test_part01.cpp @@ -22,7 +22,7 @@ #include "executor_messenger_service.h" #include "accesstoken_kit.h" -#include "mock_auth_event_listener.h" +#include "mock_event_listener.h" #include "mock_context.h" #include "mock_iuser_auth_interface.h" #include "mock_ipc_common.h" @@ -61,7 +61,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState001, TestSize.Level UserAuthService service; int32_t testApiVersion = 12; AuthType testAuthType = FACE; - EnrolledState testEnrolledState; + IpcEnrolledState testEnrolledState; uint16_t expectCredentialDigest = 23962; uint16_t expectCredentialCount = 1; auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -88,7 +88,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState002, TestSize.Level UserAuthService service; int32_t testApiVersion = 12; AuthType testAuthType = FACE; - EnrolledState testEnrolledState; + IpcEnrolledState testEnrolledState; uint16_t expectCredentialDigest = 0; uint16_t expectCredentialCount = 0; auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -106,7 +106,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState003, TestSize.Level UserAuthService service; int32_t testApiVersion = 10; AuthType testAuthType = FACE; - EnrolledState testEnrolledState; + IpcEnrolledState testEnrolledState; uint16_t expectCredentialDigest = 0; uint16_t expectCredentialCount = 0; IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -121,7 +121,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetEnrolledState004, TestSize.Level UserAuthService service; int32_t testApiVersion = 10; AuthType testAuthType = FACE; - EnrolledState testEnrolledState; + IpcEnrolledState testEnrolledState; uint16_t expectCredentialDigest = 0; uint16_t expectCredentialCount = 0; EXPECT_EQ(CHECK_PERMISSION_FAILED, service.GetEnrolledState(testApiVersion, testAuthType, testEnrolledState)); @@ -273,17 +273,19 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty001, TestSize.Level0) UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = PIN; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(new (std::nothrow) MockGetExecutorPropertyCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1); EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(2); - sptr callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -292,10 +294,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty002, TestSize.Level0) UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = PIN; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); @@ -328,8 +331,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty002, TestSize.Level0) EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(2); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -339,13 +344,15 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty003, TestSize.Level0) UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = PIN; - std::vector testKeys = {Attributes::ATTR_REMAIN_TIMES, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_REMAIN_TIMES, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); testKeys = {Attributes::ATTR_FREEZING_TIME, Attributes::ATTR_SIGNATURE}; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); testKeys = {Attributes::ATTR_NEXT_FAIL_LOCKOUT_DURATION, Attributes::ATTR_SIGNATURE}; service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); @@ -363,10 +370,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty003, TestSize.Level0) .WillOnce(Return(SUCCESS)); testCallback = sptr(new (std::nothrow) MockGetExecutorPropertyCallback()); EXPECT_NE(testCallback, nullptr); - EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); + EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(2); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -376,14 +386,15 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty004, TestSize.Level0) UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = PIN; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); - EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1); + EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(2); ON_CALL(*mockHdi, GetCredential) .WillByDefault( [](int32_t userId, int32_t authType, std::vector &infos) { @@ -409,10 +420,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty004, TestSize.Level0) .WillOnce(Return(SUCCESS)); testCallback = sptr(new (std::nothrow) MockGetExecutorPropertyCallback()); EXPECT_NE(testCallback, nullptr); - EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); + EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(2); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -422,10 +436,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty005, TestSize.Level0) UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = PIN; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); @@ -458,7 +473,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty005, TestSize.Level0) EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -468,15 +484,15 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty006, TestSize.Level0) UserAuthService service; int32_t testUserId = 123; AuthType testAuthType = FACE; - std::vector testKeys = { + std::vector testKeys = { Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE, Attributes::ATTR_NEXT_FAIL_LOCKOUT_DURATION }; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); - + sptr callbackInterface = testCallback; + int32_t ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1); @@ -508,7 +524,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty006, TestSize.Level0) EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + ret = service.GetProperty(testUserId, testAuthType, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -522,10 +539,12 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty001, TestSize.Level0) sptr testCallback(new (std::nothrow) MockSetExecutorPropertyCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnSetExecutorPropertyResult(_)).Times(2); - sptr callbackInterface = testCallback; - service.SetProperty(testUserId, testAuthType, testAttr, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.SetProperty(testUserId, testAuthType, testAttr.Serialize(), callbackInterface); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - service.SetProperty(testUserId, testAuthType, testAttr, callbackInterface); + ret = service.SetProperty(testUserId, testAuthType, testAttr.Serialize(), callbackInterface); + EXPECT_EQ(ret, SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -536,8 +555,9 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty002, TestSize.Level0) AuthType testAuthType = PIN; Attributes testAttr; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.SetProperty(testUserId, testAuthType, testAttr, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.SetProperty(testUserId, testAuthType, testAttr.Serialize(), callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto resourceNode = MockResourceNode::CreateWithExecuteIndex(2); EXPECT_NE(resourceNode, nullptr); @@ -552,8 +572,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty002, TestSize.Level0) EXPECT_CALL(*testCallback, OnSetExecutorPropertyResult(_)).Times(2); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.SetProperty(testUserId, testAuthType, testAttr, callbackInterface); - service.SetProperty(testUserId, testAuthType, testAttr, callbackInterface); + ret = service.SetProperty(testUserId, testAuthType, testAttr.Serialize(), callbackInterface); + EXPECT_EQ(ret, SUCCESS); + ret = service.SetProperty(testUserId, testAuthType, testAttr.Serialize(), callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -562,15 +584,17 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth001, TestSize.Level0) { UserAuthService service; int32_t testApiVersion = 9; - std::vector testChallenge = {1, 2, 3, 4}; - AuthType testAuthType = FACE; - AuthTrustLevel testAuthTrustLevel = ATL2; + IpcAuthParamInner ipcAuthParamInner = {}; + ipcAuthParamInner.challenge = {1, 2, 3, 4}; + ipcAuthParamInner.authType = FACE; + ipcAuthParamInner.authTrustLevel = ATL2; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_FAILURE); + return SUCCESS; } ); @@ -579,9 +603,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth001, TestSize.Level0) EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).WillOnce(Return(HDF_FAILURE)); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.Auth(testApiVersion, testChallenge, testAuthType, - testAuthTrustLevel, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -590,27 +615,31 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth002, TestSize.Level0) { UserAuthService service; int32_t testApiVersion = 9; - std::vector testChallenge = {1, 2, 3, 4}; - AuthType testAuthType = FACE; - AuthTrustLevel testAuthTrustLevel = ATL2; + IpcAuthParamInner ipcAuthParamInner = {}; + ipcAuthParamInner.challenge = {1, 2, 3, 4}; + ipcAuthParamInner.authType = FACE; + ipcAuthParamInner.authTrustLevel = ATL2; sptr testCallback(nullptr); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.Auth(testApiVersion, testChallenge, testAuthType, - testAuthTrustLevel, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); testCallback = sptr(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(2); - testAuthTrustLevel = static_cast(90000); + ipcAuthParamInner.authTrustLevel = static_cast(90000); callbackInterface = testCallback; - contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, TRUST_LEVEL_NOT_SUPPORT); EXPECT_EQ(contextId, 0); - testAuthType = PIN; - testAuthTrustLevel = ATL1; - contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + ipcAuthParamInner.authType = PIN; + ipcAuthParamInner.authTrustLevel = ATL1; + ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -619,31 +648,36 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth003, TestSize.Level0) { UserAuthService service; int32_t testApiVersion = 9; - std::vector testChallenge = {1, 2, 3, 4}; - AuthType testAuthType = PIN; - AuthTrustLevel testAuthTrustLevel = ATL2; + IpcAuthParamInner ipcAuthParamInner = {}; + ipcAuthParamInner.challenge = {1, 2, 3, 4}; + ipcAuthParamInner.authType = PIN; + ipcAuthParamInner.authTrustLevel = ATL2; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(4); - sptr callbackInterface = testCallback; - uint64_t contextId = service.Auth(testApiVersion, testChallenge, testAuthType, - testAuthTrustLevel, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); EXPECT_EQ(contextId, 0); - testAuthType = FACE; - contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + ipcAuthParamInner.authType = FACE; + ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); EXPECT_EQ(contextId, 0); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(2).WillRepeatedly(Return(NOT_ENROLLED)); - contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); testApiVersion = 8; - contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); @@ -695,7 +729,7 @@ static void MockForAuthResourceNode(std::shared_ptr &resourceN EXPECT_NE(finalResult, nullptr); std::vector scheduleResult = {1, 2, 3, 4}; EXPECT_TRUE(finalResult->SetUint8ArrayValue(Attributes::ATTR_RESULT, scheduleResult)); - EXPECT_EQ(messenger->Finish(testScheduleId, SUCCESS, finalResult), SUCCESS); + EXPECT_EQ(messenger->Finish(testScheduleId, SUCCESS, finalResult->Serialize()), SUCCESS); return SUCCESS; }); } @@ -704,20 +738,22 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth004, TestSize.Level0) { UserAuthService service; int32_t testApiVersion = 9; - std::vector testChallenge = {1, 2, 3, 4}; - AuthType testAuthType = FACE; - AuthTrustLevel testAuthTrustLevel = ATL2; + IpcAuthParamInner ipcAuthParamInner = {}; + ipcAuthParamInner.challenge = {1, 2, 3, 4}; + ipcAuthParamInner.authType = FACE; + ipcAuthParamInner.authTrustLevel = ATL2; std::shared_ptr context = nullptr; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [&context](int32_t result, const Attributes &extraInfo) { + [&context](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); if (context != nullptr) { context->Stop(); } + return SUCCESS; } ); @@ -731,8 +767,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth004, TestSize.Level0) EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); - sptr callbackInterface = testCallback; - service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.Auth(testApiVersion, ipcAuthParamInner, callbackInterface, contextId); + EXPECT_EQ(ret, SUCCESS); + EXPECT_NE(contextId, 0); promise.get_future().get(); EXPECT_TRUE(ResourceNodePool::Instance().Delete(60)); @@ -742,13 +781,15 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth004, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0) { UserAuthService service; - AuthParamInner authParam = { + IpcAuthParamInner authParam = { .userId = 125, .challenge = {1, 2, 3, 4}, .authType = FACE, .authTrustLevel = ATL2, }; - std::optional remoteAuthParam = std::nullopt; + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = false, + }; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -756,8 +797,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -765,17 +808,21 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser002, TestSize.Level0) { UserAuthService service; - AuthParamInner authParam = { + IpcAuthParamInner authParam = { .userId = 125, .challenge = {1, 2, 3, 4}, .authType = FACE, .authTrustLevel = ATL2, }; - std::optional remoteAuthParam = std::nullopt; + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = false, + }; sptr testCallback(nullptr); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); testCallback = sptr(new (std::nothrow) MockUserAuthCallback()); @@ -783,7 +830,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser002, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); authParam.authTrustLevel = static_cast(90000); callbackInterface = testCallback; - contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -791,13 +839,15 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser002, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) { UserAuthService service; - AuthParamInner authParam = { + IpcAuthParamInner authParam = { .userId = 125, .challenge = {1, 2, 3, 4}, .authType = FACE, .authTrustLevel = ATL2, }; - std::optional remoteAuthParam = std::nullopt; + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = false, + }; std::shared_ptr context = nullptr; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); @@ -805,21 +855,25 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, CHECK_PERMISSION_FAILED); + return SUCCESS; } ) .WillOnce( - [&context](int32_t result, const Attributes &extraInfo) { + [&context](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); if (context != nullptr) { context->Stop(); } + return SUCCESS; } ); - sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); EXPECT_EQ(contextId, 0); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); @@ -832,7 +886,9 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); - contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, SUCCESS); + EXPECT_NE(contextId, 0); promise.get_future().get(); EXPECT_TRUE(ResourceNodePool::Instance().Delete(60)); @@ -842,18 +898,17 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser003, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser004, TestSize.Level0) { UserAuthService service; - AuthParamInner authParam = { + IpcAuthParamInner authParam = { .userId = 125, .challenge = {1, 2, 3, 4}, .authType = FACE, .authTrustLevel = ATL2, }; - std::optional remoteAuthParam = {}; - RemoteAuthParam param = {}; - param.verifierNetworkId = "123"; - param.collectorNetworkId = "1233324321423412344134"; - remoteAuthParam = param; - EXPECT_EQ(remoteAuthParam.has_value(), true); + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = true, + .verifierNetworkId = "123", + .collectorNetworkId = "1233324321423412344134", + }; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -861,8 +916,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser004, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -870,18 +927,17 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser004, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser005, TestSize.Level0) { UserAuthService service; - AuthParamInner authParam = { + IpcAuthParamInner authParam = { .userId = 125, .challenge = {1, 2, 3, 4}, .authType = PIN, .authTrustLevel = ATL2, }; - std::optional remoteAuthParam = {}; - RemoteAuthParam param = {}; - param.verifierNetworkId = "123"; - param.collectorNetworkId = "1233324321423412344134"; - remoteAuthParam = param; - EXPECT_EQ(remoteAuthParam.has_value(), true); + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = true, + .verifierNetworkId = "123", + .collectorNetworkId = "1233324321423412344134", + }; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -889,8 +945,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser005, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -898,18 +956,17 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser005, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser006, TestSize.Level0) { UserAuthService service; - AuthParamInner authParam = { + IpcAuthParamInner authParam = { .userId = -1, .challenge = {1, 2, 3, 4}, .authType = PIN, .authTrustLevel = ATL2, }; - std::optional remoteAuthParam = {}; - RemoteAuthParam param = {}; - param.verifierNetworkId = "123"; - param.collectorNetworkId = "1233324321423412344134"; - remoteAuthParam = param; - EXPECT_EQ(remoteAuthParam.has_value(), true); + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = true, + .verifierNetworkId = "123", + .collectorNetworkId = "1233324321423412344134", + }; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -917,8 +974,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser006, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -926,19 +985,18 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser006, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser007, TestSize.Level0) { UserAuthService service; - AuthParamInner authParam = { + IpcAuthParamInner authParam = { .userId = -1, .challenge = {1, 2, 3, 4}, .authType = PIN, .authTrustLevel = ATL2, }; - std::optional remoteAuthParam = {}; - RemoteAuthParam param = {}; - param.verifierNetworkId = "123"; - param.collectorNetworkId = "1233324321423412344134"; - param.collectorTokenId = 123123; - remoteAuthParam = param; - EXPECT_EQ(remoteAuthParam.has_value(), true); + IpcRemoteAuthParam remoteAuthParam = { + .isHasRemoteAuthParam = true, + .verifierNetworkId = "123", + .collectorNetworkId = "1233324321423412344134", + .collectorTokenId = 123123, + }; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); @@ -946,12 +1004,50 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser007, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.AuthUser(authParam, remoteAuthParam, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.AuthUser(authParam, remoteAuthParam, callbackInterface, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } +HWTEST_F(UserAuthServiceTest, UserAuthServiceInitRemoteAuthParam_001, TestSize.Level0) +{ + UserAuthService service; + IpcRemoteAuthParam ipcRemoteAuthParam = { + .isHasVerifierNetworkId = true, + .isHasRemoteAuthParam = true, + .isHasCollectorNetworkId = true, + .isHasCollectorTokenId = true, + .verifierNetworkId = "123", + .collectorNetworkId = "1233324321423412344134", + .collectorTokenId = 123123, + }; + std::optional remoteAuthParam = {}; + RemoteAuthParam param = {}; + param.verifierNetworkId = "123"; + param.collectorNetworkId = "1233324321423412344134"; + remoteAuthParam = param; + EXPECT_NO_THROW(service.InitRemoteAuthParam(ipcRemoteAuthParam, remoteAuthParam)); +} + +HWTEST_F(UserAuthServiceTest, UserAuthServiceProcessPinExpired_001, TestSize.Level0) +{ + UserAuthService service; + int ret = PIN_EXPIRED; + AuthParamInner authParam = { + .authTypes = {FACE, PIN, PRIVATE_PIN}, + .authTrustLevel = ATL2, + .isUserIdSpecified = true, + }; + std::vector validType = {FACE, PIN, PRIVATE_PIN}; + ContextFactory::AuthWidgetContextPara para = { + .isPinExpired = true + }; + EXPECT_NO_THROW(service.ProcessPinExpired(ret, authParam, validType, para)); +} + HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify001, TestSize.Level0) { UserAuthService service; @@ -964,8 +1060,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify001, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); EXPECT_CALL(*mockHdi, BeginIdentification(_, _, _, _, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.Identify(testChallenge, testAuthType, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.Identify(testChallenge, testAuthType, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -977,8 +1075,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify002, TestSize.Level0) AuthType testAuthType = FACE; sptr testCallback(nullptr); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - sptr callbackInterface = testCallback; - uint64_t contextId = service.Identify(testChallenge, testAuthType, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.Identify(testChallenge, testAuthType, callbackInterface, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, 0); testCallback = sptr(new (std::nothrow) MockUserAuthCallback()); @@ -986,7 +1086,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify002, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); testAuthType = PIN; callbackInterface = testCallback; - contextId = service.Identify(testChallenge, testAuthType, callbackInterface); + ret = service.Identify(testChallenge, testAuthType, callbackInterface, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -1030,21 +1131,25 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify003, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, CHECK_PERMISSION_FAILED); + return SUCCESS; } ) .WillOnce( - [&context](int32_t result, const Attributes &extraInfo) { + [&context](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); if (context != nullptr) { context->Stop(); } + return SUCCESS; } ); - sptr callbackInterface = testCallback; - uint64_t contextId = service.Identify(testChallenge, testAuthType, callbackInterface); + sptr callbackInterface = testCallback; + uint64_t contextId = 0; + int32_t ret = service.Identify(testChallenge, testAuthType, callbackInterface, contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); EXPECT_EQ(contextId, 0); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); @@ -1057,7 +1162,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify003, TestSize.Level0) EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); - contextId = service.Identify(testChallenge, testAuthType, callbackInterface); + contextId = service.Identify(testChallenge, testAuthType, callbackInterface, contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); promise.get_future().get(); EXPECT_TRUE(ResourceNodePool::Instance().Delete(60)); @@ -1146,7 +1252,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServicePrepareRemoteAuth_001, TestSize.Lev const std::string networkId = "12312312313"; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); EXPECT_NE(testCallback, nullptr); - sptr callbackInterface = testCallback; + sptr callbackInterface = testCallback; EXPECT_EQ(service.PrepareRemoteAuth(networkId, callbackInterface), SUCCESS); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); EXPECT_EQ(service.PrepareRemoteAuth(networkId, callbackInterface), SUCCESS); @@ -1158,7 +1264,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServicePrepareRemoteAuth_002, TestSize.Lev UserAuthService service; const std::string networkId = ""; sptr testCallback(new (std::nothrow) MockUserAuthCallback()); - sptr callbackInterface = testCallback; + sptr callbackInterface = testCallback; IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); EXPECT_EQ(service.PrepareRemoteAuth(networkId, callbackInterface), SUCCESS); IpcCommon::DeleteAllPermission(); @@ -1213,17 +1319,19 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById001, TestSize.Level0 { UserAuthService service; uint64_t testCredentialId = 1; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(new (std::nothrow) MockGetExecutorPropertyCallback()); EXPECT_NE(testCallback, nullptr); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetCredentialById(_, _)).Times(1); EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(2); - sptr callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -1231,10 +1339,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById002, TestSize.Level0 { UserAuthService service; uint64_t testCredentialId = 1; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); @@ -1267,8 +1376,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById002, TestSize.Level0 EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(2); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -1277,19 +1388,23 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById003, TestSize.Level0 { UserAuthService service; uint64_t testCredentialId = 1; - std::vector testKeys = {Attributes::ATTR_REMAIN_TIMES, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_REMAIN_TIMES, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); testKeys = {Attributes::ATTR_FREEZING_TIME, Attributes::ATTR_SIGNATURE}; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); testKeys = {Attributes::ATTR_NEXT_FAIL_LOCKOUT_DURATION, Attributes::ATTR_SIGNATURE}; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); testKeys = {Attributes::ATTR_SIGNATURE}; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto resourceNode = MockResourceNode::CreateWithExecuteIndex(2); EXPECT_NE(resourceNode, nullptr); @@ -1304,7 +1419,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById003, TestSize.Level0 EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -1313,10 +1429,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById004, TestSize.Level0 { UserAuthService service; uint64_t testCredentialId = 1; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + sptr callbackInterface = testCallback; + int32_t ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); @@ -1349,7 +1466,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById004, TestSize.Level0 EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -1358,11 +1476,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById005, TestSize.Level0 { UserAuthService service; uint64_t testCredentialId = 1; - std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; + std::vector testKeys = {Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE}; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); - + sptr callbackInterface = testCallback; + int32_t ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetCredentialById(_, _)).Times(1); @@ -1394,7 +1512,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById005, TestSize.Level0 EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } @@ -1403,15 +1522,15 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById006, TestSize.Level0 { UserAuthService service; uint64_t testCredentialId = 1; - std::vector testKeys = { + std::vector testKeys = { Attributes::ATTR_PIN_SUB_TYPE, Attributes::ATTR_SIGNATURE, Attributes::ATTR_NEXT_FAIL_LOCKOUT_DURATION }; sptr testCallback(nullptr); - sptr callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); - + sptr callbackInterface = testCallback; + int32_t ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, INVALID_PARAMETERS); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetCredentialById(_, _)).Times(1); @@ -1443,7 +1562,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceGetPropertyById006, TestSize.Level0 EXPECT_CALL(*testCallback, OnGetExecutorPropertyResult(_, _)).Times(1); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); callbackInterface = testCallback; - service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + ret = service.GetPropertyById(testCredentialId, testKeys, callbackInterface); + EXPECT_EQ(ret, SUCCESS); EXPECT_TRUE(ResourceNodePool::Instance().Delete(2)); IpcCommon::DeleteAllPermission(); } diff --git a/test/unittest/services/src/user_auth_service_test_part02.cpp b/test/unittest/services/src/user_auth_service_test_part02.cpp index 8504a15cab78af70c25ac8b96ac5fbe8d9bb112d..6c8dba9bd34347c9ecbe63c778510cf700534d82 100644 --- a/test/unittest/services/src/user_auth_service_test_part02.cpp +++ b/test/unittest/services/src/user_auth_service_test_part02.cpp @@ -21,7 +21,7 @@ #include "iam_ptr.h" #include "executor_messenger_service.h" -#include "mock_auth_event_listener.h" +#include "mock_event_listener.h" #include "mock_context.h" #include "mock_iuser_auth_interface.h" #include "mock_ipc_common.h" @@ -40,50 +40,62 @@ namespace UserAuth { using namespace testing; using namespace testing::ext; +static void InitIpcAuthParamInner(IpcAuthParamInner &authParam, + std::vector &challenge, std::vector &authTypes, int32_t authTrustLevel) +{ + authParam.challenge = challenge; + authParam.authTypes = authTypes; + authParam.authTrustLevel = authTrustLevel; +} + +static void InitIpcWidgetParamInner(IpcWidgetParamInner &widgetParam, + const std::string &title, const std::string &navigationButtonText, int32_t windowMode) +{ + widgetParam.title = title; + widgetParam.navigationButtonText = navigationButtonText; + widgetParam.windowMode = windowMode; +} + HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_001, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = "确定"; - - sptr testUserAuthCallback(nullptr); - sptr testModalCallback(nullptr); - EXPECT_EQ(service.AuthWidget(apiVersion, authParam, widgetParam, testUserAuthCallback, testModalCallback), - (uint64_t)0); + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "确定", 0); + sptr testUserAuthCallback(nullptr); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testUserAuthCallback, testModalCallback, + contextId); + EXPECT_EQ(ret, GENERAL_ERROR); + EXPECT_EQ(contextId, (uint64_t)0); } HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_002, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -91,25 +103,23 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_003, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -117,25 +127,23 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_004, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -143,17 +151,12 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_005, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); @@ -162,11 +165,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_005, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillRepeatedly(Return(FAIL)); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); - service.CancelAuthOrIdentify(conxtId, 0); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -174,17 +180,12 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_006, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillRepeatedly(Return(FAIL)); @@ -193,11 +194,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_006, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); - service.CancelAuthOrIdentify(conxtId, 0); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -205,16 +209,12 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_007, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(2); @@ -222,17 +222,22 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_007, TestSize.Level0) IpcCommon::GetCallingUserId(service, userId); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); authParam.authTypes.push_back(FACE); authParam.authTypes.push_back(FACE); authParam.authTypes.push_back(FACE); authParam.authTypes.push_back(FACE); - conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -240,26 +245,24 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_008, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(static_cast(5)); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {5}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -267,26 +270,24 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_009, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(AuthType::ALL); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {ALL}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -294,26 +295,24 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_010, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = (AuthTrustLevel)50000; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, 50000); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, TRUST_LEVEL_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -321,26 +320,24 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_011, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = ATL1; - WidgetParamInner widgetParam; - widgetParam.title = ""; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL1); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -348,17 +345,12 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_012, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = ATL1; - WidgetParamInner widgetParam; - widgetParam.title = "WidgetParamTitle"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL1); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "WidgetParamTitle", "", WindowModeType::UNKNOWN_WINDOW_MODE); sptr testCallback(new (std::nothrow) MockUserAuthCallback); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1); @@ -367,11 +359,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_012, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillRepeatedly(Return(FAIL)); - sptr callbackInterface = testCallback; - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); - service.CancelAuthOrIdentify(conxtId, 0); + sptr callbackInterface = testCallback; + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, callbackInterface, testModalCallback, + contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -379,18 +374,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_013, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); auto *tempCallback = static_cast(testCallback.GetRefPtr()); EXPECT_NE(tempCallback, nullptr); @@ -400,13 +390,16 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_013, TestSize.Level0) auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillRepeatedly(Return(FAIL)); - sptr modalCallback = new MockModalCallback(); + sptr modalCallback = new MockModalCallback(); EXPECT_NE(modalCallback, nullptr); auto *testModalCallback = static_cast(modalCallback.GetRefPtr()); EXPECT_NE(testModalCallback, nullptr); EXPECT_CALL(*testModalCallback, SendCommand(_, _)).Times(0); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, modalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, modalCallback, + contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -414,27 +407,25 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_014, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(FACE); - authParam.authTrustLevel = (AuthTrustLevel)50000; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, 50000); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); auto *tempCallback = static_cast(testCallback.GetRefPtr()); EXPECT_NE(tempCallback, nullptr); EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, + contextId); + EXPECT_EQ(ret, TRUST_LEVEL_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -442,18 +433,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_015, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.challenge.push_back(2); - authParam.challenge.push_back(3); - authParam.challenge.push_back(4); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1, 2, 3, 4}; + std::vector authTypes = {FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); auto *tempCallback = static_cast(testCallback.GetRefPtr()); EXPECT_NE(tempCallback, nullptr); @@ -478,10 +464,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_015, TestSize.Level0) } ); ResourceNodePool::Instance().Insert(nullptr); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); - service.CancelAuthOrIdentify(conxtId, 0); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, + contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -489,20 +478,18 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_016, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); auto *tempCallback = static_cast(testCallback.GetRefPtr()); EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - int32_t acquire = 20; auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillRepeatedly(Return(FAIL)); @@ -523,16 +510,17 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_016, TestSize.Level0) auto resourceNode1 = Common::MakeShared(); EXPECT_CALL(*resourceNode1, GetExecutorIndex()).WillRepeatedly(Return(0)); ResourceNodePool::Instance().Insert(resourceNode1); - ON_CALL(*resourceNode1, GetProperty).WillByDefault( - [acquire](const Attributes &condition, Attributes &values) { + ON_CALL(*resourceNode1, GetProperty).WillByDefault([](const Attributes &condition, Attributes &values) { return SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); EXPECT_TRUE(ResourceNodePool::Instance().Delete(0)); - service.CancelAuthOrIdentify(conxtId, 0); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -540,20 +528,18 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0017, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); auto *tempCallback = static_cast(testCallback.GetRefPtr()); EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); - int32_t acquire = 20; auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillRepeatedly(Return(FAIL)); @@ -574,17 +560,18 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0017, TestSize.Level0) auto resourceNode1 = Common::MakeShared(); EXPECT_CALL(*resourceNode1, GetExecutorIndex()).WillRepeatedly(Return(0)); ResourceNodePool::Instance().Insert(resourceNode1); - ON_CALL(*resourceNode1, GetProperty).WillByDefault( - [acquire](const Attributes &condition, Attributes &values) { + ON_CALL(*resourceNode1, GetProperty).WillByDefault([](const Attributes &condition, Attributes &values) { values.SetStringValue(Attributes::ATTR_PIN_SUB_TYPE, "test"); return SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); EXPECT_TRUE(ResourceNodePool::Instance().Delete(0)); - service.CancelAuthOrIdentify(conxtId, 0); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -592,14 +579,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0018, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); auto *tempCallback = static_cast(testCallback.GetRefPtr()); EXPECT_NE(tempCallback, nullptr); @@ -625,18 +611,19 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0018, TestSize.Level0) auto resourceNode1 = Common::MakeShared(); EXPECT_CALL(*resourceNode1, GetExecutorIndex()).WillRepeatedly(Return(0)); ResourceNodePool::Instance().Insert(resourceNode1); - ON_CALL(*resourceNode1, GetProperty).WillByDefault( - [acquire](const Attributes &condition, Attributes &values) { + ON_CALL(*resourceNode1, GetProperty).WillByDefault([acquire](const Attributes &condition, Attributes &values) { values.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, acquire); values.SetStringValue(Attributes::ATTR_SENSOR_INFO, "test"); return SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); EXPECT_TRUE(ResourceNodePool::Instance().Delete(0)); - service.CancelAuthOrIdentify(conxtId, 0); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -644,14 +631,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0019, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); auto *tempCallback = static_cast(testCallback.GetRefPtr()); EXPECT_NE(tempCallback, nullptr); EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1); @@ -676,19 +662,20 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0019, TestSize.Level0) auto resourceNode1 = Common::MakeShared(); EXPECT_CALL(*resourceNode1, GetExecutorIndex()).WillRepeatedly(Return(0)); ResourceNodePool::Instance().Insert(resourceNode1); - ON_CALL(*resourceNode1, GetProperty).WillByDefault( - [acquire](const Attributes &condition, Attributes &values) { + ON_CALL(*resourceNode1, GetProperty).WillByDefault([acquire](const Attributes &condition, Attributes &values) { values.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, acquire); values.SetStringValue(Attributes::ATTR_SENSOR_INFO, "test"); values.SetInt32Value(Attributes::ATTR_REMAIN_TIMES, acquire); return SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, FAIL); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); EXPECT_TRUE(ResourceNodePool::Instance().Delete(0)); - service.CancelAuthOrIdentify(conxtId, 0); + service.CancelAuthOrIdentify(contextId, 0); IpcCommon::DeleteAllPermission(); } @@ -696,15 +683,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0020, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -735,9 +720,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0020, TestSize.Level0) return SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); EXPECT_TRUE(ResourceNodePool::Instance().Delete(0)); IpcCommon::DeleteAllPermission(); } @@ -746,15 +733,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0021, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::ALL); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {ALL}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -785,9 +770,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_0021, TestSize.Level0) return SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); EXPECT_TRUE(ResourceNodePool::Instance().Delete(0)); IpcCommon::DeleteAllPermission(); } @@ -796,15 +783,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_022, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -835,9 +820,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_022, TestSize.Level0) return SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t conxtId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); - EXPECT_NE(conxtId, INVALID_CONTEXT_ID); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); + EXPECT_NE(contextId, INVALID_CONTEXT_ID); EXPECT_TRUE(ResourceNodePool::Instance().Delete(0)); IpcCommon::DeleteAllPermission(); } @@ -846,18 +833,16 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_023, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); authParam.reuseUnlockResult.isReuse = true; authParam.reuseUnlockResult.reuseMode = AUTH_TYPE_IRRELEVANT; authParam.reuseUnlockResult.reuseDuration = 5 * 60 *1000; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -874,8 +859,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_023, TestSize.Level0) return HDF_SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, SUCCESS); EXPECT_EQ(contextId, REUSE_AUTH_RESULT_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -884,15 +871,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_024, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = "确定"; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "确定", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -900,8 +885,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_024, TestSize.Level0) EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetAvailableStatus(_, _, _, _)).Times(0); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -910,15 +897,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_025, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = "确定"; - widgetParam.windowMode = WindowModeType::UNKNOWN_WINDOW_MODE; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "确定", WindowModeType::UNKNOWN_WINDOW_MODE); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -933,8 +918,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_025, TestSize.Level0) return PIN_EXPIRED; } ); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -943,15 +930,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_026, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -968,8 +953,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_026, TestSize.Level0) return HDF_SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -978,15 +965,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_027, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -1003,8 +988,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_027, TestSize.Level0) return HDF_SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -1013,15 +1000,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_028, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -1038,8 +1023,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_028, TestSize.Level0) return HDF_SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -1048,16 +1035,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_029, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = ATL2; + std::vector challenge = {1}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); authParam.isUserIdSpecified = true; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -1074,8 +1059,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_029, TestSize.Level0) return HDF_SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, GENERAL_ERROR); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -1084,16 +1071,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_030, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::PIN); - authParam.authTrustLevel = ATL2; + std::vector challenge = {1}; + std::vector authTypes = {PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); authParam.isUserIdSpecified = true; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -1110,8 +1095,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_030, TestSize.Level0) return HDF_SUCCESS; } ); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -1120,16 +1107,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_031, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FACE); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FACE, FINGERPRINT}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -1137,8 +1121,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_031, TestSize.Level0) EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetAvailableStatus(_, _, _, _)).Times(0); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -1147,16 +1133,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_032, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTypes.push_back(AuthType::FACE); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = ""; - widgetParam.windowMode = WindowModeType::FULLSCREEN; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT, FACE}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "", WindowModeType::FULLSCREEN); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -1164,8 +1147,10 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_032, TestSize.Level0) EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetAvailableStatus(_, _, _, _)).Times(0); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, INVALID_PARAMETERS); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } @@ -1174,17 +1159,13 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_033, TestSize.Level0) { UserAuthService service; int32_t apiVersion = 10; - AuthParamInner authParam; - authParam.challenge.push_back(1); - authParam.authTypes.push_back(AuthType::FINGERPRINT); - authParam.authTypes.push_back(AuthType::FACE); - authParam.authTypes.push_back(AuthType::PRIVATE_PIN); - authParam.authTrustLevel = ATL2; - WidgetParamInner widgetParam; - widgetParam.title = "使用密码验证"; - widgetParam.navigationButtonText = "test"; - widgetParam.windowMode = WindowModeType::DIALOG_BOX; - sptr testCallback = new MockUserAuthCallback(); + std::vector challenge = {1}; + std::vector authTypes = {FINGERPRINT, FACE, PRIVATE_PIN}; + IpcAuthParamInner authParam; + InitIpcAuthParamInner(authParam, challenge, authTypes, ATL2); + IpcWidgetParamInner widgetParam; + InitIpcWidgetParamInner(widgetParam, "使用密码验证", "test", WindowModeType::DIALOG_BOX); + sptr testCallback = new MockUserAuthCallback(); EXPECT_NE(testCallback, nullptr); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); @@ -1192,12 +1173,138 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthWidget_033, TestSize.Level0) EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetAvailableStatus(_, _, _, _)).Times(0); EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(0); - sptr testModalCallback(nullptr); - uint64_t contextId = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback); + sptr testModalCallback(nullptr); + uint64_t contextId = 0; + int32_t ret = service.AuthWidget(apiVersion, authParam, widgetParam, testCallback, testModalCallback, contextId); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); EXPECT_EQ(contextId, BAD_CONTEXT_ID); IpcCommon::DeleteAllPermission(); } +HWTEST_F(UserAuthServiceTest, UserAuthServiceCheckAuthPermissionAndParam_001, TestSize.Level0) +{ + UserAuthService service; + std::vector challenge = {1}; + const AuthParamInner authParam = { + .challenge = challenge, + .authTypes = {PIN, FACE, PRIVATE_PIN}, + .authTrustLevel = ATL2, + .isUserIdSpecified = true, + }; + const WidgetParamInner widgetParam = { + .title = "使用密码验证", + .navigationButtonText = "navigationButtonText", + .windowMode = WindowModeType::NONE_INTERRUPTION_DIALOG_BOX, + }; + int32_t ret = service.CheckAuthPermissionAndParam(authParam, widgetParam, true); + EXPECT_EQ(ret, CHECK_SYSTEM_APP_FAILED); +} + +HWTEST_F(UserAuthServiceTest, UserAuthServiceCheckAuthPermissionAndParam_002, TestSize.Level0) +{ + UserAuthService service; + std::vector challenge = {1}; + const AuthParamInner authParam = { + .challenge = challenge, + .authTypes = {PIN, FACE, PRIVATE_PIN}, + .authTrustLevel = ATL2, + .isUserIdSpecified = true, + }; + const WidgetParamInner widgetParam = { + .title = "使用密码验证", + .navigationButtonText = "navigationButtonText", + .windowMode = WindowModeType::UNKNOWN_WINDOW_MODE, + }; + int32_t ret = service.CheckAuthPermissionAndParam(authParam, widgetParam, true); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); + IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); + ret = service.CheckAuthPermissionAndParam(authParam, widgetParam, true); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserAuthServiceTest, UserAuthServiceCheckAuthPermissionAndParam_003, TestSize.Level0) +{ + UserAuthService service; + std::vector challenge = {1}; + const AuthParamInner authParam = { + .challenge = challenge, + .authTypes = {PIN, FACE, PRIVATE_PIN}, + .authTrustLevel = ATL2, + .isUserIdSpecified = true, + }; + const WidgetParamInner widgetParam = { + .title = "使用密码验证", + .navigationButtonText = "navigationButtonText", + .windowMode = WindowModeType::UNKNOWN_WINDOW_MODE, + }; + IpcCommon::AddPermission(IS_SYSTEM_APP); + int32_t ret = service.CheckAuthPermissionAndParam(authParam, widgetParam, true); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserAuthServiceTest, UserAuthServiceCheckAuthPermissionAndParam_004, TestSize.Level0) +{ + UserAuthService service; + std::vector challenge = {1}; + const AuthParamInner authParam = { + .userId = 200, + .challenge = challenge, + .authTypes = {PIN, FACE, PRIVATE_PIN}, + .authTrustLevel = ATL2, + .isUserIdSpecified = true, + }; + const WidgetParamInner widgetParam = { + .navigationButtonText = "navigationButtonText", + .windowMode = WindowModeType::UNKNOWN_WINDOW_MODE, + }; + IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); + IpcCommon::AddPermission(IS_SYSTEM_APP); + IpcCommon::AddPermission(USER_AUTH_FROM_BACKGROUND); + IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); + int32_t ret = service.CheckAuthPermissionAndParam(authParam, widgetParam, true); + EXPECT_EQ(ret, INVALID_PARAMETERS); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserAuthServiceTest, UserAuthServiceCheckValidSolution_002, TestSize.Level0) +{ + UserAuthService service; + std::vector challenge = {1}; + const WidgetParamInner widgetParam = { + .title = "使用密码验证", + .navigationButtonText = "navigationButtonText", + .windowMode = WindowModeType::UNKNOWN_WINDOW_MODE, + }; + IpcCommon::AddPermission(ACCESS_BIOMETRIC_PERMISSION); + IpcCommon::AddPermission(IS_SYSTEM_APP); + IpcCommon::AddPermission(USER_AUTH_FROM_BACKGROUND); + IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); + int32_t userId = 100; + std::vector authTypeList; + authTypeList.push_back(FACE); + authTypeList.push_back(ALL); + authTypeList.push_back(PIN); + authTypeList.push_back(FINGERPRINT); + AuthTrustLevel atl = ATL3; + const AuthParamInner authParam = { + .userId = userId, + .challenge = challenge, + .authTypes = authTypeList, + .authTrustLevel = atl, + .isUserIdSpecified = true, + }; + std::vector validTypeList; + auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); + EXPECT_NE(mockHdi, nullptr); + EXPECT_CALL(*mockHdi, GetValidSolution(_, _, _, _)).WillOnce(Return(HDF_SUCCESS)); + int32_t ret = service.CheckValidSolution(userId, authParam, widgetParam, validTypeList); + EXPECT_EQ(ret, TYPE_NOT_SUPPORT); + MockIUserAuthInterface::Holder::GetInstance().Reset(); + IpcCommon::DeleteAllPermission(); +} + HWTEST_F(UserAuthServiceTest, UserAuthServiceCheckPrivatePinEnroll001, TestSize.Level0) { UserAuthService service; @@ -1241,7 +1348,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_001, TestSize.Level0) { UserAuthService service; IpcCommon::AddPermission(SUPPORT_USER_AUTH); - int32_t ret = service.Notice(NoticeType::WIDGET_NOTICE, "PIN"); + int32_t ret = service.Notice(static_cast(NoticeType::WIDGET_NOTICE), "PIN"); EXPECT_NE(ret, ResultCode::SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -1250,7 +1357,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_002, TestSize.Level0) { UserAuthService service; IpcCommon::AddPermission(IS_SYSTEM_APP); - int32_t ret = service.Notice(NoticeType::WIDGET_NOTICE, "PIN"); + int32_t ret = service.Notice(static_cast(NoticeType::WIDGET_NOTICE), "PIN"); EXPECT_EQ(ret, ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::DeleteAllPermission(); } @@ -1260,7 +1367,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_003, TestSize.Level0) UserAuthService service; IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); - int32_t ret = service.Notice(NoticeType::WIDGET_NOTICE, "PIN"); + int32_t ret = service.Notice(static_cast(NoticeType::WIDGET_NOTICE), "PIN"); EXPECT_EQ(ret, ResultCode::INVALID_PARAMETERS); IpcCommon::DeleteAllPermission(); } @@ -1268,14 +1375,14 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceNotice_003, TestSize.Level0) HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_001, TestSize.Level0) { UserAuthService service; - sptr testCallback = nullptr; + sptr testCallback = nullptr; EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::CHECK_SYSTEM_APP_FAILED); } HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_002, TestSize.Level0) { UserAuthService service; - sptr testCallback = nullptr; + sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::DeleteAllPermission(); @@ -1284,7 +1391,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_002, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_003, TestSize.Level0) { UserAuthService service; - sptr testCallback = nullptr; + sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); EXPECT_EQ(service.RegisterWidgetCallback(2, testCallback), ResultCode::INVALID_PARAMETERS); @@ -1294,7 +1401,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_003, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_004, TestSize.Level0) { UserAuthService service; - sptr testCallback = nullptr; + sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::INVALID_PARAMETERS); @@ -1304,7 +1411,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_004, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_005, TestSize.Level0) { UserAuthService service; - sptr testCallback = new MockWidgetCallbackInterface(); + sptr testCallback = new MockIWidgetCallback(); IpcCommon::AddPermission(IS_SYSTEM_APP); IpcCommon::AddPermission(SUPPORT_USER_AUTH); EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::SUCCESS); @@ -1314,7 +1421,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_005, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_006, TestSize.Level0) { UserAuthService service; - sptr testCallback = nullptr; + sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.RegisterWidgetCallback(1, testCallback), ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::DeleteAllPermission(); @@ -1323,34 +1430,18 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegisterWidgetCallback_006, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_001, TestSize.Level0) { UserAuthService service; - sptr testCallback = nullptr; - std::vector authTypeList; + sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); - EXPECT_EQ(service.RegistUserAuthSuccessEventListener(authTypeList, testCallback), ResultCode::INVALID_PARAMETERS); - IpcCommon::DeleteAllPermission(); -} - -HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_002, TestSize.Level0) -{ - UserAuthService service; - sptr testCallback = new MockAuthEventListener(); - std::vector authTypeList; - IpcCommon::AddPermission(IS_SYSTEM_APP); - EXPECT_EQ(service.RegistUserAuthSuccessEventListener(authTypeList, testCallback), - ResultCode::INVALID_PARAMETERS); + EXPECT_EQ(service.RegistUserAuthSuccessEventListener(testCallback), ResultCode::INVALID_PARAMETERS); IpcCommon::DeleteAllPermission(); } HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_003, TestSize.Level0) { UserAuthService service; - sptr testCallback = new MockAuthEventListener(); - std::vector authTypeList; - authTypeList.push_back(AuthType::PIN); - authTypeList.push_back(AuthType::FACE); - authTypeList.push_back(AuthType::FINGERPRINT); + sptr testCallback = new MockEventListener(); IpcCommon::AddPermission(IS_SYSTEM_APP); - EXPECT_EQ(service.RegistUserAuthSuccessEventListener(authTypeList, testCallback), + EXPECT_EQ(service.RegistUserAuthSuccessEventListener(testCallback), ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::DeleteAllPermission(); } @@ -1358,30 +1449,26 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_003, TestSize. HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_004, TestSize.Level0) { UserAuthService service; - sptr testCallback = new MockAuthEventListener(); - std::vector authTypeList; - authTypeList.push_back(AuthType::PIN); - authTypeList.push_back(AuthType::FACE); - authTypeList.push_back(AuthType::FINGERPRINT); + sptr testCallback = new MockEventListener(); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - EXPECT_EQ(service.RegistUserAuthSuccessEventListener(authTypeList, testCallback), ResultCode::GENERAL_ERROR); + EXPECT_EQ(service.RegistUserAuthSuccessEventListener(testCallback), + ResultCode::GENERAL_ERROR); IpcCommon::DeleteAllPermission(); } HWTEST_F(UserAuthServiceTest, UserAuthServiceRegistEventListerner_005, TestSize.Level0) { UserAuthService service; - sptr testCallback = new MockAuthEventListener(); - std::vector authTypeList; - authTypeList.push_back(AuthType::ALL); - EXPECT_EQ(service.RegistUserAuthSuccessEventListener(authTypeList, testCallback), ResultCode::INVALID_PARAMETERS); + sptr testCallback = new MockEventListener(); + EXPECT_EQ(service.RegistUserAuthSuccessEventListener(testCallback), + ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::DeleteAllPermission(); } HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_001, TestSize.Level0) { UserAuthService service; - sptr testCallback = nullptr; + sptr testCallback = nullptr; IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.UnRegistUserAuthSuccessEventListener(testCallback), ResultCode::INVALID_PARAMETERS); IpcCommon::DeleteAllPermission(); @@ -1390,7 +1477,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_001, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_002, TestSize.Level0) { UserAuthService service; - sptr testCallback = new MockAuthEventListener(); + sptr testCallback = new MockEventListener(); IpcCommon::AddPermission(IS_SYSTEM_APP); EXPECT_EQ(service.UnRegistUserAuthSuccessEventListener(testCallback), ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::DeleteAllPermission(); @@ -1399,7 +1486,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_002, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_003, TestSize.Level0) { UserAuthService service; - sptr testCallback = new MockAuthEventListener(); + sptr testCallback = new MockEventListener(); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); EXPECT_EQ(service.UnRegistUserAuthSuccessEventListener(testCallback), ResultCode::GENERAL_ERROR); IpcCommon::DeleteAllPermission(); @@ -1408,13 +1495,9 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_003, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_004, TestSize.Level0) { UserAuthService service; - sptr testCallback = new MockAuthEventListener(); - std::vector authTypeList; - authTypeList.push_back(AuthType::PIN); - authTypeList.push_back(AuthType::FACE); - authTypeList.push_back(AuthType::FINGERPRINT); + sptr testCallback = new MockEventListener(); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); - EXPECT_EQ(service.RegistUserAuthSuccessEventListener(authTypeList, testCallback), ResultCode::GENERAL_ERROR); + EXPECT_EQ(service.RegistUserAuthSuccessEventListener(testCallback), ResultCode::GENERAL_ERROR); EXPECT_EQ(service.UnRegistUserAuthSuccessEventListener(testCallback), ResultCode::GENERAL_ERROR); IpcCommon::DeleteAllPermission(); } @@ -1422,7 +1505,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceUnRegistEventListerner_004, TestSiz HWTEST_F(UserAuthServiceTest, UserAuthServiceSetGlobalConfigParam001, TestSize.Level0) { UserAuthService service; - GlobalConfigParam param = {}; + IpcGlobalConfigParam param = {}; EXPECT_EQ(service.SetGlobalConfigParam(param), ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(ENTERPRISE_DEVICE_MGR); @@ -1450,7 +1533,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetGlobalConfigParam001, TestSize.L HWTEST_F(UserAuthServiceTest, UserAuthServiceSetGlobalConfigParam002, TestSize.Level0) { UserAuthService service; - GlobalConfigParam param = {}; + IpcGlobalConfigParam param = {}; EXPECT_EQ(service.SetGlobalConfigParam(param), ResultCode::CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(ENTERPRISE_DEVICE_MGR); @@ -1479,7 +1562,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceSetGlobalConfigParam002, TestSize.L HWTEST_F(UserAuthServiceTest, UserAuthServiceSetGlobalConfigParam003, TestSize.Level0) { UserAuthService service; - GlobalConfigParam param = {}; + IpcGlobalConfigParam param = {}; IpcCommon::AddPermission(ENTERPRISE_DEVICE_MGR); IpcCommon::AddPermission(ACCESS_USER_AUTH_INTERNAL_PERMISSION); EXPECT_EQ(service.SetGlobalConfigParam(param), ResultCode::INVALID_PARAMETERS); @@ -1521,7 +1604,7 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceVerifyAuthToken001, TestSize.Level0 EXPECT_CALL(*testCallback, OnVerifyTokenResult(_, _)).Times(1); IpcCommon::AddPermission(USE_USER_ACCESS_MANAGER); IpcCommon::AddPermission(IS_SYSTEM_APP); - sptr callbackInterface = testCallback; + sptr callbackInterface = testCallback; service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface); IpcCommon::DeleteAllPermission(); } @@ -1535,8 +1618,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceVerifyAuthToken002, TestSize.Level0 testCallback = sptr(new (std::nothrow) MockVerifyTokenCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnVerifyTokenResult(_, _)).Times(2); - sptr callbackInterface = testCallback; - service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface); + sptr callbackInterface = testCallback; + EXPECT_EQ(service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface), INVALID_PARAMETERS); testTokenIn.resize(1); allowableDuration = 25 * 60 * 60 * 1000; @@ -1553,11 +1636,11 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceVerifyAuthToken003, TestSize.Level0 testCallback = sptr(new (std::nothrow) MockVerifyTokenCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnVerifyTokenResult(_, _)).Times(2); - sptr callbackInterface = testCallback; + sptr callbackInterface = testCallback; service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface); IpcCommon::AddPermission(USE_USER_ACCESS_MANAGER); - service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface); + EXPECT_EQ(service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface), CHECK_SYSTEM_APP_FAILED); IpcCommon::DeleteAllPermission(); } @@ -1583,8 +1666,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceVerifyAuthToken004, TestSize.Level0 EXPECT_CALL(*testCallback, OnVerifyTokenResult(_, _)).Times(1); IpcCommon::AddPermission(USE_USER_ACCESS_MANAGER); IpcCommon::AddPermission(IS_SYSTEM_APP); - sptr callbackInterface = testCallback; - service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface); + sptr callbackInterface = testCallback; + EXPECT_EQ(service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface), HDF_FAILURE); IpcCommon::DeleteAllPermission(); } @@ -1611,8 +1694,8 @@ HWTEST_F(UserAuthServiceTest, UserAuthServiceVerifyAuthToken005, TestSize.Level0 EXPECT_CALL(*testCallback, OnVerifyTokenResult(_, _)).Times(1); IpcCommon::AddPermission(USE_USER_ACCESS_MANAGER); IpcCommon::AddPermission(IS_SYSTEM_APP); - sptr callbackInterface = testCallback; - service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface); + sptr callbackInterface = testCallback; + EXPECT_EQ(service.VerifyAuthToken(testTokenIn, allowableDuration, callbackInterface), SUCCESS); IpcCommon::DeleteAllPermission(); } } // namespace UserAuth diff --git a/test/unittest/services/src/user_auth_stub_test.cpp b/test/unittest/services/src/user_auth_stub_test.cpp deleted file mode 100644 index 1bfc668f946e9587cfc535bbb10cbba5c7b12691..0000000000000000000000000000000000000000 --- a/test/unittest/services/src/user_auth_stub_test.cpp +++ /dev/null @@ -1,1153 +0,0 @@ -/* - * Copyright (C) 2022-2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_auth_stub_test.h" - -#include "iam_common_defines.h" -#include "mock_auth_event_listener.h" -#include "mock_user_auth_callback.h" -#include "mock_user_access_ctrl_callback.h" -#include "mock_user_auth_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserAuthStubTest::SetUpTestCase() -{ -} - -void UserAuthStubTest::TearDownTestCase() -{ -} - -void UserAuthStubTest::SetUp() -{ -} - -void UserAuthStubTest::TearDown() -{ -} - -HWTEST_F(UserAuthStubTest, UserAuthStubDefault, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(305, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetEnrolledStateStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_ENROLLED_STATE; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetEnrolledStateStub002, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MockUserAuthService service; - int32_t testApiVersion = 12; - AuthType testAuthType = FACE; - uint64_t expectCredentialDigest = 23962; - uint16_t expectCredentialCount = 1; - EXPECT_CALL(service, GetEnrolledState(_, _, _)).Times(1); - ON_CALL(service, GetEnrolledState) - .WillByDefault( - [testApiVersion, testAuthType, expectCredentialDigest, expectCredentialCount](int32_t apiVersion, - AuthType authType, EnrolledState &enrolledState) { - EXPECT_EQ(apiVersion, testApiVersion); - EXPECT_EQ(authType, testAuthType); - enrolledState.credentialDigest = expectCredentialDigest; - enrolledState.credentialCount = expectCredentialCount; - return SUCCESS; - } - ); - - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = static_cast(UserAuthInterfaceCode::USER_AUTH_GET_ENROLLED_STATE); - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testApiVersion)); - EXPECT_TRUE(data.WriteUint32(testAuthType)); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(SUCCESS, result); - uint64_t actualCredentialDigest; - EXPECT_TRUE(reply.ReadUint64(actualCredentialDigest)); - EXPECT_EQ(expectCredentialDigest, actualCredentialDigest); - uint16_t actualCredentialCount; - EXPECT_TRUE(reply.ReadUint16(actualCredentialCount)); - EXPECT_EQ(expectCredentialCount, actualCredentialCount); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetAvailableStatusStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_AVAILABLE_STATUS; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetAvailableStatusStub002, TestSize.Level0) -{ - MockUserAuthService service; - AuthType testAuthType = FACE; - AuthTrustLevel testAuthTrustLevel = ATL3; - int32_t testApiVersion = 8; - int32_t testUserId = 100; - EXPECT_CALL(service, GetAvailableStatus(_, _, _, _)).WillRepeatedly([]() { - return SUCCESS; - }); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = static_cast(UserAuthInterfaceCode::USER_AUTH_GET_AVAILABLE_STATUS); - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteUint32(testAuthTrustLevel)); - EXPECT_TRUE(data.WriteInt32(testApiVersion)); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetPropertyStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetPropertyStub002, TestSize.Level0) -{ - int32_t testUserId = 1232666; - AuthType testAuthType = FACE; - std::vector testAttrKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE}; - std::vector tempKeys; - for (auto &attrKey : testAttrKeys) { - tempKeys.push_back(static_cast(attrKey)); - } - sptr callback(new (std::nothrow) MockGetExecutorPropertyCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, GetProperty(_, _, _, _)).Times(1); - ON_CALL(service, GetProperty) - .WillByDefault( - [&testUserId, &testAuthType, &testAttrKeys](int32_t userId, AuthType authType, - const std::vector &keys, - sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(authType, testAuthType); - EXPECT_THAT(keys, ElementsAreArray(testAttrKeys)); - if (callback != nullptr) { - Attributes attr; - callback->OnGetExecutorPropertyResult(SUCCESS, attr); - } - } - ); - EXPECT_CALL(*callback, OnGetExecutorPropertyResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteUInt32Vector(tempKeys)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubSetPropertyStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_SET_PROPERTY; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubSetPropertyStub002, TestSize.Level0) -{ - int32_t testUserId = 132282; - AuthType testAuthType = FACE; - Attributes attributes; - - uint64_t testTemplateId = 3364734; - EXPECT_TRUE(attributes.SetUint64Value(Attributes::ATTR_TEMPLATE_ID, testTemplateId)); - - sptr callback(new (std::nothrow) MockSetExecutorPropertyCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, SetProperty(_, _, _, _)).Times(1); - ON_CALL(service, SetProperty) - .WillByDefault( - [&testUserId, &testAuthType, &testTemplateId](int32_t userId, AuthType authType, - const Attributes &attributes, sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(authType, testAuthType); - uint64_t tempTemplateId = 0; - EXPECT_TRUE(attributes.GetUint64Value(Attributes::ATTR_TEMPLATE_ID, tempTemplateId)); - EXPECT_EQ(tempTemplateId, testTemplateId); - if (callback != nullptr) { - callback->OnSetExecutorPropertyResult(SUCCESS); - } - } - ); - EXPECT_CALL(*callback, OnSetExecutorPropertyResult(_)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_SET_PROPERTY; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteUInt8Vector(attributes.Serialize())); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthStub002, TestSize.Level0) -{ - int32_t testUserId = 3467; - int32_t testApiVersion = 9; - std::vector testChallenge = {1, 2, 4, 5}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - uint64_t testContextId = 2346782; - - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, Auth(_, _, _, _, _)).Times(1); - ON_CALL(service, Auth) - .WillByDefault( - [&testChallenge, &testAuthType, &testAtl, &testContextId, &testApiVersion](int32_t apiVersion, - const std::vector &challenge, AuthType authType, AuthTrustLevel authTrustLevel, - sptr &callback) { - EXPECT_EQ(apiVersion, testApiVersion); - EXPECT_THAT(challenge, ElementsAreArray(testChallenge)); - EXPECT_EQ(authType, testAuthType); - EXPECT_EQ(authTrustLevel, testAtl); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - return testContextId; - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testApiVersion)); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - uint64_t contextId = 0; - EXPECT_TRUE(reply.ReadUint64(contextId)); - EXPECT_EQ(contextId, testContextId); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub002, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - uint64_t testContextId = 2346728; - - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, AuthUser(_, _, _)).Times(1); - ON_CALL(service, AuthUser) - .WillByDefault( - [&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](AuthParamInner &authParam, - std::optional &remoteAuthParam, sptr &callback) { - EXPECT_EQ(authParam.userId, testUserId); - EXPECT_THAT(authParam.challenge, ElementsAreArray(testChallenge)); - EXPECT_EQ(authParam.authType, testAuthType); - EXPECT_EQ(authParam.authTrustLevel, testAtl); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - return testContextId; - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - uint32_t testAuthTrustLevel = 0; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(testAuthTrustLevel)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - uint64_t contextId = 0; - EXPECT_TRUE(reply.ReadUint64(contextId)); - EXPECT_EQ(contextId, testContextId); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub003, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub004, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - uint64_t testContextId = 2346728; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, AuthUser(_, _, _)).Times(1); - ON_CALL(service, AuthUser) - .WillByDefault( - [&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](AuthParamInner &authParam, - std::optional &remoteAuthParam, sptr &callback) { - EXPECT_THAT(authParam.challenge, ElementsAreArray(testChallenge)); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - return testContextId; - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - uint32_t collectorTokenId = 123; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("verifierNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteUint32(collectorTokenId)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub005, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - uint32_t collectorTokenId = 123; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("verifierNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_TRUE(data.WriteBool(false)); - EXPECT_TRUE(data.WriteUint32(collectorTokenId)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub006, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("verifierNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_TRUE(data.WriteBool(false)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub007, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("verifierNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub008, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("verifierNetworkId")); - EXPECT_TRUE(data.WriteBool(false)); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub009, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("verifierNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub010, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub011, TestSize.Level0) -{ - int32_t testUserId = 3467; - std::vector testChallenge = {1, 2, 5, 9}; - AuthType testAuthType = FACE; - AuthTrustLevel testAtl = ATL2; - sptr callback(new (std::nothrow) MockAuthEventListenerService()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_AUTH_USER; - std::vector testAuthTypeInts; - testAuthTypeInts.push_back(static_cast(1)); - uint32_t authIntent = 0; - uint32_t collectorTokenId = 123; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_TRUE(data.WriteInt32Vector(testAuthTypeInts)); - EXPECT_TRUE(data.WriteUint32(testAtl)); - EXPECT_TRUE(data.WriteUint32(authIntent)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("verifierNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_TRUE(data.WriteBool(true)); - EXPECT_TRUE(data.WriteUint32(collectorTokenId)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(GENERAL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubIdentifyStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_IDENTIFY; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubIdentifyStub002, TestSize.Level0) -{ - std::vector testChallenge = {1, 2, 5, 8, 9}; - AuthType testAuthType = FACE; - uint64_t testContextId = 76374284; - - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, Identify(_, _, _)).Times(1); - ON_CALL(service, Identify) - .WillByDefault( - [&testChallenge, &testAuthType, &testContextId](const std::vector &challenge, AuthType authType, - sptr &callback) { - EXPECT_THAT(challenge, ElementsAreArray(testChallenge)); - EXPECT_EQ(authType, testAuthType); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - return testContextId; - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_IDENTIFY; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUInt8Vector(testChallenge)); - EXPECT_TRUE(data.WriteInt32(testAuthType)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - uint64_t contextId = 0; - EXPECT_TRUE(reply.ReadUint64(contextId)); - EXPECT_EQ(contextId, testContextId); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_CANCEL_AUTH; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub002, TestSize.Level0) -{ - uint64_t testContextId = 9346248; - int32_t testCancelReason = 0; - - MockUserAuthService service; - EXPECT_CALL(service, CancelAuthOrIdentify(_, _)).Times(1); - ON_CALL(service, CancelAuthOrIdentify) - .WillByDefault( - [&testContextId, &testCancelReason](uint64_t contextId, int32_t cancelReason) { - EXPECT_EQ(contextId, testContextId); - EXPECT_EQ(cancelReason, testCancelReason); - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_CANCEL_AUTH; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(testContextId)); - EXPECT_TRUE(data.WriteInt32(testCancelReason)); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub003, TestSize.Level0) -{ - uint64_t testContextId = 9346248; - int32_t testCancelReason = 0; - - MockUserAuthService service; - EXPECT_CALL(service, CancelAuthOrIdentify(_, _)).Times(1); - ON_CALL(service, CancelAuthOrIdentify) - .WillByDefault( - [&testContextId, &testCancelReason](uint64_t contextId, int32_t cancelReason) { - EXPECT_EQ(contextId, testContextId); - EXPECT_EQ(cancelReason, testCancelReason); - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_CANCEL_IDENTIFY; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(testContextId)); - EXPECT_TRUE(data.WriteInt32(testCancelReason)); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetVersionStub, TestSize.Level0) -{ - int32_t testVersion = 1000; - - MockUserAuthService service; - EXPECT_CALL(service, GetVersion(_)).Times(1); - ON_CALL(service, GetVersion) - .WillByDefault( - [&testVersion](int32_t &version) { - version = testVersion; - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_VERSION; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t version = -1; - EXPECT_TRUE(reply.ReadInt32(version)); - EXPECT_EQ(version, testVersion); - int32_t result; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubRegistUserAuthSuccessEventListenerStub, TestSize.Level0) -{ - MockUserAuthService service; - sptr callback(new (std::nothrow) MockAuthEventListenerService()); - EXPECT_NE(callback, nullptr); - EXPECT_CALL(service, RegistUserAuthSuccessEventListener(_, _)).Times(1); - ON_CALL(service, RegistUserAuthSuccessEventListener) - .WillByDefault( - [](const std::vector &authType, const sptr &callback) { - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_REG_EVENT_LISTENER; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - std::vector authType; - authType.push_back(static_cast(PIN)); - authType.push_back(static_cast(FACE)); - authType.push_back(static_cast(FINGERPRINT)); - - EXPECT_TRUE(data.WriteInt32Vector(authType)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubUnRegistUserAuthSuccessEventListenerStub, TestSize.Level0) -{ - MockUserAuthService service; - sptr callback(new (std::nothrow) MockAuthEventListenerService()); - EXPECT_NE(callback, nullptr); - EXPECT_CALL(service, UnRegistUserAuthSuccessEventListener(_)).Times(1); - ON_CALL(service, UnRegistUserAuthSuccessEventListener) - .WillByDefault( - [](const sptr &callback) { - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_UNREG_EVENT_LISTENER; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubSetGlobalConfigParamStub001, TestSize.Level0) -{ - MockUserAuthService service; - EXPECT_CALL(service, SetGlobalConfigParam(_)).Times(1); - ON_CALL(service, SetGlobalConfigParam) - .WillByDefault( - [](const GlobalConfigParam ¶m) { - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_SET_CLOBAL_CONFIG_PARAM; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - GlobalConfigParam param = {}; - param.type = PIN_EXPIRED_PERIOD; - param.value.pinExpiredPeriod = 1; - EXPECT_TRUE(data.WriteInt32(param.type)); - EXPECT_TRUE(data.WriteInt64(param.value.pinExpiredPeriod)); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubSetGlobalConfigParamStub002, TestSize.Level0) -{ - MockUserAuthService service; - EXPECT_CALL(service, SetGlobalConfigParam(_)).Times(1); - ON_CALL(service, SetGlobalConfigParam) - .WillByDefault( - [](const GlobalConfigParam ¶m) { - return GENERAL_ERROR; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_SET_CLOBAL_CONFIG_PARAM; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - GlobalConfigParam param = {}; - param.type = ENABLE_STATUS; - param.value.enableStatus = true; - param.userIds.push_back(1); - std::vector authTypes = {1}; - EXPECT_TRUE(data.WriteInt32(param.type)); - EXPECT_TRUE(data.WriteInt64(param.value.pinExpiredPeriod)); - EXPECT_TRUE(data.WriteInt32Vector(param.userIds)); - EXPECT_TRUE(data.WriteInt32Vector(authTypes)); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, GENERAL_ERROR); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubPrepareRemoteAuthStub_001, TestSize.Level0) -{ - MockUserAuthService service; - sptr callback(new (std::nothrow) MockAuthEventListenerService()); - EXPECT_NE(callback, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); - int32_t result; - EXPECT_FALSE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubPrepareRemoteAuthStub_002, TestSize.Level0) -{ - MockUserAuthService service; - sptr callback(new (std::nothrow) MockAuthEventListenerService()); - EXPECT_NE(callback, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(GENERAL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubPrepareRemoteAuthStub_003, TestSize.Level0) -{ - MockUserAuthService service; - sptr callback(new (std::nothrow) MockUserAuthCallback()); - EXPECT_NE(callback, nullptr); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_PREPARE_REMOTE_AUTH; - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteString("collectorNetworkId")); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - int32_t result; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetPropertyByIdStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY_BY_ID; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubGetPropertyByIdStub002, TestSize.Level0) -{ - uint64_t testCredentialId = 1; - std::vector testAttrKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE, - Attributes::ATTR_SCHEDULE_MODE}; - std::vector tempKeys; - for (auto &attrKey : testAttrKeys) { - tempKeys.push_back(static_cast(attrKey)); - } - sptr callback(new (std::nothrow) MockGetExecutorPropertyCallback()); - EXPECT_NE(callback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, GetPropertyById(_, _, _)).Times(1); - ON_CALL(service, GetPropertyById) - .WillByDefault( - [&testCredentialId, &testAttrKeys](uint64_t credentialId, const std::vector &keys, - sptr &callback) { - EXPECT_EQ(credentialId, testCredentialId); - EXPECT_THAT(keys, ElementsAreArray(testAttrKeys)); - if (callback != nullptr) { - Attributes attr; - callback->OnGetExecutorPropertyResult(SUCCESS, attr); - } - } - ); - EXPECT_CALL(*callback, OnGetExecutorPropertyResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_AUTH_GET_PROPERTY_BY_ID; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUint64(testCredentialId)); - EXPECT_TRUE(data.WriteUInt32Vector(tempKeys)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubVerifyAuthTokenStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_ACCESS_CTRL_VERIFY_AUTH_TOKEN; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - - MockUserAuthService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserAuthStubTest, UserAuthStubVerifyAuthTokenStub002, TestSize.Level0) -{ - std::vector testTokenIn = {}; - uint64_t testAllowableDuration = 0; - - sptr testCallback(new (std::nothrow) MockVerifyTokenCallback()); - EXPECT_NE(testCallback, nullptr); - MockUserAuthService service; - EXPECT_CALL(service, VerifyAuthToken(_, _, _)).Times(1); - ON_CALL(service, VerifyAuthToken) - .WillByDefault( - [&testTokenIn, &testAllowableDuration, &testCallback](const std::vector &tokenIn, - uint64_t allowableDuration, const sptr &callback) { - EXPECT_EQ(tokenIn, testTokenIn); - EXPECT_EQ(allowableDuration, testAllowableDuration); - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserAuthInterfaceCode::USER_ACCESS_CTRL_VERIFY_AUTH_TOKEN; - - EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteUInt8Vector(testTokenIn)); - EXPECT_TRUE(data.WriteUint64(testAllowableDuration)); - EXPECT_NE(testCallback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(testCallback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/services/src/user_idm_service_test.cpp b/test/unittest/services/src/user_idm_service_test.cpp index c5821e01da29dc85c1cf3e94c7c19233a19480f4..f453bae51af30e51fb61657a54ff1caed2f836e2 100644 --- a/test/unittest/services/src/user_idm_service_test.cpp +++ b/test/unittest/services/src/user_idm_service_test.cpp @@ -23,6 +23,7 @@ #include "context_pool.h" #include "executor_messenger_service.h" #include "mock_context.h" +#include "mock_event_listener.h" #include "mock_ipc_common.h" #include "mock_iuser_auth_interface.h" #include "mock_resource_node.h" @@ -122,8 +123,8 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceCloseSession, TestSize.Level0) .WillOnce(Return(HDF_SUCCESS)) .WillOnce(Return(HDF_FAILURE)); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.CloseSession(testUserId); - service.CloseSession(testUserId); + EXPECT_EQ(service.CloseSession(testUserId), SUCCESS); + EXPECT_EQ(service.CloseSession(testUserId), GENERAL_ERROR); IpcCommon::DeleteAllPermission(); } @@ -140,10 +141,10 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfo001, TestSize.Level0 auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillOnce(Return(HDF_FAILURE)); - int32_t ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback); + int32_t ret = service.GetCredentialInfo(testUserId, static_cast(testAuthType), testCallback); EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); - ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback); + ret = service.GetCredentialInfo(testUserId, static_cast(testAuthType), testCallback); EXPECT_EQ(ret, GENERAL_ERROR); IpcCommon::DeleteAllPermission(); } @@ -153,8 +154,8 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfo002, TestSize.Level0 UserIdmService service(123123, true); int32_t testUserId = 0; AuthType testAuthType = PIN; - sptr testCallback(nullptr); - int32_t ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback); + sptr testCallback(nullptr); + int32_t ret = service.GetCredentialInfo(testUserId, static_cast(testAuthType), testCallback); EXPECT_EQ(ret, INVALID_PARAMETERS); } @@ -186,9 +187,9 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfo003, TestSize.Level0 } ); IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); - int32_t ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback); + int32_t ret = service.GetCredentialInfo(testUserId, static_cast(testAuthType), testCallback); EXPECT_EQ(ret, SUCCESS); - ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback); + ret = service.GetCredentialInfo(testUserId, static_cast(testAuthType), testCallback); EXPECT_EQ(ret, SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -221,7 +222,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfo004, TestSize.Level0 ); IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); - int32_t ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback); + int32_t ret = service.GetCredentialInfo(testUserId, static_cast(testAuthType), testCallback); EXPECT_EQ(ret, SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -288,19 +289,19 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential001, TestSize.Level0) { UserIdmService service(123123, true); int32_t testUserId = 15457; - UserIdmInterface::CredentialPara testCredPara = {}; + IpcCredentialPara testCredPara = {}; testCredPara.authType = PIN; testCredPara.pinType = PIN_SIX; testCredPara.token = {1, 2, 3, 4}; - sptr testCallback(nullptr); - EXPECT_NO_THROW(service.AddCredential(testUserId, testCredPara, testCallback, false)); + sptr testCallback(nullptr); + EXPECT_EQ(service.AddCredential(testUserId, testCredPara, testCallback, false), INVALID_PARAMETERS); } HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential002, TestSize.Level0) { UserIdmService service(123123, true); int32_t testUserId = 15457; - UserIdmInterface::CredentialPara testCredPara = {}; + IpcCredentialPara testCredPara = {}; testCredPara.authType = PIN; testCredPara.pinType = PIN_SIX; testCredPara.token = {1, 2, 3, 4}; @@ -309,22 +310,24 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential002, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, CHECK_PERMISSION_FAILED); + return SUCCESS; } ) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_FAILURE); + return SUCCESS; } ); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, BeginEnrollment(_, _, _)).WillRepeatedly(Return(HDF_FAILURE)); - service.AddCredential(testUserId, testCredPara, testCallback, false); + EXPECT_EQ(service.AddCredential(testUserId, testCredPara, testCallback, false), CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.AddCredential(testUserId, testCredPara, testCallback, false); + EXPECT_EQ(service.AddCredential(testUserId, testCredPara, testCallback, false), GENERAL_ERROR); IpcCommon::DeleteAllPermission(); } @@ -375,7 +378,7 @@ static void MockForIdmResourceNode(std::shared_ptr &resourceNo EXPECT_NE(finalResult, nullptr); std::vector scheduleResult = {1, 2, 3, 4}; EXPECT_TRUE(finalResult->SetUint8ArrayValue(Attributes::ATTR_RESULT, scheduleResult)); - EXPECT_EQ(messenger->Finish(testScheduleId, SUCCESS, finalResult), SUCCESS); + EXPECT_EQ(messenger->Finish(testScheduleId, SUCCESS, finalResult->Serialize()), SUCCESS); return SUCCESS; }); } @@ -384,7 +387,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential003, TestSize.Level0) { UserIdmService service(123123, true); int32_t testUserId = 15457; - UserIdmInterface::CredentialPara testCredPara = {}; + IpcCredentialPara testCredPara = {}; testCredPara.authType = FACE; testCredPara.pinType = PIN_SIX; testCredPara.token = {1, 2, 3, 4}; @@ -394,11 +397,12 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential003, TestSize.Level0) EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [&context](int32_t result, const Attributes &extraInfo) { + [&context](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); if (context != nullptr) { context->Stop(); } + return SUCCESS; } ); std::promise promise; @@ -411,7 +415,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential003, TestSize.Level0) EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode)); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.AddCredential(testUserId, testCredPara, testCallback, false); + EXPECT_EQ(service.AddCredential(testUserId, testCredPara, testCallback, false), SUCCESS); promise.get_future().get(); EXPECT_TRUE(ResourceNodePool::Instance().Delete(60)); @@ -422,7 +426,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential001, TestSize.Level0) { UserIdmService service(123123, true); int32_t testUserId = 1548545; - UserIdmInterface::CredentialPara testCredPara = {}; + IpcCredentialPara testCredPara = {}; testCredPara.authType = FACE; testCredPara.pinType = PIN_SIX; testCredPara.token = {1, 2, 3, 4}; @@ -430,15 +434,16 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential001, TestSize.Level0) EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, NOT_ENROLLED); + return SUCCESS; } ); auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillRepeatedly(Return(HDF_SUCCESS)); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.UpdateCredential(testUserId, testCredPara, testCallback); + EXPECT_EQ(service.UpdateCredential(testUserId, testCredPara, testCallback), SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -446,20 +451,21 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential002, TestSize.Level0) { UserIdmService service(123123, true); int32_t testUserId = 1548545; - UserIdmInterface::CredentialPara testCredPara = {}; + IpcCredentialPara testCredPara = {}; testCredPara.authType = FACE; testCredPara.pinType = PIN_SIX; sptr testCallback(nullptr); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.UpdateCredential(testUserId, testCredPara, testCallback); + EXPECT_EQ(service.UpdateCredential(testUserId, testCredPara, testCallback), INVALID_PARAMETERS); testCallback = sptr(new (std::nothrow) MockIdmCallback()); EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_FAILURE); + return SUCCESS; } ); @@ -484,7 +490,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential002, TestSize.Level0) EXPECT_CALL(*mockHdi, BeginEnrollment(_, _, _)).WillOnce(Return(HDF_FAILURE)); testCredPara.token = {1, 2, 3, 4}; - service.UpdateCredential(testUserId, testCredPara, testCallback); + EXPECT_EQ(service.UpdateCredential(testUserId, testCredPara, testCallback), GENERAL_ERROR); IpcCommon::DeleteAllPermission(); } @@ -551,13 +557,15 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceEnforceDelUser001, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, CHECK_PERMISSION_FAILED); + return SUCCESS; } ) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, GENERAL_ERROR); + return SUCCESS; } ); @@ -577,7 +585,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceEnforceDelUser002, TestSize.Level0) { UserIdmService service(123123, true); int32_t testUserId = 15485; - sptr testCallback(nullptr); + sptr testCallback(nullptr); int32_t ret = service.EnforceDelUser(testUserId, testCallback); EXPECT_EQ(ret, INVALID_PARAMETERS); } @@ -633,13 +641,15 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceEnforceDelUser003, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_FAILURE); + return SUCCESS; } ) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); + return SUCCESS; } ); MockForDelUserHdi(); @@ -662,13 +672,15 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser001, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, CHECK_PERMISSION_FAILED); + return SUCCESS; } ) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_FAILURE); + return SUCCESS; } ); @@ -676,9 +688,9 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser001, TestSize.Level0) EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, DeleteUser(_, _, _, _)).WillOnce(Return(HDF_FAILURE)); - service.DelUser(testUserId, testAuthToken, testCallback); + EXPECT_EQ(service.DelUser(testUserId, testAuthToken, testCallback), CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.DelUser(testUserId, testAuthToken, testCallback); + EXPECT_EQ(service.DelUser(testUserId, testAuthToken, testCallback), HDF_FAILURE); IpcCommon::DeleteAllPermission(); } @@ -687,8 +699,8 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser002, TestSize.Level0) UserIdmService service(123123, true); int32_t testUserId = 15486465; std::vector testAuthToken = {1, 2, 3, 4}; - sptr testCallback(nullptr); - EXPECT_NO_THROW(service.DelUser(testUserId, testAuthToken, testCallback)); + sptr testCallback(nullptr); + EXPECT_EQ(service.DelUser(testUserId, testAuthToken, testCallback), INVALID_PARAMETERS); } HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser003, TestSize.Level0) @@ -700,13 +712,14 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser003, TestSize.Level0) EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); + return SUCCESS; } ); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.DelUser(testUserId, testAuthToken, testCallback); + EXPECT_EQ(service.DelUser(testUserId, testAuthToken, testCallback), SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -719,8 +732,9 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser004, TestSize.Level0) EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); + return SUCCESS; } ); @@ -743,7 +757,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser004, TestSize.Level0) ); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.DelUser(testUserId, testAuthToken, testCallback); + EXPECT_EQ(service.DelUser(testUserId, testAuthToken, testCallback), SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -759,13 +773,15 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential001, TestSize.Level0) EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, CHECK_PERMISSION_FAILED); + return SUCCESS; } ) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_FAILURE); + return SUCCESS; } ); @@ -773,9 +789,11 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential001, TestSize.Level0) EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, DeleteCredential(_, _, _, _)).WillOnce(Return(HDF_FAILURE)); - service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback); + EXPECT_EQ(service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback), + CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback); + EXPECT_EQ(service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback), + HDF_FAILURE); IpcCommon::DeleteAllPermission(); } @@ -785,8 +803,8 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential002, TestSize.Level0) int32_t testUserId = 1548865; uint64_t testCredentialId = 23424; std::vector testAuthToken = {1, 2, 3, 4}; - sptr testCallback(nullptr); - EXPECT_NO_THROW(service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback)); + sptr testCallback(nullptr); + EXPECT_EQ(service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback), INVALID_PARAMETERS); } HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential003, TestSize.Level0) @@ -800,8 +818,9 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential003, TestSize.Level0) EXPECT_NE(testCallback, nullptr); EXPECT_CALL(*testCallback, OnResult(_, _)) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, SUCCESS); + return SUCCESS; } ); @@ -821,7 +840,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential003, TestSize.Level0) ); IpcCommon::AddPermission(MANAGE_USER_IDM_PERMISSION); - service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback); + EXPECT_EQ(service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback), SUCCESS); IpcCommon::DeleteAllPermission(); } @@ -872,13 +891,15 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceClearRedundancyCredential001, TestSiz EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, CHECK_PERMISSION_FAILED); + return SUCCESS; } ) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, INVALID_HDI_INTERFACE); + return SUCCESS; } ); @@ -886,9 +907,9 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceClearRedundancyCredential001, TestSiz EXPECT_NE(mockHdi, nullptr); EXPECT_CALL(*mockHdi, GetAllExtUserInfo(_)).WillOnce(Return(HDF_FAILURE)); - service.ClearRedundancyCredential(testCallback); + EXPECT_EQ(service.ClearRedundancyCredential(testCallback), CHECK_PERMISSION_FAILED); IpcCommon::AddPermission(CLEAR_REDUNDANCY_PERMISSION); - service.ClearRedundancyCredential(testCallback); + EXPECT_EQ(service.ClearRedundancyCredential(testCallback), INVALID_HDI_INTERFACE); IpcCommon::DeleteAllPermission(); } @@ -900,13 +921,15 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceClearRedundancyCredential002, TestSiz EXPECT_CALL(*testCallback, OnResult(_, _)) .Times(2) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_SUCCESS); + return SUCCESS; } ) .WillOnce( - [](int32_t result, const Attributes &extraInfo) { + [](int32_t result, const std::vector &extraInfo) { EXPECT_EQ(result, HDF_SUCCESS); + return SUCCESS; } ); @@ -915,9 +938,7 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceClearRedundancyCredential002, TestSiz EXPECT_CALL(*mockHdi, GetAllExtUserInfo(_)) .WillRepeatedly( [](std::vector &userInfos) { - ExtUserInfo info = { - .userId = 100, - }; + ExtUserInfo info = { .userId = 100, }; userInfos.push_back(info); return HDF_SUCCESS; } @@ -941,8 +962,144 @@ HWTEST_F(UserIdmServiceTest, UserIdmServiceClearRedundancyCredential002, TestSiz ); IpcCommon::AddPermission(CLEAR_REDUNDANCY_PERMISSION); - service.ClearRedundancyCredential(testCallback); - service.ClearRedundancyCredential(testCallback); + EXPECT_EQ(service.ClearRedundancyCredential(testCallback), SUCCESS); + EXPECT_EQ(service.ClearRedundancyCredential(testCallback), SUCCESS); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceRegistEventListerner_001, TestSize.Level0) +{ + UserIdmService service(123123, true); + sptr testCallback = nullptr; + IpcCommon::AddPermission(IS_SYSTEM_APP); + EXPECT_EQ(service.RegistCredChangeEventListener(testCallback), ResultCode::INVALID_PARAMETERS); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceRegistEventListerner_003, TestSize.Level0) +{ + UserIdmService service(123123, true); + sptr testCallback = new MockEventListener(); + IpcCommon::AddPermission(IS_SYSTEM_APP); + EXPECT_EQ(service.RegistCredChangeEventListener(testCallback), + ResultCode::CHECK_PERMISSION_FAILED); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceRegistEventListerner_004, TestSize.Level0) +{ + UserIdmService service(123123, true); + sptr testCallback = new MockEventListener(); + IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); + EXPECT_EQ(service.RegistCredChangeEventListener(testCallback), ResultCode::GENERAL_ERROR); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceUnRegistEventListerner_001, TestSize.Level0) +{ + UserIdmService service(123123, true); + sptr testCallback = nullptr; + IpcCommon::AddPermission(IS_SYSTEM_APP); + EXPECT_EQ(service.UnRegistCredChangeEventListener(testCallback), ResultCode::INVALID_PARAMETERS); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceUnRegistEventListerner_002, TestSize.Level0) +{ + UserIdmService service(123123, true); + sptr testCallback = new MockEventListener(); + IpcCommon::AddPermission(IS_SYSTEM_APP); + EXPECT_EQ(service.UnRegistCredChangeEventListener(testCallback), ResultCode::CHECK_PERMISSION_FAILED); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceUnRegistEventListerner_003, TestSize.Level0) +{ + UserIdmService service(123123, true); + sptr testCallback = new MockEventListener(); + IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); + EXPECT_EQ(service.UnRegistCredChangeEventListener(testCallback), ResultCode::GENERAL_ERROR); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceUnRegistEventListerner_004, TestSize.Level0) +{ + UserIdmService service(123123, true); + sptr testCallback = new MockEventListener(); + IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); + EXPECT_EQ(service.RegistCredChangeEventListener(testCallback), ResultCode::GENERAL_ERROR); + EXPECT_EQ(service.UnRegistCredChangeEventListener(testCallback), ResultCode::GENERAL_ERROR); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfoSync001, TestSize.Level0) +{ + UserIdmService service(123123, true); + int32_t testUserId = 0; + AuthType testAuthType = PIN; + std::vector credentialInfoList; + + auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); + EXPECT_NE(mockHdi, nullptr); + EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).WillOnce(Return(HDF_FAILURE)); + int32_t ret = service.GetCredentialInfoSync(testUserId, testAuthType, credentialInfoList); + EXPECT_EQ(ret, CHECK_PERMISSION_FAILED); + IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); + ret = service.GetCredentialInfoSync(testUserId, testAuthType, credentialInfoList); + EXPECT_EQ(ret, GENERAL_ERROR); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfoSync002, TestSize.Level0) +{ + UserIdmService service(123123, true); + int32_t testUserId = 0; + AuthType testAuthType = PIN; + std::vector credentialInfoList; + + auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); + EXPECT_NE(mockHdi, nullptr); + EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1); + ON_CALL(*mockHdi, GetCredential) + .WillByDefault( + [](int32_t userId, int32_t authType, std::vector &infos) { + return HDF_SUCCESS; + } + ); + IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); + int32_t ret = service.GetCredentialInfoSync(testUserId, testAuthType, credentialInfoList); + EXPECT_EQ(ret, SUCCESS); + IpcCommon::DeleteAllPermission(); +} + +HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfoSync003, TestSize.Level0) +{ + UserIdmService service(123123, true); + int32_t testUserId = 0; + AuthType testAuthType = PIN; + std::vector credentialInfoList; + + auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get(); + EXPECT_NE(mockHdi, nullptr); + EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1); + ON_CALL(*mockHdi, GetCredential) + .WillByDefault( + [](int32_t userId, int32_t authType, std::vector &infos) { + HdiCredentialInfo tempInfo = { + .credentialId = 1, + .executorIndex = 2, + .templateId = 3, + .authType = static_cast(1), + .executorMatcher = 2, + .executorSensorHint = 3, + }; + infos.push_back(tempInfo); + return HDF_SUCCESS; + } + ); + IpcCommon::AddPermission(USE_USER_IDM_PERMISSION); + int32_t ret = service.GetCredentialInfoSync(testUserId, testAuthType, credentialInfoList); + EXPECT_EQ(ret, SUCCESS); IpcCommon::DeleteAllPermission(); } } // namespace UserAuth diff --git a/test/unittest/services/src/user_idm_stub_test.cpp b/test/unittest/services/src/user_idm_stub_test.cpp deleted file mode 100644 index 19b7ae27d26b2f7abd8aae252e11b0b6b0560082..0000000000000000000000000000000000000000 --- a/test/unittest/services/src/user_idm_stub_test.cpp +++ /dev/null @@ -1,550 +0,0 @@ -/* - * Copyright (C) 2022-2023 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "user_idm_stub_test.h" - -#include "credential_info_interface.h" -#include "iam_common_defines.h" -#include "securec.h" -#include "user_idm_callback_proxy.h" -#include "user_idm_stub.h" - -#include "mock_secure_user_info.h" -#include "mock_user_idm_callback.h" -#include "mock_user_idm_service.h" - -namespace OHOS { -namespace UserIam { -namespace UserAuth { -using namespace testing; -using namespace testing::ext; - -void UserIdmStubTest::SetUpTestCase() -{ -} - -void UserIdmStubTest::TearDownTestCase() -{ -} - -void UserIdmStubTest::SetUp() -{ -} - -void UserIdmStubTest::TearDown() -{ -} - -HWTEST_F(UserIdmStubTest, UserIdmStubOpenSessionStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_OPEN_SESSION; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubOpenSessionStub002, TestSize.Level0) -{ - int32_t testUserId = 887436; - std::vector testChallenge = {1, 2, 8, 4}; - - MockUserIdmService service; - EXPECT_CALL(service, OpenSession(_, _)).Times(1); - ON_CALL(service, OpenSession) - .WillByDefault( - [&testUserId, &testChallenge](int32_t userId, std::vector &challenge) { - EXPECT_EQ(userId, testUserId); - challenge = testChallenge; - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_OPEN_SESSION; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - - std::vector challenge; - EXPECT_TRUE(reply.ReadUInt8Vector(&challenge)); - EXPECT_THAT(challenge, ElementsAreArray(testChallenge)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubCloseSessionStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_CLOSE_SESSION; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubCloseSessionStub002, TestSize.Level0) -{ - int32_t testUserId = 887436; - - MockUserIdmService service; - EXPECT_CALL(service, CloseSession(_)).Times(1); - ON_CALL(service, CloseSession) - .WillByDefault( - [&testUserId](int32_t userId) { - EXPECT_EQ(userId, testUserId); - return; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_CLOSE_SESSION; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubGetCredentialInfoStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_CRED_INFO; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubGetCredentialInfoStub002, TestSize.Level0) -{ - int32_t testUserId = 76255; - AuthType testAuthType = FACE; - - sptr callback(new (std::nothrow) MockIdmGetCredentialInfoCallback()); - EXPECT_NE(callback, nullptr); - MockUserIdmService service; - EXPECT_CALL(service, GetCredentialInfo(_, _, _)).Times(1); - ON_CALL(service, GetCredentialInfo) - .WillByDefault( - [&testUserId, &testAuthType](int32_t userId, AuthType authType, - const sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(authType, testAuthType); - if (callback != nullptr) { - std::vector credInfoList; - callback->OnCredentialInfos(SUCCESS, credInfoList); - } - return SUCCESS; - } - ); - EXPECT_CALL(*callback, OnCredentialInfos(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_CRED_INFO; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUint32(testAuthType)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubGetSecInfoStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_SEC_INFO; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubGetSecInfoStub002, TestSize.Level0) -{ - int32_t testUserId = 87463; - - sptr callback(new (std::nothrow) MockIdmGetSecureUserInfoCallback()); - EXPECT_NE(callback, nullptr); - MockUserIdmService service; - EXPECT_CALL(service, GetSecInfo(_, _)).Times(1); - ON_CALL(service, GetSecInfo) - .WillByDefault( - [&testUserId](int32_t userId, const sptr &callback) { - EXPECT_EQ(userId, testUserId); - if (callback != nullptr) { - SecUserInfo secUserInfo = {}; - int32_t result = 0; - callback->OnSecureUserInfo(result, secUserInfo); - } - return SUCCESS; - } - ); - EXPECT_CALL(*callback, OnSecureUserInfo(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_SEC_INFO; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub002, TestSize.Level0) -{ - int32_t testUserId = 753662; - UserIdmInterface::CredentialPara testCredPara = {}; - testCredPara.authType = FACE; - testCredPara.pinType = PIN_SIX; - testCredPara.token = {2, 4, 6, 8}; - - sptr callback(new (std::nothrow) MockIdmCallback()); - EXPECT_NE(callback, nullptr); - MockUserIdmService service; - EXPECT_CALL(service, AddCredential(_, _, _, _)).Times(1); - ON_CALL(service, AddCredential) - .WillByDefault( - [&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara, - const sptr &callback, bool isUpdate) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(credPara.authType, testCredPara.authType); - EXPECT_EQ(credPara.pinType, testCredPara.pinType); - EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token)); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteInt32(testCredPara.authType)); - EXPECT_TRUE(data.WriteInt32(testCredPara.pinType)); - EXPECT_TRUE(data.WriteUInt8Vector(testCredPara.token)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub002, TestSize.Level0) -{ - int32_t testUserId = 63526; - UserIdmInterface::CredentialPara testCredPara = {}; - testCredPara.authType = PIN; - testCredPara.pinType = PIN_SIX; - testCredPara.token = {1, 2, 4, 6, 8}; - - const sptr callback(new (std::nothrow) MockIdmCallback()); - EXPECT_NE(callback, nullptr); - MockUserIdmService service; - EXPECT_CALL(service, UpdateCredential(_, _, _)).Times(1); - ON_CALL(service, UpdateCredential) - .WillByDefault( - [&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara, - const sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(credPara.authType, testCredPara.authType); - EXPECT_EQ(credPara.pinType, testCredPara.pinType); - EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token)); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteInt32(testCredPara.authType)); - EXPECT_TRUE(data.WriteInt32(testCredPara.pinType)); - EXPECT_TRUE(data.WriteUInt8Vector(testCredPara.token)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_CANCEL; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub002, TestSize.Level0) -{ - int32_t testUserId = 725345; - - MockUserIdmService service; - EXPECT_CALL(service, Cancel(_)).Times(1); - ON_CALL(service, Cancel) - .WillByDefault( - [&testUserId](int32_t userId) { - EXPECT_EQ(userId, testUserId); - return SUCCESS; - } - ); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_CANCEL; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub002, TestSize.Level0) -{ - int32_t testUserId = 83462; - - sptr callback(new (std::nothrow) MockIdmCallback()); - EXPECT_NE(callback, nullptr); - MockUserIdmService service; - EXPECT_CALL(service, EnforceDelUser(_, _)).Times(1); - ON_CALL(service, EnforceDelUser) - .WillByDefault( - [&testUserId](int32_t userId, const sptr &callback) { - EXPECT_EQ(userId, testUserId); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - return SUCCESS; - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); - - int32_t result = FAIL; - EXPECT_TRUE(reply.ReadInt32(result)); - EXPECT_EQ(result, SUCCESS); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_USER; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub002, TestSize.Level0) -{ - int32_t testUserId = 72342; - std::vector testAuthToken = {1, 3, 5, 7}; - - sptr callback(new (std::nothrow) MockIdmCallback()); - EXPECT_NE(callback, nullptr); - MockUserIdmService service; - EXPECT_CALL(service, DelUser(_, _, _)).Times(1); - ON_CALL(service, DelUser) - .WillByDefault( - [&testUserId, &testAuthToken](int32_t userId, const std::vector authToken, - const sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_THAT(authToken, ElementsAreArray(testAuthToken)); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_USER; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUInt8Vector(testAuthToken)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub001, TestSize.Level0) -{ - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_CRED; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - - MockUserIdmService service; - EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option)); -} - -HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub002, TestSize.Level0) -{ - int32_t testUserId = 93261; - uint64_t testCredentialId = 72632; - std::vector testAuthToken = {3, 5, 7, 9}; - - sptr callback(new (std::nothrow) MockIdmCallback()); - EXPECT_NE(callback, nullptr); - MockUserIdmService service; - EXPECT_CALL(service, DelCredential(_, _, _, _)).Times(1); - ON_CALL(service, DelCredential) - .WillByDefault( - [&testUserId, &testCredentialId, &testAuthToken](int32_t userId, uint64_t credentialId, - const std::vector &authToken, const sptr &callback) { - EXPECT_EQ(userId, testUserId); - EXPECT_EQ(credentialId, testCredentialId); - EXPECT_THAT(authToken, ElementsAreArray(testAuthToken)); - if (callback != nullptr) { - Attributes attr; - callback->OnResult(SUCCESS, attr); - } - } - ); - EXPECT_CALL(*callback, OnResult(_, _)).Times(1); - - MessageParcel data; - MessageParcel reply; - MessageOption option(MessageOption::TF_SYNC); - uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_CRED; - - EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor())); - EXPECT_TRUE(data.WriteInt32(testUserId)); - EXPECT_TRUE(data.WriteUint64(testCredentialId)); - EXPECT_TRUE(data.WriteUInt8Vector(testAuthToken)); - EXPECT_NE(callback->AsObject(), nullptr); - EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject())); - - EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option)); -} -} // namespace UserAuth -} // namespace UserIam -} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/services/src/widget_client_test.cpp b/test/unittest/services/src/widget_client_test.cpp index cc793fb61cd8ca9fb5c40cadc3952e868a0bfce3..c1828ca1291c660fe9366e065369d7e85c6af893 100644 --- a/test/unittest/services/src/widget_client_test.cpp +++ b/test/unittest/services/src/widget_client_test.cpp @@ -16,11 +16,12 @@ #include "widget_client.h" #include +#include "iam_callback_proxy.h" #include "auth_common.h" #include "iam_check.h" #include "iam_ptr.h" #include "widget_json.h" -#include "widget_callback_interface.h" +#include "iwidget_callback.h" #include "mock_authentication.h" #include "mock_context.h" @@ -29,7 +30,6 @@ #include "mock_widget_schedule_node.h" #include "mock_widget_callback_interface.h" #include "schedule_node_impl.h" -#include "user_auth_callback_proxy.h" #include "widget_schedule_node.h" #include "widget_callback_proxy.h" @@ -105,7 +105,7 @@ HWTEST_F(WidgetClientTest, WidgetClientTestSetWidgetParam, TestSize.Level0) HWTEST_F(WidgetClientTest, WidgetClientTestSetWidgetCallback, TestSize.Level0) { - sptr testCallback = nullptr; + sptr testCallback = nullptr; WidgetClient::Instance().SetWidgetCallback(testCallback); EXPECT_EQ(testCallback, nullptr); } @@ -388,7 +388,7 @@ HWTEST_F(WidgetClientTest, WidgetClientTestReportWidgetResult_0005, TestSize.Lev authTypeList.emplace_back(AuthType::PIN); WidgetClient::Instance().SetAuthTypeList(authTypeList); WidgetClient::Instance().SetPinSubType(PinSubType::PIN_NUMBER); - sptr widgetCallback(new (std::nothrow) MockWidgetCallbackInterface); + sptr widgetCallback(new (std::nothrow) MockIWidgetCallback); EXPECT_NE(widgetCallback, nullptr); EXPECT_CALL(*widgetCallback, SendCommand); WidgetClient::Instance().SetWidgetCallback(widgetCallback); diff --git a/test/unittest/services/src/widget_context_callback_impl_test.cpp b/test/unittest/services/src/widget_context_callback_impl_test.cpp index b7994fac3fd935a94f61fdb6bccc9336c2b61328..ba55b90d04378df9f148b6c427186f886b514494 100644 --- a/test/unittest/services/src/widget_context_callback_impl_test.cpp +++ b/test/unittest/services/src/widget_context_callback_impl_test.cpp @@ -67,7 +67,7 @@ HWTEST_F(WidgetContextCallbackImplTest, WidgetContextCallbackImplOnResult_001, T ASSERT_NE(contextCallback, nullptr); int32_t result = 1; Attributes extraInfo; - contextCallback->OnResult(result, extraInfo); + contextCallback->OnResult(result, extraInfo.Serialize()); ASSERT_EQ(para.tokenId, 0); } @@ -79,7 +79,7 @@ HWTEST_F(WidgetContextCallbackImplTest, WidgetContextCallbackImplOnResult_002, T ASSERT_NE(contextCallback, nullptr); int32_t result = 1; Attributes extraInfo; - contextCallback->OnResult(result, extraInfo); + contextCallback->OnResult(result, extraInfo.Serialize()); } HWTEST_F(WidgetContextCallbackImplTest, WidgetContextCallbackImplOnAcquireInfo_003, TestSize.Level0) @@ -96,7 +96,7 @@ HWTEST_F(WidgetContextCallbackImplTest, WidgetContextCallbackImplOnAcquireInfo_0 int32_t module = 0; int32_t acquireInfo = 0; Attributes extraInfo; - contextCallback->OnAcquireInfo(module, acquireInfo, extraInfo); + contextCallback->OnAcquireInfo(module, acquireInfo, extraInfo.Serialize()); sptr object = contextCallback->AsObject(); EXPECT_EQ(object, nullptr); diff --git a/test/unittest/services/src/widget_schedule_node_impl_test.cpp b/test/unittest/services/src/widget_schedule_node_impl_test.cpp index df2096349288867963fd378bade23f0e32e4b4cf..0c2831c309794d3c7695b4c96ccc9eaca1410c12 100644 --- a/test/unittest/services/src/widget_schedule_node_impl_test.cpp +++ b/test/unittest/services/src/widget_schedule_node_impl_test.cpp @@ -20,7 +20,6 @@ #include "mock_widget_schedule_node_callback.h" #include "mock_context.h" -#include "widget_context.h" #include "iam_ptr.h" #include "relative_timer.h" diff --git a/user_auth_icon/library/src/main/ets/components/mainpage/UserAuthIcon.ets b/user_auth_icon/library/src/main/ets/components/mainpage/UserAuthIcon.ets index e6cb0211ed680afa742eafa5efc08be747daf20b..67193151ddc724472e07348ff23833c54141de9a 100644 --- a/user_auth_icon/library/src/main/ets/components/mainpage/UserAuthIcon.ets +++ b/user_auth_icon/library/src/main/ets/components/mainpage/UserAuthIcon.ets @@ -188,51 +188,53 @@ export struct UserAuthIcon { this.info(`after init image source, imageSource = ${this.imageSource}.`); } + onclick(): void { + this.info('start handle click event.'); + if (this.onIconClick !== undefined) { + this.info('click event has response.'); + this.onIconClick(); + } + if (this.authFlag === ICON_AVAILABLE) { + try { + let userAuthInstance: userAuth.UserAuthInstance = + userAuth.getUserAuthInstance(this.authParam, this.widgetParam); + let timer: number = setTimeout(() => { + this.error('auth timeout.'); + userAuthInstance.cancel(); + this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); + }, TIMEOUT_MILLISECONDS) + this.info('get userAuth instance success.'); + userAuthInstance.on('result', { + onResult: (result) => { + this.info(`userAuthInstance callback result = ${JSON.stringify(result)}.`); + this.onAuthResult(result); + userAuthInstance.off('result'); + } + }); + this.info('auth before start.'); + userAuthInstance.start(); + this.info('auth start success.'); + clearTimeout(timer); + } catch (error) { + if (error) { + this.error(`auth catch error, code: ${error.code}, message: ${error.message}`); + this.onAuthResult({ result: error.code }); + return; + } + this.error('auth error.'); + this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); + } + } + this.info('end handle click event.'); + } + build() { Row() { Column() { SymbolGlyph($r(this.imageSource)) .fontSize(this.iconHeight) .fontColor([this.iconColor]) - .onClick(() => { - this.info('start handle click event.'); - if (this.onIconClick !== undefined) { - this.info('click event has response.'); - this.onIconClick(); - } - if (this.authFlag === ICON_AVAILABLE) { - try { - let userAuthInstance: userAuth.UserAuthInstance = - userAuth.getUserAuthInstance(this.authParam, this.widgetParam); - let timer: number = setTimeout(() => { - this.error('auth timeout.'); - userAuthInstance.cancel(); - this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); - }, TIMEOUT_MILLISECONDS) - this.info('get userAuth instance success.'); - userAuthInstance.on('result', { - onResult: (result) => { - this.info(`userAuthInstance callback result = ${JSON.stringify(result)}.`); - this.onAuthResult(result); - userAuthInstance.off('result'); - } - }); - this.info('auth before start.'); - userAuthInstance.start(); - this.info('auth start success.'); - clearTimeout(timer); - } catch (error) { - if (error) { - this.error(`auth catch error, code: ${error.code}, message: ${error.message}`); - this.onAuthResult({ result: error.code }); - return; - } - this.error('auth error.'); - this.onAuthResult({ result: userAuth.UserAuthResultCode.GENERAL_ERROR }); - } - } - this.info('end handle click event.'); - }) + .onClick(() => this.onclick()) } } }