AsyncLogic::Ending AsyncLogic::scanDir(const std::string &dir)
{
// For in case of there's already detected malware for dir
+ StrSet dirset;
+ dirset.insert(dir);
+
auto retResults =
m_dispatcher->methodCall<std::pair<int, std::vector<CsDetected *>>>(
- CommandId::DIR_GET_RESULTS, m_ctx, dir);
+ CommandId::GET_DETECTED_LIST, dirset);
if (retResults.first != CSR_ERROR_NONE) {
ERROR("[Error] ret: " << retResults.first);
auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
auto ret = hExt->dispatch<int>(
CommandId::JUDGE_STATUS,
- hExt->getContext(),
reinterpret_cast<CsDetected *>(detected)->targetName,
static_cast<int>(action));
auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
auto ret = hExt->dispatch<std::pair<int, CsDetected *>>(
- CommandId::GET_DETECTED,
- hExt->getContext(),
- std::string(file_path));
+ CommandId::GET_DETECTED, std::string(file_path));
if (ret.first != CSR_ERROR_NONE) {
ERROR("Error! ret: " << ret.first);
return CSR_ERROR_INVALID_PARAMETER;
auto ret = hExt->dispatch<std::pair<int, std::vector<CsDetected *>>>(
- CommandId::GET_DETECTED_LIST, hExt->getContext(), dirSet);
+ CommandId::GET_DETECTED_LIST, dirSet);
if (ret.first != CSR_ERROR_NONE) {
ERROR("Error! ret: " << ret.first);
auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
auto ret = hExt->dispatch<std::pair<int, CsDetected *>>(
- CommandId::GET_IGNORED,
- hExt->getContext(),
- std::string(file_path));
+ CommandId::GET_IGNORED, std::string(file_path));
if (ret.first != CSR_ERROR_NONE) {
ERROR("Error! ret: " << ret.first);
return CSR_ERROR_INVALID_PARAMETER;
auto ret = hExt->dispatch<std::pair<int, std::vector<CsDetected *>>>(
- CommandId::GET_IGNORED_LIST, hExt->getContext(), dirSet);
+ CommandId::GET_IGNORED_LIST, dirSet);
if (ret.first != CSR_ERROR_NONE) {
ERROR("Error! ret: " << ret.first);
SCAN_DATA = 0x1001,
SCAN_FILE = 0x1002,
// delta, history
- DIR_GET_RESULTS = 0x1101,
- DIR_GET_FILES = 0x1102,
- GET_DETECTED = 0x1103,
- GET_DETECTED_LIST = 0x1104,
- GET_IGNORED = 0x1105,
- GET_IGNORED_LIST = 0x1106,
+ GET_DETECTED = 0x1101,
+ GET_DETECTED_LIST = 0x1102,
+ GET_IGNORED = 0x1103,
+ GET_IGNORED_LIST = 0x1104,
+ DIR_GET_FILES = 0x1105,
// handle result
JUDGE_STATUS = 0x1201,
class CsDetected;
using CsDetectedPtr = std::unique_ptr<CsDetected>;
-using CsDetectedList = std::vector<CsDetectedPtr>;
struct CsDetected : public IResult {
CsDetected();
//===========================================================================
// DETECTED_MALWARE_FILE table
//===========================================================================
-RowsShPtr Manager::getDetectedMalwares(const std::string &dir)
+RowShPtrs Manager::getDetectedMalwares(const std::string &dir)
{
Statement stmt(m_conn, Query::SEL_DETECTED_BY_DIR);
stmt.bind(dir);
- RowsShPtr rows = std::make_shared<std::vector<RowShPtr>>();
+ RowShPtrs rows;
while (stmt.step()) {
RowShPtr row = std::make_shared<Row>();
row->ts = static_cast<time_t>(stmt.getInt64());
row->isIgnored = static_cast<bool>(stmt.getInt());
- rows->emplace_back(std::move(row));
+ rows.emplace_back(std::move(row));
}
return rows;
void cleanLastScanTime();
// DETECTED_MALWARE_FILE & USER_RESPONSE
- RowsShPtr getDetectedMalwares(const std::string &dirpath);
+ RowShPtrs getDetectedMalwares(const std::string &dirpath);
RowShPtr getDetectedMalware(const std::string &filepath);
void insertDetectedMalware(const CsDetected &, const std::string &dataVersion,
bool isIgnored);
class Row;
using RowShPtr = std::shared_ptr<Row>;
-using RowsShPtr = std::shared_ptr<std::vector<RowShPtr>>;
+using RowShPtrs = std::vector<RowShPtr>;
struct Row : public Csr::CsDetected {
std::string dataVersion; // engine's data version
#include "service/file-system.h"
#include <system_error>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
+#include <cstdio>
+#include <cstring>
+#include <cerrno>
#include <sys/stat.h>
#include "service/app-deleter.h"
#include "common/audit/logger.h"
+#include "common/exception.h"
namespace Csr {
struct stat s;
if (stat(path.c_str(), &s) != 0)
- return false;
- else
- return s.st_mtim.tv_sec >= since;
+ ThrowExc(InternalError, "Failed to stat() on file: " << path <<
+ ". errno: " << errno);
+
+ DEBUG("Modified since called with file: " << path <<
+ " file mtime: " << s.st_mtim.tv_sec <<
+ " since: " << since);
+
+ return s.st_mtim.tv_sec > since;
}
FileVisitor::FileVisitor(const std::string &fpath, time_t modifiedSince) :
FileShrPtr FileVisitor::next()
{
- if (m_nextItem && !FileSystemVisitor::isModifiedSince(m_path, m_since))
+ if (m_nextItem && FileSystemVisitor::isModifiedSince(m_path, m_since)) {
+ DEBUG("visitied file is modified since the time. file: " << m_path);
m_nextItem.reset();
+ }
FileShrPtr item = m_nextItem;
m_nextItem.reset();
#include <string>
#include <utility>
#include <algorithm>
+#include <climits>
#include "common/audit/logger.h"
#include "common/exception.h"
return scanFile(*cptr, filepath);
}
- case CommandId::DIR_GET_RESULTS: {
- CsContextShPtr cptr;
- std::string dir;
- info.second.Deserialize(cptr, dir);
- return dirGetResults(*cptr, dir);
- }
-
case CommandId::DIR_GET_FILES: {
CsContextShPtr cptr;
std::string dir;
}
case CommandId::JUDGE_STATUS: {
- CsContextShPtr cptr;
std::string filepath;
- info.second.Deserialize(cptr, filepath);
- return judgeStatus(*cptr, filepath);
+ int intAction;
+ info.second.Deserialize(filepath, intAction);
+ return judgeStatus(filepath, static_cast<csr_cs_action_e>(intAction));
}
case CommandId::GET_DETECTED: {
- CsContextShPtr cptr;
std::string filepath;
- info.second.Deserialize(cptr, filepath);
- return getDetected(*cptr, filepath);
+ info.second.Deserialize(filepath);
+ return getDetected(filepath);
}
case CommandId::GET_DETECTED_LIST: {
- CsContextShPtr cptr;
StrSet dirSet;
- info.second.Deserialize(cptr, dirSet);
- return getDetectedList(*cptr, dirSet);
+ info.second.Deserialize(dirSet);
+ return getDetectedList(dirSet);
}
case CommandId::GET_IGNORED: {
- CsContextShPtr cptr;
std::string filepath;
- info.second.Deserialize(cptr, filepath);
- return getIgnored(*cptr, filepath);
+ info.second.Deserialize(filepath);
+ return getIgnored(filepath);
}
case CommandId::GET_IGNORED_LIST: {
- CsContextShPtr cptr;
StrSet dirSet;
- info.second.Deserialize(cptr, dirSet);
- return getIgnoredList(*cptr, dirSet);
+ info.second.Deserialize(dirSet);
+ return getIgnoredList(dirSet);
}
// Web protection
return BinaryQueue::Serialize(ret, d).pop();
}
-RawBuffer Logic::scanFile(const CsContext &context, const std::string &filepath)
+RawBuffer Logic::scanFileHelper(const CsContext &context,
+ const std::string &filepath)
{
- auto history = m_db->getDetectedMalware(filepath);
-
- if (history) {
- // history exist of malware detected for the file.
- // let's check file modified since the detected time.
- auto file = createVisitor(filepath, static_cast<time_t>(history->ts))->next();
-
- if (file == nullptr) {
- // file isn't modified since the detected time. history can be used.
- // TODO: case should be separated. (file isn't exist) and (not modified)
- if (context.askUser) {
- if (history->isIgnored) {
- history->response = CSR_CS_IGNORE;
- } else {
- if ((history->response = getUserResponse(context, *history))
- == CSR_CS_IGNORE)
- m_db->setDetectedMalwareIgnored(filepath, true);
- }
- }
-
- return BinaryQueue::Serialize(CSR_ERROR_NONE, history).pop();
- } else {
- // file is modified since the detected time. let's remove history!
- m_db->deleteDetectedMalware(filepath);
- }
- }
-
CsEngineContext engineContext(m_cs);
auto &c = engineContext.get();
return BinaryQueue::Serialize(ret, d).pop();
}
-RawBuffer Logic::dirGetResults(const CsContext &context, const std::string &dir)
+RawBuffer Logic::scanFile(const CsContext &context, const std::string &filepath)
{
- INFO("Dir[" << dir << "] get results");
+ auto history = m_db->getDetectedMalware(filepath);
- printCsContext(context);
+ if (!history)
+ return scanFileHelper(context, filepath);
+
+ // history exist of malware detected for the file.
+ // let's check file modified since the detected time.
+ auto file = createVisitor(filepath, static_cast<time_t>(history->ts))->next();
+
+ // file is modified since the detected time. let's remove history!
+ if (!file) {
+ m_db->deleteDetectedMalware(filepath);
+ return scanFileHelper(context, filepath);
+ }
+
+ // file isn't modified since the detected time. history can be used.
+ if (!context.askUser)
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, history).pop();
+
+ if (history->isIgnored) {
+ history->response = CSR_CS_IGNORE;
+ } else {
+ switch (history->response = getUserResponse(context, *history)) {
+ case CSR_CS_IGNORE:
+ m_db->setDetectedMalwareIgnored(filepath, true);
+ break;
+
+ case CSR_CS_REMOVE:
+ if (!file->remove()) {
+ ERROR("Failed to remove filepath: " << filepath);
+ return BinaryQueue::Serialize(CSR_ERROR_REMOVE_FAILED, CsDetected()).pop();
+ }
+
+ m_db->deleteDetectedMalware(filepath);
+ break;
+
+ case CSR_CS_SKIP:
+ break;
- return BinaryQueue::Serialize(CSR_ERROR_NONE, std::vector<CsDetected>()).pop();
+ default:
+ ThrowExc(InternalError, "Invalid response from popup: " <<
+ static_cast<int>(history->response));
+ }
+ }
+
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, history).pop();
}
RawBuffer Logic::dirGetFiles(const CsContext &context, const std::string &dir)
return BinaryQueue::Serialize(CSR_ERROR_NONE, StrSet()).pop();
}
-RawBuffer Logic::judgeStatus(const CsContext &context,
- const std::string &filepath)
+RawBuffer Logic::judgeStatus(const std::string &filepath,
+ csr_cs_action_e action)
{
- INFO("Judge Status[" << filepath << "] by engine");
+ auto history = m_db->getDetectedMalware(filepath);
- printCsContext(context);
+ if (!history) {
+ ERROR("Target to be judged doesn't exist in db. name: " << filepath);
+ return BinaryQueue::Serialize(CSR_ERROR_INVALID_PARAMETER).pop();
+ }
- return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
-}
+ auto file = createVisitor(filepath, static_cast<time_t>(history->ts))->next();
-RawBuffer Logic::getDetected(const CsContext &context,
- const std::string &filepath)
-{
- INFO("Get Detected[" << filepath << "] by engine");
+ if (!file) {
+ ERROR("Target doesn't exist on target path on filesystem or "
+ "modified since db delta inserted. name: " << filepath);
+ m_db->deleteDetectedMalware(filepath);
+ // TODO: is it okay to just refresh db and return success?
+ return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
+ }
- printCsContext(context);
+ switch (action) {
+ case CSR_CS_ACTION_REMOVE:
+ if (!file->remove()) {
+ ERROR("Failed to remove filepath: " << filepath);
+ return BinaryQueue::Serialize(CSR_ERROR_REMOVE_FAILED).pop();
+ }
- CsDetected detected;
- detected.targetName = "test_file";
+ m_db->deleteDetectedMalware(filepath);
+ break;
- return BinaryQueue::Serialize(CSR_ERROR_NONE, detected).pop();
-}
+ case CSR_CS_ACTION_IGNORE:
+ m_db->setDetectedMalwareIgnored(filepath, true);
+ break;
-RawBuffer Logic::getDetectedList(const CsContext &context, const StrSet &dirSet)
-{
- INFO("Get detected list logic");
- std::for_each(dirSet.begin(), dirSet.end(), [](const std::string & dir) {
- INFO("dir[" << dir << "] in directory set of get detected list logic");
- });
+ case CSR_CS_ACTION_UNIGNORE:
+ m_db->setDetectedMalwareIgnored(filepath, false);
+ break;
- printCsContext(context);
+ default:
+ ThrowExc(InternalError, "Invalid acation enum val: " <<
+ static_cast<csr_cs_action_e>(action));
+ }
- CsDetectedPtr detected(new CsDetected());
- detected->targetName = "test_file";
+ return BinaryQueue::Serialize(CSR_ERROR_NONE).pop();
+}
- CsDetectedList list;
- list.emplace_back(std::move(detected));
+RawBuffer Logic::getDetected(const std::string &filepath)
+{
+ auto row = m_db->getDetectedMalware(filepath);
- return BinaryQueue::Serialize(CSR_ERROR_NONE, list).pop();
+ if (row)
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, row).pop();
+ else
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, CsDetected()).pop();
}
-RawBuffer Logic::getIgnored(const CsContext &context,
- const std::string &filepath)
+RawBuffer Logic::getDetectedList(const StrSet &dirSet)
{
- INFO("Get Ignored[" << filepath << "] by engine");
+ Db::RowShPtrs rows;
+ std::for_each(dirSet.begin(), dirSet.end(),
+ [this, &rows](const std::string & dir) {
+ for (auto &row : m_db->getDetectedMalwares(dir))
+ rows.emplace_back(std::move(row));
+ });
- printCsContext(context);
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, rows).pop();
+}
- CsDetected detected;
- detected.targetName = "test_file";
+// TODO: is this command needed?
+RawBuffer Logic::getIgnored(const std::string &filepath)
+{
+ auto row = m_db->getDetectedMalware(filepath);
- return BinaryQueue::Serialize(CSR_ERROR_NONE, detected).pop();
+ if (row && row->isIgnored)
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, row).pop();
+ else
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, CsDetected()).pop();
}
-RawBuffer Logic::getIgnoredList(const CsContext &context, const StrSet &dirSet)
+RawBuffer Logic::getIgnoredList(const StrSet &dirSet)
{
- INFO("Get ignored list logic");
- std::for_each(dirSet.begin(), dirSet.end(), [](const std::string & dir) {
- INFO("dir[" << dir << "] in directory set of get ignored list logic");
+ Db::RowShPtrs rows;
+ std::for_each(dirSet.begin(), dirSet.end(),
+ [this, &rows](const std::string & dir) {
+ for (auto &row : m_db->getDetectedMalwares(dir))
+ if (row->isIgnored)
+ rows.emplace_back(std::move(row));
});
- printCsContext(context);
-
- CsDetectedPtr detected(new CsDetected());
- detected->targetName = "test_file";
-
- CsDetectedList list;
- list.emplace_back(std::move(detected));
-
- return BinaryQueue::Serialize(CSR_ERROR_NONE, list).pop();
+ return BinaryQueue::Serialize(CSR_ERROR_NONE, rows).pop();
}
RawBuffer Logic::checkUrl(const WpContext &context, const std::string &url)
#include "service/cs-loader.h"
#include "service/wp-loader.h"
+#include "csr/content-screening-types.h"
+
namespace Csr {
class Logic {
RawBuffer scanData(const CsContext &context, const RawBuffer &data);
RawBuffer scanFile(const CsContext &context, const std::string &filepath);
- RawBuffer dirGetResults(const CsContext &context, const std::string &dir);
+ RawBuffer scanFileHelper(const CsContext &context, const std::string &filepath);
RawBuffer dirGetFiles(const CsContext &context, const std::string &dir);
- RawBuffer judgeStatus(const CsContext &context, const std::string &filepath);
- RawBuffer getDetected(const CsContext &context, const std::string &filepath);
- RawBuffer getDetectedList(const CsContext &context, const StrSet &dirSet);
- RawBuffer getIgnored(const CsContext &context, const std::string &filepath);
- RawBuffer getIgnoredList(const CsContext &context, const StrSet &dirSet);
+ RawBuffer judgeStatus(const std::string &filepath, csr_cs_action_e action);
+ RawBuffer getDetected(const std::string &filepath);
+ RawBuffer getDetectedList(const StrSet &dirSet);
+ RawBuffer getIgnored(const std::string &filepath);
+ RawBuffer getIgnoredList(const StrSet &dirSet);
RawBuffer checkUrl(const WpContext &context, const std::string &url);
CSR_ERROR_SERVER = TIZEN_ERROR_CSR | 0x03, /**< Server has been failed for some reason */
CSR_ERROR_NO_TASK = TIZEN_ERROR_CSR | 0x04, /**< No Task exists*/
CSR_ERROR_DB = TIZEN_ERROR_CSR | 0x05, /**< DB transaction error */
+ CSR_ERROR_REMOVE_FAILED = TIZEN_ERROR_CSR | 0x06, /**< Removing file or application is failed */
CSR_ERROR_ENGINE_PERMISSION = TIZEN_ERROR_CSR | 0x11, /**< Insufficient permission of engine */
CSR_ERROR_ENGINE_NOT_EXIST = TIZEN_ERROR_CSR | 0x12, /**< No engine exists*/
CSR_ERROR_ENGINE_DIASABLED = TIZEN_ERROR_CSR | 0x13, /**< Engine is in disabled state*/
CHECK_IS_NULL(detected);
auto detectedList = db.getDetectedMalwares("/opt");
- ASSERT_IF(detectedList->empty(), true);
+ ASSERT_IF(detectedList.empty(), true);
db.insertDetectedMalware(malware1, initDataVersion, false);
detected = db.getDetectedMalware(malware1.targetName);
// getDetectedMalwares test
detectedList = db.getDetectedMalwares("/opt");
- ASSERT_IF(detectedList->size(), static_cast<size_t>(2));
+ ASSERT_IF(detectedList.size(), static_cast<size_t>(2));
- for (auto &item : *detectedList) {
+ for (auto &item : detectedList) {
if (malware1.targetName == item->targetName)
checkSameMalware(malware1, *item);
else if (malware2.targetName == item->targetName)
#include <string>
#include <iostream>
+#include <climits>
+#include <ctime>
+#include <cstdio>
#include <fcntl.h>
-#include <stdio.h>
#include <sys/stat.h>
-#include <boost/test/unit_test.hpp>
#include <unistd.h>
-#include <time.h>
#include <glib.h>
#include <package-manager.h>
#include <pkgmgr-info.h>
+#include <boost/test/unit_test.hpp>
+
#include "test-common.h"
#define TEST_APP_PKG TEST_DIR "/maliciousapp.tpk"
{
std::string file = TEST_WRITE_FILE;
- auto visitor = Csr::createVisitor(file, 0);
+ auto visitor = Csr::createVisitor(file, LONG_MAX);
CHECK_IS_NOT_NULL(visitor);
-
- int cnt = 0;
-
- while (visitor->next())
- cnt++;
-
- ASSERT_IF(cnt, 1);
+ CHECK_IS_NOT_NULL(visitor->next());
+ CHECK_IS_NULL(visitor->next());
}
BOOST_AUTO_TEST_CASE(file_visitor_positive_modified)
{
std::string file = TEST_WRITE_FILE;
+ auto beforeWrite = time(nullptr);
+
+ sleep(1);
+
__writeFile(file);
- auto visitor = Csr::createVisitor(file, time(0) - 1);
- CHECK_IS_NOT_NULL(visitor);
+ sleep(1);
- int cnt = 0;
+ auto afterWrite = time(nullptr);
- while (visitor->next())
- cnt++;
+ auto visitor = Csr::createVisitor(file, beforeWrite);
+ CHECK_IS_NOT_NULL(visitor);
+ CHECK_IS_NULL(visitor->next());
- ASSERT_IF(cnt, 1);
+ visitor = Csr::createVisitor(file, afterWrite);
+ CHECK_IS_NOT_NULL(visitor);
+ CHECK_IS_NOT_NULL(visitor->next());
+ CHECK_IS_NULL(visitor->next());
}
BOOST_AUTO_TEST_CASE(file_visitor_negative_non_existing)
auto c = Test::Context<csr_cs_context_h>();
auto context = c.get();
- ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled), CSR_ERROR_NONE);
ASSERT_IF(csr_cs_set_callback_on_error(context, on_error), CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned), CSR_ERROR_NONE);
EXCEPTION_GUARD_END
}
auto c = Test::Context<csr_cs_context_h>();
auto context = c.get();
- ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed), CSR_ERROR_NONE);
ASSERT_IF(csr_cs_set_callback_on_error(context, on_error), CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned), CSR_ERROR_NONE);
const char *files[3] = {
TEST_DIR "/test_malware_file",
std::unique_lock<std::mutex> l(testCtx.m);
testCtx.cv.wait(l);
l.unlock();
- BOOST_REQUIRE_MESSAGE(testCtx.completedCnt == 1 && testCtx.scannedCnt == 1 &&
- testCtx.detectedCnt == 2 && testCtx.cancelledCnt == 0 && testCtx.errorCnt == 0,
- "Async request result isn't expected.");
+
+ ASSERT_IF(testCtx.completedCnt, 1);
+ ASSERT_IF(testCtx.scannedCnt, 1);
+ ASSERT_IF(testCtx.detectedCnt, 2);
+ ASSERT_IF(testCtx.cancelledCnt, 0);
+ ASSERT_IF(testCtx.errorCnt, 0);
EXCEPTION_GUARD_END
}
auto c = Test::Context<csr_cs_context_h>();
auto context = c.get();
- ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed), CSR_ERROR_NONE);
ASSERT_IF(csr_cs_set_callback_on_error(context, on_error), CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned), CSR_ERROR_NONE);
AsyncTestContext testCtx;
std::unique_lock<std::mutex> l(testCtx.m);
testCtx.cv.wait(l);
l.unlock();
- BOOST_REQUIRE_MESSAGE(testCtx.completedCnt == 1 && testCtx.scannedCnt == 0 &&
- testCtx.detectedCnt == 0 && testCtx.cancelledCnt == 0 && testCtx.errorCnt == 0,
- "Async request result isn't expected.");
+
+ ASSERT_IF(testCtx.completedCnt, 1);
+ ASSERT_IF(testCtx.scannedCnt, 0); // should be 1 after dir_get_files implemented
+ ASSERT_IF(testCtx.detectedCnt, 2);
+ ASSERT_IF(testCtx.cancelledCnt, 0);
+ ASSERT_IF(testCtx.errorCnt, 0);
EXCEPTION_GUARD_END
}
auto c = Test::Context<csr_cs_context_h>();
auto context = c.get();
- ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_completed(context, on_completed), CSR_ERROR_NONE);
ASSERT_IF(csr_cs_set_callback_on_error(context, on_error), CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected),
- CSR_ERROR_NONE);
- ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_cancelled(context, on_cancelled), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_detected(context, on_detected), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_set_callback_on_file_scanned(context, on_scanned), CSR_ERROR_NONE);
AsyncTestContext testCtx;
std::unique_lock<std::mutex> l(testCtx.m);
testCtx.cv.wait(l);
l.unlock();
- BOOST_REQUIRE_MESSAGE(testCtx.completedCnt == 1 && testCtx.scannedCnt == 0 &&
- testCtx.detectedCnt == 0 && testCtx.cancelledCnt == 0 && testCtx.errorCnt == 0,
- "Async request result isn't expected.");
+
+ ASSERT_IF(testCtx.completedCnt, 1);
+ ASSERT_IF(testCtx.scannedCnt, 0); // should be 1 after dir_get_files implemented
+ ASSERT_IF(testCtx.detectedCnt, 2);
+ ASSERT_IF(testCtx.cancelledCnt, 0);
+ ASSERT_IF(testCtx.errorCnt, 0);
EXCEPTION_GUARD_END
}
auto context = c.get();
csr_cs_detected_h detected;
- ASSERT_IF(csr_cs_get_detected_malware(context, "dummy_file_path", &detected),
+ ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_RISKY, &detected),
CSR_ERROR_NONE);
+ CHECK_IS_NOT_NULL(detected);
- // no malware detected
+ ASSERT_IF(csr_cs_get_detected_malware(context, TEST_FILE_RISKY, &detected),
+ CSR_ERROR_NONE);
CHECK_IS_NOT_NULL(detected);
EXCEPTION_GUARD_END
auto c = Test::Context<csr_cs_context_h>();
auto context = c.get();
csr_cs_detected_list_h detected_list;
+ csr_cs_detected_h detected;
size_t cnt = 0;
- const char *dirs[5] = {
- "dummy_dir_path1",
- "dummy_dir_path2",
- "dummy_dir_path3",
- "dummy_dir_path4",
- "dummy_dir_path5",
+ const char *dirs[1] = {
+ TEST_DIR
};
- ASSERT_IF(
- csr_cs_get_detected_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
- &detected_list, &cnt),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MALWARE, &detected),
+ CSR_ERROR_NONE);
+ CHECK_IS_NOT_NULL(detected);
+ ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_RISKY, &detected),
+ CSR_ERROR_NONE);
+ CHECK_IS_NOT_NULL(detected);
- // no malware detected
+ ASSERT_IF(csr_cs_get_detected_malwares(context, dirs,
+ sizeof(dirs) / sizeof(const char *),
+ &detected_list, &cnt), CSR_ERROR_NONE);
CHECK_IS_NOT_NULL(detected_list);
-
- ASSERT_IF(cnt, static_cast<size_t>(1));
+ ASSERT_IF(cnt, static_cast<size_t>(2));
EXCEPTION_GUARD_END
}
auto c = Test::Context<csr_cs_context_h>();
auto context = c.get();
- csr_cs_detected_h ignored;
+ csr_cs_detected_h detected;
- ASSERT_IF(csr_cs_get_ignored_malware(context, "dummy_file_path", &ignored),
+ ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MALWARE, &detected),
CSR_ERROR_NONE);
+ CHECK_IS_NOT_NULL(detected);
+ ASSERT_IF(csr_cs_judge_detected_malware(context, detected,
+ CSR_CS_ACTION_IGNORE), CSR_ERROR_NONE);
- CHECK_IS_NOT_NULL(ignored);
+ ASSERT_IF(csr_cs_get_ignored_malware(context, TEST_FILE_MALWARE, &detected),
+ CSR_ERROR_NONE);
+
+ CHECK_IS_NOT_NULL(detected);
EXCEPTION_GUARD_END
}
auto c = Test::Context<csr_cs_context_h>();
auto context = c.get();
csr_cs_detected_list_h ignored_list;
+ csr_cs_detected_h detected;
size_t cnt = 0;
- const char *dirs[5] = {
- "dummy_dir_path1",
- "dummy_dir_path2",
- "dummy_dir_path3",
- "dummy_dir_path4",
- "dummy_dir_path5",
+ const char *dirs[1] = {
+ TEST_DIR
};
- ASSERT_IF(
- csr_cs_get_ignored_malwares(context, dirs, sizeof(dirs) / sizeof(const char *),
- &ignored_list, &cnt),
- CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MALWARE, &detected),
+ CSR_ERROR_NONE);
+ CHECK_IS_NOT_NULL(detected);
+ ASSERT_IF(csr_cs_judge_detected_malware(context, detected,
+ CSR_CS_ACTION_IGNORE), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_RISKY, &detected),
+ CSR_ERROR_NONE);
+ CHECK_IS_NOT_NULL(detected);
+ ASSERT_IF(csr_cs_judge_detected_malware(context, detected,
+ CSR_CS_ACTION_IGNORE), CSR_ERROR_NONE);
+ ASSERT_IF(csr_cs_get_ignored_malwares(context, dirs,
+ sizeof(dirs) / sizeof(const char *),
+ &ignored_list, &cnt), CSR_ERROR_NONE);
CHECK_IS_NOT_NULL(ignored_list);
-
- ASSERT_IF(cnt, static_cast<size_t>(1));
+ ASSERT_IF(cnt, static_cast<size_t>(2));
EXCEPTION_GUARD_END
}
auto context = c.get();
csr_cs_detected_h detected;
- ASSERT_IF(csr_cs_get_detected_malware(context, "dummy_file_path", &detected),
+ ASSERT_IF(csr_cs_scan_file(context, TEST_FILE_MALWARE, &detected),
CSR_ERROR_NONE);
CHECK_IS_NOT_NULL(detected);
-
ASSERT_IF(csr_cs_judge_detected_malware(context, detected,
- CSR_CS_ACTION_REMOVE),
- CSR_ERROR_NONE);
+ CSR_CS_ACTION_UNIGNORE), CSR_ERROR_NONE);
EXCEPTION_GUARD_END
}