Merge branch 'tizen' into ckm 02/291202/1
authorDariusz Michaluk <d.michaluk@samsung.com>
Tue, 11 Apr 2023 13:01:14 +0000 (15:01 +0200)
committerDariusz Michaluk <d.michaluk@samsung.com>
Tue, 11 Apr 2023 13:01:14 +0000 (15:01 +0200)
Change-Id: I495f825f5d786a58289f044b9c23b78f7c7b3ab6

packaging/security-tests.manifest
packaging/security-tests.spec
src/CMakeLists.txt
src/cynara-tests/test_cases_helpers.cpp
src/security-manager-tests/test_cases.cpp
src/test-performance-check.sh [deleted file]

index 0f1fc1f..dfda779 100644 (file)
@@ -1,7 +1,5 @@
 <manifest>
     <assign>
-        <filesystem path="/usr/bin/test-performance-check.sh" exec_label="_" />
-
         <filesystem path="/usr/bin/security-manager-tests" exec_label="System::Privileged" />
         <filesystem path="/usr/bin/cynara-tests" exec_label="_" />
         <filesystem path="/usr/bin/ckm-tests" exec_label="User" />
index 51017be..0f99419 100644 (file)
@@ -37,7 +37,6 @@ BuildRequires: pkgconfig(security-privilege-manager)
 BuildRequires: pkgconfig(libsystemd)
 BuildRequires: pkgconfig(device-certificate-manager) >= 2.1
 BuildRequires: openssl1.1
-Requires: perf
 Requires: gdb
 Requires: diffutils
 Requires: iproute2
@@ -100,7 +99,6 @@ echo "security-tests postinst done ..."
 %defattr(-, root, root, -)
 /usr/bin/security-tests.sh
 /usr/bin/security-tests-all.sh
-/usr/bin/test-performance-check.sh
 /usr/bin/setup-nether-tests-nns.sh
 /usr/bin/teardown-nether-tests-nns.sh
 /usr/bin/setup-nether-tests-dns.sh
index 7799501..743513f 100644 (file)
@@ -78,18 +78,6 @@ INSTALL(FILES ${PROJECT_SOURCE_DIR}/src/security-tests-all.sh
                 WORLD_EXECUTE
     )
 
-INSTALL(FILES
-    ${PROJECT_SOURCE_DIR}/src/test-performance-check.sh
-    DESTINATION bin
-    PERMISSIONS OWNER_READ
-                OWNER_WRITE
-                OWNER_EXECUTE
-                GROUP_READ
-                GROUP_EXECUTE
-                WORLD_READ
-                WORLD_EXECUTE
-    )
-
 IF(BUILD_CKM OR BUILD_SM OR BUILD_CYNARA OR BUILD_WEB)
     ADD_SUBDIRECTORY(common)
 ENDIF(BUILD_CKM OR BUILD_SM OR BUILD_CYNARA OR BUILD_WEB)
index 86ec5e0..00ae296 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2020 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2022 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.
 #include <cynara_helpers_creds.h>
 #include <cynara_helpers_dbus.h>
 
+#include <cynara-creds-dbus.h>
 #include <cynara-creds-gdbus.h>
 #include <cynara-creds-self.h>
 #include <scoped_process_label.h>
 
+
+static const cynara_client_creds G_CLIENT_METHOD_DEFAULT = CLIENT_METHOD_DEFAULT;
+static const cynara_client_creds G_CLIENT_METHOD_SMACK   = CLIENT_METHOD_SMACK;
+static const cynara_client_creds G_CLIENT_METHOD_PID     = CLIENT_METHOD_PID;
+
+static const cynara_user_creds G_USER_METHOD_DEFAULT = USER_METHOD_DEFAULT;
+static const cynara_user_creds G_USER_METHOD_UID     = USER_METHOD_UID;
+static const cynara_user_creds G_USER_METHOD_GID     = USER_METHOD_GID;
+
+static const cynara_client_creds G_CLIENT_METHOD_LOW = (cynara_client_creds)-1;
+static const cynara_client_creds G_CLIENT_METHOD_HIGH = (cynara_client_creds)(CLIENT_METHOD_PID+10);
+
+static const cynara_user_creds G_USER_METHOD_LOW = (cynara_user_creds)-1;
+static const cynara_user_creds G_USER_METHOD_HIGH = (cynara_user_creds)(USER_METHOD_GID+10);
+
+
 class ProcessCredentials {
 public:
     ProcessCredentials() {}
@@ -218,6 +235,9 @@ RUNNER_MULTIPROCESS_TEST(tccs07_socket_credentials_pid)
     }, "tccs05");
 }
 
