Added privilege_control05_set_app_privilege_osp,
[platform/core/test/security-tests.git] / tests / libprivilege-control-tests / test_cases.cpp
index c8ecb56..9eaca16 100644 (file)
@@ -45,6 +45,7 @@
 #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"
 #define WGT_APP_PATH "/opt/usr/apps/QwCqJ0ttyS/bin/QwCqJ0ttyS.TestMisiuPysiu123"
 #define WGT_PARTNER_APP_PATH "/opt/usr/apps/7btsV1Y0sX/bin/7btsV1Y0sX.MisiuPysiu123Partner"
 #define WGT_PLATFORM_APP_PATH "/opt/usr/apps/G4DE3U2vmW/bin/G4DE3U2vmW.MisiuPysiu123Platform"
+#define OSP_APP_ID "uqNfgEjqc7"
+#define OSP_PARTNER_APP_ID "j4RuPsZrNt"
+#define OSP_PLATFORM_APP_ID "V5LKqDFBXm"
+#define OSP_APP_PATH "/opt/usr/apps/uqNfgEjqc7/bin/PysiuMisiu123Osp"
+#define OSP_PARTNER_APP_PATH "/opt/usr/apps/j4RuPsZrNt/bin/PysiuMisiu123OspPartner"
+#define OSP_PLATFORM_APP_PATH "/opt/usr/apps/V5LKqDFBXm/bin/PysiuMisiu123OspPlatform"
 
 const char *PRIVS[] = { "WRT", "test_privilege_control_rules", NULL };
 const char *PRIVS2[] = { "test_privilege_control_rules2", NULL };
@@ -71,10 +78,12 @@ const char *PRIVS2_NO_R[] = { "test_privilege_control_rules2_no_r", NULL };
 const char *PRIVS2_R[] = { "test_privilege_control_rules2_r", NULL };
 const char *PRIVS2_R_AND_NO_R[] = { "test_privilege_control_rules2_r", "test_privilege_control_rules2_no_r", NULL };
 const char *PRIVS_WGT[] = { "test_privilege_control_rules_wgt", NULL };
+const char *PRIVS_OSP[] = { "test_privilege_control_rules_osp", NULL };
 
 #define LIBPRIVILEGE_APP_GROUP_LIST "/usr/share/privilege-control/app_group_list"
 #define LIBPRIVILEGE_TEST_DAC_FILE "/usr/share/privilege-control/test_privilege_control_rules.dac"
 #define LIBPRIVILEGE_TEST_DAC_FILE_WGT "/usr/share/privilege-control/WRT_test_privilege_control_rules_wgt.dac"
+#define LIBPRIVILEGE_TEST_DAC_FILE_OSP "/usr/share/privilege-control/OSP_test_privilege_control_rules_osp.dac"
 
 #define APP_TEST_APP_1 "test-application1"
 #define APP_TEST_APP_2 "test-application_2"
@@ -82,8 +91,17 @@ const char *PRIVS_WGT[] = { "test_privilege_control_rules_wgt", NULL };
 #define APP_TEST_AV_1 "test-antivirus1"
 #define APP_TEST_AV_2 "test-antivirus_2"
 #define APP_TEST_AV_3 "test-av-3"
+
 #define SMACK_APPS_LABELS_DATABASE "/opt/dbspace/.privilege_control_all_apps_id.db"
 #define SMACK_AVS_LABELS_DATABASE "/opt/dbspace/.privilege_control_all_avs_id.db"
+#define SMACK_PUBLIC_DIRS_DATABASE "/opt/dbspace/.privilege_control_public_dirs.db"
+#define SMACK_APPS_SETTINGS_LABELS_DATABASE "/opt/dbspace/.privilege_control_app_setting.db"
+#define SMACK_SETTINGS_DIRS_DATABASE "/opt/dbspace/.privilege_control_setting_dir.db"
+
+#define APP_TEST_SETTINGS_ASP1 "test-app-settings-asp1"
+#define APP_TEST_SETTINGS_ASP2 "test-app-settings-asp2"
+#define APP_TEST_AV_ASP1 "test-app-av-asp1"
+#define APP_TEST_AV_ASP2 "test-app-av-asp2"
 
 #define SOCK_PATH "/tmp/test-smack-socket"
 
@@ -223,6 +241,63 @@ const std::vector< std::vector<std::string> > rules_wgt_platform = {
         { "test_subject_14", WGT_PLATFORM_APP_ID, "rwx" },
         { "test_subject_15", WGT_PLATFORM_APP_ID, "rwxat" }};
 
