Add test for libprivilege permissions update. 83/23383/4
authorMarcin Lis <m.lis@samsung.com>
Wed, 18 Jun 2014 13:17:42 +0000 (15:17 +0200)
committerMarcin Lis <m.lis@samsung.com>
Wed, 2 Jul 2014 16:05:17 +0000 (18:05 +0200)
This commit introduces tests for the following change:
https://review.tizen.org/gerrit/#/c/23382/

Change-Id: I42c228dac84c9aee8f7f55de4a9d4773f97f11f1
Signed-off-by: Marcin Lis <m.lis@samsung.com>
tests/libprivilege-control-tests/common/libprivilege-control_test_common.h
tests/libprivilege-control-tests/test_cases.cpp

index 7175dc6..f7251f5 100644 (file)
 #define TEST_NON_APP_DIR         "/etc/smack/test_privilege_control_DIR/non_app_dir"
 
 #define APP_ID                 "test_APP"
-#define APPID_DIR                "test_APP_ID_dir"
+#define APPID_DIR              "test_APP_ID_dir"
+#define GENERATED_APP_ID       "User" // TODO to be replaced in the future
+
+#define PERM_TO_REDEFINE       "Test::RedefinePermission"
+#define PERM_SUB_TO_REDEFINE   "Test::RedefinePermission::Sub"
 
 #define APP_1     "app_1"
 #define APP_1_DIR "/tmp/app_1"
index f96f4ff..55c16ec 100644 (file)
@@ -270,7 +270,7 @@ RUNNER_CHILD_TEST_SMACK(privilege_control05_set_app_privilege_efl)
 /**
  * Add new API feature
  */
-RUNNER_TEST(privilege_control11_add_api_feature)
+RUNNER_TEST(privilege_control08_add_api_feature)
 {
     int result;
 
@@ -394,6 +394,93 @@ RUNNER_TEST(privilege_control11_add_api_feature)
     DB_END
 }
 
+/**
+ * Add new API feature, assign it to an app and redefine the API feature.
+ * Check if app rules has changed after redefinition.
+ */
+RUNNER_TEST_SMACK(privilege_control09_perm_add_api_feature_redefine)
+{
+    int result;
+    const char *permissionName[] = { "org.tizen.test.permtoberedefined", NULL};
+
+    // Rules to be used with the first check
+    const rules_t test_rules1 = {
+        { GENERATED_APP_ID, PERM_TO_REDEFINE, "rx" },
+        { PERM_TO_REDEFINE, GENERATED_APP_ID, "rwx" },
+        { GENERATED_APP_ID, PERM_SUB_TO_REDEFINE, "rx" }
+    };
+
+    // Rules that contain differences - to be used with the second check (after re-def)
+    const rules_t test_rules2 = {
+        { GENERATED_APP_ID, PERM_TO_REDEFINE, "rwx" },
+        { PERM_TO_REDEFINE, GENERATED_APP_ID, "rx" },
+        { GENERATED_APP_ID, PERM_SUB_TO_REDEFINE, "watl" }
+    };
+
+    // Differences between rules1 and rules2 - should be revoked after re-def)
+    const rules_t diff_rules = {
+        { PERM_TO_REDEFINE, GENERATED_APP_ID, "w" },
+        { GENERATED_APP_ID, PERM_SUB_TO_REDEFINE, "rx" }
+    };
+
+    // Rules to be used with the first definition
+    const char *perm_rules1[] = {
+        "~APP~ " PERM_TO_REDEFINE " rx",
+        PERM_TO_REDEFINE " ~APP~ rwx",
+        "~APP~ " PERM_SUB_TO_REDEFINE " rx",
+        NULL
+    };
+
+    // Rules that contain differences - to be used with the second definition (re-def)
+    const char *perm_rules2[] = {
+        "~APP~ " PERM_TO_REDEFINE " rwx",
+        PERM_TO_REDEFINE " ~APP~ rx",
+        "~APP~ " PERM_SUB_TO_REDEFINE " watl",
+        NULL
+    };
+
+    DB_BEGIN
+
+    // uninstall app to make sure that all rules and permissions are revoked
+    result = perm_app_uninstall(APP_ID);
+    RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+            "perm_app_uninstall failed: " << perm_strerror(result));
+
+    result = perm_app_install(APP_ID);
+    RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+            "perm_app_install failed: " << perm_strerror(result));
+
+    result = perm_add_api_feature(APP_TYPE_OSP, permissionName[0], perm_rules1, NULL, 0);
+    RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+            "perm_add_api_feature failed: " << result);
+
+    result = perm_app_enable_permissions(APP_ID, APP_TYPE_OSP, permissionName, true);
+    RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+            "perm_app_enable_permissions failed: " << perm_strerror(result));
+
+    DB_END
+
+    // Check if rules are applied
+    result = test_have_all_accesses(test_rules1);
+    RUNNER_ASSERT_MSG_BT(result == 1, "Not all permissions added.");
+
+    DB_BEGIN
+
+    // Redefine the permission
+    result = perm_add_api_feature(APP_TYPE_OSP, permissionName[0], perm_rules2, NULL, 0);
+    RUNNER_ASSERT_MSG_BT(result == PC_OPERATION_SUCCESS,
+            "perm_add_api_feature failed: " << result);
+
+    DB_END
+
+    // Check if rules are updated
+    result = test_have_all_accesses(test_rules2);
+    RUNNER_ASSERT_MSG_BT(result == 1, "Not all permissions added after update.");
+    // The difference between rules1 and rules2 should be revoked!
+    result = test_have_any_accesses(diff_rules);
+    RUNNER_ASSERT_MSG_BT(result == 0, "Permissions are not fully updated.");
+}
+
 /*
  * Check perm_app_uninstall function
  */