From: Zofia Abramowska Date: Thu, 15 Sep 2016 13:43:09 +0000 (+0200) Subject: SM: Adjust creds tests to nonhybrid apps X-Git-Tag: security-manager_5.5_testing~20^2~42 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=693ca74061fc66f1ddd88ac10a5ccf29bfac91a3;p=platform%2Fcore%2Ftest%2Fsecurity-tests.git SM: Adjust creds tests to nonhybrid apps Change-Id: Ib91793dc8dc7a1cc5659f8e38182929b45e465be --- diff --git a/src/security-manager-tests/common/sm_api.cpp b/src/security-manager-tests/common/sm_api.cpp index f356efbe..99fa7f71 100644 --- a/src/security-manager-tests/common/sm_api.cpp +++ b/src/security-manager-tests/common/sm_api.cpp @@ -206,14 +206,6 @@ void getPkgIdBySocket(int socketFd, std::string *pkgId, std::string *appId, lib_ << " Result: " << result << ";" << " Expected result: " << expectedResult); - if (pkgId && result == SECURITY_MANAGER_SUCCESS) { - RUNNER_ASSERT_MSG(pkg_Id != nullptr, "getting pkg and app id did not allocate memory"); - } - - if (appId && result == SECURITY_MANAGER_SUCCESS) { - RUNNER_ASSERT_MSG(app_Id != nullptr, "getting pkg and app id did not allocate memory"); - } - if (pkg_Id) { *pkgId = pkg_Id; free(pkg_Id); @@ -240,14 +232,6 @@ void getPkgIdByPid(pid_t pid, std::string *pkgId, std::string *appId, lib_retcod << " Result: " << result << ";" << " Expected result: " << expectedResult); - if (pkgId && result == SECURITY_MANAGER_SUCCESS) { - RUNNER_ASSERT_MSG(pkg_Id != nullptr, "getting pkg and app id did not allocate memory"); - } - - if (appId && result == SECURITY_MANAGER_SUCCESS) { - RUNNER_ASSERT_MSG(app_Id != nullptr, "getting pkg and app id did not allocate memory"); - } - if (pkg_Id) { *pkgId = pkg_Id; free(pkg_Id); @@ -275,14 +259,6 @@ void getPkgIdByCynaraClient(const std::string &client, std::string *pkgId, std:: << " Result: " << result << ";" << " Expected result: " << expectedResult); - if (pkgId && result == SECURITY_MANAGER_SUCCESS) { - RUNNER_ASSERT_MSG(pkg_Id != nullptr, "getting pkg and app id did not allocate memory"); - } - - if (appId && result == SECURITY_MANAGER_SUCCESS) { - RUNNER_ASSERT_MSG(app_Id != nullptr, "getting pkg and app id did not allocate memory"); - } - if (pkg_Id) { *pkgId = pkg_Id; free(pkg_Id); diff --git a/src/security-manager-tests/test_cases_credentials.cpp b/src/security-manager-tests/test_cases_credentials.cpp index 504a5166..90d74a96 100644 --- a/src/security-manager-tests/test_cases_credentials.cpp +++ b/src/security-manager-tests/test_cases_credentials.cpp @@ -90,26 +90,30 @@ void clientTestTemplate(SocketAssertionFn assertion, const std::string &scope, c assertion(sock, pid); } -RUNNER_CHILD_TEST(security_manager_51a_get_id_by_socket) -{ +void test_51a_get_id_by_socket(bool isHybrid) { const char *const sm_app_id = "sm_test_51a_app"; const char *const sm_pkg_id = "sm_test_51a_pkg"; InstallRequest requestInst; requestInst.setAppId(sm_app_id); requestInst.setPkgId(sm_pkg_id); + if (isHybrid) + requestInst.setHybrid(); Api::install(requestInst); - std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id); + std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id, isHybrid); clientTestTemplate([&] (int sock, pid_t) { std::string rcvPkgId, rcvAppId; Api::getPkgIdBySocket(sock, &rcvPkgId, &rcvAppId); RUNNER_ASSERT_MSG(rcvPkgId == sm_pkg_id, "pkgIds don't match ret = " << rcvPkgId << "; expected = " << sm_pkg_id); - RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId - << "; expected = " << sm_app_id); + if (isHybrid) + RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId + << "; expected = " << sm_app_id); + else + RUNNER_ASSERT_MSG(rcvAppId.empty(), "magically acquired appId from nonhybrid app"); }, "tcsm27a", smackLabel); InstallRequest requestUninst; @@ -118,7 +122,17 @@ RUNNER_CHILD_TEST(security_manager_51a_get_id_by_socket) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_51b_get_id_by_socket) +RUNNER_CHILD_TEST(security_manager_51a_get_id_by_socket_hybrid) +{ + test_51a_get_id_by_socket(true); +} + +RUNNER_CHILD_TEST(security_manager_51a_get_id_by_socket_nonhybrid) +{ + test_51a_get_id_by_socket(false); +} + +RUNNER_CHILD_TEST(security_manager_51b_get_id_by_socket_bad_fd) { const char *const sm_app_id = "sm_test_51b_app"; const char *const sm_pkg_id = "sm_test_51b_pkg"; @@ -142,7 +156,7 @@ RUNNER_CHILD_TEST(security_manager_51b_get_id_by_socket) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_51c_get_id_by_socket) +RUNNER_CHILD_TEST(security_manager_51c_get_id_by_socket_only_pkg) { const char *const sm_app_id = "sm_test_51c_app"; const char *const sm_pkg_id = "sm_test_51c_pkg"; @@ -168,7 +182,7 @@ RUNNER_CHILD_TEST(security_manager_51c_get_id_by_socket) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_51d_get_id_by_socket) +RUNNER_CHILD_TEST(security_manager_51d_get_id_by_socket_only_appid) { const char *const sm_app_id = "sm_test_51d_app"; const char *const sm_pkg_id = "sm_test_51d_pkg"; @@ -176,10 +190,11 @@ RUNNER_CHILD_TEST(security_manager_51d_get_id_by_socket) InstallRequest requestInst; requestInst.setAppId(sm_app_id); requestInst.setPkgId(sm_pkg_id); + requestInst.setHybrid(); Api::install(requestInst); - std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id); + std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id, true); clientTestTemplate([&] (int sock, pid_t) { std::string rcvAppId; @@ -194,7 +209,7 @@ RUNNER_CHILD_TEST(security_manager_51d_get_id_by_socket) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_51e_get_id_by_socket) +RUNNER_CHILD_TEST(security_manager_51e_get_id_by_socket_nulls) { const char *const sm_app_id = "sm_test_51e_app"; const char *const sm_pkg_id = "sm_test_51e_pkg"; @@ -217,26 +232,29 @@ RUNNER_CHILD_TEST(security_manager_51e_get_id_by_socket) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_52a_get_id_by_pid) -{ +void test_52a_get_id_by_pid(bool isHybrid) { const char *const sm_app_id = "sm_test_52a_app"; const char *const sm_pkg_id = "sm_test_52a_pkg"; InstallRequest requestInst; requestInst.setAppId(sm_app_id); requestInst.setPkgId(sm_pkg_id); - + if (isHybrid) + requestInst.setHybrid(); Api::install(requestInst); - std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id); + std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id, isHybrid); clientTestTemplate([&] (int, pid_t pid) { std::string rcvPkgId, rcvAppId; Api::getPkgIdByPid(pid, &rcvPkgId, &rcvAppId); RUNNER_ASSERT_MSG(rcvPkgId == sm_pkg_id, "pkgIds don't match ret = " << rcvPkgId << "; expected = " << sm_pkg_id); - RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId - << "; expected = " << sm_app_id); + if (isHybrid) + RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId + << "; expected = " << sm_app_id); + else + RUNNER_ASSERT_MSG(rcvAppId.empty(), "magically acquired appId from nonhybrid app"); }, "tcsm28a", smackLabel); InstallRequest requestUninst; @@ -245,7 +263,17 @@ RUNNER_CHILD_TEST(security_manager_52a_get_id_by_pid) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_52b_get_id_by_pid) +RUNNER_CHILD_TEST(security_manager_52a_get_id_by_pid_hybrid) +{ + test_52a_get_id_by_pid(true); +} + +RUNNER_CHILD_TEST(security_manager_52a_get_id_by_pid_nonhybrid) +{ + test_52a_get_id_by_pid(false); +} + +RUNNER_CHILD_TEST(security_manager_52b_get_id_by_pid_bad_fd) { const char *const sm_app_id = "sm_test_52b_app"; const char *const sm_pkg_id = "sm_test_52b_pkg"; @@ -269,7 +297,7 @@ RUNNER_CHILD_TEST(security_manager_52b_get_id_by_pid) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_52c_get_id_by_pid) +RUNNER_CHILD_TEST(security_manager_52c_get_id_by_pid_only_pkg) { const char *const sm_app_id = "sm_test_52c_app"; const char *const sm_pkg_id = "sm_test_52c_pkg"; @@ -295,7 +323,7 @@ RUNNER_CHILD_TEST(security_manager_52c_get_id_by_pid) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_52d_get_id_by_pid) +RUNNER_CHILD_TEST(security_manager_52d_get_id_by_pid_only_appid) { const char *const sm_app_id = "sm_test_52d_app"; const char *const sm_pkg_id = "sm_test_52d_pkg"; @@ -303,10 +331,11 @@ RUNNER_CHILD_TEST(security_manager_52d_get_id_by_pid) InstallRequest requestInst; requestInst.setAppId(sm_app_id); requestInst.setPkgId(sm_pkg_id); + requestInst.setHybrid(); Api::install(requestInst); - std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id); + std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id, true); clientTestTemplate([&] (int, pid_t pid) { std::string rcvAppId; @@ -321,7 +350,7 @@ RUNNER_CHILD_TEST(security_manager_52d_get_id_by_pid) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_52e_get_id_by_pid) +RUNNER_CHILD_TEST(security_manager_52e_get_id_by_pid_nulls) { const char *const sm_app_id = "sm_test_52e_app"; const char *const sm_pkg_id = "sm_test_52e_pkg"; @@ -344,18 +373,19 @@ RUNNER_CHILD_TEST(security_manager_52e_get_id_by_pid) Api::uninstall(requestUninst); } -RUNNER_CHILD_TEST(security_manager_53a_get_id_by_cynara_client) -{ +void test_53a_get_id_by_cynara_client(bool isHybrid) { const char *const sm_app_id = "sm_test_53a_app"; const char *const sm_pkg_id = "sm_test_53a_pkg"; InstallRequest requestInst; requestInst.setAppId(sm_app_id); requestInst.setPkgId(sm_pkg_id); + if (isHybrid) + requestInst.setHybrid(); Api::install(requestInst); - std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id); + std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id, isHybrid); clientTestTemplate([&] (int sock, pid_t) { std::string rcvPkgId, rcvAppId; @@ -364,8 +394,9 @@ RUNNER_CHILD_TEST(security_manager_53a_get_id_by_cynara_client) Api::getPkgIdByCynaraClient(cynaraClient.get(), &rcvPkgId, &rcvAppId); RUNNER_ASSERT_MSG(rcvPkgId == sm_pkg_id, "pkgIds don't match ret = " << rcvPkgId << "; expected = " << sm_pkg_id); - RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId - << "; expected = " << sm_app_id); + if (isHybrid) + RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId + << "; expected = " << sm_app_id); }, "tcsmc53a", smackLabel); InstallRequest requestUninst; @@ -374,6 +405,16 @@ RUNNER_CHILD_TEST(security_manager_53a_get_id_by_cynara_client) Api::uninstall(requestUninst); } +RUNNER_CHILD_TEST(security_manager_53a_get_id_by_cynara_client_hybrid) +{ + test_53a_get_id_by_cynara_client(true); +} + +RUNNER_CHILD_TEST(security_manager_53a_get_id_by_cynara_client_nonhybrid) +{ + test_53a_get_id_by_cynara_client(false); +} + RUNNER_CHILD_TEST(security_manager_53b_get_id_by_cynara_client_wrong_client) { @@ -418,10 +459,11 @@ RUNNER_CHILD_TEST(security_manager_53d_get_id_by_cynara_client_only_appid) InstallRequest requestInst; requestInst.setAppId(sm_app_id); requestInst.setPkgId(sm_pkg_id); + requestInst.setHybrid(); Api::install(requestInst); - std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id); + std::string smackLabel = generateProcessLabel(sm_app_id, sm_pkg_id, true); clientTestTemplate([&] (int sock, pid_t) { std::string rcvAppId;