+// Rules from test_privilege_control_rules_osp.smack for osp
+const std::vector< std::vector<std::string> > rules_osp = {
+        { OSP_APP_ID, "test_book_8", "r" },
+        { OSP_APP_ID, "test_book_9", "w" },
+        { OSP_APP_ID, "test_book_10", "x" },
+        { OSP_APP_ID, "test_book_11", "rw" },
+        { OSP_APP_ID, "test_book_12", "rx" },
+        { OSP_APP_ID, "test_book_13", "wx" },
+        { OSP_APP_ID, "test_book_14", "rwx" },
+        { OSP_APP_ID, "test_book_15", "rwxat" },
+        { "test_subject_8", OSP_APP_ID, "r" },
+        { "test_subject_9", OSP_APP_ID, "w" },
+        { "test_subject_10", OSP_APP_ID, "x" },
+        { "test_subject_11", OSP_APP_ID, "rw" },
+        { "test_subject_12", OSP_APP_ID, "rx" },
+        { "test_subject_13", OSP_APP_ID, "wx" },
+        { "test_subject_14", OSP_APP_ID, "rwx" },
+        { "test_subject_15", OSP_APP_ID, "rwxat" }};
+
+// Rules from test_privilege_control_rules_osp.smack for osp_partner
+const std::vector< std::vector<std::string> > rules_osp_partner = {
+        { OSP_PARTNER_APP_ID, "test_book_8", "r" },
+        { OSP_PARTNER_APP_ID, "test_book_9", "w" },
+        { OSP_PARTNER_APP_ID, "test_book_10", "x" },
+        { OSP_PARTNER_APP_ID, "test_book_11", "rw" },
+        { OSP_PARTNER_APP_ID, "test_book_12", "rx" },
+        { OSP_PARTNER_APP_ID, "test_book_13", "wx" },
+        { OSP_PARTNER_APP_ID, "test_book_14", "rwx" },
+        { OSP_PARTNER_APP_ID, "test_book_15", "rwxat" },
+        { "test_subject_8", OSP_PARTNER_APP_ID, "r" },
+        { "test_subject_9", OSP_PARTNER_APP_ID, "w" },
+        { "test_subject_10", OSP_PARTNER_APP_ID, "x" },
+        { "test_subject_11", OSP_PARTNER_APP_ID, "rw" },
+        { "test_subject_12", OSP_PARTNER_APP_ID, "rx" },
+        { "test_subject_13", OSP_PARTNER_APP_ID, "wx" },
+        { "test_subject_14", OSP_PARTNER_APP_ID, "rwx" },
+        { "test_subject_15", OSP_PARTNER_APP_ID, "rwxat" }};
+
+// Rules from test_privilege_control_rules_osp.smack for osp_platform
+const std::vector< std::vector<std::string> > rules_osp_platform = {
+        { OSP_PLATFORM_APP_ID, "test_book_8", "r" },
+        { OSP_PLATFORM_APP_ID, "test_book_9", "w" },
+        { OSP_PLATFORM_APP_ID, "test_book_10", "x" },
+        { OSP_PLATFORM_APP_ID, "test_book_11", "rw" },
+        { OSP_PLATFORM_APP_ID, "test_book_12", "rx" },
+        { OSP_PLATFORM_APP_ID, "test_book_13", "wx" },
+        { OSP_PLATFORM_APP_ID, "test_book_14", "rwx" },
+        { OSP_PLATFORM_APP_ID, "test_book_15", "rwxat" },
+        { "test_subject_8", OSP_PLATFORM_APP_ID, "r" },
+        { "test_subject_9", OSP_PLATFORM_APP_ID, "w" },
+        { "test_subject_10", OSP_PLATFORM_APP_ID, "x" },
+        { "test_subject_11", OSP_PLATFORM_APP_ID, "rw" },
+        { "test_subject_12", OSP_PLATFORM_APP_ID, "rx" },
+        { "test_subject_13", OSP_PLATFORM_APP_ID, "wx" },
+        { "test_subject_14", OSP_PLATFORM_APP_ID, "rwx" },
+        { "test_subject_15", OSP_PLATFORM_APP_ID, "rwxat" }};
+
 namespace {
 
 typedef std::unique_ptr<smack_accesses,std::function<void(smack_accesses*)>> SmackUniquePtr;
@@ -365,6 +440,10 @@ int nftw_check_labels_app_shared_dir(const char *fpath, const struct stat *sb,
     result = strcmp(APPID_SHARED_DIR, label);
     RUNNER_ASSERT_MSG(result == 0, "ACCESS label on " << fpath << " is incorrect");
 
+    result = smack_have_access(APP_ID, APPID_SHARED_DIR, "rwxat");
+    RUNNER_ASSERT_MSG(result == 1,
+        "Error rwxat access was not given shared dir. Subject: " <<
+        APP_ID << ". Object: " << APPID_SHARED_DIR << ". Result: " << result);
     /* EXEC */
     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_EXEC);
     RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
@@ -383,6 +462,123 @@ int nftw_check_labels_app_shared_dir(const char *fpath, const struct stat *sb,
     return 0;
 }
 
+int check_labels_dir(const char *fpath, const struct stat *sb,
+                     const char* labels_db_path, const char* dir_db_path,
+                     const char* access)
+{
+    int result;
+    char* label;
+    char* label_gen;
+    char* scanf_label_format;
+    char label_temp[SMACK_LABEL_LEN + 1];
+    FILE* file_db;
+
+    /* ACCESS */
+    result = smack_lgetlabel(fpath, &label_gen, SMACK_LABEL_ACCESS);
+    RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
+    RUNNER_ASSERT_MSG(label_gen != NULL, "ACCESS label on " << fpath << " is not set");
+
+     /* EXEC */
+    result = smack_lgetlabel(fpath, &label, SMACK_LABEL_EXEC);
+    if(result != 0){
+        free(label_gen);
+        RUNNER_ASSERT_MSG(false, "Could not get label for the path");
+    }
+    if(label != NULL){
+        free(label_gen);
+        free(label);
+        RUNNER_ASSERT_MSG(false, "EXEC label on " << fpath << " is set.");
+    }
+
+    /* TRANSMUTE */
+    result = smack_lgetlabel(fpath, &label, SMACK_LABEL_TRANSMUTE);
+    if(result != 0){
+        free(label_gen);
+        free(label);
+        RUNNER_ASSERT_MSG(false, "Could not get label for the path");
+    }
+    if (S_ISDIR(sb->st_mode)) {
+        if(label == NULL){
+            free(label_gen);
+            free(label);
+            RUNNER_ASSERT_MSG(false, "TRANSMUTE label on " << fpath << " is not set");
+        }
+        result = strcmp("TRUE", label);
+        if(result != 0){
+            free(label_gen);
+            free(label);
+            RUNNER_ASSERT_MSG(false, "TRANSMUTE label on " << fpath << " is not set to TRUE");
+        }
+    } else if(label != NULL){
+        free(label_gen);
+        free(label);
+        RUNNER_ASSERT_MSG(false, "TRANSMUTE label on " << fpath << " is set");
+    }
+
+    free(label);
+
+    if(0 > asprintf(&scanf_label_format, "%%%ds\\n", SMACK_LABEL_LEN)){
+        free(label_gen);
+        RUNNER_ASSERT_MSG(false, "asprintf failed");
+    }
+
+    file_db = fopen(labels_db_path, "r");
+    if(file_db == NULL){
+        free(label_gen);
+        free(scanf_label_format);
+        RUNNER_ASSERT_MSG(false, "Can not open database for apps");
+    }
+    while(fscanf(file_db, scanf_label_format, label_temp)==1){
+        result = smack_have_access(label_temp, label_gen, access);
+        if(result != 1){
+            fclose(file_db);
+            free(label_gen);
+            free(scanf_label_format);
+            RUNNER_ASSERT_MSG(false,
+                "Error " << access << " access was not given for subject: "
+                << label_temp << ". Result: " << result);
+        }
+    }
+    fclose(file_db);
+
+    file_db = fopen(dir_db_path, "r");
+    if(file_db == NULL){
+        free(label_gen);
+        free(scanf_label_format);
+        RUNNER_ASSERT_MSG(false, "Can not open database for dirs");
+    }
+    bool is_dir = false;
+    while(fscanf(file_db, scanf_label_format, label_temp)==1){
+        if(strcmp(label_gen, label_temp) == 0){
+            is_dir = true;
+            break;
+        }
+    }
+    free(scanf_label_format);
+    free(label_gen);
+    fclose(file_db);
+
+    RUNNER_ASSERT_MSG(is_dir, "Error autogenerated label is not in dirs db.");
+
+    return 0;
+}
+
+int nftw_check_labels_app_public_dir(const char *fpath, const struct stat *sb,
+                               int /*typeflag*/, struct FTW * /*ftwbuf*/)
+{
+    return check_labels_dir(fpath, sb,
+                            SMACK_APPS_LABELS_DATABASE,
+                            SMACK_PUBLIC_DIRS_DATABASE, "rx");
+}
+
+int nftw_check_labels_app_settings_dir(const char *fpath, const struct stat *sb,
+                               int /*typeflag*/, struct FTW * /*ftwbuf*/)
+{
+    return check_labels_dir(fpath, sb,
+                            SMACK_APPS_SETTINGS_LABELS_DATABASE,
+                            SMACK_SETTINGS_DIRS_DATABASE, "rwx");
+}
+
 int file_exists(const char* path)
 {
     FILE* file = fopen(path, "r");
@@ -478,8 +674,81 @@ int cleaning_smack_database_files (void)
         return -1;
     }
 
+    //clean app settings database
+    unlink(SMACK_APPS_SETTINGS_LABELS_DATABASE);
+    fd = open(SMACK_APPS_SETTINGS_LABELS_DATABASE, O_RDWR | O_EXCL | O_CREAT, 0644);
+    if (fd == -1) {
+        return -1;
+    }
+
+    //clean public dirs database
+    unlink(SMACK_PUBLIC_DIRS_DATABASE);
+    fd = open(SMACK_PUBLIC_DIRS_DATABASE, O_RDWR | O_EXCL | O_CREAT, 0644);
+    if (fd == -1) {
+        return -1;
+    }
+
+    //clean settings dirs database
+    unlink(SMACK_SETTINGS_DIRS_DATABASE);
+    fd = open(SMACK_SETTINGS_DIRS_DATABASE, O_RDWR | O_EXCL | O_CREAT, 0644);
+    if (fd == -1) {
+        return -1;
+    }
+
     return 0;
 }
