[Table sanity check] process_events (#5132)

This commit is contained in:
Filipe Manco 2018-08-30 10:02:45 +01:00 committed by GitHub
parent 4cb0b2cb57
commit 40a770025c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,27 +14,52 @@
#include <osquery/tests/integration/tables/helper.h> #include <osquery/tests/integration/tables/helper.h>
#include <algorithm>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
namespace osquery { namespace osquery {
class processEnvs : public IntegrationTableTest {}; class ProcessEnvs : public IntegrationTableTest {
public:
ProcessEnvs()
: env_name("OSQUERY_TEST_ENV_NAME"),
env_value("osquery_test_env_value") {}
TEST_F(processEnvs, test_sanity) { void SetUp() override {
// 1. Query data ::setenv(env_name.c_str(), env_value.c_str(), 1);
// QueryData data = execute_query("select * from process_envs"); }
// 2. Check size before validation
// ASSERT_GE(data.size(), 0ul); void TearDown() override {
// ASSERT_EQ(data.size(), 1ul); ::unsetenv(env_name.c_str());
// ASSERT_EQ(data.size(), 0ul); }
// 3. Build validation map
// See IntegrationTableTest.cpp for avaialbe flags const std::string env_name;
// Or use custom DataCheck object const std::string env_value;
// ValidatatioMap row_map = { };
// {"pid", IntType}
// {"key", NormalType} TEST_F(ProcessEnvs, test_sanity) {
// {"value", NormalType} QueryData data = execute_query("select * from process_envs");
//}
// 4. Perform validation ValidatatioMap row_map = {
// validate_rows(data, row_map); {"pid", NonNegativeInt},
{"key", NonEmptyString},
{"value", NormalType},
};
validate_rows(data, row_map);
if (isPlatform(PlatformType::TYPE_LINUX)) {
std::string pid = std::to_string(::getpid());
Row r{
{"pid", pid},
{"key", env_name},
{"value", env_value},
};
ASSERT_NE(std::find(data.begin(), data.end(), r), data.end())
<< "Test env variable not found";
}
} }
} // namespace osquery } // namespace osquery