2015-01-23 22:52:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <boost/property_tree/json_parser.hpp>
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
2016-01-21 08:23:05 +00:00
|
|
|
|
2015-01-23 22:52:07 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
|
|
|
#include <osquery/core.h>
|
2015-09-07 18:09:06 +00:00
|
|
|
#include <osquery/distributed.h>
|
2015-09-16 17:36:34 +00:00
|
|
|
#include <osquery/enroll.h>
|
2015-01-23 22:52:07 +00:00
|
|
|
#include <osquery/sql.h>
|
|
|
|
|
2015-09-07 18:09:06 +00:00
|
|
|
#include "osquery/core/test_util.h"
|
|
|
|
|
2015-02-23 05:56:52 +00:00
|
|
|
#include "osquery/sql/sqlite_util.h"
|
2015-01-23 22:52:07 +00:00
|
|
|
|
|
|
|
namespace pt = boost::property_tree;
|
|
|
|
|
2015-09-16 17:36:34 +00:00
|
|
|
DECLARE_string(distributed_tls_read_endpoint);
|
|
|
|
DECLARE_string(distributed_tls_write_endpoint);
|
|
|
|
|
2015-01-23 22:52:07 +00:00
|
|
|
namespace osquery {
|
|
|
|
|
2015-09-16 17:36:34 +00:00
|
|
|
class DistributedTests : public testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() {
|
2015-09-07 18:09:06 +00:00
|
|
|
TLSServerRunner::start();
|
2016-01-21 08:23:05 +00:00
|
|
|
TLSServerRunner::setClientConfig();
|
2015-09-16 17:36:34 +00:00
|
|
|
clearNodeKey();
|
|
|
|
|
|
|
|
distributed_tls_read_endpoint_ =
|
|
|
|
Flag::getValue("distributed_tls_read_endpoint");
|
|
|
|
Flag::updateValue("distributed_tls_read_endpoint", "/distributed_read");
|
|
|
|
|
|
|
|
distributed_tls_write_endpoint_ =
|
|
|
|
Flag::getValue("distributed_tls_write_endpoint");
|
|
|
|
Flag::updateValue("distributed_tls_write_endpoint", "/distributed_write");
|
2015-01-23 22:52:07 +00:00
|
|
|
|
2015-09-16 17:36:34 +00:00
|
|
|
Registry::setActive("distributed", "tls");
|
2015-09-07 18:09:06 +00:00
|
|
|
}
|
2015-01-23 22:52:07 +00:00
|
|
|
|
2015-09-16 17:36:34 +00:00
|
|
|
void TearDown() {
|
|
|
|
TLSServerRunner::stop();
|
2016-01-21 08:23:05 +00:00
|
|
|
TLSServerRunner::unsetClientConfig();
|
2015-09-16 17:36:34 +00:00
|
|
|
clearNodeKey();
|
2016-01-21 08:23:05 +00:00
|
|
|
|
2015-09-16 17:36:34 +00:00
|
|
|
Flag::updateValue("distributed_tls_read_endpoint",
|
|
|
|
distributed_tls_read_endpoint_);
|
|
|
|
Flag::updateValue("distributed_tls_write_endpoint",
|
|
|
|
distributed_tls_write_endpoint_);
|
2015-09-07 18:09:06 +00:00
|
|
|
}
|
2015-01-23 22:52:07 +00:00
|
|
|
|
2016-01-21 08:23:05 +00:00
|
|
|
protected:
|
2015-09-16 17:36:34 +00:00
|
|
|
std::string distributed_tls_read_endpoint_;
|
|
|
|
std::string distributed_tls_write_endpoint_;
|
2015-09-07 18:09:06 +00:00
|
|
|
};
|
2015-01-23 22:52:07 +00:00
|
|
|
|
2015-09-07 18:09:06 +00:00
|
|
|
TEST_F(DistributedTests, test_workflow) {
|
|
|
|
auto dist = Distributed();
|
|
|
|
auto s = dist.pullUpdates();
|
|
|
|
EXPECT_TRUE(s.ok());
|
|
|
|
EXPECT_EQ(s.toString(), "OK");
|
2015-01-23 22:52:07 +00:00
|
|
|
|
2015-10-20 06:08:01 +00:00
|
|
|
EXPECT_EQ(dist.getPendingQueryCount(), 2U);
|
|
|
|
EXPECT_EQ(dist.results_.size(), 0U);
|
2015-09-07 18:09:06 +00:00
|
|
|
s = dist.runQueries();
|
|
|
|
EXPECT_TRUE(s.ok());
|
|
|
|
EXPECT_EQ(s.toString(), "OK");
|
2015-09-16 17:36:34 +00:00
|
|
|
|
2015-10-20 06:08:01 +00:00
|
|
|
EXPECT_EQ(dist.getPendingQueryCount(), 0U);
|
|
|
|
EXPECT_EQ(dist.results_.size(), 2U);
|
2015-01-23 22:52:07 +00:00
|
|
|
}
|
|
|
|
}
|