+
+void add_lables_to_db()
+{
+    FILE* file_db;
+
+    file_db = fopen(SMACK_AVS_LABELS_DATABASE, "a");
+    RUNNER_ASSERT_MSG(file_db != NULL, "Error database file "
+        << SMACK_AVS_LABELS_DATABASE << " can not be opened to apend!");
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_AV_ASP1)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_AV_ASP2)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    fclose(file_db);
+
+    file_db = fopen(SMACK_APPS_SETTINGS_LABELS_DATABASE, "a");
+    RUNNER_ASSERT_MSG(file_db != NULL, "Error database file "
+        << SMACK_APPS_SETTINGS_LABELS_DATABASE << " can not be opened to apend!");
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_SETTINGS_ASP1)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_SETTINGS_ASP2)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    fclose(file_db);
+
+    file_db = fopen(SMACK_APPS_LABELS_DATABASE, "a");
+    RUNNER_ASSERT_MSG(file_db != NULL, "Error database file "
+        << SMACK_APPS_LABELS_DATABASE << " can not be opened to apend!");
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_AV_ASP1)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_AV_ASP2)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_SETTINGS_ASP1)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    if (0 > fprintf(file_db, "%s\n", APP_TEST_SETTINGS_ASP2)) {
+        fclose(file_db);
+        RUNNER_ASSERT_MSG(false, "Error writing to database file");
+    }
+    fclose(file_db);
+}
 } // namespace
 
 RUNNER_TEST_GROUP_INIT(libprivilegecontrol)
