Add multipart/form-data tests.
This commit is contained in:
parent
ae9c80f6c7
commit
794f352ed7
@ -464,6 +464,67 @@ TEST(Http, gzip_bomb_with_limit) {
|
||||
ASSERT_TRUE(ok);
|
||||
}
|
||||
|
||||
TEST(Http, partial_form_data) {
|
||||
td::ChainBufferWriter input_writer;
|
||||
auto input = input_writer.extract_reader();
|
||||
|
||||
td::HttpReader reader;
|
||||
reader.init(&input, 0, 0);
|
||||
|
||||
auto query =
|
||||
make_http_query("------abcd\r\nCo", "Content-Type: multipart/form-data; boundary=----abcd", false, false);
|
||||
input_writer.append(query);
|
||||
input.sync_with_writer();
|
||||
|
||||
td::HttpQuery q;
|
||||
auto r_state = reader.read_next(&q);
|
||||
ASSERT_TRUE(r_state.is_error());
|
||||
ASSERT_EQ(400, r_state.error().code());
|
||||
}
|
||||
|
||||
TEST(Http, form_data) {
|
||||
td::ChainBufferWriter input_writer;
|
||||
auto input = input_writer.extract_reader();
|
||||
|
||||
td::HttpReader reader;
|
||||
reader.init(&input, 0, 1);
|
||||
|
||||
auto query = make_http_query(
|
||||
"------abcd\r\n"
|
||||
"Content-Disposition: form-data; name=\"text\"\r\n"
|
||||
"\r\n"
|
||||
"some text\r\n"
|
||||
"------abcd\r\n"
|
||||
"Content-Disposition: form-data; name=\"text2\"\r\n"
|
||||
"\r\n"
|
||||
"some text\r\n"
|
||||
"more text\r\n"
|
||||
"------abcd\r\n"
|
||||
"Content-Disposition: form-data; name=\"file\"; filename=\"file.txt\"\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"\r\n"
|
||||
"File content\r\n"
|
||||
"------abcd--",
|
||||
"Content-Type: multipart/form-data; boundary=----abcd", false, false);
|
||||
input_writer.append(query);
|
||||
input.sync_with_writer();
|
||||
|
||||
td::HttpQuery q;
|
||||
auto r_state = reader.read_next(&q);
|
||||
ASSERT_TRUE(r_state.is_ok());
|
||||
ASSERT_EQ(2u, q.args_.size());
|
||||
ASSERT_EQ("text", q.args_[0].first);
|
||||
ASSERT_EQ("some text", q.args_[0].second);
|
||||
ASSERT_EQ("text2", q.args_[1].first);
|
||||
ASSERT_EQ("some text\r\nmore text", q.args_[1].second);
|
||||
ASSERT_EQ(1u, q.files_.size());
|
||||
ASSERT_EQ("file.txt", q.files_[0].name);
|
||||
ASSERT_EQ("file", q.files_[0].field_name);
|
||||
ASSERT_EQ("text/plain", q.files_[0].content_type);
|
||||
ASSERT_EQ(12, q.files_[0].size);
|
||||
ASSERT_TRUE(!q.files_[0].temp_file_name.empty());
|
||||
}
|
||||
|
||||
#if TD_DARWIN_WATCH_OS
|
||||
struct Baton {
|
||||
std::mutex mutex;
|
||||
|
Loading…
x
Reference in New Issue
Block a user