mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-07 18:08:53 +00:00
262833c86a
This commit adds logger plugin implementations for the Amazon Kinesis (https://aws.amazon.com/kinesis/) and Kinesis Firehose (https://aws.amazon.com/kinesis/firehose/) services. To support these plugins there are a number of utility classes and functions for AWS authentication, configuration and API integration. The logger plugin implementations take advantage of the BufferedLogForwarder base class for reliable buffering and batch sending of logs. In their current implementations, the logger plugins only support sending of result logs to these AWS services.
78 lines
2.4 KiB
C++
78 lines
2.4 KiB
C++
/*
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <aws/core/utils/Outcome.h>
|
|
#include <aws/firehose/model/PutRecordBatchRequest.h>
|
|
#include <aws/firehose/model/PutRecordBatchResponseEntry.h>
|
|
#include <aws/firehose/model/PutRecordBatchResult.h>
|
|
|
|
#include <osquery/logger.h>
|
|
|
|
#include "osquery/core/test_util.h"
|
|
#include "osquery/logger/plugins/aws_firehose.h"
|
|
|
|
using namespace testing;
|
|
|
|
namespace osquery {
|
|
|
|
// Match on just the data element of a PutRecordBatchEntry
|
|
MATCHER_P(MatchesEntry, data, "") {
|
|
return data ==
|
|
std::string(reinterpret_cast<char*>(arg.GetData().GetUnderlyingData()),
|
|
arg.GetData().GetLength());
|
|
}
|
|
|
|
class MockFirehoseClient : public Aws::Firehose::FirehoseClient {
|
|
public:
|
|
MOCK_CONST_METHOD1(
|
|
PutRecordBatch,
|
|
Aws::Firehose::Model::PutRecordBatchOutcome(
|
|
const Aws::Firehose::Model::PutRecordBatchRequest& request));
|
|
};
|
|
|
|
class FirehoseTests : public testing::Test {};
|
|
|
|
TEST_F(FirehoseTests, test_send) {
|
|
FirehoseLogForwarder forwarder;
|
|
auto client = std::make_shared<StrictMock<MockFirehoseClient>>();
|
|
forwarder.client_ = client;
|
|
|
|
std::vector<std::string> logs{"foo"};
|
|
Aws::Firehose::Model::PutRecordBatchOutcome outcome;
|
|
outcome.GetResult().SetFailedPutCount(0);
|
|
EXPECT_CALL(*client,
|
|
PutRecordBatch(Property(
|
|
&Aws::Firehose::Model::PutRecordBatchRequest::GetRecords,
|
|
ElementsAre(MatchesEntry("foo")))))
|
|
.WillOnce(Return(outcome));
|
|
EXPECT_EQ(Status(0), forwarder.send(logs, "results"));
|
|
|
|
logs = {"bar", "foo"};
|
|
Aws::Firehose::Model::PutRecordBatchResponseEntry entry;
|
|
outcome.GetResult().AddRequestResponses(entry);
|
|
entry.SetErrorCode("foo");
|
|
entry.SetErrorMessage("Foo error");
|
|
outcome.GetResult().SetFailedPutCount(1);
|
|
outcome.GetResult().AddRequestResponses(entry);
|
|
|
|
EXPECT_CALL(*client,
|
|
PutRecordBatch(Property(
|
|
&Aws::Firehose::Model::PutRecordBatchRequest::GetRecords,
|
|
ElementsAre(MatchesEntry("bar"), MatchesEntry("foo")))))
|
|
.WillOnce(Return(outcome));
|
|
EXPECT_EQ(Status(1, "Foo error"), forwarder.send(logs, "results"));
|
|
}
|
|
}
|