security-manager-tests: Add test for TrustedRW package registration 34/69334/1
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 12 May 2016 15:25:57 +0000 (17:25 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 12 May 2016 15:27:57 +0000 (17:27 +0200)
Add tests verifying proper request handling and labeling of
SECURITY_MANAGER_PATH_TRUSTED_RW path.

Verification: run security-manager-tests --regexp=trusted_rw

Change-Id: Ie2a7c52dc0e6937bbac188d3aeffea276ad4acc4

src/security-manager-tests/security_manager_tests.cpp

index dc0ccb5..9e62d0a 100644 (file)
@@ -4390,7 +4390,64 @@ RUNNER_TEST(security_manager_68_path_req_shared_ro_2_X)
     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << path);
 }
 
-// TODO trusted rw
+RUNNER_TEST(security_manager_69_path_req_trusted_rw_no_author)
+{
+    const char *const sm_app_id = "sm_test_69_app_id";
+    const char *const sm_pkg_id = "sm_test_69_pkg_id";
+
+    TemporaryTestUser user("sm_test_69_user_name", GUM_USERTYPE_NORMAL, false);
+    user.create();
+    std::string path = appDirPath(user, sm_app_id, sm_pkg_id);
+
+    removeTestDirs(user, sm_app_id, sm_pkg_id);
+    createTestDirs(user, sm_app_id, sm_pkg_id);
+
+    install_app(sm_app_id, sm_pkg_id, user.getUid());
+
+    PathsRequest preq;
+    preq.setPkgId(sm_pkg_id);
+    preq.setUid(user.getUid());
+    preq.addPath(path, SECURITY_MANAGER_PATH_TRUSTED_RW);
+
+    Api::registerPaths(preq, (lib_retcode)SECURITY_MANAGER_ERROR_INPUT_PARAM);
+}
+
+RUNNER_TEST(security_manager_70_path_req_trusted_rw_positive)
+{
+    const char *const sm_app_id = "sm_test_70_app_id";
+    const char *const sm_pkg_id = "sm_test_70_pkg_id";
+    const char *const author_id = "sm_test_70_author_id";
+
+    TemporaryTestUser user("sm_test_70_user_name", GUM_USERTYPE_NORMAL, false);
+    user.create();
+    std::string path = appDirPath(user, sm_app_id, sm_pkg_id);
+
+    removeTestDirs(user, sm_app_id, sm_pkg_id);
+    createTestDirs(user, sm_app_id, sm_pkg_id);
+
+    InstallRequest ireq;
+    ireq.setAppId(sm_app_id);
+    ireq.setPkgId(sm_pkg_id);
+    ireq.setUid(user.getUid());
+    ireq.setAuthorId(author_id);
+    Api::install(ireq);
+
+    PathsRequest preq;
+    preq.setPkgId(sm_pkg_id);
+    preq.setUid(user.getUid());
+    preq.addPath(path, SECURITY_MANAGER_PATH_TRUSTED_RW);
+
+    Api::registerPaths(preq);
+
+    // check labels
+    TestSecurityManagerDatabase dbtest;
+    int64_t authorDb = dbtest.get_author_id(author_id);
+    nftw_expected_label = std::string("User::Author::") + std::to_string(authorDb);
+    nftw_expected_transmute = true;
+    nftw_expected_exec = false;
+    int result = nftw(path.c_str(), &nftw_check_sm_labels, FTW_MAX_FDS, FTW_PHYS);
+    RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << path);
+}
 
 int main(int argc, char *argv[])
 {