osquery-1/osquery/distributed/tests/distributed_tests.cpp

84 lines
2.2 KiB
C++
Raw Normal View History

/*
* 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
#include <gtest/gtest.h>
#include <osquery/core.h>
2015-09-07 18:09:06 +00:00
#include <osquery/distributed.h>
#include <osquery/enroll.h>
#include <osquery/sql.h>
2015-09-07 18:09:06 +00:00
#include "osquery/core/test_util.h"
#include "osquery/sql/sqlite_util.h"
namespace pt = boost::property_tree;
DECLARE_string(distributed_tls_read_endpoint);
DECLARE_string(distributed_tls_write_endpoint);
namespace osquery {
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();
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");
Registry::setActive("distributed", "tls");
2015-09-07 18:09:06 +00:00
}
void TearDown() {
TLSServerRunner::stop();
2016-01-21 08:23:05 +00:00
TLSServerRunner::unsetClientConfig();
clearNodeKey();
2016-01-21 08:23:05 +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
}
2016-01-21 08:23:05 +00:00
protected:
std::string distributed_tls_read_endpoint_;
std::string distributed_tls_write_endpoint_;
2015-09-07 18:09:06 +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-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-10-20 06:08:01 +00:00
EXPECT_EQ(dist.getPendingQueryCount(), 0U);
EXPECT_EQ(dist.results_.size(), 2U);
}
}