+
+//=====================================DBus===========================================
+
 // TODO: Create utility namespace for DBus, maybe?
 DBusConnectionPtr createDBusConnection(const std::string &name) {
     DBusError err;
@@ -263,7 +283,7 @@ typedef std::function<void(DBusConnectionPtr conn, pid_t pid,
                            const std::string &requestedName,
                            const ProcessCredentials &peerCredentials)> DBusAssertionFn;
 
-void dbusTestTemplate(DBusAssertionFn assertion, const std::string &/*scope*/) {
+void dbusTestTemplate(DBusAssertionFn assertion) {
     std::string requestedName = "tests.dbus.cynara";
     const ProcessCredentials peerCredentials;
 
@@ -279,6 +299,7 @@ void dbusTestTemplate(DBusAssertionFn assertion, const std::string &/*scope*/) {
     pipe.post();
 }
 
+
 RUNNER_TEST_GROUP_INIT(cynara_creds_dbus)
 
 void testDbusClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
@@ -289,7 +310,7 @@ void testDbusClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
         pid_t clientPid = std::stoi(clientPidStr.get());
         RUNNER_ASSERT_MSG(pid == clientPid, "PIDs don't match ret = " << clientPid
                           << "; expected = " << pid);
-    }, "tccd01");
+    });
 }
 
 void testDbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
@@ -300,7 +321,7 @@ void testDbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
         RUNNER_ASSERT_MSG(peerCredentials.label() == label.get(),
                           "Labels don't match ret = " << label.get()
                           << "; expected = " << peerCredentials.label());
-    }, "tccd02");
+    });
 }
 
 RUNNER_MULTIPROCESS_TEST(tccd01_dbus_credentials_client_pid)
@@ -337,7 +358,7 @@ void testDbusUserUid(cynara_user_creds method = USER_METHOD_UID) {
         uid_t uid = std::stoul(uidStr.get());
         RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid
                           << "; expected = "<< peerCredentials.uid());
-    }, "tccd04");
+    });
 }
 
 void testDbusUserGid(cynara_user_creds method = USER_METHOD_GID) {
@@ -346,7 +367,7 @@ void testDbusUserGid(cynara_user_creds method = USER_METHOD_GID) {
                          const ProcessCredentials &) {
         CStringPtr gidStr(CynaraHelperCredentials::dbusGetUser(std::move(conn),
             requestedName.c_str(), method, CYNARA_API_METHOD_NOT_SUPPORTED));
-    }, "tccd04");
+    });
 }
 
 RUNNER_MULTIPROCESS_TEST(tccd04_dbus_credentials_user_uid)
@@ -374,16 +395,342 @@ RUNNER_MULTIPROCESS_TEST(tccd06_dbus_credentials_user_default) {
     }
 }
 