@@ -491,17 +760,14 @@ RUNNER_TEST(privilege_control02_app_label_dir)
 {
     int result;
 
-    result = app_label_shared_dir(APP_ID, APP_ID, TEST_APP_DIR);
-    RUNNER_ASSERT_MSG(result != 0, "app_label_shared_dir(APP_ADD, APP_ID) == " << result);
-
     result = nftw(TEST_APP_DIR, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_APP_DIR);
 
     result = nftw(TEST_NON_APP_DIR, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_NON_APP_DIR);
 
-    result = app_label_dir(APPID_DIR, TEST_APP_DIR);
-    RUNNER_ASSERT_MSG(result == 0, "app_label_dir() failed");
+    result = app_setup_path(APPID_DIR, TEST_APP_DIR, APP_PATH_PRIVATE);
+    RUNNER_ASSERT_MSG(result == 0, "app_setup_path() failed");
 
     result = nftw(TEST_APP_DIR, &nftw_check_labels_app_dir, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for app dir");
@@ -514,14 +780,17 @@ RUNNER_TEST(privilege_control03_app_label_shared_dir)
 {
     int result;
 
+    result = app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_GROUP_RW, APP_ID);
+    RUNNER_ASSERT_MSG(result != 0, "app_setup_path(APP_ID, APP_ID) didn't fail");
+
     result = nftw(TEST_APP_DIR, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_APP_DIR);
 
     result = nftw(TEST_NON_APP_DIR, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_NON_APP_DIR);
 
-    result = app_label_shared_dir(APP_ID, APPID_SHARED_DIR, TEST_APP_DIR);
-    RUNNER_ASSERT_MSG(result == 0, "app_label_shared_dir() failed");
+    result = app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_GROUP_RW, APPID_SHARED_DIR);
+    RUNNER_ASSERT_MSG(result == 0, "app_setup_path() failed");
 
     result = nftw(TEST_APP_DIR, &nftw_check_labels_app_shared_dir, FTW_MAX_FDS, FTW_PHYS);
     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for shared app dir");
@@ -530,7 +799,6 @@ RUNNER_TEST(privilege_control03_app_label_shared_dir)
     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for non-app dir");
 }
 
-
 /**
  * Add permisions from  test_privilege_control_rules template
  */
@@ -583,6 +851,16 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
        "Error revoking app permissions. Result: " << result);
 
+    result = app_revoke_permissions(OSP_APP_ID);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
+       "Error revoking app permissions. Result: " << result);
+    result = app_revoke_permissions(OSP_PARTNER_APP_ID);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
+       "Error revoking app permissions. Result: " << result);
+    result = app_revoke_permissions(OSP_PLATFORM_APP_ID);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
+       "Error revoking app permissions. Result: " << result);
+
     // Are all the permissions revoked?
     result = test_have_any_accesses(rules);
     RUNNER_ASSERT_MSG(result!=1, "Not all permisions revoked.");
@@ -593,29 +871,91 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     result = test_have_any_accesses(rules_wgt_platform);
     RUNNER_ASSERT_MSG(result==0, "Not all permisions revoked.");
 
-    //// File exists?
+    result = test_have_any_accesses(rules);
+    RUNNER_ASSERT_MSG(result!=1, "Not all permisions revoked.");
+    result = test_have_any_accesses(rules_osp);
+    RUNNER_ASSERT_MSG(result==0, "Not all permisions revoked.");
+    result = test_have_any_accesses(rules_osp_partner);
+    RUNNER_ASSERT_MSG(result==0, "Not all permisions revoked.");
+    result = test_have_any_accesses(rules_osp_platform);
+    RUNNER_ASSERT_MSG(result==0, "Not all permisions revoked.");
+
     FILE *pFile = fopen(SMACK_RULES_DIR APP_ID, "rb");
-    if(pFile!=NULL){
+    RUNNER_ASSERT_MSG(pFile != NULL,
+            "SMACK file removed!. Errno: " << errno);
+    //// Is it empty?
+    fseek(pFile, 0L, SEEK_END);
+    int smack_file_length = ftell(pFile);
+    if (pFile != NULL)
         fclose(pFile);
-        RUNNER_ASSERT_MSG(false,
-            "SMACK file exists after revoke!");
-    }
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
 
-    fd = open(SMACK_RULES_DIR WGT_APP_ID, O_RDONLY);
-    RUNNER_ASSERT_MSG(fd >= 0, "SMACK file deleted after app_revoke_permissions");
-    RUNNER_ASSERT_MSG(lseek(fd, 0, SEEK_END) == 0, "SMACK file not empty after app_revoke_permissions");
-    close(fd);
+    pFile = fopen(SMACK_RULES_DIR WGT_APP_ID, "rb");
+    RUNNER_ASSERT_MSG(pFile != NULL,
+            "SMACK file removed!. Errno: " << errno);
+    //// Is it empty?
+    fseek(pFile, 0L, SEEK_END);
+    smack_file_length = ftell(pFile);
+    if (pFile != NULL)
+        fclose(pFile);
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
 
