Add tests to libprivilege-control perm_app_has_permission function.
[platform/core/test/security-tests.git] / tests / libprivilege-control-tests / test_cases_incorrect_params.cpp
index a101580..7735694 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #include <dpl/test/test_runner.h>
+#include <tests_common.h>
 #include <sys/smack.h>
 #include <privilege-control.h>
 #include <tests_common.h>
 
 RUNNER_TEST_GROUP_INIT(libprivilegecontrol_incorrect_params)
 
-RUNNER_TEST(privilege_control21a_incorrect_params_get_smack_label_from_process)
-{
-    RUNNER_ASSERT_MSG(get_smack_label_from_process(PID_CORRECT, NULL) == PC_ERR_INVALID_PARAM,
-            "get_smack_label_from_process didn't check if smack_label isn't NULL.");
-
-    char aquired_smack_label[SMACK_LABEL_LEN+1];
-    RUNNER_ASSERT_MSG(get_smack_label_from_process(PID_INCORRECT, aquired_smack_label) == PC_ERR_INVALID_PARAM,
-            "get_smack_label_from_process didn't check for correct pid.");
-}
-
-RUNNER_TEST_SMACK(privilege_control21b_incorrect_params_smack_pid_have_access)
-{
-    RUNNER_ASSERT_MSG(smack_pid_have_access(PID_CORRECT, "some_object", NULL) == -1,
-            "smack_pid_have_access didn't check if access_type isn't NULL.");
-    RUNNER_ASSERT_MSG(smack_pid_have_access(PID_CORRECT, NULL, "rw") == -1,
-            "smack_pid_have_access didn't check if object isn't NULL.");
-    RUNNER_ASSERT_MSG(smack_pid_have_access(PID_CORRECT, "", "rw") == -1,
-            "smack_pid_have_access didn't check if object isn't empty.");
-    RUNNER_ASSERT_MSG(smack_pid_have_access(PID_INCORRECT, "some_object", "rw") == -1,
-            "smack_pid_have_access didn't check for correct pid.");
-}
-
 RUNNER_TEST(privilege_control21c_incorrect_params_perm_app_set_privilege)
 {
-    RUNNER_ASSERT_MSG(perm_app_set_privilege(NULL, NULL, APP_SET_PRIV_PATH) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_set_privilege(NULL, NULL, APP_SET_PRIV_PATH) == PC_ERR_INVALID_PARAM,
             "perm_app_set_privilege didn't check if package name isn't NULL.");
 }
 
 RUNNER_TEST(privilege_control21d_incorrect_params_perm_app_install)
 {
-    RUNNER_ASSERT_MSG(perm_app_install(NULL) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_install(NULL) == PC_ERR_INVALID_PARAM,
             "perm_app_install didn't check if pkg_id isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_install("") == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_install("") == PC_ERR_INVALID_PARAM,
             "perm_app_install didn't check if pkg_id isn't empty.");
 }
 
 RUNNER_TEST(privilege_control21e_incorrect_params_perm_app_uninstall)
 {
-    RUNNER_ASSERT_MSG(perm_app_uninstall(NULL) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_uninstall(NULL) == PC_ERR_INVALID_PARAM,
             "perm_app_uninstall didn't check if pkg_id isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_uninstall("") == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_uninstall("") == PC_ERR_INVALID_PARAM,
             "perm_app_uninstall didn't check if pkg_id isn't empty.");
 }
 
 RUNNER_TEST(privilege_control21f_incorrect_params_perm_app_enable_permissions)
 {
-    RUNNER_ASSERT_MSG(perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, NULL, 1) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_enable_permissions(APP_ID, APP_TYPE_OTHER, NULL, 1) == PC_ERR_INVALID_PARAM,
             "perm_app_enable_permissions didn't check if perm_list isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_enable_permissions(NULL, APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_enable_permissions(NULL, APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
             "perm_app_enable_permissions didn't check if pkg_id isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_enable_permissions("", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_enable_permissions("", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
             "perm_app_enable_permissions didn't check if pkg_id isn't empty.");
