mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Mar 21st 2024 update
This commit is contained in:
@@ -136,10 +136,13 @@ MessagingComp::sendAsyncMessage(
|
||||
const string &uri,
|
||||
const string &body,
|
||||
MessageCategory category,
|
||||
const MessageMetadata &message_metadata
|
||||
const MessageMetadata &message_metadata,
|
||||
bool force_buffering
|
||||
)
|
||||
{
|
||||
i_messaging_buffer->pushNewBufferedMessage(body, method, uri, category, message_metadata, false);
|
||||
MessageMetadata new_message_metadata = message_metadata;
|
||||
new_message_metadata.setShouldBufferMessage(force_buffering);
|
||||
i_messaging_buffer->pushNewBufferedMessage(body, method, uri, category, new_message_metadata, false);
|
||||
}
|
||||
|
||||
Maybe<HTTPStatusCode, HTTPResponse>
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include "mocks/mock_messaging_connection.h"
|
||||
#include "rest.h"
|
||||
#include "rest_server.h"
|
||||
#include "dummy_socket.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace testing;
|
||||
@@ -48,11 +49,13 @@ class TestMessagingComp : public testing::Test
|
||||
public:
|
||||
TestMessagingComp()
|
||||
{
|
||||
Debug::setUnitTestFlag(D_MESSAGING, Debug::DebugLevel::TRACE);
|
||||
EXPECT_CALL(mock_time_get, getMonotonicTime()).WillRepeatedly(Return(chrono::microseconds(0)));
|
||||
|
||||
ON_CALL(mock_agent_details, getFogDomain()).WillByDefault(Return(Maybe<string>(fog_addr)));
|
||||
ON_CALL(mock_agent_details, getFogPort()).WillByDefault(Return(Maybe<uint16_t>(fog_port)));
|
||||
messaging_comp.init();
|
||||
dummy_socket.init();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -70,8 +73,8 @@ public:
|
||||
EXPECT_CALL(mock_proxy_conf, getProxyAuthentication(_)).WillRepeatedly(Return(string("cred")));
|
||||
}
|
||||
|
||||
const string fog_addr = "1.2.3.4";
|
||||
uint16_t fog_port = 80;
|
||||
const string fog_addr = "127.0.0.1";
|
||||
int fog_port = 8080;
|
||||
CPTestTempfile agent_details_file;
|
||||
MessagingComp messaging_comp;
|
||||
::Environment env;
|
||||
@@ -82,6 +85,7 @@ public:
|
||||
NiceMock<MockTimeGet> mock_time_get;
|
||||
NiceMock<MockAgentDetails> mock_agent_details;
|
||||
NiceMock<MockProxyConfiguration> mock_proxy_conf;
|
||||
DummySocket dummy_socket;
|
||||
};
|
||||
|
||||
TEST_F(TestMessagingComp, testInitComp)
|
||||
@@ -100,16 +104,19 @@ TEST_F(TestMessagingComp, testSendSyncMessage)
|
||||
HTTPMethod method = HTTPMethod::POST;
|
||||
string uri = "/test-uri";
|
||||
MessageCategory category = MessageCategory::GENERIC;
|
||||
MessageMetadata message_metadata;
|
||||
|
||||
MessageConnectionKey conn_key(fog_addr, fog_port, MessageCategory::GENERIC);
|
||||
Connection conn(conn_key, message_metadata);
|
||||
Flags<MessageConnectionConfig> conn_flags;
|
||||
conn_flags.setFlag(MessageConnectionConfig::UNSECURE_CONN);
|
||||
MessageMetadata conn_metadata(fog_addr, fog_port, conn_flags, false, true);
|
||||
Connection conn(conn_key, conn_metadata);
|
||||
|
||||
EXPECT_CALL(mock_messaging_connection, getFogConnectionByCategory(MessageCategory::GENERIC))
|
||||
.WillOnce(Return(conn));
|
||||
|
||||
HTTPResponse res(HTTPStatusCode::HTTP_OK, "response!!");
|
||||
EXPECT_CALL(mock_messaging_connection, mockSendRequest(_, _, _)).WillOnce(Return(res));
|
||||
auto sending_res = messaging_comp.sendSyncMessage(method, uri, body, category, message_metadata);
|
||||
auto sending_res = messaging_comp.sendSyncMessage(method, uri, body, category, conn_metadata);
|
||||
ASSERT_TRUE(sending_res.ok());
|
||||
HTTPResponse http_res = sending_res.unpack();
|
||||
EXPECT_EQ(http_res.getBody(), "response!!");
|
||||
@@ -126,7 +133,7 @@ TEST_F(TestMessagingComp, testSendAsyncMessage)
|
||||
MessageMetadata message_metadata;
|
||||
|
||||
EXPECT_CALL(mock_messaging_buffer, pushNewBufferedMessage(body, method, uri, category, _, _)).Times(1);
|
||||
messaging_comp.sendAsyncMessage(method, uri, body, category, message_metadata);
|
||||
messaging_comp.sendAsyncMessage(method, uri, body, category, message_metadata, true);
|
||||
}
|
||||
|
||||
TEST_F(TestMessagingComp, testSendSyncMessageOnSuspendedConn)
|
||||
@@ -163,16 +170,18 @@ TEST_F(TestMessagingComp, testUploadFile)
|
||||
setAgentDetails();
|
||||
string uri = "/test-uri";
|
||||
MessageCategory category = MessageCategory::GENERIC;
|
||||
MessageMetadata message_metadata;
|
||||
|
||||
MessageConnectionKey conn_key(fog_addr, fog_port, MessageCategory::GENERIC);
|
||||
Connection conn(conn_key, message_metadata);
|
||||
Flags<MessageConnectionConfig> conn_flags;
|
||||
conn_flags.setFlag(MessageConnectionConfig::UNSECURE_CONN);
|
||||
MessageMetadata conn_metadata(fog_addr, fog_port, conn_flags, false, true);
|
||||
Connection conn(conn_key, conn_metadata);
|
||||
EXPECT_CALL(mock_messaging_connection, getFogConnectionByCategory(MessageCategory::GENERIC))
|
||||
.WillOnce(Return(conn));
|
||||
|
||||
HTTPResponse res(HTTPStatusCode::HTTP_OK, "");
|
||||
EXPECT_CALL(mock_messaging_connection, mockSendRequest(_, _, _)).WillOnce(Return(res));
|
||||
auto upload_res = messaging_comp.uploadFile(uri, path, category, message_metadata);
|
||||
auto upload_res = messaging_comp.uploadFile(uri, path, category, conn_metadata);
|
||||
ASSERT_TRUE(upload_res.ok());
|
||||
EXPECT_EQ(upload_res.unpack(), HTTPStatusCode::HTTP_OK);
|
||||
}
|
||||
@@ -185,16 +194,18 @@ TEST_F(TestMessagingComp, testDownloadFile)
|
||||
string uri = "/test-uri";
|
||||
HTTPMethod method = HTTPMethod::GET;
|
||||
MessageCategory category = MessageCategory::GENERIC;
|
||||
MessageMetadata message_metadata;
|
||||
|
||||
MessageConnectionKey conn_key(fog_addr, fog_port, MessageCategory::GENERIC);
|
||||
Connection conn(conn_key, message_metadata);
|
||||
Flags<MessageConnectionConfig> conn_flags;
|
||||
conn_flags.setFlag(MessageConnectionConfig::UNSECURE_CONN);
|
||||
MessageMetadata conn_metadata(fog_addr, fog_port, conn_flags, false, true);
|
||||
Connection conn(conn_key, conn_metadata);
|
||||
EXPECT_CALL(mock_messaging_connection, getFogConnectionByCategory(MessageCategory::GENERIC))
|
||||
.WillOnce(Return(conn));
|
||||
|
||||
HTTPResponse res(HTTPStatusCode::HTTP_OK, "");
|
||||
EXPECT_CALL(mock_messaging_connection, mockSendRequest(_, _, _)).WillOnce(Return(res));
|
||||
auto upload_res = messaging_comp.downloadFile(method, uri, "/tmp/test.txt", category, message_metadata);
|
||||
auto upload_res = messaging_comp.downloadFile(method, uri, "/tmp/test.txt", category, conn_metadata);
|
||||
ASSERT_TRUE(upload_res.ok());
|
||||
EXPECT_EQ(upload_res.unpack(), HTTPStatusCode::HTTP_OK);
|
||||
}
|
||||
|
Reference in New Issue
Block a user