-RUNNER_TEST_SMACK(tccd06_dbus_credentials_pid) {
+RUNNER_TEST_SMACK(tccd07_dbus_credentials_pid) {
     dbusTestTemplate([] (DBusConnectionPtr conn, pid_t expectedPid,
                          const std::string &requestedName, const ProcessCredentials &) {
         auto helperPid = CynaraHelperCredentials::dbusGetPid(std::move(conn),
             requestedName.c_str(), CYNARA_API_SUCCESS);
         RUNNER_ASSERT_MSG(helperPid == expectedPid, "PIDs don't match ret = " << helperPid
                           << "; expected = " << expectedPid);
-    }, "tccd06");
+    });
+}
+
+void testDbusCredsDefault(int expectedResult, char **pClientBuff,
+                          char **pUserBuff, pid_t *pPidCred)
+{
+    // reset variables if set by previous test cases
+    if (pClientBuff != nullptr) *pClientBuff = nullptr;
+    if (pUserBuff != nullptr) *pUserBuff = nullptr;
+    if (pPidCred != nullptr) *pPidCred = -1;
+
+    dbusTestTemplate([&] (DBusConnectionPtr conn, pid_t pid,
+                          const std::string &requestedName,
+                          const ProcessCredentials &peerCredentials) {
+        cynara_user_creds userMethod = getUserDefaultMethod();
+        cynara_client_creds clientMethod = getClientDefaultMethod();
+
+        // exception override
+        if (expectedResult == CYNARA_API_SUCCESS && userMethod == USER_METHOD_GID) {
+            expectedResult = CYNARA_API_METHOD_NOT_SUPPORTED;
+        }
+
+        int ret = cynara_creds_dbus_get_default(conn.get(), requestedName.c_str(),
+                                                pClientBuff, pUserBuff, pPidCred);
+
+        RUNNER_ASSERT_MSG(ret == expectedResult,
+                          "cynara_creds_dbus_get_default returned unexpected result: " << ret <<
+                          "; expected: " << expectedResult);
+
+        if (ret != CYNARA_API_SUCCESS) {
+            return;
+        }
+
+        if (pClientBuff != nullptr) {
+            switch (clientMethod) {
+            case CLIENT_METHOD_SMACK:
+                RUNNER_ASSERT_MSG(*pClientBuff == peerCredentials.label(),
+                                  "Client labels don't match, ret = "
+                                  << *pClientBuff << "; expected = "
+                                  << peerCredentials.label());
+                free(*pClientBuff);
+                break;
+            case CLIENT_METHOD_PID:
+                RUNNER_ASSERT_MSG(*pClientBuff == std::to_string(pid),
+                                  "PIDs don't match, ret = "
+                                  << *pClientBuff << "; expected = " << pid);
+                free(*pClientBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pUserBuff != nullptr) {
+            switch (userMethod) {
+            case USER_METHOD_UID:
+                RUNNER_ASSERT_MSG(*pUserBuff == std::to_string(peerCredentials.uid()),
+                                  "UIDs don't match, ret = "
+                                  << *pUserBuff
+                                  << "; expected = " << peerCredentials.uid());
+                free(*pUserBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pPidCred != nullptr) {
+            RUNNER_ASSERT_MSG(*pPidCred == pid, "PIDs don't match, ret = "
+                              << *pPidCred
+                              << "; expected = " << pid);
+        }
+    });
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd08_dbus_credentials_default_positive_all)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, &userBuff, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd09_dbus_credentials_default_positive_partial_single)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, nullptr, nullptr);
+    testDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, &userBuff, nullptr);
+    testDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, nullptr, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd10_dbus_credentials_default_positive_partial_double)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, &userBuff, &pidCred);
+    testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, nullptr, &pidCred);
+    testDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, &userBuff, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd11_dbus_credentials_default_negative_incomplete)
+{
+    testDbusCredsDefault(CYNARA_API_INVALID_PARAM, nullptr, nullptr, nullptr);
+}
+
+void testDbusCreds(int expectedResult,
+                   const cynara_client_creds *pClientMethod, char **pClientBuff,
+                   const cynara_user_creds *pUserMethod, char **pUserBuff,
+                   pid_t *pPidCred)
+{
+    // reset variables if set by previous test cases
+    if (pClientBuff != nullptr) *pClientBuff = nullptr;
+    if (pUserBuff != nullptr) *pUserBuff = nullptr;
+    if (pPidCred != nullptr) *pPidCred = -1;
+
+    dbusTestTemplate([&] (DBusConnectionPtr conn, pid_t pid,
+                          const std::string &requestedName,
+                          const ProcessCredentials &peerCredentials) {
+
+        int ret = cynara_creds_dbus_get(conn.get(), requestedName.c_str(),
+                                        pClientMethod, pClientBuff,
+                                        pUserMethod, pUserBuff, pPidCred);
+
+        RUNNER_ASSERT_MSG(ret == expectedResult,
+                          "cynara_creds_dbus_get returned unexpected result: " << ret <<
+                          "; expected: " << expectedResult);
+
+        if (ret != CYNARA_API_SUCCESS) {
+            return;
+        }
+
+        if (pClientBuff != nullptr && pClientMethod != nullptr) {
+            switch (*pClientMethod) {
+            case CLIENT_METHOD_SMACK:
+                RUNNER_ASSERT_MSG(*pClientBuff == peerCredentials.label(),
+                                  "Client labels don't match, ret = "
+                                  << *pClientBuff << "; expected = "
+                                  << peerCredentials.label());
+                free(*pClientBuff);
+                break;
+            case CLIENT_METHOD_PID:
+                RUNNER_ASSERT_MSG(*pClientBuff == std::to_string(pid),
+                                  "PIDs don't match, ret = "
+                                  << *pClientBuff << "; expected = " << pid);
+                free(*pClientBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pUserBuff != nullptr && pUserMethod != nullptr) {
+            switch (*pUserMethod) {
+            case USER_METHOD_UID:
+                RUNNER_ASSERT_MSG(*pUserBuff == std::to_string(peerCredentials.uid()),
+                                  "UIDs don't match, ret = "
+                                  << *pUserBuff
+                                  << "; expected = " << peerCredentials.uid());
+                free(*pUserBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pPidCred != nullptr) {
+            RUNNER_ASSERT_MSG(*pPidCred == pid, "PIDs don't match, ret = "
+                              << *pPidCred
+                              << "; expected = " << pid);
+        }
+    });
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd12_dbus_credentials_positive_all)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                  &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_SMACK, &clientBuff,
+                  &G_USER_METHOD_UID, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_PID, &clientBuff,
+                  &G_USER_METHOD_UID, &userBuff, &pidCred);
+
+    testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                  &G_CLIENT_METHOD_SMACK, &clientBuff,
+                  &G_USER_METHOD_GID, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                  &G_CLIENT_METHOD_PID, &clientBuff,
+                  &G_USER_METHOD_GID, &userBuff, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd13_dbus_credentials_positive_partial_single)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_PID, &clientBuff,
+                  &G_USER_METHOD_DEFAULT, nullptr,
+                  nullptr);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_SMACK, &clientBuff,
+                  nullptr, nullptr,
+                  nullptr);
+
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_DEFAULT, nullptr,
+                  &G_USER_METHOD_DEFAULT, &userBuff,
+                  nullptr);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  nullptr, nullptr,
+                  &G_USER_METHOD_DEFAULT, &userBuff,
+                  nullptr);
+
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  nullptr, nullptr,
+                  &G_USER_METHOD_DEFAULT, nullptr,
+                  &pidCred);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_DEFAULT, nullptr,
+                  nullptr, nullptr,
+                  &pidCred);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  nullptr, nullptr,
+                  nullptr, nullptr,
+                  &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd14_dbus_credentials_positive_partial_double)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_DEFAULT, nullptr,
+                  &G_USER_METHOD_UID, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  nullptr, nullptr,
+                  &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_PID, &clientBuff,
+                  &G_USER_METHOD_DEFAULT, nullptr, &pidCred);
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                  nullptr, nullptr, &pidCred);
+
+    testDbusCreds(CYNARA_API_SUCCESS,
+                  &G_CLIENT_METHOD_SMACK, &clientBuff,
+                  &G_USER_METHOD_UID, &userBuff, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd14_dbus_credentials_negative_incomplete)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  nullptr, &clientBuff,
+                  &G_USER_METHOD_UID, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  nullptr, &clientBuff,
+                  &G_USER_METHOD_UID, nullptr, &pidCred);
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  nullptr, &clientBuff,
+                  nullptr, nullptr, &pidCred);
+
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                  nullptr, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  &G_CLIENT_METHOD_DEFAULT, nullptr,
+                  nullptr, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  nullptr, nullptr,
+                  nullptr, &userBuff, &pidCred);
+
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  &G_CLIENT_METHOD_DEFAULT, nullptr,
+                  &G_USER_METHOD_UID, nullptr, nullptr);
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  &G_CLIENT_METHOD_DEFAULT, nullptr,
+                  nullptr, nullptr, nullptr);
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  nullptr, nullptr,
+                  &G_USER_METHOD_DEFAULT, nullptr, nullptr);
+    testDbusCreds(CYNARA_API_INVALID_PARAM,
+                  nullptr, nullptr,
+                  nullptr, nullptr, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccd14_dbus_credentials_negative_incorrect)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                  &G_CLIENT_METHOD_LOW, &clientBuff,
+                  &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                  &G_CLIENT_METHOD_HIGH, &clientBuff,
+                  &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                  &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                  &G_USER_METHOD_LOW, &userBuff, &pidCred);
+    testDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                  &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                  &G_USER_METHOD_HIGH, &userBuff, &pidCred);
 }
 