-    fd = open(SMACK_RULES_DIR WGT_PARTNER_APP_ID, O_RDONLY);
-    RUNNER_ASSERT_MSG(fd >= 0, "SMACK file deleted after app_revoke_permissions");
-    RUNNER_ASSERT_MSG(lseek(fd, 0, SEEK_END) == 0, "SMACK file not empty after app_revoke_permissions");
-    close(fd);
+    pFile = fopen(SMACK_RULES_DIR WGT_PARTNER_APP_ID, "rb");
+    RUNNER_ASSERT_MSG(pFile != NULL,
+            "SMACK file removed!. Errno: " << errno);
+    //// Is it empty?
+    fseek(pFile, 0L, SEEK_END);
+    smack_file_length = ftell(pFile);
+    if (pFile != NULL)
+        fclose(pFile);
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
 
-    fd = open(SMACK_RULES_DIR WGT_PLATFORM_APP_ID, O_RDONLY);
-    RUNNER_ASSERT_MSG(fd >= 0, "SMACK file deleted after app_revoke_permissions");
-    RUNNER_ASSERT_MSG(lseek(fd, 0, SEEK_END) == 0, "SMACK file not empty after app_revoke_permissions");
-    close(fd);
+    pFile = fopen(SMACK_RULES_DIR WGT_PLATFORM_APP_ID, "rb");
+    RUNNER_ASSERT_MSG(pFile != NULL,
+            "SMACK file removed!. Errno: " << errno);
+    //// Is it empty?
+    fseek(pFile, 0L, SEEK_END);
+    smack_file_length = ftell(pFile);
+    if (pFile != NULL)
+        fclose(pFile);
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
+
+    pFile = fopen(SMACK_RULES_DIR OSP_APP_ID, "rb");
+    RUNNER_ASSERT_MSG(pFile != NULL,
+            "SMACK file removed!. Errno: " << errno);
+    //// Is it empty?
+    fseek(pFile, 0L, SEEK_END);
+    smack_file_length = ftell(pFile);
+    if (pFile != NULL)
+        fclose(pFile);
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
+
+    pFile = fopen(SMACK_RULES_DIR OSP_PARTNER_APP_ID, "rb");
+    RUNNER_ASSERT_MSG(pFile != NULL,
+            "SMACK file removed!. Errno: " << errno);
+    //// Is it empty?
+    fseek(pFile, 0L, SEEK_END);
+    smack_file_length = ftell(pFile);
+    if (pFile != NULL)
+        fclose(pFile);
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
 
+    pFile = fopen(SMACK_RULES_DIR OSP_PLATFORM_APP_ID, "rb");
+    RUNNER_ASSERT_MSG(pFile != NULL,
+            "SMACK file removed!. Errno: " << errno);
+    //// Is it empty?
+    fseek(pFile, 0L, SEEK_END);
+    smack_file_length = ftell(pFile);
+    if (pFile != NULL)
+        fclose(pFile);
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
 }
 
 static void read_gids(std::set<unsigned> &set, const char* file_path)
@@ -755,6 +1095,38 @@ RUNNER_TEST(privilege_control05_add_shared_dir_readers)
 /**
  * Set APP privileges.
  */
