#include <privilege-control.h>
#include <fstream>
#include <sstream>
+#include <sys/stat.h>
#define SMACK_RULES_DIR "/opt/etc/smack-app/accesses.d/"
#define SMACK_LOAD2 "/smack/load2"
RUNNER_ASSERT(labelPtr.get() == NULL);
}
+RUNNER_TEST(privilege_control17_appsettings_privilege)
+{
+#define APP_1 "app_1"
+#define APP_1_DIR "/tmp/app_1"
+
+#define APP_2 "app_2"
+#define APP_2_DIR "/tmp/app_2"
+
+#define APP_TEST "app_test"
+
+#define PRIV_APPSETTING (const char*[]){"http://tizen.org/privilege/appsetting", NULL}
+
+ int ret;
+ char* app1_dir_label;
+ char* app2_dir_label;
+ //prepare test
+
+
+ (void)app_uninstall(APP_TEST);
+ (void)app_uninstall(APP_1);
+ (void)app_uninstall(APP_2);
+
+ //install some app 1
+ ret = app_install(APP_1);
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in app_install." << ret);
+
+ mkdir(APP_1_DIR, S_IRWXU|S_IRGRP|S_IXGRP);
+
+ //register settings folder for app 1
+ ret = app_setup_path(APP_1, APP_1_DIR , APP_PATH_SETTINGS_RW );
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in app_setup_path: " << ret);
+
+ //install "app_test" and give it appsettings privilege
+ ret = app_install(APP_TEST);
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in app_install.");
+
+
+ ret = app_enable_permissions(APP_TEST, APP_TYPE_OSP, PRIV_APPSETTING, true);
+
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS,
+ " Error enabling app permissions. Result: " << ret);
+
+ //check if "app_test" has an RX access to the app "app_1"
+ ret = smack_have_access(APP_TEST, APP_1, "rx");
+ RUNNER_ASSERT_MSG(ret,"access denies");
+
+
+ //check if "app_test" has an RWX access to a folder registered by "app_1"
+ ret = smack_getlabel(APP_1_DIR, &app1_dir_label, SMACK_LABEL_ACCESS );
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS,"smack_getlabel failed");
+ ret = smack_have_access(APP_TEST, app1_dir_label, "rwx");
+ RUNNER_ASSERT_MSG(ret,"access denies");
+
+
+ //intstall another app: "app_2"
+ ret = app_install(APP_2);
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in app_install.");
+
+ mkdir(APP_2_DIR, S_IRWXU|S_IRGRP|S_IXGRP);
+ //register settings folder for that "app_2"
+ ret = app_setup_path(APP_2, APP_2_DIR , APP_PATH_SETTINGS_RW );
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS, "Error in app_setup_path: " << ret);
+
+ //check if "app_test" has an RX access to the app "app_2"
+ ret = smack_have_access(APP_TEST, APP_2, "rx");
+ RUNNER_ASSERT_MSG(ret,"access denies");
+
+ //check if "app_test" has an RWX access to a folder registered by "app_2"
+ ret = smack_getlabel(APP_2_DIR, &app2_dir_label, SMACK_LABEL_ACCESS );
+ RUNNER_ASSERT_MSG(ret == PC_OPERATION_SUCCESS,"smack_getlabel failed");
+ ret = smack_have_access(APP_TEST, app2_dir_label, "rwx");
+ RUNNER_ASSERT_MSG(ret,"access denies");
+
+ free (app1_dir_label);
+ free (app2_dir_label);
+ rmdir(APP_1_DIR);
+ rmdir(APP_2_DIR);
+
+ (void)app_uninstall(APP_TEST);
+ (void)app_uninstall(APP_1);
+ (void)app_uninstall(APP_2);
+
+
+}