Added privilege_control05_set_app_privilege_osp,
authorMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 6 Jun 2013 11:48:36 +0000 (13:48 +0200)
committerMarcin Niesluchowski <m.niesluchow@samsung.com>
Thu, 23 Jan 2014 13:45:09 +0000 (14:45 +0100)
privilege_control05_set_app_privilege_osp_partner,
privilege_control05_set_app_privilege_osp_platform.

[Issue#]        SSDWSSP-202
[Bug/Feature]   app_set_permissions' functionalities are not all covered by tests.
[Cause]         N/A
[Solution]      N/A
[Verification]  Running libprivilege-control tests.

Change-Id: If0da8acd7e49d3f946627e95e4d2c27ea6a0bae5

packaging/security-tests.spec
tests/libprivilege-control-tests/CMakeLists.txt
tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.dac [new file with mode: 0644]
tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.smack [new file with mode: 0644]
tests/libprivilege-control-tests/V5LKqDFBXm-1.0.0-arm.tpk [new file with mode: 0644]
tests/libprivilege-control-tests/j4RuPsZrNt-1.0.0-arm.tpk [new file with mode: 0644]
tests/libprivilege-control-tests/test_cases.cpp
tests/libprivilege-control-tests/uqNfgEjqc7-1.0.0-arm.tpk [new file with mode: 0644]

index 55d78c2..8350fa6 100644 (file)
@@ -43,12 +43,18 @@ find /etc/smack/test_privilege_control_DIR/ -type f -name exec -exec chmod 0755
 wrt-installer --install /usr/bin/TestMisiuPysiu123.wgt
 wrt-installer --install /usr/bin/MisiuPysiu123Partner.wgt
 wrt-installer --install /usr/bin/MisiuPysiu123Platform.wgt
+osp-installer --install=/usr/bin/uqNfgEjqc7-1.0.0-arm.tpk
+osp-installer --install=/usr/bin/j4RuPsZrNt-1.0.0-arm.tpk
+osp-installer --install=/usr/bin/V5LKqDFBXm-1.0.0-arm.tpk
 echo "security-tests postinst done ..."
 
 %postun
 wrt-installer --uninstall-name QwCqJ0ttyS
 wrt-installer --uninstall-name 7btsV1Y0sX
 wrt-installer --uninstall-name G4DE3U2vmW
+osp-installer --uninstall=uqNfgEjqc
+osp-installer --uninstall=j4RuPsZrNt
+osp-installer --uninstall=V5LKqDFBXm
 
 %files
 %defattr(-, root, root, -)
@@ -75,3 +81,7 @@ wrt-installer --uninstall-name G4DE3U2vmW
 /usr/bin/TestMisiuPysiu123.wgt
 /usr/bin/MisiuPysiu123Partner.wgt
 /usr/bin/MisiuPysiu123Platform.wgt
+/usr/bin/uqNfgEjqc7-1.0.0-arm.tpk
+/usr/bin/j4RuPsZrNt-1.0.0-arm.tpk
+/usr/bin/V5LKqDFBXm-1.0.0-arm.tpk
+
index 5e8e8f6..34fbec9 100644 (file)
@@ -116,6 +116,21 @@ INSTALL(FILES
   )
 
 INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/uqNfgEjqc7-1.0.0-arm.tpk
+    DESTINATION /usr/bin/
+  )
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/j4RuPsZrNt-1.0.0-arm.tpk
+    DESTINATION /usr/bin/
+  )
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/V5LKqDFBXm-1.0.0-arm.tpk
+    DESTINATION /usr/bin/
+  )
+
+INSTALL(FILES
     ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/WRT_test_privilege_control_rules_wgt.smack
     DESTINATION /usr/share/privilege-control/
   )
