mirror of
https://gitee.com/openharmony/account_os_account
synced 2025-02-20 03:51:14 +00:00
!2098 账号数据文件被破坏,查询备份数据
Merge pull request !2098 from 周士淼/fix_0912_account_info
This commit is contained in:
commit
adfdb7d7d5
@ -513,13 +513,12 @@ ErrCode OsAccountControlFileManager::GetOsAccountInfoById(const int id, OsAccoun
|
||||
return ERR_ACCOUNT_COMMON_ACCOUNT_NOT_EXIST_ERROR;
|
||||
}
|
||||
Json osAccountInfoJson = Json::parse(accountInfoStr, nullptr, false);
|
||||
if (osAccountInfoJson.is_discarded()) {
|
||||
ACCOUNT_LOGE("parse os account info json data failed");
|
||||
return ERR_ACCOUNT_COMMON_BAD_JSON_FORMAT_ERROR;
|
||||
}
|
||||
if (!osAccountInfo.FromJson(osAccountInfoJson)) {
|
||||
if (osAccountInfoJson.is_discarded() || !osAccountInfo.FromJson(osAccountInfoJson)) {
|
||||
ACCOUNT_LOGE("parse os account info json for %{public}d failed", id);
|
||||
return ERR_ACCOUNT_COMMON_BAD_JSON_FORMAT_ERROR;
|
||||
if (GetOsAccountFromDatabase("", id, osAccountInfo) != ERR_OK) {
|
||||
ACCOUNT_LOGE("GetOsAccountFromDatabase failed id=%{public}d", id);
|
||||
return ERR_ACCOUNT_COMMON_BAD_JSON_FORMAT_ERROR;
|
||||
}
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ const int32_t INVALID_TYPE = 100000;
|
||||
const gid_t ACCOUNT_GID = 3058;
|
||||
const uid_t ACCOUNT_UID = 3058;
|
||||
const int32_t THREAD_NUM = 10;
|
||||
const int32_t TEST_USER_ID100 = 100;
|
||||
const std::string STRING_PHOTO =
|
||||
"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD//gAUU29mdHdhcmU6IFNuaXBhc3Rl/"
|
||||
"9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/"
|
||||
@ -714,6 +715,32 @@ HWTEST_F(OsAccountControlFileManagerTest, OsAccountControlFileManagerCovTest030,
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: QueryOsAccountInfo001
|
||||
* @tc.desc: Test QueryOsAccountInfo001
|
||||
* @tc.type: FUNC
|
||||
* @tc.require:
|
||||
*/
|
||||
HWTEST_F(OsAccountControlFileManagerTest, QueryOsAccountInfo001, TestSize.Level1)
|
||||
{
|
||||
g_controlManager->eventCallbackFunc_ = nullptr;
|
||||
OsAccountInfo accountInfo;
|
||||
EXPECT_EQ(ERR_OK, g_controlManager->GetOsAccountInfoById(TEST_USER_ID100, accountInfo));
|
||||
std::shared_ptr<AccountFileOperator> accountFileOperator = std::make_shared<AccountFileOperator>();
|
||||
std::string path = Constants::USER_INFO_BASE + Constants::PATH_SEPARATOR + std::to_string(TEST_USER_ID100) +
|
||||
Constants::PATH_SEPARATOR + Constants::USER_INFO_FILE_NAME;
|
||||
std::string accountInfoStr = "123";
|
||||
EXPECT_EQ(ERR_OK, accountFileOperator->InputFileByPathAndContent(path, accountInfoStr));
|
||||
std::string content;
|
||||
EXPECT_EQ(ERR_OK, accountFileOperator->GetFileContentByPath(path, content));
|
||||
EXPECT_EQ(accountInfoStr, content);
|
||||
OsAccountInfo accountInfo1;
|
||||
EXPECT_EQ(ERR_OK, g_controlManager->GetOsAccountInfoById(TEST_USER_ID100, accountInfo1));
|
||||
EXPECT_EQ(accountInfo1.GetLocalId(), accountInfo.GetLocalId());
|
||||
EXPECT_EQ(accountInfo1.GetLocalName(), accountInfo.GetLocalName());
|
||||
EXPECT_EQ(accountInfo1.GetSerialNumber(), accountInfo.GetSerialNumber());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetSerialNumberM
|
||||
* @tc.desc: Test GetSerialNumber Multithreading
|
||||
|
Loading…
x
Reference in New Issue
Block a user