-    RUNNER_ASSERT_MSG(perm_app_enable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_enable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2, 1) == PC_ERR_INVALID_PARAM,
             "perm_app_enable_permissions didn't check if pkg_id is valid");
 }
 
 RUNNER_TEST(privilege_control21g_incorrect_params_app_revoke_permissions)
 {
-    RUNNER_ASSERT_MSG(perm_app_revoke_permissions(NULL) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_revoke_permissions(NULL) == PC_ERR_INVALID_PARAM,
             "perm_app_revoke_permissions didn't check if pkg_id isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_revoke_permissions("") == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_revoke_permissions("") == PC_ERR_INVALID_PARAM,
             "perm_app_revoke_permissions didn't check if pkg_id isn't empty.");
-    RUNNER_ASSERT_MSG(perm_app_revoke_permissions("~APP~") == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_revoke_permissions("~APP~") == PC_ERR_INVALID_PARAM,
             "perm_app_revoke_permissions didn't check if pkg_id is valid.");
 }
 
 RUNNER_TEST(privilege_control21h_incorrect_params_app_reset_permissions)
 {
-    RUNNER_ASSERT_MSG(perm_app_reset_permissions(NULL) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_reset_permissions(NULL) == PC_ERR_INVALID_PARAM,
             "perm_app_reset_permissions didn't check if pkg_id isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_reset_permissions("") == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_reset_permissions("") == PC_ERR_INVALID_PARAM,
             "perm_app_reset_permissions didn't check if pkg_id isn't empty.");
-    RUNNER_ASSERT_MSG(perm_app_reset_permissions("~APP~") == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_reset_permissions("~APP~") == PC_ERR_INVALID_PARAM,
             "perm_app_reset_permissions didn't check if pkg_id is valid.");
 }
 
 RUNNER_TEST(privilege_control21i_incorrect_params_app_setup_path)
 {
-    RUNNER_ASSERT_MSG(perm_app_setup_path(APPID_DIR, NULL, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_setup_path(APPID_DIR, NULL, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
             "perm_app_setup_path didn't check if path isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_setup_path(NULL, TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_setup_path(NULL, TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
             "perm_app_setup_path didn't check if pkg_id isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_setup_path("", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_setup_path("", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
             "perm_app_setup_path didn't check if pkg_id isn't empty.");
-    RUNNER_ASSERT_MSG(perm_app_setup_path("~APP~", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_setup_path("~APP~", TEST_APP_DIR, APP_PATH_PRIVATE) == PC_ERR_INVALID_PARAM,
             "perm_app_setup_path didn't check if pkg_id is valid.");
 }
 
-RUNNER_TEST(privilege_control21j_incorrect_params_app_add_friend)
-{
-    RUNNER_IGNORED_MSG("perm_app_add_friend is not implemented");
-
-    RUNNER_ASSERT_MSG(perm_app_add_friend(NULL, APP_FRIEND_2) == PC_ERR_INVALID_PARAM,
-            "perm_app_add_friend didin't check if pkg_id1 isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_add_friend("", APP_FRIEND_2) == PC_ERR_INVALID_PARAM,
-            "perm_app_add_friend didin't check if pkg_id1 isn't empty.");
-    RUNNER_ASSERT_MSG(perm_app_add_friend(APP_FRIEND_1, NULL) == PC_ERR_INVALID_PARAM,
-            "perm_app_add_friend didin't check if pkg_id2 isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_add_friend(APP_FRIEND_1, "") == PC_ERR_INVALID_PARAM,
-            "perm_app_add_friend didin't check if pkg_id2 isn't empty.");
-    RUNNER_ASSERT_MSG(perm_app_add_friend("~APP~", APP_FRIEND_2) == PC_ERR_INVALID_PARAM,
-            "perm_app_add_friend didin't check if pkg_id1 is valid.");
-    RUNNER_ASSERT_MSG(perm_app_add_friend(APP_FRIEND_1, "~APP~") == PC_ERR_INVALID_PARAM,
-            "perm_app_add_friend didin't check if pkg_id2 is valid.");
-}
-
 RUNNER_TEST(privilege_control21k_incorrect_params_add_api_feature)
 {
-    RUNNER_ASSERT_MSG(perm_add_api_feature(APP_TYPE_OSP, NULL, NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_add_api_feature(APP_TYPE_OSP, NULL, NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
             "perm_add_api_feature didn't check if api_feature_name isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_add_api_feature(APP_TYPE_OSP, "", NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_add_api_feature(APP_TYPE_OSP, "", NULL, NULL, 0) == PC_ERR_INVALID_PARAM,
             "perm_add_api_feature didn't check if api_feature_name isn't empty.");
 }
 
 RUNNER_TEST(privilege_control21l_incorrect_params_ignored_disable_permissions)
 {
-    RUNNER_ASSERT_MSG(perm_app_disable_permissions(APP_ID, APP_TYPE_OTHER, NULL) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_disable_permissions(APP_ID, APP_TYPE_OTHER, NULL) == PC_ERR_INVALID_PARAM,
             "perm_app_disable_permissions didn't check if perm_list isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_disable_permissions(NULL, APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_disable_permissions(NULL, APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
             "perm_app_disable_permissions didn't check if pkg_id isn't NULL.");
-    RUNNER_ASSERT_MSG(perm_app_disable_permissions("", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_disable_permissions("", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
             "perm_app_disable_permissions didn't check if pkg_id isn't empty.");
-    RUNNER_ASSERT_MSG(perm_app_disable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
+    RUNNER_ASSERT_MSG_BT(perm_app_disable_permissions("~APP~", APP_TYPE_OTHER, PRIVS2) == PC_ERR_INVALID_PARAM,
             "perm_app_disable_permissions didn't check if pkg_id is valid.");
 }
 
-
+RUNNER_TEST(privilege_control21m_incorrect_params_perm_app_has_permission)
+{
+    bool has_permission;
+    const char *app_label = "test_app_label";
+
+    RUNNER_ASSERT_MSG_BT(perm_app_has_permission(NULL, APP_TYPE_WGT,
+                                              PRIVS2[0], &has_permission) == PC_ERR_INVALID_PARAM,
+            "perm_app_has_permission didn't check if pkg_id isn't NULL.");
+    RUNNER_ASSERT_MSG_BT(perm_app_has_permission(app_label, APP_TYPE_OTHER,
+                                              PRIVS2[0], &has_permission) == PC_ERR_INVALID_PARAM,
+            "perm_app_has_permission should not accept app_type = OTHER.");
+    RUNNER_ASSERT_MSG_BT(perm_app_has_permission(app_label, APP_TYPE_WGT,
+                                              NULL, &has_permission) == PC_ERR_INVALID_PARAM,
+            "perm_app_has_permission didn't check if permission_name isn't NULL.");
+    RUNNER_ASSERT_MSG_BT(perm_app_has_permission(app_label, APP_TYPE_WGT,
+                                              PRIVS2[0], NULL) == PC_ERR_INVALID_PARAM,
+            "perm_app_has_permission didn't check if has_permission isn't NULL.");
+}