@@ -124,3 +139,13 @@ INSTALL(FILES
     ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/WRT_test_privilege_control_rules_wgt.dac
     DESTINATION /usr/share/privilege-control/
   )
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.smack
+    DESTINATION /usr/share/privilege-control/
+  )
+
+INSTALL(FILES
+    ${PROJECT_SOURCE_DIR}/tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.dac
+    DESTINATION /usr/share/privilege-control/
+  )
diff --git a/tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.dac b/tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.dac
new file mode 100644 (file)
index 0000000..8654033
--- /dev/null
@@ -0,0 +1,2 @@
+56789
+67890
diff --git a/tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.smack b/tests/libprivilege-control-tests/OSP_test_privilege_control_rules_osp.smack
new file mode 100644 (file)
index 0000000..858f5b1
--- /dev/null
@@ -0,0 +1,16 @@
+~APP~ test_book_8 r
+~APP~ test_book_9 w
+~APP~ test_book_10 x
+~APP~ test_book_11 rw
+~APP~ test_book_12 rx
+~APP~ test_book_13 wx
+~APP~ test_book_14 rwx
+~APP~ test_book_15 rwxat
+test_subject_8 ~APP~ r
+test_subject_9 ~APP~ w
+test_subject_10 ~APP~ x
+test_subject_11 ~APP~ rw
+test_subject_12 ~APP~ rx
+test_subject_13 ~APP~ wx
+test_subject_14 ~APP~ rwx
+test_subject_15 ~APP~ rwxat
diff --git a/tests/libprivilege-control-tests/V5LKqDFBXm-1.0.0-arm.tpk b/tests/libprivilege-control-tests/V5LKqDFBXm-1.0.0-arm.tpk
new file mode 100644 (file)
index 0000000..263bca8
Binary files /dev/null and b/tests/libprivilege-control-tests/V5LKqDFBXm-1.0.0-arm.tpk differ
diff --git a/tests/libprivilege-control-tests/j4RuPsZrNt-1.0.0-arm.tpk b/tests/libprivilege-control-tests/j4RuPsZrNt-1.0.0-arm.tpk
new file mode 100644 (file)
index 0000000..126d529
Binary files /dev/null and b/tests/libprivilege-control-tests/j4RuPsZrNt-1.0.0-arm.tpk differ
index 5860a30..9eaca16 100644 (file)
 #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 };
@@ -72,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"
@@ -233,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;
@@ -786,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.");
@@ -796,16 +871,25 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     result = test_have_any_accesses(rules_wgt_platform);
     RUNNER_ASSERT_MSG(result==0, "Not all permisions revoked.");
 
+    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");
     RUNNER_ASSERT_MSG(pFile != NULL,
             "SMACK file removed!. Errno: " << errno);
     //// Is it empty?
     fseek(pFile, 0L, SEEK_END);
     int smack_file_length = ftell(pFile);
-    RUNNER_ASSERT_MSG(smack_file_length==0,
-            "SMACK file not empty.. Errno: " << errno);
     if (pFile != NULL)
         fclose(pFile);
+    RUNNER_ASSERT_MSG(smack_file_length==0,
+            "SMACK file not empty.. Errno: " << errno);
 
     pFile = fopen(SMACK_RULES_DIR WGT_APP_ID, "rb");
     RUNNER_ASSERT_MSG(pFile != NULL,
@@ -813,32 +897,65 @@ RUNNER_CHILD_TEST(privilege_control06_revoke_permissions)
     //// 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 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);
 
-    pFile = fopen(SMACK_RULES_DIR WGT_PARTNER_APP_ID, "rb");
+    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 WGT_PLATFORM_APP_ID, "rb");
+    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)
@@ -1136,6 +1253,90 @@ RUNNER_CHILD_TEST(privilege_control05_set_app_privilege_wgt_platform)
     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)
 {
     const char *subject = "lkjq345v34sfa";
diff --git a/tests/libprivilege-control-tests/uqNfgEjqc7-1.0.0-arm.tpk b/tests/libprivilege-control-tests/uqNfgEjqc7-1.0.0-arm.tpk
new file mode 100644 (file)
index 0000000..a36ba67
Binary files /dev/null and b/tests/libprivilege-control-tests/uqNfgEjqc7-1.0.0-arm.tpk differ