mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 09:58:54 +00:00
Add a TLS config plugin test that runs the scheduler (#2898)
This commit is contained in:
parent
1d604fc1af
commit
0178419085
@ -331,6 +331,7 @@ class Config : private boost::noncopyable {
|
|||||||
FRIEND_TEST(SchedulerTests, test_config_results_purge);
|
FRIEND_TEST(SchedulerTests, test_config_results_purge);
|
||||||
FRIEND_TEST(EventsTests, test_event_subscriber_configure);
|
FRIEND_TEST(EventsTests, test_event_subscriber_configure);
|
||||||
FRIEND_TEST(TLSConfigTests, test_retrieve_config);
|
FRIEND_TEST(TLSConfigTests, test_retrieve_config);
|
||||||
|
FRIEND_TEST(TLSConfigTests, test_runner_and_scheduler);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,9 +20,10 @@
|
|||||||
#include <osquery/system.h>
|
#include <osquery/system.h>
|
||||||
#include <osquery/tables.h>
|
#include <osquery/tables.h>
|
||||||
|
|
||||||
|
#include "osquery/config/plugins/tls.h"
|
||||||
#include "osquery/core/conversions.h"
|
#include "osquery/core/conversions.h"
|
||||||
#include "osquery/core/json.h"
|
#include "osquery/core/json.h"
|
||||||
|
#include "osquery/dispatcher/scheduler.h"
|
||||||
#include "osquery/remote/requests.h"
|
#include "osquery/remote/requests.h"
|
||||||
#include "osquery/remote/serializers/json.h"
|
#include "osquery/remote/serializers/json.h"
|
||||||
#include "osquery/remote/transports/tls.h"
|
#include "osquery/remote/transports/tls.h"
|
||||||
@ -31,8 +32,6 @@
|
|||||||
#include "osquery/tests/test_additional_util.h"
|
#include "osquery/tests/test_additional_util.h"
|
||||||
#include "osquery/tests/test_util.h"
|
#include "osquery/tests/test_util.h"
|
||||||
|
|
||||||
#include "osquery/config/plugins/tls.h"
|
|
||||||
|
|
||||||
namespace pt = boost::property_tree;
|
namespace pt = boost::property_tree;
|
||||||
|
|
||||||
namespace osquery {
|
namespace osquery {
|
||||||
@ -40,14 +39,39 @@ namespace osquery {
|
|||||||
DECLARE_string(tls_hostname);
|
DECLARE_string(tls_hostname);
|
||||||
DECLARE_bool(enroll_always);
|
DECLARE_bool(enroll_always);
|
||||||
|
|
||||||
class TLSConfigTests : public testing::Test {};
|
class TLSConfigTests : public testing::Test {
|
||||||
|
public:
|
||||||
|
void SetUp() override {
|
||||||
|
TLSServerRunner::start();
|
||||||
|
TLSServerRunner::setClientConfig();
|
||||||
|
|
||||||
|
active_ = Registry::get().getActive("config");
|
||||||
|
plugin_ = Flag::getValue("config_plugin");
|
||||||
|
endpoint_ = Flag::getValue("config_tls_endpoint");
|
||||||
|
node_ = Flag::getValue("tls_node_api");
|
||||||
|
enroll_ = FLAGS_enroll_always;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override {
|
||||||
|
TLSServerRunner::unsetClientConfig();
|
||||||
|
TLSServerRunner::stop();
|
||||||
|
|
||||||
|
Flag::updateValue("config_plugin", plugin_);
|
||||||
|
Flag::updateValue("config_tls_endpoint", endpoint_);
|
||||||
|
Flag::updateValue("tls_node_api", node_);
|
||||||
|
FLAGS_enroll_always = enroll_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string active_;
|
||||||
|
std::string plugin_;
|
||||||
|
std::string endpoint_;
|
||||||
|
std::string node_;
|
||||||
|
bool enroll_{false};
|
||||||
|
};
|
||||||
|
|
||||||
TEST_F(TLSConfigTests, test_retrieve_config) {
|
TEST_F(TLSConfigTests, test_retrieve_config) {
|
||||||
TLSServerRunner::start();
|
|
||||||
TLSServerRunner::setClientConfig();
|
|
||||||
|
|
||||||
// Trigger the enroll.
|
// Trigger the enroll.
|
||||||
auto endpoint = Flag::getValue("config_tls_endpoint");
|
|
||||||
Flag::updateValue("config_tls_endpoint", "/config");
|
Flag::updateValue("config_tls_endpoint", "/config");
|
||||||
Registry::get().setActive("config", "tls");
|
Registry::get().setActive("config", "tls");
|
||||||
|
|
||||||
@ -57,7 +81,7 @@ TEST_F(TLSConfigTests, test_retrieve_config) {
|
|||||||
c.load();
|
c.load();
|
||||||
|
|
||||||
const auto& hashes = c.hash_;
|
const auto& hashes = c.hash_;
|
||||||
EXPECT_EQ("b7718020a76ced2eda82336bd15165009603d4fb",
|
EXPECT_EQ("d9b4a05d914c81a1ed4ce129928e2d9a0309c753",
|
||||||
hashes.at("tls_plugin"));
|
hashes.at("tls_plugin"));
|
||||||
|
|
||||||
// Configure the plugin to use the node API.
|
// Configure the plugin to use the node API.
|
||||||
@ -71,19 +95,25 @@ TEST_F(TLSConfigTests, test_retrieve_config) {
|
|||||||
|
|
||||||
// The GET and POST results are slightly different.
|
// The GET and POST results are slightly different.
|
||||||
EXPECT_EQ("baz", response[0]["tls_plugin"]);
|
EXPECT_EQ("baz", response[0]["tls_plugin"]);
|
||||||
|
}
|
||||||
|
|
||||||
// Clean up.
|
TEST_F(TLSConfigTests, test_runner_and_scheduler) {
|
||||||
Flag::updateValue("tls_node_api", "0");
|
Flag::updateValue("config_tls_endpoint", "/config");
|
||||||
Flag::updateValue("config_tls_endpoint", endpoint);
|
// Will cause another enroll.
|
||||||
TLSServerRunner::unsetClientConfig();
|
Registry::get().setActive("config", "tls");
|
||||||
TLSServerRunner::stop();
|
|
||||||
|
// Seed our instance config with a schedule.
|
||||||
|
Config::getInstance().load();
|
||||||
|
|
||||||
|
// Start a scheduler runner for 3 seconds.
|
||||||
|
auto t = static_cast<unsigned long int>(getUnixTime());
|
||||||
|
Dispatcher::addService(std::make_shared<SchedulerRunner>(t + 1, 1));
|
||||||
|
// Reload our instance config.
|
||||||
|
Config::getInstance().load();
|
||||||
|
Dispatcher::joinServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TLSConfigTests, test_setup) {
|
TEST_F(TLSConfigTests, test_setup) {
|
||||||
// Start a server.
|
|
||||||
TLSServerRunner::start();
|
|
||||||
TLSServerRunner::setClientConfig();
|
|
||||||
|
|
||||||
// Set a cached node key like the code would have set after a successful
|
// Set a cached node key like the code would have set after a successful
|
||||||
// enroll. Setting both nodeKey and nodeKeyTime emulates the behavior of a
|
// enroll. Setting both nodeKey and nodeKeyTime emulates the behavior of a
|
||||||
// successful enroll.
|
// successful enroll.
|
||||||
@ -152,9 +182,5 @@ TEST_F(TLSConfigTests, test_setup) {
|
|||||||
// Verify that it is indeed Enroll
|
// Verify that it is indeed Enroll
|
||||||
db_value = response_tree.get<std::string>(".command");
|
db_value = response_tree.get<std::string>(".command");
|
||||||
EXPECT_STREQ(db_value.c_str(), "enroll");
|
EXPECT_STREQ(db_value.c_str(), "enroll");
|
||||||
|
|
||||||
// Stop the server.
|
|
||||||
TLSServerRunner::unsetClientConfig();
|
|
||||||
TLSServerRunner::stop();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ from urlparse import parse_qs
|
|||||||
|
|
||||||
EXAMPLE_CONFIG = {
|
EXAMPLE_CONFIG = {
|
||||||
"schedule": {
|
"schedule": {
|
||||||
"tls_proc": {"query": "select * from processes", "interval": 0},
|
"tls_proc": {"query": "select * from processes", "interval": 1},
|
||||||
},
|
},
|
||||||
"node_invalid": False,
|
"node_invalid": False,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user