From 3473c4207ef2f437804e7eb40b8ffd2163b84846 Mon Sep 17 00:00:00 2001 From: Konrad Lipinski Date: Wed, 29 Apr 2020 09:12:07 +0200 Subject: [PATCH] Spring cleaning * drop some unused code * shrink interfaces a tiny bit * obviate construction of a few intermediate objects Change-Id: I66cbbfdab5270bc64fbb2e51b3de027f96ec86a9 --- README | 2 - src/ckm/ckm-common.cpp | 8 +- src/ckm/ckm-common.h | 7 +- src/common/service_manager.cpp | 10 +- src/common/tests_common.cpp | 102 +-------------------- src/common/tests_common.h | 28 ------ src/cynara-tests/common/cynara_test_commons.cpp | 4 +- src/cynara-tests/common/cynara_test_env.cpp | 4 +- .../common/cynara_test_file_operations.cpp | 58 ++++++------ .../common/cynara_test_file_operations.h | 4 - src/framework/include/dpl/exception.h | 6 +- .../src/test_results_collector_summary.cpp | 4 +- .../common/app_install_helper_ext.cpp | 6 +- .../common/scoped_app_launcher.cpp | 4 +- src/security-manager-tests/test_cases.cpp | 6 +- .../test_cases_prepare_app.cpp | 18 ++-- .../test_cases_public_sharing.cpp | 6 +- 17 files changed, 74 insertions(+), 203 deletions(-) diff --git a/README b/README index ea2b291..a036712 100644 --- a/README +++ b/README @@ -120,8 +120,6 @@ tests-common Same as RUNNER_TEST_CHILD but run only with smack disabled. RUNNER_MULTIPROCESS_TEST_SMACK Same as RUNNER_TEST_MULTIPROCESS but run only with smack enabled. - RUNNER_MULTIPROCESS_TEST_NOSMACK - Same as RUNNER_TEST_MULTIPROCESS but run only with smack disabled. --Assert macros---------------------------------------------------------------- Used within test registering macros. diff --git a/src/ckm/ckm-common.cpp b/src/ckm/ckm-common.cpp index 714fa64..c50f2d6 100644 --- a/src/ckm/ckm-common.cpp +++ b/src/ckm/ckm-common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000-2020 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. @@ -383,7 +383,7 @@ void check_alias_list(const CKM::AliasVector& expected) } void check_alias_info_list_helper(const CKM::AliasPwdVector& expected, const CKM::AliasPwdVector& actual, - const std::string userSmackLabel) + const std::string &userSmackLabel) { std::string errorLogMsg; std::unordered_map aliasPwdMap; @@ -421,7 +421,7 @@ void check_alias_info_list_helper(const CKM::AliasPwdVector& expected, const CKM } } -void check_alias_info_list(const CKM::AliasPwdVector& expected, const std::string& userSmackLabel) +void check_alias_info_list(const CKM::AliasPwdVector& expected) { ckmc_alias_info_list_s *aliasInfoList = NULL; int ret = ckmc_get_data_alias_info_list(&aliasInfoList); @@ -447,7 +447,7 @@ void check_alias_info_list(const CKM::AliasPwdVector& expected, const std::strin it++; } ckmc_alias_info_list_all_free(aliasInfoList); - check_alias_info_list_helper(expected, actual, userSmackLabel); + check_alias_info_list_helper(expected, actual); } size_t count_aliases(alias_type_ type, size_t minimum_initial_element_count) diff --git a/src/ckm/ckm-common.h b/src/ckm/ckm-common.h index 69120c9..a61ffcf 100644 --- a/src/ckm/ckm-common.h +++ b/src/ckm/ckm-common.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2000-2020 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. @@ -148,9 +148,8 @@ void reset_user_data(uid_t user_id, const char *passwd); ckmc_raw_buffer_s prepare_message_buffer(const char * input); void check_alias_list(const CKM::AliasVector& expected); void check_alias_info_list_helper(const CKM::AliasPwdVector& expected, const CKM::AliasPwdVector& actual, - const std::string userSmackLabel = ""); -void check_alias_info_list(const CKM::AliasPwdVector& expected, - const std::string& userSmackLabel = ""); + const std::string &userSmackLabel = {}); +void check_alias_info_list(const CKM::AliasPwdVector& expected); typedef enum { ALIAS_KEY, diff --git a/src/common/service_manager.cpp b/src/common/service_manager.cpp index 4441ace..cd27f31 100644 --- a/src/common/service_manager.cpp +++ b/src/common/service_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2014 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2013-2020 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. @@ -98,10 +98,10 @@ void ServiceManager::getUnitPath() DBus::MessageOut ServiceManager::newMethodCall(const std::string &method) { - return DBus::MessageOut(SYSTEMD_DESTINATION.c_str(), - SYSTEMD_PATH.c_str(), - SYSTEMD_MANAGER_INTERFACE.c_str(), - method.c_str()); + return DBus::MessageOut(SYSTEMD_DESTINATION, + SYSTEMD_PATH, + SYSTEMD_MANAGER_INTERFACE, + method); } std::string ServiceManager::handleObjectPathMsgReply(DBus::MessageIn &messageIn) diff --git a/src/common/tests_common.cpp b/src/common/tests_common.cpp index 235b062..b4d0d33 100644 --- a/src/common/tests_common.cpp +++ b/src/common/tests_common.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 - 2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2013-2020 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. @@ -22,16 +22,12 @@ */ #include "tests_common.h" -#include #include #include #include #include #include -#include #include -#include -#include bool smack_check(void) { @@ -65,56 +61,6 @@ int drop_root_privileges(uid_t appUid, gid_t appGid) return 1; } -/* - * Add a new group to the current process groups. - */ -void add_process_group(const char* group_name) -{ - // get group ID by group name - group *gr = getgrnam(group_name); - RUNNER_ASSERT_ERRNO_MSG(gr != nullptr, "getgrnam failed on '" << group_name << "' group"); - const gid_t new_group_id = gr->gr_gid; - - // get number of groups that the current process belongs to - int ngroups = getgroups(0, nullptr); - - //allocate groups table + space for new group entry - std::vector groups(ngroups + 1); - getgroups(ngroups, groups.data()); - - // check if the process already belongs to the group - if (std::find(groups.begin(), groups.end(), new_group_id) != groups.end()) return; - - // add new group & apply change - groups[ngroups] = new_group_id; - int ret = setgroups(groups.size(), groups.data()); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "setgroups() failed"); -} - -/* - * Remove specific group from the current process groups. - */ -void remove_process_group(const char* group_name) -{ - // get group ID by group name - group *gr = getgrnam(group_name); - RUNNER_ASSERT_ERRNO_MSG(gr != nullptr, "getgrnam failed on '" << group_name << "' group"); - const gid_t new_group_id = gr->gr_gid; - - int ngroups = getgroups(0, nullptr); - std::vector groups(ngroups); - getgroups(ngroups, groups.data()); - - // remove group from the list - groups.erase(std::remove(groups.begin(), groups.end(), new_group_id), groups.end()); - - if (groups.size() != (size_t)ngroups) { - // apply change - int ret = setgroups(groups.size(), groups.data()); - RUNNER_ASSERT_ERRNO_MSG(ret == 0, "setgroups() failed"); - } -} - std::string formatCstr(const char *cstr) { if (!cstr) @@ -166,7 +112,7 @@ int files_compare(int fd1, int fd2) return result; } -void mkdirSafe(const std::string &path, mode_t mode) +static void mkdirSafe(const std::string &path, mode_t mode) { RUNNER_ASSERT_ERRNO_MSG(0 == mkdir(path.c_str(), mode) || errno == EEXIST, "mkdir for <" << path << "> with mode <" << mode << "> failed"); @@ -182,50 +128,6 @@ void mktreeSafe(const std::string &path, mode_t mode) mkdirSafe(path, mode); } -void creatSafe(const std::string &path, mode_t mode) -{ - RUNNER_ASSERT_ERRNO_MSG(-1 != creat(path.c_str(), mode), - "creat for <" << path << "> with mode <" << mode << "> failed"); -} - -void symlinkSafe(const std::string &targetPath, const std::string &linkPath) -{ - RUNNER_ASSERT_ERRNO_MSG(0 == symlink(targetPath.c_str(), linkPath.c_str()), - "symlink for <" << linkPath << "> to <" << targetPath << "> failed"); -} - -void removeDir(const std::string &path) -{ - DIR *d = opendir(path.c_str()); - - if (nullptr == d) { - RUNNER_ASSERT_ERRNO_MSG(errno == ENOENT, "opendir of <" << path << "> failed"); - return; - } - - struct dirent *dirEntry; - while (nullptr != (dirEntry = readdir(d))) { - std::string entryName(dirEntry->d_name); - if (entryName == "." || entryName == "..") - continue; - - std::string entryPath(path + "/" + entryName); - struct stat st; - - RUNNER_ASSERT_ERRNO_MSG(0 == lstat(entryPath.c_str(), &st), - "stat for <" << entryPath << "> failed"); - if (S_ISDIR(st.st_mode)) - removeDir(entryPath); - else - RUNNER_ASSERT_ERRNO_MSG(0 == unlink(entryPath.c_str()), - "unlink for <" << entryPath << "> failed"); - } - - closedir(d); - - RUNNER_ASSERT_ERRNO_MSG(0 == rmdir(path.c_str()), "rmdir for <" << path << "> failed"); -} - void waitPid(pid_t pid) { int status; diff --git a/src/common/tests_common.h b/src/common/tests_common.h index bfb46d9..da78ac9 100644 --- a/src/common/tests_common.h +++ b/src/common/tests_common.h @@ -34,28 +34,16 @@ #include #include #include -#include #include const uid_t APP_UID = 5001; const gid_t APP_GID = 100; -const uid_t APP_UID_2 = 5200; -const gid_t APP_GID_2 = 5200; -const uid_t DB_ALARM_UID = 6001; -const gid_t DB_ALARM_GID = 6001; -const std::string TMP_DIR("/tmp"); bool smack_check(void); int drop_root_privileges(uid_t appUid = APP_UID, gid_t appGid = APP_GID); -void add_process_group(const char* group_name); -void remove_process_group(const char* group_name); std::string formatCstr(const char *cstr); int files_compare(int fd1, int fd2); -void mkdirSafe(const std::string &path, mode_t mode); void mktreeSafe(const std::string &path, mode_t mode); -void creatSafe(const std::string &path, mode_t mode); -void symlinkSafe(const std::string &targetPath, const std::string &linkPath); -void removeDir(const std::string &path); void waitPid(pid_t pid); pid_t runInChild(const std::function &process); @@ -133,20 +121,4 @@ void runInChildParentWait(const std::function &process); } \ void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED) -#define RUNNER_MULTIPROCESS_TEST_NOSMACK(Proc, ...) \ - void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple); \ - void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple); \ - static int Static##Proc##Init() \ - { \ - if (!smack_check()) \ - DPL::Test::TestRunnerSingleton::Instance().RegisterTest( \ - new DPL::Test::TestCaseExtended<__VA_ARGS__>(#Proc, &Proc)); \ - return 0; \ - } \ - const int DPL_UNUSED Static##Proc##InitVar = Static##Proc##Init(); \ - void Proc(std::tuple<__VA_ARGS__> &optionalArgsTuple) { \ - DPL::Test::RunMultiProc(std::bind(Proc##Multi, optionalArgsTuple)); \ - } \ - void Proc##Multi(std::tuple<__VA_ARGS__> &optionalArgsTuple DPL_UNUSED) - #endif diff --git a/src/cynara-tests/common/cynara_test_commons.cpp b/src/cynara-tests/common/cynara_test_commons.cpp index 91a93f4..483681f 100644 --- a/src/cynara-tests/common/cynara_test_commons.cpp +++ b/src/cynara-tests/common/cynara_test_commons.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2020 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. @@ -40,7 +40,7 @@ void loadServicePlugins(const DirectoryPaths &pluginDirectories) FileOperations::removeDirFiles(CynaraTestConsts::SERVICE_PLUGINS_DIR); for (const auto &dir : pluginDirectories) - FileOperations::copyCynaraFiles(dir.c_str(), CynaraTestConsts::SERVICE_PLUGINS_DIR); + FileOperations::copyCynaraFiles(dir, CynaraTestConsts::SERVICE_PLUGINS_DIR); } void restartCynaraService() diff --git a/src/cynara-tests/common/cynara_test_env.cpp b/src/cynara-tests/common/cynara_test_env.cpp index 7b9a1a9..7740f9d 100644 --- a/src/cynara-tests/common/cynara_test_env.cpp +++ b/src/cynara-tests/common/cynara_test_env.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2020 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. @@ -36,7 +36,7 @@ CynaraTestEnv::~CynaraTestEnv() void CynaraTestEnv::init(const std::string &testName) { - m_saveDir = TMP_DIR + "/" + testName; + m_saveDir = "/tmp/" + testName; m_dbSaveDir = m_saveDir + "/db"; m_defaultDir = "/etc/security-tests/db_patterns/default"; m_pluginsToInstallDir = "/opt/plugins_to_install"; diff --git a/src/cynara-tests/common/cynara_test_file_operations.cpp b/src/cynara-tests/common/cynara_test_file_operations.cpp index 1f7a5da..cf5b4c1 100644 --- a/src/cynara-tests/common/cynara_test_file_operations.cpp +++ b/src/cynara-tests/common/cynara_test_file_operations.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2015-2020 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. @@ -35,7 +35,9 @@ namespace FileOperations { -static int removeFile(const char *fpath, const struct stat * /*sb*/, +namespace { + +int removeFile(const char *fpath, const struct stat * /*sb*/, int tflag, struct FTW * /*ftwbuf*/) { if (tflag == FTW_F) @@ -45,18 +47,18 @@ static int removeFile(const char *fpath, const struct stat * /*sb*/, return 0; } -bool dirExists(const std::string &directory) +void syncElem(const std::string &filename, int flags, mode_t mode) { - struct stat st; - int ret = stat(directory.c_str(), &st); - if (ret == -1 && errno == ENOENT) { - return false; - } else if (ret == -1) { - RUNNER_ASSERT_ERRNO_MSG(false, "Cannot stat " << directory - << " not due to its nonexistence"); - } - RUNNER_ASSERT_MSG(st.st_mode & S_IFDIR, directory << " is not a directory"); - return true; + int fileFd = TEMP_FAILURE_RETRY(open(filename.c_str(), flags, mode)); + RUNNER_ASSERT_ERRNO_MSG(fileFd != -1, "open failed name=" << filename); + FdUniquePtr fdPtr(&fileFd); + + int ret = fsync(fileFd); + RUNNER_ASSERT_ERRNO_MSG(ret != -1, "fsync failed name=" << filename); +} + +void syncDir(const std::string &dirname, mode_t mode = S_IRUSR | S_IWUSR) { + syncElem(dirname, O_DIRECTORY, mode); } void copyCynaraFile(const std::string &src, const std::string &dst) @@ -100,6 +102,22 @@ void copyCynaraFile(const std::string &src, const std::string &dst) RUNNER_ASSERT_ERRNO_MSG(ret != -1, "fsync failed"); } +} // namespace + +bool dirExists(const std::string &directory) +{ + struct stat st; + int ret = stat(directory.c_str(), &st); + if (ret == -1 && errno == ENOENT) { + return false; + } else if (ret == -1) { + RUNNER_ASSERT_ERRNO_MSG(false, "Cannot stat " << directory + << " not due to its nonexistence"); + } + RUNNER_ASSERT_MSG(st.st_mode & S_IFDIR, directory << " is not a directory"); + return true; +} + void copyCynaraFiles(const std::string &source, const std::string &destination) { DIR *dirPtr = nullptr; @@ -121,20 +139,6 @@ void copyCynaraFiles(const std::string &source, const std::string &destination) syncDir(destination); } -void syncElem(const std::string &filename, int flags, mode_t mode) -{ - int fileFd = TEMP_FAILURE_RETRY(open(filename.c_str(), flags, mode)); - RUNNER_ASSERT_ERRNO_MSG(fileFd != -1, "open failed name=" << filename); - FdUniquePtr fdPtr(&fileFd); - - int ret = fsync(fileFd); - RUNNER_ASSERT_ERRNO_MSG(ret != -1, "fsync failed name=" << filename); -} - -void syncDir(const std::string &dirname, mode_t mode) { - syncElem(dirname, O_DIRECTORY, mode); -} - void makeDir(const std::string &directory) { RUNNER_ASSERT_ERRNO_MSG(!mkdir(directory.c_str(), S_IRWXU | S_IRWXG | S_IRWXO), diff --git a/src/cynara-tests/common/cynara_test_file_operations.h b/src/cynara-tests/common/cynara_test_file_operations.h index d3acdb8..d32008d 100644 --- a/src/cynara-tests/common/cynara_test_file_operations.h +++ b/src/cynara-tests/common/cynara_test_file_operations.h @@ -17,17 +17,13 @@ #ifndef CYNARA_TEST_FILE_OPERATIONS_H #define CYNARA_TEST_FILE_OPERATIONS_H -#include #include namespace FileOperations { bool dirExists(const std::string &directory); -void copyCynaraFile(const std::string &src, const std::string &dst); void copyCynaraFiles(const std::string &source, const std::string &destination); -void syncElem(const std::string &filename, int flags = O_RDONLY, mode_t mode = S_IRUSR | S_IWUSR); -void syncDir(const std::string &dirname, mode_t mode = S_IRUSR | S_IWUSR); void makeDir(const std::string &directory); void removeDirFiles(const std::string &dir); void removeDirIfExists(const std::string &dir); diff --git a/src/framework/include/dpl/exception.h b/src/framework/include/dpl/exception.h index eb5cfc7..214a8cf 100644 --- a/src/framework/include/dpl/exception.h +++ b/src/framework/include/dpl/exception.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2011-2020 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. @@ -114,12 +114,12 @@ class Exception static void DisplayKnownException(const Exception& e) { - LogUnhandledException(KnownExceptionToString(e).c_str()); + LogUnhandledException(KnownExceptionToString(e)); } static void DisplayUnknownException() { - LogUnhandledException(UnknownExceptionToString().c_str()); + LogUnhandledException(UnknownExceptionToString()); } Exception(const Exception &other) diff --git a/src/framework/src/test_results_collector_summary.cpp b/src/framework/src/test_results_collector_summary.cpp index efcaa31..b9bb8f2 100644 --- a/src/framework/src/test_results_collector_summary.cpp +++ b/src/framework/src/test_results_collector_summary.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2014-2020 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. @@ -76,7 +76,7 @@ void SummaryCollector::Finish() void SummaryCollector::writeStats(bool segfault) { - m_output.open(m_filename.c_str(), std::ofstream::out | std::ofstream::trunc); + m_output.open(m_filename, std::ofstream::out | std::ofstream::trunc); if (!m_output) { LogPedantic("Could not open file " << m_filename << " for writing"); return; diff --git a/src/security-manager-tests/common/app_install_helper_ext.cpp b/src/security-manager-tests/common/app_install_helper_ext.cpp index 734a09f..878dfc1 100644 --- a/src/security-manager-tests/common/app_install_helper_ext.cpp +++ b/src/security-manager-tests/common/app_install_helper_ext.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2020 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. @@ -101,7 +101,7 @@ void AppInstallHelperExt::checkPrivileges(const PrivilegeVector &allowedPrivs, int result; for (auto &priv : allowedPrivs) { - ctc.check(smackLabel.c_str(), "", user, priv.getName().c_str(), CYNARA_API_ACCESS_ALLOWED); + ctc.check(smackLabel, "", user, priv.getName(), CYNARA_API_ACCESS_ALLOWED); Api::appHasPrivilege(m_appName, priv, m_uidGid, result); RUNNER_ASSERT_MSG(result == 1, @@ -109,7 +109,7 @@ void AppInstallHelperExt::checkPrivileges(const PrivilegeVector &allowedPrivs, } for (auto &priv : deniedPrivs) { - ctc.check(smackLabel.c_str(), "", user, priv.getName().c_str(), CYNARA_API_ACCESS_DENIED); + ctc.check(smackLabel, "", user, priv.getName(), CYNARA_API_ACCESS_DENIED); Api::appHasPrivilege(m_appName, priv, m_uidGid, result); RUNNER_ASSERT_MSG(result == 0, diff --git a/src/security-manager-tests/common/scoped_app_launcher.cpp b/src/security-manager-tests/common/scoped_app_launcher.cpp index bde5681..6861bab 100644 --- a/src/security-manager-tests/common/scoped_app_launcher.cpp +++ b/src/security-manager-tests/common/scoped_app_launcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2020 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. @@ -39,7 +39,7 @@ ScopedAppLauncher::ScopedAppLauncher(const AppInstallHelper& app, RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(app.getUID(), app.getGID()) == 0, "launcher failed"); Api::prepareAppCandidate(); - Api::prepareApp(app.getAppId().c_str()); + Api::prepareApp(app.getAppId()); runInAppContext(); } catch (...) { m_syncPipe.post(); diff --git a/src/security-manager-tests/test_cases.cpp b/src/security-manager-tests/test_cases.cpp index c46e6e0..93d6cea 100644 --- a/src/security-manager-tests/test_cases.cpp +++ b/src/security-manager-tests/test_cases.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 - 2020 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2020 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. @@ -751,8 +751,8 @@ RUNNER_TEST(security_manager_22_security_manager_cmd_install) const std::string appopt = " --app=" + app_id; const std::string uidopt = " --uid=" + user.getUidString(); - mktreeSafe(path1.c_str(), 0); - mktreeSafe(path2.c_str(), 0); + mktreeSafe(path1, 0); + mktreeSafe(path2, 0); const std::string installcmd = "security-manager-cmd --install " + appopt + pkgopt + uidopt; diff --git a/src/security-manager-tests/test_cases_prepare_app.cpp b/src/security-manager-tests/test_cases_prepare_app.cpp index 4ad16d4..ff00627 100644 --- a/src/security-manager-tests/test_cases_prepare_app.cpp +++ b/src/security-manager-tests/test_cases_prepare_app.cpp @@ -131,7 +131,7 @@ ino_t getFileInode(const std::string &path) std::string getTextFileContents(const std::string &path) { - std::ifstream in(path.c_str()); + std::ifstream in(path); if (in.fail()) return std::string(); std::stringstream ss; @@ -172,13 +172,13 @@ RUNNER_CHILD_TEST(security_manager_100_synchronize_credentials_test) for (size_t i = 0; i < THREADS; i++) threads[i].run(i, expectedLabel); - Api::prepareApp(app.getAppId().c_str()); + Api::prepareApp(app.getAppId()); } RUNNER_ASSERT_MSG(thread_errors.empty(), std::endl << thread_errors); exit(0); } else { waitPid(pid); - Api::cleanupApp(app.getAppId().c_str(), tmpUser.getUid(), pid); + Api::cleanupApp(app.getAppId(), tmpUser.getUid(), pid); } } @@ -225,7 +225,7 @@ RUNNER_CHILD_TEST(security_manager_101_create_namespace_test) synchPipe.claimParentEp(); RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed"); Api::prepareAppCandidate(); - Api::prepareApp(app.getAppId().c_str()); + Api::prepareApp(app.getAppId()); synchPipe.post(); synchPipe.wait(); @@ -252,7 +252,7 @@ RUNNER_CHILD_TEST(security_manager_101_create_namespace_test) synchPipe.post(); waitPid(pid); - Api::cleanupApp(app.getAppId().c_str(), tmpUser.getUid(), pid); + Api::cleanupApp(app.getAppId(), tmpUser.getUid(), pid); } } @@ -271,7 +271,7 @@ RUNNER_CHILD_TEST(security_manager_102_check_propagation_test) synchPipe.claimParentEp(); RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed"); Api::prepareAppCandidate(); - Api::prepareApp(app.getAppId().c_str()); + Api::prepareApp(app.getAppId()); synchPipe.post(); synchPipe.wait(); @@ -296,7 +296,7 @@ RUNNER_CHILD_TEST(security_manager_102_check_propagation_test) synchPipe.post(); waitPid(pid); - Api::cleanupApp(app.getAppId().c_str(), tmpUser.getUid(), pid); + Api::cleanupApp(app.getAppId(), tmpUser.getUid(), pid); } } @@ -316,7 +316,7 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test) synchPipe.claimParentEp(); RUNNER_ASSERT_ERRNO_MSG(setLauncherSecurityAttributes(tmpUser) == 0, "launcher failed"); Api::prepareAppCandidate(); - Api::prepareApp(app.getAppId().c_str()); + Api::prepareApp(app.getAppId()); synchPipe.post(); synchPipe.wait(); @@ -367,7 +367,7 @@ RUNNER_CHILD_TEST(security_manager_103_policy_change_test) synchPipe.post(); waitPid(pid); - Api::cleanupApp(app.getAppId().c_str(), tmpUser.getUid(), pid); + Api::cleanupApp(app.getAppId(), tmpUser.getUid(), pid); } } diff --git a/src/security-manager-tests/test_cases_public_sharing.cpp b/src/security-manager-tests/test_cases_public_sharing.cpp index b71ad04..c4f0078 100644 --- a/src/security-manager-tests/test_cases_public_sharing.cpp +++ b/src/security-manager-tests/test_cases_public_sharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2019 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2016-2020 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. @@ -65,13 +65,13 @@ static void runAccessTest(uid_t uid, gid_t gid, const std::string &appId, if (pid == 0) { setLauncherSecurityAttributes(uid, gid); Api::prepareAppCandidate(); - Api::prepareApp(appId.c_str()); + Api::prepareApp(appId); f(); exit(0); } else { waitPid(pid); - Api::cleanupApp(appId.c_str(), uid, pid); + Api::cleanupApp(appId, uid, pid); } } -- 2.7.4