From 554f9de26fc15c3fbde1e4811d44a3ba90a8f7b4 Mon Sep 17 00:00:00 2001 From: Marcin Niesluchowski Date: Thu, 8 May 2014 12:03:25 +0200 Subject: [PATCH] Add tests to libprivilege-control perm_app_has_permission function. libprivilege-control function perm_app_has_permission has been restored and changed. See: -> 'Restore perm_app_has_permission API function.' -> 'Adjust perm_app_has_permission API function to Tizen 3.0 model.' Verification: -> security-tests.sh libprivilege-control --output=text --runignored (following tests should pass: -> privilege_control20_perm_app_has_permission -> privilege_control21m_incorrect_params_perm_app_has_permission) Change-Id: I62d38b4665e5cc51f50b284378a3197dc8daefd2 --- tests/libprivilege-control-tests/test_cases.cpp | 92 ++++++++++++++++++++++ .../test_cases_incorrect_params.cpp | 19 +++++ 2 files changed, 111 insertions(+) diff --git a/tests/libprivilege-control-tests/test_cases.cpp b/tests/libprivilege-control-tests/test_cases.cpp index c7603af..197aa83 100644 --- a/tests/libprivilege-control-tests/test_cases.cpp +++ b/tests/libprivilege-control-tests/test_cases.cpp @@ -1018,6 +1018,98 @@ RUNNER_TEST_SMACK(privilege_control19_app_setup_path_settings) test_app_setup_path(__LINE__, APP_PATH_SETTINGS_RW); } +void check_perm_app_has_permission(const char* app_label, const char* permission, bool is_enabled_expected) +{ + int result; + bool is_enabled; + + result = perm_app_has_permission(app_label, APP_TYPE_WGT, permission, &is_enabled); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error calling perm_app_has_permission. Result: " << result); + + RUNNER_ASSERT_MSG_BT(is_enabled == is_enabled_expected, + "Result of perm_app_has_permission should be: " << is_enabled_expected); +} + +RUNNER_TEST(privilege_control20_perm_app_has_permission) +{ + int result; + const char *other_app_label = "test_other_app_label"; + + DB_BEGIN + + result = perm_app_uninstall(WGT_APP_ID); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error uninstalling app. Result" << result); + + result = perm_app_install(WGT_APP_ID); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error installing app. Result" << result); + + result = perm_app_disable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2_R_AND_NO_R); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error disabling app r and no r permissions. Result: " << result); + + DB_END + + check_perm_app_has_permission(USER_APP_ID, PRIVS2_R[0], false); + check_perm_app_has_permission(USER_APP_ID, PRIVS2_NO_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_NO_R[0], false); + + DB_BEGIN + + result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2_R, false); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error registering app r permissions. Result: " << result); + + DB_END + + check_perm_app_has_permission(USER_APP_ID, PRIVS2_R[0], true); + check_perm_app_has_permission(USER_APP_ID, PRIVS2_NO_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_NO_R[0], false); + + DB_BEGIN + + result = perm_app_enable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2_NO_R, false); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error registering app r permissions. Result: " << result); + + DB_END + + check_perm_app_has_permission(USER_APP_ID, PRIVS2_R[0], true); + check_perm_app_has_permission(USER_APP_ID, PRIVS2_NO_R[0], true); + check_perm_app_has_permission(other_app_label, PRIVS2_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_NO_R[0], false); + + DB_BEGIN + + result = perm_app_disable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2_R); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error disabling app r and no r permissions. Result: " << result); + + DB_END + + check_perm_app_has_permission(USER_APP_ID, PRIVS2_R[0], false); + check_perm_app_has_permission(USER_APP_ID, PRIVS2_NO_R[0], true); + check_perm_app_has_permission(other_app_label, PRIVS2_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_NO_R[0], false); + + DB_BEGIN + + result = perm_app_disable_permissions(WGT_APP_ID, APP_TYPE_WGT, PRIVS2_NO_R); + RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS, + "Error disabling app r and no r permissions. Result: " << result); + + DB_END + + check_perm_app_has_permission(USER_APP_ID, PRIVS2_R[0], false); + check_perm_app_has_permission(USER_APP_ID, PRIVS2_NO_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_R[0], false); + check_perm_app_has_permission(other_app_label, PRIVS2_NO_R[0], false); +} + RUNNER_TEST(privilege_control25_test_libprivilege_strerror) { int POSITIVE_ERROR_CODE = 1; int NONEXISTING_ERROR_CODE = -239042; diff --git a/tests/libprivilege-control-tests/test_cases_incorrect_params.cpp b/tests/libprivilege-control-tests/test_cases_incorrect_params.cpp index 31cdc8c..7735694 100644 --- a/tests/libprivilege-control-tests/test_cases_incorrect_params.cpp +++ b/tests/libprivilege-control-tests/test_cases_incorrect_params.cpp @@ -122,3 +122,22 @@ RUNNER_TEST(privilege_control21l_incorrect_params_ignored_disable_permissions) 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."); +} -- 2.7.4