From: Bartlomiej Kunikowski Date: Tue, 24 Jan 2017 08:44:00 +0000 (+0100) Subject: Uninstalling smoke packages to clear security context X-Git-Tag: submit/tizen/20170213.123058~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d97e44ef130e40a3554cd9149088a3ca0477da9c;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Uninstalling smoke packages to clear security context For properly work, every smoke package need to has pkgid beginning with 'smoke', ex. 'smoketpk01' Requires: - https://review.tizen.org/gerrit/#/c/111709/ Verification: - please use 'find / -name "*smoke*" | grep rules' commend to see if there are no smoke tests entries in security rules - for now there is some bug in recovery mode for installation and there are some rules in security-mnager after this mode, but for other uninstallation works properly Change-Id: I9cbfaead2dfca6dc1a8e851da932b1f6dd3e958a --- diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index 4962626..4af4a31 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -496,16 +496,17 @@ ci::AppInstaller::Result MountUpdate(const bf::path& path_old, return MountInstall(path_new, mode); } -ci::AppInstaller::Result Uninstall(const std::string& pkgid, +ci::AppInstaller::Result Uninstall(const std::string& pkgid, bool is_readonly, RequestResult mode = RequestResult::NORMAL) { - const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()}; - return CallBackend(SIZEOFARRAY(argv), argv, mode); -} - -ci::AppInstaller::Result UninstallPreload(const std::string& pkgid, - RequestResult mode = RequestResult::NORMAL) { - const char* argv[] = {"", "-d", pkgid.c_str(), "--preload", "--force-remove"}; - return CallBackend(SIZEOFARRAY(argv), argv, mode); + if (is_readonly) { + const char* argv[] = {"", "-d", pkgid.c_str(), "--preload", + "--force-remove"}; + return CallBackend(SIZEOFARRAY(argv), argv, mode); + } else { + const char* argv[] = {"", "-d", pkgid.c_str(), "-u", + kTestUserIdStr.c_str()}; + return CallBackend(SIZEOFARRAY(argv), argv, mode); + } } ci::AppInstaller::Result EnablePackage(const std::string& path, @@ -619,6 +620,31 @@ std::vector SetupBackupDirectories(uid_t uid) { return entries; } +void UninstallAllAppsInDirectory(bf::path dir, bool is_readonly) { + if (bf::exists(dir)) { + for (auto& dir_entry : boost::make_iterator_range( + bf::directory_iterator(dir), bf::directory_iterator())) { + if (dir_entry.path().string().find("smoke") != std::string::npos && + bf::is_directory(dir_entry)) { + if (Uninstall(dir_entry.path().filename().string(), is_readonly, + RequestResult::NORMAL) != ci::AppInstaller::Result::OK) { + LOG(ERROR) << "Cannot uninstall smoke test app: " + << dir_entry.path().filename().string(); + } + } + } + } +} + +void UninstallAllSmokeApps(uid_t uid) { + if (getuid() == 0) { + bf::path root_path = kPreloadApps; + UninstallAllAppsInDirectory(root_path, true); + } + bf::path apps_rw = ci::GetRootAppPath(false, uid); + UninstallAllAppsInDirectory(apps_rw, false); +} + } // namespace namespace common_installer { @@ -633,7 +659,7 @@ class SmokeEnvironment : public testing::Environment { BackupPath(path); } void TearDown() override { - // TODO(s89.jang): Uninstall smoke packages to clear security context + UninstallAllSmokeApps(uid_); for (auto& path : backups_) RestorePath(path); } @@ -646,6 +672,11 @@ class SmokeEnvironment : public testing::Environment { class SmokeTest : public testing::Test { }; +// TODO(b.kunikowski): New smoke app pkgid name convention. +// Change all smokeapp pkgids to smoketpk, because now there +// may be some smoke app pkgid identical as in tpk smoke tests, and this may +// cause bad results of some smoke tests. + TEST_F(SmokeTest, DeltaMode_Tpk) { bf::path path = kSmokePackagesDirectory / "DeltaMode_Tpk.tpk"; bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Tpk.delta"; @@ -734,7 +765,7 @@ TEST_F(SmokeTest, DeinstallationMode_Tpk) { std::string pkgid = "smokeapp14"; std::string appid = "smokeapp14.DeinstallationModeTpk"; ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); - ASSERT_EQ(Uninstall(pkgid), ci::AppInstaller::Result::OK); + ASSERT_EQ(Uninstall(pkgid, false), ci::AppInstaller::Result::OK); CheckPackageNonExistance(pkgid, appid); } @@ -1001,7 +1032,7 @@ TEST_F(SmokeTest, DeinstallationMode_Preload) { std::string pkgid = "smoketpk31"; std::string appid = "smoketpk31.DeinstallationModePreload"; ASSERT_EQ(InstallPreload(path), ci::AppInstaller::Result::OK); - ASSERT_EQ(UninstallPreload(pkgid), ci::AppInstaller::Result::OK); + ASSERT_EQ(Uninstall(pkgid, true), ci::AppInstaller::Result::OK); CheckPackageNonExistance(pkgid, appid, true); }