SM: Code cleanup - separate credentials tests 27/85327/1
authorZofia Abramowska <z.abramowska@samsung.com>
Wed, 24 Aug 2016 14:27:40 +0000 (16:27 +0200)
committerZofia Abramowska <z.abramowska@samsung.com>
Wed, 24 Aug 2016 14:47:42 +0000 (16:47 +0200)
Change-Id: I08cc91f8becc55d28885cc19647afcce6c56115d

src/security-manager-tests/CMakeLists.txt
src/security-manager-tests/security_manager_tests.cpp
src/security-manager-tests/test_cases_credentials.cpp [new file with mode: 0644]

index 718f2ce6d201b588361556c6896eaac75f283140..dec009210a6d15b9e8ad91e68623484c45ffbc77 100644 (file)
@@ -40,6 +40,7 @@ SET(SEC_MGR_SOURCES
     ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_commons.cpp
     ${PROJECT_SOURCE_DIR}/src/cynara-tests/common/cynara_test_file_operations.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases.cpp
+    ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_credentials.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_privacy_manager.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_private_sharing.cpp
     ${PROJECT_SOURCE_DIR}/src/security-manager-tests/test_cases_trusted_sharing.cpp
index e1750510b42cb8e106303aed72e2745acafc475f..8718a6411eb1218780e4d2008448dda13046aa02 100644 (file)
@@ -584,328 +584,6 @@ RUNNER_TEST(security_manager_27p_API30_app_uninstall)
 }
 
 