+
+//===============================GDBUS======================================
+
 GDBusConnectionPtr createGDBusConnection() {
     GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
 
@@ -397,7 +744,7 @@ typedef std::function<void(GDBusConnectionPtr conn, pid_t pid,
                            const std::string &requestedName,
                            const ProcessCredentials &peerCredentials)> GDBusAssertionFn;
 
-void gdbusTestTemplate(GDBusAssertionFn assertion, const std::string &/*scope*/) {
+void gdbusTestTemplate(GDBusAssertionFn assertion) {
     std::string requestedName = "tests.dbus.cynara";
     const ProcessCredentials peerCredentials;
 
@@ -425,7 +772,7 @@ void testGdbusClientPid(cynara_client_creds method = CLIENT_METHOD_PID) {
         pid_t clientPid = std::stoi(clientPidStr.get());
         RUNNER_ASSERT_MSG(pid == clientPid, "PIDs don't match ret = " << clientPid
                           << "; expected = " << pid);
-    }, "tccgd01");
+    });
 }
 
 void testGdbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
@@ -437,7 +784,7 @@ void testGdbusClientSmack(cynara_client_creds method = CLIENT_METHOD_SMACK) {
         RUNNER_ASSERT_MSG(peerCredentials.label() == label.get(),
                           "Labels don't match ret = " << label.get()
                           << "; expected = " << peerCredentials.label());
-    }, "tccgd02");
+    });
 }
 
 RUNNER_MULTIPROCESS_TEST(tccgd01_gdbus_credentials_client_pid)
