From 021771cd0e10ea4dec6efe1a9b7d2efd0cd49236 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Thu, 30 Apr 2020 14:44:04 +0200 Subject: [PATCH] Add new test scenario, where app is killed during policy change. Change-Id: I9a57548b1f136f3612d8be5b1b2b6f64f335970d --- .../test_cases_prepare_app.cpp | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/security-manager-tests/test_cases_prepare_app.cpp b/src/security-manager-tests/test_cases_prepare_app.cpp index cf72e77..8d5b941 100644 --- a/src/security-manager-tests/test_cases_prepare_app.cpp +++ b/src/security-manager-tests/test_cases_prepare_app.cpp @@ -371,6 +371,45 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test) } } +RUNNER_CHILD_TEST(security_manager_104_policy_change_kill_app_test) +{ + TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false); + tmpUser.create(); + + AppInstallHelper app("app104", tmpUser.getUid()); + app.addPrivileges({PRIV_EXTERNALSTORAGE, PRIV_MEDIASTORAGE}); + ScopedInstaller appInstall(app); + + SynchronizationPipe synchPipe; + pid_t pid = fork(); + RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed"); + if (pid == 0) { + synchPipe.claimParentEp(); + try { + RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed"); + Api::prepareAppCandidate(); + Api::prepareApp(app.getAppId()); + } catch (...) { + synchPipe.post(); + throw; + } + synchPipe.post(); + exit(0); + } else { + synchPipe.claimChildEp(); + synchPipe.wait(); + + PolicyRequest policyRequest; + PolicyEntry policyEntry(app.getAppId(), tmpUser.getUidString(), PRIV_EXTERNALSTORAGE); + policyEntry.setLevel(PolicyEntry::LEVEL_DENY); + policyRequest.addEntry(policyEntry); + Api::sendPolicy(policyRequest); + + waitPid(pid); + Api::cleanupApp(app.getAppId(), tmpUser.getUid(), pid); + } +} + namespace { class Timestamp { uint64_t _; -- 2.7.4