Add HTTP-gzip test.
This commit is contained in:
parent
302e5940d4
commit
efd7838c68
@ -67,6 +67,14 @@ static const char gzip_bomb_arr[] =
|
||||
const char *gzip_bomb = gzip_bomb_arr;
|
||||
const size_t gzip_bomb_size = sizeof(gzip_bomb_arr) - 1;
|
||||
|
||||
static const char gzip_arr[] =
|
||||
"eJztxT1LQmEAgNGXMJEIukNI0pDS0hAUSiCa4uZfELqgQwUFuQjXhkDFisrARajBocmISFA0GstBg4owopuIgdAiKE0SfkSBf6HB5TnLmYnpxMBv89"
|
||||
"ExVnBN7pWvll_ePZqMpPo2Fg6dT-GQdfbA_zH_eftzVE16g8l9Ze7cP33ZTn2dlPP9XEfpXbyeqtnrm50HS7G0dbzyZpPNSkW_"
|
||||
"tLmeCCT0pbrzO21otbfjqqyNuIySTjNCRERERERERERERERERERERERERERERERERERE_2k3ZA8YhRBhcb_"
|
||||
"2XHN7zoR5alwbvfMtEhERERERERERERERERER0ZCqTzREVzKNyvlV8Qf1dzn-";
|
||||
const char *gzip = gzip_arr;
|
||||
const size_t gzip_size = sizeof(gzip_arr) - 1;
|
||||
|
||||
static const char sqlite_sample_db_v3_arr[] =
|
||||
"olFZ1MdfY0Abj+LtR9ft6DTZgEHW7/"
|
||||
"z7yAhC07NKr7pBAHWkbQyMPtyVSIW7PLdVaQIHYwLgd7ovQSzD7eTINxZh6Nxpwa8HTynvjhHIdQhtysRL9m3mTEj4mbjU48zq+jcFdsnzG+"
|
||||
|
@ -14,6 +14,9 @@ extern const size_t thumbnail_size;
|
||||
extern const char *gzip_bomb;
|
||||
extern const size_t gzip_bomb_size;
|
||||
|
||||
extern const char *gzip;
|
||||
extern const size_t gzip_size;
|
||||
|
||||
extern const char *sqlite_sample_db_v3;
|
||||
extern const size_t sqlite_sample_db_v3_size;
|
||||
|
||||
|
@ -68,11 +68,14 @@ static string gen_http_content() {
|
||||
return rand_string(std::numeric_limits<char>::min(), std::numeric_limits<char>::max(), len);
|
||||
}
|
||||
|
||||
static string make_http_query(string content, bool is_chunked, bool is_gzip, double gzip_k = 5,
|
||||
static string make_http_query(string content, bool is_json, bool is_chunked, bool is_gzip, double gzip_k = 5,
|
||||
string zip_override = "") {
|
||||
HttpHeaderCreator hc;
|
||||
hc.init_post("/");
|
||||
hc.add_header("jfkdlsahhjk", rand_string('a', 'z', Random::fast(1, 2000)));
|
||||
if (is_json) {
|
||||
hc.add_header("content-type", "application/json");
|
||||
}
|
||||
if (is_gzip) {
|
||||
BufferSlice zip;
|
||||
if (zip_override.empty()) {
|
||||
@ -102,7 +105,7 @@ static string make_http_query(string content, bool is_chunked, bool is_gzip, dou
|
||||
static string rand_http_query(string content) {
|
||||
bool is_chunked = Random::fast_bool();
|
||||
bool is_gzip = Random::fast_bool();
|
||||
return make_http_query(std::move(content), is_chunked, is_gzip);
|
||||
return make_http_query(std::move(content), false, is_chunked, is_gzip);
|
||||
}
|
||||
|
||||
static string join(const std::vector<string> &v) {
|
||||
@ -216,7 +219,7 @@ TEST(Http, gzip_bomb) {
|
||||
auto gzip_bomb_str =
|
||||
gzdecode(gzdecode(base64url_decode(Slice(gzip_bomb, gzip_bomb_size)).ok()).as_slice()).as_slice().str();
|
||||
|
||||
auto query = make_http_query("", false, true, 0.01, gzip_bomb_str);
|
||||
auto query = make_http_query("", false, false, true, 0.01, gzip_bomb_str);
|
||||
auto parts = rand_split(query);
|
||||
td::ChainBufferWriter input_writer;
|
||||
auto input = input_writer.extract_reader();
|
||||
@ -235,6 +238,26 @@ TEST(Http, gzip_bomb) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Http, gzip) {
|
||||
return;
|
||||
auto gzip_str = gzdecode(base64url_decode(Slice(gzip, gzip_size)).ok()).as_slice().str();
|
||||
|
||||
td::ChainBufferWriter input_writer;
|
||||
auto input = input_writer.extract_reader();
|
||||
|
||||
HttpReader reader;
|
||||
reader.init(&input, 0, 0);
|
||||
|
||||
auto query = make_http_query("", true, false, true, 0.01, gzip_str);
|
||||
input_writer.append(query);
|
||||
input.sync_with_writer();
|
||||
|
||||
HttpQuery q;
|
||||
auto r_state = reader.read_next(&q);
|
||||
ASSERT_TRUE(r_state.is_error());
|
||||
ASSERT_EQ(413, r_state.error().code());
|
||||
}
|
||||
|
||||
TEST(Http, aes_ctr_encode_decode_flow) {
|
||||
auto str = rand_string('a', 'z', 1000000);
|
||||
auto parts = rand_split(str);
|
||||
@ -418,7 +441,7 @@ TEST(Http, gzip_bomb_with_limit) {
|
||||
gzip_bomb_str = sink.result()->move_as_buffer_slice().as_slice().str();
|
||||
}
|
||||
|
||||
auto query = make_http_query("", false, true, 0.01, gzip_bomb_str);
|
||||
auto query = make_http_query("", false, false, true, 0.01, gzip_bomb_str);
|
||||
auto parts = rand_split(query);
|
||||
td::ChainBufferWriter input_writer;
|
||||
auto input = input_writer.extract_reader();
|
||||
|
Loading…
Reference in New Issue
Block a user