!2098 账号数据文件被破坏,查询备份数据

Merge pull request !2098 from 周士淼/fix_0912_account_info
This commit is contained in:
openharmony_ci 2024-09-18 08:11:41 +00:00 committed by Gitee
commit adfdb7d7d5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 32 additions and 6 deletions

View File

@ -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;
}

View File

@ -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