mirror of
https://gitee.com/openharmony/useriam_user_auth_framework
synced 2024-11-23 15:49:52 +00:00
add tdd code
Signed-off-by: youliang_1314 <youliang4@huawei.com> Change-Id: I2f7e528301e0adeae1942da3e6532535e27845eb
This commit is contained in:
parent
bed618c47d
commit
a3e4a5baa8
@ -51,7 +51,8 @@
|
||||
"//base/useriam/user_auth_framework/sa_profile:useriam.init",
|
||||
"//base/useriam/user_auth_framework/services:userauthservice",
|
||||
"//base/useriam/user_auth_framework/common/executors:userauth_executors",
|
||||
"//base/useriam/user_auth_framework/sa_profile:userauth_sa_profile"
|
||||
"//base/useriam/user_auth_framework/sa_profile:userauth_sa_profile",
|
||||
"//base/useriam/user_auth_framework/param:param_files"
|
||||
]
|
||||
},
|
||||
"inner_kits": [
|
||||
|
@ -57,7 +57,7 @@ public:
|
||||
explicit HdiServiceStatusListener(StatusCallback callback) : callback_(std::move(callback))
|
||||
{
|
||||
}
|
||||
virtual ~HdiServiceStatusListener() = default;
|
||||
~HdiServiceStatusListener() override = default;
|
||||
void OnReceive(const ServiceStatus &status) override
|
||||
{
|
||||
callback_(status);
|
||||
|
@ -40,51 +40,51 @@ namespace Common {
|
||||
using HiLogLabel = OHOS::HiviewDFX::HiLogLabel;
|
||||
|
||||
// common
|
||||
static constexpr unsigned int IAM_DOMAIN_ID_COMMON = 0xD002400;
|
||||
static constexpr HiLogLabel LABEL_IAM_COMMON = {LOG_CORE, IAM_DOMAIN_ID_COMMON, "IAM_COMMON"};
|
||||
constexpr unsigned int IAM_DOMAIN_ID_COMMON = 0xD002400;
|
||||
constexpr HiLogLabel LABEL_IAM_COMMON = {LOG_CORE, IAM_DOMAIN_ID_COMMON, "IAM_COMMON"};
|
||||
|
||||
// user idm
|
||||
static constexpr unsigned int IAM_DOMAIN_ID_IDM = 0xD002401;
|
||||
static constexpr HiLogLabel LABEL_USER_IDM_NAPI = {LOG_CORE, IAM_DOMAIN_ID_IDM, "USER_IDM_NAPI"};
|
||||
static constexpr HiLogLabel LABEL_USER_IDM_SDK = {LOG_CORE, IAM_DOMAIN_ID_IDM, "USER_IDM_SDK"};
|
||||
static constexpr HiLogLabel LABEL_USER_IDM_SA = {LOG_CORE, IAM_DOMAIN_ID_IDM, "USER_IDM_SA"};
|
||||
constexpr unsigned int IAM_DOMAIN_ID_IDM = 0xD002401;
|
||||
constexpr HiLogLabel LABEL_USER_IDM_NAPI = {LOG_CORE, IAM_DOMAIN_ID_IDM, "USER_IDM_NAPI"};
|
||||
constexpr HiLogLabel LABEL_USER_IDM_SDK = {LOG_CORE, IAM_DOMAIN_ID_IDM, "USER_IDM_SDK"};
|
||||
constexpr HiLogLabel LABEL_USER_IDM_SA = {LOG_CORE, IAM_DOMAIN_ID_IDM, "USER_IDM_SA"};
|
||||
|
||||
// user auth
|
||||
static constexpr unsigned int IAM_DOMAIN_ID_USER = 0xD002421;
|
||||
static constexpr HiLogLabel LABEL_USER_AUTH_NAPI = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_NAPI"};
|
||||
static constexpr HiLogLabel LABEL_USER_AUTH_SDK = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_SDK"};
|
||||
static constexpr HiLogLabel LABEL_USER_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_SA"};
|
||||
static constexpr HiLogLabel LABEL_USER_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_HDI"};
|
||||
static constexpr HiLogLabel LABEL_USER_AUTH_EXECUTOR = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_EXECUTOR"};
|
||||
constexpr unsigned int IAM_DOMAIN_ID_USER = 0xD002421;
|
||||
constexpr HiLogLabel LABEL_USER_AUTH_NAPI = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_NAPI"};
|
||||
constexpr HiLogLabel LABEL_USER_AUTH_SDK = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_SDK"};
|
||||
constexpr HiLogLabel LABEL_USER_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_SA"};
|
||||
constexpr HiLogLabel LABEL_USER_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_HDI"};
|
||||
constexpr HiLogLabel LABEL_USER_AUTH_EXECUTOR = {LOG_CORE, IAM_DOMAIN_ID_USER, "USER_AUTH_EXECUTOR"};
|
||||
|
||||
// auth executor manager
|
||||
static constexpr unsigned int IAM_DOMAIN_ID_AUTH_EXECUTOR_MGR = 0xD002431;
|
||||
static constexpr HiLogLabel LABEL_AUTH_EXECUTOR_MGR_SDK = {
|
||||
constexpr unsigned int IAM_DOMAIN_ID_AUTH_EXECUTOR_MGR = 0xD002431;
|
||||
constexpr HiLogLabel LABEL_AUTH_EXECUTOR_MGR_SDK = {
|
||||
LOG_CORE, IAM_DOMAIN_ID_AUTH_EXECUTOR_MGR, "AUTH_EXECUTOR_MGR_SDK"};
|
||||
static constexpr HiLogLabel LABEL_AUTH_EXECUTOR_MGR_SA = {
|
||||
constexpr HiLogLabel LABEL_AUTH_EXECUTOR_MGR_SA = {
|
||||
LOG_CORE, IAM_DOMAIN_ID_AUTH_EXECUTOR_MGR, "AUTH_EXECUTOR_MGR_SA"};
|
||||
|
||||
// pin
|
||||
static constexpr unsigned int IAM_DOMAIN_ID_PIN = 0xD002441;
|
||||
static constexpr HiLogLabel LABEL_PIN_AUTH_NAPI = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_NAPI"};
|
||||
static constexpr HiLogLabel LABEL_PIN_AUTH_SDK = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_SDK"};
|
||||
static constexpr HiLogLabel LABEL_PIN_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_SA"};
|
||||
static constexpr HiLogLabel LABEL_PIN_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_HDI"};
|
||||
static constexpr HiLogLabel LABEL_PIN_AUTH_IMPL = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_IMPL"};
|
||||
constexpr unsigned int IAM_DOMAIN_ID_PIN = 0xD002441;
|
||||
constexpr HiLogLabel LABEL_PIN_AUTH_NAPI = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_NAPI"};
|
||||
constexpr HiLogLabel LABEL_PIN_AUTH_SDK = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_SDK"};
|
||||
constexpr HiLogLabel LABEL_PIN_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_SA"};
|
||||
constexpr HiLogLabel LABEL_PIN_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_HDI"};
|
||||
constexpr HiLogLabel LABEL_PIN_AUTH_IMPL = {LOG_CORE, IAM_DOMAIN_ID_PIN, "PIN_AUTH_IMPL"};
|
||||
|
||||
// face
|
||||
static constexpr unsigned int IAM_DOMAIN_ID_FACE = 0xD002442;
|
||||
static constexpr HiLogLabel LABEL_FACE_AUTH_NAPI = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_NAPI"};
|
||||
static constexpr HiLogLabel LABEL_FACE_AUTH_SDK = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_SDK"};
|
||||
static constexpr HiLogLabel LABEL_FACE_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_SA"};
|
||||
static constexpr HiLogLabel LABEL_FACE_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_HDI"};
|
||||
static constexpr HiLogLabel LABEL_FACE_AUTH_IMPL = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_IMPL"};
|
||||
constexpr unsigned int IAM_DOMAIN_ID_FACE = 0xD002442;
|
||||
constexpr HiLogLabel LABEL_FACE_AUTH_NAPI = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_NAPI"};
|
||||
constexpr HiLogLabel LABEL_FACE_AUTH_SDK = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_SDK"};
|
||||
constexpr HiLogLabel LABEL_FACE_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_SA"};
|
||||
constexpr HiLogLabel LABEL_FACE_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_HDI"};
|
||||
constexpr HiLogLabel LABEL_FACE_AUTH_IMPL = {LOG_CORE, IAM_DOMAIN_ID_FACE, "FACE_AUTH_IMPL"};
|
||||
|
||||
// fingerprint
|
||||
static constexpr unsigned int IAM_DOMAIN_ID_FINGERPRINT = 0xD002443;
|
||||
static constexpr HiLogLabel LABEL_FINGERPRINT_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_FINGERPRINT, "FINGERPRINT_AUTH_SA"};
|
||||
static constexpr HiLogLabel LABEL_FINGERPRINT_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_FINGERPRINT, "FINGERPRINT_AUTH_HDI"};
|
||||
static constexpr HiLogLabel LABEL_FINGERPRINT_AUTH_IMPL = {
|
||||
constexpr unsigned int IAM_DOMAIN_ID_FINGERPRINT = 0xD002443;
|
||||
constexpr HiLogLabel LABEL_FINGERPRINT_AUTH_SA = {LOG_CORE, IAM_DOMAIN_ID_FINGERPRINT, "FINGERPRINT_AUTH_SA"};
|
||||
constexpr HiLogLabel LABEL_FINGERPRINT_AUTH_HDI = {LOG_CORE, IAM_DOMAIN_ID_FINGERPRINT, "FINGERPRINT_AUTH_HDI"};
|
||||
constexpr HiLogLabel LABEL_FINGERPRINT_AUTH_IMPL = {
|
||||
LOG_CORE, IAM_DOMAIN_ID_FINGERPRINT, "FINGERPRINT_AUTH_IMPL"};
|
||||
} // namespace Common
|
||||
} // namespace UserIam
|
||||
|
@ -43,7 +43,7 @@ private:
|
||||
ExitAction action_;
|
||||
};
|
||||
|
||||
#define ON_SCOPE_EXIT_ID(id, ...) auto exitGuard##id = OHOS::UserIam::Common::IamScopeGuard([&]() { __VA_ARGS__; })
|
||||
#define ON_SCOPE_EXIT_ID(id, ...) auto exitGuard##id = OHOS::UserIam::Common::IamScopeGuard([]() { __VA_ARGS__; })
|
||||
|
||||
#define ON_SCOPE_EXIT(...) ON_SCOPE_EXIT_ID(__LINE__, __VA_ARGS__)
|
||||
} // namespace Common
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
static ResultCodeV9 GetAvailableStatus(napi_env env, napi_callback_info info);
|
||||
|
||||
explicit AuthInstanceV9(napi_env env);
|
||||
~AuthInstanceV9() = default;
|
||||
~AuthInstanceV9() override = default;
|
||||
|
||||
ResultCodeV9 Init(napi_env env, napi_callback_info info);
|
||||
ResultCodeV9 On(napi_env env, napi_callback_info info);
|
||||
|
@ -30,7 +30,7 @@ class UserAuthCallbackV6 : public std::enable_shared_from_this<UserAuthCallbackV
|
||||
public AuthenticationCallback {
|
||||
public:
|
||||
UserAuthCallbackV6(napi_env env, const std::shared_ptr<JsRefHolder> &callback, napi_deferred promise);
|
||||
virtual ~UserAuthCallbackV6();
|
||||
~UserAuthCallbackV6() override;
|
||||
void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override;
|
||||
void OnResult(int32_t result, const Attributes &extraInfo) override;
|
||||
|
||||
|
@ -31,7 +31,7 @@ class UserAuthCallbackV8 : public std::enable_shared_from_this<UserAuthCallbackV
|
||||
public:
|
||||
UserAuthCallbackV8(napi_env env,
|
||||
const std::shared_ptr<JsRefHolder> &resultCallback, const std::shared_ptr<JsRefHolder> &acquireCallback);
|
||||
virtual ~UserAuthCallbackV8();
|
||||
~UserAuthCallbackV8() override;
|
||||
void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override;
|
||||
void OnResult(int32_t result, const Attributes &extraInfo) override;
|
||||
|
||||
|
@ -32,7 +32,7 @@ class UserAuthCallbackV9 : public std::enable_shared_from_this<UserAuthCallbackV
|
||||
public AuthenticationCallback {
|
||||
public:
|
||||
explicit UserAuthCallbackV9(napi_env env);
|
||||
virtual ~UserAuthCallbackV9();
|
||||
~UserAuthCallbackV9() override;
|
||||
void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override;
|
||||
void OnResult(int32_t result, const Attributes &extraInfo) override;
|
||||
|
||||
|
@ -53,7 +53,7 @@ private:
|
||||
class JsRefHolder : public NoCopyable {
|
||||
public:
|
||||
JsRefHolder(napi_env env, napi_value value);
|
||||
~JsRefHolder();
|
||||
~JsRefHolder() override;
|
||||
bool IsValid() const;
|
||||
napi_ref Get() const;
|
||||
|
||||
|
@ -375,42 +375,42 @@ napi_value ResultCodeV9Constructor(napi_env env)
|
||||
napi_value AuthenticationResultConstructor(napi_env env)
|
||||
{
|
||||
napi_value resultCode = nullptr;
|
||||
napi_value no_support = nullptr;
|
||||
napi_value noSupport = nullptr;
|
||||
napi_value success = nullptr;
|
||||
napi_value compare_failure = nullptr;
|
||||
napi_value compareFailure = nullptr;
|
||||
napi_value canceled = nullptr;
|
||||
napi_value timeout = nullptr;
|
||||
napi_value camera_fail = nullptr;
|
||||
napi_value cameraFail = nullptr;
|
||||
napi_value busy = nullptr;
|
||||
napi_value invalid_parameters = nullptr;
|
||||
napi_value invalidParameters = nullptr;
|
||||
napi_value locked = nullptr;
|
||||
napi_value not_enrolled = nullptr;
|
||||
napi_value general_error = nullptr;
|
||||
napi_value notEnrolled = nullptr;
|
||||
napi_value generalError = nullptr;
|
||||
NAPI_CALL(env, napi_create_object(env, &resultCode));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::NO_SUPPORT), &no_support));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::NO_SUPPORT), &noSupport));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::SUCCESS), &success));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::COMPARE_FAILURE),
|
||||
&compare_failure));
|
||||
&compareFailure));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::CANCELED), &canceled));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::TIMEOUT), &timeout));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::CAMERA_FAIL), &camera_fail));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::CAMERA_FAIL), &cameraFail));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::BUSY), &busy));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::INVALID_PARAMETERS),
|
||||
&invalid_parameters));
|
||||
&invalidParameters));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::LOCKED), &locked));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::NOT_ENROLLED), ¬_enrolled));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::GENERAL_ERROR), &general_error));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "NO_SUPPORT", no_support));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::NOT_ENROLLED), ¬Enrolled));
|
||||
NAPI_CALL(env, napi_create_int32(env, static_cast<int32_t>(AuthenticationResult::GENERAL_ERROR), &generalError));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "NO_SUPPORT", noSupport));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "SUCCESS", success));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "COMPARE_FAILURE", compare_failure));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "COMPARE_FAILURE", compareFailure));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "CANCELED", canceled));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "TIMEOUT", timeout));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "CAMERA_FAIL", camera_fail));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "CAMERA_FAIL", cameraFail));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "BUSY", busy));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "INVALID_PARAMETERS", invalid_parameters));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "INVALID_PARAMETERS", invalidParameters));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "LOCKED", locked));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "NOT_ENROLLED", not_enrolled));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "GENERAL_ERROR", general_error));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "NOT_ENROLLED", notEnrolled));
|
||||
NAPI_CALL(env, napi_set_named_property(env, resultCode, "GENERAL_ERROR", generalError));
|
||||
return resultCode;
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,7 @@ napi_status UserAuthNapiHelper::CallVoidNapiFunc(napi_env env, napi_ref funcRef,
|
||||
|
||||
napi_status UserAuthNapiHelper::SetInt32Property(napi_env env, napi_value obj, const char *name, int32_t value)
|
||||
{
|
||||
napi_value napiValue = 0;
|
||||
napi_value napiValue = nullptr;
|
||||
napi_status ret = napi_create_int32(env, value, &napiValue);
|
||||
if (ret != napi_ok) {
|
||||
IAM_LOGE("napi_create_int32 failed %{public}d", ret);
|
||||
@ -356,7 +356,7 @@ napi_status UserAuthNapiHelper::SetInt32Property(napi_env env, napi_value obj, c
|
||||
|
||||
napi_status UserAuthNapiHelper::SetUint32Property(napi_env env, napi_value obj, const char *name, uint32_t value)
|
||||
{
|
||||
napi_value napiValue = 0;
|
||||
napi_value napiValue = nullptr;
|
||||
napi_status ret = napi_create_uint32(env, value, &napiValue);
|
||||
if (ret != napi_ok) {
|
||||
IAM_LOGE("napi_create_uint32 failed %{public}d", ret);
|
||||
|
@ -24,7 +24,7 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ExecutorMessengerClient final : public ExecutorMessenger {
|
||||
public:
|
||||
ExecutorMessengerClient(const sptr<ExecutorMessengerInterface> &messenger);
|
||||
explicit ExecutorMessengerClient(const sptr<ExecutorMessengerInterface> &messenger);
|
||||
int32_t SendData(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole, ExecutorRole dstRole,
|
||||
const std::shared_ptr<AuthMessage> &msg) override;
|
||||
int32_t Finish(uint64_t scheduleId, ExecutorRole srcRole, int32_t resultCode,
|
||||
|
@ -56,6 +56,11 @@ IdmGetCredInfoCallbackService::IdmGetCredInfoCallbackService(
|
||||
void IdmGetCredInfoCallbackService::OnCredentialInfos(const std::vector<std::shared_ptr<CredentialInfo>> infoList,
|
||||
const std::optional<PinSubType> pinSubType)
|
||||
{
|
||||
if (getCredInfoCallback_ == nullptr) {
|
||||
IAM_LOGE("getCredInfoCallback is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<UserAuth::CredentialInfo> credInfoList;
|
||||
for (const auto &it : infoList) {
|
||||
if (it == nullptr) {
|
||||
|
@ -76,7 +76,11 @@ void UserIdmClientImpl::AddCredential(int32_t userId, const CredentialParameters
|
||||
callback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return;
|
||||
}
|
||||
proxy->AddCredential(userId, para.authType, para.pinType.value_or(PIN_SIX), para.token, wrapper, false);
|
||||
UserIdmInterface::CredentialPara credPara = {};
|
||||
credPara.authType = para.authType;
|
||||
credPara.pinType = para.pinType.value_or(PIN_SIX);
|
||||
credPara.token = std::move(para.token);
|
||||
proxy->AddCredential(userId, credPara, wrapper, false);
|
||||
}
|
||||
|
||||
void UserIdmClientImpl::UpdateCredential(int32_t userId, const CredentialParameters ¶,
|
||||
@ -101,7 +105,11 @@ void UserIdmClientImpl::UpdateCredential(int32_t userId, const CredentialParamet
|
||||
callback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return;
|
||||
}
|
||||
proxy->UpdateCredential(userId, para.authType, para.pinType.value_or(PIN_SIX), para.token, wrapper);
|
||||
UserIdmInterface::CredentialPara credPara = {};
|
||||
credPara.authType = para.authType;
|
||||
credPara.pinType = para.pinType.value_or(PIN_SIX);
|
||||
credPara.token = std::move(para.token);
|
||||
proxy->UpdateCredential(userId, credPara, wrapper);
|
||||
}
|
||||
|
||||
int32_t UserIdmClientImpl::Cancel(int32_t userId)
|
||||
|
@ -39,6 +39,12 @@ public:
|
||||
USER_IDM_DEL_CRED,
|
||||
};
|
||||
|
||||
struct CredentialPara {
|
||||
AuthType authType {ALL};
|
||||
PinSubType pinType {PIN_SIX};
|
||||
std::vector<uint8_t> token;
|
||||
};
|
||||
|
||||
/*
|
||||
* start an IDM operation to obtain challenge value, a challenge value of 0 indicates that open session failed.
|
||||
*
|
||||
@ -82,8 +88,8 @@ public:
|
||||
* (credential type, subtype, password authentication token).
|
||||
* param callback get results / acquire info callback.
|
||||
*/
|
||||
virtual void AddCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate) = 0;
|
||||
virtual void AddCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback, bool isUpdate) = 0;
|
||||
/*
|
||||
* update user credential information.
|
||||
*
|
||||
@ -92,8 +98,8 @@ public:
|
||||
* (credential type, subtype, password authentication token).
|
||||
* param callback update results / acquire info callback.
|
||||
*/
|
||||
virtual void UpdateCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback) = 0;
|
||||
virtual void UpdateCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback) = 0;
|
||||
|
||||
/*
|
||||
* Cancel entry and pass in user id.
|
||||
|
@ -33,10 +33,10 @@ public:
|
||||
int32_t GetCredentialInfo(int32_t userId, AuthType authType,
|
||||
const sptr<IdmGetCredInfoCallbackInterface> &callback) override;
|
||||
int32_t GetSecInfo(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) override;
|
||||
void AddCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate) override;
|
||||
void UpdateCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback) override;
|
||||
void AddCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback, bool isUpdate) override;
|
||||
void UpdateCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback) override;
|
||||
int32_t Cancel(int32_t userId) override;
|
||||
int32_t EnforceDelUser(int32_t userId, const sptr<IdmCallbackInterface> &callback) override;
|
||||
void DelUser(int32_t userId, const std::vector<uint8_t> authToken,
|
||||
|
@ -142,8 +142,8 @@ int32_t UserIdmProxy::GetSecInfo(int32_t userId, const sptr<IdmGetSecureUserInfo
|
||||
return result;
|
||||
}
|
||||
|
||||
void UserIdmProxy::AddCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate)
|
||||
void UserIdmProxy::AddCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback, bool isUpdate)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
@ -160,15 +160,15 @@ void UserIdmProxy::AddCredential(int32_t userId, AuthType authType, PinSubType p
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteInt32(authType)) {
|
||||
if (!data.WriteInt32(credPara.authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteInt32(pinSubType)) {
|
||||
if (!data.WriteInt32(credPara.pinType)) {
|
||||
IAM_LOGE("failed to write pinSubType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(token)) {
|
||||
if (!data.WriteUInt8Vector(credPara.token)) {
|
||||
IAM_LOGE("failed to write token");
|
||||
return;
|
||||
}
|
||||
@ -180,8 +180,8 @@ void UserIdmProxy::AddCredential(int32_t userId, AuthType authType, PinSubType p
|
||||
SendRequest(UserIdmInterface::USER_IDM_ADD_CREDENTIAL, data, reply);
|
||||
}
|
||||
|
||||
void UserIdmProxy::UpdateCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback)
|
||||
void UserIdmProxy::UpdateCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
@ -198,15 +198,15 @@ void UserIdmProxy::UpdateCredential(int32_t userId, AuthType authType, PinSubTyp
|
||||
IAM_LOGE("failed to write userId");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteInt32(authType)) {
|
||||
if (!data.WriteInt32(credPara.authType)) {
|
||||
IAM_LOGE("failed to write authType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteInt32(pinSubType)) {
|
||||
if (!data.WriteInt32(credPara.pinType)) {
|
||||
IAM_LOGE("failed to write pinSubType");
|
||||
return;
|
||||
}
|
||||
if (!data.WriteUInt8Vector(token)) {
|
||||
if (!data.WriteUInt8Vector(credPara.token)) {
|
||||
IAM_LOGE("failed to write token");
|
||||
return;
|
||||
}
|
||||
|
@ -190,8 +190,11 @@ int32_t UserIdmStub::AddCredentialStub(MessageParcel &data, MessageParcel &reply
|
||||
IAM_LOGI("auth type is pin, clear token");
|
||||
token.clear();
|
||||
}
|
||||
AddCredential(userId, static_cast<AuthType>(authType), static_cast<PinSubType>(authSubType),
|
||||
token, callback, false);
|
||||
CredentialPara credPara = {};
|
||||
credPara.authType = static_cast<AuthType>(authType);
|
||||
credPara.pinType = static_cast<PinSubType>(authSubType);
|
||||
credPara.token = token;
|
||||
AddCredential(userId, credPara, callback, false);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
@ -229,7 +232,11 @@ int32_t UserIdmStub::UpdateCredentialStub(MessageParcel &data, MessageParcel &re
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
|
||||
UpdateCredential(userId, static_cast<AuthType>(authType), static_cast<PinSubType>(authSubType), token, callback);
|
||||
CredentialPara credPara = {};
|
||||
credPara.authType = static_cast<AuthType>(authType);
|
||||
credPara.pinType = static_cast<PinSubType>(authSubType);
|
||||
credPara.token = token;
|
||||
UpdateCredential(userId, credPara, callback);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
38
param/BUILD.gn
Normal file
38
param/BUILD.gn
Normal file
@ -0,0 +1,38 @@
|
||||
# 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
|
||||
## Install useriam.para to /system/etc/param/useriam.para
|
||||
## Install useriam.para.dac to /system/etc/param/useriam.para.dac
|
||||
|
||||
group("param_files") {
|
||||
deps = [
|
||||
":useriam.para",
|
||||
":useriam.para.dac",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("useriam.para") {
|
||||
source = "useriam.para"
|
||||
relative_install_dir = "param"
|
||||
part_name = "user_auth_framework"
|
||||
subsystem_name = "useriam"
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("useriam.para.dac") {
|
||||
source = "useriam.para.dac"
|
||||
relative_install_dir = "param"
|
||||
part_name = "user_auth_framework"
|
||||
subsystem_name = "useriam"
|
||||
}
|
14
param/useriam.para
Normal file
14
param/useriam.para
Normal file
@ -0,0 +1,14 @@
|
||||
# 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.
|
||||
|
||||
bootevent.useriam.fwkready=false
|
14
param/useriam.para.dac
Normal file
14
param/useriam.para.dac
Normal file
@ -0,0 +1,14 @@
|
||||
# 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.
|
||||
|
||||
bootevent.useriam.fwkready="useriam:useriam:755"
|
@ -29,13 +29,33 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ContextFactory : public DelayedSingleton<ContextFactory> {
|
||||
public:
|
||||
static std::shared_ptr<Context> CreateSimpleAuthContext(int32_t userId, const std::vector<uint8_t> &challenge,
|
||||
AuthType authType, AuthTrustLevel authTrustLevel, uint32_t tokenId,
|
||||
struct AuthContextPara {
|
||||
int32_t userId {0};
|
||||
AuthType authType {ALL};
|
||||
AuthTrustLevel atl {ATL1};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> challenge;
|
||||
};
|
||||
|
||||
struct IdentifyContextPara {
|
||||
AuthType authType {ALL};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> challenge;
|
||||
};
|
||||
|
||||
struct EnrollContextPara {
|
||||
int32_t userId {0};
|
||||
AuthType authType {ALL};
|
||||
PinSubType pinType {PIN_SIX};
|
||||
uint32_t tokenId {0};
|
||||
std::vector<uint8_t> token;
|
||||
};
|
||||
static std::shared_ptr<Context> CreateSimpleAuthContext(const AuthContextPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateIdentifyContext(const IdentifyContextPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateEnrollContext(const EnrollContextPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateIdentifyContext(const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
uint32_t tokenId, const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateEnrollContext(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, uint32_t tokenId, const std::shared_ptr<ContextCallback> &callback);
|
||||
static std::shared_ptr<Context> CreateWidgetAuthContext(std::shared_ptr<ContextCallback> callback);
|
||||
};
|
||||
} // namespace UserAuth
|
||||
|
@ -31,7 +31,7 @@ private:
|
||||
static void ProcessPinAuthEvent(const ContextCallbackNotifyListener::MetaData &metaData);
|
||||
static void ProcessDelUserEvent(const ContextCallbackNotifyListener::MetaData &metaData);
|
||||
Trace();
|
||||
~Trace();
|
||||
~Trace() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -31,41 +31,40 @@
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
std::shared_ptr<Context> ContextFactory::CreateSimpleAuthContext(int32_t userId, const std::vector<uint8_t> &challenge,
|
||||
AuthType authType, AuthTrustLevel authTrustLevel, uint32_t tokenId,
|
||||
std::shared_ptr<Context> ContextFactory::CreateSimpleAuthContext(const AuthContextPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback)
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
|
||||
uint64_t newContextId = ContextPool::GetNewContextId();
|
||||
auto auth = Common::MakeShared<AuthenticationImpl>(newContextId, userId, authType, authTrustLevel);
|
||||
auto auth = Common::MakeShared<AuthenticationImpl>(newContextId, para.userId, para.authType, para.atl);
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(auth != nullptr, nullptr);
|
||||
auth->SetChallenge(challenge);
|
||||
auth->SetAccessTokenId(tokenId);
|
||||
auth->SetChallenge(para.challenge);
|
||||
auth->SetAccessTokenId(para.tokenId);
|
||||
return Common::MakeShared<SimpleAuthContext>(newContextId, auth, callback);
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> ContextFactory::CreateIdentifyContext(const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
uint32_t tokenId, const std::shared_ptr<ContextCallback> &callback)
|
||||
std::shared_ptr<Context> ContextFactory::CreateIdentifyContext(const IdentifyContextPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback)
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
|
||||
uint64_t newContextId = ContextPool::GetNewContextId();
|
||||
auto identify = Common::MakeShared<IdentificationImpl>(newContextId, authType);
|
||||
auto identify = Common::MakeShared<IdentificationImpl>(newContextId, para.authType);
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(identify != nullptr, nullptr);
|
||||
identify->SetChallenge(challenge);
|
||||
identify->SetAccessTokenId(tokenId);
|
||||
identify->SetChallenge(para.challenge);
|
||||
identify->SetAccessTokenId(para.tokenId);
|
||||
return Common::MakeShared<IdentifyContext>(newContextId, identify, callback);
|
||||
}
|
||||
|
||||
std::shared_ptr<Context> ContextFactory::CreateEnrollContext(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, uint32_t tokenId, const std::shared_ptr<ContextCallback> &callback)
|
||||
std::shared_ptr<Context> ContextFactory::CreateEnrollContext(const EnrollContextPara ¶,
|
||||
const std::shared_ptr<ContextCallback> &callback)
|
||||
{
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(callback != nullptr, nullptr);
|
||||
uint64_t newContextId = ContextPool::GetNewContextId();
|
||||
auto enroll = Common::MakeShared<EnrollmentImpl>(userId, authType);
|
||||
auto enroll = Common::MakeShared<EnrollmentImpl>(para.userId, para.authType);
|
||||
IF_FALSE_LOGE_AND_RETURN_VAL(enroll != nullptr, nullptr);
|
||||
enroll->SetAuthToken(token);
|
||||
enroll->SetAccessTokenId(tokenId);
|
||||
enroll->SetPinSubType(pinSubType);
|
||||
enroll->SetAuthToken(para.token);
|
||||
enroll->SetAccessTokenId(para.tokenId);
|
||||
enroll->SetPinSubType(para.pinType);
|
||||
return Common::MakeShared<EnrollContext>(newContextId, enroll, callback);
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,9 @@ Trace::~Trace()
|
||||
|
||||
void Trace::ProcessCredChangeEvent(const ContextCallbackNotifyListener::MetaData &metaData)
|
||||
{
|
||||
bool checkRet = metaData.operationType == TRACE_ADD_CREDENTIAL || metaData.operationType == TRACE_DELETE_CREDENTIAL
|
||||
|| metaData.operationType == TRACE_UPDATE_CREDENTIAL;
|
||||
bool checkRet = metaData.operationType == TRACE_ADD_CREDENTIAL ||
|
||||
metaData.operationType == TRACE_DELETE_CREDENTIAL ||
|
||||
metaData.operationType == TRACE_UPDATE_CREDENTIAL;
|
||||
if (!checkRet) {
|
||||
return;
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
#ifndef IAM_USER_IDM_SESSION_CONTROLLER_H
|
||||
#define IAM_USER_IDM_SESSION_CONTROLLER_H
|
||||
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace OHOS {
|
||||
@ -24,16 +23,11 @@ namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class UserIdmSessionController {
|
||||
public:
|
||||
using SessionMap = std::unordered_map<int32_t, std::vector<uint8_t>>;
|
||||
static UserIdmSessionController &Instance();
|
||||
|
||||
virtual bool OpenSession(int32_t userId, std::vector<uint8_t> &challenge) = 0;
|
||||
virtual bool CloseSession(int32_t userId) = 0;
|
||||
virtual bool CloseSession(const std::vector<uint8_t> &challenge) = 0;
|
||||
virtual bool IsSessionOpened(int32_t userId) const = 0;
|
||||
virtual bool IsSessionOpened(const std::vector<uint8_t> &challenge) const = 0;
|
||||
virtual bool ForceReset() = 0;
|
||||
virtual SessionMap GetOpenedSessions() const = 0;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -34,7 +34,7 @@ bool UserIdmSessionControllerImpl::OpenSession(int32_t userId, std::vector<uint8
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!map_.empty()) {
|
||||
if (!sessionSet_.empty()) {
|
||||
IAM_LOGW("old session is not closed");
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ bool UserIdmSessionControllerImpl::OpenSession(int32_t userId, std::vector<uint8
|
||||
IAM_LOGE("failed to open session, error code : %{public}d", ret);
|
||||
return false;
|
||||
}
|
||||
map_[userId] = challenge;
|
||||
sessionSet_.insert(userId);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -61,61 +61,23 @@ bool UserIdmSessionControllerImpl::CloseSession(int32_t userId)
|
||||
return false;
|
||||
}
|
||||
|
||||
map_.erase(userId);
|
||||
sessionSet_.erase(userId);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UserIdmSessionControllerImpl::CloseSession(const std::vector<uint8_t> &challenge)
|
||||
{
|
||||
std::optional<int32_t> userId;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
for (const auto &[key, value] : map_) {
|
||||
if (value == challenge) {
|
||||
userId = key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (userId.has_value()) {
|
||||
return CloseSession(userId.value());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool UserIdmSessionControllerImpl::IsSessionOpened(int32_t userId) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return map_.find(userId) != map_.end();
|
||||
}
|
||||
|
||||
bool UserIdmSessionControllerImpl::IsSessionOpened(const std::vector<uint8_t> &challenge) const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
for (const auto &[key, value] : map_) {
|
||||
if (value == challenge) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return sessionSet_.find(userId) != sessionSet_.end();
|
||||
}
|
||||
|
||||
bool UserIdmSessionControllerImpl::ForceReset()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
map_.clear();
|
||||
sessionSet_.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
UserIdmSessionController::SessionMap UserIdmSessionControllerImpl::GetOpenedSessions() const
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return map_;
|
||||
}
|
||||
|
||||
UserIdmSessionController &UserIdmSessionController::Instance()
|
||||
{
|
||||
return UserIdmSessionControllerImpl::GetInstance();
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "user_idm_session_controller.h"
|
||||
@ -32,15 +33,12 @@ class UserIdmSessionControllerImpl : public UserIdmSessionController, public Sin
|
||||
public:
|
||||
bool OpenSession(int32_t userId, std::vector<uint8_t> &challenge) override;
|
||||
bool CloseSession(int32_t userId) override;
|
||||
bool CloseSession(const std::vector<uint8_t> &challenge) override;
|
||||
bool IsSessionOpened(int32_t userId) const override;
|
||||
bool IsSessionOpened(const std::vector<uint8_t> &challenge) const override;
|
||||
bool ForceReset() override;
|
||||
SessionMap GetOpenedSessions() const override;
|
||||
|
||||
private:
|
||||
mutable std::mutex mutex_;
|
||||
UserIdmSessionController::SessionMap map_;
|
||||
std::set<int32_t> sessionSet_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -43,10 +43,10 @@ public:
|
||||
int32_t GetCredentialInfo(int32_t userId, AuthType authType,
|
||||
const sptr<IdmGetCredInfoCallbackInterface> &callback) override;
|
||||
int32_t GetSecInfo(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) override;
|
||||
void AddCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate) override;
|
||||
void UpdateCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback) override;
|
||||
void AddCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback, bool isUpdate) override;
|
||||
void UpdateCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback) override;
|
||||
int32_t Cancel(int32_t userId) override;
|
||||
int32_t EnforceDelUser(int32_t userId, const sptr<IdmCallbackInterface> &callback) override;
|
||||
void DelUser(int32_t userId, const std::vector<uint8_t> authToken,
|
||||
|
@ -119,6 +119,7 @@ void CoAuthService::Init()
|
||||
UserIam::UserAuth::ReportSystemFault(Common::GetNowTimeString(), "user_auth_hdi host");
|
||||
}));
|
||||
IAM_LOGI("set fwk ready parameter");
|
||||
SetParameter("bootevent.useriam.fwkready", "false");
|
||||
SetParameter("bootevent.useriam.fwkready", "true");
|
||||
} else {
|
||||
RelativeTimer::GetInstance().Register(Init, DEFER_TIME);
|
||||
|
@ -235,17 +235,20 @@ uint64_t UserAuthService::Auth(int32_t apiVersion, const std::vector<uint8_t> &c
|
||||
contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
auto tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
auto context = ContextFactory::CreateSimpleAuthContext(userId, challenge, authType, authTrustLevel,
|
||||
tokenId, contextCallback);
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
para.userId = userId;
|
||||
para.authType = authType;
|
||||
para.atl = authTrustLevel;
|
||||
para.challenge = std::move(challenge);
|
||||
auto context = ContextFactory::CreateSimpleAuthContext(para, contextCallback);
|
||||
if (!ContextPool::Instance().Insert(context)) {
|
||||
IAM_LOGE("failed to insert context");
|
||||
contextCallback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
auto cleaner = ContextHelper::Cleaner(context);
|
||||
contextCallback->SetCleaner(cleaner);
|
||||
contextCallback->SetCleaner(ContextHelper::Cleaner(context));
|
||||
|
||||
if (!context->Start()) {
|
||||
int32_t errorCode = context->GetLatestError();
|
||||
@ -280,17 +283,20 @@ uint64_t UserAuthService::AuthUser(int32_t userId, const std::vector<uint8_t> &c
|
||||
contextCallback->OnResult(CHECK_PERMISSION_FAILED, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
auto tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
auto context = ContextFactory::CreateSimpleAuthContext(userId, challenge, authType, authTrustLevel,
|
||||
tokenId, contextCallback);
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
para.userId = userId;
|
||||
para.authType = authType;
|
||||
para.atl = authTrustLevel;
|
||||
para.challenge = std::move(challenge);
|
||||
auto context = ContextFactory::CreateSimpleAuthContext(para, contextCallback);
|
||||
if (!ContextPool::Instance().Insert(context)) {
|
||||
IAM_LOGE("failed to insert context");
|
||||
contextCallback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
auto cleaner = ContextHelper::Cleaner(context);
|
||||
contextCallback->SetCleaner(cleaner);
|
||||
contextCallback->SetCleaner(ContextHelper::Cleaner(context));
|
||||
|
||||
if (!context->Start()) {
|
||||
IAM_LOGE("failed to start auth");
|
||||
@ -327,16 +333,18 @@ uint64_t UserAuthService::Identify(const std::vector<uint8_t> &challenge, AuthTy
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
auto tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
auto context = ContextFactory::CreateIdentifyContext(challenge, authType, tokenId, contextCallback);
|
||||
ContextFactory::IdentifyContextPara para = {};
|
||||
para.tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
para.authType = authType;
|
||||
para.challenge = std::move(challenge);
|
||||
auto context = ContextFactory::CreateIdentifyContext(para, contextCallback);
|
||||
if (!ContextPool::Instance().Insert(context)) {
|
||||
IAM_LOGE("failed to insert context");
|
||||
contextCallback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return BAD_CONTEXT_ID;
|
||||
}
|
||||
|
||||
auto cleaner = ContextHelper::Cleaner(context);
|
||||
contextCallback->SetCleaner(cleaner);
|
||||
contextCallback->SetCleaner(ContextHelper::Cleaner(context));
|
||||
|
||||
if (!context->Start()) {
|
||||
IAM_LOGE("failed to start identify");
|
||||
|
@ -154,8 +154,8 @@ int32_t UserIdmService::GetSecInfo(int32_t userId, const sptr<IdmGetSecureUserIn
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
void UserIdmService::AddCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate)
|
||||
void UserIdmService::AddCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback, bool isUpdate)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
@ -171,7 +171,7 @@ void UserIdmService::AddCredential(int32_t userId, AuthType authType, PinSubType
|
||||
return;
|
||||
}
|
||||
uint64_t callingUid = static_cast<uint64_t>(this->GetCallingUid());
|
||||
contextCallback->SetTraceAuthType(authType);
|
||||
contextCallback->SetTraceAuthType(credPara.authType);
|
||||
contextCallback->SetTraceCallingUid(callingUid);
|
||||
contextCallback->SetTraceUserId(userId);
|
||||
|
||||
@ -184,8 +184,13 @@ void UserIdmService::AddCredential(int32_t userId, AuthType authType, PinSubType
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
CancelCurrentEnrollIfExist();
|
||||
auto tokenId = IpcCommon::GetAccessTokenId(*this);
|
||||
auto context =
|
||||
ContextFactory::CreateEnrollContext(userId, authType, pinSubType, token, tokenId, contextCallback);
|
||||
ContextFactory::EnrollContextPara para = {};
|
||||
para.authType = credPara.authType;
|
||||
para.userId = userId;
|
||||
para.pinType = credPara.pinType;
|
||||
para.tokenId = tokenId;
|
||||
para.token = credPara.token;
|
||||
auto context = ContextFactory::CreateEnrollContext(para, contextCallback);
|
||||
if (!ContextPool::Instance().Insert(context)) {
|
||||
IAM_LOGE("failed to insert context");
|
||||
contextCallback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
@ -201,8 +206,8 @@ void UserIdmService::AddCredential(int32_t userId, AuthType authType, PinSubType
|
||||
}
|
||||
}
|
||||
|
||||
void UserIdmService::UpdateCredential(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback)
|
||||
void UserIdmService::UpdateCredential(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
IAM_LOGE("callback is nullptr");
|
||||
@ -210,20 +215,20 @@ void UserIdmService::UpdateCredential(int32_t userId, AuthType authType, PinSubT
|
||||
}
|
||||
|
||||
Attributes extraInfo;
|
||||
if (token.empty()) {
|
||||
if (credPara.token.empty()) {
|
||||
IAM_LOGE("token is empty in update");
|
||||
callback->OnResult(GENERAL_ERROR, extraInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
auto credInfos = UserIdmDatabase::Instance().GetCredentialInfo(userId, authType);
|
||||
auto credInfos = UserIdmDatabase::Instance().GetCredentialInfo(userId, credPara.authType);
|
||||
if (credInfos.empty()) {
|
||||
IAM_LOGE("current userid %{public}d has no credential for type %{public}u", userId, authType);
|
||||
IAM_LOGE("current userid %{public}d has no credential for type %{public}u", userId, credPara.authType);
|
||||
callback->OnResult(NOT_ENROLLED, extraInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
AddCredential(userId, authType, pinSubType, token, callback, true);
|
||||
AddCredential(userId, credPara, callback, true);
|
||||
}
|
||||
|
||||
int32_t UserIdmService::Cancel(int32_t userId)
|
||||
|
@ -177,12 +177,12 @@ void FuzzAddCredential(Parcel &parcel)
|
||||
{
|
||||
IAM_LOGI("begin");
|
||||
int32_t userId = parcel.ReadInt32();
|
||||
AuthType authType = static_cast<AuthType>(parcel.ReadInt32());
|
||||
PinSubType pinSubType = static_cast<PinSubType>(parcel.ReadInt32());
|
||||
std::vector<uint8_t> token;
|
||||
FillFuzzUint8Vector(parcel, token);
|
||||
UserIdmInterface::CredentialPara para = {};
|
||||
para.authType = static_cast<AuthType>(parcel.ReadInt32());
|
||||
para.pinType = static_cast<PinSubType>(parcel.ReadInt32());
|
||||
FillFuzzUint8Vector(parcel, para.token);
|
||||
sptr<IdmCallbackInterface> callback = GetFuzzIdmCallback(parcel);
|
||||
g_UserIdmService.AddCredential(userId, authType, pinSubType, token, callback, false);
|
||||
g_UserIdmService.AddCredential(userId, para, callback, false);
|
||||
IAM_LOGI("end");
|
||||
}
|
||||
|
||||
@ -190,12 +190,12 @@ void FuzzUpdateCredential(Parcel &parcel)
|
||||
{
|
||||
IAM_LOGI("begin");
|
||||
int32_t userId = parcel.ReadInt32();
|
||||
AuthType authType = static_cast<AuthType>(parcel.ReadInt32());
|
||||
PinSubType pinSubType = static_cast<PinSubType>(parcel.ReadInt32());
|
||||
std::vector<uint8_t> token;
|
||||
FillFuzzUint8Vector(parcel, token);
|
||||
UserIdmInterface::CredentialPara para = {};
|
||||
para.authType = static_cast<AuthType>(parcel.ReadInt32());
|
||||
para.pinType = static_cast<PinSubType>(parcel.ReadInt32());
|
||||
FillFuzzUint8Vector(parcel, para.token);
|
||||
sptr<IdmCallbackInterface> callback = GetFuzzIdmCallback(parcel);
|
||||
g_UserIdmService.UpdateCredential(userId, authType, pinSubType, token, callback);
|
||||
g_UserIdmService.UpdateCredential(userId, para, callback);
|
||||
IAM_LOGI("end");
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "iam_logger.h"
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#include "driver_manager.h"
|
||||
#include "mock_iauth_driver_hdi.h"
|
||||
#include "mock_iauth_executor_hdi.h"
|
||||
|
||||
@ -54,9 +55,24 @@ void DriverManagerUnitTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(DriverManagerUnitTest, UserAuthDriverManager_GetExecutorListTest_001, TestSize.Level0)
|
||||
HWTEST_F(DriverManagerUnitTest, DriverManagerTest_001, TestSize.Level0)
|
||||
{
|
||||
EXPECT_TRUE(0 == 0);
|
||||
std::string serviceName = "mockDriver";
|
||||
HdiConfig config = {};
|
||||
config.id = 10;
|
||||
config.driver = nullptr;
|
||||
std::map<std::string, HdiConfig> hdiName2Config;
|
||||
EXPECT_EQ(DriverManager::GetInstance().Start(hdiName2Config), USERAUTH_SUCCESS);
|
||||
hdiName2Config.emplace(serviceName, config);
|
||||
EXPECT_EQ(DriverManager::GetInstance().Start(hdiName2Config), USERAUTH_ERROR);
|
||||
EXPECT_EQ(DriverManager::GetInstance().GetDriverByServiceName(serviceName), nullptr);
|
||||
config.driver = Common::MakeShared<MockIAuthDriverHdi>();
|
||||
EXPECT_EQ(DriverManager::GetInstance().Start(hdiName2Config), USERAUTH_ERROR);
|
||||
DriverManager::GetInstance().GetDriverByServiceName(serviceName);
|
||||
EXPECT_EQ(DriverManager::GetInstance().Start(hdiName2Config), USERAUTH_ERROR);
|
||||
DriverManager::GetInstance().OnFrameworkReady();
|
||||
DriverManager::GetInstance().SubscribeHdiDriverStatus();
|
||||
DriverManager::GetInstance().OnAllHdiDisconnect();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -27,8 +27,7 @@ using namespace OHOS::UserIam;
|
||||
using namespace OHOS::UserIam::UserAuth;
|
||||
|
||||
class MockIAuthDriverHdi : public IAuthDriverHdi {
|
||||
virtual ~MockIAuthDriverHdi() = default;
|
||||
|
||||
public:
|
||||
MOCK_METHOD1(GetExecutorList, void(std::vector<std::shared_ptr<IAuthExecutorHdi>> &executorList));
|
||||
};
|
||||
} // namespace UserAuth
|
||||
|
@ -20,28 +20,43 @@ ohos_unittest("iam_inner_api_test") {
|
||||
"mocks",
|
||||
"//base/useriam/user_auth_framework/test/unittest/services/mocks",
|
||||
"//base/useriam/user_auth_framework/interfaces/inner_api",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/inc",
|
||||
]
|
||||
|
||||
sources = [
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/auth_message_impl.cpp",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/co_auth_client_impl.cpp",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/executor_callback_service.cpp",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/executor_messenger_client.cpp",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/user_auth_callback_service.cpp",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/user_auth_client_impl.cpp",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/user_idm_callback_service.cpp",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client/src/user_idm_client_impl.cpp",
|
||||
"mocks/mock_ipc_client_utils.cpp",
|
||||
"src/co_auth_client_test.cpp",
|
||||
"src/co_auth_proxy_test.cpp",
|
||||
"src/executor_callback_service_test.cpp",
|
||||
"src/executor_messenger_client_test.cpp",
|
||||
"src/user_auth_callback_service_test.cpp",
|
||||
"src/user_auth_client_test.cpp",
|
||||
"src/user_auth_proxy_test.cpp",
|
||||
"src/user_idm_callback_service_test.cpp",
|
||||
"src/user_idm_client_test.cpp",
|
||||
"src/user_idm_proxy_test.cpp",
|
||||
]
|
||||
|
||||
configs = [
|
||||
"//base/useriam/user_auth_framework/common:iam_log_config",
|
||||
"//base/useriam/user_auth_framework/common:iam_utils_config",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/ipc:userauth_client_ipc_config",
|
||||
]
|
||||
remove_configs = [ "//build/config/compiler:no_exceptions" ]
|
||||
|
||||
deps = [
|
||||
"//base/security/access_token/interfaces/innerkits/nativetoken:libnativetoken",
|
||||
"//base/security/access_token/interfaces/innerkits/token_setproc:libtoken_setproc",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/client:userauth_client",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/common:attributes",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/common:dfx",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/ipc:userauth_client_ipc",
|
||||
"//base/useriam/user_auth_framework/frameworks/native/ipc:userauth_service_ipc",
|
||||
"//third_party/googletest:gmock",
|
||||
]
|
||||
|
37
test/unittest/inner_api/inc/executor_callback_service_test.h
Normal file
37
test/unittest/inner_api/inc/executor_callback_service_test.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_SERVICE_TEST_H
|
||||
#define EXECUTOR_CALLBACK_SERVICE_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ExecutorCallbackServiceTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // EXECUTOR_CALLBACK_SERVICE_TEST_H
|
37
test/unittest/inner_api/inc/executor_messenger_client_test.h
Normal file
37
test/unittest/inner_api/inc/executor_messenger_client_test.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_CLIENT_TEST_H
|
||||
#define EXECUTOR_MESSENGER_CLIENT_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ExecutorMessengerClientTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // EXECUTOR_MESSENGER_CLIENT_TEST_H
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_SERVICE_TEST_H
|
||||
#define USER_AUTH_CALLBACK_SERVICE_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class UserAuthCallbackServiceTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USER_AUTH_CALLBACK_SERVICE_TEST_H
|
37
test/unittest/inner_api/inc/user_idm_callback_service_test.h
Normal file
37
test/unittest/inner_api/inc/user_idm_callback_service_test.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_SERVICE_TEST_H
|
||||
#define USER_IDM_CALLBACK_SERVICE_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class UserIdmCallbackServiceTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // USER_IDM_CALLBACK_SERVICE_TEST_H
|
@ -12,8 +12,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef IAM_MOCK_EXECUTOR_MESSENGER_H
|
||||
#define IAM_MOCK_EXECUTOR_MESSENGER_H
|
||||
#ifndef MOCK_EXECUTOR_MESSENGER_H
|
||||
#define MOCK_EXECUTOR_MESSENGER_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -29,19 +29,12 @@ public:
|
||||
MOCK_METHOD0(AsObject, sptr<IRemoteObject>());
|
||||
MOCK_METHOD4(OnRemoteRequest,
|
||||
int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option));
|
||||
MOCK_METHOD5(SendData, int32_t(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole, ExecutorRole dstRole,
|
||||
const std::vector<uint8_t> &msg));
|
||||
MOCK_METHOD5(Finish,
|
||||
int32_t(uint64_t scheduleId, ExecutorRole srcRole, int32_t resultCode, const Attributes &finalResult));
|
||||
|
||||
static std::shared_ptr<ExecutorMessengerInterface> Create()
|
||||
{
|
||||
using namespace testing;
|
||||
auto messenger = Common::MakeShared<MockExecutorMessenger>();
|
||||
return messenger;
|
||||
}
|
||||
MOCK_METHOD5(SendData, int32_t(uint64_t scheduleId, uint64_t transNum, ExecutorRole srcRole,
|
||||
ExecutorRole dstRole, const std::vector<uint8_t> &msg));
|
||||
MOCK_METHOD4(Finish, int32_t(uint64_t scheduleId, ExecutorRole srcRole, ResultCode resultCode,
|
||||
const std::shared_ptr<Attributes> &finalResult));
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // IAM_MOCK_EXECUTOR_MESSENGER_H
|
||||
#endif // MOCK_EXECUTOR_MESSENGER_H
|
38
test/unittest/inner_api/mocks/mock_ipc_client_utils.cpp
Normal file
38
test/unittest/inner_api/mocks/mock_ipc_client_utils.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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 "mock_ipc_client_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
sptr<IRemoteObject> IpcClientUtils::obj_ = nullptr;
|
||||
|
||||
sptr<IRemoteObject> IpcClientUtils::GetRemoteObject(int32_t saId)
|
||||
{
|
||||
return obj_;
|
||||
}
|
||||
|
||||
void IpcClientUtils::SetObj(const sptr<IRemoteObject> &obj)
|
||||
{
|
||||
obj_ = obj;
|
||||
}
|
||||
|
||||
void IpcClientUtils::ResetObj()
|
||||
{
|
||||
obj_ = nullptr;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
36
test/unittest/inner_api/mocks/mock_ipc_client_utils.h
Normal file
36
test/unittest/inner_api/mocks/mock_ipc_client_utils.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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 MOCK_IPC_CLIENT_UTILS_H
|
||||
#define MOCK_IPC_CLIENT_UTILS_H
|
||||
|
||||
#include "iremote_object.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class IpcClientUtils {
|
||||
public:
|
||||
static sptr<IRemoteObject> GetRemoteObject(int32_t saId);
|
||||
static void SetObj(const sptr<IRemoteObject> &obj);
|
||||
static void ResetObj();
|
||||
|
||||
private:
|
||||
static sptr<IRemoteObject> obj_;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // MOCK_IPC_CLIENT_UTILS_H
|
@ -15,13 +15,12 @@
|
||||
|
||||
#include "co_auth_client_test.h"
|
||||
|
||||
#include "file_ex.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
#include "co_auth_client.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_co_auth_service.h"
|
||||
#include "mock_executor_register_callback.h"
|
||||
#include "mock_remote_object.h"
|
||||
#include "mock_ipc_client_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
@ -31,33 +30,10 @@ using namespace testing::ext;
|
||||
|
||||
void CoAuthClientTest::SetUpTestCase()
|
||||
{
|
||||
static const char *PERMS[] = {
|
||||
"ohos.permission.ACCESS_AUTH_RESPOOL",
|
||||
"ohos.permission.ACCESS_USER_AUTH_INTERNAL",
|
||||
"ohos.permission.ACCESS_BIOMETRIC",
|
||||
"ohos.permission.MANAGE_USER_IDM",
|
||||
"ohos.permission.USE_USER_IDM",
|
||||
"ohos.permission.ENFORCE_USER_IDM"
|
||||
};
|
||||
uint64_t tokenId;
|
||||
NativeTokenInfoParams infoInstance = {
|
||||
.dcapsNum = 0,
|
||||
.permsNum = 6,
|
||||
.aclsNum = 0,
|
||||
.dcaps = nullptr,
|
||||
.perms = PERMS,
|
||||
.acls = nullptr,
|
||||
.processName = "co_auth",
|
||||
.aplStr = "system_core",
|
||||
};
|
||||
tokenId = GetAccessTokenId(&infoInstance);
|
||||
SetSelfTokenID(tokenId);
|
||||
SaveStringToFile("/sys/fs/selinux/enforce", "0");
|
||||
}
|
||||
|
||||
void CoAuthClientTest::TearDownTestCase()
|
||||
{
|
||||
SaveStringToFile("/sys/fs/selinux/enforce", "1");
|
||||
}
|
||||
|
||||
void CoAuthClientTest::SetUp()
|
||||
@ -70,7 +46,7 @@ void CoAuthClientTest::TearDown()
|
||||
|
||||
HWTEST_F(CoAuthClientTest, CoAuthClientRegister, TestSize.Level0)
|
||||
{
|
||||
static ExecutorInfo testInfo = {};
|
||||
ExecutorInfo testInfo = {};
|
||||
testInfo.authType = PIN;
|
||||
testInfo.executorRole = COLLECTOR;
|
||||
testInfo.executorSensorHint = 11;
|
||||
@ -78,9 +54,46 @@ HWTEST_F(CoAuthClientTest, CoAuthClientRegister, TestSize.Level0)
|
||||
testInfo.esl = ESL1;
|
||||
testInfo.publicKey = {1, 2, 3, 4};
|
||||
|
||||
uint64_t testExecutorIndex = 73265;
|
||||
|
||||
auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
|
||||
auto service = Common::MakeShared<MockCoAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, ExecutorRegister(_, _)).Times(1);
|
||||
ON_CALL(*service, ExecutorRegister)
|
||||
.WillByDefault(
|
||||
[&testInfo, &testExecutorIndex](const CoAuthInterface::ExecutorRegisterInfo &info,
|
||||
sptr<ExecutorCallbackInterface> &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;
|
||||
}
|
||||
);
|
||||
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
|
||||
ON_CALL(*obj, SendRequest)
|
||||
.WillByDefault(
|
||||
[&service, testExecutorIndex](uint32_t code, MessageParcel &data, MessageParcel &reply,
|
||||
MessageOption &option) {
|
||||
service->OnRemoteRequest(code, data, reply, option);
|
||||
uint64_t executorIndex = 0;
|
||||
EXPECT_TRUE(reply.ReadUint64(executorIndex));
|
||||
EXPECT_EQ(executorIndex, testExecutorIndex);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
CoAuthClient::GetInstance().Register(testInfo, testCallback);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -46,7 +46,7 @@ void CoAuthProxyTest::TearDown()
|
||||
|
||||
HWTEST_F(CoAuthProxyTest, CoAuthProxyExecutorRegister, TestSize.Level0)
|
||||
{
|
||||
static CoAuthInterface::ExecutorRegisterInfo testInfo = {};
|
||||
CoAuthInterface::ExecutorRegisterInfo testInfo = {};
|
||||
testInfo.authType = PIN;
|
||||
testInfo.executorRole = COLLECTOR;
|
||||
testInfo.executorSensorHint = 11;
|
||||
@ -54,6 +54,8 @@ HWTEST_F(CoAuthProxyTest, CoAuthProxyExecutorRegister, TestSize.Level0)
|
||||
testInfo.esl = ESL1;
|
||||
testInfo.publicKey = {1, 2, 3, 4};
|
||||
|
||||
uint64_t testExecutorIndex = 73265;
|
||||
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
auto proxy = Common::MakeShared<CoAuthProxy>(obj);
|
||||
@ -64,21 +66,22 @@ HWTEST_F(CoAuthProxyTest, CoAuthProxyExecutorRegister, TestSize.Level0)
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, ExecutorRegister(_, _))
|
||||
.Times(Exactly(1))
|
||||
.WillOnce([](const CoAuthInterface::ExecutorRegisterInfo &info, sptr<ExecutorCallbackInterface> &callback) {
|
||||
.WillOnce(
|
||||
[&testInfo, &testExecutorIndex](const CoAuthInterface::ExecutorRegisterInfo &info,
|
||||
sptr<ExecutorCallbackInterface> &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, ElementsAre(1, 2, 3, 4));
|
||||
const uint64_t contextId = 111;
|
||||
return contextId;
|
||||
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 SUCCESS;
|
||||
return OHOS::NO_ERROR;
|
||||
});
|
||||
proxy->ExecutorRegister(testInfo, testCallback);
|
||||
}
|
||||
|
217
test/unittest/inner_api/src/executor_callback_service_test.cpp
Normal file
217
test/unittest/inner_api/src/executor_callback_service_test.cpp
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
* 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 "executor_callback_service_test.h"
|
||||
|
||||
#include "executor_callback_service.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_executor_register_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
void ExecutorCallbackServiceTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorCallbackServiceTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorCallbackServiceTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorCallbackServiceTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerReady001, TestSize.Level0)
|
||||
{
|
||||
sptr<ExecutorMessengerInterface> testMessenger = nullptr;
|
||||
std::vector<uint8_t> testPublicKey = {1, 2, 3, 4};
|
||||
std::vector<uint64_t> testTemplateIdList = {12, 13, 14, 15};
|
||||
|
||||
std::shared_ptr<ExecutorRegisterCallback> testCallback = nullptr;
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnMessengerReady(testMessenger, testPublicKey, testTemplateIdList);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnMessengerReady002, TestSize.Level0)
|
||||
{
|
||||
sptr<ExecutorMessengerInterface> testMessenger = nullptr;
|
||||
std::vector<uint8_t> testPublicKey = {1, 2, 3, 4};
|
||||
std::vector<uint64_t> testTemplateIdList = {12, 13, 14, 15};
|
||||
|
||||
auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnMessengerReady(_, _, _)).Times(1);
|
||||
ON_CALL(*testCallback, OnMessengerReady)
|
||||
.WillByDefault(
|
||||
[&testPublicKey, &testTemplateIdList](const std::shared_ptr<ExecutorMessenger> &messenger,
|
||||
const std::vector<uint8_t> &publicKey, const std::vector<uint64_t> &templateIds) {
|
||||
EXPECT_NE(messenger, nullptr);
|
||||
EXPECT_THAT(publicKey, ElementsAreArray(testPublicKey));
|
||||
EXPECT_THAT(templateIds, ElementsAreArray(testTemplateIdList));
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnMessengerReady(testMessenger, testPublicKey, testTemplateIdList);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnBeginExecute001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 57875;
|
||||
std::vector<uint8_t> testPublicKey = {1, 2, 3, 4};
|
||||
Attributes testCommand;
|
||||
|
||||
std::shared_ptr<ExecutorRegisterCallback> testCallback = nullptr;
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnBeginExecute(testScheduleId, testPublicKey, testCommand);
|
||||
EXPECT_EQ(result, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnBeginExecute002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 57875;
|
||||
std::vector<uint8_t> testPublicKey = {1, 2, 3, 4};
|
||||
Attributes testCommand;
|
||||
|
||||
auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnBeginExecute(_, _, _)).Times(1);
|
||||
ON_CALL(*testCallback, OnBeginExecute)
|
||||
.WillByDefault(
|
||||
[&testScheduleId, &testPublicKey](uint64_t scheduleId, const std::vector<uint8_t> &publicKey,
|
||||
const Attributes &commandAttrs) {
|
||||
EXPECT_EQ(scheduleId, testScheduleId);
|
||||
EXPECT_THAT(publicKey, ElementsAreArray(testPublicKey));
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnBeginExecute(testScheduleId, testPublicKey, testCommand);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnEndExecute001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 57875;
|
||||
Attributes testCommand;
|
||||
|
||||
std::shared_ptr<ExecutorRegisterCallback> testCallback = nullptr;
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnEndExecute(testScheduleId, testCommand);
|
||||
EXPECT_EQ(result, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnEndExecute002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 57875;
|
||||
Attributes testCommand;
|
||||
|
||||
auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnEndExecute(_, _)).Times(1);
|
||||
ON_CALL(*testCallback, OnEndExecute)
|
||||
.WillByDefault(
|
||||
[&testScheduleId](uint64_t scheduleId, const Attributes &commandAttrs) {
|
||||
EXPECT_EQ(scheduleId, testScheduleId);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnEndExecute(testScheduleId, testCommand);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnSetProperty001, TestSize.Level0)
|
||||
{
|
||||
Attributes testProperties;
|
||||
|
||||
std::shared_ptr<ExecutorRegisterCallback> testCallback = nullptr;
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnSetProperty(testProperties);
|
||||
EXPECT_EQ(result, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnSetProperty002, TestSize.Level0)
|
||||
{
|
||||
Attributes testProperties;
|
||||
|
||||
auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnSetProperty(_)).Times(1);
|
||||
ON_CALL(*testCallback, OnSetProperty)
|
||||
.WillByDefault(
|
||||
[](const Attributes &properties) {
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnSetProperty(testProperties);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnGetProperty001, TestSize.Level0)
|
||||
{
|
||||
Attributes testCondition;
|
||||
Attributes testValues;
|
||||
|
||||
std::shared_ptr<ExecutorRegisterCallback> testCallback = nullptr;
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnGetProperty(testCondition, testValues);
|
||||
EXPECT_EQ(result, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorCallbackServiceTest, ExecutorCallbackServiceTestOnGetProperty002, TestSize.Level0)
|
||||
{
|
||||
Attributes testCondition;
|
||||
Attributes testValues;
|
||||
int32_t testCode = 544857;
|
||||
|
||||
auto testCallback = Common::MakeShared<MockExecutorRegisterCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnGetProperty(_, _)).Times(1);
|
||||
ON_CALL(*testCallback, OnGetProperty)
|
||||
.WillByDefault(
|
||||
[&testCode](const Attributes &conditions, Attributes &results) {
|
||||
EXPECT_TRUE(results.SetInt32Value(Attributes::ATTR_RESULT_CODE, testCode));
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<ExecutorCallbackService>(testCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->OnGetProperty(testCondition, testValues);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
int32_t code = 0;
|
||||
EXPECT_TRUE(testValues.GetInt32Value(Attributes::ATTR_RESULT_CODE, code));
|
||||
EXPECT_EQ(code, testCode);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
148
test/unittest/inner_api/src/executor_messenger_client_test.cpp
Normal file
148
test/unittest/inner_api/src/executor_messenger_client_test.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* 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 "executor_messenger_client_test.h"
|
||||
|
||||
#include "executor_messenger_client.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_executor_messenger.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
void ExecutorMessengerClientTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorMessengerClientTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorMessengerClientTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorMessengerClientTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestSendData001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 6598;
|
||||
uint64_t testTransNum = 8784;
|
||||
ExecutorRole testSrcRole = SCHEDULER;
|
||||
ExecutorRole testDstRole = COLLECTOR;
|
||||
std::vector<uint8_t> message = {1, 2, 4, 6};
|
||||
std::shared_ptr<AuthMessage> testMsg = AuthMessage::As(message);
|
||||
EXPECT_NE(testMsg, nullptr);
|
||||
|
||||
sptr<ExecutorMessengerInterface> testMessenger = nullptr;
|
||||
auto service = Common::MakeShared<ExecutorMessengerClient>(testMessenger);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->SendData(testScheduleId, testTransNum, testSrcRole, testDstRole, testMsg);
|
||||
EXPECT_EQ(result, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestSendData002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 6598;
|
||||
uint64_t testTransNum = 8784;
|
||||
ExecutorRole testSrcRole = SCHEDULER;
|
||||
ExecutorRole testDstRole = COLLECTOR;
|
||||
std::shared_ptr<AuthMessage> testMsg = nullptr;
|
||||
|
||||
sptr<MockExecutorMessenger> testMessenger = new MockExecutorMessenger();
|
||||
EXPECT_NE(testMessenger, nullptr);
|
||||
auto service = Common::MakeShared<ExecutorMessengerClient>(testMessenger);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->SendData(testScheduleId, testTransNum, testSrcRole, testDstRole, testMsg);
|
||||
EXPECT_EQ(result, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestSendData003, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 6598;
|
||||
uint64_t testTransNum = 8784;
|
||||
ExecutorRole testSrcRole = SCHEDULER;
|
||||
ExecutorRole testDstRole = COLLECTOR;
|
||||
std::vector<uint8_t> message = {1, 2, 4, 6};
|
||||
std::shared_ptr<AuthMessage> testMsg = AuthMessage::As(message);
|
||||
EXPECT_NE(testMsg, nullptr);
|
||||
|
||||
sptr<MockExecutorMessenger> testMessenger = new MockExecutorMessenger();
|
||||
EXPECT_NE(testMessenger, nullptr);
|
||||
EXPECT_CALL(*testMessenger, SendData(_, _, _, _, _)).Times(1);
|
||||
ON_CALL(*testMessenger, SendData)
|
||||
.WillByDefault(
|
||||
[&testScheduleId, &testTransNum, &testSrcRole, &testDstRole, &message](uint64_t scheduleId,
|
||||
uint64_t transNum, ExecutorRole srcRole, ExecutorRole dstRole, const std::vector<uint8_t> &msg) {
|
||||
EXPECT_EQ(scheduleId, testScheduleId);
|
||||
EXPECT_EQ(transNum, testTransNum);
|
||||
EXPECT_EQ(srcRole, testSrcRole);
|
||||
EXPECT_EQ(dstRole, testDstRole);
|
||||
EXPECT_THAT(msg, ElementsAreArray(message));
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<ExecutorMessengerClient>(testMessenger);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->SendData(testScheduleId, testTransNum, testSrcRole, testDstRole, testMsg);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestFinish001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 6598;
|
||||
ExecutorRole testSrcRole = SCHEDULER;
|
||||
int32_t testResultCode = FAIL;
|
||||
Attributes finalResult;
|
||||
|
||||
sptr<ExecutorMessengerInterface> testMessenger = nullptr;
|
||||
auto service = Common::MakeShared<ExecutorMessengerClient>(testMessenger);
|
||||
EXPECT_NE(service, nullptr);
|
||||
int32_t result = service->Finish(testScheduleId, testSrcRole, testResultCode, finalResult);
|
||||
EXPECT_EQ(result, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorMessengerClientTest, ExecutorMessengerClientTestFinish002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId = 6598;
|
||||
ExecutorRole testSrcRole = SCHEDULER;
|
||||
int32_t testResultCode = FAIL;
|
||||
Attributes finalResult;
|
||||
|
||||
sptr<MockExecutorMessenger> testMessenger = new MockExecutorMessenger();
|
||||
EXPECT_NE(testMessenger, nullptr);
|
||||
EXPECT_CALL(*testMessenger, Finish(_, _, _, _)).Times(1);
|
||||
ON_CALL(*testMessenger, Finish)
|
||||
.WillByDefault(
|
||||
[&testScheduleId, &testSrcRole, &testResultCode](uint64_t scheduleId, ExecutorRole srcRole,
|
||||
ResultCode resultCode, const std::shared_ptr<Attributes> &finalResult) {
|
||||
EXPECT_EQ(scheduleId, testScheduleId);
|
||||
EXPECT_EQ(srcRole, testSrcRole);
|
||||
EXPECT_EQ(resultCode, testResultCode);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<ExecutorMessengerClient>(testMessenger);
|
||||
int32_t result = service->Finish(testScheduleId, testSrcRole, testResultCode, finalResult);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
180
test/unittest/inner_api/src/user_auth_callback_service_test.cpp
Normal file
180
test/unittest/inner_api/src/user_auth_callback_service_test.cpp
Normal file
@ -0,0 +1,180 @@
|
||||
/*
|
||||
* 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_auth_callback_service_test.h"
|
||||
|
||||
#include "user_auth_callback_service.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_user_auth_client_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
void UserAuthCallbackServiceTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void UserAuthCallbackServiceTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void UserAuthCallbackServiceTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void UserAuthCallbackServiceTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest001, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
Attributes testExtraInfo;
|
||||
|
||||
int32_t testModule = 52334;
|
||||
int32_t testAcquireInfo = 57845;
|
||||
|
||||
std::shared_ptr<AuthenticationCallback> authCallback = nullptr;
|
||||
auto service = Common::MakeShared<UserAuthCallbackService>(authCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnResult(testResult, testExtraInfo);
|
||||
service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest002, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
Attributes testExtraInfo;
|
||||
|
||||
int32_t testModule = 52334;
|
||||
int32_t testAcquireInfo = 57845;
|
||||
|
||||
auto authCallback = Common::MakeShared<MockAuthenticationCallback>();
|
||||
EXPECT_NE(authCallback, nullptr);
|
||||
EXPECT_CALL(*authCallback, OnResult(_, _)).Times(1);
|
||||
ON_CALL(*authCallback, OnResult)
|
||||
.WillByDefault(
|
||||
[&testResult](int32_t result, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(result, testResult);
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*authCallback, OnAcquireInfo(_, _, _)).Times(1);
|
||||
ON_CALL(*authCallback, OnAcquireInfo)
|
||||
.WillByDefault(
|
||||
[&testModule, &testAcquireInfo](int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(module, testModule);
|
||||
EXPECT_EQ(acquireInfo, testAcquireInfo);
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<UserAuthCallbackService>(authCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnResult(testResult, testExtraInfo);
|
||||
service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthCallbackServiceTest, UserAuthCallbackServiceTest003, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
Attributes testExtraInfo;
|
||||
|
||||
int32_t testModule = 52334;
|
||||
int32_t testAcquireInfo = 57845;
|
||||
|
||||
auto identifyCallback = Common::MakeShared<MockIdentificationCallback>();
|
||||
EXPECT_NE(identifyCallback, nullptr);
|
||||
EXPECT_CALL(*identifyCallback, OnResult(_, _)).Times(1);
|
||||
ON_CALL(*identifyCallback, OnResult)
|
||||
.WillByDefault(
|
||||
[&testResult](int32_t result, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(result, testResult);
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*identifyCallback, OnAcquireInfo(_, _, _)).Times(1);
|
||||
ON_CALL(*identifyCallback, OnAcquireInfo)
|
||||
.WillByDefault(
|
||||
[&testModule, &testAcquireInfo](int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(module, testModule);
|
||||
EXPECT_EQ(acquireInfo, testAcquireInfo);
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<UserAuthCallbackService>(identifyCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnResult(testResult, testExtraInfo);
|
||||
service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthCallbackServiceTest, GetExecutorPropertyCallbackServiceTest001, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
Attributes testAttr;
|
||||
|
||||
std::shared_ptr<GetPropCallback> getPropCallback = nullptr;
|
||||
auto service = Common::MakeShared<GetExecutorPropertyCallbackService>(getPropCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnGetExecutorPropertyResult(testResult, testAttr);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthCallbackServiceTest, GetExecutorPropertyCallbackServiceTest002, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
Attributes testAttr;
|
||||
|
||||
auto getPropCallback = Common::MakeShared<MockGetPropCallback>();
|
||||
EXPECT_NE(getPropCallback, nullptr);
|
||||
EXPECT_CALL(*getPropCallback, OnResult(_, _)).Times(1);
|
||||
ON_CALL(*getPropCallback, OnResult)
|
||||
.WillByDefault(
|
||||
[&testResult](int32_t result, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(result, testResult);
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<GetExecutorPropertyCallbackService>(getPropCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnGetExecutorPropertyResult(testResult, testAttr);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthCallbackServiceTest, SetExecutorPropertyCallbackServiceTest001, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
|
||||
std::shared_ptr<SetPropCallback> setPropCallback = nullptr;
|
||||
auto service = Common::MakeShared<SetExecutorPropertyCallbackService>(setPropCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnSetExecutorPropertyResult(testResult);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthCallbackServiceTest, SetExecutorPropertyCallbackServiceTest002, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
|
||||
auto setPropCallback = Common::MakeShared<MockSetPropCallback>();
|
||||
EXPECT_NE(setPropCallback, nullptr);
|
||||
EXPECT_CALL(*setPropCallback, OnResult(_, _)).Times(1);
|
||||
ON_CALL(*setPropCallback, OnResult)
|
||||
.WillByDefault(
|
||||
[&testResult](int32_t result, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(result, testResult);
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<SetExecutorPropertyCallbackService>(setPropCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnSetExecutorPropertyResult(testResult);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -15,13 +15,12 @@
|
||||
|
||||
#include "user_auth_client_test.h"
|
||||
|
||||
#include "file_ex.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
#include "iam_ptr.h"
|
||||
#include "user_auth_client.h"
|
||||
#include "user_auth_client_impl.h"
|
||||
#include "mock_ipc_client_utils.h"
|
||||
#include "mock_remote_object.h"
|
||||
#include "mock_user_auth_service.h"
|
||||
#include "mock_user_auth_client_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -32,12 +31,10 @@ using namespace testing::ext;
|
||||
|
||||
void UserAuthClientTest::SetUpTestCase()
|
||||
{
|
||||
SaveStringToFile("/sys/fs/selinux/enforce", "0");
|
||||
}
|
||||
|
||||
void UserAuthClientTest::TearDownTestCase()
|
||||
{
|
||||
SaveStringToFile("/sys/fs/selinux/enforce", "1");
|
||||
}
|
||||
|
||||
void UserAuthClientTest::SetUp()
|
||||
@ -48,88 +45,465 @@ void UserAuthClientTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetAvailableStatus, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetAvailableStatus001, TestSize.Level0)
|
||||
{
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAtl = ATL1;
|
||||
int32_t ret = UserAuthClientImpl::Instance().GetAvailableStatus(0, testAuthType, testAtl);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
int32_t ret = UserAuthClientImpl::Instance().GetAvailableStatus(testAuthType, testAtl);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetProperty, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetAvailableStatus002, TestSize.Level0)
|
||||
{
|
||||
int32_t testApiVersion = 9;
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAtl = ATL1;
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, GetAvailableStatus(_, _, _)).Times(1);
|
||||
ON_CALL(*service, GetAvailableStatus)
|
||||
.WillByDefault(
|
||||
[&testApiVersion, &testAuthType, &testAtl](int32_t apiVersion, AuthType authType,
|
||||
AuthTrustLevel authTrustLevel) {
|
||||
EXPECT_EQ(apiVersion, testApiVersion);
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
EXPECT_EQ(authTrustLevel, testAtl);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
int32_t ret = UserAuthClientImpl::Instance().GetAvailableStatus(testApiVersion, testAuthType, testAtl);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetProperty001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
GetPropertyRequest testRequest = {};
|
||||
auto testCallback = Common::MakeShared<MockGetPropCallback>();
|
||||
|
||||
std::shared_ptr<MockGetPropCallback> testCallback = nullptr;
|
||||
UserAuthClient::GetInstance().GetProperty(testUserId, testRequest, testCallback);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockGetPropCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
UserAuthClient::GetInstance().GetProperty(testUserId, testRequest, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientSetProperty, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetProperty002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
GetPropertyRequest testRequest = {};
|
||||
testRequest.authType = FACE;
|
||||
testRequest.keys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE};
|
||||
|
||||
auto testCallback = Common::MakeShared<MockGetPropCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, GetProperty(_, _, _, _)).Times(1);
|
||||
ON_CALL(*service, GetProperty)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testRequest](int32_t userId, AuthType authType,
|
||||
const std::vector<Attributes::AttributeKey> &keys,
|
||||
sptr<GetExecutorPropertyCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_EQ(authType, testRequest.authType);
|
||||
EXPECT_THAT(keys, ElementsAreArray(testRequest.keys));
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnGetExecutorPropertyResult(SUCCESS, extraInfo);
|
||||
}
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
UserAuthClient::GetInstance().GetProperty(testUserId, testRequest, testCallback);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientSetProperty001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
SetPropertyRequest testRequest = {};
|
||||
auto testCallback = Common::MakeShared<MockSetPropCallback>();
|
||||
std::shared_ptr<MockSetPropCallback> testCallback = nullptr;
|
||||
UserAuthClient::GetInstance().SetProperty(testUserId, testRequest, testCallback);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockSetPropCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
UserAuthClient::GetInstance().SetProperty(testUserId, testRequest, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication001, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientSetProperty002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
SetPropertyRequest testRequest = {};
|
||||
testRequest.authType = PIN;
|
||||
testRequest.mode = PROPERTY_MODE_DEL;
|
||||
EXPECT_EQ(testRequest.attrs.SetInt32Value(Attributes::ATTR_RESULT_CODE, FAIL), true);
|
||||
auto testCallback = Common::MakeShared<MockSetPropCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, SetProperty(_, _, _, _)).Times(1);
|
||||
ON_CALL(*service, SetProperty)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testRequest](int32_t userId, AuthType authType, const Attributes &attributes,
|
||||
sptr<SetExecutorPropertyCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_EQ(authType, testRequest.authType);
|
||||
int32_t resultCode;
|
||||
EXPECT_EQ(attributes.GetInt32Value(Attributes::ATTR_RESULT_CODE, resultCode), true);
|
||||
EXPECT_EQ(resultCode, FAIL);
|
||||
if (callback != nullptr) {
|
||||
callback->OnSetExecutorPropertyResult(SUCCESS);
|
||||
}
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
UserAuthClient::GetInstance().SetProperty(testUserId, testRequest, testCallback);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginNorthAuthentication001, TestSize.Level0)
|
||||
{
|
||||
int32_t testApiVersion = 8;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 3, 2, 1, 0};
|
||||
AuthType testAuthType = PIN;
|
||||
AuthTrustLevel testAtl = ATL1;
|
||||
std::shared_ptr<MockAuthenticationCallback> testCallback = nullptr;
|
||||
uint64_t contextId = UserAuthClientImpl::Instance().BeginNorthAuthentication(testApiVersion, testChallenge,
|
||||
testAuthType, testAtl, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockAuthenticationCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
contextId = UserAuthClientImpl::Instance().BeginNorthAuthentication(testApiVersion, testChallenge,
|
||||
testAuthType, testAtl, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginNorthAuthentication002, TestSize.Level0)
|
||||
{
|
||||
int32_t testApiVersion = 8;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 3, 2, 1, 0};
|
||||
AuthType testAuthType = PIN;
|
||||
AuthTrustLevel testAtl = ATL1;
|
||||
SetPropertyRequest testRequest = {};
|
||||
auto testCallback = Common::MakeShared<MockAuthenticationCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge, testAuthType, testAtl, testCallback);
|
||||
|
||||
uint64_t testContextId = 15858;
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, Auth(_, _, _, _, _)).Times(1);
|
||||
ON_CALL(*service, Auth)
|
||||
.WillByDefault(
|
||||
[&testApiVersion, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t apiVersion,
|
||||
const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
|
||||
sptr<UserAuthCallbackInterface> &callback) {
|
||||
EXPECT_EQ(apiVersion, testApiVersion);
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
EXPECT_EQ(authTrustLevel, testAtl);
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(SUCCESS, extraInfo);
|
||||
}
|
||||
return testContextId;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
uint64_t contextId = UserAuthClientImpl::Instance().BeginNorthAuthentication(testApiVersion, testChallenge,
|
||||
testAuthType, testAtl, testCallback);
|
||||
EXPECT_EQ(contextId, testContextId);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 84548;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 8, 7, 5, 4};
|
||||
AuthType testAuthType = PIN;
|
||||
AuthTrustLevel testAtl = ATL1;
|
||||
std::shared_ptr<MockAuthenticationCallback> testCallback = nullptr;
|
||||
uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge,
|
||||
testAuthType, testAtl, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockAuthenticationCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge,
|
||||
testAuthType, testAtl, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginAuthentication002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 84548;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4, 8, 7, 5, 4};
|
||||
AuthType testAuthType = PIN;
|
||||
AuthTrustLevel testAtl = ATL1;
|
||||
SetPropertyRequest testRequest = {};
|
||||
auto testCallback = Common::MakeShared<MockAuthenticationCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
UserAuthClientImpl::Instance().BeginNorthAuthentication(0, testChallenge, testAuthType, testAtl, testCallback);
|
||||
|
||||
uint64_t testContextId = 15858;
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, AuthUser(_, _, _, _, _)).Times(1);
|
||||
ON_CALL(*service, AuthUser)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t userId,
|
||||
const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
|
||||
sptr<UserAuthCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
EXPECT_EQ(authTrustLevel, testAtl);
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(SUCCESS, extraInfo);
|
||||
}
|
||||
return testContextId;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
uint64_t contextId = UserAuthClient::GetInstance().BeginAuthentication(testUserId, testChallenge,
|
||||
testAuthType, testAtl, testCallback);
|
||||
EXPECT_EQ(contextId, testContextId);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testContextId = 12345562;
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
int32_t ret = UserAuthClient::GetInstance().CancelAuthentication(testContextId);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginIdentification, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientCancelAuthentication002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testContextId = 12345562;
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, CancelAuthOrIdentify(_)).Times(1);
|
||||
ON_CALL(*service, CancelAuthOrIdentify)
|
||||
.WillByDefault(
|
||||
[&testContextId](uint64_t contextId) {
|
||||
EXPECT_EQ(contextId, testContextId);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
int32_t ret = UserAuthClient::GetInstance().CancelAuthentication(testContextId);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginIdentification001, TestSize.Level0)
|
||||
{
|
||||
std::vector<uint8_t> testChallenge = {4, 5, 6, 7, 3, 4, 1, 2};
|
||||
AuthType testAuthType = FACE;
|
||||
std::shared_ptr<MockIdentificationCallback> testCallback = nullptr;
|
||||
uint64_t contextId = UserAuthClient::GetInstance().BeginIdentification(testChallenge, testAuthType, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockIdentificationCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
contextId = UserAuthClient::GetInstance().BeginIdentification(testChallenge, testAuthType, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientBeginIdentification002, TestSize.Level0)
|
||||
{
|
||||
std::vector<uint8_t> testChallenge = {4, 5, 6, 7, 3, 4, 1, 2};
|
||||
AuthType testAuthType = FACE;
|
||||
auto testCallback = Common::MakeShared<MockIdentificationCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
UserAuthClient::GetInstance().BeginIdentification(testChallenge, testAuthType, testCallback);
|
||||
|
||||
uint64_t testContextId = 548781;
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, Identify(_, _, _)).Times(1);
|
||||
ON_CALL(*service, Identify)
|
||||
.WillByDefault(
|
||||
[&testChallenge, &testAuthType, &testContextId](const std::vector<uint8_t> &challenge,
|
||||
AuthType authType, sptr<UserAuthCallbackInterface> &callback) {
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(SUCCESS, extraInfo);
|
||||
}
|
||||
return testContextId;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
uint64_t contextId = UserAuthClient::GetInstance().BeginIdentification(testChallenge, testAuthType, testCallback);
|
||||
EXPECT_EQ(contextId, testContextId);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientCancelIdentification, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientCancelIdentification001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testContextId = 1221215;
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
int32_t ret = UserAuthClient::GetInstance().CancelIdentification(testContextId);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetVersion, TestSize.Level0)
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientCancelIdentification002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testContextId = 1221215;
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, CancelAuthOrIdentify(_)).Times(1);
|
||||
ON_CALL(*service, CancelAuthOrIdentify)
|
||||
.WillByDefault(
|
||||
[&testContextId](uint64_t contextId) {
|
||||
EXPECT_EQ(contextId, testContextId);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
int32_t ret = UserAuthClient::GetInstance().CancelIdentification(testContextId);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetVersion001, TestSize.Level0)
|
||||
{
|
||||
int32_t version = -1;
|
||||
UserAuthClientImpl::Instance().GetVersion(version);
|
||||
EXPECT_EQ(version, 0);
|
||||
int32_t ret = UserAuthClientImpl::Instance().GetVersion(version);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthClientTest, UserAuthClientGetVersion002, TestSize.Level0)
|
||||
{
|
||||
int32_t testVersion = 20000;
|
||||
|
||||
auto service = Common::MakeShared<MockUserAuthService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, GetVersion(_)).Times(1);
|
||||
ON_CALL(*service, GetVersion)
|
||||
.WillByDefault(
|
||||
[&testVersion](int32_t &version) {
|
||||
version = testVersion;
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
int32_t version;
|
||||
int32_t result = UserAuthClientImpl::Instance().GetVersion(version);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
EXPECT_EQ(version, testVersion);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
195
test/unittest/inner_api/src/user_idm_callback_service_test.cpp
Normal file
195
test/unittest/inner_api/src/user_idm_callback_service_test.cpp
Normal file
@ -0,0 +1,195 @@
|
||||
/*
|
||||
* 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_callback_service_test.h"
|
||||
|
||||
#include "user_idm_callback_service.h"
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_credential_info.h"
|
||||
#include "mock_secure_user_info.h"
|
||||
#include "mock_user_idm_client_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
void UserIdmCallbackServiceTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void UserIdmCallbackServiceTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void UserIdmCallbackServiceTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void UserIdmCallbackServiceTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmCallbackServiceTest, UserIdmCallbackServiceTest001, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
Attributes testExtraInfo;
|
||||
|
||||
int32_t testModule = 52334;
|
||||
int32_t testAcquireInfo = 57845;
|
||||
|
||||
std::shared_ptr<UserIdmClientCallback> idmClientCallback = nullptr;
|
||||
auto service = Common::MakeShared<IdmCallbackService>(idmClientCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnResult(testResult, testExtraInfo);
|
||||
service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmCallbackServiceTest, UserIdmCallbackServiceTest002, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = FAIL;
|
||||
Attributes testExtraInfo;
|
||||
|
||||
int32_t testModule = 52334;
|
||||
int32_t testAcquireInfo = 57845;
|
||||
|
||||
auto idmClientCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(idmClientCallback, nullptr);
|
||||
EXPECT_CALL(*idmClientCallback, OnResult(_, _)).Times(1);
|
||||
ON_CALL(*idmClientCallback, OnResult)
|
||||
.WillByDefault(
|
||||
[&testResult](int32_t result, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(result, testResult);
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*idmClientCallback, OnAcquireInfo(_, _, _)).Times(1);
|
||||
ON_CALL(*idmClientCallback, OnAcquireInfo)
|
||||
.WillByDefault(
|
||||
[&testModule, &testAcquireInfo](int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) {
|
||||
EXPECT_EQ(module, testModule);
|
||||
EXPECT_EQ(acquireInfo, testAcquireInfo);
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<IdmCallbackService>(idmClientCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnResult(testResult, testExtraInfo);
|
||||
service->OnAcquireInfo(testModule, testAcquireInfo, testExtraInfo);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmCallbackServiceTest, IdmGetCredInfoCallbackServiceTest001, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::shared_ptr<IdmGetCredInfoCallbackInterface::CredentialInfo>> testInfoList;
|
||||
|
||||
std::shared_ptr<GetCredentialInfoCallback> getCredInfoCallback = nullptr;
|
||||
auto service = Common::MakeShared<IdmGetCredInfoCallbackService>(getCredInfoCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnCredentialInfos(testInfoList, std::nullopt);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmCallbackServiceTest, IdmGetCredInfoCallbackServiceTest002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testCredentialId = 265326;
|
||||
uint64_t testTemplateId = 62324;
|
||||
AuthType testAuthType = PIN;
|
||||
PinSubType testSubType = PIN_SIX;
|
||||
|
||||
std::vector<std::shared_ptr<IdmGetCredInfoCallbackInterface::CredentialInfo>> testInfoList;
|
||||
testInfoList.push_back(nullptr);
|
||||
auto testCredInfo = Common::MakeShared<MockCredentialInfo>();
|
||||
EXPECT_NE(testCredInfo, nullptr);
|
||||
testInfoList.push_back(testCredInfo);
|
||||
EXPECT_CALL(*testCredInfo, GetCredentialId()).Times(1);
|
||||
ON_CALL(*testCredInfo, GetCredentialId)
|
||||
.WillByDefault(
|
||||
[&testCredentialId]() {
|
||||
return testCredentialId;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*testCredInfo, GetTemplateId()).Times(1);
|
||||
ON_CALL(*testCredInfo, GetTemplateId)
|
||||
.WillByDefault(
|
||||
[&testTemplateId]() {
|
||||
return testTemplateId;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*testCredInfo, GetAuthType()).Times(1);
|
||||
ON_CALL(*testCredInfo, GetAuthType)
|
||||
.WillByDefault(
|
||||
[&testAuthType]() {
|
||||
return testAuthType;
|
||||
}
|
||||
);
|
||||
|
||||
auto getCredInfoCallback = Common::MakeShared<MockGetCredentialInfoCallback>();
|
||||
EXPECT_NE(getCredInfoCallback, nullptr);
|
||||
EXPECT_CALL(*getCredInfoCallback, OnCredentialInfo(_)).Times(1);
|
||||
ON_CALL(*getCredInfoCallback, OnCredentialInfo)
|
||||
.WillByDefault(
|
||||
[&testCredentialId, &testTemplateId, &testAuthType, &testSubType](
|
||||
const std::vector<CredentialInfo> &infoList) {
|
||||
EXPECT_FALSE(infoList.empty());
|
||||
EXPECT_EQ(infoList[0].credentialId, testCredentialId);
|
||||
EXPECT_EQ(infoList[0].templateId, testTemplateId);
|
||||
EXPECT_EQ(infoList[0].authType, testAuthType);
|
||||
EXPECT_TRUE(infoList[0].pinType.has_value());
|
||||
EXPECT_EQ(infoList[0].pinType.value(), testSubType);
|
||||
}
|
||||
);
|
||||
auto service = Common::MakeShared<IdmGetCredInfoCallbackService>(getCredInfoCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnCredentialInfos(testInfoList, testSubType);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmCallbackServiceTest, IdmGetSecureUserInfoCallbackServiceTest001, TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<IdmGetSecureUserInfoCallbackInterface::SecureUserInfo> testUserInfo = nullptr;
|
||||
|
||||
std::shared_ptr<GetSecUserInfoCallback> getSecInfoCallback = nullptr;
|
||||
auto service = Common::MakeShared<IdmGetSecureUserInfoCallbackService>(getSecInfoCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnSecureUserInfo(testUserInfo);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmCallbackServiceTest, IdmGetSecureUserInfoCallbackServiceTest002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testSecUserId = 54871;
|
||||
auto testUserInfo = Common::MakeShared<MockSecureUserInfo>();
|
||||
EXPECT_NE(testUserInfo, nullptr);
|
||||
EXPECT_CALL(*testUserInfo, GetSecUserId()).Times(1);
|
||||
ON_CALL(*testUserInfo, GetSecUserId)
|
||||
.WillByDefault(
|
||||
[&testSecUserId]() {
|
||||
return testSecUserId;
|
||||
}
|
||||
);
|
||||
|
||||
auto getSecInfoCallback = Common::MakeShared<MockGetSecUserInfoCallback>();
|
||||
EXPECT_NE(getSecInfoCallback, nullptr);
|
||||
EXPECT_CALL(*getSecInfoCallback, OnSecUserInfo(_)).Times(1);
|
||||
ON_CALL(*getSecInfoCallback, OnSecUserInfo)
|
||||
.WillByDefault(
|
||||
[&testSecUserId](const SecUserInfo &info) {
|
||||
EXPECT_EQ(info.secureUid, testSecUserId);
|
||||
}
|
||||
);
|
||||
|
||||
auto service = Common::MakeShared<IdmGetSecureUserInfoCallbackService>(getSecInfoCallback);
|
||||
EXPECT_NE(service, nullptr);
|
||||
service->OnSecureUserInfo(testUserInfo);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -15,12 +15,11 @@
|
||||
|
||||
#include "user_idm_client_test.h"
|
||||
|
||||
#include "file_ex.h"
|
||||
#include "nativetoken_kit.h"
|
||||
#include "token_setproc.h"
|
||||
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_ipc_client_utils.h"
|
||||
#include "mock_remote_object.h"
|
||||
#include "mock_user_idm_client_callback.h"
|
||||
#include "mock_user_idm_service.h"
|
||||
#include "user_idm_client.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -31,12 +30,10 @@ using namespace testing::ext;
|
||||
|
||||
void UserIdmClientTest::SetUpTestCase()
|
||||
{
|
||||
SaveStringToFile("/sys/fs/selinux/enforce", "0");
|
||||
}
|
||||
|
||||
void UserIdmClientTest::TearDownTestCase()
|
||||
{
|
||||
SaveStringToFile("/sys/fs/selinux/enforce", "1");
|
||||
}
|
||||
|
||||
void UserIdmClientTest::SetUp()
|
||||
@ -47,47 +44,249 @@ void UserIdmClientTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientOpenSession, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientOpenSession001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 21200;
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
std::vector<uint8_t> challenge = UserIdmClient::GetInstance().OpenSession(testUserId);
|
||||
UserIdmClient::GetInstance().CloseSession(testUserId);
|
||||
EXPECT_TRUE(challenge.empty());
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientCloseSession, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientOpenSession002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 21200;
|
||||
std::vector<uint8_t> testChallenge = {1, 3, 4, 7};
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, OpenSession(_, _)).Times(1);
|
||||
ON_CALL(*service, OpenSession)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testChallenge](int32_t userId, std::vector<uint8_t> &challenge) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
challenge = testChallenge;
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
std::vector<uint8_t> challenge = UserIdmClient::GetInstance().OpenSession(testUserId);
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientCloseSession001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
UserIdmClient::GetInstance().CloseSession(testUserId);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientAddCredential, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientCloseSession002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, CloseSession(_)).Times(1);
|
||||
ON_CALL(*service, CloseSession)
|
||||
.WillByDefault(
|
||||
[&testUserId](int32_t userId) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
return;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
UserIdmClient::GetInstance().CloseSession(testUserId);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientAddCredential001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
CredentialParameters testPara = {};
|
||||
auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
|
||||
UserIdmClient::GetInstance().AddCredential(testUserId, testPara, testCallback);
|
||||
|
||||
testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
IpcClientUtils::ResetObj();
|
||||
UserIdmClient::GetInstance().AddCredential(testUserId, testPara, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientUpdateCredential, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientAddCredential002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
CredentialParameters testPara = {};
|
||||
testPara.authType = FACE;
|
||||
testPara.pinType = std::nullopt;
|
||||
testPara.token = {1, 4, 7, 0};
|
||||
auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, AddCredential(_, _, _, _)).Times(1);
|
||||
ON_CALL(*service, AddCredential)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &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);
|
||||
}
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
UserIdmClient::GetInstance().AddCredential(testUserId, testPara, testCallback);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientUpdateCredential001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
CredentialParameters testPara = {};
|
||||
std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
|
||||
UserIdmClient::GetInstance().UpdateCredential(testUserId, testPara, testCallback);
|
||||
|
||||
testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
IpcClientUtils::ResetObj();
|
||||
UserIdmClient::GetInstance().UpdateCredential(testUserId, testPara, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientCancel, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientUpdateCredential002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
int32_t ret = UserIdmClient::GetInstance().Cancel(testUserId);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
CredentialParameters testPara = {};
|
||||
testPara.authType = PIN;
|
||||
testPara.pinType = PIN_SIX;
|
||||
testPara.token = {1, 4, 7, 0};
|
||||
auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, UpdateCredential(_, _, _)).Times(1);
|
||||
ON_CALL(*service, UpdateCredential)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_EQ(credPara.authType, testPara.authType);
|
||||
EXPECT_TRUE(testPara.pinType.has_value());
|
||||
EXPECT_EQ(credPara.pinType, testPara.pinType.value());
|
||||
EXPECT_THAT(credPara.token, ElementsAreArray(testPara.token));
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(SUCCESS, extraInfo);
|
||||
}
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
UserIdmClient::GetInstance().UpdateCredential(testUserId, testPara, testCallback);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientDeleteCredential, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientCancel001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
int32_t ret = UserIdmClient::GetInstance().Cancel(testUserId);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientCancel002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, Cancel(_)).Times(1);
|
||||
ON_CALL(*service, Cancel)
|
||||
.WillByDefault(
|
||||
[&testUserId](int32_t userId) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
int32_t ret = UserIdmClient::GetInstance().Cancel(testUserId);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientDeleteCredential001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
uint64_t testCredentialId = 111;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
|
||||
UserIdmClient::GetInstance().DeleteCredential(testUserId, testCredentialId, testAuthToken, testCallback);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
UserIdmClient::GetInstance().DeleteCredential(testUserId, testCredentialId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientDeleteCredential002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
uint64_t testCredentialId = 111;
|
||||
@ -95,48 +294,238 @@ HWTEST_F(UserIdmClientTest, UserIdmClientDeleteCredential, TestSize.Level0)
|
||||
auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, DelCredential(_, _, _, _)).Times(1);
|
||||
ON_CALL(*service, DelCredential)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testCredentialId, &testAuthToken](int32_t userId, uint64_t credentialId,
|
||||
const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_EQ(credentialId, testCredentialId);
|
||||
EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(SUCCESS, extraInfo);
|
||||
}
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
UserIdmClient::GetInstance().DeleteCredential(testUserId, testCredentialId, testAuthToken, testCallback);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientDeleteUser, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientDeleteUser001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
|
||||
UserIdmClient::GetInstance().DeleteUser(testUserId, testAuthToken, testCallback);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
UserIdmClient::GetInstance().DeleteUser(testUserId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientDeleteUser002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, DelUser(_, _, _)).Times(1);
|
||||
ON_CALL(*service, DelUser)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testAuthToken](int32_t userId, const std::vector<uint8_t> authToken,
|
||||
const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(SUCCESS, extraInfo);
|
||||
}
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
UserIdmClient::GetInstance().DeleteUser(testUserId, testAuthToken, testCallback);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientEraseUser, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientEraseUser001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
|
||||
int32_t ret = UserIdmClient::GetInstance().EraseUser(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
ret = UserIdmClient::GetInstance().EraseUser(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientEraseUser002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, EnforceDelUser(_, _)).Times(1);
|
||||
ON_CALL(*service, EnforceDelUser)
|
||||
.WillByDefault(
|
||||
[&testUserId](int32_t userId, const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
if (callback != nullptr) {
|
||||
Attributes extraInfo;
|
||||
callback->OnResult(SUCCESS, extraInfo);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
int32_t ret = UserIdmClient::GetInstance().EraseUser(testUserId, testCallback);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientGetCredentialInfo, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientGetCredentialInfo001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
AuthType testAuthType = PIN;
|
||||
std::shared_ptr<MockGetCredentialInfoCallback> testCallback = nullptr;
|
||||
int32_t ret = UserIdmClient::GetInstance().GetCredentialInfo(testUserId, testAuthType, testCallback);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockGetCredentialInfoCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnCredentialInfo(_)).Times(1);
|
||||
ret = UserIdmClient::GetInstance().GetCredentialInfo(testUserId, testAuthType, testCallback);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientGetCredentialInfo002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
AuthType testAuthType = PIN;
|
||||
auto testCallback = Common::MakeShared<MockGetCredentialInfoCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnCredentialInfo(_)).Times(1);
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, GetCredentialInfo(_, _, _)).Times(1);
|
||||
ON_CALL(*service, GetCredentialInfo)
|
||||
.WillByDefault(
|
||||
[&testUserId, &testAuthType](int32_t userId, AuthType authType,
|
||||
const sptr<IdmGetCredInfoCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
if (callback != nullptr) {
|
||||
callback->OnCredentialInfos({}, std::nullopt);
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
int32_t ret = UserIdmClient::GetInstance().GetCredentialInfo(testUserId, testAuthType, testCallback);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientGetSecUserInfo, TestSize.Level0)
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientGetSecUserInfo001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
std::shared_ptr<MockGetSecUserInfoCallback> testCallback = nullptr;
|
||||
int32_t ret = UserIdmClient::GetInstance().GetSecUserInfo(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
|
||||
IpcClientUtils::ResetObj();
|
||||
testCallback = Common::MakeShared<MockGetSecUserInfoCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnSecUserInfo(_)).Times(1);
|
||||
ret = UserIdmClient::GetInstance().GetSecUserInfo(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmClientTest, UserIdmClientGetSecUserInfo002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 200;
|
||||
auto testCallback = Common::MakeShared<MockGetSecUserInfoCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnSecUserInfo(_)).Times(0);
|
||||
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, GetSecInfo(_, _)).Times(1);
|
||||
ON_CALL(*service, GetSecInfo)
|
||||
.WillByDefault(
|
||||
[&testUserId](int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_NE(callback, nullptr);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
IpcClientUtils::SetObj(obj);
|
||||
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;
|
||||
});
|
||||
|
||||
int32_t ret = UserIdmClient::GetInstance().GetSecUserInfo(testUserId, testCallback);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
IpcClientUtils::ResetObj();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -161,9 +161,10 @@ HWTEST_F(UserIdmProxyTest, UserIdmProxyGetSecInfo, TestSize.Level0)
|
||||
HWTEST_F(UserIdmProxyTest, UserIdmProxyAddCredential, TestSize.Level0)
|
||||
{
|
||||
static const int32_t testUserId = 200;
|
||||
static const AuthType testAuthType = FACE;
|
||||
static const PinSubType testPinSubType = PIN_SIX;
|
||||
static const std::vector<uint8_t> testToken = {1, 2, 3, 4};
|
||||
UserIdmInterface::CredentialPara testCredPara = {};
|
||||
testCredPara.authType = FACE;
|
||||
testCredPara.pinType = PIN_SIX;
|
||||
testCredPara.token = {1, 2, 3, 4};
|
||||
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
@ -174,15 +175,14 @@ HWTEST_F(UserIdmProxyTest, UserIdmProxyAddCredential, TestSize.Level0)
|
||||
sptr<IdmCallbackInterface> testCallback = new (std::nothrow) IdmCallbackService(idmCallback);
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, AddCredential(_, _, _, _, _, _))
|
||||
EXPECT_CALL(*service, AddCredential(_, _, _, _))
|
||||
.Times(Exactly(1))
|
||||
.WillOnce([&testCallback](int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate) {
|
||||
EXPECT_EQ(testUserId, userId);
|
||||
EXPECT_EQ(testAuthType, authType);
|
||||
EXPECT_EQ(testPinSubType, pinSubType);
|
||||
EXPECT_THAT(testToken, ElementsAre(1, 2, 3, 4));
|
||||
EXPECT_EQ(testCallback, callback);
|
||||
.WillOnce([&testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &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);
|
||||
@ -191,15 +191,16 @@ HWTEST_F(UserIdmProxyTest, UserIdmProxyAddCredential, TestSize.Level0)
|
||||
service->OnRemoteRequest(code, data, reply, option);
|
||||
return SUCCESS;
|
||||
});
|
||||
proxy->AddCredential(testUserId, testAuthType, testPinSubType, testToken, testCallback, false);
|
||||
proxy->AddCredential(testUserId, testCredPara, testCallback, false);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmProxyTest, UserIdmProxyUpdateCredential, TestSize.Level0)
|
||||
{
|
||||
static const int32_t testUserId = 200;
|
||||
static const AuthType testAuthType = FACE;
|
||||
static const PinSubType testPinSubType = PIN_SIX;
|
||||
static const std::vector<uint8_t> testToken = {1, 2, 3, 4};
|
||||
UserIdmInterface::CredentialPara testCredPara = {};
|
||||
testCredPara.authType = FACE;
|
||||
testCredPara.pinType = PIN_SIX;
|
||||
testCredPara.token = {1, 2, 3, 4};
|
||||
|
||||
sptr<MockRemoteObject> obj = new MockRemoteObject();
|
||||
EXPECT_NE(obj, nullptr);
|
||||
@ -210,15 +211,14 @@ HWTEST_F(UserIdmProxyTest, UserIdmProxyUpdateCredential, TestSize.Level0)
|
||||
sptr<IdmCallbackInterface> testCallback = new (std::nothrow) IdmCallbackService(idmCallback);
|
||||
auto service = Common::MakeShared<MockUserIdmService>();
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_CALL(*service, UpdateCredential(_, _, _, _, _))
|
||||
EXPECT_CALL(*service, UpdateCredential(_, _, _))
|
||||
.Times(Exactly(1))
|
||||
.WillOnce([&testCallback](int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_EQ(testUserId, userId);
|
||||
EXPECT_EQ(testAuthType, authType);
|
||||
EXPECT_EQ(testPinSubType, pinSubType);
|
||||
EXPECT_THAT(testToken, ElementsAre(1, 2, 3, 4));
|
||||
EXPECT_EQ(testCallback, callback);
|
||||
.WillOnce([&testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &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);
|
||||
@ -227,7 +227,7 @@ HWTEST_F(UserIdmProxyTest, UserIdmProxyUpdateCredential, TestSize.Level0)
|
||||
service->OnRemoteRequest(code, data, reply, option);
|
||||
return SUCCESS;
|
||||
});
|
||||
proxy->UpdateCredential(testUserId, testAuthType, testPinSubType, testToken, testCallback);
|
||||
proxy->UpdateCredential(testUserId, testCredPara, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmProxyTest, UserIdmProxyCancel, TestSize.Level0)
|
||||
|
@ -57,12 +57,14 @@ ohos_unittest("iam_services_test") {
|
||||
"//base/useriam/user_auth_framework/services/core/src/user_idm_session_controller_impl.cpp",
|
||||
"//base/useriam/user_auth_framework/services/ipc/src/co_auth_service.cpp",
|
||||
"//base/useriam/user_auth_framework/services/ipc/src/executor_messenger_service.cpp",
|
||||
"//base/useriam/user_auth_framework/services/ipc/src/ipc_common.cpp",
|
||||
"//base/useriam/user_auth_framework/services/ipc/src/user_auth_service.cpp",
|
||||
"//base/useriam/user_auth_framework/services/ipc/src/user_idm_service.cpp",
|
||||
"mocks/mock_ipc_common.cpp",
|
||||
"mocks/mock_iuser_auth_interface.cpp",
|
||||
"src/attributes_test.cpp",
|
||||
"src/authentication_impl_test.cpp",
|
||||
"src/co_auth_service_test.cpp",
|
||||
"src/co_auth_stub_test.cpp",
|
||||
"src/context_callback_impl_test.cpp",
|
||||
"src/context_factory_test.cpp",
|
||||
"src/context_pool_test.cpp",
|
||||
@ -70,11 +72,14 @@ ohos_unittest("iam_services_test") {
|
||||
"src/enroll_context_test.cpp",
|
||||
"src/enrolled_info_test.cpp",
|
||||
"src/enrollment_impl_test.cpp",
|
||||
"src/executor_messenger_service_test.cpp",
|
||||
"src/identification_impl_test.cpp",
|
||||
"src/identify_context_test.cpp",
|
||||
"src/relative_timer_test.cpp",
|
||||
"src/resource_node_pool_test.cpp",
|
||||
"src/resource_node_test.cpp",
|
||||
"src/resource_node_utils_test.cpp",
|
||||
"src/schedule_node_helper_test.cpp",
|
||||
"src/schedule_node_test.cpp",
|
||||
"src/secure_user_info_test.cpp",
|
||||
"src/simple_auth_context_test.cpp",
|
||||
|
37
test/unittest/services/inc/co_auth_stub_test.h
Normal file
37
test/unittest/services/inc/co_auth_stub_test.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_CO_AUTH_STUB_TEST_H
|
||||
#define IAM_CO_AUTH_STUB_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class CoAuthStubTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // IAM_CO_AUTH_STUB_TEST_H
|
37
test/unittest/services/inc/executor_messenger_service_test.h
Normal file
37
test/unittest/services/inc/executor_messenger_service_test.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_SERVICE_TEST_H
|
||||
#define EXECUTOR_MESSENGER_SERVICE_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ExecutorMessengerServiceTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // EXECUTOR_MESSENGER_SERVICE_TEST_H
|
37
test/unittest/services/inc/resource_node_utils_test.h
Normal file
37
test/unittest/services/inc/resource_node_utils_test.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_RESOURCE_NODE_UTILS_TEST_H
|
||||
#define IAM_RESOURCE_NODE_UTILS_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ResourceNodeUtilsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // IAM_RESOURCE_NODE_UTILS_TEST_H
|
37
test/unittest/services/inc/schedule_node_helper_test.h
Normal file
37
test/unittest/services/inc/schedule_node_helper_test.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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_SCHEDULE_NODE_HELPER_TEST_H
|
||||
#define IAM_SCHEDULE_NODE_HELPER_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class ScheduleNodeHelperTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
|
||||
static void TearDownTestCase();
|
||||
|
||||
void SetUp() override;
|
||||
|
||||
void TearDown() override;
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // IAM_SCHEDULE_NODE_HELPER_TEST_H
|
@ -17,12 +17,12 @@
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "credential_info.h"
|
||||
#include "user_idm_callback_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class MockCredentialInfo final : public CredentialInfo {
|
||||
class MockCredentialInfo final : public IdmGetCredInfoCallbackInterface::CredentialInfo {
|
||||
public:
|
||||
virtual ~MockCredentialInfo() = default;
|
||||
MOCK_CONST_METHOD0(GetCredentialId, uint64_t());
|
||||
|
@ -16,15 +16,15 @@
|
||||
#define IAM_MOCK_EXECUTOR_CALLBACK_H
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include "iremote_stub.h"
|
||||
|
||||
#include "executor_callback_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class MockExecutorCallback final : public ExecutorCallbackInterface {
|
||||
class MockExecutorCallback final : public IRemoteStub<ExecutorCallbackInterface> {
|
||||
public:
|
||||
MOCK_METHOD0(AsObject, sptr<IRemoteObject>());
|
||||
MOCK_METHOD4(OnRemoteRequest,
|
||||
int32_t(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option));
|
||||
MOCK_METHOD3(OnMessengerReady,
|
||||
|
78
test/unittest/services/mocks/mock_ipc_common.cpp
Normal file
78
test/unittest/services/mocks/mock_ipc_common.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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 "mock_ipc_common.h"
|
||||
|
||||
#include "iam_common_defines.h"
|
||||
#include "iam_logger.h"
|
||||
#ifdef HAS_OS_ACCOUNT_PART
|
||||
#include "os_account_manager.h"
|
||||
#endif // HAS_OS_ACCOUNT_PART
|
||||
#define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA
|
||||
|
||||
namespace {
|
||||
const uint32_t TEST_USER_ID = 548781;
|
||||
}
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
int32_t IpcCommon::GetCallingUserId(IPCObjectStub &stub, int32_t &userId)
|
||||
{
|
||||
if (userId != 0) {
|
||||
return SUCCESS;
|
||||
}
|
||||
userId = TEST_USER_ID;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
int32_t IpcCommon::GetActiveUserId(std::optional<int32_t> &userId)
|
||||
{
|
||||
if (userId.has_value() && userId.value() != 0) {
|
||||
return SUCCESS;
|
||||
}
|
||||
std::vector<int32_t> ids;
|
||||
#ifdef HAS_OS_ACCOUNT_PART
|
||||
ErrCode queryRet = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
|
||||
if (queryRet != ERR_OK || ids.empty()) {
|
||||
IAM_LOGE("failed to query active account id");
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
#else // HAS_OS_ACCOUNT_PART
|
||||
const int32_t DEFAULT_OS_ACCOUNT_ID = 0;
|
||||
ids.push_back(DEFAULT_OS_ACCOUNT_ID);
|
||||
IAM_LOGI("there is no os account part, use default id");
|
||||
#endif // HAS_OS_ACCOUNT_PART
|
||||
userId = ids.front();
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
// for unittest only
|
||||
bool IpcCommon::CheckPermission(IPCObjectStub &stub, Permission permission)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t IpcCommon::GetAccessTokenId(IPCObjectStub &stub)
|
||||
{
|
||||
uint32_t tokenId = stub.GetFirstTokenID();
|
||||
if (tokenId == 0) {
|
||||
tokenId = stub.GetCallingTokenID();
|
||||
}
|
||||
return tokenId;
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
68
test/unittest/services/mocks/mock_ipc_common.h
Normal file
68
test/unittest/services/mocks/mock_ipc_common.h
Normal file
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 MOCK_IPC_COMMON_H
|
||||
#define MOCK_IPC_COMMON_H
|
||||
|
||||
#include <cinttypes>
|
||||
#include <iremote_stub.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
enum Permission {
|
||||
MANAGE_USER_IDM_PERMISSION,
|
||||
USE_USER_IDM_PERMISSION,
|
||||
ACCESS_USER_AUTH_INTERNAL_PERMISSION,
|
||||
ACCESS_BIOMETRIC_PERMISSION,
|
||||
ACCESS_AUTH_RESPOOL,
|
||||
ENFORCE_USER_IDM,
|
||||
};
|
||||
|
||||
class IpcCommon final : public NoCopyable {
|
||||
public:
|
||||
using Recipient = std::function<void()>;
|
||||
static int32_t GetCallingUserId(IPCObjectStub &stub, int32_t &userId);
|
||||
static int32_t GetActiveUserId(std::optional<int32_t> &userId);
|
||||
static bool CheckPermission(IPCObjectStub &stub, Permission permission);
|
||||
static uint32_t GetAccessTokenId(IPCObjectStub &stub);
|
||||
class PeerDeathRecipient final : public IPCObjectProxy::DeathRecipient {
|
||||
public:
|
||||
explicit PeerDeathRecipient(Recipient &&recipient) : recipient_(std::forward<Recipient>(recipient))
|
||||
{
|
||||
}
|
||||
~PeerDeathRecipient() override = default;
|
||||
void OnRemoteDied(const wptr<IRemoteObject> &object) override
|
||||
{
|
||||
if (auto remote = object.promote(); !remote) {
|
||||
return;
|
||||
}
|
||||
if (recipient_) {
|
||||
recipient_();
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
Recipient recipient_;
|
||||
};
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
#endif // MOCK_IPC_COMMON_H
|
@ -17,18 +17,19 @@
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "secure_user_info.h"
|
||||
#include "user_idm_callback_interface.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
class MockSecureUserInfo final : public SecureUserInfo {
|
||||
class MockSecureUserInfo final : public IdmGetSecureUserInfoCallbackInterface::SecureUserInfo {
|
||||
public:
|
||||
~MockSecureUserInfo() override = default;
|
||||
MOCK_CONST_METHOD0(GetUserId, int32_t());
|
||||
MOCK_CONST_METHOD0(GetPinSubType, PinSubType());
|
||||
MOCK_CONST_METHOD0(GetSecUserId, uint64_t());
|
||||
MOCK_CONST_METHOD0(GetEnrolledInfo, std::vector<std::shared_ptr<EnrolledInfo>>());
|
||||
MOCK_CONST_METHOD0(GetEnrolledInfo,
|
||||
std::vector<std::shared_ptr<IdmGetSecureUserInfoCallbackInterface::EnrolledInfo>>());
|
||||
};
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -14,9 +14,11 @@
|
||||
*/
|
||||
#ifndef IAM_MOCK_USER_IDM_CALLBACK_H
|
||||
#define IAM_MOCK_USER_IDM_CALLBACK_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <gmock/gmock.h>
|
||||
#include <iremote_stub.h>
|
||||
|
||||
#include "user_idm_callback_interface.h"
|
||||
|
||||
|
@ -30,10 +30,10 @@ public:
|
||||
MOCK_METHOD3(GetCredentialInfo, int32_t(int32_t userId, AuthType authType,
|
||||
const sptr<IdmGetCredInfoCallbackInterface> &callback));
|
||||
MOCK_METHOD2(GetSecInfo, int32_t(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback));
|
||||
MOCK_METHOD6(AddCredential, void(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate));
|
||||
MOCK_METHOD5(UpdateCredential, void(int32_t userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback));
|
||||
MOCK_METHOD4(AddCredential, void(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback, bool isUpdate));
|
||||
MOCK_METHOD3(UpdateCredential, void(int32_t userId, const CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &callback));
|
||||
MOCK_METHOD1(Cancel, int32_t(int32_t userId));
|
||||
MOCK_METHOD2(EnforceDelUser, int32_t(int32_t userId, const sptr<IdmCallbackInterface> &callback));
|
||||
MOCK_METHOD3(DelUser, void(int32_t userId, const std::vector<uint8_t> authToken,
|
||||
|
@ -15,14 +15,31 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#include "authentication_impl.h"
|
||||
#include "resource_node_pool.h"
|
||||
#include "mock_iuser_auth_interface.h"
|
||||
#include "mock_resource_node.h"
|
||||
#include "mock_schedule_node_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
using HdiAuthResultInfo = OHOS::HDI::UserAuth::V1_0::AuthResultInfo;
|
||||
using HdiAuthSolution = OHOS::HDI::UserAuth::V1_0::AuthSolution;
|
||||
using HdiExecutorSendMsg = OHOS::HDI::UserAuth::V1_0::ExecutorSendMsg;
|
||||
using HdiAuthType = OHOS::HDI::UserAuth::V1_0::AuthType;
|
||||
using HdiEnrollParam = OHOS::HDI::UserAuth::V1_0::EnrollParam;
|
||||
using HdiExecutorInfo = OHOS::HDI::UserAuth::V1_0::ExecutorInfo;
|
||||
using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_0::ScheduleInfo;
|
||||
using HdiExecutorRole = OHOS::HDI::UserAuth::V1_0::ExecutorRole;
|
||||
using HdiScheduleMode = OHOS::HDI::UserAuth::V1_0::ScheduleMode;
|
||||
using HdiExecutorSecureLevel = OHOS::HDI::UserAuth::V1_0::ExecutorSecureLevel;
|
||||
|
||||
class AuthenticationImplTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@ -114,6 +131,107 @@ HWTEST_F(AuthenticationImplTest, AuthenticationInvalidExecutor, TestSize.Level0)
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
EXPECT_FALSE(authentication->Start(scheduleList, nullptr));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate001, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 54871;
|
||||
constexpr int32_t userId = 1534;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, UpdateAuthenticationResult(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, UpdateAuthenticationResult)
|
||||
.WillByDefault(
|
||||
[](uint64_t contextId, const std::vector<uint8_t> &scheduleResult, HdiAuthResultInfo &info) {
|
||||
info.result = HDF_SUCCESS;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
EXPECT_NE(authentication, nullptr);
|
||||
std::vector<uint8_t> scheduleResult;
|
||||
Authentication::AuthResultInfo info = {};
|
||||
EXPECT_TRUE(authentication->Update(scheduleResult, info));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestUpdate002, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 54871;
|
||||
constexpr int32_t userId = 1534;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, UpdateAuthenticationResult(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, UpdateAuthenticationResult)
|
||||
.WillByDefault(
|
||||
[](uint64_t contextId, const std::vector<uint8_t> &scheduleResult, HdiAuthResultInfo &info) {
|
||||
info.result = HDF_FAILURE;
|
||||
HdiExecutorSendMsg msg = {};
|
||||
msg.commandId = 10;
|
||||
msg.executorIndex = 20;
|
||||
info.msgs.push_back(msg);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
);
|
||||
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
EXPECT_NE(authentication, nullptr);
|
||||
std::vector<uint8_t> scheduleResult;
|
||||
Authentication::AuthResultInfo info = {};
|
||||
EXPECT_FALSE(authentication->Update(scheduleResult, info));
|
||||
}
|
||||
|
||||
HWTEST_F(AuthenticationImplTest, AuthenticationImplTestStart, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 34567;
|
||||
constexpr uint64_t userId = 25781;
|
||||
constexpr uint64_t executorIndex = 60;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, CancelAuthentication(_))
|
||||
.Times(2)
|
||||
.WillOnce(Return(HDF_SUCCESS))
|
||||
.WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _))
|
||||
.WillRepeatedly(
|
||||
[](uint64_t contextId, const HdiAuthSolution ¶m, std::vector<HdiScheduleInfo> &scheduleInfos) {
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
scheduleInfo.authType = HdiAuthType::FACE;
|
||||
scheduleInfo.executorMatcher = 10;
|
||||
HdiExecutorInfo executorInfo = {};
|
||||
executorInfo.executorIndex = 60;
|
||||
executorInfo.info.authType = HdiAuthType::FACE;
|
||||
executorInfo.info.esl = HdiExecutorSecureLevel::ESL1;
|
||||
executorInfo.info.executorMatcher = 10;
|
||||
executorInfo.info.executorRole = HdiExecutorRole::ALL_IN_ONE;
|
||||
executorInfo.info.executorSensorHint = 90;
|
||||
executorInfo.info.publicKey = {1, 2, 3, 4};
|
||||
scheduleInfo.executors.push_back(executorInfo);
|
||||
scheduleInfo.scheduleId = 20;
|
||||
scheduleInfo.scheduleMode = HdiScheduleMode::AUTH;
|
||||
scheduleInfo.templateIds.push_back(30);
|
||||
scheduleInfos.push_back(scheduleInfo);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, FACE, ALL_IN_ONE);
|
||||
EXPECT_NE(resourceNode, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
|
||||
auto authentication = std::make_shared<AuthenticationImpl>(contextId, userId, FACE, ATL3);
|
||||
EXPECT_NE(authentication, nullptr);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_TRUE(authentication->Start(scheduleList, callback));
|
||||
EXPECT_TRUE(authentication->Cancel());
|
||||
|
||||
EXPECT_TRUE(authentication->Start(scheduleList, callback));
|
||||
EXPECT_FALSE(authentication->Cancel());
|
||||
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -16,9 +16,10 @@
|
||||
#include "co_auth_service_test.h"
|
||||
|
||||
#include "co_auth_service.h"
|
||||
#include "executor_callback_stub.h"
|
||||
|
||||
#include <message_parcel.h>
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_executor_callback.h"
|
||||
#include "mock_iuser_auth_interface.h"
|
||||
#include "resource_node_pool.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
@ -36,37 +37,71 @@ void CoAuthServiceTest::TearDownTestCase()
|
||||
|
||||
void CoAuthServiceTest::SetUp()
|
||||
{
|
||||
MockIUserAuthInterface::Holder::GetInstance().Reset();
|
||||
}
|
||||
|
||||
void CoAuthServiceTest::TearDown()
|
||||
{
|
||||
MockIUserAuthInterface::Holder::GetInstance().Reset();
|
||||
}
|
||||
|
||||
HWTEST_F(CoAuthServiceTest, CoAuthServiceTestOnRemoteRequest, TestSize.Level0)
|
||||
HWTEST_F(CoAuthServiceTest, CoAuthServiceTest001, TestSize.Level0)
|
||||
{
|
||||
sptr<ExecutorCallbackStub> callback = new (std::nothrow) ExecutorCallbackStub();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
ExecutorRegisterInfo info = {};
|
||||
info.authType = PIN;
|
||||
sptr<ExecutorCallbackInterface> testCallback = new MockExecutorCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
sptr<MockExecutorCallback> tempCallback = static_cast<MockExecutorCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
|
||||
CoAuthInterface::ExecutorRegisterInfo info = {};
|
||||
info.authType = FINGERPRINT;
|
||||
info.executorRole = SCHEDULER;
|
||||
info.executorSensorHint = 0;
|
||||
info.executorMatcher = 0;
|
||||
info.esl = ESL1;
|
||||
info.publicKey = {'a', 'b', 'c', 'd'};
|
||||
EXPECT_EQ(data.WriteInt32(info.authType), true);
|
||||
EXPECT_EQ(data.WriteInt32(info.executorRole), true);
|
||||
EXPECT_EQ(data.WriteInt32(info.esl), true);
|
||||
EXPECT_EQ(data.WriteUInt8Vector(info.publicKey), true);
|
||||
EXPECT_EQ(data.WriteRemoteObject(callback->AsObject()), true);
|
||||
uint32_t code = static_cast<uint32_t>(ICoAuth::CO_AUTH_EXECUTOR_REGISTER);
|
||||
|
||||
auto service = Common::MakeShared<CoAuthService>(1, true);
|
||||
EXPECT_NE(service, nullptr);
|
||||
EXPECT_EQ(service->OnRemoteRequest(code, data, reply), 0);
|
||||
uint64_t executorIndex = 0;
|
||||
EXPECT_EQ(reply.ReadUint64(executorIndex), true);
|
||||
EXPECT_NE(executorIndex, 0);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnMessengerReady(_, _, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, AddExecutor(_, _, _, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, DeleteExecutor(_)).Times(1);
|
||||
uint64_t executorIndex = service->ExecutorRegister(info, testCallback);
|
||||
EXPECT_EQ(executorIndex, 0);
|
||||
EXPECT_EQ(ResourceNodePool::Instance().Delete(executorIndex), true);
|
||||
}
|
||||
|
||||
HWTEST_F(CoAuthServiceTest, CoAuthServiceTest003, TestSize.Level0)
|
||||
{
|
||||
auto service = Common::MakeShared<CoAuthService>(1, true);
|
||||
EXPECT_NE(service, nullptr);
|
||||
|
||||
CoAuthInterface::ExecutorRegisterInfo info = {};
|
||||
sptr<ExecutorCallbackInterface> testCallback = nullptr;
|
||||
uint64_t executorIndex = service->ExecutorRegister(info, testCallback);
|
||||
EXPECT_EQ(executorIndex, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(CoAuthServiceTest, CoAuthServiceTest004, TestSize.Level0)
|
||||
{
|
||||
int testFd1 = -1;
|
||||
int testFd2 = 1;
|
||||
std::vector<std::u16string> testArgs;
|
||||
|
||||
auto service = Common::MakeShared<CoAuthService>(1, true);
|
||||
EXPECT_NE(service, nullptr);
|
||||
|
||||
EXPECT_EQ(service->Dump(testFd1, testArgs), INVALID_PARAMETERS);
|
||||
EXPECT_EQ(service->Dump(testFd2, testArgs), SUCCESS);
|
||||
testArgs.push_back(u"-h");
|
||||
EXPECT_EQ(service->Dump(testFd2, testArgs), SUCCESS);
|
||||
testArgs.clear();
|
||||
testArgs.push_back(u"-l");
|
||||
EXPECT_EQ(service->Dump(testFd2, testArgs), SUCCESS);
|
||||
testArgs.clear();
|
||||
testArgs.push_back(u"-k");
|
||||
EXPECT_EQ(service->Dump(testFd2, testArgs), GENERAL_ERROR);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
120
test/unittest/services/src/co_auth_stub_test.cpp
Normal file
120
test/unittest/services/src/co_auth_stub_test.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* 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_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.publicKey = {'a', 'b', 'c', 'd'};
|
||||
|
||||
uint64_t testContextId = 124545;
|
||||
|
||||
sptr<MockExecutorCallback> callback = new MockExecutorCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
MockCoAuthService service;
|
||||
EXPECT_CALL(service, ExecutorRegister(_, _)).Times(1);
|
||||
ON_CALL(service, ExecutorRegister)
|
||||
.WillByDefault(
|
||||
[&testInfo, &testContextId](const CoAuthInterface::ExecutorRegisterInfo &info,
|
||||
sptr<ExecutorCallbackInterface> &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.WriteUInt8Vector(testInfo.publicKey));
|
||||
EXPECT_NE(callback->AsObject(), nullptr);
|
||||
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
|
||||
uint32_t code = CoAuthInterface::CO_AUTH_EXECUTOR_REGISTER;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
uint64_t contextId = -1;
|
||||
EXPECT_TRUE(reply.ReadUint64(contextId));
|
||||
EXPECT_EQ(contextId, testContextId);
|
||||
}
|
||||
|
||||
HWTEST_F(CoAuthStubTest, CoAuthStubTestExecutorRegister002, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
|
||||
uint32_t code = CoAuthInterface::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 = CoAuthInterface::CO_AUTH_EXECUTOR_REGISTER;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
MockCoAuthService service;
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -92,21 +92,24 @@ HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserAuth, TestSize.Level0)
|
||||
HWTEST_F(ContextCallbackImplTest, ContextCallbackImplUserIdmOnResult, TestSize.Level0)
|
||||
{
|
||||
int32_t testResult = 66;
|
||||
std::vector<uint8_t> testMsg = {1, 2, 3, 4};
|
||||
auto testAttr = Common::MakeShared<Attributes>();
|
||||
ASSERT_TRUE(testAttr != nullptr);
|
||||
EXPECT_TRUE(testAttr->SetInt32Value(Attributes::ATTR_REMAIN_TIMES, 2));
|
||||
EXPECT_TRUE(testAttr->SetInt32Value(Attributes::ATTR_FREEZING_TIME, 40));
|
||||
|
||||
auto notify = [](const ContextCallbackNotifyListener::MetaData &metaData) { return; };
|
||||
ContextCallbackNotifyListener::GetInstance().AddNotifier(notify);
|
||||
ContextCallbackNotifyListener::GetInstance().AddNotifier(nullptr);
|
||||
|
||||
sptr<MockIdmCallback> mockCallback = new (nothrow) MockIdmCallback();
|
||||
ASSERT_TRUE(mockCallback != nullptr);
|
||||
EXPECT_CALL(*mockCallback, OnResult(_, _))
|
||||
.Times(Exactly(1))
|
||||
.WillOnce([&testResult, &testAttr](int32_t result, const Attributes &reqRet) {
|
||||
EXPECT_TRUE(testResult == result);
|
||||
EXPECT_TRUE(&reqRet == testAttr.get());
|
||||
});
|
||||
EXPECT_CALL(*mockCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockCallback, OnAcquireInfo(_, _, _)).Times(1);
|
||||
sptr<IdmCallbackInterface> callback = mockCallback;
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL);
|
||||
ASSERT_NE(contextCallback, nullptr);
|
||||
contextCallback->OnAcquireInfo(static_cast<ExecutorRole>(0), 0, {});
|
||||
contextCallback->OnAcquireInfo(static_cast<ExecutorRole>(0), 0, testMsg);
|
||||
contextCallback->OnResult(testResult, *testAttr);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
|
@ -59,8 +59,8 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_001, TestSize.Level0
|
||||
sptr<UserAuthCallbackInterface> callback = new (nothrow) MockUserAuthCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER);
|
||||
auto context = factory->CreateSimpleAuthContext(
|
||||
0, challenge, static_cast<AuthType>(0), static_cast<AuthTrustLevel>(0), 0, contextCallback);
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
auto context = factory->CreateSimpleAuthContext(para, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
EXPECT_NE(context->GetContextId(), 0U);
|
||||
ASSERT_EQ(context->GetContextType(), CONTEXT_SIMPLE_AUTH);
|
||||
@ -74,8 +74,8 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateSimpleAuth_002, TestSize.Level0
|
||||
// Error: callback is null
|
||||
sptr<UserAuthCallbackInterface> callback = nullptr;
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_AUTH_USER);
|
||||
auto context = factory->CreateSimpleAuthContext(
|
||||
0, challenge, static_cast<AuthType>(0), static_cast<AuthTrustLevel>(0), 0, contextCallback);
|
||||
ContextFactory::AuthContextPara para = {};
|
||||
auto context = factory->CreateSimpleAuthContext(para, contextCallback);
|
||||
ASSERT_EQ(context, nullptr);
|
||||
}
|
||||
|
||||
@ -87,7 +87,8 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_001, TestSize.Level0)
|
||||
sptr<UserAuthCallbackInterface> callback = new (nothrow) MockUserAuthCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY);
|
||||
auto context = factory->CreateIdentifyContext(challenge, static_cast<AuthType>(0), 0, contextCallback);
|
||||
ContextFactory::IdentifyContextPara para = {};
|
||||
auto context = factory->CreateIdentifyContext(para, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
EXPECT_NE(context->GetContextId(), 0U);
|
||||
ASSERT_EQ(context->GetContextType(), CONTEXT_IDENTIFY);
|
||||
@ -101,7 +102,8 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateIdentify_002, TestSize.Level0)
|
||||
// Error: callback is null
|
||||
sptr<UserAuthCallbackInterface> callback = nullptr;
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_IDENTIFY);
|
||||
auto context = factory->CreateIdentifyContext(challenge, static_cast<AuthType>(0), 0, contextCallback);
|
||||
ContextFactory::IdentifyContextPara para = {};
|
||||
auto context = factory->CreateIdentifyContext(para, contextCallback);
|
||||
ASSERT_EQ(context, nullptr);
|
||||
}
|
||||
|
||||
@ -113,8 +115,8 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_001, TestSize.Lev
|
||||
sptr<IdmCallbackInterface> callback = new (nothrow) MockIdmCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL);
|
||||
auto context = factory->CreateEnrollContext(0, static_cast<AuthType>(0), static_cast<PinSubType>(0), token,
|
||||
0, contextCallback);
|
||||
ContextFactory::EnrollContextPara para = {};
|
||||
auto context = factory->CreateEnrollContext(para, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
EXPECT_NE(context->GetContextId(), 0U);
|
||||
ASSERT_EQ(context->GetContextType(), CONTEXT_ENROLL);
|
||||
@ -128,8 +130,8 @@ HWTEST_F(ContextFactoryTest, ContextFactoryCreateEnrollContext_002, TestSize.Lev
|
||||
// Error: callback is null
|
||||
sptr<IdmCallbackInterface> callback = nullptr;
|
||||
auto contextCallback = ContextCallback::NewInstance(callback, TRACE_ADD_CREDENTIAL);
|
||||
auto context = factory->CreateEnrollContext(0, static_cast<AuthType>(0), static_cast<PinSubType>(0), token,
|
||||
0, contextCallback);
|
||||
ContextFactory::EnrollContextPara para = {};
|
||||
auto context = factory->CreateEnrollContext(para, contextCallback);
|
||||
ASSERT_EQ(context, nullptr);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
|
@ -100,6 +100,7 @@ HWTEST_F(ContextPoolTest, ContextPoolInsertAndDelete, TestSize.Level0)
|
||||
auto context1 = MockContext::CreateWithContextId(CONTEXT_ID1);
|
||||
auto context2 = MockContext::CreateWithContextId(CONTEXT_ID2);
|
||||
auto context3 = MockContext::CreateWithContextId(CONTEXT_ID3);
|
||||
EXPECT_EQ(pool.Select(CONTEXT_ID3).lock(), nullptr);
|
||||
EXPECT_EQ(pool.Insert(context1), true);
|
||||
EXPECT_EQ(pool.Insert(context2), true);
|
||||
EXPECT_EQ(pool.Insert(context3), true);
|
||||
@ -110,6 +111,10 @@ HWTEST_F(ContextPoolTest, ContextPoolInsertAndDelete, TestSize.Level0)
|
||||
EXPECT_EQ(pool.Delete(CONTEXT_ID1), true);
|
||||
EXPECT_EQ(pool.Delete(CONTEXT_ID2), true);
|
||||
EXPECT_EQ(pool.Delete(CONTEXT_ID3), true);
|
||||
|
||||
EXPECT_FALSE(pool.Delete(CONTEXT_ID1));
|
||||
EXPECT_FALSE(pool.Delete(CONTEXT_ID2));
|
||||
EXPECT_FALSE(pool.Delete(CONTEXT_ID3));
|
||||
}
|
||||
|
||||
HWTEST_F(ContextPoolTest, ContextSelectScheduleNodeByScheduleId, TestSize.Level0)
|
||||
@ -124,6 +129,9 @@ HWTEST_F(ContextPoolTest, ContextSelectScheduleNodeByScheduleId, TestSize.Level0
|
||||
auto context2 = MockContext::CreateContextWithScheduleNode(CONTEXT_ID2, {SCHEDULE_ID2});
|
||||
EXPECT_EQ(pool.Insert(context2), true);
|
||||
|
||||
std::shared_ptr<ContextPool::ContextPoolListener> listener = nullptr;
|
||||
EXPECT_FALSE(pool.RegisterContextPoolListener(listener));
|
||||
EXPECT_EQ(pool.SelectScheduleNodeByScheduleId(302), nullptr);
|
||||
EXPECT_NE(pool.SelectScheduleNodeByScheduleId(SCHEDULE_ID1), nullptr);
|
||||
EXPECT_EQ(pool.Delete(CONTEXT_ID1), true);
|
||||
EXPECT_EQ(pool.SelectScheduleNodeByScheduleId(SCHEDULE_ID1), nullptr);
|
||||
@ -210,6 +218,53 @@ HWTEST_F(ContextPoolTest, ContextPoolRandomId, TestSize.Level0)
|
||||
generated.emplace(contextId);
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(ContextPoolTest, ContextPoolTestSelect, TestSize.Level0)
|
||||
{
|
||||
auto context1 = Common::MakeShared<MockContext>();
|
||||
EXPECT_NE(context1, nullptr);
|
||||
EXPECT_CALL(*context1, GetContextId()).WillRepeatedly(Return(10));
|
||||
EXPECT_CALL(*context1, GetContextType()).WillRepeatedly(Return(CONTEXT_SIMPLE_AUTH));
|
||||
|
||||
auto context2 = Common::MakeShared<MockContext>();
|
||||
EXPECT_NE(context2, nullptr);
|
||||
EXPECT_CALL(*context2, GetContextId()).WillRepeatedly(Return(20));
|
||||
EXPECT_CALL(*context2, GetContextType()).WillRepeatedly(Return(CONTEXT_IDENTIFY));
|
||||
|
||||
auto &pool = ContextPool::Instance();
|
||||
auto contextVector = pool.Select(CONTEXT_SIMPLE_AUTH);
|
||||
EXPECT_EQ(contextVector.size(), 0);
|
||||
EXPECT_TRUE(pool.Insert(context1));
|
||||
EXPECT_TRUE(pool.Insert(context2));
|
||||
|
||||
contextVector = pool.Select(WIDGET_AUTH_CONTEXT);
|
||||
EXPECT_EQ(contextVector.size(), 0);
|
||||
contextVector = pool.Select(CONTEXT_SIMPLE_AUTH);
|
||||
EXPECT_EQ(contextVector.size(), 1);
|
||||
auto tempContext = contextVector[0].lock();
|
||||
EXPECT_NE(tempContext, nullptr);
|
||||
EXPECT_EQ(tempContext->GetContextId(), 10);
|
||||
EXPECT_TRUE(pool.Delete(10));
|
||||
EXPECT_TRUE(pool.Delete(20));
|
||||
}
|
||||
|
||||
HWTEST_F(ContextPoolTest, ContextPoolTestGetNewContextId, TestSize.Level0)
|
||||
{
|
||||
const int32_t COUNT = 1000;
|
||||
std::vector<uint64_t> contextIdVector(COUNT);
|
||||
|
||||
for (int32_t i = 0; i < COUNT; ++i) {
|
||||
uint64_t contextId = ContextPool::GetNewContextId();
|
||||
contextIdVector[i] = contextId;
|
||||
auto context = MockContext::CreateWithContextId(contextId);
|
||||
ContextPool::Instance().Insert(context);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < COUNT; ++i) {
|
||||
uint64_t contextId = contextIdVector[i];
|
||||
EXPECT_TRUE(ContextPool::Instance().Delete(contextId));
|
||||
}
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
@ -266,6 +266,63 @@ HWTEST_F(EnrollContextTest, EnrollContextTest_Stop_002, TestSize.Level0)
|
||||
ASSERT_EQ(context->Stop(), true);
|
||||
}
|
||||
|
||||
HWTEST_F(EnrollContextTest, EnrollContextTest_Stop_003, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
|
||||
std::shared_ptr<MockEnrollment> mockEnroll = Common::MakeShared<MockEnrollment>();
|
||||
ASSERT_NE(mockEnroll, nullptr);
|
||||
EXPECT_CALL(*mockEnroll, Start(_, _)).Times(1);
|
||||
ON_CALL(*mockEnroll, Start)
|
||||
.WillByDefault(
|
||||
[](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
|
||||
std::shared_ptr<ScheduleNodeCallback> callback) {
|
||||
scheduleList.push_back(nullptr);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*mockEnroll, Cancel()).Times(Exactly(1)).WillOnce([]() {
|
||||
return true;
|
||||
});
|
||||
std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
|
||||
ASSERT_NE(contextCallback, nullptr);
|
||||
std::shared_ptr<Context> context = Common::MakeShared<EnrollContext>(testContestId, mockEnroll, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
ASSERT_EQ(context->Start(), false);
|
||||
ASSERT_EQ(context->Stop(), true);
|
||||
}
|
||||
|
||||
HWTEST_F(EnrollContextTest, EnrollContextTest_Stop_004, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
|
||||
std::shared_ptr<MockEnrollment> mockEnroll = Common::MakeShared<MockEnrollment>();
|
||||
ASSERT_NE(mockEnroll, nullptr);
|
||||
EXPECT_CALL(*mockEnroll, Start(_, _)).Times(1);
|
||||
ON_CALL(*mockEnroll, Start)
|
||||
.WillByDefault(
|
||||
[](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
|
||||
std::shared_ptr<ScheduleNodeCallback> callback) {
|
||||
auto scheduleNode = Common::MakeShared<MockScheduleNode>();
|
||||
EXPECT_NE(scheduleNode, nullptr);
|
||||
EXPECT_CALL(*scheduleNode, StartSchedule()).Times(1);
|
||||
EXPECT_CALL(*scheduleNode, StopSchedule()).Times(1);
|
||||
scheduleList.push_back(scheduleNode);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*mockEnroll, GetLatestError()).Times(1);
|
||||
EXPECT_CALL(*mockEnroll, Cancel()).Times(Exactly(1)).WillOnce([]() {
|
||||
return false;
|
||||
});
|
||||
std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
|
||||
ASSERT_NE(contextCallback, nullptr);
|
||||
std::shared_ptr<Context> context = Common::MakeShared<EnrollContext>(testContestId, mockEnroll, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
ASSERT_EQ(context->Start(), false);
|
||||
ASSERT_EQ(context->Stop(), false);
|
||||
}
|
||||
|
||||
HWTEST_F(EnrollContextTest, EnrollContextTest_OnScheduleStarted, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
@ -437,6 +494,45 @@ HWTEST_F(EnrollContextTest, EnrollContextTest_OnScheduleStoped_005, TestSize.Lev
|
||||
ASSERT_EQ(ret2, true);
|
||||
nodeCallback->OnScheduleStoped(ResultCode::SUCCESS, result);
|
||||
}
|
||||
|
||||
HWTEST_F(EnrollContextTest, EnrollContextTest_OnScheduleStoped_006, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
static const std::vector<uint8_t> testScheduleResult = {3, 4, 5, 6};
|
||||
static const uint64_t testCredentialId = 7;
|
||||
|
||||
std::shared_ptr<MockEnrollment> mockEnroll = Common::MakeShared<MockEnrollment>();
|
||||
ASSERT_NE(mockEnroll, nullptr);
|
||||
EXPECT_CALL(*mockEnroll, Update(_, _, _, _))
|
||||
.Times(Exactly(1))
|
||||
.WillOnce([](const std::vector<uint8_t> &scheduleResult, uint64_t &credentialId,
|
||||
std::shared_ptr<CredentialInfo> &info, std::vector<uint8_t> &rootSecret) {
|
||||
EXPECT_EQ(scheduleResult, testScheduleResult);
|
||||
credentialId = testCredentialId;
|
||||
auto credInfo = Common::MakeShared<MockCredentialInfo>();
|
||||
EXPECT_NE(credInfo, nullptr);
|
||||
EXPECT_CALL(*credInfo, GetExecutorIndex()).WillOnce(Return(10));
|
||||
info = credInfo;
|
||||
rootSecret = {1, 2, 3, 4};
|
||||
return true;
|
||||
});
|
||||
std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
|
||||
ASSERT_NE(contextCallback, nullptr);
|
||||
EXPECT_CALL(*contextCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
std::shared_ptr<ScheduleNodeCallback> nodeCallback =
|
||||
Common::MakeShared<EnrollContext>(testContestId, mockEnroll, contextCallback);
|
||||
ASSERT_NE(nodeCallback, nullptr);
|
||||
// Success
|
||||
std::shared_ptr<Attributes> result = Common::MakeShared<Attributes>();
|
||||
ASSERT_NE(result, nullptr);
|
||||
bool ret1 = result->SetUint8ArrayValue(Attributes::ATTR_SIGNATURE, testScheduleResult);
|
||||
ASSERT_EQ(ret1, true);
|
||||
|
||||
bool ret2 = result->SetUint8ArrayValue(Attributes::ATTR_RESULT, testScheduleResult);
|
||||
ASSERT_EQ(ret2, true);
|
||||
nodeCallback->OnScheduleStoped(ResultCode::SUCCESS, result);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
@ -12,17 +12,29 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#include "credential_info_impl.h"
|
||||
#include "enrollment_impl.h"
|
||||
#include "resource_node_pool.h"
|
||||
#include "mock_iuser_auth_interface.h"
|
||||
#include "mock_resource_node.h"
|
||||
#include "mock_schedule_node_callback.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
using HdiAuthType = OHOS::HDI::UserAuth::V1_0::AuthType;
|
||||
using EnrollParam = OHOS::HDI::UserAuth::V1_0::EnrollParam;
|
||||
using HdiEnrollParam = OHOS::HDI::UserAuth::V1_0::EnrollParam;
|
||||
using HdiExecutorInfo = OHOS::HDI::UserAuth::V1_0::ExecutorInfo;
|
||||
using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_0::ScheduleInfo;
|
||||
using HdiExecutorRole = OHOS::HDI::UserAuth::V1_0::ExecutorRole;
|
||||
using HdiScheduleMode = OHOS::HDI::UserAuth::V1_0::ScheduleMode;
|
||||
using HdiExecutorSecureLevel = OHOS::HDI::UserAuth::V1_0::ExecutorSecureLevel;
|
||||
class EnrollmentImplTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@ -70,9 +82,9 @@ HWTEST_F(EnrollmentImplTest, EnrollmentHdiEmpty, TestSize.Level0)
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, BeginEnrollment(userId, _, _, _)).WillRepeatedly(Return(0));
|
||||
|
||||
auto authentication = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
EXPECT_FALSE(authentication->Start(scheduleList, nullptr));
|
||||
EXPECT_FALSE(enroll->Start(scheduleList, nullptr));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,12 +100,12 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiError, TestSize.Level0)
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(Return(1));
|
||||
|
||||
auto authentication = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
std::vector<uint8_t> scheduleResult = {1, 2, 3};
|
||||
uint64_t credentialId = 0;
|
||||
std::shared_ptr<CredentialInfo> info = nullptr;
|
||||
std::vector<uint8_t> rootSecret;
|
||||
EXPECT_FALSE(authentication->Update(scheduleResult, credentialId, info, rootSecret));
|
||||
EXPECT_FALSE(enroll->Update(scheduleResult, credentialId, info, rootSecret));
|
||||
}
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful, TestSize.Level0)
|
||||
@ -122,12 +134,12 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful, TestSize.Level0)
|
||||
};
|
||||
EXPECT_CALL(*mock, UpdateEnrollmentResult(userId, _, _)).WillRepeatedly(DoAll(WithArg<2>(fillUpInfos), Return(0)));
|
||||
|
||||
auto authentication = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
HdiCredentialInfo oldInfo = {};
|
||||
std::shared_ptr<CredentialInfo> info = std::make_shared<CredentialInfoImpl>(userId, oldInfo);
|
||||
uint64_t credentialId = 0;
|
||||
std::vector<uint8_t> rootSecret;
|
||||
EXPECT_TRUE(authentication->Update(scheduleResult, credentialId, info, rootSecret));
|
||||
EXPECT_TRUE(enroll->Update(scheduleResult, credentialId, info, rootSecret));
|
||||
|
||||
// test return values
|
||||
EXPECT_EQ(credentialId, credentialIdRet);
|
||||
@ -139,6 +151,55 @@ HWTEST_F(EnrollmentImplTest, EnrollmentUpdateHdiSuccessful, TestSize.Level0)
|
||||
EXPECT_EQ(info->GetExecutorMatcher(), 5U);
|
||||
EXPECT_EQ(info->GetExecutorSensorHint(), 6U);
|
||||
}
|
||||
|
||||
HWTEST_F(EnrollmentImplTest, EnrollmentImplTestStart, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t userId = 34567;
|
||||
constexpr uint64_t executorIndex = 60;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, CancelEnrollment(_))
|
||||
.Times(2)
|
||||
.WillOnce(Return(HDF_SUCCESS))
|
||||
.WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollment(_, _, _, _))
|
||||
.WillRepeatedly(
|
||||
[](int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
HdiScheduleInfo &info) {
|
||||
info.authType = HdiAuthType::FACE;
|
||||
info.executorMatcher = 10;
|
||||
HdiExecutorInfo executorInfo = {};
|
||||
executorInfo.executorIndex = 60;
|
||||
executorInfo.info.authType = HdiAuthType::FACE;
|
||||
executorInfo.info.esl = HdiExecutorSecureLevel::ESL1;
|
||||
executorInfo.info.executorMatcher = 10;
|
||||
executorInfo.info.executorRole = HdiExecutorRole::ALL_IN_ONE;
|
||||
executorInfo.info.executorSensorHint = 90;
|
||||
executorInfo.info.publicKey = {1, 2, 3, 4};
|
||||
info.executors.push_back(executorInfo);
|
||||
info.scheduleId = 20;
|
||||
info.scheduleMode = HdiScheduleMode::IDENTIFY;
|
||||
info.templateIds.push_back(30);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, FACE, ALL_IN_ONE);
|
||||
EXPECT_NE(resourceNode, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
|
||||
auto enroll = std::make_shared<EnrollmentImpl>(userId, FACE);
|
||||
EXPECT_NE(enroll, nullptr);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_TRUE(enroll->Start(scheduleList, callback));
|
||||
EXPECT_TRUE(enroll->Cancel());
|
||||
|
||||
EXPECT_TRUE(enroll->Start(scheduleList, callback));
|
||||
EXPECT_FALSE(enroll->Cancel());
|
||||
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
105
test/unittest/services/src/executor_messenger_service_test.cpp
Normal file
105
test/unittest/services/src/executor_messenger_service_test.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* 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 "executor_messenger_service_test.h"
|
||||
|
||||
#include "context_pool.h"
|
||||
#include "executor_messenger_service.h"
|
||||
#include "mock_context.h"
|
||||
#include "mock_schedule_node.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
void ExecutorMessengerServiceTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorMessengerServiceTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorMessengerServiceTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void ExecutorMessengerServiceTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorMessengerServiceTest, ExecutorMessengerServiceTest001, TestSize.Level0)
|
||||
{
|
||||
auto service1 = ExecutorMessengerService::GetInstance();
|
||||
EXPECT_NE(service1, nullptr);
|
||||
auto service2 = ExecutorMessengerService::GetInstance();
|
||||
EXPECT_NE(service2, nullptr);
|
||||
EXPECT_EQ(service1, service2);
|
||||
}
|
||||
|
||||
HWTEST_F(ExecutorMessengerServiceTest, ExecutorMessengerServiceTest002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testScheduleId1 = 1545;
|
||||
uint64_t testScheduleId2 = 1876;
|
||||
uint64_t testContextId = 78545;
|
||||
uint64_t testTransNum = 8751;
|
||||
ExecutorRole testSrcRole = SCHEDULER;
|
||||
ExecutorRole testDstRole = VERIFIER;
|
||||
ResultCode testResultCode = FAIL;
|
||||
std::shared_ptr<Attributes> testFinalResult = nullptr;
|
||||
std::vector<uint8_t> testMsg = {1, 2, 3, 4};
|
||||
|
||||
auto service = ExecutorMessengerService::GetInstance();
|
||||
EXPECT_NE(service, nullptr);
|
||||
|
||||
int32_t result1 = service->SendData(testScheduleId1, testTransNum, testSrcRole, testDstRole, testMsg);
|
||||
EXPECT_EQ(result1, GENERAL_ERROR);
|
||||
|
||||
int32_t result2 = service->Finish(testScheduleId1, testSrcRole, testResultCode, testFinalResult);
|
||||
EXPECT_EQ(result2, GENERAL_ERROR);
|
||||
|
||||
auto scheduleNode1 = MockScheduleNode::CreateWithScheduleId(testScheduleId1);
|
||||
EXPECT_NE(scheduleNode1, nullptr);
|
||||
EXPECT_CALL(*scheduleNode1, ContinueSchedule(_, _, _, _)).WillRepeatedly(Return(false));
|
||||
EXPECT_CALL(*scheduleNode1, ContinueSchedule(_, _)).WillRepeatedly(Return(false));
|
||||
auto scheduleNode2 = MockScheduleNode::CreateWithScheduleId(testScheduleId2);
|
||||
EXPECT_NE(scheduleNode2, nullptr);
|
||||
EXPECT_CALL(*scheduleNode2, ContinueSchedule(_, _, _, _)).WillRepeatedly(Return(true));
|
||||
EXPECT_CALL(*scheduleNode2, ContinueSchedule(_, _)).WillRepeatedly(Return(true));
|
||||
std::set<std::shared_ptr<ScheduleNode>> scheduleNodeSet;
|
||||
scheduleNodeSet.insert(scheduleNode1);
|
||||
scheduleNodeSet.insert(scheduleNode2);
|
||||
|
||||
auto context = MockContext::CreateContextWithScheduleNode(testContextId, scheduleNodeSet);
|
||||
EXPECT_NE(context, nullptr);
|
||||
EXPECT_TRUE(ContextPool::Instance().Insert(context));
|
||||
|
||||
result1 = service->SendData(testScheduleId1, testTransNum, testSrcRole, testDstRole, testMsg);
|
||||
EXPECT_EQ(result1, GENERAL_ERROR);
|
||||
result1 = service->SendData(testScheduleId2, testTransNum, testSrcRole, testDstRole, testMsg);
|
||||
EXPECT_EQ(result1, SUCCESS);
|
||||
|
||||
result2 = service->Finish(testScheduleId1, testSrcRole, testResultCode, testFinalResult);
|
||||
EXPECT_EQ(result2, GENERAL_ERROR);
|
||||
result2 = service->Finish(testScheduleId2, testSrcRole, testResultCode, testFinalResult);
|
||||
EXPECT_EQ(result2, SUCCESS);
|
||||
|
||||
EXPECT_TRUE(ContextPool::Instance().Delete(testContextId));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -14,14 +14,27 @@
|
||||
*/
|
||||
#include <memory>
|
||||
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#include "identification_impl.h"
|
||||
#include "mock_iuser_auth_interface.h"
|
||||
#include "mock_resource_node.h"
|
||||
#include "mock_schedule_node_callback.h"
|
||||
#include "resource_node_pool.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_0::ScheduleInfo;
|
||||
using HdiScheduleMode = OHOS::HDI::UserAuth::V1_0::ScheduleMode;
|
||||
using HdiAuthType = OHOS::HDI::UserAuth::V1_0::AuthType;
|
||||
using HdiExecutorInfo = OHOS::HDI::UserAuth::V1_0::ExecutorInfo;
|
||||
using HdiExecutorSecureLevel = OHOS::HDI::UserAuth::V1_0::ExecutorSecureLevel;
|
||||
using HdiExecutorRole = OHOS::HDI::UserAuth::V1_0::ExecutorRole;
|
||||
|
||||
class IdentificationImplTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@ -113,6 +126,55 @@ HWTEST_F(IdentificationImplTest, IdentificationUpdateHdiSuccessful, TestSize.Lev
|
||||
EXPECT_EQ(retInfo.userId, 0x11);
|
||||
EXPECT_THAT(retInfo.token, ElementsAre(1, 2, 3, 4, 5, 6));
|
||||
}
|
||||
|
||||
HWTEST_F(IdentificationImplTest, IdentificationTestStart, TestSize.Level0)
|
||||
{
|
||||
constexpr uint64_t contextId = 34567;
|
||||
constexpr uint64_t executorIndex = 60;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, CancelIdentification(_))
|
||||
.Times(2)
|
||||
.WillOnce(Return(HDF_SUCCESS))
|
||||
.WillOnce(Return(HDF_FAILURE));
|
||||
EXPECT_CALL(*mockHdi, BeginIdentification(_, _, _, _, _))
|
||||
.WillRepeatedly(
|
||||
[](uint64_t contextId, HdiAuthType authType, const std::vector<uint8_t> &challenge, uint32_t executorId,
|
||||
HdiScheduleInfo &scheduleInfo) {
|
||||
scheduleInfo.authType = HdiAuthType::FACE;
|
||||
scheduleInfo.executorMatcher = 10;
|
||||
HdiExecutorInfo executorInfo = {};
|
||||
executorInfo.executorIndex = 60;
|
||||
executorInfo.info.authType = HdiAuthType::FACE;
|
||||
executorInfo.info.esl = HdiExecutorSecureLevel::ESL1;
|
||||
executorInfo.info.executorMatcher = 10;
|
||||
executorInfo.info.executorRole = HdiExecutorRole::ALL_IN_ONE;
|
||||
executorInfo.info.executorSensorHint = 90;
|
||||
executorInfo.info.publicKey = {1, 2, 3, 4};
|
||||
scheduleInfo.executors.push_back(executorInfo);
|
||||
scheduleInfo.scheduleId = 20;
|
||||
scheduleInfo.scheduleMode = HdiScheduleMode::IDENTIFY;
|
||||
scheduleInfo.templateIds.push_back(30);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
auto resourceNode = MockResourceNode::CreateWithExecuteIndex(executorIndex, FACE, ALL_IN_ONE);
|
||||
EXPECT_NE(resourceNode, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
|
||||
auto identification = std::make_shared<IdentificationImpl>(contextId, FACE);
|
||||
EXPECT_NE(identification, nullptr);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleList;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_TRUE(identification->Start(scheduleList, callback));
|
||||
EXPECT_TRUE(identification->Cancel());
|
||||
|
||||
EXPECT_TRUE(identification->Start(scheduleList, callback));
|
||||
EXPECT_FALSE(identification->Cancel());
|
||||
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Delete(executorIndex));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "resource_node_pool_test.h"
|
||||
|
||||
#include "iam_ptr.h"
|
||||
#include "resource_node_pool.h"
|
||||
|
||||
#include "mock_resource_node.h"
|
||||
@ -194,6 +195,53 @@ HWTEST_F(ResourceNodePoolTest, ResourceNodePoolListenerUpdate, TestSize.Level0)
|
||||
|
||||
EXPECT_EQ(pool.DeregisterResourceNodePoolListener(listener), true);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodePoolTest, ResourceNodePoolTestDelete, TestSize.Level0)
|
||||
{
|
||||
auto &pool = ResourceNodePool::Instance();
|
||||
const uint64_t EXECUTOR_INDEX1 = 300;
|
||||
const uint64_t EXECUTOR_INDEX2 = 500;
|
||||
auto resource1 = MockResourceNode::CreateWithExecuteIndex(EXECUTOR_INDEX1);
|
||||
auto resource2 = MockResourceNode::CreateWithExecuteIndex(EXECUTOR_INDEX2);
|
||||
|
||||
auto listener1 = Common::MakeShared<MockResourceNodePoolListener>();
|
||||
EXPECT_NE(listener1, nullptr);
|
||||
EXPECT_CALL(*listener1, OnResourceNodePoolDelete(_)).Times(2);
|
||||
EXPECT_CALL(*listener1, OnResourceNodePoolInsert(_)).Times(2);
|
||||
EXPECT_TRUE(pool.RegisterResourceNodePoolListener(listener1));
|
||||
std::shared_ptr<ResourceNodePool::ResourceNodePoolListener> listener2 = nullptr;
|
||||
EXPECT_FALSE(pool.RegisterResourceNodePoolListener(listener2));
|
||||
|
||||
EXPECT_TRUE(pool.Insert(resource1));
|
||||
EXPECT_TRUE(pool.Insert(resource2));
|
||||
pool.DeleteAll();
|
||||
|
||||
EXPECT_TRUE(pool.DeregisterResourceNodePoolListener(listener1));
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodePoolTest, ResourceNodePoolTestEnumerate, TestSize.Level0)
|
||||
{
|
||||
auto &pool = ResourceNodePool::Instance();
|
||||
const uint64_t EXECUTOR_INDEX1 = 300;
|
||||
const uint64_t EXECUTOR_INDEX2 = 500;
|
||||
auto resource1 = MockResourceNode::CreateWithExecuteIndex(EXECUTOR_INDEX1);
|
||||
auto resource2 = MockResourceNode::CreateWithExecuteIndex(EXECUTOR_INDEX2);
|
||||
|
||||
auto action1 = [](const std::weak_ptr<ResourceNode> &) {
|
||||
return;
|
||||
};
|
||||
std::function<void(const std::weak_ptr<ResourceNode> &)> action2 = nullptr;
|
||||
pool.Enumerate(action2);
|
||||
pool.Enumerate(action1);
|
||||
EXPECT_TRUE(pool.Insert(resource1));
|
||||
EXPECT_TRUE(pool.Insert(resource2));
|
||||
EXPECT_EQ(pool.Select(400).lock(), nullptr);
|
||||
EXPECT_NE(pool.Select(EXECUTOR_INDEX1).lock(), nullptr);
|
||||
EXPECT_NE(pool.Select(EXECUTOR_INDEX1).lock(), nullptr);
|
||||
pool.Enumerate(action1);
|
||||
|
||||
pool.DeleteAll();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
@ -15,9 +15,11 @@
|
||||
|
||||
#include "resource_node_test.h"
|
||||
|
||||
#include "iam_ptr.h"
|
||||
#include "co_auth_interface.h"
|
||||
#include "resource_node.h"
|
||||
|
||||
#include "mock_executor_callback.h"
|
||||
#include "mock_iuser_auth_interface.h"
|
||||
#include "mock_resource_node.h"
|
||||
|
||||
@ -108,6 +110,63 @@ HWTEST_F(ResourceNodeTest, InsertSuccessWithTemplateIdList, TestSize.Level0)
|
||||
EXPECT_THAT(fwkPublicKey, ElementsAre(5, 3, 7, 1, 4));
|
||||
}
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodeTest, ResourceNodeTest001, TestSize.Level0)
|
||||
{
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, AddExecutor(_, _, _, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, DeleteExecutor(_)).Times(1);
|
||||
|
||||
ExecutorRegisterInfo info = {};
|
||||
std::vector<uint64_t> templateIdList;
|
||||
std::vector<uint8_t> fwkPublicKey;
|
||||
std::shared_ptr<ExecutorCallbackInterface> testCallback = nullptr;
|
||||
auto node = ResourceNode::MakeNewResource(info, testCallback, templateIdList, fwkPublicKey);
|
||||
EXPECT_NE(node, nullptr);
|
||||
|
||||
uint64_t scheduleId = 10;
|
||||
std::vector<uint8_t> publicKey;
|
||||
Attributes command;
|
||||
Attributes properties;
|
||||
Attributes condition;
|
||||
Attributes values;
|
||||
EXPECT_EQ(node->BeginExecute(scheduleId, publicKey, command), GENERAL_ERROR);
|
||||
EXPECT_EQ(node->EndExecute(scheduleId, command), GENERAL_ERROR);
|
||||
EXPECT_EQ(node->SetProperty(properties), GENERAL_ERROR);
|
||||
EXPECT_EQ(node->GetProperty(condition, values), GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodeTest, ResourceNodeTest002, TestSize.Level0)
|
||||
{
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, AddExecutor(_, _, _, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, DeleteExecutor(_)).Times(1);
|
||||
|
||||
ExecutorRegisterInfo info = {};
|
||||
std::vector<uint64_t> templateIdList;
|
||||
std::vector<uint8_t> fwkPublicKey;
|
||||
auto testCallback = Common::MakeShared<MockExecutorCallback>();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
EXPECT_CALL(*testCallback, OnBeginExecute(_, _, _)).WillRepeatedly(Return(SUCCESS));
|
||||
EXPECT_CALL(*testCallback, OnEndExecute(_, _)).WillRepeatedly(Return(SUCCESS));
|
||||
EXPECT_CALL(*testCallback, OnSetProperty(_)).WillRepeatedly(Return(SUCCESS));
|
||||
EXPECT_CALL(*testCallback, OnGetProperty(_, _)).WillRepeatedly(Return(SUCCESS));
|
||||
auto node = ResourceNode::MakeNewResource(info, testCallback, templateIdList, fwkPublicKey);
|
||||
EXPECT_NE(node, nullptr);
|
||||
|
||||
uint64_t scheduleId = 10;
|
||||
std::vector<uint8_t> publicKey;
|
||||
Attributes command;
|
||||
Attributes properties;
|
||||
Attributes condition;
|
||||
Attributes values;
|
||||
EXPECT_EQ(node->BeginExecute(scheduleId, publicKey, command), SUCCESS);
|
||||
EXPECT_EQ(node->EndExecute(scheduleId, command), SUCCESS);
|
||||
EXPECT_EQ(node->SetProperty(properties), SUCCESS);
|
||||
EXPECT_EQ(node->GetProperty(condition, values), SUCCESS);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
||||
|
130
test/unittest/services/src/resource_node_utils_test.cpp
Normal file
130
test/unittest/services/src/resource_node_utils_test.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 "resource_node_utils_test.h"
|
||||
|
||||
#include "iam_ptr.h"
|
||||
#include "mock_credential_info.h"
|
||||
#include "mock_resource_node.h"
|
||||
#include "resource_node_pool.h"
|
||||
#include "resource_node_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
void ResourceNodeUtilsTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceNodeUtilsTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceNodeUtilsTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void ResourceNodeUtilsTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodeUtilsTest, NotifyExecutorToDeleteTemplates001, TestSize.Level0)
|
||||
{
|
||||
std::vector<std::shared_ptr<IdmGetCredInfoCallbackInterface::CredentialInfo>> infos;
|
||||
int32_t result = ResourceNodeUtils::NotifyExecutorToDeleteTemplates(infos);
|
||||
EXPECT_EQ(result, INVALID_PARAMETERS);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodeUtilsTest, NotifyExecutorToDeleteTemplates002, TestSize.Level0)
|
||||
{
|
||||
auto credInfo = Common::MakeShared<MockCredentialInfo>();
|
||||
EXPECT_NE(credInfo, nullptr);
|
||||
EXPECT_CALL(*credInfo, GetExecutorIndex()).WillRepeatedly(Return(10));
|
||||
|
||||
std::vector<std::shared_ptr<IdmGetCredInfoCallbackInterface::CredentialInfo>> infos;
|
||||
infos.push_back(credInfo);
|
||||
int32_t result = ResourceNodeUtils::NotifyExecutorToDeleteTemplates(infos);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodeUtilsTest, NotifyExecutorToDeleteTemplates003, TestSize.Level0)
|
||||
{
|
||||
auto credInfo1 = Common::MakeShared<MockCredentialInfo>();
|
||||
EXPECT_NE(credInfo1, nullptr);
|
||||
EXPECT_CALL(*credInfo1, GetExecutorIndex()).WillRepeatedly(Return(10));
|
||||
EXPECT_CALL(*credInfo1, GetTemplateId()).WillRepeatedly(Return(20));
|
||||
|
||||
auto credInfo2 = Common::MakeShared<MockCredentialInfo>();
|
||||
EXPECT_NE(credInfo2, nullptr);
|
||||
EXPECT_CALL(*credInfo2, GetExecutorIndex()).WillRepeatedly(Return(100));
|
||||
EXPECT_CALL(*credInfo2, GetTemplateId()).WillRepeatedly(Return(200));
|
||||
|
||||
std::vector<std::shared_ptr<IdmGetCredInfoCallbackInterface::CredentialInfo>> infos;
|
||||
infos.push_back(credInfo1);
|
||||
infos.push_back(credInfo2);
|
||||
|
||||
auto resourceNode1 = Common::MakeShared<MockResourceNode>();
|
||||
EXPECT_NE(resourceNode1, nullptr);
|
||||
EXPECT_CALL(*resourceNode1, GetExecutorIndex()).WillRepeatedly(Return(10));
|
||||
EXPECT_CALL(*resourceNode1, SetProperty(_)).WillRepeatedly(Return(FAIL));
|
||||
auto resourceNode2 = Common::MakeShared<MockResourceNode>();
|
||||
EXPECT_NE(resourceNode2, nullptr);
|
||||
EXPECT_CALL(*resourceNode2, GetExecutorIndex()).WillRepeatedly(Return(100));
|
||||
EXPECT_CALL(*resourceNode2, SetProperty(_)).WillRepeatedly(Return(SUCCESS));
|
||||
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode1));
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode2));
|
||||
|
||||
int32_t result = ResourceNodeUtils::NotifyExecutorToDeleteTemplates(infos);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
ResourceNodePool::Instance().DeleteAll();
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodeUtilsTest, SendMsgToExecutor001, TestSize.Level0)
|
||||
{
|
||||
uint64_t testIndex = 10;
|
||||
std::vector<uint8_t> testMsg = {1, 2, 3, 4};
|
||||
|
||||
ResourceNodeUtils::SendMsgToExecutor(testIndex, testMsg);
|
||||
}
|
||||
|
||||
HWTEST_F(ResourceNodeUtilsTest, SendMsgToExecutor002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testIndex1 = 10;
|
||||
uint64_t testIndex2 = 100;
|
||||
std::vector<uint8_t> testMsg = {1, 2, 3, 4};
|
||||
|
||||
auto resourceNode1 = Common::MakeShared<MockResourceNode>();
|
||||
EXPECT_NE(resourceNode1, nullptr);
|
||||
EXPECT_CALL(*resourceNode1, GetExecutorIndex()).WillRepeatedly(Return(10));
|
||||
EXPECT_CALL(*resourceNode1, SetProperty(_)).WillRepeatedly(Return(FAIL));
|
||||
auto resourceNode2 = Common::MakeShared<MockResourceNode>();
|
||||
EXPECT_NE(resourceNode2, nullptr);
|
||||
EXPECT_CALL(*resourceNode2, GetExecutorIndex()).WillRepeatedly(Return(100));
|
||||
EXPECT_CALL(*resourceNode2, SetProperty(_)).WillRepeatedly(Return(SUCCESS));
|
||||
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode1));
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode2));
|
||||
|
||||
ResourceNodeUtils::SendMsgToExecutor(testIndex1, testMsg);
|
||||
ResourceNodeUtils::SendMsgToExecutor(testIndex2, testMsg);
|
||||
ResourceNodePool::Instance().DeleteAll();
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
117
test/unittest/services/src/schedule_node_helper_test.cpp
Normal file
117
test/unittest/services/src/schedule_node_helper_test.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* 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 "schedule_node_helper_test.h"
|
||||
|
||||
#include "iam_ptr.h"
|
||||
|
||||
#include "mock_schedule_node_callback.h"
|
||||
#include "mock_resource_node.h"
|
||||
#include "resource_node_pool.h"
|
||||
#include "schedule_node_helper.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
using HdiAuthResultInfo = OHOS::HDI::UserAuth::V1_0::AuthResultInfo;
|
||||
using HdiAuthSolution = OHOS::HDI::UserAuth::V1_0::AuthSolution;
|
||||
using HdiExecutorSendMsg = OHOS::HDI::UserAuth::V1_0::ExecutorSendMsg;
|
||||
using HdiAuthType = OHOS::HDI::UserAuth::V1_0::AuthType;
|
||||
using HdiEnrollParam = OHOS::HDI::UserAuth::V1_0::EnrollParam;
|
||||
using HdiExecutorInfo = OHOS::HDI::UserAuth::V1_0::ExecutorInfo;
|
||||
using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_0::ScheduleInfo;
|
||||
using HdiExecutorRole = OHOS::HDI::UserAuth::V1_0::ExecutorRole;
|
||||
using HdiScheduleMode = OHOS::HDI::UserAuth::V1_0::ScheduleMode;
|
||||
using HdiExecutorSecureLevel = OHOS::HDI::UserAuth::V1_0::ExecutorSecureLevel;
|
||||
|
||||
void ScheduleNodeHelperTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ScheduleNodeHelperTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ScheduleNodeHelperTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void ScheduleNodeHelperTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTest_001, TestSize.Level0)
|
||||
{
|
||||
std::vector<HdiScheduleInfo> scheduleInfoList;
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleNodeList;
|
||||
ScheduleNodeHelper::NodeOptionalPara para = {};
|
||||
EXPECT_TRUE(ScheduleNodeHelper::BuildFromHdi(scheduleInfoList, callback, scheduleNodeList, para));
|
||||
}
|
||||
|
||||
HWTEST_F(ScheduleNodeHelperTest, ScheduleNodeHelperTest_002, TestSize.Level0)
|
||||
{
|
||||
std::vector<HdiScheduleInfo> scheduleInfoList;
|
||||
HdiScheduleInfo scheduleInfo = {};
|
||||
scheduleInfo.authType = HdiAuthType::FACE;
|
||||
scheduleInfo.executorMatcher = 10;
|
||||
HdiExecutorInfo executorInfo1 = {};
|
||||
executorInfo1.executorIndex = 60;
|
||||
scheduleInfo.executors.push_back(executorInfo1);
|
||||
|
||||
HdiExecutorInfo executorInfo2 = {};
|
||||
executorInfo2.executorIndex = 90;
|
||||
scheduleInfo.executors.push_back(executorInfo2);
|
||||
|
||||
scheduleInfo.scheduleId = 20;
|
||||
scheduleInfo.scheduleMode = HdiScheduleMode::AUTH;
|
||||
scheduleInfo.templateIds.push_back(30);
|
||||
scheduleInfoList.push_back(scheduleInfo);
|
||||
|
||||
std::vector<std::vector<ExecutorRole>> executorRoles = {
|
||||
{COLLECTOR, COLLECTOR},
|
||||
{VERIFIER, VERIFIER},
|
||||
{ALL_IN_ONE, ALL_IN_ONE},
|
||||
{COLLECTOR, VERIFIER},
|
||||
{COLLECTOR, ALL_IN_ONE},
|
||||
{VERIFIER, COLLECTOR},
|
||||
{VERIFIER, ALL_IN_ONE},
|
||||
{ALL_IN_ONE, COLLECTOR},
|
||||
{ALL_IN_ONE, VERIFIER},
|
||||
};
|
||||
|
||||
for (const auto &executorRole : executorRoles) {
|
||||
auto resourceNode1 = MockResourceNode::CreateWithExecuteIndex(60, FACE, executorRole[0]);
|
||||
EXPECT_NE(resourceNode1, nullptr);
|
||||
auto resourceNode2 = MockResourceNode::CreateWithExecuteIndex(90, FACE, executorRole[1]);
|
||||
EXPECT_NE(resourceNode2, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode1));
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode2));
|
||||
|
||||
auto callback = Common::MakeShared<MockScheduleNodeCallback>();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
std::vector<std::shared_ptr<ScheduleNode>> scheduleNodeList;
|
||||
ScheduleNodeHelper::NodeOptionalPara para = {};
|
||||
ScheduleNodeHelper::BuildFromHdi(scheduleInfoList, callback, scheduleNodeList, para);
|
||||
ResourceNodePool::Instance().DeleteAll();
|
||||
}
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -267,6 +267,63 @@ HWTEST_F(SimpleAuthContextTest, SimpleAuthContextTest_Stop_002, TestSize.Level0)
|
||||
ASSERT_EQ(context->Stop(), true);
|
||||
}
|
||||
|
||||
HWTEST_F(SimpleAuthContextTest, SimpleAuthContextTest_Stop_003, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
|
||||
std::shared_ptr<MockAuthentication> mockAuth = Common::MakeShared<MockAuthentication>();
|
||||
ASSERT_NE(mockAuth, nullptr);
|
||||
EXPECT_CALL(*mockAuth, Start(_, _)).Times(1);
|
||||
ON_CALL(*mockAuth, Start)
|
||||
.WillByDefault(
|
||||
[](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
|
||||
std::shared_ptr<ScheduleNodeCallback> callback) {
|
||||
scheduleList.push_back(nullptr);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*mockAuth, Cancel()).Times(Exactly(1)).WillOnce([]() {
|
||||
return true;
|
||||
});
|
||||
std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
|
||||
ASSERT_NE(contextCallback, nullptr);
|
||||
std::shared_ptr<Context> context = Common::MakeShared<SimpleAuthContext>(testContestId, mockAuth, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
ASSERT_EQ(context->Start(), false);
|
||||
ASSERT_EQ(context->Stop(), true);
|
||||
}
|
||||
|
||||
HWTEST_F(SimpleAuthContextTest, SimpleAuthContextTest_Stop_004, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
|
||||
std::shared_ptr<MockAuthentication> mockAuth = Common::MakeShared<MockAuthentication>();
|
||||
ASSERT_NE(mockAuth, nullptr);
|
||||
EXPECT_CALL(*mockAuth, Start(_, _)).Times(1);
|
||||
ON_CALL(*mockAuth, Start)
|
||||
.WillByDefault(
|
||||
[](std::vector<std::shared_ptr<ScheduleNode>> &scheduleList,
|
||||
std::shared_ptr<ScheduleNodeCallback> callback) {
|
||||
auto scheduleNode = Common::MakeShared<MockScheduleNode>();
|
||||
EXPECT_NE(scheduleNode, nullptr);
|
||||
EXPECT_CALL(*scheduleNode, StartSchedule()).Times(1);
|
||||
EXPECT_CALL(*scheduleNode, StopSchedule()).Times(1);
|
||||
scheduleList.push_back(scheduleNode);
|
||||
return true;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*mockAuth, GetLatestError()).Times(1);
|
||||
EXPECT_CALL(*mockAuth, Cancel()).Times(Exactly(1)).WillOnce([]() {
|
||||
return false;
|
||||
});
|
||||
std::shared_ptr<ContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
|
||||
ASSERT_NE(contextCallback, nullptr);
|
||||
std::shared_ptr<Context> context = Common::MakeShared<SimpleAuthContext>(testContestId, mockAuth, contextCallback);
|
||||
ASSERT_NE(context, nullptr);
|
||||
ASSERT_EQ(context->Start(), false);
|
||||
ASSERT_EQ(context->Stop(), false);
|
||||
}
|
||||
|
||||
HWTEST_F(SimpleAuthContextTest, SimpleAuthContextTest_OnScheduleStarted, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
@ -445,6 +502,43 @@ HWTEST_F(SimpleAuthContextTest, SimpleAuthContextTest_OnScheduleStoped_005, Test
|
||||
nodeCallback->OnScheduleStoped(testResultCode, result);
|
||||
}
|
||||
|
||||
HWTEST_F(SimpleAuthContextTest, SimpleAuthContextTest_OnScheduleStoped_006, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
static const std::vector<uint8_t> testScheduleResult = {3, 4, 5, 6};
|
||||
static const int32_t testResultCode = 7;
|
||||
static const int32_t testFreezingTime = 8;
|
||||
static const int32_t testRemainTimes = 9;
|
||||
static const std::vector<uint8_t> testSignature = {10, 11, 12, 13};
|
||||
|
||||
std::shared_ptr<MockAuthentication> mockAuth = Common::MakeShared<MockAuthentication>();
|
||||
ASSERT_NE(mockAuth, nullptr);
|
||||
EXPECT_CALL(*mockAuth, Update(_, _))
|
||||
.Times(Exactly(1))
|
||||
.WillOnce([](const std::vector<uint8_t> &scheduleResult, Authentication::AuthResultInfo &resultInfo) {
|
||||
EXPECT_EQ(scheduleResult, testScheduleResult);
|
||||
resultInfo.result = testResultCode;
|
||||
resultInfo.freezingTime = testFreezingTime;
|
||||
resultInfo.remainTimes = testRemainTimes;
|
||||
resultInfo.token = testSignature;
|
||||
resultInfo.rootSecret = {1, 2, 3, 4};
|
||||
return true;
|
||||
});
|
||||
std::shared_ptr<MockContextCallback> contextCallback = Common::MakeShared<MockContextCallback>();
|
||||
ASSERT_NE(contextCallback, nullptr);
|
||||
EXPECT_CALL(*contextCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
std::shared_ptr<ScheduleNodeCallback> nodeCallback =
|
||||
Common::MakeShared<SimpleAuthContext>(testContestId, mockAuth, contextCallback);
|
||||
ASSERT_NE(nodeCallback, nullptr);
|
||||
// Success
|
||||
std::shared_ptr<Attributes> result = Common::MakeShared<Attributes>();
|
||||
ASSERT_NE(result, nullptr);
|
||||
bool ret = result->SetUint8ArrayValue(Attributes::ATTR_RESULT, testScheduleResult);
|
||||
ASSERT_EQ(ret, true);
|
||||
nodeCallback->OnScheduleStoped(testResultCode, result);
|
||||
}
|
||||
|
||||
HWTEST_F(SimpleAuthContextTest, SimpleAuthContextTest_ContextFree, TestSize.Level0)
|
||||
{
|
||||
static const uint64_t testContestId = 2;
|
||||
|
@ -16,7 +16,10 @@
|
||||
#include "user_auth_service_test.h"
|
||||
|
||||
#include "iam_common_defines.h"
|
||||
#include "mock_iuser_auth_interface.h"
|
||||
#include "mock_user_auth_callback.h"
|
||||
#include "mock_resource_node.h"
|
||||
#include "resource_node_pool.h"
|
||||
#include "user_auth_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
@ -25,6 +28,10 @@ namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
using HdiCredentialInfo = OHOS::HDI::UserAuth::V1_0::CredentialInfo;
|
||||
using HdiEnrolledInfo = OHOS::HDI::UserAuth::V1_0::EnrolledInfo;
|
||||
using HdiAuthType = OHOS::HDI::UserAuth::V1_0::AuthType;
|
||||
|
||||
void UserAuthServiceTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
@ -35,18 +42,320 @@ void UserAuthServiceTest::TearDownTestCase()
|
||||
|
||||
void UserAuthServiceTest::SetUp()
|
||||
{
|
||||
MockIUserAuthInterface::Holder::GetInstance().Reset();
|
||||
}
|
||||
|
||||
void UserAuthServiceTest::TearDown()
|
||||
{
|
||||
MockIUserAuthInterface::Holder::GetInstance().Reset();
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus, TestSize.Level0)
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus001, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
AuthType authType = FACE;
|
||||
AuthTrustLevel authTrustLevel = ATL3;
|
||||
EXPECT_EQ(CHECK_PERMISSION_FAILED, service.GetAvailableStatus(0, authType, authTrustLevel));
|
||||
int32_t testApiVersion = 8;
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = ATL3;
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetAuthTrustLevel(_, _, _)).Times(1);
|
||||
EXPECT_NE(SUCCESS, service.GetAvailableStatus(testApiVersion, testAuthType, testAuthTrustLevel));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus002, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testApiVersion = 8;
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = static_cast<AuthTrustLevel>(90000);
|
||||
EXPECT_EQ(TRUST_LEVEL_NOT_SUPPORT, service.GetAvailableStatus(testApiVersion, testAuthType, testAuthTrustLevel));
|
||||
|
||||
testAuthTrustLevel = ATL2;
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetAuthTrustLevel(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetAuthTrustLevel)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, HdiAuthType authType, uint32_t &authTrustLevel) {
|
||||
authTrustLevel = static_cast<AuthTrustLevel>(0);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
EXPECT_EQ(TRUST_LEVEL_NOT_SUPPORT, service.GetAvailableStatus(testApiVersion, testAuthType, testAuthTrustLevel));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceGetAvailableStatus003, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testApiVersion = 8;
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = ATL2;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetAuthTrustLevel(_, _, _)).WillRepeatedly([]() {
|
||||
return NOT_ENROLLED;
|
||||
});
|
||||
EXPECT_EQ(TRUST_LEVEL_NOT_SUPPORT, service.GetAvailableStatus(testApiVersion, testAuthType, testAuthTrustLevel));
|
||||
|
||||
testApiVersion = 9;
|
||||
EXPECT_EQ(NOT_ENROLLED, service.GetAvailableStatus(testApiVersion, testAuthType, testAuthTrustLevel));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty001, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testUserId = 123;
|
||||
AuthType testAuthType = FACE;
|
||||
std::vector<Attributes::AttributeKey> testKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE};
|
||||
sptr<GetExecutorPropertyCallbackInterface> testCallback = new MockGetExecutorPropertyCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockGetExecutorPropertyCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnGetExecutorPropertyResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
service.GetProperty(testUserId, testAuthType, testKeys, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceGetProperty002, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testUserId = 123;
|
||||
AuthType testAuthType = FACE;
|
||||
std::vector<Attributes::AttributeKey> testKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE};
|
||||
sptr<GetExecutorPropertyCallbackInterface> testCallback = nullptr;
|
||||
service.GetProperty(testUserId, testAuthType, testKeys, testCallback);
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetCredential)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, HdiAuthType authType, std::vector<HdiCredentialInfo> &infos) {
|
||||
HdiCredentialInfo tempInfo = {
|
||||
.credentialId = 1,
|
||||
.executorIndex = 2,
|
||||
.templateId = 3,
|
||||
.authType = static_cast<HdiAuthType>(1),
|
||||
.executorMatcher = 2,
|
||||
.executorSensorHint = 3,
|
||||
};
|
||||
infos.push_back(tempInfo);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
auto resourceNode = MockResourceNode::CreateWithExecuteIndex(2);
|
||||
EXPECT_NE(resourceNode, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
|
||||
MockResourceNode *node = static_cast<MockResourceNode *>(resourceNode.get());
|
||||
EXPECT_CALL(*node, GetProperty(_, _)).WillRepeatedly([]() {
|
||||
return FAIL;
|
||||
});
|
||||
testCallback = new MockGetExecutorPropertyCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockGetExecutorPropertyCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnGetExecutorPropertyResult(_, _)).Times(1);
|
||||
service.GetProperty(testUserId, testAuthType, testKeys, testCallback);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Delete(2));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty001, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testUserId = 124;
|
||||
AuthType testAuthType = FACE;
|
||||
Attributes testAttr;
|
||||
sptr<SetExecutorPropertyCallbackInterface> testCallback = new MockSetExecutorPropertyCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockSetExecutorPropertyCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnSetExecutorPropertyResult(_)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
service.SetProperty(testUserId, testAuthType, testAttr, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceSetProperty002, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testUserId = 124;
|
||||
AuthType testAuthType = FACE;
|
||||
Attributes testAttr;
|
||||
sptr<SetExecutorPropertyCallbackInterface> testCallback = nullptr;
|
||||
service.SetProperty(testUserId, testAuthType, testAttr, testCallback);
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetCredential)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, HdiAuthType authType, std::vector<HdiCredentialInfo> &infos) {
|
||||
HdiCredentialInfo tempInfo = {
|
||||
.credentialId = 1,
|
||||
.executorIndex = 2,
|
||||
.templateId = 3,
|
||||
.authType = static_cast<HdiAuthType>(1),
|
||||
.executorMatcher = 2,
|
||||
.executorSensorHint = 3,
|
||||
};
|
||||
infos.push_back(tempInfo);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
auto resourceNode = MockResourceNode::CreateWithExecuteIndex(2);
|
||||
EXPECT_NE(resourceNode, nullptr);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Insert(resourceNode));
|
||||
MockResourceNode *node = static_cast<MockResourceNode *>(resourceNode.get());
|
||||
EXPECT_CALL(*node, SetProperty(_)).WillRepeatedly([]() {
|
||||
return FAIL;
|
||||
});
|
||||
testCallback = new MockSetExecutorPropertyCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockSetExecutorPropertyCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnSetExecutorPropertyResult(_)).Times(1);
|
||||
service.SetProperty(testUserId, testAuthType, testAttr, testCallback);
|
||||
EXPECT_TRUE(ResourceNodePool::Instance().Delete(2));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth001, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testApiVersion = 9;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = ATL2;
|
||||
sptr<UserAuthCallbackInterface> testCallback = new MockUserAuthCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(1);
|
||||
uint64_t contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceAuth002, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testApiVersion = 9;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = ATL2;
|
||||
sptr<UserAuthCallbackInterface> testCallback = nullptr;
|
||||
uint64_t contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
testCallback = new MockUserAuthCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(2);
|
||||
testAuthTrustLevel = static_cast<AuthTrustLevel>(90000);
|
||||
contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
testAuthType = PIN;
|
||||
testAuthTrustLevel = ATL1;
|
||||
contextId = service.Auth(testApiVersion, testChallenge, testAuthType, testAuthTrustLevel, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser001, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testUserId = 125;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = ATL2;
|
||||
sptr<UserAuthCallbackInterface> testCallback = new MockUserAuthCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, BeginAuthentication(_, _, _)).Times(1);
|
||||
uint64_t contextId = service.AuthUser(testUserId, testChallenge, testAuthType, testAuthTrustLevel, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceAuthUser002, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t testUserId = 125;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = ATL2;
|
||||
sptr<UserAuthCallbackInterface> testCallback = nullptr;
|
||||
uint64_t contextId = service.AuthUser(testUserId, testChallenge, testAuthType, testAuthTrustLevel, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
testCallback = new MockUserAuthCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
testAuthTrustLevel = static_cast<AuthTrustLevel>(90000);
|
||||
contextId = service.AuthUser(testUserId, testChallenge, testAuthType, testAuthTrustLevel, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify001, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
AuthType testAuthType = FACE;
|
||||
sptr<UserAuthCallbackInterface> testCallback = new MockUserAuthCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, BeginIdentification(_, _, _, _, _)).Times(1);
|
||||
uint64_t contextId = service.Identify(testChallenge, testAuthType, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceIdentify002, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
AuthType testAuthType = FACE;
|
||||
sptr<UserAuthCallbackInterface> testCallback = nullptr;
|
||||
uint64_t contextId = service.Identify(testChallenge, testAuthType, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
|
||||
testCallback = new MockUserAuthCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockUserAuthCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
testAuthType = PIN;
|
||||
contextId = service.Identify(testChallenge, testAuthType, testCallback);
|
||||
EXPECT_EQ(contextId, 0);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceCancelAuthOrIdentify, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
uint64_t testContextId = 12355236;
|
||||
EXPECT_EQ(service.CancelAuthOrIdentify(testContextId), GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthServiceTest, UserAuthServiceGetVersion, TestSize.Level0)
|
||||
{
|
||||
UserAuthService service(100, true);
|
||||
int32_t version;
|
||||
service.GetVersion(version);
|
||||
EXPECT_EQ(version, 0);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -41,252 +41,416 @@ void UserAuthStubTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubGetAvailableStatusStub, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubGetAvailableStatusStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::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;
|
||||
int32_t apiVersion = 0;
|
||||
AuthType authType = FACE;
|
||||
AuthTrustLevel authTrustLevel = ATL3;
|
||||
EXPECT_CALL(service, GetAvailableStatus(apiVersion, FACE, ATL3)).WillOnce(Return(0));
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAuthTrustLevel = ATL3;
|
||||
int32_t testApiVersion = 8;
|
||||
EXPECT_CALL(service, GetAvailableStatus(_, _, _)).Times(1);
|
||||
ON_CALL(service, GetAvailableStatus)
|
||||
.WillByDefault(
|
||||
[&testAuthType, &testAuthTrustLevel, &testApiVersion](int32_t apiVersion, AuthType authType,
|
||||
AuthTrustLevel authTrustLevel) {
|
||||
EXPECT_EQ(apiVersion, testApiVersion);
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
EXPECT_EQ(authTrustLevel, testAuthTrustLevel);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_GET_AVAILABLE_STATUS;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(authType));
|
||||
EXPECT_TRUE(data.WriteUint32(authTrustLevel));
|
||||
EXPECT_TRUE(data.WriteInt32(apiVersion));
|
||||
EXPECT_TRUE(data.WriteInt32(testAuthType));
|
||||
EXPECT_TRUE(data.WriteUint32(testAuthTrustLevel));
|
||||
EXPECT_TRUE(data.WriteInt32(testApiVersion));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserAuthInterface::USER_AUTH_GET_AVAILABLE_STATUS, data, reply, option));
|
||||
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, UserAuthStubGetAvailableStatusStubFailed, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubGetPropertyStub001, TestSize.Level0)
|
||||
{
|
||||
MockUserAuthService service;
|
||||
AuthType authType = FACE;
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_GET_PROPERTY;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(authType));
|
||||
|
||||
EXPECT_EQ(READ_PARCEL_ERROR,
|
||||
service.OnRemoteRequest(UserAuthInterface::USER_AUTH_GET_AVAILABLE_STATUS, data, reply, option));
|
||||
MockUserAuthService service;
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubGetPropertyByIdStub, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubGetPropertyStub002, TestSize.Level0)
|
||||
{
|
||||
MockUserAuthService service;
|
||||
int32_t userId = 1;
|
||||
AuthType authType = FACE;
|
||||
std::vector<Attributes::AttributeKey> attrKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE,
|
||||
int32_t testUserId = 1232666;
|
||||
AuthType testAuthType = FACE;
|
||||
std::vector<Attributes::AttributeKey> testAttrKeys = {Attributes::ATTR_RESULT_CODE, Attributes::ATTR_SIGNATURE,
|
||||
Attributes::ATTR_SCHEDULE_MODE};
|
||||
std::vector<uint32_t> keys;
|
||||
for (auto &attrKey : attrKeys) {
|
||||
keys.push_back(static_cast<uint32_t>(attrKey));
|
||||
std::vector<uint32_t> tempKeys;
|
||||
for (auto &attrKey : testAttrKeys) {
|
||||
tempKeys.push_back(static_cast<uint32_t>(attrKey));
|
||||
}
|
||||
sptr<MockGetExecutorPropertyCallback> callback = new MockGetExecutorPropertyCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, GetProperty(userId, FACE, _, _)).Times(1);
|
||||
MockUserAuthService service;
|
||||
EXPECT_CALL(service, GetProperty(_, _, _, _)).Times(1);
|
||||
ON_CALL(service, GetProperty)
|
||||
.WillByDefault(
|
||||
[](std::optional<int32_t> userId, AuthType authType, const std::vector<Attributes::AttributeKey> &keys,
|
||||
[&testUserId, &testAuthType, &testAttrKeys](int32_t userId, AuthType authType,
|
||||
const std::vector<Attributes::AttributeKey> &keys,
|
||||
sptr<GetExecutorPropertyCallbackInterface> &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 = UserAuthInterface::USER_AUTH_GET_PROPERTY;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(userId));
|
||||
EXPECT_TRUE(data.WriteInt32(authType));
|
||||
EXPECT_TRUE(data.WriteUInt32Vector(keys));
|
||||
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(UserAuthInterface::USER_AUTH_GET_PROPERTY, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubSetPropertyStub, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubSetPropertyStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_SET_PROPERTY;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
|
||||
MockUserAuthService service;
|
||||
int32_t userId = 1;
|
||||
AuthType authType = FACE;
|
||||
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<MockSetExecutorPropertyCallback> callback = new MockSetExecutorPropertyCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, SetProperty(userId, FACE, _, _)).Times(1);
|
||||
MockUserAuthService service;
|
||||
EXPECT_CALL(service, SetProperty(_, _, _, _)).Times(1);
|
||||
ON_CALL(service, SetProperty)
|
||||
.WillByDefault([](int32_t userId, AuthType authType, const Attributes &attributes,
|
||||
sptr<SetExecutorPropertyCallbackInterface> &callback) {
|
||||
.WillByDefault(
|
||||
[&testUserId, &testAuthType, &testTemplateId](int32_t userId, AuthType authType,
|
||||
const Attributes &attributes, sptr<SetExecutorPropertyCallbackInterface> &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 = UserAuthInterface::USER_AUTH_SET_PROPERTY;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(userId));
|
||||
EXPECT_TRUE(data.WriteInt32(authType));
|
||||
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(UserAuthInterface::USER_AUTH_SET_PROPERTY, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubAuthStub, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubAuthStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_AUTH;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
|
||||
MockUserAuthService service;
|
||||
int32_t apiVersion = 0;
|
||||
std::vector<uint8_t> challenge = {1, 2, 4};
|
||||
AuthType authType = FACE;
|
||||
AuthTrustLevel atl = ATL2;
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubAuthStub002, TestSize.Level0)
|
||||
{
|
||||
int32_t testApiVersion = 9;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 4, 5};
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAtl = ATL2;
|
||||
uint64_t testContextId = 2346782;
|
||||
|
||||
sptr<MockUserAuthCallback> callback = new MockUserAuthCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, Auth(apiVersion, _, FACE, atl, _)).Times(1);
|
||||
MockUserAuthService service;
|
||||
EXPECT_CALL(service, Auth(_, _, _, _, _)).Times(1);
|
||||
ON_CALL(service, Auth)
|
||||
.WillByDefault([](int32_t apiVersion, const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) {
|
||||
.WillByDefault(
|
||||
[&testChallenge, &testAuthType, &testAtl, &testContextId, &testApiVersion](int32_t apiVersion,
|
||||
const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
|
||||
sptr<UserAuthCallbackInterface> &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);
|
||||
}
|
||||
uint64_t contextId = 300;
|
||||
return contextId;
|
||||
});
|
||||
return testContextId;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_AUTH;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(challenge));
|
||||
EXPECT_TRUE(data.WriteInt32(authType));
|
||||
EXPECT_TRUE(data.WriteUint32(static_cast<uint32_t>(atl)));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
|
||||
EXPECT_TRUE(data.WriteInt32(testAuthType));
|
||||
EXPECT_TRUE(data.WriteUint32(testAtl));
|
||||
EXPECT_NE(callback->AsObject(), nullptr);
|
||||
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
|
||||
EXPECT_TRUE(data.WriteInt32(apiVersion));
|
||||
EXPECT_TRUE(data.WriteInt32(testApiVersion));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserAuthInterface::USER_AUTH_AUTH, data, reply, option));
|
||||
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, UserAuthStubAuthUserStub, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_AUTH_USER;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
|
||||
MockUserAuthService service;
|
||||
int32_t userId = 1;
|
||||
std::vector<uint8_t> challenge = {1, 2, 5};
|
||||
AuthType authType = FACE;
|
||||
AuthTrustLevel atl = ATL2;
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubAuthUserStub002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 3467;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 5, 9};
|
||||
AuthType testAuthType = FACE;
|
||||
AuthTrustLevel testAtl = ATL2;
|
||||
uint64_t testContextId = 2346728;
|
||||
|
||||
sptr<MockUserAuthCallback> callback = new MockUserAuthCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, AuthUser(userId, _, FACE, atl, _)).Times(1);
|
||||
MockUserAuthService service;
|
||||
EXPECT_CALL(service, AuthUser(_, _, _, _, _)).Times(1);
|
||||
ON_CALL(service, AuthUser)
|
||||
.WillByDefault([](int32_t userId, const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
AuthTrustLevel authTrustLevel, sptr<UserAuthCallbackInterface> &callback) {
|
||||
.WillByDefault(
|
||||
[&testUserId, &testChallenge, &testAuthType, &testAtl, &testContextId](int32_t userId,
|
||||
const std::vector<uint8_t> &challenge, AuthType authType, AuthTrustLevel authTrustLevel,
|
||||
sptr<UserAuthCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
EXPECT_EQ(authTrustLevel, testAtl);
|
||||
if (callback != nullptr) {
|
||||
Attributes attr;
|
||||
callback->OnResult(SUCCESS, attr);
|
||||
}
|
||||
uint64_t contextId = 300;
|
||||
return contextId;
|
||||
});
|
||||
return testContextId;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_AUTH_USER;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(userId));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(challenge));
|
||||
EXPECT_TRUE(data.WriteInt32(authType));
|
||||
EXPECT_TRUE(data.WriteUint32(static_cast<uint32_t>(atl)));
|
||||
EXPECT_TRUE(data.WriteInt32(testUserId));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(testChallenge));
|
||||
EXPECT_TRUE(data.WriteInt32(testAuthType));
|
||||
EXPECT_TRUE(data.WriteUint32(testAtl));
|
||||
EXPECT_NE(callback->AsObject(), nullptr);
|
||||
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserAuthInterface::USER_AUTH_AUTH_USER, data, reply, option));
|
||||
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, UserAuthStubIdentifyStub, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubIdentifyStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_IDENTIFY;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
|
||||
MockUserAuthService service;
|
||||
std::vector<uint8_t> challenge = {1, 2, 5};
|
||||
AuthType authType = FACE;
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubIdentifyStub002, TestSize.Level0)
|
||||
{
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 5, 8, 9};
|
||||
AuthType testAuthType = FACE;
|
||||
uint64_t testContextId = 76374284;
|
||||
|
||||
sptr<MockUserAuthCallback> callback = new MockUserAuthCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, Identify(_, FACE, _)).Times(1);
|
||||
MockUserAuthService service;
|
||||
EXPECT_CALL(service, Identify(_, _, _)).Times(1);
|
||||
ON_CALL(service, Identify)
|
||||
.WillByDefault(
|
||||
[](const std::vector<uint8_t> &challenge, AuthType authType, sptr<UserAuthCallbackInterface> &callback) {
|
||||
[&testChallenge, &testAuthType, &testContextId](const std::vector<uint8_t> &challenge, AuthType authType,
|
||||
sptr<UserAuthCallbackInterface> &callback) {
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
if (callback != nullptr) {
|
||||
Attributes attr;
|
||||
callback->OnResult(SUCCESS, attr);
|
||||
}
|
||||
uint64_t contextId = 300;
|
||||
return contextId;
|
||||
});
|
||||
return testContextId;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_IDENTIFY;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(challenge));
|
||||
EXPECT_TRUE(data.WriteInt32(authType));
|
||||
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(UserAuthInterface::USER_AUTH_IDENTIFY, data, reply, option));
|
||||
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, UserAuthStubCancelAuthOrIdentifyStub, TestSize.Level0)
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_CANCEL_AUTH;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
|
||||
MockUserAuthService service;
|
||||
const uint64_t CONTEXT_ID = 100;
|
||||
EXPECT_CALL(service, CancelAuthOrIdentify(100)).WillOnce(Return(0));
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserAuthStubTest, UserAuthStubCancelAuthOrIdentifyStub002, TestSize.Level0)
|
||||
{
|
||||
uint64_t testContextId = 9346248;
|
||||
|
||||
MockUserAuthService service;
|
||||
EXPECT_CALL(service, CancelAuthOrIdentify(_)).Times(1);
|
||||
ON_CALL(service, CancelAuthOrIdentify)
|
||||
.WillByDefault(
|
||||
[&testContextId](uint64_t contextId) {
|
||||
EXPECT_EQ(contextId, testContextId);
|
||||
return SUCCESS;
|
||||
}
|
||||
);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserAuthInterface::USER_AUTH_CANCEL_AUTH;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteUint64(CONTEXT_ID));
|
||||
EXPECT_TRUE(data.WriteUint64(testContextId));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserAuthInterface::USER_AUTH_CANCEL_AUTH, data, reply, option));
|
||||
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(_)).WillOnce(Return(0));
|
||||
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 = UserAuthInterface::USER_AUTH_GET_VERSION;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserAuthInterface::GetDescriptor()));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserAuthInterface::USER_AUTH_GET_VERSION, data, reply, option));
|
||||
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);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -199,6 +199,152 @@ HWTEST_F(UserIdmDatabaseTest, SuccessfulGetCredentialInfoVector, TestSize.Level0
|
||||
EXPECT_EQ(2U, info[1]->GetExecutorSensorHint());
|
||||
EXPECT_EQ(3U, info[1]->GetExecutorMatcher());
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmDatabaseTest, DeleteCredentialInfo001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 4501;
|
||||
uint64_t testCredentialId = 87841;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
std::shared_ptr<CredentialInfo> testCredInfo = nullptr;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, DeleteCredential(_, _, _, _)).WillRepeatedly(Return(1));
|
||||
int32_t result = UserIdmDatabase::Instance().DeleteCredentialInfo(testUserId, testCredentialId,
|
||||
testAuthToken, testCredInfo);
|
||||
EXPECT_EQ(result, 1);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmDatabaseTest, DeleteCredentialInfo002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 4501;
|
||||
uint64_t testCredentialId = 87841;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
std::shared_ptr<CredentialInfo> testCredInfo = nullptr;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, DeleteCredential(_, _, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, DeleteCredential)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, HdiCredentialInfo &info) {
|
||||
info.authType = static_cast<HdiAuthType>(1);
|
||||
info.credentialId = 10;
|
||||
info.executorIndex = 20;
|
||||
info.executorMatcher = 30;
|
||||
info.executorSensorHint = 40;
|
||||
info.templateId = 50;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
int32_t result = UserIdmDatabase::Instance().DeleteCredentialInfo(testUserId, testCredentialId,
|
||||
testAuthToken, testCredInfo);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
EXPECT_NE(testCredInfo, nullptr);
|
||||
EXPECT_EQ(testCredInfo->GetAuthType(), PIN);
|
||||
EXPECT_EQ(testCredInfo->GetCredentialId(), 10);
|
||||
EXPECT_EQ(testCredInfo->GetExecutorIndex(), 20);
|
||||
EXPECT_EQ(testCredInfo->GetExecutorMatcher(), 30);
|
||||
EXPECT_EQ(testCredInfo->GetExecutorSensorHint(), 40);
|
||||
EXPECT_EQ(testCredInfo->GetTemplateId(), 50);
|
||||
EXPECT_EQ(testCredInfo->GetUserId(), testUserId);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmDatabaseTest, DeleteUser001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 4501;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
std::vector<std::shared_ptr<CredentialInfo>> testCredInfos;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, DeleteUser(_, _, _)).WillRepeatedly(Return(1));
|
||||
int32_t result = UserIdmDatabase::Instance().DeleteUser(testUserId, testAuthToken, testCredInfos);
|
||||
EXPECT_EQ(result, 1);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmDatabaseTest, DeleteUser002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 4501;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
std::vector<std::shared_ptr<CredentialInfo>> testCredInfos;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, DeleteUser(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, DeleteUser)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, const std::vector<uint8_t> &authToken, std::vector<HdiCredentialInfo> &deletedInfos) {
|
||||
HdiCredentialInfo info = {};
|
||||
info.authType = static_cast<HdiAuthType>(1);
|
||||
info.credentialId = 10;
|
||||
info.executorIndex = 20;
|
||||
info.executorMatcher = 30;
|
||||
info.executorSensorHint = 40;
|
||||
info.templateId = 50;
|
||||
deletedInfos.emplace_back(info);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
int32_t result = UserIdmDatabase::Instance().DeleteUser(testUserId, testAuthToken, testCredInfos);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
EXPECT_EQ(testCredInfos.size(), 1);
|
||||
EXPECT_NE(testCredInfos[0], nullptr);
|
||||
EXPECT_EQ(testCredInfos[0]->GetAuthType(), PIN);
|
||||
EXPECT_EQ(testCredInfos[0]->GetCredentialId(), 10);
|
||||
EXPECT_EQ(testCredInfos[0]->GetExecutorIndex(), 20);
|
||||
EXPECT_EQ(testCredInfos[0]->GetExecutorMatcher(), 30);
|
||||
EXPECT_EQ(testCredInfos[0]->GetExecutorSensorHint(), 40);
|
||||
EXPECT_EQ(testCredInfos[0]->GetTemplateId(), 50);
|
||||
EXPECT_EQ(testCredInfos[0]->GetUserId(), testUserId);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmDatabaseTest, DeleteUserEnforce001, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 4501;
|
||||
std::vector<std::shared_ptr<CredentialInfo>> testCredInfos;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, EnforceDeleteUser(_, _)).WillRepeatedly(Return(1));
|
||||
int32_t result = UserIdmDatabase::Instance().DeleteUserEnforce(testUserId, testCredInfos);
|
||||
EXPECT_EQ(result, 1);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmDatabaseTest, DeleteUserEnforce002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 4501;
|
||||
std::vector<std::shared_ptr<CredentialInfo>> testCredInfos;
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, EnforceDeleteUser(_, _)).Times(1);
|
||||
ON_CALL(*mockHdi, EnforceDeleteUser)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, std::vector<HdiCredentialInfo> &deletedInfos) {
|
||||
HdiCredentialInfo info = {};
|
||||
info.authType = static_cast<HdiAuthType>(1);
|
||||
info.credentialId = 10;
|
||||
info.executorIndex = 20;
|
||||
info.executorMatcher = 30;
|
||||
info.executorSensorHint = 40;
|
||||
info.templateId = 50;
|
||||
deletedInfos.emplace_back(info);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
int32_t result = UserIdmDatabase::Instance().DeleteUserEnforce(testUserId, testCredInfos);
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
EXPECT_EQ(testCredInfos.size(), 1);
|
||||
EXPECT_NE(testCredInfos[0], nullptr);
|
||||
EXPECT_EQ(testCredInfos[0]->GetAuthType(), PIN);
|
||||
EXPECT_EQ(testCredInfos[0]->GetCredentialId(), 10);
|
||||
EXPECT_EQ(testCredInfos[0]->GetExecutorIndex(), 20);
|
||||
EXPECT_EQ(testCredInfos[0]->GetExecutorMatcher(), 30);
|
||||
EXPECT_EQ(testCredInfos[0]->GetExecutorSensorHint(), 40);
|
||||
EXPECT_EQ(testCredInfos[0]->GetTemplateId(), 50);
|
||||
EXPECT_EQ(testCredInfos[0]->GetUserId(), testUserId);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
} // namespace OHOS
|
@ -14,10 +14,11 @@
|
||||
*/
|
||||
|
||||
#include "user_idm_service_test.h"
|
||||
#include "user_idm_service.h"
|
||||
|
||||
#include "iam_common_defines.h"
|
||||
#include "mock_iuser_auth_interface.h"
|
||||
#include "mock_user_idm_callback.h"
|
||||
#include "user_idm_service.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace UserIam {
|
||||
@ -25,6 +26,13 @@ namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
using HdiCredentialInfo = OHOS::HDI::UserAuth::V1_0::CredentialInfo;
|
||||
using HdiEnrolledInfo = OHOS::HDI::UserAuth::V1_0::EnrolledInfo;
|
||||
using HdiAuthType = OHOS::HDI::UserAuth::V1_0::AuthType;
|
||||
using HdiPinSubType = OHOS::HDI::UserAuth::V1_0::PinSubType;
|
||||
using HdiEnrollParam = OHOS::HDI::UserAuth::V1_0::EnrollParam;
|
||||
using HdiScheduleInfo = OHOS::HDI::UserAuth::V1_0::ScheduleInfo;
|
||||
|
||||
void UserIdmServiceTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
@ -35,15 +43,511 @@ void UserIdmServiceTest::TearDownTestCase()
|
||||
|
||||
void UserIdmServiceTest::SetUp()
|
||||
{
|
||||
MockIUserAuthInterface::Holder::GetInstance().Reset();
|
||||
}
|
||||
|
||||
void UserIdmServiceTest::TearDown()
|
||||
{
|
||||
MockIUserAuthInterface::Holder::GetInstance().Reset();
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceOpenSession, TestSize.Level0)
|
||||
{
|
||||
EXPECT_EQ(0, 0);
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 0;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, OpenSession(_, _)).Times(1);
|
||||
ON_CALL(*mockHdi, OpenSession)
|
||||
.WillByDefault(
|
||||
[&testChallenge](int32_t userId, std::vector<uint8_t> &challenge) {
|
||||
challenge = testChallenge;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
std::vector<uint8_t> challenge;
|
||||
int32_t ret = service.OpenSession(testUserId, challenge);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceCloseSession, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 3546;
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, CloseSession(_)).Times(1);
|
||||
ON_CALL(*mockHdi, CloseSession)
|
||||
.WillByDefault(
|
||||
[&testUserId](int32_t userId) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
service.CloseSession(testUserId);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfo001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 0;
|
||||
AuthType testAuthType = PIN;
|
||||
sptr<IdmGetCredInfoCallbackInterface> testCallback = new MockIdmGetCredentialInfoCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmGetCredentialInfoCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnCredentialInfos(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
int32_t ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfo002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 0;
|
||||
AuthType testAuthType = PIN;
|
||||
sptr<IdmGetCredInfoCallbackInterface> testCallback = nullptr;
|
||||
int32_t ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS);
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetCredential)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, HdiAuthType authType, std::vector<HdiCredentialInfo> &infos) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
testCallback = new MockIdmGetCredentialInfoCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmGetCredentialInfoCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnCredentialInfos(_, _)).Times(1);
|
||||
ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback);
|
||||
EXPECT_EQ(ret, NOT_ENROLLED);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceGetCredentialInfo003, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 0;
|
||||
AuthType testAuthType = PIN;
|
||||
sptr<IdmGetCredInfoCallbackInterface> testCallback = new MockIdmGetCredentialInfoCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmGetCredentialInfoCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnCredentialInfos(_, _)).Times(1);
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetCredential)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, HdiAuthType authType, std::vector<HdiCredentialInfo> &infos) {
|
||||
HdiCredentialInfo tempInfo = {
|
||||
.credentialId = 1,
|
||||
.executorIndex = 2,
|
||||
.templateId = 3,
|
||||
.authType = static_cast<HdiAuthType>(1),
|
||||
.executorMatcher = 2,
|
||||
.executorSensorHint = 3,
|
||||
};
|
||||
infos.push_back(tempInfo);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*mockHdi, GetUserInfo(_, _, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetUserInfo)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, uint64_t &secureUid, HdiPinSubType &pinSubType, std::vector<HdiEnrolledInfo> &infos) {
|
||||
HdiEnrolledInfo info = {
|
||||
.enrolledId = 0,
|
||||
.authType = static_cast<HdiAuthType>(1),
|
||||
};
|
||||
infos.push_back(info);
|
||||
pinSubType = static_cast<HdiPinSubType>(10000);
|
||||
secureUid = 4542;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
int32_t ret = service.GetCredentialInfo(testUserId, testAuthType, testCallback);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceGetSecInfo001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 0;
|
||||
sptr<IdmGetSecureUserInfoCallbackInterface> testCallback = new MockIdmGetSecureUserInfoCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmGetSecureUserInfoCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnSecureUserInfo(_)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, GetUserInfo(_, _, _, _)).Times(1);
|
||||
int32_t ret = service.GetSecInfo(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceGetSecInfo002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 0;
|
||||
sptr<IdmGetSecureUserInfoCallbackInterface> testCallback = nullptr;
|
||||
int32_t ret = service.GetSecInfo(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS);
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetUserInfo(_, _, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetUserInfo)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, uint64_t &secureUid, HdiPinSubType &pinSubType, std::vector<HdiEnrolledInfo> &infos) {
|
||||
HdiEnrolledInfo info = {
|
||||
.enrolledId = 0,
|
||||
.authType = static_cast<HdiAuthType>(1),
|
||||
};
|
||||
infos.push_back(info);
|
||||
pinSubType = static_cast<HdiPinSubType>(10000);
|
||||
secureUid = 4542;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
testCallback = new MockIdmGetSecureUserInfoCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmGetSecureUserInfoCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnSecureUserInfo(_)).Times(1);
|
||||
ret = service.GetSecInfo(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15457;
|
||||
UserIdmInterface::CredentialPara testCredPara = {};
|
||||
testCredPara.authType = PIN;
|
||||
testCredPara.pinType = PIN_SIX;
|
||||
testCredPara.token = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = nullptr;
|
||||
service.AddCredential(testUserId, testCredPara, testCallback, false);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceAddCredential002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15457;
|
||||
UserIdmInterface::CredentialPara testCredPara = {};
|
||||
testCredPara.authType = PIN;
|
||||
testCredPara.pinType = PIN_SIX;
|
||||
testCredPara.token = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollment(_, _, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, BeginEnrollment)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
HdiScheduleInfo &info) {
|
||||
info = {};
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
service.AddCredential(testUserId, testCredPara, testCallback, false);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 1548545;
|
||||
UserIdmInterface::CredentialPara testCredPara = {};
|
||||
testCredPara.authType = FACE;
|
||||
testCredPara.pinType = PIN_SIX;
|
||||
testCredPara.token = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
service.UpdateCredential(testUserId, testCredPara, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceUpdateCredential002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 1548545;
|
||||
UserIdmInterface::CredentialPara testCredPara = {};
|
||||
testCredPara.authType = FACE;
|
||||
testCredPara.pinType = PIN_SIX;
|
||||
sptr<IdmCallbackInterface> testCallback = nullptr;
|
||||
service.UpdateCredential(testUserId, testCredPara, testCallback);
|
||||
|
||||
testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(2);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetCredential(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, GetCredential)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, HdiAuthType authType, std::vector<HdiCredentialInfo> &infos) {
|
||||
HdiCredentialInfo tempInfo = {
|
||||
.credentialId = 1,
|
||||
.executorIndex = 2,
|
||||
.templateId = 3,
|
||||
.authType = static_cast<HdiAuthType>(2),
|
||||
.executorMatcher = 2,
|
||||
.executorSensorHint = 3,
|
||||
};
|
||||
infos.push_back(tempInfo);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*mockHdi, BeginEnrollment(_, _, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, BeginEnrollment)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, const std::vector<uint8_t> &authToken, const HdiEnrollParam ¶m,
|
||||
HdiScheduleInfo &info) {
|
||||
info = {};
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
|
||||
service.UpdateCredential(testUserId, testCredPara, testCallback);
|
||||
|
||||
testCredPara.token = {1, 2, 3, 4};
|
||||
service.UpdateCredential(testUserId, testCredPara, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceCancel001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 154835;
|
||||
int32_t ret = service.Cancel(testUserId);
|
||||
EXPECT_NE(ret, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceCancel002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 154835;
|
||||
std::vector<uint8_t> testChallenge = {1, 2, 3, 4};
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, OpenSession(_, _)).Times(1);
|
||||
ON_CALL(*mockHdi, OpenSession)
|
||||
.WillByDefault(
|
||||
[&testChallenge](int32_t userId, std::vector<uint8_t> &challenge) {
|
||||
challenge = testChallenge;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
);
|
||||
std::vector<uint8_t> challenge;
|
||||
int32_t ret = service.OpenSession(testUserId, challenge);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
ret = service.Cancel(testUserId);
|
||||
EXPECT_EQ(ret, GENERAL_ERROR);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceEnforceDelUser001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15485;
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetUserInfo(_, _, _, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, EnforceDeleteUser(_, _)).Times(1);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
int32_t ret = service.EnforceDelUser(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceEnforceDelUser002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15485;
|
||||
sptr<IdmCallbackInterface> testCallback = nullptr;
|
||||
int32_t ret = service.EnforceDelUser(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, INVALID_PARAMETERS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceEnforceDelUser003, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15485;
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetUserInfo(_, _, _, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, EnforceDeleteUser(_, _)).Times(1);
|
||||
ON_CALL(*mockHdi, EnforceDeleteUser)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, std::vector<HdiCredentialInfo> &deletedInfos) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
);
|
||||
int32_t ret = service.EnforceDelUser(testUserId, testCallback);
|
||||
EXPECT_EQ(ret, -1);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15486465;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, DeleteUser(_, _, _)).Times(1);
|
||||
service.DelUser(testUserId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15486465;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = nullptr;
|
||||
service.DelUser(testUserId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser003, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15486465;
|
||||
std::vector<uint8_t> testAuthToken;
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
service.DelUser(testUserId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceDelUser004, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 15486465;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, DeleteUser(_, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, DeleteUser)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, const std::vector<uint8_t> &authToken, std::vector<HdiCredentialInfo> &deletedInfos) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
);
|
||||
service.DelUser(testUserId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential001, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 1548865;
|
||||
uint64_t testCredentialId = 23424;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, DeleteCredential(_, _, _, _)).Times(1);
|
||||
service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential002, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 1548865;
|
||||
uint64_t testCredentialId = 23424;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = nullptr;
|
||||
service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceDelCredential003, TestSize.Level0)
|
||||
{
|
||||
UserIdmService service(123123, true);
|
||||
int32_t testUserId = 1548865;
|
||||
uint64_t testCredentialId = 23424;
|
||||
std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
|
||||
sptr<IdmCallbackInterface> testCallback = new MockIdmCallback();
|
||||
EXPECT_NE(testCallback, nullptr);
|
||||
auto *tempCallback = static_cast<MockIdmCallback *>(testCallback.GetRefPtr());
|
||||
EXPECT_NE(tempCallback, nullptr);
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*tempCallback, OnResult(_, _)).Times(1);
|
||||
EXPECT_CALL(*mockHdi, DeleteCredential(_, _, _, _)).Times(1);
|
||||
ON_CALL(*mockHdi, DeleteCredential)
|
||||
.WillByDefault(
|
||||
[](int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, HdiCredentialInfo &info) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
);
|
||||
service.DelCredential(testUserId, testCredentialId, testAuthToken, testCallback);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmServiceTest, UserIdmServiceTestDump, TestSize.Level0)
|
||||
{
|
||||
int testFd1 = -1;
|
||||
int testFd2 = 1;
|
||||
std::vector<std::u16string> testArgs;
|
||||
|
||||
UserIdmService service(123123, true);
|
||||
|
||||
auto mockHdi = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_NE(mockHdi, nullptr);
|
||||
EXPECT_CALL(*mockHdi, GetUserInfo(_, _, _, _)).Times(1);
|
||||
|
||||
EXPECT_EQ(service.Dump(testFd1, testArgs), INVALID_PARAMETERS);
|
||||
EXPECT_EQ(service.Dump(testFd2, testArgs), SUCCESS);
|
||||
testArgs.push_back(u"-h");
|
||||
EXPECT_EQ(service.Dump(testFd2, testArgs), SUCCESS);
|
||||
testArgs.clear();
|
||||
testArgs.push_back(u"-l");
|
||||
EXPECT_EQ(service.Dump(testFd2, testArgs), SUCCESS);
|
||||
testArgs.clear();
|
||||
testArgs.push_back(u"-k");
|
||||
EXPECT_EQ(service.Dump(testFd2, testArgs), GENERAL_ERROR);
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -93,18 +93,11 @@ HWTEST_F(UserIdmSessionControllerTest, UserIdmServiceIsSessionOpened, TestSize.L
|
||||
EXPECT_CALL(*mock, OpenSession(userId, _)).WillRepeatedly(DoAll(WithArg<1>(fillUpChallenge), Return(SUCCESS)));
|
||||
|
||||
EXPECT_EQ(false, UserIdmSessionController::Instance().IsSessionOpened(userId));
|
||||
EXPECT_EQ(false, UserIdmSessionController::Instance().IsSessionOpened(nonce));
|
||||
EXPECT_EQ(0U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().OpenSession(userId, challenge));
|
||||
EXPECT_THAT(challenge, ElementsAreArray(nonce));
|
||||
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().IsSessionOpened(userId));
|
||||
EXPECT_EQ(1U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().IsSessionOpened(challenge));
|
||||
|
||||
std::vector<uint8_t> notExisted = {1, 2, 3, 4, 5};
|
||||
EXPECT_EQ(false, UserIdmSessionController::Instance().IsSessionOpened(notExisted));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmSessionControllerTest, UserIdmServiceIsSessionClosedByUserId, TestSize.Level0)
|
||||
@ -118,15 +111,14 @@ HWTEST_F(UserIdmSessionControllerTest, UserIdmServiceIsSessionClosedByUserId, Te
|
||||
|
||||
auto mock = MockIUserAuthInterface::Holder::GetInstance().Get();
|
||||
EXPECT_CALL(*mock, OpenSession(userId, _)).WillRepeatedly(DoAll(WithArg<1>(fillUpChallenge), Return(SUCCESS)));
|
||||
EXPECT_CALL(*mock, CloseSession(userId)).WillRepeatedly(Return(SUCCESS));
|
||||
|
||||
EXPECT_EQ(0U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
EXPECT_CALL(*mock, CloseSession(userId))
|
||||
.WillOnce(Return(HDF_SUCCESS))
|
||||
.WillOnce(Return(HDF_FAILURE));
|
||||
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().OpenSession(userId, challenge));
|
||||
EXPECT_EQ(1U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().CloseSession(userId));
|
||||
EXPECT_EQ(0U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
EXPECT_TRUE(UserIdmSessionController::Instance().CloseSession(userId));
|
||||
EXPECT_FALSE(UserIdmSessionController::Instance().CloseSession(userId));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmSessionControllerTest, UserIdmServiceIsSessionClosedByChallenge, TestSize.Level0)
|
||||
@ -142,13 +134,9 @@ HWTEST_F(UserIdmSessionControllerTest, UserIdmServiceIsSessionClosedByChallenge,
|
||||
EXPECT_CALL(*mock, OpenSession(userId, _)).WillRepeatedly(DoAll(WithArg<1>(fillUpChallenge), Return(SUCCESS)));
|
||||
EXPECT_CALL(*mock, CloseSession(userId)).WillRepeatedly(Return(SUCCESS));
|
||||
|
||||
EXPECT_EQ(0U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().OpenSession(userId, challenge));
|
||||
EXPECT_EQ(1U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().CloseSession(nonce));
|
||||
EXPECT_EQ(0U, UserIdmSessionController::Instance().GetOpenedSessions().size());
|
||||
EXPECT_EQ(true, UserIdmSessionController::Instance().CloseSession(userId));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
@ -31,13 +31,6 @@ namespace UserAuth {
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace {
|
||||
constexpr int32_t IDM_STUB_TEST_USER_ID = 1;
|
||||
const vector<uint8_t> IDM_STUB_TEST_AUTH_TOKEN = {1, 2, 3, 4, 5};
|
||||
constexpr uint64_t IDM_STUB_TEST_CRED_ID = 1;
|
||||
std::vector<uint8_t> g_challengeVectorTest = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
} // namespace
|
||||
|
||||
void UserIdmStubTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
@ -54,288 +47,502 @@ void UserIdmStubTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubOpenSessionStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubOpenSessionStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_OPEN_SESSION;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
EXPECT_CALL(service, OpenSession(Eq(IDM_STUB_TEST_USER_ID), _)).Times(1);
|
||||
ON_CALL(service, OpenSession).WillByDefault([](std::optional<int32_t> userId, std::vector<uint8_t> &challenge) {
|
||||
challenge = g_challengeVectorTest;
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubOpenSessionStub002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 887436;
|
||||
std::vector<uint8_t> 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<uint8_t> &challenge) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
challenge = testChallenge;
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_OPEN_SESSION;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteInt32(testUserId));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserIdmInterface::USER_IDM_OPEN_SESSION, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
|
||||
std::vector<uint8_t> challenge;
|
||||
EXPECT_TRUE(reply.ReadUInt8Vector(&challenge));
|
||||
EXPECT_THAT(g_challengeVectorTest, ElementsAre(1, 2, 3, 4, 5, 6, 7, 8));
|
||||
EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubCloseSessionStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubCloseSessionStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_CLOSE_SESSION;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
EXPECT_CALL(service, CloseSession(Eq(IDM_STUB_TEST_USER_ID))).Times(1);
|
||||
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 = UserIdmInterface::USER_IDM_CLOSE_SESSION;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteInt32(testUserId));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserIdmInterface::USER_IDM_CLOSE_SESSION, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubGetCredentialInfoStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubGetCredentialInfoStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_GET_CRED_INFO;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
const sptr<MockIdmGetCredentialInfoCallback> callback = new (std::nothrow) MockIdmGetCredentialInfoCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, GetCredentialInfo(Eq(IDM_STUB_TEST_USER_ID), FACE, _)).Times(1);
|
||||
ON_CALL(service, GetCredentialInfo)
|
||||
.WillByDefault([](std::optional<int32_t> userId, AuthType authType,
|
||||
const sptr<IdmGetCredInfoCallbackInterface> &callback) {
|
||||
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<MockIdmGetCredentialInfoCallback> 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<IdmGetCredInfoCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_EQ(authType, testAuthType);
|
||||
if (callback != nullptr) {
|
||||
std::vector<std::shared_ptr<CredentialInfo>> infoList;
|
||||
callback->OnCredentialInfos(infoList, std::nullopt);
|
||||
}
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*callback, OnCredentialInfos(_, _)).Times(1);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_GET_CRED_INFO;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteUint32(FACE));
|
||||
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(UserIdmInterface::USER_IDM_GET_CRED_INFO, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
|
||||
int32_t result;
|
||||
int32_t result = FAIL;
|
||||
EXPECT_TRUE(reply.ReadInt32(result));
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubGetSecInfoStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubGetSecInfoStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::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<MockIdmGetSecureUserInfoCallback> callback = new (std::nothrow) MockIdmGetSecureUserInfoCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, GetSecInfo(Eq(IDM_STUB_TEST_USER_ID), _)).Times(1);
|
||||
ON_CALL(service, GetSecInfo)
|
||||
.WillByDefault([](std::optional<int32_t> userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) {
|
||||
EXPECT_NE(callback, nullptr);
|
||||
MockUserIdmService service;
|
||||
EXPECT_CALL(service, GetSecInfo(_, _)).Times(1);
|
||||
ON_CALL(service, GetSecInfo)
|
||||
.WillByDefault(
|
||||
[&testUserId](int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) {
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
if (callback != nullptr) {
|
||||
const std::shared_ptr<SecureUserInfo> info;
|
||||
const std::shared_ptr<IdmGetSecureUserInfoCallbackInterface::SecureUserInfo> info;
|
||||
callback->OnSecureUserInfo(info);
|
||||
}
|
||||
return SUCCESS;
|
||||
});
|
||||
}
|
||||
);
|
||||
EXPECT_CALL(*callback, OnSecureUserInfo(_)).Times(1);
|
||||
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_GET_SEC_INFO;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteInt32(testUserId));
|
||||
EXPECT_NE(callback->AsObject(), nullptr);
|
||||
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserIdmInterface::USER_IDM_GET_SEC_INFO, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
|
||||
int32_t result;
|
||||
int32_t result = FAIL;
|
||||
EXPECT_TRUE(reply.ReadInt32(result));
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_ADD_CREDENTIAL;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
const sptr<MockIdmCallback> callback = new (std::nothrow) MockIdmCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, AddCredential(Eq(IDM_STUB_TEST_USER_ID), PIN, PIN_SIX, IsEmpty(), _, false)).Times(1);
|
||||
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<MockIdmCallback> callback = new (std::nothrow) MockIdmCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
MockUserIdmService service;
|
||||
EXPECT_CALL(service, AddCredential(_, _, _, _)).Times(1);
|
||||
ON_CALL(service, AddCredential)
|
||||
.WillByDefault(
|
||||
[](std::optional<int32_t> userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback, bool isUpdate) {
|
||||
EXPECT_NE(callback, nullptr);
|
||||
[&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &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 = UserIdmInterface::USER_IDM_ADD_CREDENTIAL;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteInt32(PIN));
|
||||
EXPECT_TRUE(data.WriteInt32(PIN_SIX));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(IDM_STUB_TEST_AUTH_TOKEN));
|
||||
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(UserIdmInterface::USER_IDM_ADD_CREDENTIAL, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::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<MockIdmCallback> callback = new (std::nothrow) MockIdmCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, UpdateCredential(Eq(IDM_STUB_TEST_USER_ID), PIN, PIN_SIX, Eq(IDM_STUB_TEST_AUTH_TOKEN), _))
|
||||
.Times(1);
|
||||
EXPECT_NE(callback, nullptr);
|
||||
MockUserIdmService service;
|
||||
EXPECT_CALL(service, UpdateCredential(_, _, _)).Times(1);
|
||||
ON_CALL(service, UpdateCredential)
|
||||
.WillByDefault([](std::optional<int32_t> userId, AuthType authType, PinSubType pinSubType,
|
||||
const std::vector<uint8_t> &token, const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_NE(callback, nullptr);
|
||||
.WillByDefault(
|
||||
[&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
|
||||
const sptr<IdmCallbackInterface> &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 = UserIdmInterface::USER_IDM_UPDATE_CREDENTIAL;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteInt32(PIN));
|
||||
EXPECT_TRUE(data.WriteInt32(PIN_SIX));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(IDM_STUB_TEST_AUTH_TOKEN));
|
||||
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(UserIdmInterface::USER_IDM_UPDATE_CREDENTIAL, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_CANCEL;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
EXPECT_CALL(service, Cancel(Eq(IDM_STUB_TEST_USER_ID))).WillOnce(Return(SUCCESS));
|
||||
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 = UserIdmInterface::USER_IDM_CANCEL;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteInt32(testUserId));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserIdmInterface::USER_IDM_CANCEL, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
|
||||
int32_t result;
|
||||
int32_t result = FAIL;
|
||||
EXPECT_TRUE(reply.ReadInt32(result));
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_ENFORCE_DEL_USER;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
const sptr<MockIdmCallback> callback = new (std::nothrow) MockIdmCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, EnforceDelUser(Eq(IDM_STUB_TEST_USER_ID), _)).Times(1);
|
||||
ON_CALL(service, EnforceDelUser).WillByDefault([](int32_t userId, const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 83462;
|
||||
|
||||
sptr<MockIdmCallback> 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<IdmCallbackInterface> &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 = UserIdmInterface::USER_IDM_ENFORCE_DEL_USER;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteInt32(testUserId));
|
||||
EXPECT_NE(callback->AsObject(), nullptr);
|
||||
EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
|
||||
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(UserIdmInterface::USER_IDM_ENFORCE_DEL_USER, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
|
||||
int32_t result;
|
||||
int32_t result = FAIL;
|
||||
EXPECT_TRUE(reply.ReadInt32(result));
|
||||
EXPECT_EQ(result, SUCCESS);
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_DEL_USER;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
const sptr<MockIdmCallback> callback = new (std::nothrow) MockIdmCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service, DelUser(Eq(IDM_STUB_TEST_USER_ID), Eq(IDM_STUB_TEST_AUTH_TOKEN), _)).Times(1);
|
||||
EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub002, TestSize.Level0)
|
||||
{
|
||||
int32_t testUserId = 72342;
|
||||
std::vector<uint8_t> testAuthToken = {1, 3, 5, 7};
|
||||
|
||||
sptr<MockIdmCallback> callback = new (std::nothrow) MockIdmCallback();
|
||||
EXPECT_NE(callback, nullptr);
|
||||
MockUserIdmService service;
|
||||
EXPECT_CALL(service, DelUser(_, _, _)).Times(1);
|
||||
ON_CALL(service, DelUser)
|
||||
.WillByDefault([](std::optional<int32_t> userId, const std::vector<uint8_t> authToken,
|
||||
.WillByDefault(
|
||||
[&testUserId, &testAuthToken](int32_t userId, const std::vector<uint8_t> authToken,
|
||||
const sptr<IdmCallbackInterface> &callback) {
|
||||
EXPECT_NE(callback, nullptr);
|
||||
EXPECT_EQ(userId, testUserId);
|
||||
EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
|
||||
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 = UserIdmInterface::USER_IDM_DEL_USER;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(IDM_STUB_TEST_AUTH_TOKEN));
|
||||
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(UserIdmInterface::USER_IDM_DEL_USER, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub, TestSize.Level0)
|
||||
HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub001, TestSize.Level0)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
uint32_t code = UserIdmInterface::USER_IDM_DEL_CRED;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
|
||||
MockUserIdmService service;
|
||||
const sptr<MockIdmCallback> callback = new (std::nothrow) MockIdmCallback();
|
||||
ASSERT_NE(callback, nullptr);
|
||||
EXPECT_CALL(service,
|
||||
DelCredential(Eq(IDM_STUB_TEST_USER_ID), Eq(IDM_STUB_TEST_CRED_ID), Eq(IDM_STUB_TEST_AUTH_TOKEN), _))
|
||||
.Times(1);
|
||||
ON_CALL(service, DelCredential)
|
||||
.WillByDefault([](std::optional<int32_t> userId, uint64_t credentialId, const std::vector<uint8_t> &authToken,
|
||||
const sptr<IdmCallbackInterface> &callback) {
|
||||
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<uint8_t> testAuthToken = {3, 5, 7, 9};
|
||||
|
||||
sptr<MockIdmCallback> 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<uint8_t> &authToken, const sptr<IdmCallbackInterface> &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 = UserIdmInterface::USER_IDM_DEL_CRED;
|
||||
|
||||
EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
|
||||
EXPECT_TRUE(data.WriteInt32(IDM_STUB_TEST_USER_ID));
|
||||
EXPECT_TRUE(data.WriteUint64(IDM_STUB_TEST_CRED_ID));
|
||||
EXPECT_TRUE(data.WriteUInt8Vector(IDM_STUB_TEST_AUTH_TOKEN));
|
||||
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(UserIdmInterface::USER_IDM_DEL_CRED, data, reply, option));
|
||||
EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
|
||||
}
|
||||
} // namespace UserAuth
|
||||
} // namespace UserIam
|
||||
|
Loading…
Reference in New Issue
Block a user