From 00afb41d6d9eeb748ce80868e8f32491b5b11b4d Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Fri, 23 Aug 2019 08:51:07 +0200 Subject: [PATCH] Adjust prepareApp to use new API that sets up context for candidate process Change-Id: Ia0eb474cc21392aaf677b3e434903ed286094d30 --- src/common/sm_api.cpp | 11 ++++++- src/common/sm_api.h | 3 +- .../test_cases_prepare_app.cpp | 38 +++++++++++++++++++--- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/common/sm_api.cpp b/src/common/sm_api.cpp index e8c5bba..4516755 100644 --- a/src/common/sm_api.cpp +++ b/src/common/sm_api.cpp @@ -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()); diff --git a/src/common/sm_api.h b/src/common/sm_api.h index 1b4d2e1..a623ab8 100644 --- a/src/common/sm_api.h +++ b/src/common/sm_api.h @@ -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); diff --git a/src/security-manager-tests/test_cases_prepare_app.cpp b/src/security-manager-tests/test_cases_prepare_app.cpp index 79f75ad..bcfe071 100644 --- a/src/security-manager-tests/test_cases_prepare_app.cpp +++ b/src/security-manager-tests/test_cases_prepare_app.cpp @@ -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(); -- 2.7.4