+
+void check_groups(const char* dac_file) {
+       std::set<unsigned> groups_check;
+       read_gids(groups_check, LIBPRIVILEGE_APP_GROUP_LIST);
+       read_gids(groups_check, dac_file);
+
+       int groups_cnt = getgroups(0, NULL);
+       RUNNER_ASSERT_MSG(groups_cnt > 0, "Wrong number of supplementary groupsCnt");
+       gid_t *groups_list = (gid_t *) calloc(groups_cnt, sizeof(gid_t));
+       RUNNER_ASSERT_MSG(groups_list != NULL, "Memory allocation failed");
+       RUNNER_ASSERT(-1 != getgroups(groups_cnt, groups_list));
+
+       for (int i = 0; i < groups_cnt; ++i) {
+               //getgroups() can return multiple number of the same group
+               //they are returned in sequence, so we will given number when last
+               //element of this number is reached
+               if( (i < groups_cnt - 1) && (groups_list[i+1] == groups_list[i]))
+                       continue;
+               if (groups_check.erase(groups_list[i]) == 0) {
+                       // getgroups() may also return process' main group
+                       if (groups_list[i] != getgid())
+                               RUNNER_ASSERT_MSG(false, "Application belongs to unknown group (GID=" << groups_list[i] << ")");
+               }
+       }
+       free(groups_list);
+       std::string groups_left;
+       for (std::set<unsigned>::iterator it = groups_check.begin(); it != groups_check.end(); it++) {
+               groups_left.append(std::to_string(*it)).append(" ");
+       }
+       RUNNER_ASSERT_MSG(groups_check.empty(), "Application doesn't belong to some required groups: " << groups_left);
+}
+
 RUNNER_CHILD_TEST(privilege_control05_set_app_privilege)
 {
     int result;
@@ -791,28 +1163,7 @@ RUNNER_CHILD_TEST(privilege_control05_set_app_privilege)
     result = strcmp(getenv("USER"), APP_USER_NAME);
     RUNNER_ASSERT_MSG(result == 0, "Wrong user USER NAME");
 
-    std::set<unsigned> groups_check;
-    read_gids(groups_check, LIBPRIVILEGE_APP_GROUP_LIST);
-    read_gids(groups_check, LIBPRIVILEGE_TEST_DAC_FILE);
-
-    int groups_cnt = getgroups(0, NULL);
-    RUNNER_ASSERT_MSG(groups_cnt > 0, "Wrong number of supplementary groupsCnt");
-    gid_t *groups_list = (gid_t *) calloc(groups_cnt, sizeof(gid_t));
-    RUNNER_ASSERT_MSG(groups_list != NULL, "Memory allocation failed");
-    RUNNER_ASSERT(-1 != getgroups(groups_cnt, groups_list));
-
-    for (int i = 0; i < groups_cnt; ++i) {
-        if (groups_check.erase(groups_list[i]) == 0) {
-            // getgroups() may also return process' main group
-            if (groups_list[i] != getgid())
-                RUNNER_ASSERT_MSG(false, "Application belongs to unknown group (GID=" << groups_list[i] << ")");
-        }
-    }
-    std::string groups_left;
-    for (std::set<unsigned>::iterator it = groups_check.begin(); it != groups_check.end(); it++) {
-        groups_left.append(std::to_string(*it)).append(" ");
-    }
-    RUNNER_ASSERT_MSG(groups_check.empty(), "Application doesn't belong to some required groups: " << groups_left);
+    check_groups(LIBPRIVILEGE_TEST_DAC_FILE);
 }
 
 /**
@@ -840,28 +1191,10 @@ RUNNER_CHILD_TEST(privilege_control05_set_app_privilege_wgt)
     result = strcmp(WGT_APP_ID, label);
     RUNNER_ASSERT_MSG(result == 0, "Process label " << label << " is incorrect");
 
-    std::set<unsigned> groups_check;
-    read_gids(groups_check, LIBPRIVILEGE_APP_GROUP_LIST);
-    read_gids(groups_check, LIBPRIVILEGE_TEST_DAC_FILE_WGT);
-
-    int groups_cnt = getgroups(0, NULL);
-    RUNNER_ASSERT_MSG(groups_cnt > 0, "Wrong number of supplementary groupsCnt");
-    gid_t *groups_list = (gid_t *) calloc(groups_cnt, sizeof(gid_t));
-    RUNNER_ASSERT_MSG(groups_list != NULL, "Memory allocation failed");
-    getgroups(groups_cnt, groups_list);
-
-    for (int i = 0; i < groups_cnt; ++i) {
-        if (groups_check.erase(groups_list[i]) == 0) {
-            // getgroups() may also return process' main group
-            if (groups_list[i] != getgid())
-                RUNNER_ASSERT_MSG(false, "Application belongs to unknown group (GID=" << groups_list[i] << ")");
-        }
-    }
-    std::string groups_left;
-    for (std::set<unsigned>::iterator it = groups_check.begin(); it != groups_check.end(); it++) {
-        groups_left.append(std::to_string(*it)).append(" ");
-    }
-    RUNNER_ASSERT_MSG(groups_check.empty(), "Application doesn't belong to some required groups: " << groups_left);
+
+    check_groups(LIBPRIVILEGE_TEST_DAC_FILE_WGT);
+
+
 }
 
 /**
@@ -889,28 +1222,7 @@ RUNNER_CHILD_TEST(privilege_control05_set_app_privilege_wgt_partner)
     result = strcmp(WGT_PARTNER_APP_ID, label);
     RUNNER_ASSERT_MSG(result == 0, "Process label " << label << " is incorrect");
 
-    std::set<unsigned> groups_check;
-    read_gids(groups_check, LIBPRIVILEGE_APP_GROUP_LIST);
-    read_gids(groups_check, LIBPRIVILEGE_TEST_DAC_FILE_WGT);
-
-    int groups_cnt = getgroups(0, NULL);
-    RUNNER_ASSERT_MSG(groups_cnt > 0, "Wrong number of supplementary groupsCnt");
-    gid_t *groups_list = (gid_t *) calloc(groups_cnt, sizeof(gid_t));
-    RUNNER_ASSERT_MSG(groups_list != NULL, "Memory allocation failed");
-    getgroups(groups_cnt, groups_list);
-
-    for (int i = 0; i < groups_cnt; ++i) {
-        if (groups_check.erase(groups_list[i]) == 0) {
-            // getgroups() may also return process' main group
-            if (groups_list[i] != getgid())
-                RUNNER_ASSERT_MSG(false, "Application belongs to unknown group (GID=" << groups_list[i] << ")");
-        }
-    }
-    std::string groups_left;
-    for (std::set<unsigned>::iterator it = groups_check.begin(); it != groups_check.end(); it++) {
-        groups_left.append(std::to_string(*it)).append(" ");
-    }
-    RUNNER_ASSERT_MSG(groups_check.empty(), "Application doesn't belong to some required groups: " << groups_left);
+    check_groups(LIBPRIVILEGE_TEST_DAC_FILE_WGT);
 }
 
 /**
@@ -938,28 +1250,91 @@ RUNNER_CHILD_TEST(privilege_control05_set_app_privilege_wgt_platform)
     result = strcmp(WGT_PLATFORM_APP_ID, label);
     RUNNER_ASSERT_MSG(result == 0, "Process label " << label << " is incorrect");
 
-    std::set<unsigned> groups_check;
-    read_gids(groups_check, LIBPRIVILEGE_APP_GROUP_LIST);
-    read_gids(groups_check, LIBPRIVILEGE_TEST_DAC_FILE_WGT);
-
-    int groups_cnt = getgroups(0, NULL);
-    RUNNER_ASSERT_MSG(groups_cnt > 0, "Wrong number of supplementary groupsCnt");
-    gid_t *groups_list = (gid_t *) calloc(groups_cnt, sizeof(gid_t));
-    RUNNER_ASSERT_MSG(groups_list != NULL, "Memory allocation failed");
-    getgroups(groups_cnt, groups_list);
-
-    for (int i = 0; i < groups_cnt; ++i) {
-        if (groups_check.erase(groups_list[i]) == 0) {
-            // getgroups() may also return process' main group
-            if (groups_list[i] != getgid())
-                RUNNER_ASSERT_MSG(false, "Application belongs to unknown group (GID=" << groups_list[i] << ")");
-        }
-    }
-    std::string groups_left;
-    for (std::set<unsigned>::iterator it = groups_check.begin(); it != groups_check.end(); it++) {
-        groups_left.append(std::to_string(*it)).append(" ");
-    }
-    RUNNER_ASSERT_MSG(groups_check.empty(), "Application doesn't belong to some required groups: " << groups_left);
+    check_groups(LIBPRIVILEGE_TEST_DAC_FILE_WGT);
+}
+
+/**
+ * Set APP privileges. osp app.
+ */
+RUNNER_CHILD_TEST(privilege_control05_set_app_privilege_osp)
+{
+    int result;
+
+    result = app_enable_permissions(OSP_APP_ID, APP_TYPE_OSP, PRIVS_OSP, 1);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
+        " Error enabling app permissions. Result: " << result);
+
+    result = test_have_all_accesses(rules_osp);
+    RUNNER_ASSERT_MSG(result==1, "Permissions not added.");
+
+    result = set_app_privilege(OSP_APP_ID, NULL, OSP_APP_PATH);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Error in set_app_privilege. Error: " << result);
+
+    // Check if SMACK label really set
+    char * label;
+    result = smack_new_label_from_self(&label);
+    RUNNER_ASSERT_MSG(result == 0, "Error getting current process label");
+    RUNNER_ASSERT_MSG(label != NULL, "Process label is not set");
+    result = strcmp(OSP_APP_ID, label);
+    RUNNER_ASSERT_MSG(result == 0, "Process label " << label << " is incorrect");
+
+    check_groups(LIBPRIVILEGE_TEST_DAC_FILE_OSP);
+}
+
+/**
+ * Set APP privileges. partner osp app.
+ */
+RUNNER_CHILD_TEST(privilege_control05_set_app_privilege_osp_partner)
+{
+    int result;
+
+    result = app_enable_permissions(OSP_PARTNER_APP_ID, APP_TYPE_OSP_PARTNER, PRIVS_OSP, 1);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
+        " Error enabling app permissions. Result: " << result);
+
+    result = test_have_all_accesses(rules_osp_partner);
+    RUNNER_ASSERT_MSG(result==1, "Permissions not added.");
+
+    result = set_app_privilege(OSP_PARTNER_APP_ID, NULL, OSP_PARTNER_APP_PATH);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Error in set_app_privilege. Error: " << result);
+
+    // Check if SMACK label really set
+    char * label;
+    result = smack_new_label_from_self(&label);
+    RUNNER_ASSERT_MSG(result == 0, "Error getting current process label");
+    RUNNER_ASSERT_MSG(label != NULL, "Process label is not set");
+    result = strcmp(OSP_PARTNER_APP_ID, label);
+    RUNNER_ASSERT_MSG(result == 0, "Process label " << label << " is incorrect");
+
+    check_groups(LIBPRIVILEGE_TEST_DAC_FILE_OSP);
+}
+
+/**
+ * Set APP privileges. platform osp app.
+ */
+RUNNER_CHILD_TEST(privilege_control05_set_app_privilege_osp_platform)
+{
+    int result;
+
+    result = app_enable_permissions(OSP_PLATFORM_APP_ID, APP_TYPE_OSP_PLATFORM, PRIVS_OSP, 1);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
+        " Error enabling app permissions. Result: " << result);
+
+    result = test_have_all_accesses(rules_osp_platform);
+    RUNNER_ASSERT_MSG(result==1, "Permissions not added.");
+
+    result = set_app_privilege(OSP_PLATFORM_APP_ID, NULL, OSP_PLATFORM_APP_PATH);
+    RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS, "Error in set_app_privilege. Error: " << result);
+
+    // Check if SMACK label really set
+    char * label;
+    result = smack_new_label_from_self(&label);
+    RUNNER_ASSERT_MSG(result == 0, "Error getting current process label");
+    RUNNER_ASSERT_MSG(label != NULL, "Process label is not set");
+    result = strcmp(OSP_PLATFORM_APP_ID, label);
+    RUNNER_ASSERT_MSG(result == 0, "Process label " << label << " is incorrect");
+
+    check_groups(LIBPRIVILEGE_TEST_DAC_FILE_OSP);
 }
 
 RUNNER_TEST(privilege_control08_app_give_access)
