std::pair<JSON, QueryLogItem> getSerializedQueryLogItem() { std::pair<JSON, QueryLogItem> p; QueryLogItem i; JSON doc = JSON::newObject(); auto dr = getSerializedDiffResults(); i.results = std::move(dr.second); i.name = "foobar"; i.calendar_time = "Mon Aug 25 12:10:57 2014"; i.time = 1408993857; i.identifier = "foobaz"; i.epoch = 0L; i.counter = 0L; auto diff_doc = doc.getObject(); diff_doc.Swap(dr.first.doc()); doc.add("diffResults", diff_doc); doc.addRef("name", "foobar"); doc.addRef("hostIdentifier", "foobaz"); doc.addRef("calendarTime", "Mon Aug 25 12:10:57 2014"); doc.add("unixTime", 1408993857); doc.add("epoch", 0_sz); doc.add("counter", 0_sz); return std::make_pair(std::move(doc), std::move(i)); }
std::pair<std::string, osquery::DiffResults> getSerializedDiffResultsJSON() { auto results = getSerializedDiffResults(); std::ostringstream ss; pt::write_json(ss, results.first, false); return std::make_pair(ss.str(), results.second); }
TEST_F(ResultsTests, test_serialize_diff_results) { auto results = getSerializedDiffResults(); pt::ptree tree; auto s = serializeDiffResults(results.second, tree); EXPECT_TRUE(s.ok()); EXPECT_EQ(s.toString(), "OK"); EXPECT_EQ(results.first, tree); }
std::pair<pt::ptree, QueryLogItem> getSerializedQueryLogItem() { QueryLogItem i; pt::ptree root; auto dr = getSerializedDiffResults(); i.results = dr.second; i.name = "foobar"; i.calendar_time = "Mon Aug 25 12:10:57 2014"; i.time = 1408993857; i.identifier = "foobaz"; root.add_child("diffResults", dr.first); root.put<std::string>("name", "foobar"); root.put<std::string>("hostIdentifier", "foobaz"); root.put<std::string>("calendarTime", "Mon Aug 25 12:10:57 2014"); root.put<int>("unixTime", 1408993857); return std::make_pair(root, i); }
std::pair<pt::ptree, osquery::HistoricalQueryResults> getSerializedHistoricalQueryResults() { auto qd = getSerializedQueryData(); auto dr = getSerializedDiffResults(); HistoricalQueryResults r; r.mostRecentResults.first = 2; r.mostRecentResults.second = qd.second; pt::ptree root; pt::ptree mostRecentResults; mostRecentResults.add_child("2", qd.first); root.add_child("mostRecentResults", mostRecentResults); return std::make_pair(root, r); }
std::pair<std::string, DiffResults> getSerializedDiffResultsJSON() { auto results = getSerializedDiffResults(); std::string output; results.first.toString(output); return std::make_pair(output, std::move(results.second)); }