mirror of
https://gitee.com/openharmony/account_os_account
synced 2024-11-23 02:00:01 +00:00
!2255 【账号iam】异常分支接口返回值处理
Merge pull request !2255 from lichenchen/master
This commit is contained in:
commit
7e3bdfdff3
@ -109,12 +109,13 @@ void DomainAuthCallbackAdapter::OnResult(const int32_t errCode, Parcel &parcel)
|
||||
ACCOUNT_LOGE("callback is nullptr");
|
||||
return;
|
||||
}
|
||||
Attributes attr;
|
||||
std::shared_ptr<DomainAuthResult> authResult(DomainAuthResult::Unmarshalling(parcel));
|
||||
if (authResult == nullptr) {
|
||||
ACCOUNT_LOGE("authResult is nullptr");
|
||||
callback_->OnResult(ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR, attr);
|
||||
return;
|
||||
}
|
||||
Attributes attr;
|
||||
attr.SetUint8ArrayValue(Attributes::AttributeKey::ATTR_SIGNATURE, (*authResult).token);
|
||||
attr.SetInt32Value(Attributes::AttributeKey::ATTR_REMAIN_TIMES, (*authResult).authStatusInfo.remainingTimes);
|
||||
attr.SetInt32Value(Attributes::AttributeKey::ATTR_FREEZING_TIME, (*authResult).authStatusInfo.freezingTime);
|
||||
@ -138,6 +139,7 @@ void DomainCredentialRecipient::OnSetData(int32_t authSubType, std::vector<uint8
|
||||
AccountSA::DomainAuthResult emptyResult;
|
||||
if (!emptyResult.Marshalling(emptyParcel)) {
|
||||
ACCOUNT_LOGE("authResult Marshalling failed");
|
||||
callback->OnResult(ERR_ACCOUNT_COMMON_WRITE_PARCEL_ERROR, emptyParcel);
|
||||
return;
|
||||
}
|
||||
callback->OnResult(errCode, emptyParcel);
|
||||
|
@ -155,14 +155,19 @@ void AccountIAMClient::DelUser(
|
||||
int32_t AccountIAMClient::GetCredentialInfo(
|
||||
int32_t userId, AuthType authType, const std::shared_ptr<GetCredInfoCallback> &callback)
|
||||
{
|
||||
if (callback == nullptr) {
|
||||
ACCOUNT_LOGE("The callback for get credential info is nullptr");
|
||||
return ERR_ACCOUNT_COMMON_NULL_PTR_ERROR;
|
||||
}
|
||||
std::vector<CredentialInfo> infoList;
|
||||
auto proxy = GetAccountIAMProxy();
|
||||
if (proxy == nullptr) {
|
||||
callback->OnCredentialInfo(ERR_ACCOUNT_COMMON_GET_PROXY, infoList);
|
||||
return ERR_ACCOUNT_COMMON_GET_PROXY;
|
||||
}
|
||||
sptr<IGetCredInfoCallback> wrapper = new (std::nothrow) GetCredInfoCallbackService(callback);
|
||||
ErrCode result = proxy->GetCredentialInfo(userId, authType, wrapper);
|
||||
if ((result != ERR_OK) && (callback != nullptr)) {
|
||||
std::vector<CredentialInfo> infoList;
|
||||
if (result != ERR_OK) {
|
||||
callback->OnCredentialInfo(result, infoList);
|
||||
}
|
||||
return result;
|
||||
@ -224,12 +229,15 @@ uint64_t AccountIAMClient::AuthUser(
|
||||
ACCOUNT_LOGE("callback is nullptr");
|
||||
return contextId;
|
||||
}
|
||||
Attributes emptyResult;
|
||||
auto proxy = GetAccountIAMProxy();
|
||||
if (proxy == nullptr) {
|
||||
callback->OnResult(ERR_ACCOUNT_COMMON_GET_PROXY, emptyResult);
|
||||
return contextId;
|
||||
}
|
||||
if ((!authOptions.hasRemoteAuthOptions) && (authOptions.accountId == -1) &&
|
||||
(!GetCurrentUserId(authOptions.accountId))) {
|
||||
callback->OnResult(ERR_ACCOUNT_COMMON_INVALID_PARAMETER, emptyResult);
|
||||
return contextId;
|
||||
}
|
||||
#ifdef HAS_PIN_AUTH_PART
|
||||
@ -258,7 +266,6 @@ uint64_t AccountIAMClient::AuthUser(
|
||||
}
|
||||
ErrCode result = proxy->AuthUser(authParam, wrapper, contextId);
|
||||
if (result != ERR_OK) {
|
||||
Attributes emptyResult;
|
||||
callback->OnResult(result, emptyResult);
|
||||
}
|
||||
return contextId;
|
||||
|
@ -76,6 +76,15 @@ public:
|
||||
int32_t result_;
|
||||
};
|
||||
|
||||
class GetCredCallbackMockTest final : public AccountSA::GetCredInfoCallback {
|
||||
public:
|
||||
void OnCredentialInfo(int32_t result, const std::vector<CredentialInfo> &infoList)
|
||||
{
|
||||
result_ = result;
|
||||
}
|
||||
int32_t result_;
|
||||
};
|
||||
|
||||
class PreRemoteAuthCallbackMockTest final : public AccountSA::PreRemoteAuthCallback {
|
||||
public:
|
||||
void OnResult(int32_t result) override
|
||||
@ -182,16 +191,29 @@ HWTEST_F(AccountIAMProxyMockTest, AccountIAMClient_DelUser_0100, TestSize.Level0
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClient_GetCredentialInfo_0100
|
||||
* @tc.desc: Test func with proxy is nullptr.
|
||||
* @tc.desc: Test func with callback is nullptr.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5N90O
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIAMProxyMockTest, AccountIAMClient_GetCredentialInfo_0100, TestSize.Level0)
|
||||
{
|
||||
ASSERT_EQ(ERR_ACCOUNT_COMMON_GET_PROXY,
|
||||
ASSERT_EQ(ERR_ACCOUNT_COMMON_NULL_PTR_ERROR,
|
||||
AccountIAMClient::GetInstance().GetCredentialInfo(TEST_USER_ID, AuthType::PIN, nullptr));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClient_GetCredentialInfo_0200
|
||||
* @tc.desc: Test func with proxy is nullptr.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(AccountIAMProxyMockTest, AccountIAMClient_GetCredentialInfo_0200, TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<GetCredCallbackMockTest> testCallbcak = std::make_shared<GetCredCallbackMockTest>();
|
||||
ASSERT_EQ(ERR_ACCOUNT_COMMON_GET_PROXY,
|
||||
AccountIAMClient::GetInstance().GetCredentialInfo(TEST_USER_ID, AuthType::PIN, testCallbcak));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountIAMClient_AuthUser_0100
|
||||
* @tc.desc: Test func with proxy is nullptr.
|
||||
|
@ -267,7 +267,7 @@ void AuthCallback::OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Att
|
||||
|
||||
void IDMCallbackDeathRecipient::OnRemoteDied(const wptr<IRemoteObject> &remote)
|
||||
{
|
||||
ACCOUNT_LOGI("Remote callback died, cancel cred");
|
||||
ACCOUNT_LOGW("Remote callback died, cancel cred");
|
||||
if (userId_ > 0) {
|
||||
UserIDMClient::GetInstance().Cancel(userId_);
|
||||
}
|
||||
@ -315,7 +315,7 @@ void AddCredCallback::OnResult(int32_t result, const Attributes &extraInfo)
|
||||
innerCallback_->AsObject()->RemoveDeathRecipient(deathRecipient_);
|
||||
auto &innerIamMgr = InnerAccountIAMManager::GetInstance();
|
||||
if ((result == 0) && (credInfo_.authType == AuthType::PIN)) {
|
||||
InnerAccountIAMManager::GetInstance().SetState(userId_, AFTER_ADD_CRED);
|
||||
innerIamMgr.SetState(userId_, AFTER_ADD_CRED);
|
||||
uint64_t credentialId = 0;
|
||||
extraInfo.GetUint64Value(Attributes::AttributeKey::ATTR_CREDENTIAL_ID, credentialId);
|
||||
(void)IInnerOsAccountManager::GetInstance().SetOsAccountCredentialId(userId_, credentialId);
|
||||
@ -397,6 +397,7 @@ void UpdateCredCallback::InnerOnResult(int32_t result, const Attributes &extraIn
|
||||
ACCOUNT_LOGE("UpdateCredCallback fail code=%{public}d, authType=%{public}d", result, credInfo_.authType);
|
||||
return innerCallback_->OnResult(result, extraInfo);
|
||||
}
|
||||
innerIamMgr.SetState(userId_, AFTER_OPEN_SESSION);
|
||||
UpdateCredInfo updateCredInfo(extraInfo);
|
||||
if (updateCredInfo.oldSecret.empty()) {
|
||||
ErrCode code = innerIamMgr.UpdateUserAuthWithRecoveryKey(credInfo_.token,
|
||||
@ -575,12 +576,12 @@ void CommitCredUpdateCallback::InnerOnResult(int32_t result, const Attributes &e
|
||||
}
|
||||
Attributes extraInfoResult;
|
||||
extraInfoResult.SetUint64Value(Attributes::AttributeKey::ATTR_CREDENTIAL_ID, extraUpdateInfo_.credentialId);
|
||||
innerIamMgr.SetState(userId_, AFTER_UPDATE_CRED);
|
||||
innerCallback_->OnResult(result, extraInfoResult);
|
||||
ErrCode updateRet = innerIamMgr.UpdateStorageKeyContext(userId_);
|
||||
if (updateRet != ERR_OK) {
|
||||
ReportOsAccountOperationFail(userId_, "commitCredUpdate", updateRet, "Failed to update key context");
|
||||
}
|
||||
innerIamMgr.SetState(userId_, AFTER_OPEN_SESSION);
|
||||
}
|
||||
|
||||
void CommitCredUpdateCallback::OnResult(int32_t result, const Attributes &extraInfo)
|
||||
@ -762,7 +763,8 @@ void GetDomainAuthStatusInfoCallback::OnResult(int32_t result, Parcel &parcel)
|
||||
Attributes attributes;
|
||||
std::shared_ptr<AuthStatusInfo> infoPtr(AuthStatusInfo::Unmarshalling(parcel));
|
||||
if (infoPtr == nullptr) {
|
||||
innerCallback_->OnResult(result, attributes);
|
||||
ACCOUNT_LOGE("Unmarshalling parcel to auth status info failed.");
|
||||
innerCallback_->OnResult(ERR_ACCOUNT_COMMON_READ_PARCEL_ERROR, attributes);
|
||||
return;
|
||||
}
|
||||
attributes.SetInt32Value(Attributes::ATTR_PIN_SUB_TYPE, static_cast<int32_t>(IAMAuthSubType::DOMAIN_MIXED));
|
||||
|
@ -276,6 +276,7 @@ int32_t InnerAccountIAMManager::Cancel(int32_t userId)
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto it = userStateMap_.find(userId);
|
||||
if ((it == userStateMap_.end()) || (it->second >= AFTER_ADD_CRED)) {
|
||||
ACCOUNT_LOGE("Failed to cancel after 'addCredential' success");
|
||||
return ResultCode::GENERAL_ERROR;
|
||||
}
|
||||
return UserIDMClient::GetInstance().Cancel(userId);
|
||||
|
Loading…
Reference in New Issue
Block a user