mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-30 03:34:26 +03:00
Jun 16th update
This commit is contained in:
@@ -33,14 +33,12 @@
|
||||
#include "config.h"
|
||||
#include "url_parser.h"
|
||||
#include "debug.h"
|
||||
#include "sasal.h"
|
||||
#include "scope_exit.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_HTTP_REQUEST);
|
||||
|
||||
using namespace std;
|
||||
|
||||
SASAL_START // Orchestration - Communication
|
||||
// LCOV_EXCL_START Reason: Depends on real download server.
|
||||
|
||||
class CurlGlobalInit
|
||||
@@ -434,5 +432,3 @@ TraceIdGenerator::generateTraceId()
|
||||
string part5 = generateRandomString(12);
|
||||
return string(part1 + "-" + part2 + "-" + part3 + "-" + part4 + "-" + part5);
|
||||
}
|
||||
|
||||
SASAL_END
|
||||
|
@@ -28,11 +28,9 @@
|
||||
#include "i_encryptor.h"
|
||||
#include "scope_exit.h"
|
||||
#include "url_parser.h"
|
||||
#include "sasal.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_HTTP_REQUEST);
|
||||
|
||||
SASAL_START // Orchestration - Communication
|
||||
// LCOV_EXCL_START Reason: Depends on real download server.
|
||||
|
||||
enum class HTTP_VERSION
|
||||
@@ -111,5 +109,3 @@ public:
|
||||
private:
|
||||
std::string ca_path;
|
||||
};
|
||||
|
||||
SASAL_END
|
||||
|
@@ -19,7 +19,6 @@
|
||||
#include "debug.h"
|
||||
#include "config.h"
|
||||
#include "rest.h"
|
||||
#include "sasal.h"
|
||||
#include "cereal/external/rapidjson/document.h"
|
||||
|
||||
#include <fstream>
|
||||
@@ -27,8 +26,6 @@
|
||||
using namespace std;
|
||||
using namespace rapidjson;
|
||||
|
||||
SASAL_START // Orchestration - Communication
|
||||
|
||||
USE_DEBUG_FLAG(D_ORCHESTRATOR);
|
||||
|
||||
class Downloader::Impl : Singleton::Provide<I_Downloader>::From<Downloader>
|
||||
@@ -42,7 +39,7 @@ public:
|
||||
const GetResourceFile &resourse_file
|
||||
) const override;
|
||||
|
||||
Maybe<map<string, string>> downloadVirtualFileFromFog(
|
||||
Maybe<map<pair<string, string>, string>> downloadVirtualFileFromFog(
|
||||
const GetResourceFile &resourse_file,
|
||||
Package::ChecksumTypes checksum_type
|
||||
) const override;
|
||||
@@ -114,18 +111,19 @@ Downloader::Impl::downloadFileFromFog(
|
||||
return file_path;
|
||||
}
|
||||
|
||||
Maybe<map<string, string>>
|
||||
Maybe<map<pair<string, string>, string>>
|
||||
Downloader::Impl::downloadVirtualFileFromFog(
|
||||
const GetResourceFile &resourse_file,
|
||||
Package::ChecksumTypes) const
|
||||
{
|
||||
static const string tenand_id_key = "tenantId";
|
||||
static const string policy_key = "policy";
|
||||
static const string settings_key = "settings";
|
||||
static const string tenants_key = "tenants";
|
||||
static const string error_text = "error";
|
||||
static const string tenand_id_key = "tenantId";
|
||||
static const string profile_id_key = "profileId";
|
||||
static const string policy_key = "policy";
|
||||
static const string settings_key = "settings";
|
||||
static const string tenants_key = "tenants";
|
||||
static const string error_text = "error";
|
||||
|
||||
map<string, string> res;
|
||||
map<pair<string, string>, string> res;
|
||||
I_UpdateCommunication *update_communication = Singleton::Consume<I_UpdateCommunication>::by<Downloader>();
|
||||
auto downloaded_data = update_communication->downloadAttributeFile(resourse_file);
|
||||
if (!downloaded_data.ok()) return downloaded_data.passErr();
|
||||
@@ -146,7 +144,14 @@ Downloader::Impl::downloadVirtualFileFromFog(
|
||||
if (artifact_data == itr->MemberEnd()) artifact_data = itr->FindMember(settings_key.c_str());
|
||||
|
||||
if (artifact_data != itr->MemberEnd()) {
|
||||
string file_path = dir_path + "/" + resourse_file.getFileName() + "_" + tenant_id + ".download";
|
||||
auto profile_id_obj = itr->FindMember(profile_id_key.c_str());
|
||||
if (profile_id_obj == itr->MemberEnd()) continue;
|
||||
|
||||
string profile_id = profile_id_obj->value.GetString();
|
||||
|
||||
string file_path =
|
||||
dir_path + "/" + resourse_file.getFileName() + "_" +
|
||||
tenant_id + "_profile_" + profile_id + ".download";
|
||||
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
@@ -154,7 +159,7 @@ Downloader::Impl::downloadVirtualFileFromFog(
|
||||
|
||||
I_OrchestrationTools *orchestration_tools = Singleton::Consume<I_OrchestrationTools>::by<Downloader>();
|
||||
if (orchestration_tools->writeFile(buffer.GetString(), file_path)) {
|
||||
res.insert({tenant_id, file_path});
|
||||
res.insert({{tenant_id, profile_id}, file_path});
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -383,5 +388,3 @@ Downloader::preload()
|
||||
registerExpectedConfiguration<string>("orchestration", "Self signed certificates acceptable");
|
||||
registerExpectedConfiguration<bool>("orchestration", "Add tenant suffix");
|
||||
}
|
||||
|
||||
SASAL_END
|
||||
|
@@ -295,8 +295,8 @@ TEST_F(DownloaderTest, download_virtual_policy)
|
||||
{
|
||||
GetResourceFile resourse_file(GetResourceFile::ResourceFileType::VIRTUAL_POLICY);
|
||||
|
||||
resourse_file.addTenant("0000", "1", "checksum0000");
|
||||
resourse_file.addTenant("1111", "2", "checksum1111");
|
||||
resourse_file.addTenant("0000", "1234", "1", "checksum0000");
|
||||
resourse_file.addTenant("1111", "1235", "2", "checksum1111");
|
||||
|
||||
string tenant_0000_file =
|
||||
"{"
|
||||
@@ -319,6 +319,7 @@ TEST_F(DownloaderTest, download_virtual_policy)
|
||||
" \"tenants\": [\n"
|
||||
" {\n"
|
||||
" \"tenantId\": \"0000\",\n"
|
||||
" \"profileId\": \"1234\",\n"
|
||||
" \"policy\": {\n"
|
||||
" \"waap\": \"108-005\",\n"
|
||||
" \"accessControl\": \"Internal error, check logs\",\n"
|
||||
@@ -328,6 +329,7 @@ TEST_F(DownloaderTest, download_virtual_policy)
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"tenantId\": \"1111\",\n"
|
||||
" \"profileId\": \"1235\",\n"
|
||||
" \"policy\": {\n"
|
||||
" \"messageId\": \"108-005\",\n"
|
||||
" \"message\": \"Internal error, check logs\",\n"
|
||||
@@ -340,16 +342,16 @@ TEST_F(DownloaderTest, download_virtual_policy)
|
||||
|
||||
EXPECT_CALL(mock_communication, downloadAttributeFile(resourse_file)).WillOnce(Return(fog_response));
|
||||
|
||||
EXPECT_CALL(mock_orchestration_tools, writeFile(tenant_0000_file, "/tmp/virtualPolicy_0000.download"))
|
||||
EXPECT_CALL(mock_orchestration_tools, writeFile(tenant_0000_file, "/tmp/virtualPolicy_0000_profile_1234.download"))
|
||||
.WillOnce(Return(true));
|
||||
|
||||
EXPECT_CALL(mock_orchestration_tools, writeFile(tenant_1111_file, "/tmp/virtualPolicy_1111.download"))
|
||||
EXPECT_CALL(mock_orchestration_tools, writeFile(tenant_1111_file, "/tmp/virtualPolicy_1111_profile_1235.download"))
|
||||
.WillOnce(Return(true));
|
||||
|
||||
map<string, string> expected_downloaded_files =
|
||||
map<pair<string, string>, string> expected_downloaded_files =
|
||||
{
|
||||
{ "0000", "/tmp/virtualPolicy_0000.download" },
|
||||
{ "1111", "/tmp/virtualPolicy_1111.download" }
|
||||
{ {"0000", "1234" }, "/tmp/virtualPolicy_0000_profile_1234.download" },
|
||||
{ {"1111", "1235" }, "/tmp/virtualPolicy_1111_profile_1235.download" }
|
||||
};
|
||||
|
||||
EXPECT_EQ(
|
||||
@@ -365,7 +367,12 @@ TEST_F(DownloaderTest, download_virtual_settings)
|
||||
{
|
||||
GetResourceFile resourse_file(GetResourceFile::ResourceFileType::VIRTUAL_SETTINGS);
|
||||
|
||||
resourse_file.addTenant("4c721b40-85df-4364-be3d-303a10ee9789", "1", "checksum0000");
|
||||
resourse_file.addTenant(
|
||||
"4c721b40-85df-4364-be3d-303a10ee9789",
|
||||
"4c721b40-85df-4364-be3d-303a10ee9780",
|
||||
"1",
|
||||
"checksum0000"
|
||||
);
|
||||
|
||||
string tenant_0000_file =
|
||||
"{"
|
||||
@@ -389,6 +396,7 @@ TEST_F(DownloaderTest, download_virtual_settings)
|
||||
" \"tenants\": [\n"
|
||||
" {\n"
|
||||
" \"tenantId\": \"4c721b40-85df-4364-be3d-303a10ee9789\",\n"
|
||||
" \"profileId\": \"4c721b40-85df-4364-be3d-303a10ee9780\",\n"
|
||||
" \"settings\": {\n"
|
||||
" \"agentSettings\": [\n"
|
||||
" {\n"
|
||||
@@ -410,14 +418,24 @@ TEST_F(DownloaderTest, download_virtual_settings)
|
||||
|
||||
EXPECT_CALL(mock_communication, downloadAttributeFile(resourse_file)).WillOnce(Return(fog_response));
|
||||
|
||||
stringstream tenant_0000_path;
|
||||
tenant_0000_path << "/tmp/virtualSettings_4c721b40-85df-4364-be3d-303a10ee9789"
|
||||
"_profile_4c721b40-85df-4364-be3d-303a10ee9780.download";
|
||||
EXPECT_CALL(
|
||||
mock_orchestration_tools,
|
||||
writeFile(tenant_0000_file, "/tmp/virtualSettings_4c721b40-85df-4364-be3d-303a10ee9789.download")
|
||||
writeFile(
|
||||
tenant_0000_file,
|
||||
tenant_0000_path.str()
|
||||
)
|
||||
).WillOnce(Return(true));
|
||||
|
||||
map<string, string> expected_downloaded_files = {
|
||||
{ "4c721b40-85df-4364-be3d-303a10ee9789",
|
||||
"/tmp/virtualSettings_4c721b40-85df-4364-be3d-303a10ee9789.download"
|
||||
stringstream file_path;
|
||||
file_path << "/tmp/virtualSettings_4c721b40-85df-4364-be3d-303a10ee9789"
|
||||
"_profile_4c721b40-85df-4364-be3d-303a10ee9780.download";
|
||||
|
||||
map<pair<string, string>, string> expected_downloaded_files = {
|
||||
{ {"4c721b40-85df-4364-be3d-303a10ee9789", "4c721b40-85df-4364-be3d-303a10ee9780"},
|
||||
file_path.str()
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -18,7 +18,6 @@
|
||||
#include "debug.h"
|
||||
#include "i_encryptor.h"
|
||||
#include "url_parser.h"
|
||||
#include "sasal.h"
|
||||
#include "config.h"
|
||||
#include "i_environment.h"
|
||||
#include "orchestration_comp.h"
|
||||
@@ -32,8 +31,6 @@
|
||||
using boost::asio::ip::tcp;
|
||||
using namespace std;
|
||||
|
||||
SASAL_START // Orchestration - Communication
|
||||
|
||||
USE_DEBUG_FLAG(D_ORCHESTRATOR);
|
||||
USE_DEBUG_FLAG(D_HTTP_REQUEST);
|
||||
|
||||
@@ -272,5 +269,3 @@ HTTPClient::getFileHttp(const URLParser &url, ofstream &out_file, const string &
|
||||
return Maybe<void>();
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
SASAL_END
|
||||
|
@@ -19,7 +19,6 @@
|
||||
#include "i_encryptor.h"
|
||||
#include "downloader.h"
|
||||
#include "config.h"
|
||||
#include "sasal.h"
|
||||
#include "boost/uuid/uuid.hpp"
|
||||
#include "boost/uuid/uuid_generators.hpp"
|
||||
#include <boost/asio/deadline_timer.hpp>
|
||||
@@ -39,8 +38,6 @@ using namespace boost::placeholders;
|
||||
using boost::asio::ip::tcp;
|
||||
using namespace std;
|
||||
|
||||
SASAL_START // Orchestration - Communication
|
||||
|
||||
USE_DEBUG_FLAG(D_COMMUNICATION);
|
||||
USE_DEBUG_FLAG(D_HTTP_REQUEST);
|
||||
USE_DEBUG_FLAG(D_ORCHESTRATOR);
|
||||
@@ -615,5 +612,3 @@ HTTPClient::curlGetFileOverSSL(const URLParser &url, ofstream &out_file, const s
|
||||
}
|
||||
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
SASAL_END
|
||||
|
Reference in New Issue
Block a user