@@ -475,7 +822,7 @@ void testGdbusUserUid(cynara_user_creds method = USER_METHOD_UID) {
         uid_t uid = std::stoul(uidStr.get());
         RUNNER_ASSERT_MSG(peerCredentials.uid() == uid, "UIDs don't match ret = " << uid
                           << "; expected = "<< peerCredentials.uid());
-    }, "tccgd04");
+    });
 }
 
 void testGdbusUserGid(cynara_user_creds method = USER_METHOD_GID) {
@@ -485,7 +832,7 @@ void testGdbusUserGid(cynara_user_creds method = USER_METHOD_GID) {
                                 const ProcessCredentials &) {
         GStringPtr gidStr(CynaraHelperCredentials::gdbusGetUser(std::move(conn),
                           requestedName.c_str(), method, CYNARA_API_METHOD_NOT_SUPPORTED));
-    }, "tccgd04");
+    });
 }
 
 RUNNER_MULTIPROCESS_TEST(tccgd04_gdbus_credentials_user_uid)
@@ -513,16 +860,341 @@ RUNNER_MULTIPROCESS_TEST(tccgd06_gdbus_credentials_user_default) {
     }
 }
 
-RUNNER_MULTIPROCESS_TEST(tccgd06_gdbus_credentials_pid) {
+RUNNER_MULTIPROCESS_TEST(tccgd07_gdbus_credentials_pid) {
     gdbusTestTemplate([] (GDBusConnectionPtr conn, pid_t expectedPid,
                           const std::string &requestedName, const ProcessCredentials &) {
         auto helperPid = CynaraHelperCredentials::gdbusGetPid(std::move(conn),
                          requestedName.c_str());
         RUNNER_ASSERT_MSG(helperPid == expectedPid, "PIDs don't match ret = " << helperPid
                           << "; expected = " << expectedPid);
-    }, "tccgd06");
+    });
+}
+
+void testGDbusCredsDefault(int expectedResult, char **pClientBuff,
+                           char **pUserBuff, pid_t *pPidCred)
+{
+    // reset variables if set by previous test cases
+    if (pClientBuff != nullptr) *pClientBuff = nullptr;
+    if (pUserBuff != nullptr) *pUserBuff = nullptr;
+    if (pPidCred != nullptr) *pPidCred = -1;
+
+    gdbusTestTemplate([&] (GDBusConnectionPtr conn, pid_t pid,
+                           const std::string &requestedName,
+                           const ProcessCredentials &peerCredentials) {
+        cynara_user_creds userMethod = getUserDefaultMethod();
+        cynara_client_creds clientMethod = getClientDefaultMethod();
+
+        // exception override
+        if (expectedResult == CYNARA_API_SUCCESS && userMethod == USER_METHOD_GID) {
+            expectedResult = CYNARA_API_METHOD_NOT_SUPPORTED;
+        }
+
+        int ret = cynara_creds_gdbus_get_default(conn.get(), requestedName.c_str(),
+                                                 pClientBuff, pUserBuff, pPidCred);
+
+        RUNNER_ASSERT_MSG(ret == expectedResult,
+                          "cynara_creds_gdbus_get_default returned unexpected result: " << ret <<
+                          "; expected: " << expectedResult);
+
+        if (ret != CYNARA_API_SUCCESS) {
+            return;
+        }
+
+        if (pClientBuff != nullptr) {
+            switch (clientMethod) {
+            case CLIENT_METHOD_SMACK:
+                RUNNER_ASSERT_MSG(*pClientBuff == peerCredentials.label(),
+                                  "Client labels don't match, ret = "
+                                  << *pClientBuff << "; expected = "
+                                  << peerCredentials.label());
+                g_free(*pClientBuff);
+                break;
+            case CLIENT_METHOD_PID:
+                RUNNER_ASSERT_MSG(*pClientBuff == std::to_string(pid),
+                                  "PIDs don't match, ret = "
+                                  << *pClientBuff << "; expected = " << pid);
+                g_free(*pClientBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pUserBuff != nullptr) {
+            switch (userMethod) {
+            case USER_METHOD_UID:
+                RUNNER_ASSERT_MSG(*pUserBuff == std::to_string(peerCredentials.uid()),
+                                  "UIDs don't match, ret = "
+                                  << *pUserBuff
+                                  << "; expected = " << peerCredentials.uid());
+                g_free(*pUserBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pPidCred != nullptr) {
+            RUNNER_ASSERT_MSG(*pPidCred == pid, "PIDs don't match, ret = "
+                              << *pPidCred
+                              << "; expected = " << pid);
+        }
+    });
+}
+
+RUNNER_MULTIPROCESS_TEST(tccgd08_gdbus_credentials_default_positive_all)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, &userBuff, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccgd09_gdbus_credentials_default_positive_partial_single)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, nullptr, nullptr);
+    testGDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, &userBuff, nullptr);
+    testGDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, nullptr, &pidCred);
 }
 
