Exemplo n.º 1
0
TEST_F(ConfigTests, test_get_scheduled_queries) {
  Config c;
  std::vector<ScheduledQuery> queries;
  c.addPack("unrestricted_pack", "", getUnrestrictedPack());
  c.scheduledQueries(
      ([&queries](const std::string&,
                  const ScheduledQuery& query) { queries.push_back(query); }));
  EXPECT_EQ(queries.size(), getUnrestrictedPack().get_child("queries").size());
}
Exemplo n.º 2
0
TEST_F(ConfigTests, test_get_scheduled_queries) {
  std::vector<ScheduledQuery> queries;
  get().addPack("unrestricted_pack", "", getUnrestrictedPack());
  get().scheduledQueries(
      ([&queries](const std::string&, const ScheduledQuery& query) {
        queries.push_back(query);
      }));

  auto expected_size = getUnrestrictedPack().get_child("queries").size();
  EXPECT_EQ(queries.size(), expected_size)
      << "The number of queries in the schedule (" << queries.size()
      << ") should equal " << expected_size;
}
Exemplo n.º 3
0
TEST_F(ConfigTests, test_pack_file_paths) {
  size_t count = 0;
  auto fileCounter = [&count](const std::string& c,
                              const std::vector<std::string>& files) {
    count += files.size();
  };

  get().addPack("unrestricted_pack", "", getUnrestrictedPack());
  get().files(fileCounter);
  EXPECT_EQ(count, 2U);

  count = 0;
  get().removePack("unrestricted_pack");
  get().files(fileCounter);
  EXPECT_EQ(count, 0U);

  count = 0;
  get().addPack("restricted_pack", "", getRestrictedPack());
  get().files(fileCounter);
  EXPECT_EQ(count, 0U);

  // Test a more-generic update.
  count = 0;
  get().update({{"data", "{\"file_paths\": {\"new\": [\"/new\"]}}"}});
  get().files(fileCounter);
  EXPECT_EQ(count, 1U);

  count = 0;
  get().update({{"data", "{}"}});
  get().files(fileCounter);
  EXPECT_EQ(count, 0U);
}
Exemplo n.º 4
0
TEST_F(PacksTests, test_should_pack_execute) {
  auto kpack = Pack("kernel", getUnrestrictedPack());
  EXPECT_TRUE(kpack.shouldPackExecute());

  auto fpack = Pack("foobar", getPackWithDiscovery());
  EXPECT_FALSE(fpack.shouldPackExecute());
}
Exemplo n.º 5
0
TEST_F(PacksTests, test_should_pack_execute) {
  Pack kpack("unrestricted_pack", getUnrestrictedPack());
  EXPECT_TRUE(kpack.shouldPackExecute());

  Pack fpack("discovery_pack", getPackWithDiscovery());
  EXPECT_FALSE(fpack.shouldPackExecute());
}
Exemplo n.º 6
0
TEST_F(ConfigTests, test_remove) {
  Config c;
  c.addPack("unrestricted_pack", "", getUnrestrictedPack());
  c.removePack("unrestricted_pack");

  c.packs(([](Pack& pack) { EXPECT_NE("unrestricted_pack", pack.getName()); }));
}
Exemplo n.º 7
0
TEST_F(ConfigTests, test_remove) {
  Config c;
  c.addPack("unrestricted_pack", "", getUnrestrictedPack());
  c.removePack("unrestricted_pack");
  for (Pack& pack : c.schedule_) {
    EXPECT_NE("unrestricted_pack", pack.getName());
  }
}
Exemplo n.º 8
0
 Status genPack(const std::string& name,
                const std::string& value,
                std::string& pack) override {
   genPackCount++;
   std::stringstream ss;
   pt::write_json(ss, getUnrestrictedPack(), false);
   pack = ss.str();
   return Status(0, "OK");
 }
Exemplo n.º 9
0
TEST_F(PacksTests, test_get_discovery_queries) {
  std::vector<std::string> expected;

  auto kpack = Pack("kernel", getUnrestrictedPack());
  EXPECT_EQ(kpack.getDiscoveryQueries(), expected);

  expected = {"select pid from processes where name = 'foobar';"};
  auto fpack = Pack("foobar", getPackWithDiscovery());
  EXPECT_EQ(fpack.getDiscoveryQueries(), expected);
}
Exemplo n.º 10
0
TEST_F(ConfigTests, test_pack_removal) {
  size_t pack_count = 0;
  get().packs(([&pack_count](std::shared_ptr<Pack>& pack) { pack_count++; }));
  EXPECT_EQ(pack_count, 0U);

  pack_count = 0;
  get().addPack("unrestricted_pack", "", getUnrestrictedPack());
  get().packs(([&pack_count](std::shared_ptr<Pack>& pack) { pack_count++; }));
  EXPECT_EQ(pack_count, 1U);

  pack_count = 0;
  get().removePack("unrestricted_pack");
  get().packs(([&pack_count](std::shared_ptr<Pack>& pack) { pack_count++; }));
  EXPECT_EQ(pack_count, 0U);
}
Exemplo n.º 11
0
TEST_F(ConfigTests, test_add_remove_pack) {
  Config c;
  auto first = c.schedule_.begin();
  auto last = c.schedule_.end();
  EXPECT_EQ(std::distance(first, last), 0);

  c.addPack("unrestricted_pack", "", getUnrestrictedPack());
  first = c.schedule_.begin();
  last = c.schedule_.end();
  EXPECT_EQ(std::distance(first, last), 1);

  c.removePack("unrestricted_pack");
  first = c.schedule_.begin();
  last = c.schedule_.end();
  EXPECT_EQ(std::distance(first, last), 0);
}
Exemplo n.º 12
0
TEST_F(ConfigTests, test_add_remove_pack) {
  Config c;

  size_t pack_count = 0;
  c.packs(([&pack_count](Pack& pack) { pack_count++; }));
  EXPECT_EQ(pack_count, 0U);

  pack_count = 0;
  c.addPack("unrestricted_pack", "", getUnrestrictedPack());
  c.packs(([&pack_count](Pack& pack) { pack_count++; }));
  EXPECT_EQ(pack_count, 1U);

  pack_count = 0;
  c.removePack("unrestricted_pack");
  c.packs(([&pack_count](Pack& pack) { pack_count++; }));
  EXPECT_EQ(pack_count, 0U);
}
Exemplo n.º 13
0
 Status genConfig(std::map<std::string, std::string>& config) override {
     std::stringstream ss;
     pt::write_json(ss, getUnrestrictedPack(), false);
     config["data"] = ss.str();
     return Status(0);
 }