mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
April 21th 2024 update
This commit is contained in:
@@ -34,6 +34,10 @@ ValidBulkQueryResponse::serialize(cereal::JSONInputArchive &ar)
|
||||
void
|
||||
IntelligenceQueryBulkResponse::serialize(cereal::JSONInputArchive &ar)
|
||||
{
|
||||
ar(cereal::make_nvp("errors", errors));
|
||||
ar(cereal::make_nvp("queriesResponse", valid_responses));
|
||||
try {
|
||||
ar(cereal::make_nvp("errors", errors));
|
||||
} catch (const cereal::Exception &e) {
|
||||
ar.setNextName(nullptr);
|
||||
}
|
||||
}
|
||||
|
@@ -14,6 +14,8 @@
|
||||
#ifndef __INTELLIGENCE_REQUEST_H__
|
||||
#define __INTELLIGENCE_REQUEST_H__
|
||||
#include "intelligence_is_v2/query_request_v2.h"
|
||||
#include "messaging/messaging_enums.h"
|
||||
#include "messaging/messaging_metadata.h"
|
||||
|
||||
#include <vector>
|
||||
#include "maybe_res.h"
|
||||
@@ -23,9 +25,14 @@ namespace Intelligence {
|
||||
class IntelligenceRequest : ClientRest
|
||||
{
|
||||
public:
|
||||
IntelligenceRequest(const std::vector<QueryRequest> &queries, bool is_pretty, bool is_bulk)
|
||||
IntelligenceRequest(
|
||||
const std::vector<QueryRequest> &queries,
|
||||
bool is_pretty,
|
||||
bool is_bulk,
|
||||
const MessageMetadata &req_md
|
||||
)
|
||||
:
|
||||
queries(queries), is_pretty(is_pretty), is_bulk(is_bulk)
|
||||
queries(queries), is_pretty(is_pretty), is_bulk(is_bulk), req_md(req_md)
|
||||
{}
|
||||
|
||||
Maybe<void> checkAssetsLimit() const;
|
||||
@@ -38,12 +45,14 @@ public:
|
||||
|
||||
size_t getSize() const { return queries.size(); }
|
||||
bool isBulk() const { return is_bulk; }
|
||||
const MessageMetadata & getReqMD() const { return req_md; }
|
||||
|
||||
private:
|
||||
const std::vector<QueryRequest> &queries;
|
||||
bool is_pretty = true;
|
||||
bool is_bulk = false;
|
||||
Maybe<std::string> response_from_fog = genError("Uninitialized");
|
||||
const MessageMetadata &req_md;
|
||||
};
|
||||
|
||||
}
|
||||
|
@@ -202,11 +202,26 @@ public:
|
||||
|
||||
if (objectType.isActive()) {
|
||||
auto type = object_names.find(objectType.get());
|
||||
if (type != object_names.end()) invalidation.setObjectType(type->second);
|
||||
if (type != object_names.end()) {
|
||||
invalidation.setObjectType(type->second);
|
||||
}
|
||||
else {
|
||||
dbgWarning(D_INTELLIGENCE) << "Received invalid object type: " << objectType.get();
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceId.isActive()) invalidation.setSourceId(sourceId.get());
|
||||
|
||||
if (invalidationType.isActive()) {
|
||||
auto type = invalidation_type_names.find(invalidationType.get());
|
||||
if (type != invalidation_type_names.end()) {
|
||||
invalidation.setInvalidationType(type->second);
|
||||
}
|
||||
else {
|
||||
dbgWarning(D_INTELLIGENCE) << "Received invalid invalidation type: " << invalidationType.get();
|
||||
}
|
||||
}
|
||||
|
||||
string registration_id = "";
|
||||
if (invalidationRegistrationId.isActive()) registration_id = invalidationRegistrationId.get();
|
||||
|
||||
@@ -227,6 +242,7 @@ private:
|
||||
C2S_OPTIONAL_PARAM(string, invalidationRegistrationId);
|
||||
C2S_OPTIONAL_PARAM(vector<StrAttributes>, mainAttributes);
|
||||
C2S_OPTIONAL_PARAM(vector<StrAttributes>, attributes);
|
||||
C2S_OPTIONAL_PARAM(string, invalidationType);
|
||||
};
|
||||
|
||||
class IntelligenceComponentV2::Impl
|
||||
@@ -280,9 +296,14 @@ public:
|
||||
}
|
||||
|
||||
Maybe<Response>
|
||||
getResponse(const vector<QueryRequest> &query_requests, bool is_pretty, bool is_bulk) const override
|
||||
getResponse(
|
||||
const vector<QueryRequest> &query_requests,
|
||||
bool is_pretty,
|
||||
bool is_bulk,
|
||||
const MessageMetadata &req_md
|
||||
) const override
|
||||
{
|
||||
IntelligenceRequest intelligence_req(query_requests, is_pretty, is_bulk);
|
||||
IntelligenceRequest intelligence_req(query_requests, is_pretty, is_bulk, req_md);
|
||||
if (!intelligence_req.checkAssetsLimit().ok()) return intelligence_req.checkAssetsLimit().passErr();
|
||||
if (!intelligence_req.checkMinConfidence().ok()) return intelligence_req.checkMinConfidence().passErr();
|
||||
if (intelligence_req.isPagingActivated()) {
|
||||
@@ -297,10 +318,10 @@ public:
|
||||
}
|
||||
|
||||
Maybe<Intelligence::Response>
|
||||
getResponse(const QueryRequest &query_request, bool is_pretty) const override
|
||||
getResponse(const QueryRequest &query_request, bool is_pretty, const MessageMetadata &req_md) const override
|
||||
{
|
||||
vector<QueryRequest> queries = {query_request};
|
||||
return getResponse(queries, is_pretty, false);
|
||||
return getResponse(queries, is_pretty, false, req_md);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -312,6 +333,11 @@ private:
|
||||
if (!is_supported) {
|
||||
is_supported = getProfileAgentSettingWithDefault<bool>(false, "agent.config.supportInvalidation");
|
||||
}
|
||||
|
||||
if (!is_supported) {
|
||||
is_supported = getConfigurationWithDefault(false, "intelligence", "support Invalidation");
|
||||
}
|
||||
|
||||
return is_supported;
|
||||
}
|
||||
|
||||
@@ -390,7 +416,8 @@ private:
|
||||
auto tenant = details->getTenantId();
|
||||
if (tenant == "") tenant = "Global";
|
||||
headers["X-Tenant-Id"] = tenant;
|
||||
auto agent = details->getAgentId();
|
||||
auto rest = Singleton::Consume<I_RestApi>::by<IntelligenceComponentV2>();
|
||||
auto agent = details->getAgentId() + ":" + to_string(rest->getListeningPort());
|
||||
headers["X-Source-Id"] = agent;
|
||||
|
||||
return headers;
|
||||
@@ -474,6 +501,7 @@ IntelligenceComponentV2::preload()
|
||||
{
|
||||
registerExpectedConfiguration<uint>("intelligence", "maximum request overall time");
|
||||
registerExpectedConfiguration<uint>("intelligence", "maximum request lap time");
|
||||
registerExpectedConfiguration<bool>("intelligence", "support Invalidation");
|
||||
registerExpectedSetting<string>("intelligence", "local intelligence server ip");
|
||||
registerExpectedSetting<uint>("intelligence", primary_port_setting);
|
||||
registerExpectedSetting<uint>("intelligence", secondary_port_setting);
|
||||
|
@@ -126,7 +126,7 @@ TEST_F(IntelligenceComponentMockTest, getResponseErrorTest)
|
||||
QueryRequest request(Condition::EQUALS, "category", "cloud", true);
|
||||
|
||||
Maybe<Intelligence::Response> res_error = genError("Test error");
|
||||
EXPECT_CALL(intelligence_mock, getResponse(_, _)
|
||||
EXPECT_CALL(intelligence_mock, getResponse(_, _, _)
|
||||
).WillOnce(Return(res_error));
|
||||
|
||||
auto maybe_ans = intell->queryIntelligence<Profile>(request);
|
||||
@@ -180,7 +180,7 @@ TEST_F(IntelligenceComponentMockTest, getResponseTest)
|
||||
|
||||
Intelligence::Response response(response_str, 1, false);
|
||||
|
||||
EXPECT_CALL(intelligence_mock, getResponse(_, _)
|
||||
EXPECT_CALL(intelligence_mock, getResponse(_, _, _)
|
||||
).WillOnce(Return(response));
|
||||
|
||||
auto maybe_ans = intell->queryIntelligence<Profile>(request);
|
||||
@@ -341,7 +341,7 @@ TEST_F(IntelligenceComponentMockTest, bulkOnlineIntelligenceMockTest)
|
||||
);
|
||||
Intelligence::Response response(response_str, 4, true);
|
||||
|
||||
EXPECT_CALL(intelligence_mock, getResponse(_, _, _)
|
||||
EXPECT_CALL(intelligence_mock, getResponse(_, _, _, _)
|
||||
).WillOnce(Return(response));
|
||||
|
||||
auto maybe_ans = intell->queryIntelligence<Profile>(requests);
|
||||
|
@@ -24,7 +24,7 @@ USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
TEST(IntelligenceQueryTestV2, genJsonPrettySingleRequest) {
|
||||
QueryRequest request(Condition::EQUALS, "phase", "testing", true);
|
||||
vector<QueryRequest> requests = {request};
|
||||
Intelligence::IntelligenceRequest query(requests, true, false);
|
||||
Intelligence::IntelligenceRequest query(requests, true, false, MessageMetadata("", 0));
|
||||
|
||||
std::string expected = "{\n"
|
||||
" \"limit\": 20,\n"
|
||||
@@ -42,7 +42,7 @@ TEST(IntelligenceQueryTestV2, genJsonPrettySingleRequest) {
|
||||
TEST(IntelligenceQueryTestV2, genJsonUnprettySingleRequest) {
|
||||
QueryRequest request(Condition::EQUALS, "phase", "testing", true);
|
||||
vector<QueryRequest> requests = {request};
|
||||
Intelligence::IntelligenceRequest query(requests, false, false);
|
||||
Intelligence::IntelligenceRequest query(requests, false, false, MessageMetadata("", 0));
|
||||
|
||||
std::string expected = "{"
|
||||
"\"limit\":20,"
|
||||
@@ -59,7 +59,7 @@ TEST(IntelligenceQueryTestV2, genJsonUnprettySingleRequest) {
|
||||
TEST(IntelligenceQueryTestV2, genJsonUnprettySingleRequestSpaces) {
|
||||
QueryRequest request(Condition::EQUALS, "ph ase", "te sti\" n g\\", true);
|
||||
vector<QueryRequest> requests = {request};
|
||||
Intelligence::IntelligenceRequest query(requests, false, false);
|
||||
Intelligence::IntelligenceRequest query(requests, false, false, MessageMetadata("", 0));
|
||||
std::string expected = "{"
|
||||
"\"limit\":20,"
|
||||
"\"fullResponse\":true,"
|
||||
@@ -76,7 +76,7 @@ TEST(IntelligenceQueryTestV2, genJsonPrettyBulkRequests) {
|
||||
QueryRequest request1(Condition::EQUALS, "phase", "testing", true);
|
||||
QueryRequest request2(Condition::EQUALS, "height", "testing", 25);
|
||||
std::vector<QueryRequest> requests = {request1, request2};
|
||||
Intelligence::IntelligenceRequest query(requests, true, true);
|
||||
Intelligence::IntelligenceRequest query(requests, true, true, MessageMetadata("", 0));
|
||||
|
||||
std::string expected = "{\n"
|
||||
" \"queries\": [\n"
|
||||
@@ -114,7 +114,7 @@ TEST(IntelligenceQueryTestV2, genJsonUnprettyBulkRequest) {
|
||||
QueryRequest request1(Condition::EQUALS, "phase", "testing", true);
|
||||
QueryRequest request2(Condition::EQUALS, "height", "testing", 25);
|
||||
std::vector<QueryRequest> requests = {request1, request2};
|
||||
Intelligence::IntelligenceRequest query(requests, false, true);
|
||||
Intelligence::IntelligenceRequest query(requests, false, true, MessageMetadata("", 0));
|
||||
|
||||
std::string expected = "{"
|
||||
"\"queries\":[{"
|
||||
|
@@ -117,12 +117,12 @@ TEST(InvalidationBasic, SettersAndGetters)
|
||||
EXPECT_EQ(invalidation.getClassifier(ClassifierType::GROUP), "");
|
||||
EXPECT_EQ(invalidation.getClassifier(ClassifierType::ORDER), "");
|
||||
EXPECT_EQ(invalidation.getClassifier(ClassifierType::KIND), "");
|
||||
EXPECT_EQ(invalidation.getInvalidationType(), InvalidationType::ADD);
|
||||
|
||||
EXPECT_TRUE(invalidation.getMainAttributes().empty());
|
||||
EXPECT_TRUE(invalidation.getAttributes().empty());
|
||||
EXPECT_FALSE(invalidation.getSourceId().ok());
|
||||
EXPECT_FALSE(invalidation.getObjectType().ok());
|
||||
EXPECT_FALSE(invalidation.getInvalidationType().ok());
|
||||
|
||||
set<string> main_vals = { "2", "3" };
|
||||
set<string> vals = { "5", "6" };
|
||||
@@ -152,7 +152,7 @@ TEST(InvalidationBasic, SettersAndGetters)
|
||||
EXPECT_EQ(invalidation.getAttributes().begin()->getStringSetAttr("attr2").unpack(), vals);
|
||||
EXPECT_EQ(invalidation.getSourceId().unpack(), "id");
|
||||
EXPECT_EQ(invalidation.getObjectType().unpack(), Intelligence::ObjectType::ASSET);
|
||||
EXPECT_EQ(invalidation.getInvalidationType(), InvalidationType::DELETE);
|
||||
EXPECT_EQ(invalidation.getInvalidationType().unpack(), InvalidationType::DELETE);
|
||||
}
|
||||
|
||||
TEST(InvalidationBasic, Matching)
|
||||
@@ -348,7 +348,6 @@ TEST_F(IntelligenceInvalidation, sending_public_invalidation)
|
||||
"\"category\": \"bbb\", "
|
||||
"\"family\": \"ccc\", "
|
||||
"\"objectType\": \"asset\", "
|
||||
"\"invalidationType\": \"add\", "
|
||||
"\"sourceId\": \"id\", "
|
||||
"\"mainAttributes\": [ { \"attr2\": \"2\" } ], "
|
||||
"\"attributes\": [ { \"attr3\": \"3\" } ]"
|
||||
@@ -389,7 +388,6 @@ TEST_F(IntelligenceInvalidation, multiple_assets_invalidation)
|
||||
"\"category\": \"bbb\", "
|
||||
"\"family\": \"ccc\", "
|
||||
"\"objectType\": \"asset\", "
|
||||
"\"invalidationType\": \"add\", "
|
||||
"\"sourceId\": \"id\", "
|
||||
"\"mainAttributes\": [ { \"attr2\": \"2\" }, { \"attr2\": \"22\", \"attr3\": [ \"33\", \"44\" ] } ], "
|
||||
"\"attributes\": [ { \"attr3\": \"3\" } ]"
|
||||
@@ -439,7 +437,6 @@ TEST_F(IntelligenceInvalidation, sending_private_invalidation)
|
||||
"\"category\": \"bbb\", "
|
||||
"\"family\": \"ccc\", "
|
||||
"\"objectType\": \"asset\", "
|
||||
"\"invalidationType\": \"add\", "
|
||||
"\"sourceId\": \"id\", "
|
||||
"\"mainAttributes\": [ { \"attr2\": \"2\" } ], "
|
||||
"\"attributes\": [ { \"attr3\": \"3\" } ]"
|
||||
|
@@ -142,7 +142,14 @@ Sender::sendMessage()
|
||||
{
|
||||
if (server_port.ok() && !server_ip.ok()) return genError("Can't send intelligence request. Server ip invalid");
|
||||
if (server_ip.ok() && !server_port.ok()) return genError("Can't send intelligence request. Server port invalid");
|
||||
auto req_md = server_ip.ok() ? MessageMetadata(*server_ip, *server_port, conn_flags) : MessageMetadata();
|
||||
|
||||
MessageMetadata req_md;
|
||||
if (server_ip.ok()) {
|
||||
req_md = MessageMetadata(*server_ip, *server_port, conn_flags);
|
||||
}
|
||||
else {
|
||||
req_md = request.getReqMD().getHostName().empty() ? MessageMetadata() : request.getReqMD();
|
||||
}
|
||||
|
||||
if (server_ip.ok()) {
|
||||
dbgTrace(D_INTELLIGENCE)
|
||||
|
@@ -27,6 +27,7 @@ Invalidation::Invalidation(const string &class_value)
|
||||
:
|
||||
source_id(genError<void>()),
|
||||
object_type(genError<void>()),
|
||||
invalidation_type(genError<void>()),
|
||||
listening_id(genError<void>()),
|
||||
registration_id(genError<void>())
|
||||
{
|
||||
@@ -133,7 +134,9 @@ Invalidation::genObject() const
|
||||
}
|
||||
|
||||
if (object_type.ok()) invalidation <<", \"objectType\": \"" << convertObjectType.at(*object_type) << '"';
|
||||
invalidation << ", \"invalidationType\": \"" << convertInvalidationType.at(invalidation_type) << '"';
|
||||
if (invalidation_type.ok()) {
|
||||
invalidation << ", \"invalidationType\": \"" << convertInvalidationType.at(*invalidation_type) << '"';
|
||||
}
|
||||
if (source_id.ok()) invalidation <<", \"sourceId\": \"" << *source_id << '"';
|
||||
if (registration_id.ok()) invalidation <<", \"invalidationRegistrationId\": \"" << *registration_id << '"';
|
||||
|
||||
@@ -211,6 +214,10 @@ Invalidation::matches(const Invalidation &other) const
|
||||
if (!other.object_type.ok() || *object_type != *other.object_type) return false;
|
||||
}
|
||||
|
||||
if (invalidation_type.ok()) {
|
||||
if (!other.invalidation_type.ok() || *invalidation_type != *other.invalidation_type) return false;
|
||||
}
|
||||
|
||||
if (source_id.ok()) {
|
||||
if (!other.source_id.ok() || *source_id != *other.source_id) return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user