+RUNNER_MULTIPROCESS_TEST(tccgd10_gdbus_credentials_default_positive_partial_double)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCredsDefault(CYNARA_API_SUCCESS, nullptr, &userBuff, &pidCred);
+    testGDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, nullptr, &pidCred);
+    testGDbusCredsDefault(CYNARA_API_SUCCESS, &clientBuff, &userBuff, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccgd11_gdbus_credentials_default_negative_incomplete)
+{
+    testGDbusCredsDefault(CYNARA_API_INVALID_PARAM, nullptr, nullptr, nullptr);
+}
+
+void testGDbusCreds(int expectedResult,
+                    const cynara_client_creds *pClientMethod, char **pClientBuff,
+                    const cynara_user_creds *pUserMethod, char **pUserBuff,
+                    pid_t *pPidCred)
+{
+    // reset variables if set by previous test cases
+    if (pClientBuff != nullptr) *pClientBuff = nullptr;
+    if (pUserBuff != nullptr) *pUserBuff = nullptr;
+    if (pPidCred != nullptr) *pPidCred = -1;
+
+    gdbusTestTemplate([&] (GDBusConnectionPtr conn, pid_t pid,
+                           const std::string &requestedName,
+                           const ProcessCredentials &peerCredentials) {
+
+        int ret = cynara_creds_gdbus_get(conn.get(), requestedName.c_str(),
+                                         pClientMethod, pClientBuff,
+                                         pUserMethod, pUserBuff, pPidCred);
+
+        RUNNER_ASSERT_MSG(ret == expectedResult,
+                          "cynara_creds_gdbus_get returned unexpected result: " << ret <<
+                          "; expected: " << expectedResult);
+
+        if (ret != CYNARA_API_SUCCESS) {
+            return;
+        }
+
+        if (pClientBuff != nullptr && pClientMethod != nullptr) {
+            switch (*pClientMethod) {
+            case CLIENT_METHOD_SMACK:
+                RUNNER_ASSERT_MSG(*pClientBuff == peerCredentials.label(),
+                                  "Client labels don't match, ret = "
+                                  << *pClientBuff << "; expected = "
+                                  << peerCredentials.label());
+                g_free(*pClientBuff);
+                break;
+            case CLIENT_METHOD_PID:
+                RUNNER_ASSERT_MSG(*pClientBuff == std::to_string(pid),
+                                  "PIDs don't match, ret = "
+                                  << *pClientBuff << "; expected = " << pid);
+                g_free(*pClientBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pUserBuff != nullptr && pUserMethod != nullptr) {
+            switch (*pUserMethod) {
+            case USER_METHOD_UID:
+                RUNNER_ASSERT_MSG(*pUserBuff == std::to_string(peerCredentials.uid()),
+                                  "UIDs don't match, ret = "
+                                  << *pUserBuff
+                                  << "; expected = " << peerCredentials.uid());
+                g_free(*pUserBuff);
+                break;
+            default:
+                break;
+            }
+        }
+
+        if (pPidCred != nullptr) {
+            RUNNER_ASSERT_MSG(*pPidCred == pid, "PIDs don't match, ret = "
+                              << *pPidCred
+                              << "; expected = " << pid);
+        }
+    });
+}
+
+RUNNER_MULTIPROCESS_TEST(tccgd12_gdbus_credentials_positive_all)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                   &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_SMACK, &clientBuff,
+                   &G_USER_METHOD_UID, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_PID, &clientBuff,
+                   &G_USER_METHOD_UID, &userBuff, &pidCred);
+
+    testGDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                   &G_CLIENT_METHOD_SMACK, &clientBuff,
+                   &G_USER_METHOD_GID, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                   &G_CLIENT_METHOD_PID, &clientBuff,
+                   &G_USER_METHOD_GID, &userBuff, &pidCred);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccgd13_gdbus_credentials_positive_partial_single)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_PID, &clientBuff,
+                   &G_USER_METHOD_DEFAULT, nullptr,
+                   nullptr);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_SMACK, &clientBuff,
+                   nullptr, nullptr,
+                   nullptr);
+
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_DEFAULT, nullptr,
+                   &G_USER_METHOD_DEFAULT, &userBuff,
+                   nullptr);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   nullptr, nullptr,
+                   &G_USER_METHOD_DEFAULT, &userBuff,
+                   nullptr);
+
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   nullptr, nullptr,
+                   &G_USER_METHOD_DEFAULT, nullptr,
+                   &pidCred);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_DEFAULT, nullptr,
+                   nullptr, nullptr,
+                   &pidCred);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   nullptr, nullptr,
+                   nullptr, nullptr,
+                   &pidCred);
+ }
+
+RUNNER_MULTIPROCESS_TEST(tccgd14_gdbus_credentials_positive_partial_double)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_DEFAULT, nullptr,
+                   &G_USER_METHOD_UID, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   nullptr, nullptr,
+                   &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_PID, &clientBuff,
+                   &G_USER_METHOD_DEFAULT, nullptr, &pidCred);
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                   nullptr, nullptr, &pidCred);
+
+    testGDbusCreds(CYNARA_API_SUCCESS,
+                   &G_CLIENT_METHOD_SMACK, &clientBuff,
+                   &G_USER_METHOD_UID, &userBuff, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccgd14_gdbus_credentials_negative_incomplete)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   nullptr, &clientBuff,
+                   &G_USER_METHOD_UID, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   nullptr, &clientBuff,
+                   &G_USER_METHOD_UID, nullptr, &pidCred);
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   nullptr, &clientBuff,
+                   nullptr, nullptr, &pidCred);
+
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                   nullptr, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   &G_CLIENT_METHOD_DEFAULT, nullptr,
+                   nullptr, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   nullptr, nullptr,
+                   nullptr, &userBuff, &pidCred);
+
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   &G_CLIENT_METHOD_DEFAULT, nullptr,
+                   &G_USER_METHOD_UID, nullptr, nullptr);
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   &G_CLIENT_METHOD_DEFAULT, nullptr,
+                   nullptr, nullptr, nullptr);
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   nullptr, nullptr,
+                   &G_USER_METHOD_DEFAULT, nullptr, nullptr);
+    testGDbusCreds(CYNARA_API_INVALID_PARAM,
+                   nullptr, nullptr,
+                   nullptr, nullptr, nullptr);
+}
+
+RUNNER_MULTIPROCESS_TEST(tccgd14_gdbus_credentials_negative_incorrect)
+{
+    char *clientBuff = nullptr;
+    char *userBuff = nullptr;
+    pid_t pidCred = -1;
+
+    testGDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                   &G_CLIENT_METHOD_LOW, &clientBuff,
+                   &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                   &G_CLIENT_METHOD_HIGH, &clientBuff,
+                   &G_USER_METHOD_DEFAULT, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                   &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                   &G_USER_METHOD_LOW, &userBuff, &pidCred);
+    testGDbusCreds(CYNARA_API_METHOD_NOT_SUPPORTED,
+                   &G_CLIENT_METHOD_DEFAULT, &clientBuff,
+                   &G_USER_METHOD_HIGH, &userBuff, &pidCred);
+}
+
+
+//================================SdBus===============================================
 
 SdBusConnectionPtr createSdBusConnection(const std::string &requestedName) {
     sd_bus *bus = NULL;
index 82d5dd4..2d8cf74 100644 (file)
@@ -642,6 +642,56 @@ RUNNER_TEST(security_manager_09d_uninstall_app_from_hybrid_package)
     }
 }
 
