Add new test scenario, where app is killed during policy change. 15/232315/3
authorDariusz Michaluk <d.michaluk@samsung.com>
Thu, 30 Apr 2020 12:44:04 +0000 (14:44 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 5 May 2020 10:13:20 +0000 (10:13 +0000)
Change-Id: I9a57548b1f136f3612d8be5b1b2b6f64f335970d

src/security-manager-tests/test_cases_prepare_app.cpp

index cf72e77..8d5b941 100644 (file)
@@ -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 _;