2014-12-18 18:50:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
2015-04-23 00:49:27 +00:00
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
2014-12-18 18:50:47 +00:00
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-09-10 01:54:53 +00:00
|
|
|
#pragma once
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
|
2014-12-03 23:14:02 +00:00
|
|
|
#include <osquery/config.h>
|
|
|
|
#include <osquery/core.h>
|
|
|
|
#include <osquery/database.h>
|
|
|
|
#include <osquery/filesystem.h>
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-04-27 21:57:04 +00:00
|
|
|
namespace pt = boost::property_tree;
|
|
|
|
|
2014-08-15 07:25:30 +00:00
|
|
|
namespace osquery {
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-04-29 19:36:24 +00:00
|
|
|
/// Any SQL-dependent tests should use kTestQuery for a pre-populated example.
|
|
|
|
const std::string kTestQuery = "SELECT * FROM test_table";
|
|
|
|
|
2015-05-23 19:40:36 +00:00
|
|
|
extern std::string kTestDataPath;
|
2015-04-29 19:36:24 +00:00
|
|
|
|
|
|
|
/// Tests should limit intermediate input/output to a working directory.
|
|
|
|
/// Config data, logging results, and intermediate database/caching usage.
|
|
|
|
#ifdef DARWIN
|
|
|
|
const std::string kTestWorkingDirectory = "/private/tmp/osquery-tests/";
|
|
|
|
#else
|
|
|
|
const std::string kTestWorkingDirectory = "/tmp/osquery-tests/";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/// A fake directory tree should be used for filesystem iterator testing.
|
|
|
|
const std::string kFakeDirectory = kTestWorkingDirectory + "fstree";
|
2015-02-14 00:52:11 +00:00
|
|
|
|
2015-04-27 21:57:04 +00:00
|
|
|
ScheduledQuery getOsqueryScheduledQuery();
|
|
|
|
|
2014-07-31 00:35:19 +00:00
|
|
|
// getTestDBExpectedResults returns the results of kTestQuery of the table that
|
|
|
|
// initially gets returned from createTestDB()
|
2015-03-22 21:58:00 +00:00
|
|
|
QueryData getTestDBExpectedResults();
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
// Starting with the dataset returned by createTestDB(), getTestDBResultStream
|
|
|
|
// returns a vector of std::pair's where pair.first is the query that would
|
|
|
|
// need to be performed on the dataset to make the results be pair.second
|
2015-03-22 21:58:00 +00:00
|
|
|
std::vector<std::pair<std::string, QueryData> > getTestDBResultStream();
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
// getSerializedRow() return an std::pair where pair->first is a string which
|
2015-03-22 21:58:00 +00:00
|
|
|
// should serialize to pair->second. pair->second should deserialize
|
2014-07-31 00:35:19 +00:00
|
|
|
// to pair->first
|
2015-04-27 21:57:04 +00:00
|
|
|
std::pair<pt::ptree, Row> getSerializedRow();
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
// getSerializedQueryData() return an std::pair where pair->first is a string
|
2015-03-22 21:58:00 +00:00
|
|
|
// which should serialize to pair->second. pair->second should
|
2014-07-31 00:35:19 +00:00
|
|
|
// deserialize to pair->first
|
2015-04-27 21:57:04 +00:00
|
|
|
std::pair<pt::ptree, QueryData> getSerializedQueryData();
|
|
|
|
std::pair<std::string, QueryData> getSerializedQueryDataJSON();
|
2014-07-31 00:35:19 +00:00
|
|
|
|
|
|
|
// getSerializedDiffResults() return an std::pair where pair->first is a string
|
2015-03-22 21:58:00 +00:00
|
|
|
// which should serialize to pair->second. pair->second should
|
2014-07-31 00:35:19 +00:00
|
|
|
// deserialize to pair->first
|
2015-04-27 21:57:04 +00:00
|
|
|
std::pair<pt::ptree, DiffResults> getSerializedDiffResults();
|
2015-03-22 21:58:00 +00:00
|
|
|
std::pair<std::string, DiffResults> getSerializedDiffResultsJSON();
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2015-04-27 21:57:04 +00:00
|
|
|
// getSerializedQueryLogItem() return an std::pair where pair->first
|
2015-03-22 21:58:00 +00:00
|
|
|
// is a string which should serialize to pair->second. pair->second
|
2014-07-31 00:35:19 +00:00
|
|
|
// should deserialize to pair->first
|
2015-04-27 21:57:04 +00:00
|
|
|
std::pair<pt::ptree, QueryLogItem> getSerializedQueryLogItem();
|
|
|
|
std::pair<std::string, QueryLogItem> getSerializedQueryLogItemJSON();
|
2014-07-31 00:35:19 +00:00
|
|
|
|
2014-08-17 08:44:22 +00:00
|
|
|
// generate content for a PEM-encoded certificate
|
|
|
|
std::string getCACertificateContent();
|
|
|
|
|
2014-08-02 03:46:22 +00:00
|
|
|
// generate the content that would be found in an /etc/hosts file
|
|
|
|
std::string getEtcHostsContent();
|
|
|
|
|
2015-04-23 00:49:27 +00:00
|
|
|
// generate the content that would be found in an /etc/protocols file
|
|
|
|
std::string getEtcProtocolsContent();
|
|
|
|
|
2014-08-02 03:46:22 +00:00
|
|
|
// generate the expected data that getEtcHostsContent() should parse into
|
2015-03-22 21:58:00 +00:00
|
|
|
QueryData getEtcHostsExpectedResults();
|
2014-08-02 03:46:22 +00:00
|
|
|
|
2015-04-23 00:49:27 +00:00
|
|
|
// generate the expected data that getEtcProtocolsContent() should parse into
|
|
|
|
QueryData getEtcProtocolsExpectedResults();
|
|
|
|
|
2015-01-21 21:36:55 +00:00
|
|
|
// the three items that you need to test osquery::splitString
|
2014-08-04 21:12:06 +00:00
|
|
|
struct SplitStringTestData {
|
|
|
|
std::string test_string;
|
2014-08-04 23:08:49 +00:00
|
|
|
std::string delim;
|
2014-08-04 21:12:06 +00:00
|
|
|
std::vector<std::string> test_vector;
|
|
|
|
};
|
|
|
|
|
2015-01-21 21:36:55 +00:00
|
|
|
// generate a set of test data to test osquery::splitString
|
2014-08-04 21:12:06 +00:00
|
|
|
std::vector<SplitStringTestData> generateSplitStringTestData();
|
2015-02-14 00:52:11 +00:00
|
|
|
|
|
|
|
// generate a small directory structure for testing
|
|
|
|
void createMockFileStructure();
|
|
|
|
// remove the small directory structure used for testing
|
|
|
|
void tearDownMockFileStructure();
|
2014-08-15 07:25:30 +00:00
|
|
|
}
|