-
-RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_CREDENTIAL_API)
-
-class ProcessCredentials {
-public:
-    ProcessCredentials(const std::string &smackLabel) : m_label(smackLabel) {}
-
-    const std::string &label(void) const {
-        return m_label;
-    }
-
-    uid_t uid(void) const {
-        return TzPlatformConfig::getGlobalUserId();
-    }
-
-    gid_t gid(void) const {
-        return PasswdAccess::gid("users");
-    }
-
-private:
-    std::string m_label;
-};
-
-pid_t runInChild(const std::function<void(void)> &process) {
-    pid_t pid = fork();
-    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
-
-    if (pid == 0) {
-        process();
-        exit(EXIT_SUCCESS);
-    }
-
-    return pid;
-}
-
-void udsServer(SynchronizationPipe &pipe, const struct sockaddr_un &sockaddr,
-               const struct ProcessCredentials &peerCredentials) {
-    SecurityServer::AccessProvider ap(peerCredentials.label());
-    ap.applyAndSwithToUser(peerCredentials.uid(), peerCredentials.gid());
-    pipe.claimChildEp();
-
-    int sock = UDSHelpers::createServer(&sockaddr);
-    SockUniquePtr sockPtr(&sock);
-    pipe.post();
-    int clientSock = UDSHelpers::acceptClient(sock);
-
-    UDSHelpers::waitForDisconnect(clientSock);
-}
-
-typedef std::function<void(int sock, pid_t pid)> SocketAssertionFn;
-
-void clientTestTemplate(SocketAssertionFn assertion, const std::string &scope, const std::string &smackLabel) {
-    const auto sockaddr = UDSHelpers::makeAbstractAddress("test_sm_" + scope + ".socket");
-    const ProcessCredentials peerCredentials(smackLabel);
-
-    SynchronizationPipe pipe;
-
-    pid_t pid = runInChild(std::bind(udsServer, std::ref(pipe), std::cref(sockaddr),
-                           std::cref(peerCredentials)));
-
-    pipe.claimParentEp();
-    pipe.wait();
-    int sock = UDSHelpers::createClient(&sockaddr);
-    SockUniquePtr sockPtr(&sock);
-
-    assertion(sock, pid);
-}
-
-RUNNER_CHILD_TEST(security_manager_51a_get_id_by_socket)
-{
-    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);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    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);
-    }, "tcsm27a", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_51b_get_id_by_socket)
-{
-    const char *const sm_app_id = "sm_test_51b_app";
-    const char *const sm_pkg_id = "sm_test_51b_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int sock, pid_t) {
-        std::string rcvPkgId, rcvAppId;
-        Api::getPkgIdBySocket(sock + 1, &rcvPkgId, &rcvAppId, SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
-    }, "tcsm27b", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_51c_get_id_by_socket)
-{
-    const char *const sm_app_id = "sm_test_51c_app";
-    const char *const sm_pkg_id = "sm_test_51c_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int sock, pid_t) {
-        std::string rcvPkgId;
-        Api::getPkgIdBySocket(sock, &rcvPkgId, nullptr);
-        RUNNER_ASSERT_MSG(rcvPkgId == sm_pkg_id, "pkgIds don't match ret = " << rcvPkgId
-                          << "; expected = " << sm_pkg_id);
-    }, "tcsm27c", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_51d_get_id_by_socket)
-{
-    const char *const sm_app_id = "sm_test_51d_app";
-    const char *const sm_pkg_id = "sm_test_51d_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int sock, pid_t) {
-        std::string rcvAppId;
-        Api::getPkgIdBySocket(sock, nullptr, &rcvAppId);
-        RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId
-                          << "; expected = " << sm_app_id);
-    }, "tcsm27d", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_51e_get_id_by_socket)
-{
-    const char *const sm_app_id = "sm_test_51e_app";
-    const char *const sm_pkg_id = "sm_test_51e_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int sock, pid_t) {
-        Api::getPkgIdBySocket(sock, nullptr, nullptr, SECURITY_MANAGER_ERROR_INPUT_PARAM);
-    }, "tcsm27e", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_52a_get_id_by_pid)
-{
-    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);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    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);
-    }, "tcsm28a", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_52b_get_id_by_pid)
-{
-    const char *const sm_app_id = "sm_test_52b_app";
-    const char *const sm_pkg_id = "sm_test_52b_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int, pid_t pid) {
-        std::string rcvPkgId, rcvAppId;
-        Api::getPkgIdByPid(pid + 1, &rcvPkgId, &rcvAppId, SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
-    }, "tcsm28b", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_52c_get_id_by_pid)
-{
-    const char *const sm_app_id = "sm_test_52c_app";
-    const char *const sm_pkg_id = "sm_test_52c_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int, pid_t pid) {
-        std::string rcvPkgId;
-        Api::getPkgIdByPid(pid, &rcvPkgId, nullptr);
-        RUNNER_ASSERT_MSG(rcvPkgId == sm_pkg_id, "pkgIds don't match ret = " << rcvPkgId
-                          << "; expected = " << sm_pkg_id);
-    }, "tcsm28c", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_52d_get_id_by_pid)
-{
-    const char *const sm_app_id = "sm_test_52d_app";
-    const char *const sm_pkg_id = "sm_test_52d_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int, pid_t pid) {
-        std::string rcvAppId;
-        Api::getPkgIdByPid(pid, nullptr, &rcvAppId);
-        RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId
-                          << "; expected = " << sm_app_id);
-    }, "tcsm28d", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
-RUNNER_CHILD_TEST(security_manager_52e_get_id_by_pid)
-{
-    const char *const sm_app_id = "sm_test_52e_app";
-    const char *const sm_pkg_id = "sm_test_52e_pkg";
-
-    InstallRequest requestInst;
-    requestInst.setAppId(sm_app_id);
-    requestInst.setPkgId(sm_pkg_id);
-
-    Api::install(requestInst);
-
-    std::string smackLabel = generateAppLabel(sm_app_id);
-
-    clientTestTemplate([&] (int sock, pid_t) {
-        Api::getPkgIdByPid(sock, nullptr, nullptr, SECURITY_MANAGER_ERROR_INPUT_PARAM);
-    }, "tcsm28e", smackLabel);
-
-    InstallRequest requestUninst;
-    requestUninst.setAppId(sm_app_id);
-
-    Api::uninstall(requestUninst);
-}
-
 RUNNER_CHILD_TEST(security_manager_53_app_has_privilege)
 {
     const char *const sm_app_id = "sm_test_53_app";
diff --git a/src/security-manager-tests/test_cases_credentials.cpp b/src/security-manager-tests/test_cases_credentials.cpp
new file mode 100644 (file)
index 0000000..d2811e8
--- /dev/null
@@ -0,0 +1,356 @@
+/*
+ * Copyright (c) 2016 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.
+ *    You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing, software
+ *    distributed under the License is distributed on an "AS IS" BASIS,
+ *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *    See the License for the specific language governing permissions and
+ *    limitations under the License.
+ */
+
+#include <cstdlib>
+#include <functional>
+#include <string>
+#include <sys/types.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include <access_provider.h>
+#include <dpl/test/test_runner.h>
+#include <memory.h>
+#include <passwd_access.h>
+#include <sm_api.h>
+#include <sm_commons.h>
+#include <sm_request.h>
+#include <synchronization_pipe.h>
+#include <tests_common.h>
+#include <tzplatform.h>
+#include <uds.h>
+
+RUNNER_TEST_GROUP_INIT(SECURITY_MANAGER_CREDENTIAL_API)
+
+using namespace SecurityManagerTest;
+
+class ProcessCredentials {
+public:
+    ProcessCredentials(const std::string &smackLabel) : m_label(smackLabel) {}
+
+    const std::string &label(void) const {
+        return m_label;
+    }
+
+    uid_t uid(void) const {
+        return TzPlatformConfig::getGlobalUserId();
+    }
+
+    gid_t gid(void) const {
+        return PasswdAccess::gid("users");
+    }
+
+private:
+    std::string m_label;
+};
+
+pid_t runInChild(const std::function<void(void)> &process) {
+    pid_t pid = fork();
+    RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
+
+    if (pid == 0) {
+        process();
+        exit(EXIT_SUCCESS);
+    }
+    return pid;
+}
+
+void udsServer(SynchronizationPipe &pipe, const struct sockaddr_un &sockaddr,
+               const struct ProcessCredentials &peerCredentials) {
+    SecurityServer::AccessProvider ap(peerCredentials.label());
+    ap.applyAndSwithToUser(peerCredentials.uid(), peerCredentials.gid());
+    pipe.claimChildEp();
+
+    int sock = UDSHelpers::createServer(&sockaddr);
+    SockUniquePtr sockPtr(&sock);
+    pipe.post();
+    int clientSock = UDSHelpers::acceptClient(sock);
+
+    UDSHelpers::waitForDisconnect(clientSock);
+}
+
+typedef std::function<void(int sock, pid_t pid)> SocketAssertionFn;
+
+void clientTestTemplate(SocketAssertionFn assertion, const std::string &scope, const std::string &smackLabel) {
+    const auto sockaddr = UDSHelpers::makeAbstractAddress("test_sm_" + scope + ".socket");
+    const ProcessCredentials peerCredentials(smackLabel);
+
+    SynchronizationPipe pipe;
+
+    pid_t pid = runInChild(std::bind(udsServer, std::ref(pipe), std::cref(sockaddr),
+                           std::cref(peerCredentials)));
+
+    pipe.claimParentEp();
+    pipe.wait();
+    int sock = UDSHelpers::createClient(&sockaddr);
+    SockUniquePtr sockPtr(&sock);
+
+    assertion(sock, pid);
+}
+
+RUNNER_CHILD_TEST(security_manager_51a_get_id_by_socket)
+{
+    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);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    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);
+    }, "tcsm27a", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_51b_get_id_by_socket)
+{
+    const char *const sm_app_id = "sm_test_51b_app";
+    const char *const sm_pkg_id = "sm_test_51b_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int sock, pid_t) {
+        std::string rcvPkgId, rcvAppId;
+        Api::getPkgIdBySocket(sock + 1, &rcvPkgId, &rcvAppId, SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
+    }, "tcsm27b", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_51c_get_id_by_socket)
+{
+    const char *const sm_app_id = "sm_test_51c_app";
+    const char *const sm_pkg_id = "sm_test_51c_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int sock, pid_t) {
+        std::string rcvPkgId;
+        Api::getPkgIdBySocket(sock, &rcvPkgId, nullptr);
+        RUNNER_ASSERT_MSG(rcvPkgId == sm_pkg_id, "pkgIds don't match ret = " << rcvPkgId
+                          << "; expected = " << sm_pkg_id);
+    }, "tcsm27c", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_51d_get_id_by_socket)
+{
+    const char *const sm_app_id = "sm_test_51d_app";
+    const char *const sm_pkg_id = "sm_test_51d_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int sock, pid_t) {
+        std::string rcvAppId;
+        Api::getPkgIdBySocket(sock, nullptr, &rcvAppId);
+        RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId
+                          << "; expected = " << sm_app_id);
+    }, "tcsm27d", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_51e_get_id_by_socket)
+{
+    const char *const sm_app_id = "sm_test_51e_app";
+    const char *const sm_pkg_id = "sm_test_51e_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int sock, pid_t) {
+        Api::getPkgIdBySocket(sock, nullptr, nullptr, SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    }, "tcsm27e", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_52a_get_id_by_pid)
+{
+    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);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    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);
+    }, "tcsm28a", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_52b_get_id_by_pid)
+{
+    const char *const sm_app_id = "sm_test_52b_app";
+    const char *const sm_pkg_id = "sm_test_52b_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int, pid_t pid) {
+        std::string rcvPkgId, rcvAppId;
+        Api::getPkgIdByPid(pid + 1, &rcvPkgId, &rcvAppId, SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT);
+    }, "tcsm28b", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_52c_get_id_by_pid)
+{
+    const char *const sm_app_id = "sm_test_52c_app";
+    const char *const sm_pkg_id = "sm_test_52c_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int, pid_t pid) {
+        std::string rcvPkgId;
+        Api::getPkgIdByPid(pid, &rcvPkgId, nullptr);
+        RUNNER_ASSERT_MSG(rcvPkgId == sm_pkg_id, "pkgIds don't match ret = " << rcvPkgId
+                          << "; expected = " << sm_pkg_id);
+    }, "tcsm28c", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_52d_get_id_by_pid)
+{
+    const char *const sm_app_id = "sm_test_52d_app";
+    const char *const sm_pkg_id = "sm_test_52d_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int, pid_t pid) {
+        std::string rcvAppId;
+        Api::getPkgIdByPid(pid, nullptr, &rcvAppId);
+        RUNNER_ASSERT_MSG(rcvAppId == sm_app_id, "appIds don't match ret = " << rcvAppId
+                          << "; expected = " << sm_app_id);
+    }, "tcsm28d", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}
+
+RUNNER_CHILD_TEST(security_manager_52e_get_id_by_pid)
+{
+    const char *const sm_app_id = "sm_test_52e_app";
+    const char *const sm_pkg_id = "sm_test_52e_pkg";
+
+    InstallRequest requestInst;
+    requestInst.setAppId(sm_app_id);
+    requestInst.setPkgId(sm_pkg_id);
+
+    Api::install(requestInst);
+
+    std::string smackLabel = generateAppLabel(sm_app_id);
+
+    clientTestTemplate([&] (int sock, pid_t) {
+        Api::getPkgIdByPid(sock, nullptr, nullptr, SECURITY_MANAGER_ERROR_INPUT_PARAM);
+    }, "tcsm28e", smackLabel);
+
+    InstallRequest requestUninst;
+    requestUninst.setAppId(sm_app_id);
+
+    Api::uninstall(requestUninst);
+}