401 lines
15 KiB
C++
401 lines
15 KiB
C++
|
|
#include <gtest/gtest.h>
|
|
#include <http_convert.h>
|
|
#include <event.h>
|
|
|
|
unsigned char __64x[] = {
|
|
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
|
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
|
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
|
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
|
0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58, 0x58,
|
|
0x58, 0x58, 0x58, 0x58
|
|
};
|
|
|
|
unsigned char __64x_gz[] = {
|
|
0x1f, 0x8b, 0x08, 0x08, 0x56, 0x77, 0xab, 0x5b, 0x00, 0x03, 0x36, 0x34,
|
|
0x78, 0x00, 0x8b, 0x88, 0xa0, 0x0c, 0x00, 0x00, 0x7b, 0xab, 0x2a, 0xf2,
|
|
0x40, 0x00, 0x00, 0x00
|
|
};
|
|
|
|
unsigned char monkey[] = {
|
|
0x7a, 0x6e, 0x78, 0x63, 0x76, 0x6e, 0x6d, 0x7a, 0x2c, 0x78, 0x76, 0x6e,
|
|
0x6d, 0x2e, 0x2c, 0x7a, 0x78, 0x63, 0x6e, 0x76, 0x2e, 0x2c, 0x78, 0x63,
|
|
0x6e, 0x2e, 0x7a, 0x2c, 0x76, 0x6e, 0x2e, 0x7a, 0x76, 0x6e, 0x2e, 0x7a,
|
|
0x78, 0x63, 0x76, 0x6e, 0x2e, 0x2c, 0x7a, 0x78, 0x63, 0x6e, 0x2e, 0x76,
|
|
0x6e, 0x2e, 0x76, 0x2c, 0x7a, 0x6e, 0x6d, 0x2e, 0x2c, 0x76, 0x6e, 0x7a,
|
|
0x78, 0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71, 0x77,
|
|
0x75, 0x72, 0x69, 0x6f, 0x70, 0x75, 0x74, 0x69, 0x6f, 0x70, 0x71, 0x77,
|
|
0x75, 0x72, 0x69, 0x6f, 0x77, 0x75, 0x71, 0x65, 0x72, 0x69, 0x6f, 0x75,
|
|
0x70, 0x71, 0x77, 0x65, 0x72, 0x6f, 0x70, 0x75, 0x77, 0x65, 0x72, 0x6f,
|
|
0x70, 0x71, 0x77, 0x75, 0x72, 0x77, 0x65, 0x75, 0x71, 0x72, 0x69, 0x6f,
|
|
0x70, 0x75, 0x72, 0x6f, 0x70, 0x71, 0x77, 0x75, 0x72, 0x69, 0x6f, 0x70,
|
|
0x75, 0x71, 0x77, 0x72, 0x69, 0x6f, 0x70, 0x75, 0x71, 0x77, 0x65, 0x6f,
|
|
0x70, 0x72, 0x75, 0x69, 0x6f, 0x71, 0x77, 0x65, 0x75, 0x72, 0x71, 0x77,
|
|
0x65, 0x75, 0x72, 0x69, 0x6f, 0x75, 0x71, 0x77, 0x65, 0x6f, 0x70, 0x72,
|
|
0x75, 0x69, 0x6f, 0x75, 0x70, 0x71, 0x69, 0x79, 0x74, 0x69, 0x6f, 0x71,
|
|
0x74, 0x79, 0x69, 0x6f, 0x77, 0x74, 0x79, 0x71, 0x70, 0x74, 0x79, 0x70,
|
|
0x72, 0x79, 0x6f, 0x71, 0x77, 0x65, 0x75, 0x74, 0x69, 0x6f, 0x69, 0x6f,
|
|
0x71, 0x74, 0x77, 0x65, 0x71, 0x72, 0x75, 0x6f, 0x77, 0x71, 0x65, 0x79,
|
|
0x74, 0x69, 0x6f, 0x77, 0x71, 0x75, 0x69, 0x6f, 0x75, 0x72, 0x6f, 0x77,
|
|
0x65, 0x74, 0x79, 0x6f, 0x71, 0x77, 0x75, 0x70, 0x69, 0x6f, 0x74, 0x77,
|
|
0x65, 0x75, 0x71, 0x69, 0x6f, 0x72, 0x77, 0x65, 0x75, 0x71, 0x72, 0x6f,
|
|
0x69, 0x70, 0x69, 0x74, 0x75, 0x71, 0x77, 0x69, 0x6f, 0x72, 0x71, 0x77,
|
|
0x74, 0x69, 0x6f, 0x77, 0x65, 0x75, 0x72, 0x69, 0x6f, 0x75, 0x79, 0x74,
|
|
0x75, 0x69, 0x6f, 0x65, 0x72, 0x79, 0x74, 0x75, 0x69, 0x6f, 0x77, 0x65,
|
|
0x72, 0x79, 0x75, 0x69, 0x74, 0x6f, 0x77, 0x65, 0x79, 0x74, 0x75, 0x69,
|
|
0x77, 0x65, 0x79, 0x75, 0x69, 0x74, 0x79, 0x65, 0x72, 0x75, 0x69, 0x72,
|
|
0x74, 0x79, 0x75, 0x71, 0x72, 0x69, 0x71, 0x77, 0x65, 0x75, 0x72, 0x6f,
|
|
0x70, 0x71, 0x77, 0x65, 0x69, 0x72, 0x75, 0x69, 0x6f, 0x71, 0x77, 0x65,
|
|
0x75, 0x72, 0x69, 0x6f, 0x71, 0x77, 0x75, 0x65, 0x72, 0x69, 0x6f, 0x71,
|
|
0x77, 0x79, 0x75, 0x69, 0x74, 0x75, 0x69, 0x65, 0x72, 0x77, 0x6f, 0x74,
|
|
0x75, 0x65, 0x72, 0x79, 0x75, 0x69, 0x6f, 0x74, 0x77, 0x65, 0x79, 0x72,
|
|
0x74, 0x75, 0x69, 0x77, 0x65, 0x72, 0x74, 0x79, 0x69, 0x6f, 0x77, 0x65,
|
|
0x72, 0x79, 0x72, 0x75, 0x65, 0x69, 0x6f, 0x71, 0x70, 0x74, 0x79, 0x69,
|
|
0x6f, 0x72, 0x75, 0x79, 0x69, 0x6f, 0x70, 0x71, 0x77, 0x74, 0x6a, 0x6b,
|
|
0x61, 0x73, 0x64, 0x66, 0x68, 0x6c, 0x61, 0x66, 0x68, 0x6c, 0x61, 0x73,
|
|
0x64, 0x68, 0x66, 0x6a, 0x6b, 0x6c, 0x61, 0x73, 0x68, 0x6a, 0x6b, 0x66,
|
|
0x68, 0x61, 0x73, 0x6a, 0x6b, 0x6c, 0x66, 0x68, 0x6b, 0x6c, 0x61, 0x73,
|
|
0x6a, 0x64, 0x66, 0x68, 0x6b, 0x6c, 0x61, 0x73, 0x64, 0x68, 0x66, 0x6a,
|
|
0x6b, 0x61, 0x6c, 0x73, 0x64, 0x68, 0x66, 0x6b, 0x6c, 0x61, 0x73, 0x64,
|
|
0x68, 0x6a, 0x6b, 0x66, 0x6c, 0x61, 0x68, 0x73, 0x6a, 0x64, 0x6b, 0x66,
|
|
0x68, 0x6b, 0x6c, 0x61, 0x73, 0x66, 0x68, 0x6a, 0x6b, 0x61, 0x73, 0x64,
|
|
0x66, 0x68, 0x61, 0x73, 0x66, 0x6a, 0x6b, 0x61, 0x73, 0x64, 0x68, 0x66,
|
|
0x6b, 0x6c, 0x73, 0x64, 0x68, 0x61, 0x6c, 0x67, 0x68, 0x68, 0x61, 0x66,
|
|
0x3b, 0x68, 0x64, 0x6b, 0x6c, 0x61, 0x73, 0x66, 0x68, 0x6a, 0x6b, 0x6c,
|
|
0x61, 0x73, 0x68, 0x6a, 0x6b, 0x6c, 0x66, 0x61, 0x73, 0x64, 0x68, 0x66,
|
|
0x61, 0x73, 0x64, 0x6a, 0x6b, 0x6c, 0x66, 0x68, 0x73, 0x64, 0x6a, 0x6b,
|
|
0x6c, 0x61, 0x66, 0x73, 0x64, 0x3b, 0x68, 0x6b, 0x6c, 0x64, 0x61, 0x64,
|
|
0x66, 0x6a, 0x6a, 0x6b, 0x6c, 0x61, 0x73, 0x64, 0x68, 0x66, 0x6a, 0x61,
|
|
0x73, 0x64, 0x64, 0x66, 0x6a, 0x6b, 0x6c, 0x66, 0x68, 0x61, 0x6b, 0x6a,
|
|
0x6b, 0x6c, 0x61, 0x73, 0x64, 0x6a, 0x66, 0x6b, 0x6c, 0x3b, 0x61, 0x73,
|
|
0x64, 0x6a, 0x66, 0x61, 0x73, 0x66, 0x6c, 0x6a, 0x61, 0x73, 0x64, 0x66,
|
|
0x68, 0x6a, 0x6b, 0x6c, 0x61, 0x73, 0x64, 0x66, 0x68, 0x6a, 0x6b, 0x61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d5, 0x7b, 0x35, 0xf6, 0x50, 0xfc, 0xde,
|
|
0xab, 0x35, 0xdb, 0x0e, 0xb4, 0xdb, 0x6e, 0xac, 0x7a, 0x23, 0x37, 0x96,
|
|
0xf5, 0xb6, 0x0e, 0x94, 0xb9, 0x3a, 0x88, 0xa3, 0x04, 0xef, 0x50, 0x16,
|
|
0xf3, 0x7d, 0x10, 0x8c, 0xfd, 0x08, 0x22, 0x95, 0x8c, 0x44, 0x44, 0x75,
|
|
0xfc, 0x58, 0xab, 0xcc, 0xcb, 0xae, 0xbf, 0xac, 0x71, 0xe5, 0x30, 0xc2,
|
|
0x41, 0x90, 0x5b, 0x02, 0xca, 0xbc, 0xd7, 0x17, 0xd4, 0x56, 0xb5, 0x9a,
|
|
0x6d, 0xfb, 0x3d, 0x8b, 0xb8, 0x1a, 0x21, 0xa9, 0x7d, 0x34, 0x37, 0x48,
|
|
0xbf, 0x04, 0xa1, 0x78, 0x6c, 0x72, 0x76, 0x4c, 0xc4, 0xc5, 0x8f, 0x58,
|
|
0xb1, 0xe6, 0x25, 0xc4, 0x0f, 0x9f, 0x2c, 0x68, 0x6c, 0xff, 0x35, 0x04,
|
|
0xd8, 0xfd, 0x07, 0xec, 0x10, 0x9d, 0x29, 0x4b, 0x03, 0x00, 0x00
|
|
};
|
|
|
|
unsigned int monkey_gz_len = 407;
|
|
unsigned int monkey_len = 843;
|
|
unsigned int __64x_len = 64;
|
|
unsigned int __64x_gz_len = 28;
|
|
bool g_print_to_stderr = true;
|
|
|
|
struct callback_ctx
|
|
{
|
|
unsigned char * data;
|
|
unsigned int sz_data;
|
|
};
|
|
|
|
int __gzip_64x_data_callback(struct http_half_private * hf_private,
|
|
tfe_http_event ev, const unsigned char * data, size_t len, void * user)
|
|
{
|
|
auto * __ctx = (struct callback_ctx *)user;
|
|
memcpy(__ctx->data + __ctx->sz_data, data, len);
|
|
__ctx->sz_data += len;
|
|
return 0;
|
|
}
|
|
|
|
class HttpConvertUncompress : public ::testing::Test
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
__ctx = new struct callback_ctx;
|
|
__ctx->data = new unsigned char[2048];
|
|
__ctx->sz_data = 0;
|
|
|
|
cv_object = hf_content_uncompress_create(
|
|
HTTP_ACCEPT_ENCODING_GZIP, __gzip_64x_data_callback, __ctx);
|
|
|
|
ASSERT_TRUE(cv_object != NULL);
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
delete[] __ctx->data;
|
|
delete __ctx;
|
|
hf_content_uncompress_destroy(cv_object);
|
|
}
|
|
|
|
protected:
|
|
struct callback_ctx * __ctx{};
|
|
struct hf_content_uncompress * cv_object{};
|
|
};
|
|
|
|
TEST_F(HttpConvertUncompress, Gzip64x)
|
|
{
|
|
int ret = hf_content_uncompress_write(cv_object, NULL, EV_HTTP_REQ_BODY_CONT,
|
|
(const unsigned char *) __64x_gz, (size_t) __64x_gz_len);
|
|
|
|
EXPECT_EQ(ret, 1);
|
|
EXPECT_EQ(__ctx->sz_data, __64x_len);
|
|
EXPECT_EQ(memcmp(__ctx->data, __64x, __64x_len), 0);
|
|
}
|
|
|
|
TEST_F(HttpConvertUncompress, GzipMonkey)
|
|
{
|
|
int ret = hf_content_uncompress_write(cv_object, NULL, EV_HTTP_REQ_BODY_CONT,
|
|
(const unsigned char *) monkey_gz, (size_t) monkey_gz_len);
|
|
|
|
EXPECT_EQ(ret, 1);
|
|
EXPECT_EQ(__ctx->sz_data, monkey_len);
|
|
EXPECT_EQ(memcmp(__ctx->data, monkey, monkey_len), 0);
|
|
}
|
|
|
|
TEST_F(HttpConvertUncompress, GzipMonkeyFrag)
|
|
{
|
|
unsigned frag_length = monkey_gz_len / 2;
|
|
|
|
int ret = 0;
|
|
ret = hf_content_uncompress_write(cv_object, NULL, EV_HTTP_REQ_BODY_CONT,
|
|
(const unsigned char *) monkey_gz, frag_length);
|
|
|
|
EXPECT_EQ(ret, 0);
|
|
ret = hf_content_uncompress_write(cv_object, NULL, EV_HTTP_REQ_BODY_CONT,
|
|
(const unsigned char *) monkey_gz + frag_length, monkey_gz_len - frag_length);
|
|
|
|
EXPECT_EQ(ret, 1);
|
|
EXPECT_EQ(__ctx->sz_data, monkey_len);
|
|
EXPECT_EQ(memcmp(__ctx->data, monkey, monkey_len), 0);
|
|
}
|
|
|
|
class HttpConvertCompress : public ::testing::TestWithParam<unsigned int>
|
|
{
|
|
protected:
|
|
void SetUp() override
|
|
{
|
|
cv_compress_object = hf_content_compress_create(encode);
|
|
cv_uncompress_object = hf_content_uncompress_create(encode, __gzip_uncompress_callback, &uncompress_buf);
|
|
ASSERT_TRUE(cv_compress_object != NULL);
|
|
}
|
|
|
|
void TearDown() override
|
|
{
|
|
hf_content_compress_destroy(cv_compress_object);
|
|
evbuffer_free(buf);
|
|
}
|
|
|
|
protected:
|
|
unsigned int encode = GetParam();
|
|
struct hf_content_compress * cv_compress_object{};
|
|
struct hf_content_uncompress * cv_uncompress_object{};
|
|
struct evbuffer * buf{evbuffer_new()};
|
|
std::vector<char> uncompress_buf;
|
|
|
|
protected:
|
|
static int __gzip_uncompress_callback(struct http_half_private * hf_private,
|
|
tfe_http_event ev, const unsigned char * data, size_t len, void * user)
|
|
{
|
|
auto * __uncompress_buf = static_cast<std::vector<char> *>(user);
|
|
__uncompress_buf->insert(__uncompress_buf->end(), data, data + len);
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
TEST_P(HttpConvertCompress, MonkeyToGzip)
|
|
{
|
|
int ret = hf_content_compress_write(cv_compress_object, monkey, sizeof(monkey), buf, 1);
|
|
ASSERT_EQ(ret, 0);
|
|
|
|
unsigned char * __raw_buf_ptr = evbuffer_pullup(buf, -1);
|
|
size_t __raw_buf_length = evbuffer_get_length(buf);
|
|
|
|
ret = hf_content_uncompress_write(cv_uncompress_object, NULL, EV_HTTP_REQ_BODY_CONT,
|
|
__raw_buf_ptr, __raw_buf_length);
|
|
|
|
ASSERT_TRUE(__raw_buf_ptr != NULL);
|
|
ASSERT_EQ(ret, 1);
|
|
EXPECT_EQ(uncompress_buf.size(), sizeof(monkey));
|
|
EXPECT_EQ(memcmp(uncompress_buf.data(), monkey, sizeof(monkey)), 0);
|
|
}
|
|
|
|
TEST_P(HttpConvertCompress, MonkeyToGzipStream)
|
|
{
|
|
unsigned frag_length = sizeof(monkey) / 2;
|
|
|
|
/* First frag */
|
|
int ret = hf_content_compress_write(cv_compress_object, monkey, frag_length, buf, 0);
|
|
ASSERT_EQ(ret, 0);
|
|
|
|
/* Last frag */
|
|
ret = hf_content_compress_write(cv_compress_object, monkey + frag_length, sizeof(monkey) - frag_length, buf, 1);
|
|
ASSERT_EQ(ret, 0);
|
|
|
|
unsigned char * __raw_buf_ptr = evbuffer_pullup(buf, -1);
|
|
size_t __raw_buf_length = evbuffer_get_length(buf);
|
|
|
|
ret = hf_content_uncompress_write(cv_uncompress_object, NULL, EV_HTTP_REQ_BODY_CONT,
|
|
__raw_buf_ptr, __raw_buf_length);
|
|
|
|
ASSERT_TRUE(__raw_buf_ptr != NULL);
|
|
ASSERT_EQ(ret, 1);
|
|
EXPECT_EQ(uncompress_buf.size(), sizeof(monkey));
|
|
EXPECT_EQ(memcmp(uncompress_buf.data(), monkey, sizeof(monkey)), 0);
|
|
}
|
|
|
|
TEST_P(HttpConvertCompress, MonkeyToGzipStreamWithNullEnd)
|
|
{
|
|
unsigned frag_length = sizeof(monkey) / 2;
|
|
|
|
/* First frag */
|
|
int ret = hf_content_compress_write(cv_compress_object, monkey, frag_length, buf, 0);
|
|
ASSERT_EQ(ret, 0);
|
|
|
|
/* Last frag */
|
|
ret = hf_content_compress_write(cv_compress_object, monkey + frag_length, sizeof(monkey) - frag_length, buf, 0);
|
|
ASSERT_EQ(ret, 0);
|
|
|
|
/* End frag */
|
|
ret = hf_content_compress_write(cv_compress_object, NULL, 0, buf, 1);
|
|
ASSERT_EQ(ret, 0);
|
|
|
|
unsigned char * __raw_buf_ptr = evbuffer_pullup(buf, -1);
|
|
size_t __raw_buf_length = evbuffer_get_length(buf);
|
|
|
|
ret = hf_content_uncompress_write(cv_uncompress_object, NULL, EV_HTTP_REQ_BODY_CONT,
|
|
__raw_buf_ptr, __raw_buf_length);
|
|
|
|
ASSERT_TRUE(__raw_buf_ptr != NULL);
|
|
ASSERT_EQ(ret, 1);
|
|
EXPECT_EQ(uncompress_buf.size(), sizeof(monkey));
|
|
EXPECT_EQ(memcmp(uncompress_buf.data(), monkey, sizeof(monkey)), 0);
|
|
}
|
|
|
|
INSTANTIATE_TEST_CASE_P(HttpConvertCompressGroup, HttpConvertCompress,
|
|
::testing::Values(HTTP_ACCEPT_ENCODING_GZIP, HTTP_ACCEPT_ENCODING_DEFLATE, HTTP_ACCEPT_ENCODING_BR));
|
|
|
|
void tfe_stream_write_access_log(const struct tfe_stream * stream, int level, const char * fmt, ...)
|
|
{
|
|
return;
|
|
}
|
|
|
|
void tfe_stream_resume(const struct tfe_stream * stream)
|
|
{
|
|
return;
|
|
}
|
|
|
|
void tfe_stream_suspend(const struct tfe_stream * stream, enum tfe_conn_dir by)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int tfe_stream_write(const struct tfe_stream * stream, enum tfe_conn_dir dir, const unsigned char * data, size_t size)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int tfe_stream_write_frag(struct tfe_stream_write_ctx * w_ctx, const unsigned char * data, size_t size)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int tfe_stream_action_set_opt(const struct tfe_stream * stream, enum tfe_stream_action_opt type,
|
|
void * value, size_t size)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
struct tfe_stream_write_ctx * tfe_stream_write_frag_start(const struct tfe_stream * stream, enum tfe_conn_dir dir)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
struct event_base * tfe_proxy_get_work_thread_evbase(unsigned int thread_id)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
struct event_base * tfe_proxy_get_gc_evbase(void)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void tfe_stream_write_frag_end(struct tfe_stream_write_ctx * w_ctx)
|
|
{
|
|
return;
|
|
}
|
|
|
|
void tfe_stream_detach(const struct tfe_stream * stream)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int tfe_stream_preempt(const struct tfe_stream * stream)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
unsigned int tfe_proxy_get_work_thread_count()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void tfe_stream_kill(const struct tfe_stream * stream)
|
|
{}
|
|
|
|
const char * tfe_version()
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
int main(int argc, char ** argv)
|
|
{
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|