+RUNNER_TEST(security_manager_09e_update_app_nonhybrid_package)
+{
+    constexpr char pkgId[] = "sm_test_09e";
+    AppInstallHelperExt apps[] = {{"sm_test_09e_0", pkgId},
+                                  {"sm_test_09e_1", pkgId}};
+
+    InstallRequest installRequest;
+    installRequest.setPkgId(apps[0].getPkgId());
+    installRequest.setAppId(apps[0].getAppId());
+    // following installation will install sm_test_09e_0
+    Api::install(installRequest, SECURITY_MANAGER_SUCCESS);
+    apps[0].checkAfterInstall();
+    InstallRequest updateRequest;
+    updateRequest.setPkgId(apps[1].getPkgId());
+    updateRequest.setAppId(apps[1].getAppId());
+    // following update should uninstall sm_test_09e_0 and leave sm_test_09e_1 in the DB
+    Api::update(updateRequest, SECURITY_MANAGER_SUCCESS);
+    apps[1].checkAfterInstall();
+    apps[0].checkAfterUninstall(false);
+    // this uninstall should succeed and make sure DB contains NO applications from this package
+    Api::uninstall(updateRequest, SECURITY_MANAGER_SUCCESS);
+    apps[1].checkAfterUninstall(true);
+}
+
+RUNNER_TEST(security_manager_09f_update_app_hybrid_package)
+{
+    constexpr char pkgId[] = "sm_test_09f";
+    AppInstallHelperExt apps[] = {{"sm_test_09f_0", pkgId},
+                                  {"sm_test_09f_1", pkgId}};
+
+    InstallRequest installRequest;
+    installRequest.setPkgId(apps[0].getPkgId());
+    installRequest.setAppId(apps[0].getAppId());
+    installRequest.setHybrid();
+    // following installation will install sm_test_09f_0
+    Api::install(installRequest, SECURITY_MANAGER_SUCCESS);
+    apps[0].checkAfterInstall();
+    InstallRequest updateRequest;
+    updateRequest.setPkgId(apps[1].getPkgId());
+    updateRequest.setAppId(apps[1].getAppId());
+    updateRequest.setHybrid();
+    // following update should uninstall sm_test_09f_0 and leave sm_test_09f_1 in the DB
+    Api::update(updateRequest, SECURITY_MANAGER_SUCCESS);
+    apps[1].checkAfterInstall();
+    apps[0].checkAfterUninstall(false);
+    // this uninstall should succeed and make sure DB contains NO applications from this package
+    Api::uninstall(updateRequest, SECURITY_MANAGER_SUCCESS);
+    apps[1].checkAfterUninstall(true);
+}
+
 RUNNER_CHILD_TEST(security_manager_10_app_has_privilege)
 {
     const PrivilegeVector allowedPrivs = {PRIV_WIFIDIRECT, PRIV_TELEPHONY};
diff --git a/src/test-performance-check.sh b/src/test-performance-check.sh
deleted file mode 100644 (file)
index 5d373ce..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/bin/sh
-
-NOF_TRIES=3
-i=$NOF_TRIES
-ERR_FILE=error.log
-RESULTS_FILE=results.log
-
-SUM=0
-
-black="\033[0;30m";
-red="\033[0;31m";
-green="\033[0;32m";
-brown="\033[0;33m";
-blue="\033[0;34m";
-purple="\033[0;35m";
-grey="\033[1;30m";
-yellow="\033[1;33m";
-default="\033[0m";
-
-
-function echo_as_percent () {
-full=$(( $1 / 100 ))
-rest_full=$(( $1 % 100 ))
-dec=$(($rest_full / 10 ))
-rest_dec=$(($rest_full % 10 ))
-echo "$full.$dec$rest_dec%"
-echo "$full.$dec$rest_dec%" >> $RESULTS_FILE
-
-}
-
-date >> $RESULTS_FILE
-date >> $ERR_FILE
-while [ $((i--)) -gt 0 ]
-do
-echo -e "$blue==============test no $i=============$default"
-
-perf record -a -g & > /dev/null 2> /dev/null
-sleep 1
-security-tests-all.sh > /dev/null 2> /dev/null
-pkill -SIGINT perf
-
-sleep 2
-
-echo "perf results:"
-perf report -U -s symbol -gflat,1,caller 2>> $ERR_FILE | grep smk
-OUTPUT=$(perf report -U -s symbol -gflat,1,caller 2>> $ERR_FILE | grep smk | sed "s:%.*$::g;s:^[ \t]::g;s:[^0-9]::g;s:^0::g;s:^0::g;s:$:+:g;$ s:+::" | tr -d "\n")
-
-echo -e "$blue sum:"
-echo_as_percent $(($OUTPUT))
-echo -e "$default"
-
-SUM=$(($SUM + $OUTPUT))
-
-done
-echo -e "$blue==============done============="
-OUTPUT=$(($SUM/3))
-echo "average:"
-echo "average:" >> $RESULTS_FILE
-echo_as_percent $OUTPUT
-echo -e "$default"
-
-