mirror of
https://github.com/openharmony/useriam_user_auth.git
synced 2026-07-19 22:33:53 -04:00
@@ -26,30 +26,31 @@ UserAuthProxy::UserAuthProxy(const sptr<IRemoteObject> &object) : IRemoteProxy<I
|
||||
int32_t UserAuthProxy::GetAvailableStatus(const AuthType authType, const AuthTurstLevel authTurstLevel)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy GetAvailableStatus is start");
|
||||
int32_t result = GENERAL_ERROR;
|
||||
int32_t result = SUCCESS;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!");
|
||||
return result;
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(authType))) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast<uint32_t>(authType)).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(authTurstLevel))) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast<uint32_t>(authTurstLevel)).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
bool ret = SendRequest(static_cast<int32_t>(IUserAuth::USER_AUTH_GET_AVAILABLE_STATUS), data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret);
|
||||
return IPC_ERROR;
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
if (!reply.ReadInt32(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Readback fail!");
|
||||
return GENERAL_ERROR;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -127,36 +128,37 @@ uint64_t UserAuthProxy::Auth(const uint64_t challenge, const AuthType authType,
|
||||
const AuthTurstLevel authTurstLevel, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy Auth is start");
|
||||
u_int64_t result = SUCCESS;
|
||||
const uint64_t invalidContextID = 0;
|
||||
uint64_t result = invalidContextID;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth write descriptor failed!");
|
||||
return result;
|
||||
return invalidContextID;
|
||||
}
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthProxy::Auth challenge = %{public}" PRIu64 "", challenge);
|
||||
if (!data.WriteUint64(challenge)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(challenge).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(authType))) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast<uint32_t>(authType)).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(authTurstLevel))) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast<uint32_t>(authTurstLevel)).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback->AsObject()).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH, data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth SendRequest is failed, error code: %{public}d", ret);
|
||||
return result;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!reply.ReadUint64(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Readback fail!");
|
||||
@@ -169,39 +171,40 @@ uint64_t UserAuthProxy::AuthUser(const int32_t userId, const uint64_t challenge,
|
||||
const AuthTurstLevel authTurstLevel, sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_INNERKIT, "UserAuthProxy AuthUser is start");
|
||||
u_int64_t result = SUCCESS;
|
||||
const uint64_t invalidContextID = 0;
|
||||
uint64_t result = invalidContextID;
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option(MessageOption::TF_SYNC);
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
|
||||
return result;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteInt32(userId)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteInt32(userId).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteUint64(challenge)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(challenge).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(authType))) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast<uint32_t>(authType)).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteUint32(static_cast<uint32_t>(authTurstLevel))) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint32(static_cast<uint32_t>(authTurstLevel)).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!data.WriteRemoteObject(callback->AsObject())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteRemoteObject(callback->AsObject()).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return invalidContextID;
|
||||
}
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_AUTH_USER, data, reply, option);
|
||||
if (!ret) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "SendRequest is failed, error code: %{public}d", ret);
|
||||
return result;
|
||||
return invalidContextID;
|
||||
}
|
||||
if (!reply.ReadUint64(result)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "userauth Readback fail!");
|
||||
@@ -220,11 +223,11 @@ int32_t UserAuthProxy::CancelAuth(const uint64_t contextId)
|
||||
|
||||
if (!data.WriteInterfaceToken(UserAuthProxy::GetDescriptor())) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "write descriptor failed!");
|
||||
return result;
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
if (!data.WriteUint64(contextId)) {
|
||||
USERAUTH_HILOGE(MODULE_INNERKIT, "failed to WriteUint64(contextId).");
|
||||
return E_READ_PARCEL_ERROR;
|
||||
return E_WRITE_PARCEL_ERROR;
|
||||
}
|
||||
bool ret = SendRequest(IUserAuth::USER_AUTH_CANCEL_AUTH, data, reply, option);
|
||||
if (!ret) {
|
||||
|
||||
@@ -78,7 +78,7 @@ int32_t UserAuthService::GetAvailableStatus(const AuthType authType, const AuthT
|
||||
ret = this->GetCallingUserID(userID);
|
||||
if (ret != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService GetAvailableStatus GetUserID is ERROR!");
|
||||
return result;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = userauthController_.GetAuthTrustLevel(userID, authType, authTurstLevelFromSys);
|
||||
@@ -177,8 +177,7 @@ uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService Auth is start");
|
||||
int ret = SUCCESS;
|
||||
int result = SUCCESS;
|
||||
const uint64_t invalidContextID = 0;
|
||||
int32_t userID = 0;
|
||||
uint64_t callerID = 0;
|
||||
std::string callerName = "";
|
||||
@@ -193,13 +192,13 @@ uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType
|
||||
}
|
||||
|
||||
if (GetControllerData(callback, extraInfo, authTurstLevel, callerID, callerName, contextID) == FAIL) {
|
||||
return ret;
|
||||
return invalidContextID;
|
||||
}
|
||||
result = this->GetCallingUserID(userID);
|
||||
int32_t result = this->GetCallingUserID(userID);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth GetUserID is ERROR!");
|
||||
callback->onResult(FAIL, extraInfo);
|
||||
return ret;
|
||||
return invalidContextID;
|
||||
}
|
||||
|
||||
authSolutionParam.contextId = contextID;
|
||||
@@ -211,7 +210,7 @@ uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth GenerateSolution is ERROR!");
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
return invalidContextID;
|
||||
}
|
||||
|
||||
coAuthInfo.authType = authType;
|
||||
@@ -223,7 +222,7 @@ uint64_t UserAuthService::Auth(const uint64_t challenge, const AuthType authType
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService Auth coAuth is ERROR!");
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
return invalidContextID;
|
||||
}
|
||||
return contextID;
|
||||
}
|
||||
@@ -233,8 +232,7 @@ uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challeng
|
||||
sptr<IUserAuthCallback>& callback)
|
||||
{
|
||||
USERAUTH_HILOGD(MODULE_SERVICE, "UserAuthService AuthUser is start");
|
||||
int ret = SUCCESS;
|
||||
int result = SUCCESS;
|
||||
const uint64_t invalidContextID = 0;
|
||||
uint64_t callerID = 0;
|
||||
std::string callerName = "";
|
||||
uint64_t contextID = 0;
|
||||
@@ -248,7 +246,7 @@ uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challeng
|
||||
}
|
||||
|
||||
if (GetControllerData(callback, extraInfo, authTurstLevel, callerID, callerName, contextID) == FAIL) {
|
||||
return ret;
|
||||
return invalidContextID;
|
||||
}
|
||||
|
||||
authSolutionParam.contextId = contextID;
|
||||
@@ -256,12 +254,12 @@ uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challeng
|
||||
authSolutionParam.authTrustLevel = authTurstLevel;
|
||||
authSolutionParam.challenge = challenge;
|
||||
authSolutionParam.authType = authType;
|
||||
result = userauthController_.GenerateSolution(authSolutionParam, coAuthInfo.sessionIds);
|
||||
int32_t result = userauthController_.GenerateSolution(authSolutionParam, coAuthInfo.sessionIds);
|
||||
if (result != SUCCESS) {
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser GenerateSolution is ERROR!");
|
||||
userauthController_.DeleteContextID(contextID);
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
return invalidContextID;
|
||||
}
|
||||
|
||||
coAuthInfo.authType = authType;
|
||||
@@ -274,7 +272,7 @@ uint64_t UserAuthService::AuthUser(const int32_t userId, const uint64_t challeng
|
||||
USERAUTH_HILOGE(MODULE_SERVICE, "UserAuthService AuthUser coAuth is ERROR!");
|
||||
userauthController_.DeleteContextID(contextID);
|
||||
callback->onResult(result, extraInfo);
|
||||
return ret;
|
||||
return invalidContextID;
|
||||
}
|
||||
return contextID;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,9 @@ HWTEST_F(UseriamUtTest, UseriamUtTest_001, TestSize.Level1)
|
||||
{
|
||||
AuthType authType = FACE;
|
||||
AuthTurstLevel authTurstLevel = ATL1;
|
||||
EXPECT_EQ(0, UserAuth::GetInstance().GetAvailableStatus(authType, authTurstLevel));
|
||||
// The ipc communication test is OK. The service and ut tests cannot obtain the correct userId,
|
||||
// and return a error 5(TYPE_NOT_SUPPORT).
|
||||
EXPECT_EQ(5, UserAuth::GetInstance().GetAvailableStatus(authType, authTurstLevel));
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_002, TestSize.Level1)
|
||||
@@ -127,23 +129,27 @@ HWTEST_F(UseriamUtTest, UseriamUtTest_004, TestSize.Level1)
|
||||
AuthType authType = FACE;
|
||||
AuthTurstLevel authTurstLevel = ATL1;
|
||||
std::shared_ptr<UserAuthCallback> callback = std::make_shared<TestUserAuthCallback>();
|
||||
EXPECT_EQ(123, UserAuth::GetInstance().Auth(challenge, authType, authTurstLevel, callback));
|
||||
// Ut test IPC communication is OK, getCallinguerId interface returns fail, verification failed,
|
||||
// return value 0(FAIL).
|
||||
EXPECT_EQ(0, UserAuth::GetInstance().Auth(challenge, authType, authTurstLevel, callback));
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_005, TestSize.Level1)
|
||||
{
|
||||
int32_t userId = 100;
|
||||
int32_t userId = 0;
|
||||
uint64_t challenge = 001;
|
||||
AuthType authType = FACE;
|
||||
AuthTurstLevel authTurstLevel = ATL1;
|
||||
std::shared_ptr<UserAuthCallback> callback = std::make_shared<TestUserAuthCallback>();
|
||||
EXPECT_EQ(123, UserAuth::GetInstance().AuthUser(userId, challenge, authType, authTurstLevel, callback));
|
||||
// Ut test IPC communication is OK, userId is invalid, verification failed, return value 0(FAIL).
|
||||
EXPECT_EQ(0, UserAuth::GetInstance().AuthUser(userId, challenge, authType, authTurstLevel, callback));
|
||||
}
|
||||
|
||||
HWTEST_F(UseriamUtTest, UseriamUtTest_006, TestSize.Level1)
|
||||
{
|
||||
uint64_t contextId = 123;
|
||||
EXPECT_EQ(0, UserAuth::GetInstance().CancelAuth(contextId));
|
||||
uint64_t contextId = 0;
|
||||
// Tests whether an 12(INVALID_CONTEXTID) is returned when an invalid contexID is used to cancel authentication.
|
||||
EXPECT_EQ(12, UserAuth::GetInstance().CancelAuth(contextId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user