osquery-1/osquery/config/tests/test_utils.cpp
Jesse Kornblum c7355b19aa Update osquery licensing wording (#5452)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5452

As suggested in another diff, this diff updates the language we use to describe the osquery licensing terms. We are changing all instances of

//This source code is licensed as defined on the LICENSE file found in the root directory of this source tree.//

to

//This source code is licensed in accordance with the terms specified in the LICENSE file found in the root directory of this source tree.//

We accomplish this with a codemod:

  $ codemod -md xplat/osquery/oss --extensions cpp,h,in,py,sh,mm,ps1 "(.\s+)This source code is licensed as defined on the LICENSE file found in the(.*)root directory of this source tree\." "\1This source code is licensed in accordance with the terms specified in\2the LICENSE file found in the root directory of this source tree."

Reviewed By: fmanco

Differential Revision: D14131290

fbshipit-source-id: 52c90da342263e2a80f5a678ecd760c19cf7513e
2019-02-19 10:59:48 -08:00

98 lines
2.8 KiB
C++

/**
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed in accordance with the terms specified in
* the LICENSE file found in the root directory of this source tree.
*/
#include <osquery/config/tests/test_utils.h>
#include <osquery/filesystem/filesystem.h>
#include <osquery/utils/system/env.h>
#include <gtest/gtest.h>
#include <boost/io/detail/quoted_manip.hpp>
#include <cstdlib>
namespace {
namespace fs = boost::filesystem;
fs::path getConfDirPathImpl() {
char const* kEnvVarName = "TEST_CONF_FILES_DIR";
auto const value_opt = osquery::getEnvVar(kEnvVarName);
EXPECT_TRUE(static_cast<bool>(value_opt))
<< "Env var " << boost::io::quoted(kEnvVarName) << " was not found, "
<< " looks like cxx_test argument 'env' is not set up.";
return fs::path(value_opt.get());
}
}
namespace osquery {
fs::path const& getTestConfigDirectory() {
static auto const path = getConfDirPathImpl();
return path;
}
std::map<std::string, std::string> getTestConfigMap(const std::string& file) {
std::string content;
auto const filepath = getTestConfigDirectory() / file;
auto status = readFile(filepath, content);
EXPECT_TRUE(status.ok())
<< "Could not read file: " << boost::io::quoted(filepath.string())
<< ", because: " << status.what();
std::map<std::string, std::string> config;
config["awesome"] = content;
return config;
}
JSON getExamplePacksConfig() {
std::string content;
auto const filepath = getTestConfigDirectory() / "test_inline_pack.conf";
auto status = readFile(filepath, content);
EXPECT_TRUE(status.ok())
<< "Could not read file: " << boost::io::quoted(filepath.string())
<< ", because: " << status.what();
JSON doc = JSON::newObject();
doc.fromString(content);
return doc;
}
/// no discovery queries, no platform restriction
JSON getUnrestrictedPack() {
auto doc = getExamplePacksConfig();
return JSON::newFromValue(doc.doc()["packs"]["unrestricted_pack"]);
}
// several restrictions (version, platform, shard)
JSON getRestrictedPack() {
auto doc = getExamplePacksConfig();
return JSON::newFromValue(doc.doc()["packs"]["restricted_pack"]);
}
/// 1 discovery query, darwin platform restriction
JSON getPackWithDiscovery() {
auto doc = getExamplePacksConfig();
return JSON::newFromValue(doc.doc()["packs"]["discovery_pack"]);
}
/// 1 discovery query which will always pass
JSON getPackWithValidDiscovery() {
auto doc = getExamplePacksConfig();
return JSON::newFromValue(doc.doc()["packs"]["valid_discovery_pack"]);
}
/// no discovery queries, no platform restriction, fake version string
JSON getPackWithFakeVersion() {
auto doc = getExamplePacksConfig();
return JSON::newFromValue(doc.doc()["packs"]["fake_version_pack"]);
}
} // namespace osquery