mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Apr 27th Update
This commit is contained in:
@@ -140,6 +140,9 @@ IntelligenceComponentV2::preload()
|
||||
registerExpectedConfiguration<bool>("intelligence", "offline intelligence only");
|
||||
registerExpectedConfiguration<uint>("intelligence", "maximum request overall time");
|
||||
registerExpectedConfiguration<uint>("intelligence", "maximum request lap time");
|
||||
registerExpectedSetting<string>("intelligence", "local intelligence server ip");
|
||||
registerExpectedSetting<uint>("intelligence", "local intelligence server secondary port");
|
||||
registerExpectedSetting<uint>("intelligence", "local intelligence server primary port");
|
||||
|
||||
registerExpectedConfigFile("agent-intelligence", Config::ConfigFileType::Policy);
|
||||
}
|
||||
|
@@ -5,6 +5,8 @@
|
||||
using namespace std;
|
||||
using namespace testing;
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
TEST(QueryRequestTestV2, QueryTest)
|
||||
{
|
||||
QueryRequest request(Condition::EQUALS, "phase", "testing", true);
|
||||
@@ -438,3 +440,104 @@ TEST(QueryRequestTestV2, OneLinerComplexQueryTest)
|
||||
"}";
|
||||
EXPECT_EQ(out.str(), output_json);
|
||||
}
|
||||
|
||||
TEST(QueryRequestTestV2, CrossTenantAssetDBTest)
|
||||
{
|
||||
QueryRequest request(Condition::EQUALS, "class", "risk", true);
|
||||
|
||||
request.setObjectType(ObjectType::CONFIGURATION);
|
||||
request.setCrossTenantAssetDB(true);
|
||||
|
||||
string output_json =
|
||||
"{\n"
|
||||
" \"limit\": 20,\n"
|
||||
" \"fullResponse\": true,\n"
|
||||
" \"query\": {\n"
|
||||
" \"operator\": \"equals\",\n"
|
||||
" \"key\": \"mainAttributes.class\",\n"
|
||||
" \"value\": \"risk\"\n"
|
||||
" },\n"
|
||||
" \"objectType\": \"configuration\",\n"
|
||||
" \"queryTypes\": {\n"
|
||||
" \"queryCrossTenantAssetDB\": true\n"
|
||||
" }\n"
|
||||
"}";
|
||||
|
||||
stringstream out;
|
||||
{
|
||||
cereal::JSONOutputArchive out_ar(out);
|
||||
request.saveToJson(out_ar);
|
||||
}
|
||||
EXPECT_EQ(out.str(), output_json);
|
||||
}
|
||||
|
||||
TEST(QueryRequestTestV2, IllegalObjectTypeTest)
|
||||
{
|
||||
QueryRequest request(Condition::EQUALS, "class", "risk", true);
|
||||
stringstream debug_output;
|
||||
Debug::setNewDefaultStdout(&debug_output);
|
||||
Debug::setUnitTestFlag(D_INTELLIGENCE, Debug::DebugLevel::TRACE);
|
||||
|
||||
request.setObjectType(static_cast<ObjectType>(static_cast<int>(ObjectType::COUNT) + 1));
|
||||
request.setCrossTenantAssetDB(true);
|
||||
|
||||
string output_json =
|
||||
"{\n"
|
||||
" \"limit\": 20,\n"
|
||||
" \"fullResponse\": true,\n"
|
||||
" \"query\": {\n"
|
||||
" \"operator\": \"equals\",\n"
|
||||
" \"key\": \"mainAttributes.class\",\n"
|
||||
" \"value\": \"risk\"\n"
|
||||
" },\n"
|
||||
" \"queryTypes\": {\n"
|
||||
" \"queryCrossTenantAssetDB\": true\n"
|
||||
" }\n"
|
||||
"}";
|
||||
|
||||
stringstream out;
|
||||
{
|
||||
cereal::JSONOutputArchive out_ar(out);
|
||||
request.saveToJson(out_ar);
|
||||
}
|
||||
EXPECT_EQ(out.str(), output_json);
|
||||
|
||||
string debug_str = "Illegal Object Type.";
|
||||
EXPECT_THAT(debug_output.str(), HasSubstr(debug_str));
|
||||
Debug::setNewDefaultStdout(&cout);
|
||||
}
|
||||
|
||||
TEST(QueryRequestTestV2, UninitializedObjectTypeTest)
|
||||
{
|
||||
QueryRequest request(Condition::EQUALS, "class", "risk", true);
|
||||
stringstream debug_output;
|
||||
Debug::setNewDefaultStdout(&debug_output);
|
||||
Debug::setUnitTestFlag(D_INTELLIGENCE, Debug::DebugLevel::TRACE);
|
||||
|
||||
request.setCrossTenantAssetDB(true);
|
||||
|
||||
string output_json =
|
||||
"{\n"
|
||||
" \"limit\": 20,\n"
|
||||
" \"fullResponse\": true,\n"
|
||||
" \"query\": {\n"
|
||||
" \"operator\": \"equals\",\n"
|
||||
" \"key\": \"mainAttributes.class\",\n"
|
||||
" \"value\": \"risk\"\n"
|
||||
" },\n"
|
||||
" \"queryTypes\": {\n"
|
||||
" \"queryCrossTenantAssetDB\": true\n"
|
||||
" }\n"
|
||||
"}";
|
||||
|
||||
stringstream out;
|
||||
{
|
||||
cereal::JSONOutputArchive out_ar(out);
|
||||
request.saveToJson(out_ar);
|
||||
}
|
||||
EXPECT_EQ(out.str(), output_json);
|
||||
|
||||
string debug_str = "uninitialized";
|
||||
EXPECT_THAT(debug_output.str(), HasSubstr(debug_str));
|
||||
Debug::setNewDefaultStdout(&cout);
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "intelligence_is_v2/query_request_v2.h"
|
||||
#include "debug.h"
|
||||
#include "enum_array.h"
|
||||
|
||||
const uint QueryRequest::default_min_confidence = 500;
|
||||
const uint QueryRequest::default_assets_limit = 20;
|
||||
@@ -22,6 +23,8 @@ using namespace Intelligence_IS_V2;
|
||||
|
||||
USE_DEBUG_FLAG(D_INTELLIGENCE);
|
||||
|
||||
static const EnumArray<ObjectType, string> object_type_to_string_array{ "asset", "zone", "configuration" };
|
||||
|
||||
BulkQueryRequest::BulkQueryRequest(QueryRequest &_request, int _index)
|
||||
:
|
||||
request(_request),
|
||||
@@ -55,6 +58,17 @@ QueryRequest::QueryRequest(
|
||||
full_response = full_reponse;
|
||||
}
|
||||
|
||||
Maybe<string>
|
||||
QueryRequest::convertObjectTypeToString() const
|
||||
{
|
||||
if (!object_type.ok()) return object_type.passErr();
|
||||
if (static_cast<uint>(*object_type) < static_cast<uint>(ObjectType::COUNT)) {
|
||||
return object_type_to_string_array[*object_type];
|
||||
}
|
||||
|
||||
return genError("Illegal Object Type.");
|
||||
}
|
||||
|
||||
void
|
||||
QueryRequest::saveToJson(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
@@ -64,6 +78,13 @@ QueryRequest::saveToJson(cereal::JSONOutputArchive &ar) const
|
||||
cereal::make_nvp("query", query)
|
||||
);
|
||||
|
||||
auto objTypeString = convertObjectTypeToString();
|
||||
if (objTypeString.ok()) {
|
||||
ar(cereal::make_nvp("objectType", *objTypeString));
|
||||
} else {
|
||||
dbgTrace(D_INTELLIGENCE) << objTypeString.getErr();
|
||||
}
|
||||
|
||||
if (cursor.ok()) ar(cereal::make_nvp("cursor", cursor.unpack().second));
|
||||
requested_attributes.save(ar);
|
||||
query_types.save(ar);
|
||||
@@ -78,6 +99,13 @@ QueryRequest::save(cereal::JSONOutputArchive &ar) const
|
||||
cereal::make_nvp("query", query)
|
||||
);
|
||||
|
||||
auto objTypeString = convertObjectTypeToString();
|
||||
if (objTypeString.ok()) {
|
||||
ar(cereal::make_nvp("objectType", *objTypeString));
|
||||
} else {
|
||||
dbgTrace(D_INTELLIGENCE) << objTypeString.getErr();
|
||||
}
|
||||
|
||||
if (cursor.ok()) ar(cereal::make_nvp("cursor", cursor.unpack().second));
|
||||
requested_attributes.save(ar);
|
||||
query_types.save(ar);
|
||||
@@ -129,6 +157,12 @@ QueryRequest::setTenantsList(const vector<string> tenants)
|
||||
query_types.setSerializableTenantList(tenants);
|
||||
}
|
||||
|
||||
void
|
||||
QueryRequest::setCrossTenantAssetDB(bool cross_tenant_asset_db)
|
||||
{
|
||||
query_types.setQueryCrossTenantAssetDB(cross_tenant_asset_db);
|
||||
}
|
||||
|
||||
void
|
||||
QueryRequest::setAssetsLimit(uint _assets_limit)
|
||||
{
|
||||
@@ -173,6 +207,12 @@ QueryRequest::setCursor(CursorState state, const string &value)
|
||||
cursor = RequestCursor(state, value);
|
||||
}
|
||||
|
||||
void
|
||||
QueryRequest::setObjectType(const ObjectType &obj_type)
|
||||
{
|
||||
object_type = obj_type;
|
||||
}
|
||||
|
||||
QueryRequest
|
||||
QueryRequest::calcQueryRequestOperator(const QueryRequest &other_query, const Operator &operator_type)
|
||||
{
|
||||
|
@@ -17,22 +17,37 @@ using namespace std;
|
||||
using namespace Intelligence_IS_V2;
|
||||
|
||||
void
|
||||
serializableTenantList::serialize(cereal::JSONOutputArchive &ar) const
|
||||
SerializableQueryTypes::serializeMultiTenant(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
ar(cereal::make_nvp("multiTenant", tenants));
|
||||
ar(cereal::make_nvp("multiTenant", *tenants));
|
||||
}
|
||||
|
||||
void
|
||||
SerializableQueryTypes::serializeCrossTenantAssetDB(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
ar(cereal::make_nvp("queryCrossTenantAssetDB", *query_cross_tenant_asset_db));
|
||||
}
|
||||
|
||||
void
|
||||
SerializableQueryTypes::save(cereal::JSONOutputArchive &ar) const
|
||||
{
|
||||
if (!is_nsaas) return;
|
||||
serializableTenantList serializable_tenants(tenants);
|
||||
ar(cereal::make_nvp("queryTypes", serializable_tenants));
|
||||
if (!tenants.ok() && !query_cross_tenant_asset_db.ok()) return;
|
||||
|
||||
ar.setNextName("queryTypes");
|
||||
ar.startNode();
|
||||
if (tenants.ok()) serializeMultiTenant(ar);
|
||||
if (query_cross_tenant_asset_db.ok()) serializeCrossTenantAssetDB(ar);
|
||||
ar.finishNode();
|
||||
}
|
||||
|
||||
void
|
||||
SerializableQueryTypes::setSerializableTenantList(const std::vector<std::string> _tenants)
|
||||
SerializableQueryTypes::setSerializableTenantList(const vector<string> &tenant_list)
|
||||
{
|
||||
tenants = _tenants;
|
||||
is_nsaas = true;
|
||||
tenants = tenant_list;
|
||||
};
|
||||
|
||||
void
|
||||
SerializableQueryTypes::setQueryCrossTenantAssetDB(bool cross_tenant_asset_db)
|
||||
{
|
||||
query_cross_tenant_asset_db = cross_tenant_asset_db;
|
||||
}
|
||||
|
Reference in New Issue
Block a user