@@ -1131,12 +1506,12 @@ RUNNER_TEST(privilege_control11_add_api_feature)
     // correct rules
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "malformed malformed maaaaaalformed", NULL }, NULL, 0);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "malformed malformed r--a-" });
+    osp_blahblah_check(__LINE__, { "malformed malformed r--a- -----" });
     remove_smack_files();
 
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){ "subject object foo", NULL }, NULL, 0);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "subject object -----" });
+    osp_blahblah_check(__LINE__, { "subject object ----- -----" });
     remove_smack_files();
 
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){
@@ -1146,14 +1521,14 @@ RUNNER_TEST(privilege_control11_add_api_feature)
         "",
         NULL }, NULL, 0);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "subject object rwxat", "subject2 object2 rwxat"});
+    osp_blahblah_check(__LINE__, { "subject object rwxat -----", "subject2 object2 rwxat -----"});
     remove_smack_files();
 
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){
         "Sub::jE,ct object a-RwX",
         NULL }, NULL, 0);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "Sub::jE,ct object rwxa-"});
+    osp_blahblah_check(__LINE__, { "Sub::jE,ct object rwxa- -----"});
     remove_smack_files();
 
     // TODO For now identical/complementary rules are not merged.
@@ -1164,14 +1539,14 @@ RUNNER_TEST(privilege_control11_add_api_feature)
         "",
         NULL }, NULL, 0);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "subject object rwxat", "subject object rwxat"});
