Adjust prepareApp to use new API that sets up context for candidate process 03/212603/1
authorTomasz Swierczek <t.swierczek@samsung.com>
Fri, 23 Aug 2019 06:51:07 +0000 (08:51 +0200)
committerTomasz Swierczek <t.swierczek@samsung.com>
Fri, 23 Aug 2019 08:06:49 +0000 (10:06 +0200)
Change-Id: Ia0eb474cc21392aaf677b3e434903ed286094d30

src/common/sm_api.cpp
src/common/sm_api.h
src/security-manager-tests/test_cases_prepare_app.cpp

index e8c5bba..4516755 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -123,6 +123,15 @@ void dropProcessPrivileges(lib_retcode expectedResult)
                           << " Expected result: " << expectedResult);
 }
 
+void prepareAppCandidate(lib_retcode expectedResult)
+{
+    int result = security_manager_prepare_app_candidate();
+    RUNNER_ASSERT_MSG((lib_retcode) result == expectedResult,
+                      "preparing app candidate process returned wrong value."
+                          << " Result: " << result << ";"
+                          << " Expected result: " << expectedResult);
+}
+
 void prepareApp(const std::string &appId, lib_retcode expectedResult)
 {
     int result = security_manager_prepare_app(appId.c_str());
index 1b4d2e1..a623ab8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2014-2019 Samsung Electronics Co., Ltd. All rights reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -37,6 +37,7 @@ void setProcessLabel(const std::string &appId, lib_retcode expectedResult = SECU
 void setProcessGroups(const std::string &appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void dropProcessPrivileges(lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void prepareApp(const std::string &appId, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
+void prepareAppCandidate(lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void cleanupApp(const std::string &appId, uid_t uid, pid_t pid, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void addUser(const UserRequest &request, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
 void deleteUser(const UserRequest &request, lib_retcode expectedResult = SECURITY_MANAGER_SUCCESS);
index 79f75ad..bcfe071 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd. All rights reserved
  *
  *    Licensed under the Apache License, Version 2.0 (the "License");
  *    you may not use this file except in compliance with the License.
@@ -186,7 +186,7 @@ RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_test)
     if (pid == 0) {
         {
             RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed");
-
+            Api::prepareAppCandidate();
             ThreadWrapper threads[THREADS];
 
             for (size_t i = 0; i < THREADS; i++)
@@ -202,6 +202,34 @@ RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_test)
     }
 }
 
+RUNNER_CHILD_TEST(security_manager_101_create_namespace_test_n)
+{
+    TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
+    tmpUser.create();
+
+    AppInstallHelper app("app100_n", tmpUser.getUid());
+    ScopedInstaller appInstall(app);
+    const std::string expectedLabel = app.generateAppLabel();
+
+    pid_t pid = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "Fork failed");
+    if (pid == 0) {
+        {
+            RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed");
+            ThreadWrapper threads[THREADS];
+
+            for (size_t i = 0; i < THREADS; i++)
+                threads[i].run(i, expectedLabel);
+
+            Api::prepareAppCandidate(SECURITY_MANAGER_ERROR_INPUT_PARAM);
+        }
+        RUNNER_ASSERT_MSG(!thread_errors.empty(), std::endl << thread_errors);
+        exit(0);
+    } else {
+        waitPid(pid);
+    }
+}
+
 RUNNER_CHILD_TEST(security_manager_101_create_namespace_test)
 {
     TemporaryTestUser tmpUser(APP_TEST_USER, GUM_USERTYPE_NORMAL, false);
@@ -216,7 +244,7 @@ RUNNER_CHILD_TEST(security_manager_101_create_namespace_test)
     if (pid == 0) {
         synchPipe.claimParentEp();
         RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed");
-
+        Api::prepareAppCandidate();
         Api::prepareApp(app.getAppId().c_str());
         synchPipe.post();
         synchPipe.wait();
@@ -262,7 +290,7 @@ RUNNER_CHILD_TEST(security_manager_102_check_propagation_test)
     if (pid == 0) {
         synchPipe.claimParentEp();
         RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed");
-
+        Api::prepareAppCandidate();
         Api::prepareApp(app.getAppId().c_str());
         synchPipe.post();
         synchPipe.wait();
@@ -308,7 +336,7 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test)
     if (pid == 0) {
         synchPipe.claimParentEp();
         RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed");
-
+        Api::prepareAppCandidate();
         Api::prepareApp(app.getAppId().c_str());
         synchPipe.post();
         synchPipe.wait();