diff --git a/frameworks/native/backup_ext/include/ext_extension.h b/frameworks/native/backup_ext/include/ext_extension.h index 51a12dd34cce5193dbf7bf023932187328dc64fa..0d9164788e849429a31ee8785645bf789e0bab75 100644 --- a/frameworks/native/backup_ext/include/ext_extension.h +++ b/frameworks/native/backup_ext/include/ext_extension.h @@ -336,7 +336,7 @@ private: void RestoreBigFiles(bool appendTargetPath); void FillEndFileInfos(const std::string &path, const unordered_map &result); void RestoreBigFileAfter(const string &filePath, const struct stat &sta); - int DealIncreUnPacketResult(const off_t tarFileSize, const std::string &tarFileName, + void DealIncreUnPacketResult(const off_t tarFileSize, const std::string &tarFileName, const std::tuple &result); ErrCode StartOnProcessTaskThread(wptr obj, BackupRestoreScenario scenario); diff --git a/frameworks/native/backup_ext/include/untar_file.h b/frameworks/native/backup_ext/include/untar_file.h index 49eb36e2620430df21d52040d89a495a2f609554..ed05bae6c95332a0e2658526a456055220415656 100644 --- a/frameworks/native/backup_ext/include/untar_file.h +++ b/frameworks/native/backup_ext/include/untar_file.h @@ -18,7 +18,6 @@ #include "tar_file.h" #include "b_json/b_report_entity.h" -#include "b_filesystem/b_dir.h" namespace OHOS::FileManagement::Backup { struct FileStatInfo { @@ -31,6 +30,7 @@ struct FileStatInfo { }; using ErrFileInfo = std::map>; +using EndFileInfo = std::map; const int FIRST_PARAM = 0; const int SECOND_PARAM = 1; diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 7845876e7d1ed8e735cd044b785732670283b9ee..f931cbb4415f7627f1ee201b572ebf52883baf3c 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -854,7 +854,7 @@ tuple BackupExtExtension::CalculateDataSize(const B // 扫描文件计算数据量 tie(bigFileInfo, smallFiles) = GetFileInfos(includes, excludes); - ScanFileSingleton::GetInstance().SetCompeletedFlag(true); + ScanFileSingleton::GetInstance().SetCompletedFlag(true); appStatistic_->smallFileCount_ = smallFiles.size(); appStatistic_->bigFileCount_ = bigFileInfo.size(); for (const auto &item : bigFileInfo) { @@ -924,10 +924,6 @@ int BackupExtExtension::DoRestore(const string &fileName, const off_t fileSize) endFileInfos_.merge(fileInfos); errFileInfos_.merge(errInfos); } - if (BDir::CheckAndRmSoftLink(tarName) || BDir::CheckAndRmSoftLink(fileInfos)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } if (ret != 0) { HILOGE("Failed to untar file = %{public}s, err = %{public}d", tarName.c_str(), ret); return ret; @@ -955,25 +951,23 @@ void BackupExtExtension::GetTarIncludes(const string &tarName, unordered_map &result) { + if (!isDebug_) { + return; + } int err = std::get(result); - EndFileInfo tmpEndInfo = std::get(result); if (!isRpValid_) { if (err != ERR_OK) { endFileInfos_[tarFileName] = tarFileSize; errFileInfos_[tarFileName] = {err}; } + EndFileInfo tmpEndInfo = std::get(result); endFileInfos_.merge(tmpEndInfo); } - if (BDir::CheckAndRmSoftLink(tmpEndInfo)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } ErrFileInfo tmpErrInfo = std::get(result); errFileInfos_.merge(tmpErrInfo); - return ERR_OK; } int BackupExtExtension::DoIncrementalRestore() @@ -1001,9 +995,9 @@ int BackupExtExtension::DoIncrementalRestore() string tarName = path + item; // 当用户指定fullBackupOnly字段或指定版本的恢复,解压目录当前在/backup/restore - if (!BDir::IsFilePathValid(tarName) || BDir::CheckAndRmSoftLink(tarName)) { + if (!BDir::IsFilePathValid(tarName)) { HILOGE("Check incre tarfile path : %{public}s err, path is forbidden", GetAnonyPath(tarName).c_str()); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); + return ERR_INVALID_VALUE; } unordered_map result; GetTarIncludes(tarName, result); @@ -1016,9 +1010,7 @@ int BackupExtExtension::DoIncrementalRestore() std::tuple unPacketRes = UntarFile::GetInstance().IncrementalUnPacket(tarName, path, result); err = std::get(unPacketRes); - if (int tmpErr = DealIncreUnPacketResult(tarFileSize, item, unPacketRes); tmpErr != ERR_OK) { - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } + DealIncreUnPacketResult(tarFileSize, item, unPacketRes); HILOGI("Application recovered successfully, package path is %{public}s", tarName.c_str()); DeleteBackupIncrementalTars(tarName); } @@ -1039,11 +1031,11 @@ void BackupExtExtension::AsyncTaskBackup(const string config) ptr->CalculateDataSizeTask(config); } catch (const BError &e) { HILOGE("extension: AsyncTaskBackup error, err code:%{public}d", e.GetCode()); - ScanFileSingleton::GetInstance().SetCompeletedFlag(true); + ScanFileSingleton::GetInstance().SetCompletedFlag(true); ptr->AppDone(e.GetCode()); } catch (...) { HILOGE("Failed to restore the ext bundle"); - ScanFileSingleton::GetInstance().SetCompeletedFlag(true); + ScanFileSingleton::GetInstance().SetCompletedFlag(true); ptr->AppDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); } }; @@ -1066,11 +1058,11 @@ void BackupExtExtension::AsyncTaskBackup(const string config) ptr->DoBackUpTask(config); } catch (const BError &e) { HILOGE("extension: AsyncTaskBackup error, err code:%{public}d", e.GetCode()); - ScanFileSingleton::GetInstance().SetCompeletedFlag(false); + ScanFileSingleton::GetInstance().SetCompletedFlag(false); ptr->AppDone(e.GetCode()); } catch (...) { HILOGE("Failed to restore the ext bundle"); - ScanFileSingleton::GetInstance().SetCompeletedFlag(false); + ScanFileSingleton::GetInstance().SetCompletedFlag(false); ptr->AppDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); } ptr->DoClear(); @@ -1096,13 +1088,6 @@ void BackupExtExtension::RestoreBigFilesForSpecialCloneCloud(const ExtManageInfo if (!BDir::IsFilePathValid(fileName)) { HILOGE("Check big special file path : %{public}s err, path is forbidden", GetAnonyPath(fileName).c_str()); errFileInfos_[fileName].emplace_back(DEFAULT_INVAL_VALUE); - if (!RemoveFile(fileName)) { - HILOGE("Failed to delete the backup bigFile %{public}s", GetAnonyPath(fileName).c_str()); - } - return; - } - if (BDir::CheckAndRmSoftLink(fileName)) { - HILOGE("File soft links are forbidden"); return; } if (chmod(fileName.c_str(), sta.st_mode) != 0) { @@ -1141,10 +1126,6 @@ ErrCode BackupExtExtension::RestoreTarForSpecialCloneCloud(const ExtManageInfo & HILOGE("Check spec tarfile hash path : %{public}s err, path is forbidden", GetAnonyPath(tarName).c_str()); return ERR_INVALID_VALUE; } - if (BDir::CheckAndRmSoftLink(tarName)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } if (!BDir::IsFilePathValid(untarPath)) { HILOGE("Check spec tarfile path : %{public}s err, path is forbidden", GetAnonyPath(untarPath).c_str()); return ERR_INVALID_VALUE; @@ -1155,18 +1136,18 @@ ErrCode BackupExtExtension::RestoreTarForSpecialCloneCloud(const ExtManageInfo & } auto [err, fileInfos, errInfos] = UntarFile::GetInstance().UnPacket(tarName, untarPath); if (isDebug_) { + if (err != 0) { + endFileInfos_[tarName] = item.sta.st_size; + errFileInfos_[tarName] = { err }; + } endFileInfos_.merge(fileInfos); errFileInfos_.merge(errInfos); } - if (BDir::CheckAndRmSoftLink(fileInfos)) { - HILOGE("File soft links are forbidden"); - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } - DeleteBackupIncrementalTars(tarName); if (err != ERR_OK) { HILOGE("Failed to untar file = %{public}s, err = %{public}d", tarName.c_str(), err); return err; } + DeleteBackupIncrementalTars(tarName); return ERR_OK; } @@ -1380,10 +1361,6 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, HILOGE("Check big file path : %{public}s err, path is forbidden", GetAnonyPath(filePath).c_str()); return; } - if (BDir::CheckAndRmSoftLink(fileName)) { - HILOGE("File soft links are forbidden"); - return; - } if (isDebug_) { endFileInfos_[filePath] = item.sta.st_size; } @@ -1396,10 +1373,7 @@ void BackupExtExtension::RestoreOneBigFile(const std::string &path, HILOGE("failed to move the file. err = %{public}d", errno); return; } - if (BDir::CheckAndRmSoftLink(filePath)) { - HILOGE("File soft links are forbidden"); - return; - } + RestoreBigFileAfter(filePath, item.sta); } diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index ff18af6c142571addffc07de9c9c57b781d0042e..59203d07e43ed5d295f6f075e57352750c8cc625 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -152,7 +152,7 @@ void BackupExtExtension::SetClearDataFlag(bool isClearData) string BackupExtExtension::GetBundlePath() { - if (BFile::EndsWith(bundleName_, BConstants::BUNDLE_FILE_MANAGER) && bundleName_.size() == BConstants::FM_LEN) { + if (bundleName_ == BConstants::BUNDLE_FILE_MANAGER) { return string(BConstants::PATH_FILEMANAGE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); } else if (bundleName_ == BConstants::BUNDLE_MEDIAL_DATA) { return string(BConstants::PATH_MEDIALDATA_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_RESTORE); @@ -1516,9 +1516,7 @@ ErrCode BackupExtExtension::CloudSpecialRestore(string tarName, string untarPath auto unPacketRes = UntarFile::GetInstance().IncrementalUnPacket(tarName, untarPath, result); ErrCode err = ERR_OK; err = std::get(unPacketRes); - if (int tmpErr = DealIncreUnPacketResult(tarFileSize, tarName, unPacketRes); tmpErr != ERR_OK) { - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE).GetCode(); - } + DealIncreUnPacketResult(tarFileSize, tarName, unPacketRes); HILOGI("Application recovered successfully, package path is %{public}s", tarName.c_str()); DeleteBackupIncrementalTars(tarName); return err; @@ -1592,7 +1590,7 @@ void BackupExtExtension::DoBackUpTask(const string &config) int ret = 0; TarMap fileBackupedInfo; - while (!ScanFileSingleton::GetInstance().GetCompeletedFlag()) { + while (!ScanFileSingleton::GetInstance().GetCompletedFlag()) { ScanFileSingleton::GetInstance().WaitForFiles(); std::map incFiles = ScanFileSingleton::GetInstance().GetAllBigFiles(); if (incFiles.empty()) { @@ -1615,7 +1613,7 @@ void BackupExtExtension::DoBackUpTask(const string &config) ret = DoBackup(bigFileInfo, fileBackupedInfo, smallFiles, includeSize, excludeSize); DoBackupEnd(); - ScanFileSingleton::GetInstance().SetCompeletedFlag(false); + ScanFileSingleton::GetInstance().SetCompletedFlag(false); AppDone(ret); HILOGI("backup app done %{public}d", ret); } diff --git a/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp b/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp index 019f6a59836752ffe9124150d4be6d4455186495..21449436cde1752f6393ca653426b85c1bdb58f3 100644 --- a/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp +++ b/interfaces/kits/ndk/fileshare/src/oh_file_share.cpp @@ -94,7 +94,7 @@ static bool ConvertPolicyErrorResult(const std::deque &remote) .activeTime = TimeUtils::GetCurrentTime(), }); if (ret == ERR_OK) { + HILOGE("Success to init a new restore session"); ClearFailedBundles(); successBundlesNum_ = 0; ClearBundleRadarReport(); @@ -523,6 +524,7 @@ ErrCode Service::InitBackupSession(const sptr &remote) .activeTime = TimeUtils::GetCurrentTime(), }); if (ret == ERR_OK) { + HILOGE("Success to init a new backup session"); ClearFailedBundles(); successBundlesNum_ = 0; ClearBundleRadarReport(); @@ -977,7 +979,6 @@ ErrCode Service::ServiceResultReport(const std::string& restoreRetInfo, BackupRe { string callerName; HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - UpdateHandleCnt(errCode); try { ErrCode ret = VerifyCallerAndGetCallerName(callerName); if (ret != ERR_OK) { diff --git a/services/backup_sa/src/module_ipc/service_incremental.cpp b/services/backup_sa/src/module_ipc/service_incremental.cpp index 60a1838e32c8f0e3a2319a69db5ac3dee24f0f7c..1b478b1030ed8bdf91951a0255e324994def8597 100644 --- a/services/backup_sa/src/module_ipc/service_incremental.cpp +++ b/services/backup_sa/src/module_ipc/service_incremental.cpp @@ -340,6 +340,7 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot .callerName = GetCallerName(), .activeTime = TimeUtils::GetCurrentTime()}); if (errCode == ERR_OK) { + HILOGE("Success to init a new incremental backup session"); ClearFailedBundles(); successBundlesNum_ = 0; ClearBundleRadarReport(); @@ -348,10 +349,10 @@ ErrCode Service::InitIncrementalBackupSession(const sptr& remot } totalStatistic_->Report("InitIncrementalBackupSession", MODULE_INIT, errCode); if (errCode == BError(BError::Codes::SA_SESSION_CONFLICT)) { - HILOGE("Active restore session error, Already have a session"); + HILOGE("Active incremental backup error, Already have a session"); return errCode; } - HILOGE("Active restore session error"); + HILOGE("Active backup session error"); StopAll(nullptr, true); return errCode; } @@ -759,6 +760,7 @@ ErrCode Service::GetIncrementalFileHandle(const std::string &bundleName, const s { HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); try { + HILOGI("Begin get incrementalFileHandle"); if (session_ == nullptr) { HILOGE("GetIncrementalFileHandle error, session is empty"); return BError(BError::Codes::SA_INVAL_ARG); diff --git a/services/backup_sa/src/module_ipc/sub_service.cpp b/services/backup_sa/src/module_ipc/sub_service.cpp index ddc2bd0d3c823de275d6917f1c19559c21a6f8ea..a71006c6ede85910f370dbc162a76b5eb493a45d 100644 --- a/services/backup_sa/src/module_ipc/sub_service.cpp +++ b/services/backup_sa/src/module_ipc/sub_service.cpp @@ -879,6 +879,29 @@ ErrCode Service::HandleCurAppDone(ErrCode errCode, const std::string &bundleName return BError(BError::Codes::OK); } +void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) +{ + if (session_ == nullptr) { + HILOGE("Session is empty, bundleName:%{public}s", bundleName.c_str()); + return; + } + HILOGI("Begin"); + try { + if (scenario == BackupRestoreScenario::FULL_RESTORE) { + session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::INCREMENTAL_RESTORE) { + session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::FULL_BACKUP) { + session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); + } else if (scenario == BackupRestoreScenario::INCREMENTAL_BACKUP) { + session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); + } + } catch (const BError &e) { + HILOGE("Call onBundleFinished error, client is died"); + return; + } +} + std::string Service::GetCallerName() { std::string callerName; @@ -1065,29 +1088,6 @@ UniqueFd Service::GetLocalCapabilitiesForBundleInfos() } } -void Service::CallOnBundleEndByScenario(const std::string &bundleName, BackupRestoreScenario scenario, ErrCode errCode) -{ - if (session_ == nullptr) { - HILOGE("Session is empty, bundleName:%{public}s", bundleName.c_str()); - return; - } - HILOGI("Begin"); - try { - if (scenario == BackupRestoreScenario::FULL_RESTORE) { - session_->GetServiceReverseProxy()->RestoreOnBundleFinished(errCode, bundleName); - } else if (scenario == BackupRestoreScenario::INCREMENTAL_RESTORE) { - session_->GetServiceReverseProxy()->IncrementalRestoreOnBundleFinished(errCode, bundleName); - } else if (scenario == BackupRestoreScenario::FULL_BACKUP) { - session_->GetServiceReverseProxy()->BackupOnBundleFinished(errCode, bundleName); - } else if (scenario == BackupRestoreScenario::INCREMENTAL_BACKUP) { - session_->GetServiceReverseProxy()->IncrementalBackupOnBundleFinished(errCode, bundleName); - } - } catch (const BError &e) { - HILOGE("Call onBundleFinished error, client is died"); - return; - } -} - ErrCode Service::GetBackupDataSize(bool isPreciseScan, const std::vector& bundleNameList) { try { diff --git a/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp b/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp index 681821422a931a1284b55c0688bdaff703c59347..10932eb329b039ae4f6395bcece62558ec9bf7c2 100644 --- a/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp +++ b/services/backup_sa/src/module_ipc/svc_restore_deps_manager.cpp @@ -33,7 +33,7 @@ vector SvcRestoreDepsManager::GetRestoreBundleNames(const vector, int32_t)); MOCK_METHOD((std::function &argv)>), ParseReleaseInfo, ()); - MOCK_METHOD(ErrCode, GetBackupCompatibilityInfo, (std::function, std::string)); - MOCK_METHOD(ErrCode, GetRestoreCompatibilityInfo, (std::function, std::string)); - MOCK_METHOD((std::function &argv)>), ParseCompatibilityInfo, ()); public: MOCK_METHOD(bool, GetProfileFromAbility, (const OHOS::AppExecFwk::AbilityInfo&, const std::string&, std::vector&), (const)); diff --git a/tests/mock/module_ipc/service_mock.cpp b/tests/mock/module_ipc/service_mock.cpp index c07e583048a30feabc67ffe8c8e05800c48c249c..735762b1801a06d38beb540225e0ea7946de1b8d 100644 --- a/tests/mock/module_ipc/service_mock.cpp +++ b/tests/mock/module_ipc/service_mock.cpp @@ -387,14 +387,14 @@ void Service::CreateDirIfNotExist(const std::string &path) { } -void Service::StartRunningTimer(const std::string &bundleName) {} - std::vector Service::GetSupportBackupBundleNames(vector&, bool, const vector&) { return {}; } +void Service::StartRunningTimer(const std::string &bundleName) {} + void Service::HandleNotSupportBundleNames(const vector&, vector&, bool) {} void Service::SetBundleIncDataInfo(const std::vector&, std::vector&) {} diff --git a/tests/unittests/backup_sa/BUILD.gn b/tests/unittests/backup_sa/BUILD.gn index b552944b36440350ab9912752b5be12b0964ecbd..5351c84bdbf85a42b387bef2ee72b856a1145dc2 100644 --- a/tests/unittests/backup_sa/BUILD.gn +++ b/tests/unittests/backup_sa/BUILD.gn @@ -19,7 +19,6 @@ group("backup_sa_test") { deps = [ "module_app_gallery:app_gallery_test", - "module_client:service_client_test", "module_external:adapter_test", "module_ipc:backup_sa_ipc_test", "session:session_test", diff --git a/tests/unittests/backup_sa/module_client/BUILD.gn b/tests/unittests/backup_sa/module_client/BUILD.gn deleted file mode 100644 index 47a26fff8f5029cd1fb742034138dd9d5d05b161..0000000000000000000000000000000000000000 --- a/tests/unittests/backup_sa/module_client/BUILD.gn +++ /dev/null @@ -1,86 +0,0 @@ -# Copyright (c) 2024 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/test.gni") -import("//foundation/filemanagement/app_file_service/app_file_service.gni") -import("//foundation/filemanagement/app_file_service/backup.gni") - -ohos_unittest("service_client_test") { - module_out_path = path_module_out_tests - - include_dirs = [ - "${path_backup}/frameworks/native/backup_kit_inner/include", - "${path_backup}/interfaces/inner_api/native/backup_kit_inner/impl", - "${path_backup}/services/backup_sa/include", - "${path_backup}/services/backup_sa/include/module_notify", - "${path_backup}/utils/include", - "${path_backup}/utils/src", - "${path_backup}/tests/mock/utils_mock/include", - ".", - ] - - sources = [ - "${path_backup}/tests/mock/utils_mock/src/utils_mock_global_variable.cpp", - "service_client_test.cpp", - ] - - deps = [ - "${path_backup}/interfaces/inner_api/native/backup_kit_inner:backup_kit_inner", - "${path_backup}/services/backup_sa:backup_sa_ipc_stub", - "${path_backup}/utils:backup_utils", - ] - - sanitize = { - integer_overflow = true - ubsan = true - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - } - - defines = [ - "LOG_TAG=\"app_file_service\"", - "LOG_DOMAIN=0xD200000", - "private = public", - "protected = public", - ] - - external_deps = [ - "ability_base:want", - "ability_runtime:ability_connect_callback_stub", - "ability_runtime:ability_manager", - "access_token:libaccesstoken_sdk", - "access_token:libtokenid_sdk", - "bundle_framework:appexecfwk_base", - "bundle_framework:appexecfwk_core", - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "googletest:gmock_main", - "googletest:gtest_main", - "hilog:libhilog", - "hitrace:hitrace_meter", - "ipc:ipc_core", - "jsoncpp:jsoncpp", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "storage_service:storage_manager_sa_proxy", - ] - - use_exceptions = true -} - -group("backup_sa_service_client_test") { - testonly = true - deps = [ ":service_client_test" ] -} diff --git a/tests/unittests/backup_sa/module_client/service_client_test.cpp b/tests/unittests/backup_sa/module_client/service_client_test.cpp deleted file mode 100644 index ce840db00e8ad26ba98074819f0ee2fd37ff1033..0000000000000000000000000000000000000000 --- a/tests/unittests/backup_sa/module_client/service_client_test.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/* - * Copyright (c) 2022-2024 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 -#include - -#include "b_error/b_error.h" -#include "service_client.h" -#include "service_reverse.h" -#include "b_session_restore.h" - -namespace OHOS::FileManagement::Backup { -using namespace std; -using namespace testing; - -class ServiceClientTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(); - void SetUp() override {}; - void TearDown() override {}; - -public: - static inline sptr proxy = nullptr; -}; - -void ServiceClientTest::SetUpTestCase() -{ - GTEST_LOG_(INFO) << "begin SetUpTestCase"; - proxy = ServiceClient::GetInstance(); - if (proxy == nullptr) { - GTEST_LOG_(INFO) << "Failed to get ServiceClient instance"; - } -} - -void ServiceClientTest::TearDownTestCase() -{ - if (proxy != nullptr) { - ServiceClient::InvaildInstance(); - proxy = nullptr; - } - ServiceClient::InvaildInstance(); -} - -/** - * @tc.number: SUB_service_client_test_0100 - * @tc.name: SUB_service_client_test_0100 - * @tc.desc: 测试 InitIncrementalBackupSession 接口 - * @tc.size: MEDIUM - * @tc.type: FUNC - * @tc.level Level 1 - * @tc.require: issuesI9KPRL - */ -HWTEST_F(ServiceClientTest, SUB_service_client_test_0100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0100"; - EXPECT_NE(proxy, nullptr); - ServiceClient::InvaildInstance(); - proxy=ServiceClient::serviceProxy_; - EXPECT_EQ(proxy, nullptr); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0100"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0200"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - ErrCode ret = proxy->Start(); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); - ret = proxy->Finish(); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_PERM)); - ret = proxy->Release(); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_PERM)); - ret = proxy->GetAppLocalListAndDoIncrementalBackup(); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0200"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0300"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - int32_t result = -1; - bundleName = "test"; - proxy->CancelForResult(bundleName, result); - EXPECT_EQ(result, 0); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0300"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0400, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0400"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - ErrCode err = -1; - ErrCode ret = proxy->AppIncrementalDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 0; - ret = proxy->AppIncrementalDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 1; - ret = proxy->AppIncrementalDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0400"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0500, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0500"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - ErrCode err = -1; - ErrCode ret = proxy->AppDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 0; - ret = proxy->AppDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - err = 1; - ret = proxy->AppDone(err); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0500"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0600, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0600"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - int fd = -1; - ErrCode ret = proxy->GetLocalCapabilities(fd); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - fd = -2; - ret = proxy->GetLocalCapabilitiesForBundleInfos(fd); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0600"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0700, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0700"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - std::string fileName; - ErrCode ret = proxy->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = ""; - fileName = ""; - ret = proxy->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = "test"; - fileName = "test"; - ret = proxy->GetIncrementalFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0700"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0800, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0800"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - std::string fileName; - bool booleanValue = false; - ErrCode ret = proxy->GetBackupInfo(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_BEF)); - EXPECT_EQ(bundleName, ""); - EXPECT_EQ(fileName, ""); - booleanValue = true; - ret = proxy->StartExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = false; - ret = proxy->StartExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = true; - ret = proxy->StartFwkTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = false; - ret = proxy->StartFwkTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = true; - ret = proxy->StopExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - booleanValue = false; - ret = proxy->StopExtTimer(booleanValue); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bool isExt = true; - bundleName = ""; - ret = proxy->UpdateTimer(bundleName, 0, isExt); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_EQ(isExt, false); - bundleName = "test"; - ret = proxy->UpdateTimer(bundleName, 10, isExt); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(isExt, false); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0800"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_0900, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_0900"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string stringVal = ""; - ErrCode ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = ""; - ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = "test"; - ret = proxy->ReportAppProcessInfo(stringVal, BackupRestoreScenario::FULL_BACKUP); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - int64_t val = -1; - ret = proxy->RefreshDataSize(val); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - val = 1; - ret = proxy->RefreshDataSize(val); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = ""; - ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - stringVal = ""; - ret = proxy->ServiceResultReport(stringVal, BackupRestoreScenario::FULL_BACKUP, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_0900"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1000, testing::ext::TestSize.Level1) -{ - std::string bundleName = ""; - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1000"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - BFileInfo *fileInfo = nullptr; - BFileInfo bf {bundleName, "", 0}; - fileInfo = &bf; - ErrCode ret = proxy->PublishFile(*fileInfo); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->PublishIncrementalFile(*fileInfo); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->PublishSAIncrementalFile(*fileInfo, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1000"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1100, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1100"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - int fd = 0; - int32_t restoreType = -1; - int32_t userid = -1; - std::vector bundleNames; - std::vector detailInfos; - std::vector bundlesToBackup; - ErrCode ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleNames.push_back("test"); - ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesBackupSession(bundleNames); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - detailInfos.push_back("test"); - ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - ret = proxy->AppendBundlesDetailsBackupSession(bundleNames, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - restoreType = 1; - userid = 1; - ret = proxy->AppendBundlesRestoreSessionDataByDetail(fd, bundleNames, detailInfos, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesRestoreSessionData(fd, bundleNames, restoreType, userid); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppendBundlesIncrementalBackupSessionWithBundleInfos(bundlesToBackup, detailInfos); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1100"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1200, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1200"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - sptr srptr = nullptr; - ErrCode ret = proxy->InitRestoreSession(srptr); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->InitBackupSession(srptr); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->InitIncrementalBackupSession(srptr); - EXPECT_NE(ret, BError(BError::Codes::OK)); - std::string errMsg = ""; - std::string result = "err"; - proxy->InitRestoreSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_NE(ret, BError(BError::Codes::OK)); - proxy->InitBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_NE(ret, BError(BError::Codes::OK)); - proxy->InitIncrementalBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_NE(ret, BError(BError::Codes::OK)); - BSessionRestore::Callbacks callback; - srptr = sptr(new ServiceReverse(callback)); - ret = proxy->InitRestoreSession(srptr); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - ret = proxy->InitBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - ret = proxy->InitIncrementalBackupSession(srptr); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - - proxy->InitRestoreSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - EXPECT_NE(errMsg, ""); - proxy->InitBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - EXPECT_NE(errMsg, ""); - proxy->InitIncrementalBackupSessionWithErrMsg(srptr, ret, errMsg); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_CONFLICT)); - EXPECT_NE(errMsg, ""); - - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1200"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1300, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1300"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1300"; -} - -HWTEST_F(ServiceClientTest, SUB_service_client_test_1400, testing::ext::TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ServiceClientTest-begin SUB_service_client_test_1400"; - proxy = ServiceClient::GetInstance(); - EXPECT_NE(proxy, nullptr); - std::string bundleName; - std::string fileName; - bool isExt = true; - bundleName = ""; - ErrCode ret = proxy->UpdateSendRate(bundleName, 0, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_TRUE(isExt); - bundleName = "test"; - ret = proxy->UpdateSendRate(bundleName, 10, isExt); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - EXPECT_TRUE(isExt); - bundleName = ""; - ret = proxy->AppIncrementalFileReady(bundleName, 0, 0, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - bundleName = "test"; - ret = proxy->AppIncrementalFileReady(bundleName, 1, 1, 0); - EXPECT_EQ(ret, BError(BError::BackupErrorCode::E_INVAL)); - fileName = ""; - ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - fileName = "name"; - ret = proxy->AppFileReady(fileName, -1, 0); - EXPECT_NE(ret, BError(BError::Codes::OK)); - ret = proxy->AppFileReady(fileName, 0, 0); - EXPECT_NE(ret, BError(BError::BackupErrorCode::E_INVAL)); - bundleName = ""; - fileName = ""; - ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(fileName, ""); - bundleName = "test"; - ret = proxy->GetFileHandle(bundleName, fileName); - EXPECT_EQ(ret, BError(BError::Codes::OK)); - EXPECT_EQ(fileName, ""); - GTEST_LOG_(INFO) << "ServiceClientTest-end SUB_service_client_test_1400"; -} -} // namespace OHOS::FileManagement::Backup \ No newline at end of file diff --git a/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp b/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp index a8967a8288f8c50dfa7c5e55337c27592fe6246e..58d25582d013d42a063cbcef9d43bf878ebad64e 100644 --- a/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp +++ b/tests/unittests/backup_sa/module_external/bms_adapter_test.cpp @@ -69,7 +69,6 @@ public: MOCK_METHOD(int32_t, GetExtensionRunningSaList, (const std::string&, (std::vector>&))); MOCK_METHOD(int32_t, GetRunningSaExtensionInfoList, (const std::string&, (std::vector&))); MOCK_METHOD(int32_t, GetCommonEventExtraDataIdlist, (int32_t, (std::vector&), const std::string&)); - MOCK_METHOD((sptr), GetLocalAbilityManagerProxy, (int32_t)); }; class BundleMgrMock : public IRemoteStub { diff --git a/tests/unittests/backup_sa/module_ipc/BUILD.gn b/tests/unittests/backup_sa/module_ipc/BUILD.gn index bc4f9bd3b888396aa30fa2649f28e65a814a50a0..afeed10d2e03e78cdba5639348a204c6762bd5fa 100644 --- a/tests/unittests/backup_sa/module_ipc/BUILD.gn +++ b/tests/unittests/backup_sa/module_ipc/BUILD.gn @@ -61,6 +61,7 @@ ohos_unittest("module_ipc_test") { ] sanitize = { + integer_overflow = true cfi = true cfi_cross_dso = true debug = false @@ -139,6 +140,7 @@ ohos_unittest("backup_service_test") { ] sanitize = { + integer_overflow = true cfi = true cfi_cross_dso = true debug = false @@ -348,6 +350,7 @@ ohos_unittest("backup_service_scheduler_test") { ] sanitize = { + integer_overflow = true cfi = true cfi_cross_dso = true debug = false diff --git a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp index c9936728158ce3a5f1c4ec296c71166a6c736afb..a1253d5ea7e912a6cc45e3b7a628dab9b7033812 100644 --- a/tests/unittests/backup_sa/module_ipc/service_other_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_other_test.cpp @@ -1244,7 +1244,7 @@ HWTEST_F(ServiceTest, SUB_Service_PublishFile_0100, TestSize.Level1) EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_SHELL)); - EXPECT_CALL(*skeleton, GetCallingUid()).WillOnce(Return(BConstants::SYSTEM_UID)); + EXPECT_CALL(*skeleton, GetCallingUid()).WillRepeatedly(Return(BConstants::SYSTEM_UID)); EXPECT_CALL(*session, GetExtConnection(_)).WillOnce(Return(connect)); EXPECT_CALL(*connect, GetBackupExtProxy()).WillOnce(Return(svcProxy)); EXPECT_CALL(*svcProxy, PublishFile(_)).WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); @@ -1317,6 +1317,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppDone_0200, TestSize.Level1) auto ret = service->AppDone(errCode); EXPECT_EQ(ret, BError(BError::Codes::OK)); + EXPECT_CALL(*skeleton, GetCallingTokenID()).WillOnce(Return(0)); EXPECT_CALL(*token, GetTokenType(_)).WillOnce(Return(Security::AccessToken::ATokenTypeEnum::TOKEN_HAP)); EXPECT_CALL(*token, GetHapTokenInfo(_, _)).WillOnce(Return(0)); @@ -1547,7 +1548,7 @@ HWTEST_F(ServiceTest, SUB_Service_AppendBundlesClearSession_0000, TestSize.Level info.name = "bundleNames"; info.appIndex = 0; bundleInfos.push_back(info); - EXPECT_CALL(*session, GetSessionUserId()).WillOnce(Return(0)); + EXPECT_CALL(*session, GetSessionUserId()).WillRepeatedly(Return(0)); EXPECT_CALL(*bms, GetBundleInfos(_, _)).WillOnce(Return(bundleInfos)); EXPECT_CALL(*session, IsOnOnStartSched()).WillOnce(Return(false)); EXPECT_CALL(*jsonUtil, BuildBundleNameIndexInfo(_, _)).WillOnce(Return("bundleName")) diff --git a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp index db4f1931e95b169b41a632cf1cca63f39072cee3..160351ddf3cb665c21004480bc5649b2ee2c605d 100644 --- a/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_stub_test.cpp @@ -56,10 +56,8 @@ public: MOCK_METHOD3(ServiceResultReport, ErrCode(const string restoreRetInfo, BackupRestoreScenario scenario, ErrCode errCode)); MOCK_METHOD2(GetFileHandle, ErrCode(const string &bundleName, const string &fileName)); - MOCK_METHOD5( - AppendBundlesRestoreSession, - ErrCode(UniqueFd fd, const std::vector &bundleNames, const std::vector &detailInfos, - RestoreTypeEnum restoreType, int32_t userId)); + MOCK_METHOD5(AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, + const std::vector &detailInfos, RestoreTypeEnum restoreType, int32_t userId)); MOCK_METHOD4( AppendBundlesRestoreSession, ErrCode(UniqueFd fd, const std::vector &bundleNames, RestoreTypeEnum restoreType, int32_t userId)); diff --git a/tests/unittests/backup_sa/module_ipc/service_test.cpp b/tests/unittests/backup_sa/module_ipc/service_test.cpp index d47502656b17d255318dd7e9011fa2de2a9ebb81..f51d1fc6fb944ee434c18c6308f46d8a249f8af2 100644 --- a/tests/unittests/backup_sa/module_ipc/service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/service_test.cpp @@ -888,8 +888,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtStart_0101, testing::ext::TestSize.Level1) BackupExtInfo extInfo {}; auto callDied = [](const string &&bundleName, bool isCleanCalled) {}; auto callConnected = [](const string &&bundleName) {}; - string bundleNameIndexInfo = "123456789"; - extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); + extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, BUNDLE_NAME)); extInfo.backUpConnection->backupProxy_ = nullptr; impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; impl_.scenario = IServiceReverseType::Scenario::UNDEFINED; @@ -2051,8 +2050,7 @@ HWTEST_F(ServiceTest, SUB_Service_ExtConnectDied_0100, testing::ext::TestSize.Le BackupExtInfo extInfo {}; auto callDied = [](const string &&bundleName, bool isCleanCalled) {}; auto callConnected = [](const string &&bundleName) {}; - string bundleNameIndexInfo = "123456789"; - extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, bundleNameIndexInfo)); + extInfo.backUpConnection = sptr(new SvcBackupConnection(callDied, callConnected, BUNDLE_NAME)); impl_.backupExtNameMap[BUNDLE_NAME] = extInfo; impl_.scenario = IServiceReverseType::Scenario::RESTORE; EXPECT_TRUE(servicePtr_ != nullptr); diff --git a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp index cb6051d3f77de94608254f1efafa2079e9fedc96..3a3888e5925f4bb46f764c20d3b10d6b3a36a28e 100644 --- a/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp +++ b/tests/unittests/backup_sa/module_ipc/sub_service_test.cpp @@ -2306,12 +2306,12 @@ HWTEST_F(ServiceTest, SUB_Service_GetCompatibilityInfo_0200, testing::ext::TestS res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); - EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*svcProxy, HandleGetCompatibilityInfo(_, _, _)) .WillOnce(Return(BError(BError::Codes::SA_INVAL_ARG).GetCode())); res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); EXPECT_EQ(res, BError(BError::Codes::SA_INVAL_ARG).GetCode()); + EXPECT_CALL(*session, GetScenario()).WillRepeatedly(Return(IServiceReverseType::Scenario::RESTORE)); EXPECT_CALL(*svcProxy, HandleGetCompatibilityInfo(_, _, _)) .WillOnce(Return(BError(BError::Codes::OK).GetCode())); res = service->GetCompatibilityInfo(bundleName, extInfo, compatInfo); diff --git a/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp b/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp index c759c1f44deba5d75497a259f28584128b447651..bbd05eb032d61cfc236ddc21d37361cdc208f3a2 100644 --- a/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp +++ b/tests/unittests/backup_utils/b_utils/scan_file_singleton_test.cpp @@ -76,28 +76,28 @@ HWTEST_F(ScanFileSingletonTest, scan_file_singleton_GetAllBigfiles_0100, testing /** * @brief 测试设置和获取完成标志 - * @tc.number: SUB_scan_file_singleton_SetGetCompeletedFlag_0100 - * @tc.name: scan_file_singleton_SetGetCompeletedFlag_0100 - * @tc.desc: 测试ScanFileSingleton的SetCompeletedFlag和GetCompeletedFlag方法是否能正确设置和获取完成标志 + * @tc.number: SUB_scan_file_singleton_SetGetCompletedFlag_0100 + * @tc.name: scan_file_singleton_SetGetCompletedFlag_0100 + * @tc.desc: 测试ScanFileSingleton的SetCompletedFlag和GetCompletedFlag方法是否能正确设置和获取完成标志 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(ScanFileSingletonTest, scan_file_singleton_SetGetCompeletedFlag_0100, testing::ext::TestSize.Level1) +HWTEST_F(ScanFileSingletonTest, scan_file_singleton_SetGetCompletedFlag_0100, testing::ext::TestSize.Level1) { auto& instance = ScanFileSingleton::GetInstance(); - instance.SetCompeletedFlag(true); - EXPECT_TRUE(instance.GetCompeletedFlag()) << "The completed flag should be true."; + instance.SetCompletedFlag(true); + EXPECT_TRUE(instance.GetCompletedFlag()) << "The completed flag should be true."; - instance.SetCompeletedFlag(false); - EXPECT_FALSE(instance.GetCompeletedFlag()) << "The completed flag should be false."; + instance.SetCompletedFlag(false); + EXPECT_FALSE(instance.GetCompletedFlag()) << "The completed flag should be false."; } /** * @brief 测试添加和获取小文件信息 * @tc.number: SUB_scan_file_singleton_GetAllSmallFiles_0100 * @tc.name: scan_file_singleton_GetAllSmallFiles_0100 - * @tc.desc: 测试ScanFileSingleton的GetAllBigfiles方法是否能正确添加和获取小文件信息 + * @tc.desc: 测试ScanFileSingleton的GetAllSmallFiles方法是否能正确添加和获取小文件信息 * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 @@ -107,10 +107,10 @@ HWTEST_F(ScanFileSingletonTest, scan_file_singleton_GetAllSmallFiles_0100, testi auto& instance = ScanFileSingleton::GetInstance(); instance.AddSmallFile("/path/to/small_file.txt", 512); - auto allSmallFiels = instance.GetAllSmallFiles(); + auto allSmallFiles = instance.GetAllSmallFiles(); - EXPECT_EQ(allSmallFiels.size(), 1) << "There should be one small file in queue."; - EXPECT_EQ(allSmallFiels["/path/to/small_file.txt"], 512) << "The file size should be 512 bytes."; + EXPECT_EQ(allSmallFiles.size(), 1) << "There should be one small file in queue."; + EXPECT_EQ(allSmallFiles["/path/to/small_file.txt"], 512) << "The file size should be 512 bytes."; } /** diff --git a/utils/include/b_filesystem/b_dir.h b/utils/include/b_filesystem/b_dir.h index 9c5f236a0e5603b917e9b6327f14aecd63dac04d..d0eaf3a99fdfd3074fe10ac8a226031dfd59e4e3 100644 --- a/utils/include/b_filesystem/b_dir.h +++ b/utils/include/b_filesystem/b_dir.h @@ -32,7 +32,6 @@ #include "errors.h" namespace OHOS::FileManagement::Backup { -using EndFileInfo = std::map; class BDir { public: /** @@ -103,22 +102,6 @@ public: */ static bool IsFilePathValid(const std::string &filePath); - /** - * @brief 核实文件是否存在软链接并删除 - * - * @param filePath 待核实的路径 - * @return 是否存在软连接 - */ - static bool CheckAndRmSoftLink(const std::string &filePath); - - /** - * @brief 核实文件是否存在软链接并删除 - * - * @param filePaths 待核实的路径集合 - * @return 是否存在软连接 - */ - static bool CheckAndRmSoftLink(const EndFileInfo &filePaths); - /** * @brief 判断目录列表是否包含路径 */ diff --git a/utils/include/b_radar/radar_const.h b/utils/include/b_radar/radar_const.h index 6ebf347daa8234cfd6850d977576740966532023..cd9ae364b81f86dc2fcc20d68fea1da235caf22d 100644 --- a/utils/include/b_radar/radar_const.h +++ b/utils/include/b_radar/radar_const.h @@ -107,7 +107,7 @@ struct RadarError { error_ = TransferErrCode(code); } - int16_t TransferErrCode(int32_t code) + uint16_t TransferErrCode(int32_t code) { if (code == 0) { return 0; diff --git a/utils/include/b_utils/scan_file_singleton.h b/utils/include/b_utils/scan_file_singleton.h index a3174279bd57f72c61681fecfa8ab96fc99d3d29..2316c70566b8515cfbb5e734d6483f920a903b5a 100644 --- a/utils/include/b_utils/scan_file_singleton.h +++ b/utils/include/b_utils/scan_file_singleton.h @@ -33,9 +33,9 @@ public: std::map GetAllBigFiles(); - bool GetCompeletedFlag(); + bool GetCompletedFlag(); - void SetCompeletedFlag(bool value); + void SetCompletedFlag(bool value); std::map GetAllSmallFiles(); diff --git a/utils/src/b_filesystem/b_dir.cpp b/utils/src/b_filesystem/b_dir.cpp index ca6638f09a05e5a87a392d8bc93e2f7667f9c602..e5630d7322fb6c635ced01ca5b70c4bc544bf8df 100644 --- a/utils/src/b_filesystem/b_dir.cpp +++ b/utils/src/b_filesystem/b_dir.cpp @@ -532,33 +532,6 @@ bool BDir::IsFilePathValid(const std::string &filePath) return AppFileService::SandboxHelper::IsValidPath(filePath); } -bool BDir::CheckAndRmSoftLink(const std::string &filePath) -{ - if (std::filesystem::is_symlink(filePath)) { - HILOGE("Soft link is not allowed, path = %{public}s", GetAnonyPath(filePath).c_str()); - if (unlink(filePath.c_str()) < 0) { - HILOGE("Failed to unlink the backup file : %{public}s", GetAnonyPath(filePath).c_str()); - } - return true; - } - return false; -} - -bool BDir::CheckAndRmSoftLink(const EndFileInfo &filePaths) -{ - bool isSoftLink = false; - for (const auto &it : filePaths) { - if (std::filesystem::is_symlink(it.first)) { - HILOGE("Soft link is not allowed, path = %{public}s", GetAnonyPath(it.first).c_str()); - isSoftLink = true; - if (unlink(it.first.c_str()) < 0) { - HILOGE("Failed to unlink the backup file : %{public}s", GetAnonyPath(it.first).c_str()); - } - } - } - return isSoftLink; -} - bool BDir::IsDirsMatch(const vector &excludePaths, const string &path) { if (path.empty()) { diff --git a/utils/src/b_utils/scan_file_singleton.cpp b/utils/src/b_utils/scan_file_singleton.cpp index 8761a4cc3621ad7cd8794c7ef65a4e9e50ca2816..37455d4fbd24702c16fad1785ed4a717da9c9525 100644 --- a/utils/src/b_utils/scan_file_singleton.cpp +++ b/utils/src/b_utils/scan_file_singleton.cpp @@ -52,13 +52,13 @@ std::map ScanFileSingleton::GetAllBigFiles() return fileMap; } -bool ScanFileSingleton::GetCompeletedFlag() +bool ScanFileSingleton::GetCompletedFlag() { std::lock_guard lock(mutexLock_); return isCalculateCompleted_; } -void ScanFileSingleton::SetCompeletedFlag(bool value) +void ScanFileSingleton::SetCompletedFlag(bool value) { std::lock_guard lock(mutexLock_); isCalculateCompleted_ = value;