+    osp_blahblah_check(__LINE__, { "subject object rwxat -----", "subject object rwxat -----"});
     remove_smack_files();
 
 
     // empty group ids
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){0,1,2},0);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "a a ---a-"});
+    osp_blahblah_check(__LINE__, { "a a ---a- -----"});
     result = file_exists(OSP_BLAHBLAH_DAC);
     RUNNER_ASSERT(result == -1);
     remove_smack_files();
@@ -1181,19 +1556,19 @@ RUNNER_TEST(privilege_control11_add_api_feature)
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){0,1,2},3);
     printf("%d \n", result);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "a a ---a-"});
+    osp_blahblah_check(__LINE__, { "a a ---a- -----"});
     osp_blahblah_dac_check(__LINE__, {0,1,2});
     remove_smack_files();
 
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){0,1,2},1);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "a a ---a-"});
+    osp_blahblah_check(__LINE__, { "a a ---a- -----"});
     osp_blahblah_dac_check(__LINE__, {0});
     remove_smack_files();
 
     result = add_api_feature(APP_TYPE_OSP, BLAHBLAH_FEATURE , (const char*[]){"a a a",NULL},(const gid_t[]){1,1,1},3);
     RUNNER_ASSERT(result == PC_OPERATION_SUCCESS);
-    osp_blahblah_check(__LINE__, { "a a ---a-"});
+    osp_blahblah_check(__LINE__, { "a a ---a- -----"});
     osp_blahblah_dac_check(__LINE__, {1,1,1});
     remove_smack_files();
 }
@@ -1508,16 +1883,20 @@ RUNNER_TEST(privilege_control11_app_enable_permissions)
             "Error revoking app permissions. Result: " << result);
 }
 
+/*
+ * Until app_disable_permissions is not fixed this test should remain
+ * commented
+ */
 /**
  * Remove previously granted SMACK permissions based on permissions list.
  */
-RUNNER_TEST(privilege_control12_app_disable_permissions)
+/*RUNNER_TEST(privilege_control12_app_disable_permissions)
 {
-
+*/
 /**
  * Test - disable all granted permissions.
  */
-    int result;
+/*    int result;
 
     // Prepare permissions that we want to disable
     result = app_enable_permissions(APP_ID, APP_TYPE_OTHER, PRIVS2, 1);
@@ -1532,11 +1911,11 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
     // Are all the permissions disabled?
     result = test_have_any_accesses(rules2);
     RUNNER_ASSERT_MSG(result!=1, "Not all permisions disabled.");
-
+*/
 /**
  * Test - disable some granted permissions leaving non complementary and then disabling those too.
  */
-
+/*
     // Prepare permissions that will not be disabled
     result = app_enable_permissions(APP_ID, APP_TYPE_OTHER, PRIVS, 1);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -1568,11 +1947,11 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
     // Are all second permissions disabled?
     result = test_have_any_accesses(rules);
     RUNNER_ASSERT_MSG(result!=1, "Not all second permisions disabled.");
-
+*/
 /**
  * Test - disable only no r granted permissions.
  */
-
+/*
     // Prepare permissions
     result = app_enable_permissions(APP_ID, APP_TYPE_OTHER, PRIVS2, 1);
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
@@ -1600,7 +1979,7 @@ RUNNER_TEST(privilege_control12_app_disable_permissions)
     RUNNER_ASSERT_MSG(result == PC_OPERATION_SUCCESS,
             "Error disabling app permissions. Result: " << result);
 }
-
+*/
 /**
  * Reset SMACK permissions for an application by revoking all previously
  * granted rules and enabling them again from a rules file from disk.
@@ -1967,3 +2346,137 @@ RUNNER_TEST(privilege_control16_app_setup_path){
     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);
+
+
+}
+
+RUNNER_TEST(privilege_control18_app_setup_path_public)
+{
+    int result;
+
+    cleaning_smack_database_files();
+    add_lables_to_db();
+
+    result = nftw(TEST_APP_DIR, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_APP_DIR);
+
+    result = nftw(TEST_NON_APP_DIR, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_NON_APP_DIR);
+
+    result = app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_PUBLIC_RO);
+    RUNNER_ASSERT_MSG(result == 0, "app_setup_path() failed");
+
+    result = nftw(TEST_APP_DIR, &nftw_check_labels_app_public_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for shared app dir");
+
+    result = nftw(TEST_NON_APP_DIR, &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for non-app dir");
+
+    cleaning_smack_database_files();
+}
+
+RUNNER_TEST(privilege_control19_app_setup_path_settings)
+{
+    int result;
+
+    cleaning_smack_database_files();
+    add_lables_to_db();
+
+    result = nftw(TEST_APP_DIR, &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_APP_DIR);
+
+    result = nftw(TEST_NON_APP_DIR, &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to clean up Smack labels in " << TEST_NON_APP_DIR);
+
+    result = app_setup_path(APP_ID, TEST_APP_DIR, APP_PATH_SETTINGS_RW);
+    RUNNER_ASSERT_MSG(result == 0, "app_setup_path() failed");
+
+    result = nftw(TEST_APP_DIR, &nftw_check_labels_app_settings_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for shared app dir");
+
+    result = nftw(TEST_NON_APP_DIR, &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for non-app dir");
+
+    cleaning_smack_database_files();
+}