From 9deb52d6a1cabf41baf9ffc0580cc772961b6dba Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Mon, 21 Nov 2016 13:55:24 +0900 Subject: [PATCH] Fix media path and app dir path Use app directory base path from tzplatform config macro. But for TZ_USER_APP which contains rw user app path for 3rd party is unusable on this position (for regex) because we csr server is not user service so not usable in compile time. - /opt/home -> /opt/usr/home - Add sdcard prefix additionally (TZ_SYS_STORAGE) - /home//content -> /home//media # it's for test program Change-Id: Icde1d8772686deb86953ae8a2272c7de3adda769 Signed-off-by: Kyungwook Tak --- CMakeLists.txt | 5 ++ packaging/csr-framework.spec | 5 ++ src/CMakeLists.txt | 1 + src/framework/main/csr-main.cpp | 3 ++ src/framework/service/app-dirs.cpp | 81 +++++++++++++++++++++++++++++++ src/framework/service/app-dirs.h | 33 +++++++++++++ src/framework/service/file-system.cpp | 30 ++---------- test/CMakeLists.txt | 1 + test/internals/CMakeLists.txt | 1 + test/test-api-content-screening-async.cpp | 49 ++++++------------- test/test-helper.cpp | 34 +++++++++++-- test/test-resource.cpp | 16 +++--- 12 files changed, 189 insertions(+), 70 deletions(-) create mode 100644 src/framework/service/app-dirs.cpp create mode 100644 src/framework/service/app-dirs.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 28a5d86..a1b9339 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,11 @@ IF (PLATFORM_VERSION_3) SET(DECLARE_POPUP_USER "") SET(DECLARE_POPUP_GROUP "") SET(DECLARE_POPUP_SMACK_PROCESS_LABEL "") + + ADD_DEFINITIONS("-DTZ_SYS_STORAGE=\"${TZ_SYS_STORAGE}\"") + ADD_DEFINITIONS("-DTZ_SYS_RW_APP=\"${TZ_SYS_RW_APP}\"") + ADD_DEFINITIONS("-DTZ_SYS_RO_APP=\"${TZ_SYS_RO_APP}\"") + CONFIGURE_FILE(packaging/${SERVICE_NAME}.manifest.in ${SERVICE_NAME}.manifest @ONLY) CONFIGURE_FILE(packaging/${SERVICE_NAME}-test.manifest.in ${SERVICE_NAME}-test.manifest @ONLY) CONFIGURE_FILE(data/scripts/${SERVICE_NAME}-upgrade.sh.in data/scripts/${SERVICE_NAME}-upgrade.sh @ONLY) diff --git a/packaging/csr-framework.spec b/packaging/csr-framework.spec index 5bd4054..058a9ab 100644 --- a/packaging/csr-framework.spec +++ b/packaging/csr-framework.spec @@ -42,6 +42,7 @@ BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(efl-extension) BuildRequires: pkgconfig(icu-i18n) %if "%{?tizen_version}" == "3.0" +BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(cynara-client) %else BuildRequires: pkgconfig(libsmack) @@ -135,6 +136,7 @@ Group: Security/Testing BuildRequires: boost-devel BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(storage) Requires: %{name} = %{version} %description test @@ -186,6 +188,9 @@ Content Screening and Reputation framework (test program) -DWITH_SAMPLE_ENGINE:BOOL=OFF \ %endif %if "%{?tizen_version}" == "3.0" + -DTZ_SYS_STORAGE=%TZ_SYS_STORAGE \ + -DTZ_SYS_RW_APP=%TZ_SYS_RW_APP \ + -DTZ_SYS_RO_APP=%TZ_SYS_RO_APP \ -DPLATFORM_VERSION_3:BOOL=ON %else -DPLATFORM_VERSION_3:BOOL=OFF diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a17ad25..8fe7fe3 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,7 @@ SET(${TARGET_CSR_SERVER}_SRCS framework/service/fs-utils.cpp framework/service/file-system.cpp framework/service/app-deleter.cpp + framework/service/app-dirs.cpp framework/service/iloader.cpp framework/service/cs-loader.cpp framework/service/wp-loader.cpp diff --git a/src/framework/main/csr-main.cpp b/src/framework/main/csr-main.cpp index 650ab64..dd9d036 100644 --- a/src/framework/main/csr-main.cpp +++ b/src/framework/main/csr-main.cpp @@ -21,6 +21,7 @@ */ #include "service/server-service.h" +#include "service/app-dirs.h" #include "common/audit/logger.h" int main(void) @@ -28,6 +29,8 @@ int main(void) try { INFO("Start csr-server main!"); + Csr::AppDirs::init(); + Csr::ServerService service; INFO("Let's start csr-server service!"); diff --git a/src/framework/service/app-dirs.cpp b/src/framework/service/app-dirs.cpp new file mode 100644 index 0000000..16ec314 --- /dev/null +++ b/src/framework/service/app-dirs.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include "service/app-dirs.h" + +#include +#include + +namespace { + +inline std::regex _regex(const char *str) +{ + return std::regex(str, std::regex_constants::extended); +} + +} + +namespace Csr { + +std::vector AppDirs::m_regex; + +const std::vector &AppDirs::get() +{ + return AppDirs::m_regex; +} + +void AppDirs::init() +{ + static std::once_flag f; + + std::call_once(f, []() { AppDirs::initOnce(); }); +} + +void AppDirs::initOnce() +{ +#define __INS_REGEX(str) AppDirs::m_regex.emplace_back(_regex(str)) + +#ifdef PLATFORM_VERSION_3 + // internal storages + __INS_REGEX("^(" TZ_SYS_RW_APP "/([^/]+))"); // $TZ_SYS_RW_APP/{pkgid}/ + __INS_REGEX("^(" TZ_SYS_RO_APP "/([^/]+))"); // $TZ_SYS_RO_APP/{pkgid}/ + // (linked prefix)/home/{user}/(appdir)/{pkgid}/ + __INS_REGEX("^(/home/([^/]+)/apps_rw/([^/]+))"); + __INS_REGEX("^(/opt/usr/home/([^/]+)/apps_rw/([^/]+))"); + + // external storages + // (linked prefix)/sdcard/app2sd/{pkgid}/ + // (linked prefix)/sdcard/app2sd/{user}/{pkgid}/ + // (linked prefix)/sdcard/apps/{user}/apps_rw/{pkgid}/ + __INS_REGEX("^(/sdcard/app2sd/([^/]+))"); + __INS_REGEX("^(/sdcard/app2sd/([^/]+)/([^/]+))"); + __INS_REGEX("^(/sdcard/apps/([^/]+)/apps_rw/([^/]+))"); + __INS_REGEX("^(" TZ_SYS_STORAGE "/sdcard/app2sd/([^/]+))"); + __INS_REGEX("^(" TZ_SYS_STORAGE "/sdcard/app2sd/([^/]+)/([^/]+))"); + __INS_REGEX("^(" TZ_SYS_STORAGE "/sdcard/apps/([^/]+)/apps_rw/([^/]+))"); +#else + // internal storages + __INS_REGEX("^(/usr/apps/([^/]+))"); // /usr/apps/{pkgid}/ + __INS_REGEX("^(/opt/usr/apps/([^/]+))"); // /opt/usr/apps/{pkgid}/ + + // external storages + __INS_REGEX("^(/sdcard/apps/([^/]+))"); // /sdcard/apps/{pkgid}/ + __INS_REGEX("^(/sdcard/app2sd/([^/]+))"); // /sdcard/app2sd/{pkgid}/ +#endif + +#undef __INS_REGEX +} + +} diff --git a/src/framework/service/app-dirs.h b/src/framework/service/app-dirs.h new file mode 100644 index 0000000..82bfcd9 --- /dev/null +++ b/src/framework/service/app-dirs.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#pragma once + +#include +#include + +namespace Csr { + +class AppDirs { +public: + static const std::vector &get(); + static void init(); + +private: + static void initOnce(); + static std::vector m_regex; +}; + +} diff --git a/src/framework/service/file-system.cpp b/src/framework/service/file-system.cpp index 71a1528..19e0aaf 100644 --- a/src/framework/service/file-system.cpp +++ b/src/framework/service/file-system.cpp @@ -31,6 +31,7 @@ #include "common/audit/logger.h" #include "common/exception.h" #include "service/app-deleter.h" +#include "service/app-dirs.h" #include "service/fs-utils.h" #include "service/dir-blacklist.h" @@ -38,31 +39,6 @@ namespace Csr { -namespace { - -inline std::regex makeRegexpr(const char *str) -{ - return std::regex(str, std::regex_constants::extended); -} - -std::vector g_regexprs{ -#ifdef PLATFORM_VERSION_3 - makeRegexpr("^(/opt/usr/apps/([^/]+))"), // /opt/usr/apps/{pkgid}/ - makeRegexpr("^(/home/([^/]+)/apps_rw/([^/]+))"), // /home/{user}/apps_rw/{pkgid}/ - makeRegexpr("^(/opt/home/([^/]+)/apps_rw/([^/]+))"), // /opt/home/{user}/apps_rw/{pkgid}/ - makeRegexpr("^(/sdcard/app2sd/([^/]+)/([^/]+))"), // /sdcard/app2sd/{user}/{pkgid}/ - makeRegexpr("^(/sdcard/app2sd/([^/]+))"), // /sdcard/app2sd/{pkgid}/ - makeRegexpr("^(/sdcard/apps/([^/]+)/apps_rw/([^/]+))") // /sdcard/apps/{user}/apps_rw/{pkgid}/ -#else - makeRegexpr("^(/usr/apps/([^/]+))"), // /usr/apps/{pkgid}/ - makeRegexpr("^(/opt/usr/apps/([^/]+))"), // /opt/usr/apps/{pkgid}/ - makeRegexpr("^(/sdcard/apps/([^/]+))"), // /sdcard/apps/{pkgid}/ - makeRegexpr("^(/sdcard/app2sd/([^/]+))"), // /sdcard/app2sd/{pkgid}/ -#endif -}; - -} // namespace anonymous - int File::getPkgTypes(const std::string &user, const std::string &pkgid) { pkgmgrinfo_pkginfo_h handle; @@ -104,7 +80,7 @@ std::string File::getPkgPath(const std::string &path) { std::smatch matched; - for (const auto ®e : g_regexprs) { + for (const auto ®e : AppDirs::get()) { if (!std::regex_search(path, matched, rege)) continue; @@ -156,7 +132,7 @@ File::File(const std::string &fpath, const FilePtr &parentdir, int type, std::smatch matched; - for (const auto ®e : g_regexprs) { + for (const auto ®e : AppDirs::get()) { if (!std::regex_search(this->m_path, matched, rege)) continue; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7a7b787..4900e22 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -32,6 +32,7 @@ PKG_CHECK_MODULES(${TARGET_CSR_TEST_COMMON}_DEP glib-2.0 pkgmgr pkgmgr-info + storage ) SET(${TARGET_CSR_TEST_COMMON}_SRCS diff --git a/test/internals/CMakeLists.txt b/test/internals/CMakeLists.txt index ce815d4..67c4f95 100644 --- a/test/internals/CMakeLists.txt +++ b/test/internals/CMakeLists.txt @@ -47,6 +47,7 @@ SET(${TARGET_CSR_INTERNAL_TEST}_SRCS ${CSR_FW_SRC_PATH}/service/fs-utils.cpp ${CSR_FW_SRC_PATH}/service/file-system.cpp ${CSR_FW_SRC_PATH}/service/app-deleter.cpp + ${CSR_FW_SRC_PATH}/service/app-dirs.cpp ${CSR_FW_SRC_PATH}/service/iloader.cpp ${CSR_FW_SRC_PATH}/service/cs-loader.cpp ${CSR_FW_SRC_PATH}/service/wp-loader.cpp diff --git a/test/test-api-content-screening-async.cpp b/test/test-api-content-screening-async.cpp index 5e9b99c..09e6c2a 100644 --- a/test/test-api-content-screening-async.cpp +++ b/test/test-api-content-screening-async.cpp @@ -360,44 +360,35 @@ BOOST_AUTO_TEST_CASE(scan_dir_root) Test::uninstall_app(TEST_WGT_PKG_ID); Test::uninstall_app(TEST_TPK_PKG_ID); - std::string homeDirPrefix; -#ifdef PLATFORM_VERSION_3 - // "/home" is symlinked of "/opt/home" so in root directory scanning, - // user directory prefix("/opt") is additionally needed to check file_name field - // in malware handle - homeDirPrefix = "/opt"; -#endif - ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_HIGH, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_HIGH, false, ""); - ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_FILE_MEDIA(), + ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_MEDIA(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_FILE_MEDIA(), - false, ""); + ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_MEDIA(), false, ""); ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_TMP, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FILE_TMP, false, ""); - ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(), + ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(), + ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID); - ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(), + ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_TPK_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(), + ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID); - ASSERT_DETECTED_IN_LIST(testCtx.detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(), + ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FAKE_APP_FILE(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(), + ASSERT_DETECTED_IN_LIST_EXT(testCtx.detectedList, TEST_FAKE_APP_FILE(), false, ""); ASSERT_DETECTED_IN_LIST(testCtx.detectedList, TEST_FILE_MEDIUM, MALWARE_MEDIUM_NAME, @@ -1119,45 +1110,37 @@ BOOST_AUTO_TEST_CASE(scan_async_multiple) for (size_t i = 0; i < NUM; ++i) ASSERT_CALLBACK(testCtxs[i], -1, -1, 1, 0, 0); - std::string homeDirPrefix; -#ifdef PLATFORM_VERSION_3 - // "/home" is symlinked of "/opt/home" so in root directory scanning, - // user directory prefix("/opt") is additionally needed to check file_name field - // in malware handle - homeDirPrefix = "/opt"; -#endif - for (size_t i = 0; i < NUM; ++i) { ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_HIGH, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FILE_HIGH, false, ""); - ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_FILE_MEDIA(), + ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_MEDIA(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_FILE_MEDIA(), + ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FILE_MEDIA(), false, ""); ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_TMP, MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FILE_TMP, false, ""); - ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(), + ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_WGT_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_WGT_APP_ROOT(), + ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_WGT_APP_ROOT(), true, TEST_WGT_PKG_ID); - ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(), + ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_TPK_APP_ROOT(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_TPK_APP_ROOT(), + ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_TPK_APP_ROOT(), true, TEST_TPK_PKG_ID); - ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(), + ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FAKE_APP_FILE(), MALWARE_HIGH_NAME, MALWARE_HIGH_SEVERITY, MALWARE_HIGH_DETAILED_URL); - ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, homeDirPrefix + TEST_FAKE_APP_FILE(), + ASSERT_DETECTED_IN_LIST_EXT(testCtxs[i].detectedList, TEST_FAKE_APP_FILE(), false, ""); ASSERT_DETECTED_IN_LIST(testCtxs[i].detectedList, TEST_FILE_MEDIUM, MALWARE_MEDIUM_NAME, diff --git a/test/test-helper.cpp b/test/test-helper.cpp index 7e92de3..508cbd5 100644 --- a/test/test-helper.cpp +++ b/test/test-helper.cpp @@ -29,6 +29,30 @@ #include "test-common.h" +namespace { + +std::string get_real_filepath(const std::string &path) +{ + if (path.compare(0, strlen("/opt/usr/home"), "/opt/usr/home") == 0) + return path.substr(strlen("/opt/usr")); + else if (path.compare(0, strlen("/opt/media"), "/opt/media") == 0) + return path.substr(strlen("/opt")); + else + return path; +} + +const char *get_real_filepath(const char *path) +{ + if (strncmp(path, "/opt/usr/home", strlen("/opt/usr/home")) == 0) + return path + strlen("/opt/usr"); + else if (strncmp(path, "/opt/media", strlen("/opt/media")) == 0) + return path + strlen("/opt"); + else + return path; +} + +} + void ASSERT_DETECTED(csr_cs_malware_h detected, const std::string &e_malware_name, csr_cs_severity_level_e e_severity, const std::string &e_detailed_url) { @@ -106,12 +130,13 @@ void ASSERT_DETECTED_IN_LIST(const std::vector &detectedList, const std::string &file_name, const std::string &name, csr_cs_severity_level_e severity, const std::string &detailed_url) { + auto real_file_name = ::get_real_filepath(file_name); csr_cs_severity_level_e a_severity; Test::ScopedCstr a_file_name, a_name, a_detailed_url; for (auto &d : detectedList) { ASSERT_SUCCESS(csr_cs_malware_get_file_name(d, &a_file_name.ptr)); - if (file_name != a_file_name.ptr) + if (real_file_name.compare(::get_real_filepath(a_file_name.ptr)) != 0) continue; ASSERT_SUCCESS(csr_cs_malware_get_name(d, &a_name.ptr)); @@ -126,19 +151,20 @@ void ASSERT_DETECTED_IN_LIST(const std::vector &detectedList, } BOOST_REQUIRE_MESSAGE(false, - "Cannot find the file[" << file_name << "] in detected list."); + "Cannot find the file[" << real_file_name << "] in detected list."); } void ASSERT_DETECTED_IN_LIST_EXT(const std::vector &detectedList, const std::string &file_name, bool is_app, const std::string &pkg_id) { + auto real_file_name = ::get_real_filepath(file_name); bool a_is_app; Test::ScopedCstr a_file_name, a_pkg_id; for (auto &d : detectedList) { ASSERT_SUCCESS(csr_cs_malware_get_file_name(d, &a_file_name.ptr)); - if (file_name != a_file_name.ptr) + if (real_file_name.compare(::get_real_filepath(a_file_name.ptr)) != 0) continue; ASSERT_SUCCESS(csr_cs_malware_is_app(d, &a_is_app)); @@ -151,5 +177,5 @@ void ASSERT_DETECTED_IN_LIST_EXT(const std::vector &detectedLi } BOOST_REQUIRE_MESSAGE(false, - "Cannot find the file[" << file_name << "] in detected list."); + "Cannot find the file[" << real_file_name << "] in detected list."); } diff --git a/test/test-resource.cpp b/test/test-resource.cpp index 3b2f801..ce73bf7 100644 --- a/test/test-resource.cpp +++ b/test/test-resource.cpp @@ -26,6 +26,8 @@ #include #include +#include + #include "test-common.h" namespace { @@ -66,12 +68,14 @@ std::string getUsername(void) const char *TEST_DIR_MEDIA(void) { - if (s_testDirMedia.empty()) -#ifdef PLATFORM_VERSION_3 - s_testDirMedia = "/home/" + ::getUsername() + "/content"; -#else - s_testDirMedia = "/opt/usr/media"; -#endif + if (s_testDirMedia.empty()) { + char *path = nullptr; + if (storage_get_root_directory(STORAGE_TYPE_INTERNAL, &path) != STORAGE_ERROR_NONE) + throw std::logic_error("failed to storage_get_root_directory"); + + s_testDirMedia = path; + free(path); + } return s_testDirMedia.c_str(); } -- 2.7.4