Add test cases which check libprivilege-control params
authorLukasz Kostyra <l.kostyra@partner.samsung.com>
Thu, 18 Jul 2013 11:14:44 +0000 (13:14 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 14:07:37 +0000 (15:07 +0100)
[Issue#]        SSDWSSP-376
[Feature]       Test cases which call libprivilege-control functions with incorrect arguments.
[Cause]         Many libprivilege-control API functions didn't check for incorrect arguments and
                could cause crashes this way.
[Solution]      A new test cases were added: one for regular API functions, one for deprecated API
                functions, one for not completed API functions (the latter one is ignored).
[Verification]  Run libprivilege-control-test.

Change-Id: I911cc58c3acb2883c41a8e31360010ce57ace1f7

tests/libprivilege-control-tests/test_cases.cpp

index 3a23833..e53a2a5 100644 (file)
@@ -326,6 +326,10 @@ const char *WRT_BLAHBLAH_DAC = "/usr/share/privilege-control/WGT_blahblah.dac";
 const char *OTHER_BLAHBLAH_DAC = "/usr/share/privilege-control/blahblah.dac";
 const char *BLAHBLAH_FEATURE = "http://feature/blah/blahblah";
 
+//correct and incorrect PID used in incorrect params test
+const pid_t PID_CORRECT = 0;
+const pid_t PID_INCORRECT = -1;
+
 /**
  * Check if every rule is true.
  * @return 1 if ALL rules in SMACK, 0 if ANY rule isn't
@@ -2583,3 +2587,92 @@ RUNNER_CHILD_TEST_NOSMACK(privilege_control24d_test_whether_macro_works_child_no
        //Until a fix for RUNNER_IGNORED_MSG comes up to wrt-commons, this must be commented out.
        //RUNNER_IGNORED_MSG("STUB: I should be called on NOSMACK environment only.");
 }
+//////////////////////////////////////////////////////
+//TEST FOR INCORRECT PARAMS CHECK IN LIBPRIVILEGE APIS
+//////////////////////////////////////////////////////
+
+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(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, "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, "perm_app_install didn't check if pkg_id isn't NULL.");
+    RUNNER_ASSERT_MSG(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, "perm_app_uninstall didn't check if pkg_id isn't NULL.");
+    RUNNER_ASSERT_MSG(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, "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, "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, "perm_app_enable_permissions didn't check if pkg_id isn't empty.");
+}
+
+RUNNER_TEST(privilege_control21g_incorrect_params_app_revoke_permissions)
+{
+    RUNNER_ASSERT_MSG(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, "perm_app_revoke_permissions didn't check if pkg_id isn't empty.");
+}
+
+RUNNER_TEST(privilege_control21h_incorrect_params_app_reset_permissions)
+{
+    RUNNER_ASSERT_MSG(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, "perm_app_reset_permissions didn't check if pkg_id isn't empty.");
+}
+
+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, "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, "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, "perm_app_setup_path didn't check if pkg_id isn't empty.");
+}
+
+RUNNER_TEST(privilege_control21j_incorrect_params_app_add_friend)
+{
+    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_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, "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, "perm_add_api_feature didn't check if api_feature_name isn't empty.");
+}
+
+//A test for incompleted app_disable_permissions function
+RUNNER_TEST(privilege_control21l_incorrect_params_ignored_disable_permissions)
+{
+    //perm_app_disable_permissions is only a stub for now. When this function will be completed,
+    //un-ignore this test.
+    RUNNER_IGNORED_MSG("A test for perm_app_disable_permissions. Check comment.");
+
+    //perm_app_disable_permissions - since this func is only a stub, no tests are performed
+    RUNNER_ASSERT_MSG(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, "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, "perm_app_disable_permissions didn't check if pkg_id isn't empty.");
+}