From: Bartlomiej Kunikowski Date: Fri, 20 Jan 2017 10:36:45 +0000 (+0100) Subject: Uninstalling smoke packages to clear security context X-Git-Tag: accepted/tizen/common/20170214.173614~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F60%2F111460%2F10;p=platform%2Fcore%2Fappfw%2Fwgt-backend.git Uninstalling smoke packages to clear security context For properly work, every smoke package need to has pkgid beginning with 'smoke', ex. 'smokeapp01', 'smokehyb01' Requires: - https://review.tizen.org/gerrit/#/c/110900/ Verification: - please use 'find / -name "*smoke*" | grep rules' commend to see if there are no smoke tests entries in security rules - for now there are some bug in recovery mode for installation and there are some artifacts after this mode, but for other uninstallation works properly Change-Id: Ib2d963a5323d41c2d4aaa2ba18b1d6483cd04bd9 --- diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index 7328a1c..2555a80 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -543,15 +543,17 @@ ci::AppInstaller::Result MountInstall(const bf::path& path, ci::AppInstaller::Result Uninstall(const std::string& pkgid, PackageType type, + bool is_preload, RequestResult mode = RequestResult::NORMAL) { - const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()}; - return CallBackend(SIZEOFARRAY(argv), argv, type, mode); -} - -ci::AppInstaller::Result UninstallPreload(const std::string& pkgid, - PackageType type, RequestResult mode = RequestResult::NORMAL) { - const char* argv[] = {"", "-d", pkgid.c_str(), "--preload", "--force-remove"}; - return CallBackend(SIZEOFARRAY(argv), argv, type, mode); + if (is_preload) { + const char* argv[] = {"", "-d", pkgid.c_str(), "--preload", + "--force-remove"}; + return CallBackend(SIZEOFARRAY(argv), argv, type, mode); + } else { + const char* argv[] = {"", "-d", pkgid.c_str(), "-u", + kTestUserIdStr.c_str()}; + return CallBackend(SIZEOFARRAY(argv), argv, type, mode); + } } ci::AppInstaller::Result RDSUpdate(const bf::path& path, @@ -669,6 +671,32 @@ std::vector SetupBackupDirectories(uid_t uid) { return entries; } +void UninstallAllAppsInDirectory(bf::path dir, bool is_preload) { + 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(), PackageType::WGT, + is_preload, 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 { @@ -683,7 +711,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); } @@ -696,6 +724,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 smokewgt, 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, InstallationMode) { bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt"; std::string pkgid = "smokeapp03"; @@ -724,7 +757,8 @@ TEST_F(SmokeTest, DeinstallationMode) { std::string appid = "smokeapp05.DeinstallationMode"; ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK); - ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK); + ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false), + ci::AppInstaller::Result::OK); CheckPackageNonExistance(pkgid, {appid}); } @@ -991,7 +1025,7 @@ TEST_F(SmokeTest, DeinstallationMode_Hybrid) { std::string appid1 = "smokehyb03.Web"; ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK); - ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID), + ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false), ci::AppInstaller::Result::OK); CheckPackageNonExistance(pkgid, {appid1}); } @@ -1187,6 +1221,8 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) { ValidateDataFiles(pkgid, kTestUserId); } +// TODO(b.kunikowski): Change pkgid to "smokewgt##" like others pkgids, because +// it is needed for properly test environment tear-down TEST_F(SmokeTest, UserDefinedPlugins) { bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt"; std::string pkgid = "0CSPVhKmRk"; @@ -1262,7 +1298,7 @@ TEST_F(SmokeTest, DeinstallationMode_Preload) { std::string appid = "smokeapp39.DeinstallationModePreload"; ASSERT_EQ(InstallPreload(path, PackageType::WGT), ci::AppInstaller::Result::OK); - ASSERT_EQ(UninstallPreload(pkgid, PackageType::WGT), + ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, true), ci::AppInstaller::Result::OK); CheckPackageReadonlyNonExistance(pkgid, {appid}); }