From 44dffc083b7f98971cbe7aea4a336eabfe17f3aa Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Thu, 10 Oct 2024 09:37:31 +0800 Subject: [PATCH] add tDD Signed-off-by: sunjiakun --- .../bms_bundle_app_service_fwk_installer.cpp | 770 ++++++++++++++++++ 1 file changed, 770 insertions(+) diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_app_service_fwk_installer.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_app_service_fwk_installer.cpp index 99ab27f60..1bcef5c61 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_app_service_fwk_installer.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_app_service_fwk_installer.cpp @@ -65,6 +65,7 @@ const std::string BUNDLE_CODE_DIR = "/data/app/el1/bundle/public/com.example.l3j const std::string BUNDLE_LIBRARY_PATH_DIR = "/data/app/el1/bundle/public/com.example.l3jsdemo/libs/arm"; const std::string TEST_CREATE_FILE_PATH = "/data/test/resource/bms/app_service_test/test_create_dir/test.hap"; const std::string BUILD_HASH = "8670157ae28ac2dc08075c4a9364e320898b4aaf4c1ab691df6afdb854a6811b"; +const std::string SHARED_MODULE_TYPE = "shared"; } // namespace class BmsBundleAppServiceFwkInstallerTest : public testing::Test { @@ -510,6 +511,43 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0500, Function | DeleteBundleInfo(BUNDLE_NAME); } +/** + * @tc.number: CheckNeedInstall_0600 + * @tc.name: test CheckNeedInstall + * @tc.desc: 1.Test the CheckNeedInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedInstall_0600, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + InitAppServiceFwkInstaller(appServiceFwkInstaller); + std::unordered_map infos; + + InnerBundleInfo innerBundleInfo; + ApplicationInfo applicationInfo; + applicationInfo.bundleName = BUNDLE_NAME; + innerBundleInfo.baseBundleInfo_->versionCode = VERSION_LOW; + innerBundleInfo.SetBaseApplicationInfo(applicationInfo); + AddBundleInfo(BUNDLE_NAME, innerBundleInfo); + auto dataMgr = bundleMgrService_->GetDataMgr(); + ASSERT_NE(dataMgr, nullptr); + + InnerBundleInfo newInfo; + bool getRes = dataMgr->FetchInnerBundleInfo(BUNDLE_NAME, newInfo); + EXPECT_TRUE(getRes); + + appServiceFwkInstaller.bundleName_ = BUNDLE_NAME; + appServiceFwkInstaller.versionCode_ = newInfo.GetVersionCode(); + infos[VERSION_ONE_LIBRARY_ONE_PATH] = newInfo; + + InnerBundleInfo oldInfo; + oldInfo.baseBundleInfo_->versionCode = VERSION; + bool isDowngrade = false; + bool result = appServiceFwkInstaller.CheckNeedInstall(infos, oldInfo, isDowngrade); + + EXPECT_FALSE(result); + DeleteBundleInfo(BUNDLE_NAME); +} + /** * @tc.number: CheckNeedUpdate_0100 * @tc.name: test CheckNeedUpdate @@ -621,6 +659,33 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0500, Function | S EXPECT_TRUE(res); } +/** + * @tc.number: CheckNeedUpdate_0600 + * @tc.name: test CheckNeedUpdate + * @tc.desc: 1.Test the CheckNeedUpdate + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckNeedUpdate_0600, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + appServiceFwkInstaller.versionCode_ = VERSION_LOW; + + InnerBundleInfo oldInfo; + oldInfo.baseBundleInfo_->versionCode = VERSION_LOW; + oldInfo.currentPackage_ = MODULE_NAME_TEST; + + InnerModuleInfo innerModuleInfo; + innerModuleInfo.moduleName = MODULE_NAME_TEST; + + InnerBundleInfo newInfo; + newInfo.currentPackage_ = MODULE_NAME_TEST; + innerModuleInfo.buildHash = BUILD_HASH; + newInfo.innerModuleInfos_[MODULE_NAME_TEST] = innerModuleInfo; + + bool res = appServiceFwkInstaller.CheckNeedUpdate(newInfo, oldInfo); + EXPECT_TRUE(appServiceFwkInstaller.moduleUpdate_); + EXPECT_TRUE(res); +} + /** * @tc.number: RemoveBundleCodeDir_0010 * @tc.name: test RemoveBundleCodeDir @@ -777,6 +842,67 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0050, Functi dataMgr->installStates_.erase(BUNDLE_NAME); } +/** + * @tc.number: UninstallLowerVersion_0060 + * @tc.name: test UninstallLowerVersion + * @tc.desc: 1.Test the UninstallLowerVersion + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0060, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + InitAppServiceFwkInstaller(appServiceFwkInstaller); + appServiceFwkInstaller.bundleName_ = BUNDLE_NAME; + + InnerBundleInfo info; + BundleInfo bundleInfo; + bundleInfo.name = BUNDLE_NAME; + info.SetBaseBundleInfo(bundleInfo); + + auto dataMgr = GetBundleDataMgr(); + ASSERT_NE(dataMgr, nullptr); + dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS; + dataMgr->bundleInfos_.emplace(BUNDLE_NAME, info); + + std::vector moduleNameList; + auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList); + EXPECT_EQ(res, ERR_OK); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); + dataMgr->installStates_.erase(BUNDLE_NAME); +} + +/** + * @tc.number: UninstallLowerVersion_0080 + * @tc.name: test UninstallLowerVersion + * @tc.desc: 1.Test the UninstallLowerVersion + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UninstallLowerVersion_0080, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + InitAppServiceFwkInstaller(appServiceFwkInstaller); + appServiceFwkInstaller.bundleName_ = BUNDLE_NAME; + if (appServiceFwkInstaller.dataMgr_ == nullptr) + { + appServiceFwkInstaller.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + InnerBundleInfo info; + BundleInfo bundleInfo; + bundleInfo.name = BUNDLE_NAME; + info.SetBaseBundleInfo(bundleInfo); + InnerModuleInfo innerModuleInfo; + innerModuleInfo.moduleName = MODULE_NAME_LIBRARY_ONE; + info.innerModuleInfos_.emplace(MODULE_NAME_LIBRARY_ONE, innerModuleInfo); + appServiceFwkInstaller.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, info); + + std::vector moduleNameList{MODULE_NAME_LIBRARY_ONE}; + auto res = appServiceFwkInstaller.UninstallLowerVersion(moduleNameList); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + /** * @tc.number: ProcessNewModuleInstall_0010 * @tc.name: test ProcessNewModuleInstall @@ -836,6 +962,31 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessInstall_0010, Function | Sm appServiceFwkInstaller.AddAppProvisionInfo(BUNDLE_NAME, provisionInfo, installParam); } +/** + * @tc.number: ProcessInstall_0020 + * @tc.name: test ProcessInstall + * @tc.desc: 1.Test the ProcessInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessInstall_0020, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + InitAppServiceFwkInstaller(appServiceFwkInstaller); + + std::vector hspPaths; + hspPaths.push_back(VERSION_ONE_LIBRARY_ONE_PATH); + InstallParam installParam; + installParam.isPreInstallApp = false; + installParam.specifiedDistributionType = BUNDLE_NAME; + installParam.additionalInfo = BUNDLE_NAME; + + auto res = appServiceFwkInstaller.ProcessInstall(hspPaths, installParam); + appServiceFwkInstaller.deleteBundlePath_.push_back(VERSION_ONE_LIBRARY_ONE_PATH); + std::unordered_map infos; + appServiceFwkInstaller.SavePreInstallBundleInfo(res, infos, installParam); + EXPECT_EQ(res, ERR_OK); + appServiceFwkInstaller.deleteBundlePath_.clear(); +} + /** * @tc.number: ProcessInstall_0010 * @tc.name: test ProcessInstall @@ -913,6 +1064,54 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessNativeLibrary_0010, Functio EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR); } +/** + * @tc.number: ProcessNativeLibrary_0020 + * @tc.name: test ProcessNativeLibrary + * @tc.desc: 1.Test the ProcessNativeLibrary + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessNativeLibrary_0020, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + InitAppServiceFwkInstaller(appServiceFwkInstaller); + + InnerBundleInfo innerBundleInfo; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.compressNativeLibs = true; + innerModuleInfo.nativeLibraryPath = ""; + innerBundleInfo.innerModuleInfos_.emplace(MODULE_NAME_TEST, innerModuleInfo); + + auto res = appServiceFwkInstaller.ProcessNativeLibrary( + VERSION_ONE_LIBRARY_ONE_PATH, BUNDLE_DATA_DIR, MODULE_NAME_TEST, BUNDLE_DATA_DIR, innerBundleInfo); + EXPECT_EQ(res, ERR_OK); +} + +/** + * @tc.number: SaveBundleInfoToStorage_0010 + * @tc.name: test SaveBundleInfoToStorage + * @tc.desc: 1.Test the SaveBundleInfoToStorage + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, SaveBundleInfoToStorage_0010, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller installer; + InitAppServiceFwkInstaller(installer); + + installer.bundleName_ = BUNDLE_NAME; + installer.dataMgr_->installStates_.clear(); + InnerBundleInfo info; + info.currentPackage_ = MODULE_NAME_TEST; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, info); + + auto res = installer.SaveBundleInfoToStorage(); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_INTERNAL_ERROR); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + /** * @tc.number: MoveSoToRealPath_0010 * @tc.name: test MoveSoToRealPath @@ -935,6 +1134,29 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, MoveSoToRealPath_0010, Function | EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_STATE_ERROR); } +/** + * @tc.number: MoveSoToRealPath_0020 + * @tc.name: test MoveSoToRealPath + * @tc.desc: 1.Test the MoveSoToRealPath + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, MoveSoToRealPath_0020, Function | SmallTest | Level0) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + InitAppServiceFwkInstaller(appServiceFwkInstaller); + auto res = appServiceFwkInstaller.MoveSoToRealPath(MODULE_NAME_LIBRARY_ONE, "data/test", MODULE_NAME_LIBRARY_ONE); + EXPECT_EQ(res, ERR_OK); + + InstallParam installParam; + std::unordered_map infos; + InnerBundleInfo info; + info.baseBundleInfo_->versionCode = VERSION_LOW; + appServiceFwkInstaller.versionCode_ = VERSION; + appServiceFwkInstaller.uninstallModuleVec_.emplace_back(MODULE_NAME_TEST); + res = appServiceFwkInstaller.UpdateAppService(info, infos, installParam); + EXPECT_EQ(res, ERR_OK); + appServiceFwkInstaller.uninstallModuleVec_.clear(); +} + /** * @tc.number: ProcessBundleUpdateStatus_0010 * @tc.name: test ProcessBundleUpdateStatus @@ -1076,6 +1298,22 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ExtractModule_0100, Function | Sma EXPECT_EQ(ret, ERR_OK); } +/** + * @tc.number: ExtractModule_0200 + * @tc.name: test function of ExtractModule + * @tc.desc: 1. calling ExtractModule of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ExtractModule_0200, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + InitAppServiceFwkInstaller(installer); + InnerBundleInfo oldInfo; + InnerBundleInfo newInfo; + std::string bundlePath; + auto ret = installer.ExtractModule(oldInfo, newInfo, bundlePath); + EXPECT_EQ(ret, ERR_OK); +} + /** * @tc.number: MoveSoToRealPath_0100 * @tc.name: test function of MoveSoToRealPath @@ -1107,6 +1345,225 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0100, Fu EXPECT_NE(ret, ERR_OK); } +/** + * @tc.number: DeliveryProfileToCodeSign_0200 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0200, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + Security::Verify::ProvisionInfo provisionInfo; + provisionInfo.distributionType = Security::Verify::AppDistType::ENTERPRISE; + provisionInfo.type = Security::Verify::ProvisionType::RELEASE; + provisionInfo.profileBlockLength = 0; + Security::Verify::HapVerifyResult hapVerifyResult; + hapVerifyResult.SetProvisionInfo(provisionInfo); + hapVerifyResults.push_back(hapVerifyResult); + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_0300 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0300, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + Security::Verify::ProvisionInfo provisionInfo; + provisionInfo.distributionType = Security::Verify::AppDistType::ENTERPRISE_NORMAL; + provisionInfo.type = Security::Verify::ProvisionType::RELEASE; + provisionInfo.profileBlock = nullptr; + Security::Verify::HapVerifyResult hapVerifyResult; + hapVerifyResult.SetProvisionInfo(provisionInfo); + hapVerifyResults.push_back(hapVerifyResult); + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_0400 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0400, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + Security::Verify::ProvisionInfo provisionInfo; + provisionInfo.distributionType = Security::Verify::AppDistType::ENTERPRISE_MDM; + provisionInfo.type = Security::Verify::ProvisionType::RELEASE; + provisionInfo.profileBlock = nullptr; + Security::Verify::HapVerifyResult hapVerifyResult; + hapVerifyResult.SetProvisionInfo(provisionInfo); + hapVerifyResults.push_back(hapVerifyResult); + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_0500 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0500, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + Security::Verify::ProvisionInfo provisionInfo; + provisionInfo.distributionType = Security::Verify::AppDistType::APP_GALLERY; + provisionInfo.type = Security::Verify::ProvisionType::DEBUG; + provisionInfo.profileBlockLength = 0; + Security::Verify::HapVerifyResult hapVerifyResult; + hapVerifyResult.SetProvisionInfo(provisionInfo); + hapVerifyResults.push_back(hapVerifyResult); + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_0600 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0600, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + Security::Verify::ProvisionInfo provisionInfo; + provisionInfo.distributionType = Security::Verify::AppDistType::APP_GALLERY; + provisionInfo.type = Security::Verify::ProvisionType::RELEASE; + provisionInfo.profileBlockLength = 0; + Security::Verify::HapVerifyResult hapVerifyResult; + hapVerifyResult.SetProvisionInfo(provisionInfo); + hapVerifyResults.push_back(hapVerifyResult); + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_0700 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0700, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + Security::Verify::ProvisionInfo provisionInfo; + provisionInfo.distributionType = Security::Verify::AppDistType::APP_GALLERY; + provisionInfo.type = Security::Verify::ProvisionType::RELEASE; + provisionInfo.profileBlockLength = 1; + provisionInfo.bundleInfo.bundleName = BUNDLE_NAME; + provisionInfo.profileBlock = std::make_unique(provisionInfo.profileBlockLength); + + Security::Verify::HapVerifyResult hapVerifyResult; + hapVerifyResult.SetProvisionInfo(provisionInfo); + hapVerifyResults.push_back(hapVerifyResult); + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_0800 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_0800, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + installer.bundleName_ = BUNDLE_NAME; + InnerBundleInfo info; + BundleInfo bundleInfo; + bundleInfo.name = BUNDLE_NAME; + info.SetBaseBundleInfo(bundleInfo); + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, info); + + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_OK); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_1000 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_1000, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + hapVerifyResults.clear(); + installer.bundleName_ = ""; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_APPEXECFWK_INSTALL_FAILED_INCOMPATIBLE_SIGNATURE); +} + +/** + * @tc.number: DeliveryProfileToCodeSign_1100 + * @tc.name: test function of DeliveryProfileToCodeSign + * @tc.desc: calling DeliveryProfileToCodeSign of AppServiceFwkInstaller + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, DeliveryProfileToCodeSign_1100, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::vector hapVerifyResults; + Security::Verify::ProvisionInfo provisionInfo; + provisionInfo.distributionType = Security::Verify::AppDistType::ENTERPRISE; + provisionInfo.profileBlockLength = 1; + provisionInfo.bundleInfo.bundleName = BUNDLE_NAME; + provisionInfo.profileBlock = std::make_unique(provisionInfo.profileBlockLength); + + Security::Verify::HapVerifyResult hapVerifyResult; + hapVerifyResult.SetProvisionInfo(provisionInfo); + hapVerifyResults.push_back(hapVerifyResult); + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto ret = installer.DeliveryProfileToCodeSign(hapVerifyResults); + EXPECT_EQ(ret, ERR_BUNDLE_MANAGER_CODE_SIGNATURE_DELIVERY_FILE_FAILED); +} + /** * @tc.number: CreateSignatureFileStream_0100 * @tc.name: test function of CreateSignatureFileStream @@ -1209,6 +1666,35 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, RollBack_0010, Function | SmallTes dataMgr->installStates_.erase(BUNDLE_NAME); } +/** + * @tc.number: RollBack_0020 + * @tc.name: test RollBack + * @tc.desc: 1.test roll back + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, RollBack_0020, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller appServiceFwkInstaller; + InitAppServiceFwkInstaller(appServiceFwkInstaller); + appServiceFwkInstaller.bundleName_ = BUNDLE_NAME; + + auto dataMgr = GetBundleDataMgr(); + ASSERT_NE(dataMgr, nullptr); + dataMgr->installStates_[BUNDLE_NAME] = InstallState::INSTALL_SUCCESS; + + InstallState state; + appServiceFwkInstaller.dataMgr_->installStates_.emplace(BUNDLE_NAME, state); + + appServiceFwkInstaller.newInnerBundleInfo_.baseBundleInfo_->isPreInstallApp = true; + appServiceFwkInstaller.RollBack(); + auto item = appServiceFwkInstaller.dataMgr_->installStates_.find(BUNDLE_NAME); + auto res = item == appServiceFwkInstaller.dataMgr_->installStates_.end(); + EXPECT_FALSE(res); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); + dataMgr->installStates_.erase(BUNDLE_NAME); +} + /** * @tc.number: ProcessModuleUpdate_0010 * @tc.name: test ProcessModuleUpdate @@ -1236,4 +1722,288 @@ HWTEST_F(BmsBundleAppServiceFwkInstallerTest, ProcessModuleUpdate_0010, Function DeletePreBundleInfo(BUNDLE_NAME); dataMgr->installStates_.erase(BUNDLE_NAME); } + +/** + * @tc.number: UnInstall_0010 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0010, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + std::string bundleName = ""; + auto res = installer.UnInstall(bundleName); + EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_PARAM_ERROR); +} + +/** + * @tc.number: UnInstall_0020 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0020, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK; + + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo); + + auto res = installer.UnInstall(BUNDLE_NAME); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + +/** + * @tc.number: UnInstall_0030 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0030, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK; + + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo); + installer.dataMgr_->transferStates_.emplace(InstallState::UNINSTALL_START, InstallState::UNINSTALL_START); + + auto res = installer.UnInstall(BUNDLE_NAME); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR); + + installer.dataMgr_->transferStates_.clear(); + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + +/** + * @tc.number: UnInstall_0040 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0040, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + std::string bundleName = ""; + std::string moduleName = MODULE_NAME_TEST; + auto res = installer.UnInstall(bundleName, moduleName); + EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_PARAM_ERROR); +} + +/** + * @tc.number: UnInstall_0050 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0050, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + std::string bundleName = BUNDLE_NAME; + std::string moduleName = ""; + auto res = installer.UnInstall(bundleName, moduleName); + EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_PARAM_ERROR); +} + +/** + * @tc.number: UnInstall_0060 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0060, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + auto res = installer.UnInstall(BUNDLE_NAME, MODULE_NAME_TEST); + EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_PARAM_ERROR); +} + +/** + * @tc.number: UnInstall_0070 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0070, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK; + + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo); + + auto res = installer.UnInstall(BUNDLE_NAME, MODULE_NAME_TEST); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + +/** + * @tc.number: UnInstall_0080 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0080, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK; + InnerModuleInfo innerModuleInfo; + innerModuleInfo.distro.moduleType = SHARED_MODULE_TYPE; + innerModuleInfo.moduleName = MODULE_NAME_LIBRARY_ONE; + innerBundleInfo.innerModuleInfos_.emplace(MODULE_NAME_LIBRARY_ONE, innerModuleInfo); + + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo); + + auto res = installer.UnInstall(BUNDLE_NAME, MODULE_NAME_TEST); + EXPECT_EQ(res, ERR_BUNDLE_MANAGER_MODULE_NOT_EXIST); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + +/** + * @tc.number: UnInstall_0090 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0090, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + InnerBundleInfo innerBundleInfo; + auto res = installer.UnInstall(BUNDLE_NAME, MODULE_NAME_TEST, innerBundleInfo); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_BUNDLE_MGR_SERVICE_ERROR); +} + +/** + * @tc.number: UnInstall_0100 + * @tc.name: test UnInstall + * @tc.desc: 1.test UnInstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, UnInstall_0100, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + InnerBundleInfo innerBundleInfo; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo); + installer.dataMgr_->installStates_.emplace(BUNDLE_NAME, InstallState::INSTALL_START); + + auto res = installer.UnInstall(BUNDLE_NAME, MODULE_NAME_TEST, innerBundleInfo); + EXPECT_EQ(res, ERR_OK); + + installer.dataMgr_->installStates_.clear(); + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + +/** + * @tc.number: BeforeUninstall_0010 + * @tc.name: test BeforeUninstall + * @tc.desc: 1.test BeforeUninstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, BeforeUninstall_0010, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + std::string bundleName = ""; + auto res = installer.BeforeUninstall(bundleName); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_PARAM_ERROR); +} + +/** + * @tc.number: BeforeUninstall_0020 + * @tc.name: test BeforeUninstall + * @tc.desc: 1.test BeforeUninstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, BeforeUninstall_0020, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.clear(); + auto res = installer.BeforeUninstall(BUNDLE_NAME); + EXPECT_EQ(res, ERR_APPEXECFWK_UNINSTALL_PARAM_ERROR); +} + +/** + * @tc.number: BeforeUninstall_0030 + * @tc.name: test BeforeUninstall + * @tc.desc: 1.test BeforeUninstall + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, BeforeUninstall_0030, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + InnerBundleInfo innerBundleInfo; + innerBundleInfo.baseApplicationInfo_->bundleType = BundleType::APP_SERVICE_FWK; + + if (installer.dataMgr_ == nullptr) + { + installer.dataMgr_ = DelayedSingleton::GetInstance()->GetDataMgr(); + } + installer.dataMgr_->bundleInfos_.emplace(BUNDLE_NAME, innerBundleInfo); + + auto res = installer.BeforeUninstall(BUNDLE_NAME); + EXPECT_EQ(res, ERR_OK); + + DeleteBundleInfo(BUNDLE_NAME); + DeletePreBundleInfo(BUNDLE_NAME); +} + +/** + * @tc.number: CheckAndParseFiles_0010 + * @tc.name: test CheckAndParseFiles + * @tc.desc: 1.test CheckAndParseFiles + */ +HWTEST_F(BmsBundleAppServiceFwkInstallerTest, CheckAndParseFiles_0010, Function | SmallTest | Level1) +{ + AppServiceFwkInstaller installer; + auto dataMgr = GetBundleDataMgr(); + ASSERT_NE(dataMgr, nullptr); + std::vector hspPaths; + InstallParam installParam; + std::unordered_map newInfos; + + auto res = installer.CheckAndParseFiles(hspPaths, installParam, newInfos); + EXPECT_EQ(res, ERR_APPEXECFWK_INSTALL_FILE_PATH_INVALID); +} }