1 #include <dpl/test/test_runner.h>
3 #include <libprivilege-control_test_common.h>
5 #include <security-server.h>
6 #include <privilege-control.h>
8 const char *SSTP_APP_ID = "sstp_test_app";
9 const char *SSTP_OTHER_LABEL = "sstp_test_other_label";
11 const char *SSTP_PERMS[] = {
17 const char *SSTP_PERMS1[] = {
22 const char *SSTP_PERMS2[] = {
27 void check_security_server_app_has_privilege(const char *app_label,
28 const char *permission,
29 int is_enabled_expected)
34 result = security_server_app_has_privilege(app_label, APP_TYPE_WGT, permission, &is_enabled);
35 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
36 "Error calling security_server_app_has_privilege. Result: " << result);
38 RUNNER_ASSERT_MSG(is_enabled == is_enabled_expected,
39 "Result of security_server_app_has_privilege should be: " << is_enabled_expected);
42 RUNNER_TEST_GROUP_INIT(SECURITY_SERVER_TESTS_PRIVILEGE);
44 RUNNER_TEST(sstp_01_security_server_app_has_privilege)
50 result = perm_app_uninstall(SSTP_APP_ID);
51 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
52 "Error uninstalling app. Result" << result);
54 result = perm_app_install(SSTP_APP_ID);
55 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
56 "Error installing app. Result" << result);
58 result = perm_app_disable_permissions(SSTP_APP_ID, APP_TYPE_WGT, SSTP_PERMS);
59 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
60 "Error disabling app r and no r permissions. Result: " << result);
64 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[0], 0);
65 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[1], 0);
66 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[0], 0);
67 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[1], 0);
71 result = perm_app_enable_permissions(SSTP_APP_ID, APP_TYPE_WGT, SSTP_PERMS1, false);
72 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
73 "Error registering app r permissions. Result: " << result);
77 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[0], 1);
78 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[1], 0);
79 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[0], 0);
80 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[1], 0);
84 result = perm_app_enable_permissions(SSTP_APP_ID, APP_TYPE_WGT, SSTP_PERMS2, false);
85 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
86 "Error registering app r permissions. Result: " << result);
90 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[0], 1);
91 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[1], 1);
92 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[0], 0);
93 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[1], 0);
97 result = perm_app_disable_permissions(SSTP_APP_ID, APP_TYPE_WGT, SSTP_PERMS1);
98 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
99 "Error disabling app r and no r permissions. Result: " << result);
103 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[0], 0);
104 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[1], 1);
105 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[0], 0);
106 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[1], 0);
110 result = perm_app_disable_permissions(SSTP_APP_ID, APP_TYPE_WGT, SSTP_PERMS2);
111 RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
112 "Error disabling app r and no r permissions. Result: " << result);
116 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[0], 0);
117 check_security_server_app_has_privilege(USER_APP_ID, SSTP_PERMS[1], 0);
118 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[0], 0);
119 check_security_server_app_has_privilege(SSTP_OTHER_LABEL, SSTP_PERMS[1], 0);
122 int main(int argc, char *argv[])
124 return DPL::Test::TestRunnerSingleton::Instance().ExecTestRunner(argc, argv);