mirror of
https://github.com/openappsec/attachment.git
synced 2025-06-28 16:41:03 +03:00
remove nano attachment ut
This commit is contained in:
parent
077d27f467
commit
45faebab27
@ -26,7 +26,5 @@ add_library(
|
|||||||
|
|
||||||
target_link_libraries(nano_attachment shmem_ipc_2 nano_attachment_util osrc_compression_utils)
|
target_link_libraries(nano_attachment shmem_ipc_2 nano_attachment_util osrc_compression_utils)
|
||||||
|
|
||||||
# add_subdirectory(nano_attachment_ut)
|
|
||||||
|
|
||||||
install(TARGETS nano_attachment DESTINATION lib)
|
install(TARGETS nano_attachment DESTINATION lib)
|
||||||
install(TARGETS nano_attachment DESTINATION nginx_attachment/lib PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ)
|
install(TARGETS nano_attachment DESTINATION nginx_attachment/lib PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ)
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
include_directories(${CMAKE_SOURCE_DIR}/attachments/nano_attachment)
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_attachment_ut
|
|
||||||
"nano_attachment_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
|
|
||||||
if( NOT "${PLATFORM_TYPE}" STREQUAL "alpine")
|
|
||||||
add_unit_test(
|
|
||||||
nano_attachment_io_ut
|
|
||||||
"nano_attachment_io_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_attachment_sender_ut
|
|
||||||
"nano_attachment_sender_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_thread_ut
|
|
||||||
"nano_thread_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_sender_thread_ut
|
|
||||||
"nano_sender_thread_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_configuration_ut
|
|
||||||
"nano_configuration_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_initializer_ut
|
|
||||||
"nano_initializer_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_attachment_metrics_ut
|
|
||||||
"nano_attachment_metrics_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
||||||
|
|
||||||
add_unit_test(
|
|
||||||
nano_compression_ut
|
|
||||||
"nano_compression_ut.cc"
|
|
||||||
"nano_attachment"
|
|
||||||
)
|
|
@ -1,990 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
|
|
||||||
#include "mock_nano_initializer.h"
|
|
||||||
#include "mock_shmem_ipc.h"
|
|
||||||
#include "mock_nano_socket.h"
|
|
||||||
#include "mock_nano_poll.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
#include "nano_attachment_io.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoAttachmentIoTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
nano_attachment_init_process(_)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
attachment = InitNanoAttachment(
|
|
||||||
static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID),
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
STDOUT_FILENO
|
|
||||||
);
|
|
||||||
EXPECT_NE(attachment, nullptr);
|
|
||||||
|
|
||||||
attachment->dbg_level = nano_http_cp_debug_level::DBG_LEVEL_TRACE;
|
|
||||||
|
|
||||||
session_data = InitSessionData(attachment, 501);
|
|
||||||
EXPECT_NE(session_data, nullptr);
|
|
||||||
|
|
||||||
ctx_data.session_data = session_data;
|
|
||||||
init_thread_ctx(&ctx, attachment, &ctx_data);
|
|
||||||
|
|
||||||
reply_from_service_mock = (HttpReplyFromService *)malloc(
|
|
||||||
sizeof(HttpReplyFromService) +
|
|
||||||
sizeof(HttpModifyData) +
|
|
||||||
sizeof(HttpInjectData) +
|
|
||||||
sizeof(HttpWebResponseData)
|
|
||||||
);
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_INSPECT);
|
|
||||||
reply_from_service_mock->session_id = session_data->session_id;
|
|
||||||
reply_from_service_mock->modification_count = 0;
|
|
||||||
|
|
||||||
modify_data_mock = reinterpret_cast<HttpModifyData *>(reply_from_service_mock->modify_data);
|
|
||||||
inject_data = reinterpret_cast<HttpInjectData *>(
|
|
||||||
reply_from_service_mock->modify_data + sizeof(HttpModifyData)
|
|
||||||
);
|
|
||||||
web_response_data = reinterpret_cast<HttpWebResponseData *>(
|
|
||||||
reply_from_service_mock->modify_data + sizeof(HttpModifyData)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TearDown() override
|
|
||||||
{
|
|
||||||
free(reply_from_service_mock);
|
|
||||||
FiniSessionData(attachment, session_data);
|
|
||||||
FiniNanoAttachment(attachment);
|
|
||||||
::testing::Mock::VerifyAndClearExpectations(&initializer_mocker);
|
|
||||||
::testing::Mock::VerifyAndClearExpectations(&mock_shmem_ipc);
|
|
||||||
::testing::Mock::VerifyAndClearExpectations(&mock_nano_socket);
|
|
||||||
::testing::Mock::VerifyAndClearExpectations(&mock_nano_poll);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano_str_t
|
|
||||||
create_nano_str(const char *str)
|
|
||||||
{
|
|
||||||
nano_str_t nano_str;
|
|
||||||
nano_str.data = reinterpret_cast<unsigned char *>(const_cast<char *>(str));
|
|
||||||
nano_str.len = strlen(str);
|
|
||||||
return nano_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
AttachmentVerdictResponse inspect_response = {
|
|
||||||
AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT,
|
|
||||||
1,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentVerdictResponse accept_response = {
|
|
||||||
AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT,
|
|
||||||
1,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentVerdictResponse custom_drop_response = {
|
|
||||||
AttachmentVerdict::ATTACHMENT_VERDICT_DROP,
|
|
||||||
1,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpMetaData http_meta_data = {
|
|
||||||
create_nano_str("HTTP/1.1"),
|
|
||||||
create_nano_str("GET"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com"),
|
|
||||||
create_nano_str("192.168.1.100"),
|
|
||||||
80,
|
|
||||||
create_nano_str("/dogs.html"),
|
|
||||||
create_nano_str("192.168.1.101"),
|
|
||||||
253,
|
|
||||||
create_nano_str("nanoattachmentut.com"),
|
|
||||||
create_nano_str("/dogs.html")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaderData http_headers[3] = {
|
|
||||||
{
|
|
||||||
create_nano_str("Host"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("User-Agent"),
|
|
||||||
create_nano_str("Mozilla/5.0")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("Accept"),
|
|
||||||
create_nano_str("text/html")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaders http_headers_data = {
|
|
||||||
http_headers,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
nano_str_t body[3] = {
|
|
||||||
create_nano_str("Hello"),
|
|
||||||
create_nano_str("World"),
|
|
||||||
create_nano_str("!")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpBody http_body_data = {
|
|
||||||
body,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData ctx_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_METADATA,
|
|
||||||
session_data,
|
|
||||||
nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpReplyFromService *reply_from_service_mock;
|
|
||||||
HttpModifyData *modify_data_mock;
|
|
||||||
HttpInjectData *inject_data;
|
|
||||||
HttpWebResponseData *web_response_data;
|
|
||||||
uint32_t reply_session_id = -1;
|
|
||||||
void *reply_session_id_void = &reply_session_id;
|
|
||||||
struct pollfd fds;
|
|
||||||
struct pollfd *mock_fds = &fds;
|
|
||||||
const char **replay_data_mock;
|
|
||||||
|
|
||||||
NanoAttachment *attachment;
|
|
||||||
HttpSessionData *session_data;
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
StrictMock<NanoInitializerMocker> initializer_mocker;
|
|
||||||
StrictMock<NanoShmemIPCMocker> mock_shmem_ipc;
|
|
||||||
StrictMock<NanoSocketMocker> mock_nano_socket;
|
|
||||||
StrictMock<NanoPollMocker> mock_nano_poll;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, ConnectToCommSocket)
|
|
||||||
{
|
|
||||||
NanoCommunicationResult res;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
socket(AF_UNIX, SOCK_STREAM, 0)
|
|
||||||
).WillOnce(Return(53));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
connect(53, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
res = connect_to_comm_socket(attachment);
|
|
||||||
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
EXPECT_EQ(attachment->comm_socket, 53);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, ConnectToRegistrationSocket)
|
|
||||||
{
|
|
||||||
NanoCommunicationResult res;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
socket(AF_UNIX, SOCK_STREAM, 0)
|
|
||||||
).WillOnce(Return(39));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
connect(39, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
res = connect_to_registration_socket(attachment);
|
|
||||||
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
EXPECT_EQ(attachment->registration_socket, 39);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoMetadataSender)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = reinterpret_cast<const char *>(reply_from_service_mock);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
nano_metadata_sender(
|
|
||||||
attachment,
|
|
||||||
&http_meta_data,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoMetadataSenderFailOnce)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
nano_metadata_sender(
|
|
||||||
attachment,
|
|
||||||
&http_meta_data,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoHeadersSender)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = (const char *)reply_from_service_mock;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
nano_header_sender(
|
|
||||||
attachment,
|
|
||||||
&http_headers_data,
|
|
||||||
&ctx,
|
|
||||||
AttachmentDataType::REQUEST_HEADER,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoBodySender)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).Times(3)
|
|
||||||
.WillOnce(Return(0))
|
|
||||||
.WillOnce(Return(0))
|
|
||||||
.WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillRepeatedly(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).WillRepeatedly(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<0>(&mock_fds),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
mock_fds[0].revents = POLLIN;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillRepeatedly(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
close(_)
|
|
||||||
).WillRepeatedly(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
connect(_, _, _)
|
|
||||||
).WillRepeatedly(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
socket(_, _, _)
|
|
||||||
).WillRepeatedly(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
write_to_service(attachment, _, _, _, _)
|
|
||||||
).WillRepeatedly(Return(NanoCommunicationResult::NANO_OK));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillRepeatedly(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillRepeatedly(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = (const char *)reply_from_service_mock;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillRepeatedly(Return(1));
|
|
||||||
|
|
||||||
nano_body_sender(
|
|
||||||
attachment,
|
|
||||||
&http_body_data,
|
|
||||||
&ctx,
|
|
||||||
AttachmentDataType::REQUEST_BODY,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoSendResponseContentLength)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
nano_send_response_content_length(
|
|
||||||
attachment,
|
|
||||||
332,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 1u);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoSendResponseCode)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
nano_send_response_code(
|
|
||||||
attachment,
|
|
||||||
443,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 1u);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoEndTransactionSender)
|
|
||||||
{
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_ACCEPT);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = reinterpret_cast<const char *>(reply_from_service_mock);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::REQUEST_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
EXPECT_EQ(session_data->verdict, ServiceVerdict::TRAFFIC_VERDICT_ACCEPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoDelayedTransactionSender)
|
|
||||||
{
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_ACCEPT);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = reinterpret_cast<const char *>(reply_from_service_mock);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
nano_request_delayed_verdict(
|
|
||||||
attachment,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
EXPECT_EQ(session_data->verdict, ServiceVerdict::TRAFFIC_VERDICT_ACCEPT);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoDropResponseBadResponse)
|
|
||||||
{
|
|
||||||
web_response_data->web_response_type = static_cast<uint16_t>(NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_DROP);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = reinterpret_cast<const char *>(reply_from_service_mock);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::REQUEST_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
EXPECT_EQ(session_data->verdict, ServiceVerdict::TRAFFIC_VERDICT_DROP);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoDropCustomResponse)
|
|
||||||
{
|
|
||||||
web_response_data->web_response_type = static_cast<uint16_t>(NanoWebResponseType::CUSTOM_WEB_RESPONSE);
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_DROP);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = reinterpret_cast<const char *>(reply_from_service_mock);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::REQUEST_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
EXPECT_EQ(session_data->verdict, ServiceVerdict::TRAFFIC_VERDICT_DROP);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoDropRedirectResponse)
|
|
||||||
{
|
|
||||||
web_response_data->web_response_type = static_cast<uint16_t>(NanoWebResponseType::REDIRECT_WEB_RESPONSE);
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_DROP);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = reinterpret_cast<const char *>(reply_from_service_mock);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::REQUEST_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
EXPECT_EQ(session_data->verdict, ServiceVerdict::TRAFFIC_VERDICT_DROP);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoInjectResponse)
|
|
||||||
{
|
|
||||||
reply_from_service_mock->modification_count = 1;
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_INJECT);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_poll,
|
|
||||||
poll(_, _, _)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(1))
|
|
||||||
.WillOnce(Return(2));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillOnce(Return(sizeof(SessionID)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_nano_socket,
|
|
||||||
read(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<1>(&reply_session_id_void),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*reinterpret_cast<uint32_t *>(reply_session_id_void) = 501;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
isDataAvailable(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
receiveData(_, _, _)
|
|
||||||
).WillOnce(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<2>(&replay_data_mock),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
*replay_data_mock = reinterpret_cast<const char *>(reply_from_service_mock);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
popData(_)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::REQUEST_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
EXPECT_EQ(session_data->verdict, ServiceVerdict::TRAFFIC_VERDICT_INSPECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentIoTest, NanoSendMetricData)
|
|
||||||
{
|
|
||||||
reply_from_service_mock->verdict = static_cast<uint16_t>(ServiceVerdict::TRAFFIC_VERDICT_ACCEPT);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
mock_shmem_ipc,
|
|
||||||
sendChunkedData(_, _, _, _)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
nano_send_metric_data_sender(attachment);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
|
|
||||||
#include "mock_nano_initializer.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
#include "nano_attachment_metric.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoAttachmentMetricTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
nano_attachment_init_process(_)
|
|
||||||
).WillOnce(
|
|
||||||
Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
attachment = InitNanoAttachment(
|
|
||||||
static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID),
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
STDOUT_FILENO
|
|
||||||
);
|
|
||||||
EXPECT_NE(attachment, nullptr);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TearDown() override
|
|
||||||
{
|
|
||||||
FiniNanoAttachment(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
NanoAttachment *attachment;
|
|
||||||
StrictMock<NanoInitializerMocker> initializer_mocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentMetricTest, CheckMetricsFunctions)
|
|
||||||
{
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::INJECT_VERDICTS_COUNT, 100u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::DROP_VERDICTS_COUNT, 200u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::ACCEPT_VERDICTS_COUNT, 300u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::IRRELEVANT_VERDICTS_COUNT, 400u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::MAX_RES_PPROCESSING_TIME_UNTIL_VERDICT, 400u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::MAX_RES_PPROCESSING_TIME_UNTIL_VERDICT, 200u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::MIN_RES_PPROCESSING_TIME_UNTIL_VERDICT, 50u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::MIN_RES_PPROCESSING_TIME_UNTIL_VERDICT, 150u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::AVERAGE_RES_PPROCESSING_TIME_UNTIL_VERDICT, 50u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::AVERAGE_RES_PPROCESSING_TIME_UNTIL_VERDICT, 50u);
|
|
||||||
updateMetricField(attachment, AttachmentMetricType::AVERAGE_RES_PPROCESSING_TIME_UNTIL_VERDICT, 20u);
|
|
||||||
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::INJECT_VERDICTS_COUNT)], 100u);
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::DROP_VERDICTS_COUNT)], 200u);
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::ACCEPT_VERDICTS_COUNT)], 300u);
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::IRRELEVANT_VERDICTS_COUNT)], 400u);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
attachment->metric_data[static_cast<int>(AttachmentMetricType::MAX_RES_PPROCESSING_TIME_UNTIL_VERDICT)],
|
|
||||||
400u
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
attachment->metric_data[static_cast<int>(AttachmentMetricType::MIN_RES_PPROCESSING_TIME_UNTIL_VERDICT)],
|
|
||||||
50u
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
attachment->metric_data[static_cast<int>(AttachmentMetricType::AVERAGE_RES_PPROCESSING_TIME_UNTIL_VERDICT)],
|
|
||||||
40u
|
|
||||||
);
|
|
||||||
|
|
||||||
reset_metric_data(attachment);
|
|
||||||
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::INJECT_VERDICTS_COUNT)], 0u);
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::DROP_VERDICTS_COUNT)], 0u);
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::ACCEPT_VERDICTS_COUNT)], 0u);
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::IRRELEVANT_VERDICTS_COUNT)], 0u);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
attachment->metric_data[static_cast<int>(AttachmentMetricType::MAX_RES_PPROCESSING_TIME_UNTIL_VERDICT)],
|
|
||||||
0u
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
attachment->metric_data[static_cast<int>(AttachmentMetricType::MIN_RES_PPROCESSING_TIME_UNTIL_VERDICT)],
|
|
||||||
0u
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(
|
|
||||||
attachment->metric_data[static_cast<int>(AttachmentMetricType::AVERAGE_RES_PPROCESSING_TIME_UNTIL_VERDICT)],
|
|
||||||
0u
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,736 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
|
|
||||||
#include "mock_nano_initializer.h"
|
|
||||||
#include "mock_nano_attachment_thread.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
#include "nano_attachment_sender.h"
|
|
||||||
#include "nano_attachment_sender_thread.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoAttachmentSenderTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
nano_attachment_init_process(_)
|
|
||||||
).WillOnce(
|
|
||||||
Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
attachment = InitNanoAttachment(
|
|
||||||
static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID),
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
STDOUT_FILENO
|
|
||||||
);
|
|
||||||
EXPECT_NE(attachment, nullptr);
|
|
||||||
attachment->dbg_level = nano_http_cp_debug_level_e::DBG_LEVEL_TRACE;
|
|
||||||
|
|
||||||
session_data = InitSessionData(attachment, 1);
|
|
||||||
EXPECT_NE(session_data, nullptr);
|
|
||||||
start_data.session_data = session_data;
|
|
||||||
req_header_data.session_data = session_data;
|
|
||||||
res_header_data.session_data = session_data;
|
|
||||||
req_body_data.session_data = session_data;
|
|
||||||
res_body_data.session_data = session_data;
|
|
||||||
req_end_data.session_data = session_data;
|
|
||||||
res_end_data.session_data = session_data;
|
|
||||||
req_filter_data.session_data = session_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TearDown() override
|
|
||||||
{
|
|
||||||
FiniSessionData(attachment, session_data);
|
|
||||||
FiniNanoAttachment(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano_str_t
|
|
||||||
create_nano_str(const char *str)
|
|
||||||
{
|
|
||||||
nano_str_t nano_str;
|
|
||||||
nano_str.data = reinterpret_cast<unsigned char *>(const_cast<char *>(str));
|
|
||||||
nano_str.len = strlen(str);
|
|
||||||
return nano_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
AttachmentData *data,
|
|
||||||
void *arg,
|
|
||||||
NanoCommunicationResult com_res,
|
|
||||||
ServiceVerdict verdict
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
HttpEventThreadCtx *ctx = (HttpEventThreadCtx *)arg;
|
|
||||||
init_thread_ctx(ctx, attachment, data);
|
|
||||||
|
|
||||||
ctx->session_data_p = data->session_data;
|
|
||||||
ctx->res = com_res;
|
|
||||||
ctx->session_data_p->verdict = verdict;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpMetaData http_meta_data = {
|
|
||||||
create_nano_str("HTTP/1.1"),
|
|
||||||
create_nano_str("GET"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com"),
|
|
||||||
create_nano_str("192.168.1.100"),
|
|
||||||
80,
|
|
||||||
create_nano_str("/dogs.html"),
|
|
||||||
create_nano_str("192.168.1.101"),
|
|
||||||
253,
|
|
||||||
create_nano_str("nanoattachmentut.com"),
|
|
||||||
create_nano_str("/dogs.html")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaderData http_headers[3] = {
|
|
||||||
{
|
|
||||||
create_nano_str("Host"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("User-Agent"),
|
|
||||||
create_nano_str("Mozilla/5.0")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("Accept"),
|
|
||||||
create_nano_str("text/html")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaders http_headers_data = {
|
|
||||||
http_headers,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpRequestFilterData request_filter_data = {
|
|
||||||
&http_meta_data,
|
|
||||||
&http_headers_data,
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
nano_str_t body[3] = {
|
|
||||||
create_nano_str("Hello"),
|
|
||||||
create_nano_str("World"),
|
|
||||||
create_nano_str("!")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpBody http_body_data = {
|
|
||||||
body,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData start_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_METADATA,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_meta_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_filter_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_FILTER,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&request_filter_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_header_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_HEADER,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_headers_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData res_header_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_RESPONSE_HEADER,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_headers_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_body_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_BODY,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_body_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData res_body_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_RESPONSE_BODY,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_body_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_end_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_END,
|
|
||||||
session_data,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData res_end_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_RESPONSE_END,
|
|
||||||
session_data,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
NanoAttachment *attachment;
|
|
||||||
HttpSessionData *session_data;
|
|
||||||
StrictMock<NanoInitializerMocker> initializer_mocker;
|
|
||||||
StrictMock<NanoAttachmentThreadMocker> thread_mocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestCorruptMemory)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_ERROR)
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendMetadata(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestFailOpenDrop)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
CustomResponseData *custom_response_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_ERROR)
|
|
||||||
);
|
|
||||||
|
|
||||||
attachment->fail_mode_verdict = static_cast<int>(NanoCommunicationResult::NANO_HTTP_FORBIDDEN);
|
|
||||||
response = SendMetadata(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_DROP);
|
|
||||||
EXPECT_NE(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.web_response_data->web_response_type, NanoWebResponseType::CUSTOM_WEB_RESPONSE);
|
|
||||||
EXPECT_STREQ(
|
|
||||||
reinterpret_cast<const char *>(
|
|
||||||
response.web_response_data->uuid
|
|
||||||
),
|
|
||||||
"20118dba-81f7-4999-8e94-003cf242f5dd"
|
|
||||||
);
|
|
||||||
EXPECT_NE(response.web_response_data->data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
|
|
||||||
custom_response_data = (CustomResponseData *)response.web_response_data->data;
|
|
||||||
EXPECT_EQ(custom_response_data->response_code, 403);
|
|
||||||
EXPECT_STREQ(reinterpret_cast<const char *>(custom_response_data->title), "Default Title");
|
|
||||||
EXPECT_STREQ(reinterpret_cast<const char *>(custom_response_data->body), "Default Body");
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestTimeout)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&start_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_TIMEOUT,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(0))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendMetadata(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestIrrelevant)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&start_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_DECLINED,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_ACCEPT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendMetadata(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestFailed)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&start_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_ERROR,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendMetadata(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestFilter)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&req_filter_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendRequestFilter(attachment, &req_filter_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendMetadata)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&start_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendMetadata(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestHeaders)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&req_header_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendRequestHeaders(attachment, &req_header_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendResponseHeaders)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&res_header_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::RESPONSE
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendResponseHeaders(attachment, &res_header_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestBody)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&req_body_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendRequestBody(attachment, &req_body_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendResponseBody)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&res_body_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::RESPONSE
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_INSPECT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendResponseBody(attachment, &res_body_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendRequestEnd)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&req_end_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REQUEST
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_ACCEPT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendRequestEnd(attachment, &req_end_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendResponseEnd)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
void *_ctx;
|
|
||||||
AttachmentData *_attachment_data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&res_end_data,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::RESPONSE
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<1>(&_attachment_data), SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
_attachment_data,
|
|
||||||
_ctx,
|
|
||||||
NanoCommunicationResult::NANO_OK,
|
|
||||||
ServiceVerdict::TRAFFIC_VERDICT_ACCEPT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
response = SendResponseEnd(attachment, &res_end_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(response.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(response.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderTest, SendMetricData)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
handle_shmem_corruption(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::METRICS
|
|
||||||
)
|
|
||||||
).WillOnce(Return(1));
|
|
||||||
|
|
||||||
SendMetricData(attachment);
|
|
||||||
}
|
|
@ -1,482 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
|
|
||||||
#include "mock_nano_socket.h"
|
|
||||||
#include "mock_nano_initializer.h"
|
|
||||||
#include "mock_nano_attachment_sender.h"
|
|
||||||
#include "mock_nano_configuration.h"
|
|
||||||
#include "mock_nano_compression.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoAttachmentTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
nano_attachment_init_process(_)
|
|
||||||
).WillOnce(
|
|
||||||
Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
attachment = InitNanoAttachment(
|
|
||||||
static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID),
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
STDOUT_FILENO
|
|
||||||
);
|
|
||||||
EXPECT_NE(attachment, nullptr);
|
|
||||||
|
|
||||||
session_data = InitSessionData(attachment, 1);
|
|
||||||
EXPECT_NE(session_data, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TearDown() override
|
|
||||||
{
|
|
||||||
FiniSessionData(attachment, session_data);
|
|
||||||
FiniNanoAttachment(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano_str_t
|
|
||||||
create_nano_str(const char *str)
|
|
||||||
{
|
|
||||||
nano_str_t nano_str;
|
|
||||||
nano_str.data = reinterpret_cast<unsigned char *>(const_cast<char *>(str));
|
|
||||||
nano_str.len = strlen(str);
|
|
||||||
return nano_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebResponseData *
|
|
||||||
create_custom_drop_response_data()
|
|
||||||
{
|
|
||||||
WebResponseData *web_response_data = (WebResponseData *)malloc(sizeof(WebResponseData));
|
|
||||||
web_response_data->web_response_type = NanoWebResponseType::CUSTOM_WEB_RESPONSE;
|
|
||||||
memcpy(web_response_data->uuid, "TestThisIsUuidTest\0", 20);
|
|
||||||
|
|
||||||
CustomResponseData *custom_response_data = (CustomResponseData *)malloc(sizeof(CustomResponseData));
|
|
||||||
custom_response_data->response_code = 502;
|
|
||||||
memcpy(custom_response_data->title, "Woof Woof\0", 10);
|
|
||||||
memcpy(custom_response_data->body, "This is Ruby's barking\0", 24);
|
|
||||||
|
|
||||||
web_response_data->data = custom_response_data;
|
|
||||||
|
|
||||||
return web_response_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebResponseData *
|
|
||||||
create_redirect_response_data()
|
|
||||||
{
|
|
||||||
WebResponseData *web_response_data = (WebResponseData *)malloc(sizeof(WebResponseData));
|
|
||||||
web_response_data->web_response_type = NanoWebResponseType::REDIRECT_WEB_RESPONSE;
|
|
||||||
memcpy(web_response_data->uuid, "TestThisIsUuidTest\0", 20);
|
|
||||||
|
|
||||||
RedirectData *redirect_response_data = (RedirectData *)malloc(sizeof(CustomResponseData));
|
|
||||||
memcpy(redirect_response_data->redirect_location, "Woowwwiee.com\0", 15);
|
|
||||||
|
|
||||||
web_response_data->data = redirect_response_data;
|
|
||||||
|
|
||||||
return web_response_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
NanoHttpModificationList *
|
|
||||||
create_modifications_data()
|
|
||||||
{
|
|
||||||
NanoHttpModificationList *modification_node =
|
|
||||||
(NanoHttpModificationList *)malloc(sizeof(NanoHttpModificationList));
|
|
||||||
|
|
||||||
modification_node->next = NULL;
|
|
||||||
modification_node->modification.mod_type = HttpModificationType::APPEND;
|
|
||||||
modification_node->modification_buffer = NULL;
|
|
||||||
|
|
||||||
return modification_node;
|
|
||||||
}
|
|
||||||
|
|
||||||
AttachmentVerdictResponse inspect_response = {
|
|
||||||
AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT,
|
|
||||||
1,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentVerdictResponse accept_response = {
|
|
||||||
AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT,
|
|
||||||
1,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentVerdictResponse custom_drop_response = {
|
|
||||||
AttachmentVerdict::ATTACHMENT_VERDICT_DROP,
|
|
||||||
1,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpMetaData http_meta_data = {
|
|
||||||
create_nano_str("HTTP/1.1"),
|
|
||||||
create_nano_str("GET"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com"),
|
|
||||||
create_nano_str("192.168.1.100"),
|
|
||||||
80,
|
|
||||||
create_nano_str("/dogs.html"),
|
|
||||||
create_nano_str("192.168.1.101"),
|
|
||||||
253,
|
|
||||||
create_nano_str("nanoattachmentut.com"),
|
|
||||||
create_nano_str("/dogs.html")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaderData http_headers[3] = {
|
|
||||||
{
|
|
||||||
create_nano_str("Host"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("User-Agent"),
|
|
||||||
create_nano_str("Mozilla/5.0")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("Accept"),
|
|
||||||
create_nano_str("text/html")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaders http_headers_data = {
|
|
||||||
http_headers,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
nano_str_t body[3] = {
|
|
||||||
create_nano_str("Hello"),
|
|
||||||
create_nano_str("World"),
|
|
||||||
create_nano_str("!")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpBody http_body_data = {
|
|
||||||
body,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData start_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_METADATA,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_meta_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_header_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_HEADER,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_headers_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_body_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_BODY,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_body_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_end_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_END,
|
|
||||||
session_data,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
NanoAttachment *attachment;
|
|
||||||
HttpSessionData *session_data;
|
|
||||||
StrictMock<NanoAttachmentSenderMocker> sender_mocker;
|
|
||||||
StrictMock<NanoInitializerMocker> initializer_mocker;
|
|
||||||
StrictMock<NanoSocketMocker> socket_mocker;
|
|
||||||
StrictMock<NanoConfigurationMocker> configuration_mocker;
|
|
||||||
StrictMock<NanoCompressionMocker> compression_mocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, InitNanoAttachment)
|
|
||||||
{
|
|
||||||
EXPECT_EQ(strcmp(attachment->shared_verdict_signal_path, ""), 0);
|
|
||||||
|
|
||||||
EXPECT_EQ(attachment->worker_id, 2);
|
|
||||||
EXPECT_EQ(attachment->num_of_workers, 4);
|
|
||||||
EXPECT_EQ(attachment->nano_user_id, getuid());
|
|
||||||
EXPECT_EQ(attachment->nano_group_id, getgid());
|
|
||||||
EXPECT_EQ(attachment->registration_socket, -1);
|
|
||||||
EXPECT_EQ(attachment->attachment_type, static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID));
|
|
||||||
EXPECT_EQ(attachment->comm_socket, -1);
|
|
||||||
EXPECT_EQ(attachment->logging_fd, STDOUT_FILENO);
|
|
||||||
|
|
||||||
EXPECT_EQ(attachment->is_configuration_updated, NanoCommunicationResult::NANO_ERROR);
|
|
||||||
EXPECT_EQ(attachment->current_config_version, 0u);
|
|
||||||
EXPECT_EQ(attachment->dbg_level, nano_http_cp_debug_level::DBG_LEVEL_INFO);
|
|
||||||
EXPECT_EQ(attachment->num_of_connection_attempts, 0);
|
|
||||||
EXPECT_EQ(attachment->fail_open_timeout, 50u);
|
|
||||||
EXPECT_EQ(attachment->fail_open_delayed_timeout, 150u);
|
|
||||||
EXPECT_EQ(attachment->sessions_per_minute_limit_verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(attachment->max_sessions_per_minute, 0u);
|
|
||||||
EXPECT_EQ(attachment->req_max_proccessing_ms_time, 3000u);
|
|
||||||
EXPECT_EQ(attachment->res_max_proccessing_ms_time, 3000u);
|
|
||||||
EXPECT_EQ(attachment->registration_thread_timeout_msec, 100u);
|
|
||||||
EXPECT_EQ(attachment->req_start_thread_timeout_msec, 100u);
|
|
||||||
EXPECT_EQ(attachment->req_header_thread_timeout_msec, 100u);
|
|
||||||
EXPECT_EQ(attachment->req_body_thread_timeout_msec, 150u);
|
|
||||||
EXPECT_EQ(attachment->res_header_thread_timeout_msec, 100u);
|
|
||||||
EXPECT_EQ(attachment->res_body_thread_timeout_msec, 150u);
|
|
||||||
EXPECT_EQ(attachment->waiting_for_verdict_thread_timeout_msec, 150u);
|
|
||||||
EXPECT_EQ(attachment->inspection_mode, NanoHttpInspectionMode::NON_BLOCKING_THREAD);
|
|
||||||
EXPECT_EQ(attachment->num_of_nano_ipc_elements, 200u);
|
|
||||||
EXPECT_EQ(attachment->keep_alive_interval_msec, DEFAULT_KEEP_ALIVE_INTERVAL_MSEC);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
configuration_mocker,
|
|
||||||
reset_attachment_config(_)
|
|
||||||
).WillOnce(
|
|
||||||
Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
|
|
||||||
RestartAttachmentConfiguration(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, InitSessionData)
|
|
||||||
{
|
|
||||||
EXPECT_NE(session_data, nullptr);
|
|
||||||
EXPECT_EQ(session_data->was_request_fully_inspected, 0);
|
|
||||||
EXPECT_EQ(session_data->verdict, ServiceVerdict::TRAFFIC_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(session_data->session_id, 1u);
|
|
||||||
EXPECT_EQ(session_data->remaining_messages_to_reply, 0u);
|
|
||||||
EXPECT_EQ(session_data->req_proccesing_time, 0u);
|
|
||||||
EXPECT_EQ(session_data->res_proccesing_time, 0u);
|
|
||||||
EXPECT_EQ(session_data->processed_req_body_size, 0u);
|
|
||||||
EXPECT_EQ(session_data->processed_res_body_size, 0u);
|
|
||||||
EXPECT_EQ(IsSessionFinalized(attachment, session_data), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, AcceptFlow)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(sender_mocker, SendMetadata(attachment, &start_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestHeaders(attachment, &req_header_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestBody(attachment, &req_body_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestEnd(attachment, &req_end_data)).WillOnce(Return(accept_response));
|
|
||||||
|
|
||||||
AttachmentVerdictResponse response = SendDataNanoAttachment(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_header_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_body_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_end_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, DropFlow)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
BlockPageData block_page_data;
|
|
||||||
custom_drop_response.web_response_data = create_custom_drop_response_data();
|
|
||||||
|
|
||||||
EXPECT_CALL(sender_mocker, SendMetadata(attachment, &start_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestHeaders(attachment, &req_header_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestBody(attachment, &req_body_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestEnd(attachment, &req_end_data)).WillOnce(Return(custom_drop_response));
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_header_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_body_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_end_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_DROP);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::CUSTOM_WEB_RESPONSE);
|
|
||||||
|
|
||||||
block_page_data = GetBlockPage(attachment, session_data, &response);
|
|
||||||
EXPECT_EQ(block_page_data.response_code, 502);
|
|
||||||
EXPECT_EQ(strcmp((char *)block_page_data.uuid.data, "TestThisIsUuidTest"), 0);
|
|
||||||
EXPECT_EQ(strcmp((char *)block_page_data.title.data, "Woof Woof"), 0);
|
|
||||||
EXPECT_EQ(strcmp((char *)block_page_data.body.data, "This is Ruby's barking"), 0);
|
|
||||||
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, RedirectFlow)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
RedirectPageData redirect_page_data;
|
|
||||||
custom_drop_response.web_response_data = create_redirect_response_data();
|
|
||||||
|
|
||||||
EXPECT_CALL(sender_mocker, SendMetadata(attachment, &start_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestHeaders(attachment, &req_header_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestBody(attachment, &req_body_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestEnd(attachment, &req_end_data)).WillOnce(Return(custom_drop_response));
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_header_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_body_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_end_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_DROP);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::REDIRECT_WEB_RESPONSE);
|
|
||||||
|
|
||||||
redirect_page_data = GetRedirectPage(attachment, session_data, &response);
|
|
||||||
EXPECT_EQ(strcmp((char *)redirect_page_data.redirect_location.data, "Woowwwiee.com"), 0);
|
|
||||||
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, ModificationsFlow)
|
|
||||||
{
|
|
||||||
AttachmentVerdictResponse response;
|
|
||||||
NanoResponseModifications response_modifications;
|
|
||||||
accept_response.modifications = create_modifications_data();
|
|
||||||
|
|
||||||
EXPECT_CALL(sender_mocker, SendMetadata(attachment, &start_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestHeaders(attachment, &req_header_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestBody(attachment, &req_body_data)).WillOnce(Return(inspect_response));
|
|
||||||
EXPECT_CALL(sender_mocker, SendRequestEnd(attachment, &req_end_data)).WillOnce(Return(accept_response));
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &start_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_header_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_body_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_INSPECT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
|
|
||||||
response = SendDataNanoAttachment(attachment, &req_end_data);
|
|
||||||
EXPECT_EQ(response.session_id, 1u);
|
|
||||||
EXPECT_EQ(response.verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
EXPECT_EQ(IsResponseWithModification(attachment, session_data, &response), 1);
|
|
||||||
response_modifications = GetResponseModifications(attachment, session_data, &response);
|
|
||||||
EXPECT_NE(response_modifications.modifications, nullptr);
|
|
||||||
EXPECT_EQ(response_modifications.modifications->next, nullptr);
|
|
||||||
EXPECT_EQ(response_modifications.modifications->modification.mod_type, HttpModificationType::APPEND);
|
|
||||||
|
|
||||||
FreeAttachmentResponseContent(attachment, session_data, &response);
|
|
||||||
EXPECT_EQ(GetWebResponseType(attachment, session_data, &response), NanoWebResponseType::NO_WEB_RESPONSE);
|
|
||||||
EXPECT_EQ(IsResponseWithModification(attachment, session_data, &response), 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, SendAlive)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(socket_mocker, socket(AF_UNIX, SOCK_STREAM, 0)).WillOnce(Return(34));
|
|
||||||
EXPECT_CALL(socket_mocker, connect(34, _, _)).WillOnce(Return(0));
|
|
||||||
EXPECT_CALL(initializer_mocker, write_to_service(attachment, _, _, _, _))
|
|
||||||
.WillRepeatedly(Return(NanoCommunicationResult::NANO_OK));
|
|
||||||
EXPECT_CALL(socket_mocker, close(34));
|
|
||||||
SendKeepAlive(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, SendAliveFail)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(socket_mocker, socket(AF_UNIX, SOCK_STREAM, 0)).WillOnce(Return(34));
|
|
||||||
EXPECT_CALL(socket_mocker, connect(34, _, _)).WillOnce(Return(-1));
|
|
||||||
EXPECT_CALL(socket_mocker, close(34));
|
|
||||||
SendKeepAlive(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, TestMetricUpdate)
|
|
||||||
{
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::INJECT_VERDICTS_COUNT)], 0u);
|
|
||||||
UpdateMetric(attachment, AttachmentMetricType::INJECT_VERDICTS_COUNT, 100);
|
|
||||||
EXPECT_EQ(attachment->metric_data[static_cast<int>(AttachmentMetricType::INJECT_VERDICTS_COUNT)], 100u);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, SendAccumulatedMetricData)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(sender_mocker, SendMetricData(attachment)).WillOnce(Return(NanoCommunicationResult::NANO_OK));
|
|
||||||
SendAccumulatedMetricData(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, CompressData)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
compression_mocker,
|
|
||||||
nano_compress_body(attachment, &http_body_data, session_data)
|
|
||||||
).WillOnce(Return(nullptr)
|
|
||||||
);
|
|
||||||
compressBody(attachment, session_data, &http_body_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, DecompressData)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
compression_mocker,
|
|
||||||
nano_decompress_body(attachment, &http_body_data, session_data)
|
|
||||||
).WillOnce(Return(nullptr)
|
|
||||||
);
|
|
||||||
decompressBody(attachment, session_data, &http_body_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, FreeCompressedData)
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
compression_mocker,
|
|
||||||
nano_free_compressed_body(attachment, &http_body_data, session_data)
|
|
||||||
);
|
|
||||||
freeCompressedBody(attachment, session_data, &http_body_data);
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
#include "compression_utils.h"
|
|
||||||
|
|
||||||
#include "mock_nano_socket.h"
|
|
||||||
#include "mock_nano_initializer.h"
|
|
||||||
#include "mock_nano_attachment_sender.h"
|
|
||||||
#include "mock_nano_configuration.h"
|
|
||||||
#include "mock_nano_compression.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
#include "nano_compression.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoAttachmentTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
nano_attachment_init_process(_)
|
|
||||||
).WillOnce(
|
|
||||||
Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
attachment = InitNanoAttachment(
|
|
||||||
static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID),
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
STDOUT_FILENO
|
|
||||||
);
|
|
||||||
EXPECT_NE(attachment, nullptr);
|
|
||||||
|
|
||||||
session_data = InitSessionData(attachment, 1);
|
|
||||||
EXPECT_NE(session_data, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TearDown() override
|
|
||||||
{
|
|
||||||
FiniSessionData(attachment, session_data);
|
|
||||||
FiniNanoAttachment(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano_str_t
|
|
||||||
create_nano_str(const char *str)
|
|
||||||
{
|
|
||||||
nano_str_t nano_str;
|
|
||||||
nano_str.data = reinterpret_cast<unsigned char *>(const_cast<char *>(str));
|
|
||||||
nano_str.len = strlen(str);
|
|
||||||
return nano_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
nano_str_t body[3] = {
|
|
||||||
create_nano_str("Hello"),
|
|
||||||
create_nano_str("World"),
|
|
||||||
create_nano_str("!")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpBody http_body_data = {
|
|
||||||
body,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_body_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_BODY,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_body_data
|
|
||||||
};
|
|
||||||
|
|
||||||
NanoAttachment *attachment;
|
|
||||||
HttpSessionData *session_data;
|
|
||||||
StrictMock<NanoInitializerMocker> initializer_mocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentTest, CompressData)
|
|
||||||
{
|
|
||||||
session_data->response_data.compression_type = CompressionType::GZIP;
|
|
||||||
|
|
||||||
HttpBody * compressed_body_data = nullptr;
|
|
||||||
HttpBody * decompressed_body_data = nullptr;
|
|
||||||
|
|
||||||
compressed_body_data = nano_compress_body(attachment, &http_body_data, session_data);
|
|
||||||
EXPECT_EQ(compressed_body_data->bodies_count, 3u);
|
|
||||||
|
|
||||||
decompressed_body_data = nano_decompress_body(attachment, compressed_body_data, session_data);
|
|
||||||
EXPECT_EQ(decompressed_body_data->bodies_count, 3u);
|
|
||||||
EXPECT_EQ(decompressed_body_data->data[0].len, 5u);
|
|
||||||
EXPECT_EQ(decompressed_body_data->data[1].len, 5u);
|
|
||||||
EXPECT_EQ(decompressed_body_data->data[2].len, 1u);
|
|
||||||
|
|
||||||
EXPECT_EQ(strncmp((char *)decompressed_body_data->data[0].data, "Hello", decompressed_body_data->data[0].len), 0);
|
|
||||||
EXPECT_EQ(strncmp((char *)decompressed_body_data->data[1].data, "World", decompressed_body_data->data[1].len), 0);
|
|
||||||
EXPECT_EQ(strncmp((char *)decompressed_body_data->data[2].data, "!", decompressed_body_data->data[2].len), 0);
|
|
||||||
|
|
||||||
nano_free_compressed_body(attachment, compressed_body_data, session_data);
|
|
||||||
nano_free_compressed_body(attachment, decompressed_body_data, session_data);
|
|
||||||
}
|
|
@ -1,128 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
#include "http_configuration.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
#include "nano_configuration.h"
|
|
||||||
#include "nano_utils.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoConfigurationTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
string
|
|
||||||
createIPRangesString(const vector<string> &ip_ranges)
|
|
||||||
{
|
|
||||||
stringstream ip_ranges_string_stream;
|
|
||||||
ip_ranges_string_stream << "[";
|
|
||||||
for (auto iterator = ip_ranges.begin(); iterator < ip_ranges.end() - 1; iterator++) {
|
|
||||||
ip_ranges_string_stream << "\"" << *iterator << "\"" << ", ";
|
|
||||||
}
|
|
||||||
ip_ranges_string_stream << "\"" << ip_ranges.back() << "\"]";
|
|
||||||
|
|
||||||
return ip_ranges_string_stream.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
NanoAttachment attachment;
|
|
||||||
LoggingData logging_data;
|
|
||||||
const string static_resources_path = "/dev/shm/static_resources/";
|
|
||||||
const vector<string> ip_ranges = { "8.8.8.8", "9.9.9.9-10.10.10.10", "0:0:0:0:0:0:0:1-0:0:0:0:0:0:0:4"};
|
|
||||||
const string attachment_configuration_file_name = "cp_nano_http_attachment_conf";
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoConfigurationTest, InitAttachmentConfiguration)
|
|
||||||
{
|
|
||||||
NanoCommunicationResult res;
|
|
||||||
string valid_configuration =
|
|
||||||
"{\n"
|
|
||||||
"\"context_values\": {"
|
|
||||||
"\"clientIp\": \"1.2.3.4\","
|
|
||||||
"\"listeningIp\": \"5.6.7.8\","
|
|
||||||
"\"uriPrefix\": \"/abc\","
|
|
||||||
"\"hostName\": \"test\","
|
|
||||||
"\"httpMethod\": \"GET\","
|
|
||||||
"\"listeningPort\": 80"
|
|
||||||
"},"
|
|
||||||
"\"is_fail_open_mode_enabled\": 0,\n"
|
|
||||||
"\"fail_open_timeout\": 1234,\n"
|
|
||||||
"\"is_fail_open_mode_hold_enabled\": 0,\n"
|
|
||||||
"\"fail_open_hold_timeout\": 4321,\n"
|
|
||||||
"\"sessions_per_minute_limit_verdict\": \"Accept\",\n"
|
|
||||||
"\"max_sessions_per_minute\": 0,\n"
|
|
||||||
"\"num_of_nginx_ipc_elements\": 200,\n"
|
|
||||||
"\"keep_alive_interval_msec\": 10000,\n"
|
|
||||||
"\"dbg_level\": 2,\n"
|
|
||||||
"\"nginx_inspection_mode\": 1,\n"
|
|
||||||
"\"operation_mode\": 0,\n"
|
|
||||||
"\"req_body_thread_timeout_msec\": 155,\n"
|
|
||||||
"\"req_proccessing_timeout_msec\": 42,\n"
|
|
||||||
"\"registration_thread_timeout_msec\": 101,\n"
|
|
||||||
"\"res_proccessing_timeout_msec\": 420,\n"
|
|
||||||
"\"res_header_thread_timeout_msec\": 1,\n"
|
|
||||||
"\"res_body_thread_timeout_msec\": 80,\n"
|
|
||||||
"\"waiting_for_verdict_thread_timeout_msec\": 60,\n"
|
|
||||||
"\"req_header_thread_timeout_msec\": 10,\n"
|
|
||||||
"\"ip_ranges\": " + createIPRangesString(ip_ranges) + ",\n"
|
|
||||||
"\"static_resources_path\": \"" + static_resources_path + "\""
|
|
||||||
"}\n";
|
|
||||||
ofstream valid_configuration_file(attachment_configuration_file_name);
|
|
||||||
valid_configuration_file << valid_configuration;
|
|
||||||
valid_configuration_file.close();
|
|
||||||
|
|
||||||
attachment.shared_verdict_signal_path[0] = '\0';
|
|
||||||
attachment.worker_id = 2;
|
|
||||||
attachment.num_of_workers = 4;
|
|
||||||
attachment.nano_user_id = getuid();
|
|
||||||
attachment.nano_group_id = getgid();
|
|
||||||
attachment.registration_socket = -1;
|
|
||||||
attachment.attachment_type = static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID);
|
|
||||||
attachment.nano_service_ipc = NULL;
|
|
||||||
attachment.comm_socket = -1;
|
|
||||||
attachment.logging_data = &logging_data;
|
|
||||||
|
|
||||||
res = set_logging_fd(&attachment, STDOUT_FILENO);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
|
|
||||||
res = set_docker_id(&attachment);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
|
|
||||||
res = set_unique_id(&attachment);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
|
|
||||||
attachment.is_configuration_updated = NanoCommunicationResult::NANO_ERROR;
|
|
||||||
attachment.current_config_version = 0;
|
|
||||||
attachment.dbg_level = nano_http_cp_debug_level_e::DBG_LEVEL_TRACE;
|
|
||||||
|
|
||||||
res = init_attachment_config(&attachment, attachment_configuration_file_name.c_str());
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
|
|
||||||
EXPECT_EQ(attachment.is_configuration_updated, NanoCommunicationResult::NANO_OK);
|
|
||||||
EXPECT_EQ(attachment.dbg_level, nano_http_cp_debug_level_e::DBG_LEVEL_INFO);
|
|
||||||
EXPECT_EQ(attachment.fail_mode_verdict, 1);
|
|
||||||
EXPECT_EQ(attachment.fail_open_timeout, 1234u);
|
|
||||||
EXPECT_EQ(attachment.fail_mode_delayed_verdict, 1);
|
|
||||||
EXPECT_EQ(attachment.fail_open_delayed_timeout, 4321u);
|
|
||||||
EXPECT_EQ(attachment.sessions_per_minute_limit_verdict, AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT);
|
|
||||||
EXPECT_EQ(attachment.max_sessions_per_minute, 0u);
|
|
||||||
EXPECT_EQ(attachment.req_max_proccessing_ms_time, 42u);
|
|
||||||
EXPECT_EQ(attachment.res_max_proccessing_ms_time, 420u);
|
|
||||||
EXPECT_EQ(attachment.registration_thread_timeout_msec, 101u);
|
|
||||||
EXPECT_EQ(attachment.req_header_thread_timeout_msec, 10u);
|
|
||||||
EXPECT_EQ(attachment.req_body_thread_timeout_msec, 155u);
|
|
||||||
EXPECT_EQ(attachment.res_header_thread_timeout_msec, 1u);
|
|
||||||
EXPECT_EQ(attachment.res_body_thread_timeout_msec, 80u);
|
|
||||||
EXPECT_EQ(attachment.waiting_for_verdict_thread_timeout_msec, 60u);
|
|
||||||
EXPECT_EQ(attachment.num_of_nano_ipc_elements, 200u);
|
|
||||||
EXPECT_EQ(attachment.keep_alive_interval_msec, 10000u);
|
|
||||||
EXPECT_EQ(attachment.inspection_mode, NanoHttpInspectionMode::BLOCKING_THREAD);
|
|
||||||
|
|
||||||
res = reset_attachment_config(&attachment);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_ERROR);
|
|
||||||
}
|
|
@ -1,373 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
#include <poll.h>
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "mock_nano_socket.h"
|
|
||||||
#include "mock_shmem_ipc.h"
|
|
||||||
#include "mock_nano_access.h"
|
|
||||||
#include "mock_nano_poll.h"
|
|
||||||
#include "mock_nano_configuration.h"
|
|
||||||
#include "mock_nano_stat.h"
|
|
||||||
#include "mock_nano_attachment_thread.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_initializer.h"
|
|
||||||
#include "nano_attachment_sender_thread.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoInitializerTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
ipc_holder = make_unique<int>();
|
|
||||||
mock_ipc = reinterpret_cast<SharedMemoryIPC *>(ipc_holder.get());
|
|
||||||
|
|
||||||
set_logging_fd(&attachment, STDOUT_FILENO);
|
|
||||||
attachment.dbg_level = nano_http_cp_debug_level_e::DBG_LEVEL_TRACE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
AttachmentData *data,
|
|
||||||
void *arg,
|
|
||||||
int comm_socket,
|
|
||||||
NanoCommunicationResult com_res
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
HttpEventThreadCtx *ctx = (HttpEventThreadCtx *)arg;
|
|
||||||
init_thread_ctx(ctx, &attachment, data);
|
|
||||||
attachment.comm_socket = comm_socket;
|
|
||||||
attachment.registration_socket = comm_socket;
|
|
||||||
ctx->res = com_res;
|
|
||||||
}
|
|
||||||
|
|
||||||
unique_ptr<int> ipc_holder;
|
|
||||||
NanoAttachment attachment;
|
|
||||||
SharedMemoryIPC *mock_ipc;
|
|
||||||
void *_ctx;
|
|
||||||
|
|
||||||
StrictMock<NanoSocketMocker> socket_mocker;
|
|
||||||
StrictMock<NanoShmemIPCMocker> ipc_mocker;
|
|
||||||
StrictMock<NanoAccessMocker> access_mocker;
|
|
||||||
StrictMock<NanoPollMocker> poll_mocker;
|
|
||||||
StrictMock<NanoConfigurationMocker> config_mocker;
|
|
||||||
StrictMock<NanoStatMocker> stat_mocker;
|
|
||||||
StrictMock<NanoAttachmentThreadMocker> thread_mocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoInitializerTest, InitNanoAttachmentProcess)
|
|
||||||
{
|
|
||||||
NanoCommunicationResult res;
|
|
||||||
|
|
||||||
struct pollfd mock_s_poll;
|
|
||||||
struct pollfd *mock_s_poll_ptr = &mock_s_poll;
|
|
||||||
|
|
||||||
attachment.registration_state = nano_attachment_registration_state::REGISTERED;
|
|
||||||
attachment.comm_socket = -1;
|
|
||||||
attachment.nano_service_ipc = nullptr;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
poll_mocker,
|
|
||||||
poll(_, _, _)
|
|
||||||
).WillRepeatedly(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<0>(&mock_s_poll_ptr),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
mock_s_poll_ptr->revents = POLLIN;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillRepeatedly(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
read(
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_
|
|
||||||
)
|
|
||||||
).Times(1)
|
|
||||||
.WillOnce(Return(sizeof(uint8_t)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
&attachment,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REGISTRATION
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
nullptr,
|
|
||||||
_ctx,
|
|
||||||
32,
|
|
||||||
NanoCommunicationResult::NANO_OK
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
config_mocker,
|
|
||||||
init_attachment_config(
|
|
||||||
&attachment,
|
|
||||||
_
|
|
||||||
)
|
|
||||||
).Times(2)
|
|
||||||
.WillOnce(Return(NanoCommunicationResult::NANO_ERROR))
|
|
||||||
.WillOnce(Return(NanoCommunicationResult::NANO_OK));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
access_mocker,
|
|
||||||
access(
|
|
||||||
_,
|
|
||||||
_
|
|
||||||
)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
ipc_mocker,
|
|
||||||
initIpc(
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_
|
|
||||||
)
|
|
||||||
).WillOnce(Return(mock_ipc));
|
|
||||||
|
|
||||||
res = nano_attachment_init_process(&attachment);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoInitializerTest, RegisterToAttachment)
|
|
||||||
{
|
|
||||||
NanoCommunicationResult res;
|
|
||||||
struct pollfd mock_s_poll;
|
|
||||||
struct pollfd *mock_s_poll_ptr = &mock_s_poll;
|
|
||||||
|
|
||||||
attachment.comm_socket = 53;
|
|
||||||
attachment.registration_socket = 34;
|
|
||||||
attachment.nano_service_ipc = mock_ipc;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
close(34)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
close(88)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
&attachment,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REGISTRATION
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
nullptr,
|
|
||||||
_ctx,
|
|
||||||
88,
|
|
||||||
NanoCommunicationResult::NANO_OK
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillRepeatedly(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
poll_mocker,
|
|
||||||
poll(_, _, _)
|
|
||||||
).WillRepeatedly(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<0>(&mock_s_poll_ptr),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
mock_s_poll_ptr->revents = POLLIN;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
read(
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_
|
|
||||||
)
|
|
||||||
).Times(1)
|
|
||||||
.WillOnce(Return(sizeof(uint8_t)));
|
|
||||||
|
|
||||||
res = register_to_attachments_manager(&attachment);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoInitializerTest, DisconnectCommunication)
|
|
||||||
{
|
|
||||||
int res;
|
|
||||||
attachment.comm_socket = 53;
|
|
||||||
attachment.nano_service_ipc = mock_ipc;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
close(53)
|
|
||||||
).WillOnce(Return(-1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
ipc_mocker,
|
|
||||||
destroyIpc(mock_ipc, 0)
|
|
||||||
).WillOnce(Return());
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
ipc_mocker,
|
|
||||||
isCorruptedShmem(mock_ipc, 0)
|
|
||||||
).WillOnce(Return(0));
|
|
||||||
|
|
||||||
handle_shmem_corruption(&attachment);
|
|
||||||
|
|
||||||
disconnect_communication(&attachment);
|
|
||||||
|
|
||||||
EXPECT_EQ(attachment.comm_socket, -1);
|
|
||||||
EXPECT_EQ(attachment.nano_service_ipc, nullptr);
|
|
||||||
|
|
||||||
res = isIpcReady(&attachment);
|
|
||||||
EXPECT_EQ(res, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoInitializerTest, RestartCommunication)
|
|
||||||
{
|
|
||||||
NanoCommunicationResult res;
|
|
||||||
struct pollfd mock_s_poll;
|
|
||||||
struct pollfd *mock_s_poll_ptr = &mock_s_poll;
|
|
||||||
|
|
||||||
attachment.comm_socket = 53;
|
|
||||||
attachment.registration_socket = 34;
|
|
||||||
attachment.nano_service_ipc = mock_ipc;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
ipc_mocker,
|
|
||||||
destroyIpc(mock_ipc, 0)
|
|
||||||
).WillOnce(Return());
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
poll_mocker,
|
|
||||||
poll(_, _, _)
|
|
||||||
).WillRepeatedly(
|
|
||||||
DoAll(
|
|
||||||
SaveArg<0>(&mock_s_poll_ptr),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
mock_s_poll_ptr->revents = POLLIN;
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
write(_, _, _)
|
|
||||||
).WillRepeatedly(Return(1));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
socket_mocker,
|
|
||||||
read(
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_
|
|
||||||
)
|
|
||||||
).Times(1)
|
|
||||||
.WillOnce(Return(sizeof(uint8_t)));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
ipc_mocker,
|
|
||||||
initIpc(
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_
|
|
||||||
)
|
|
||||||
).WillOnce(Return(mock_ipc));
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
thread_mocker,
|
|
||||||
NanoRunInThreadTimeout(
|
|
||||||
&attachment,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
_,
|
|
||||||
TransactionType::REGISTRATION
|
|
||||||
)
|
|
||||||
).WillOnce(DoAll(SaveArg<3>(&_ctx),
|
|
||||||
InvokeWithoutArgs(
|
|
||||||
[&] () {
|
|
||||||
NanoRunInThreadTimeoutInvoker(
|
|
||||||
nullptr,
|
|
||||||
_ctx,
|
|
||||||
53,
|
|
||||||
NanoCommunicationResult::NANO_OK
|
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
|
||||||
Return(1))
|
|
||||||
);
|
|
||||||
|
|
||||||
res = restart_communication(&attachment);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoInitializerTest, SetLoggingFailure)
|
|
||||||
{
|
|
||||||
NanoCommunicationResult res;
|
|
||||||
EXPECT_CALL(stat_mocker, mkdir(_, _)).WillOnce(Return(-1));
|
|
||||||
|
|
||||||
res = set_logging_fd(&attachment, 0);
|
|
||||||
EXPECT_EQ(res, NanoCommunicationResult::NANO_ERROR);
|
|
||||||
}
|
|
@ -1,471 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
|
|
||||||
#include "mock_nano_initializer.h"
|
|
||||||
#include "mock_nano_attachment_io.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
#include "nano_attachment_sender_thread.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoAttachmentSenderThreadTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
nano_attachment_init_process(_)
|
|
||||||
).WillOnce(
|
|
||||||
Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
attachment = InitNanoAttachment(
|
|
||||||
static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID),
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
STDOUT_FILENO
|
|
||||||
);
|
|
||||||
EXPECT_NE(attachment, nullptr);
|
|
||||||
attachment->dbg_level = nano_http_cp_debug_level::DBG_LEVEL_TRACE;
|
|
||||||
|
|
||||||
session_data = InitSessionData(attachment, 1);
|
|
||||||
EXPECT_NE(session_data, nullptr);
|
|
||||||
start_data.session_data = session_data;
|
|
||||||
req_header_data.session_data = session_data;
|
|
||||||
res_header_data.session_data = session_data;
|
|
||||||
req_body_data.session_data = session_data;
|
|
||||||
res_body_data.session_data = session_data;
|
|
||||||
req_end_data.session_data = session_data;
|
|
||||||
res_end_data.session_data = session_data;
|
|
||||||
delayed_verdict_data.session_data = session_data;
|
|
||||||
req_filter_data.session_data = session_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TearDown() override
|
|
||||||
{
|
|
||||||
FiniSessionData(attachment, session_data);
|
|
||||||
FiniNanoAttachment(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano_str_t
|
|
||||||
create_nano_str(const char *str)
|
|
||||||
{
|
|
||||||
nano_str_t nano_str;
|
|
||||||
nano_str.data = reinterpret_cast<unsigned char *>(const_cast<char *>(str));
|
|
||||||
nano_str.len = strlen(str);
|
|
||||||
return nano_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpMetaData http_meta_data = {
|
|
||||||
create_nano_str("HTTP/1.1"),
|
|
||||||
create_nano_str("GET"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com"),
|
|
||||||
create_nano_str("192.168.1.100"),
|
|
||||||
80,
|
|
||||||
create_nano_str("/dogs.html"),
|
|
||||||
create_nano_str("192.168.1.101"),
|
|
||||||
253,
|
|
||||||
create_nano_str("nanoattachmentut.com"),
|
|
||||||
create_nano_str("/dogs.html")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaderData http_headers[4] = {
|
|
||||||
{
|
|
||||||
create_nano_str("Host"),
|
|
||||||
create_nano_str("www.nanoattachmentut.com")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("User-Agent"),
|
|
||||||
create_nano_str("Mozilla/5.0")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("Accept"),
|
|
||||||
create_nano_str("text/html")
|
|
||||||
},
|
|
||||||
{
|
|
||||||
create_nano_str("content-encoding"),
|
|
||||||
create_nano_str("gzip")
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpHeaders http_headers_data = {
|
|
||||||
http_headers,
|
|
||||||
4
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpRequestFilterData request_filter_data = {
|
|
||||||
&http_meta_data,
|
|
||||||
&http_headers_data,
|
|
||||||
false
|
|
||||||
};
|
|
||||||
|
|
||||||
ResHttpHeaders res_http_headers_data = {
|
|
||||||
&http_headers_data,
|
|
||||||
static_cast<uint16_t>(522),
|
|
||||||
static_cast<uint64_t>(300)
|
|
||||||
};
|
|
||||||
|
|
||||||
nano_str_t body[3] = {
|
|
||||||
create_nano_str("Hello"),
|
|
||||||
create_nano_str("World"),
|
|
||||||
create_nano_str("!")
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpBody http_body_data = {
|
|
||||||
body,
|
|
||||||
3
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData start_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_METADATA,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_meta_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_header_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_HEADER,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_headers_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_filter_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_FILTER,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&request_filter_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData res_header_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_RESPONSE_HEADER,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&res_http_headers_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_body_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_BODY,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_body_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData res_body_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_RESPONSE_BODY,
|
|
||||||
session_data,
|
|
||||||
(DataBuffer)&http_body_data
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData req_end_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_END,
|
|
||||||
session_data,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData res_end_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_RESPONSE_END,
|
|
||||||
session_data,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData delayed_verdict_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HOLD_DATA,
|
|
||||||
session_data,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
NanoAttachment *attachment;
|
|
||||||
HttpSessionData *session_data;
|
|
||||||
StrictMock<NanoInitializerMocker> initializer_mocker;
|
|
||||||
StrictMock<NanoAttachmentIoMocker> io_mocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, InitThreadCtx)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
init_thread_ctx(&ctx, attachment, &req_body_data);
|
|
||||||
EXPECT_EQ(ctx.attachment, attachment);
|
|
||||||
EXPECT_EQ(ctx.data, &req_body_data);
|
|
||||||
EXPECT_EQ(ctx.session_data_p, session_data);
|
|
||||||
EXPECT_EQ(ctx.res, NanoCommunicationResult::NANO_OK);
|
|
||||||
EXPECT_EQ(ctx.web_response_data, nullptr);
|
|
||||||
EXPECT_EQ(ctx.modifications, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, RegistrationCommSocketThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
connect_to_comm_socket(attachment)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, nullptr);
|
|
||||||
RegistrationCommSocketThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, RegistrationSocketThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
connect_to_registration_socket(attachment)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, nullptr);
|
|
||||||
RegistrationSocketThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendMetadataThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_metadata_sender(
|
|
||||||
attachment,
|
|
||||||
(HttpMetaData *)start_data.data,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &start_data);
|
|
||||||
SendMetadataThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendRequestFilterThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_metadata_sender(
|
|
||||||
attachment,
|
|
||||||
(HttpMetaData *)start_data.data,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_header_sender(
|
|
||||||
attachment,
|
|
||||||
(HttpHeaders *)req_header_data.data,
|
|
||||||
&ctx,
|
|
||||||
AttachmentDataType::REQUEST_HEADER,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::REQUEST_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &req_filter_data);
|
|
||||||
SendRequestFilterThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendRequestHeadersThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_header_sender(
|
|
||||||
attachment,
|
|
||||||
(HttpHeaders *)req_header_data.data,
|
|
||||||
&ctx,
|
|
||||||
AttachmentDataType::REQUEST_HEADER,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
false
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &req_header_data);
|
|
||||||
SendRequestHeadersThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendResponseHeadersThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
ResHttpHeaders *res_headers = (ResHttpHeaders *)res_header_data.data;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_send_response_code(
|
|
||||||
attachment,
|
|
||||||
static_cast<uint16_t>(522),
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_send_response_content_length(
|
|
||||||
attachment,
|
|
||||||
static_cast<uint64_t>(300),
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_header_sender(
|
|
||||||
attachment,
|
|
||||||
(HttpHeaders *)res_headers->headers,
|
|
||||||
&ctx,
|
|
||||||
AttachmentDataType::RESPONSE_HEADER,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply,
|
|
||||||
true
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &res_header_data);
|
|
||||||
SendResponseHeadersThread(&ctx);
|
|
||||||
|
|
||||||
EXPECT_EQ(session_data->response_data.compression_type, CompressionType::GZIP);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendRequestBodyThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_body_sender(
|
|
||||||
attachment,
|
|
||||||
(HttpBody *)req_body_data.data,
|
|
||||||
&ctx,
|
|
||||||
AttachmentDataType::REQUEST_BODY,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &req_body_data);
|
|
||||||
SendRequestBodyThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendResponseBodyThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_body_sender(
|
|
||||||
attachment,
|
|
||||||
(HttpBody *)res_body_data.data,
|
|
||||||
&ctx,
|
|
||||||
AttachmentDataType::RESPONSE_BODY,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &res_body_data);
|
|
||||||
SendResponseBodyThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendRequestEndThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::REQUEST_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &req_end_data);
|
|
||||||
SendRequestEndThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendResponseEndThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_end_transaction_sender(
|
|
||||||
attachment,
|
|
||||||
AttachmentDataType::RESPONSE_END,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &res_end_data);
|
|
||||||
SendResponseEndThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendDelayedVerdictRequestThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_request_delayed_verdict(
|
|
||||||
attachment,
|
|
||||||
&ctx,
|
|
||||||
session_data->session_id,
|
|
||||||
&session_data->remaining_messages_to_reply
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &delayed_verdict_data);
|
|
||||||
SendDelayedVerdictRequestThread(&ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoAttachmentSenderThreadTest, SendMetricToServiceThread)
|
|
||||||
{
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
io_mocker,
|
|
||||||
nano_send_metric_data_sender(attachment)
|
|
||||||
);
|
|
||||||
|
|
||||||
init_thread_ctx(&ctx, attachment, &delayed_verdict_data);
|
|
||||||
SendMetricToServiceThread(&ctx);
|
|
||||||
}
|
|
@ -1,128 +0,0 @@
|
|||||||
#include "cptest.h"
|
|
||||||
#include "nano_attachment_common.h"
|
|
||||||
#include "attachment_types.h"
|
|
||||||
|
|
||||||
#include "mock_nano_socket.h"
|
|
||||||
#include "mock_nano_initializer.h"
|
|
||||||
#include "mock_nano_sender_thread.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "nano_attachment.h"
|
|
||||||
#include "nano_attachment_thread.h"
|
|
||||||
#include "nano_attachment_sender_thread.h"
|
|
||||||
}
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace testing;
|
|
||||||
|
|
||||||
class NanoThreadTest : public Test
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void
|
|
||||||
SetUp() override
|
|
||||||
{
|
|
||||||
EXPECT_CALL(
|
|
||||||
initializer_mocker,
|
|
||||||
nano_attachment_init_process(_)
|
|
||||||
).WillOnce(
|
|
||||||
Return(NanoCommunicationResult::NANO_OK)
|
|
||||||
);
|
|
||||||
attachment = InitNanoAttachment(
|
|
||||||
static_cast<uint8_t>(AttachmentType::NGINX_ATT_ID),
|
|
||||||
2,
|
|
||||||
4,
|
|
||||||
STDOUT_FILENO
|
|
||||||
);
|
|
||||||
EXPECT_NE(attachment, nullptr);
|
|
||||||
attachment->dbg_level = nano_http_cp_debug_level_e::DBG_LEVEL_TRACE;
|
|
||||||
|
|
||||||
session_data = InitSessionData(attachment, 1);
|
|
||||||
EXPECT_NE(session_data, nullptr);
|
|
||||||
|
|
||||||
ctx_data.session_data = session_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
TearDown() override
|
|
||||||
{
|
|
||||||
FiniSessionData(attachment, session_data);
|
|
||||||
FiniNanoAttachment(attachment);
|
|
||||||
}
|
|
||||||
|
|
||||||
nano_str_t
|
|
||||||
create_nano_str(const char *str)
|
|
||||||
{
|
|
||||||
nano_str_t nano_str;
|
|
||||||
nano_str.data = reinterpret_cast<unsigned char *>(const_cast<char *>(str));
|
|
||||||
nano_str.len = strlen(str);
|
|
||||||
return nano_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
AttachmentVerdictResponse accept_response = {
|
|
||||||
AttachmentVerdict::ATTACHMENT_VERDICT_ACCEPT,
|
|
||||||
1,
|
|
||||||
NULL,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
AttachmentData ctx_data = {
|
|
||||||
1,
|
|
||||||
HttpChunkType::HTTP_REQUEST_END,
|
|
||||||
session_data,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
HttpEventThreadCtx ctx;
|
|
||||||
|
|
||||||
NanoAttachment *attachment;
|
|
||||||
HttpSessionData *session_data;
|
|
||||||
StrictMock<NanoSenderThreadMocker> sender_thread_mocker;
|
|
||||||
StrictMock<NanoInitializerMocker> initializer_mocker;
|
|
||||||
StrictMock<NanoSocketMocker> socket_mocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST_F(NanoThreadTest, NanoRunInThreadTimeout)
|
|
||||||
{
|
|
||||||
int res;
|
|
||||||
char func_name[] = "SendRequestEndThread";
|
|
||||||
EXPECT_CALL(
|
|
||||||
sender_thread_mocker,
|
|
||||||
SendRequestEndThread(&ctx)
|
|
||||||
).WillOnce(Return(nullptr));
|
|
||||||
|
|
||||||
res = NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&ctx_data,
|
|
||||||
SendRequestEndThread,
|
|
||||||
(void *)&ctx,
|
|
||||||
attachment->req_header_thread_timeout_msec,
|
|
||||||
func_name,
|
|
||||||
REQUEST
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(res, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(NanoThreadTest, NanoRunInThreadTimeoutNonThread)
|
|
||||||
{
|
|
||||||
int res;
|
|
||||||
char func_name[] = "SendRequestEndThread";
|
|
||||||
attachment->inspection_mode = NanoHttpInspectionMode::NO_THREAD;
|
|
||||||
|
|
||||||
EXPECT_CALL(
|
|
||||||
sender_thread_mocker,
|
|
||||||
SendRequestEndThread(&ctx)
|
|
||||||
).WillOnce(Return(nullptr));
|
|
||||||
|
|
||||||
res = NanoRunInThreadTimeout(
|
|
||||||
attachment,
|
|
||||||
&ctx_data,
|
|
||||||
SendRequestEndThread,
|
|
||||||
(void *)&ctx,
|
|
||||||
attachment->req_header_thread_timeout_msec,
|
|
||||||
func_name,
|
|
||||||
REQUEST
|
|
||||||
);
|
|
||||||
|
|
||||||
EXPECT_EQ(res, 1);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user