2018-08-27 16:21:26 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2019-02-19 18:52:19 +00:00
|
|
|
* This source code is licensed in accordance with the terms specified in
|
|
|
|
* the LICENSE file found in the root directory of this source tree.
|
2018-08-27 16:21:26 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Sanity check integration test for deb_packages
|
|
|
|
// Spec file: specs/linux/deb_packages.table
|
|
|
|
|
2018-08-29 17:04:15 +00:00
|
|
|
#include <osquery/logger.h>
|
2020-06-05 18:22:03 +00:00
|
|
|
#include <osquery/tests/integration/tables/helper.h>
|
|
|
|
#include <osquery/utils/info/platform_type.h>
|
2018-08-29 17:04:15 +00:00
|
|
|
|
2018-08-27 16:21:26 +00:00
|
|
|
namespace osquery {
|
2018-09-21 18:54:31 +00:00
|
|
|
namespace table_tests {
|
2018-08-27 16:21:26 +00:00
|
|
|
|
2018-09-21 18:54:31 +00:00
|
|
|
class DebPackages : public testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
|
|
|
setUpEnvironment();
|
|
|
|
}
|
|
|
|
};
|
2018-08-29 17:04:15 +00:00
|
|
|
|
|
|
|
TEST_F(DebPackages, test_sanity) {
|
|
|
|
QueryData rows = execute_query("select * from deb_packages");
|
|
|
|
if (rows.size() > 0) {
|
2020-03-31 13:32:25 +00:00
|
|
|
ValidationMap row_map = {{"name", NonEmptyString},
|
|
|
|
{"version", NonEmptyString},
|
|
|
|
{"source", NormalType},
|
|
|
|
{"size", IntType},
|
|
|
|
{"arch", NonEmptyString},
|
|
|
|
{"revision", NormalType},
|
2020-05-21 00:55:40 +00:00
|
|
|
{"status", NonEmptyString},
|
|
|
|
{"maintainer", NonEmptyString},
|
|
|
|
{"section", NonEmptyString},
|
|
|
|
{"priority", NonEmptyString}};
|
2020-06-05 18:22:03 +00:00
|
|
|
|
2018-08-29 19:16:00 +00:00
|
|
|
validate_rows(rows, row_map);
|
2018-08-29 17:04:15 +00:00
|
|
|
|
|
|
|
auto all_packages = std::unordered_set<std::string>{};
|
|
|
|
for (const auto& row : rows) {
|
|
|
|
auto pckg_name = row.at("name");
|
|
|
|
all_packages.insert(pckg_name);
|
2019-11-19 04:43:18 +00:00
|
|
|
if (pckg_name == "dpkg") {
|
2019-11-01 14:36:42 +00:00
|
|
|
break;
|
2019-11-19 04:43:18 +00:00
|
|
|
}
|
2018-08-29 17:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_EQ(all_packages.count("dpkg"), 1u);
|
|
|
|
|
2020-06-05 18:22:03 +00:00
|
|
|
if (isPlatform(PlatformType::TYPE_LINUX)) {
|
2020-06-06 01:22:44 +00:00
|
|
|
validate_container_rows("deb_packages", row_map);
|
2020-06-05 18:22:03 +00:00
|
|
|
}
|
|
|
|
|
2018-08-29 17:04:15 +00:00
|
|
|
} else {
|
|
|
|
LOG(WARNING) << "Empty results of query from 'deb_packages', assume there "
|
|
|
|
"is no dpkg in the system";
|
|
|
|
}
|
2018-08-27 16:21:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-21 18:54:31 +00:00
|
|
|
} // namespace table_tests
|
2018-08-27 16:21:26 +00:00
|
|
|
} // namespace osquery
|