17 using std::unique_ptr;
34 unique_ptr<IOBuf> makePost(
35 const map<string, string>& simpleFields,
36 const map<
string, pair<string, string>>& explicitFiles,
37 const map<
string, pair<string, size_t>>& randomFiles,
38 const string optExpHeaderSeqEnding =
"") {
40 for (
const auto& kv : simpleFields) {
42 result.
append(kTestBoundary);
43 result.
append(
"\r\nContent-Disposition: form-data; name=\"");
45 result.
append(
"\"\r\n\r\n");
49 for (
const auto& kv: explicitFiles) {
51 result.
append(kTestBoundary);
52 result.
append(
"\r\nContent-Disposition: form-data; name=\"");
53 result.
append(kv.first +
"\"");
54 auto& file = kv.second;
55 if (!file.first.empty()) {
56 result.
append(
"; filename=\"" + file.first +
"\"");
60 "Content-Type: text/plain\r\n" 65 for (
const auto& kv: randomFiles) {
67 result.
append(kTestBoundary);
68 result.
append(
"\r\nContent-Disposition: form-data; name=\"");
69 result.
append(kv.first +
"\"");
70 auto& file = kv.second;
71 if (!file.first.empty()) {
72 result.
append(
"; filename=\"" + file.first +
"\"");
76 "Content-Type: text/plain\r\n" 82 result.
append(kTestBoundary);
83 result.
append(optExpHeaderSeqEnding);
95 std::shared_ptr<HTTPMessage> msg,
98 std::unique_ptr<HTTPMessage> msg,
100 std::shared_ptr<HTTPMessage> sh_msg(msg.release());
101 return onFieldStartImpl(name, filename, sh_msg, bytesProcessed);
104 std::unique_ptr<HTTPMessage> msg,
106 return onFieldStartImpl(name, filename.
value_or(
""),
std::move(msg), bytesProcessed);
111 std::shared_ptr<IOBuf> sh_data(data.release());
112 return onFieldData(sh_data, bytesProcessed);
126 void parse(unique_ptr<IOBuf> input,
size_t chunkSize = 0) {
127 IOBufQueue ibuf{IOBufQueue::cacheChainLength()};
129 if (chunkSize == 0) {
130 chunkSize = ibuf.chainLength();
132 unique_ptr<IOBuf> rem;
133 while (!ibuf.empty()) {
134 auto chunk = ibuf.split(
std::min(chunkSize, ibuf.chainLength()));
158 RFC1867Base::SetUp();
171 size_t fileLength = 0;
172 IOBufQueue parsedData{IOBufQueue::cacheChainLength()};
175 .WillRepeatedly(
Return(0));
177 .WillRepeatedly(
Invoke([&] (std::shared_ptr<IOBuf> data,
uint64_t) {
178 fileLength += data->computeChainDataLength();
179 parsedData.append(data->clone());
184 .WillRepeatedly(
Return());
185 parse(data->clone(), splitSize);
186 auto parsedDataBuf = parsedData.move();
187 if (fileLength > 0) {
190 parsedDataBuf->coalesce();
192 CHECK_EQ(fileLength, fileSize);
196 size_t fileSize = 17;
197 auto data = makePost(
198 {{
"foo",
"bar"}, {
"jojo",
"binky"}}, {}, {{
"file1", {
"", fileSize}}});
203 for (
size_t i = 1;
i < 500;
i++) {
204 size_t fileSize = 1000 +
i;
205 auto data = makePost(
206 {{
"foo",
"bar"}, {
"jojo",
"binky"}}, {}, {{
"file1", {
"", fileSize}}});
212 for (
size_t i = 1;
i < 500;
i++) {
213 size_t fileSize = 1000 +
i;
214 auto data = makePost({{
"foo",
"bar"}, {
"jojo",
"binky"}},
216 {{
"file1", {
"file1.txt", fileSize}}});
225 auto headerEndingSeq =
"--" +
string(numCRs,
'\r') +
"\n";
227 auto data = makePost({{
"foo",
"bar"}, {
"jojo",
"binky"}},
229 {{
"file1", {
"", fileSize}}},
238 RFC1867Base::SetUp();
244 for (
size_t i = 1;
i < GetParam().size();
i++) {
245 auto data = makePost({{
"foo",
"bar"}, {
"jojo",
"binky"}},
246 {{
"file1", {
"dummy file name", GetParam()}}},
257 string(
"zyx\r\nwvu", 8),
259 string(
"\rzyxwvut", 8),
261 string(
"zyxwvut\r", 8),
263 string(
"\nzyxwvut", 8),
265 string(
"zyxwvut\n", 8),
267 string(
"\r\n\r\n\r\n\r\n", 8),
269 string(
"\r\r\r\r\r\r\r\r", 8)
size_t parse(const char *buf, size_t len)
INSTANTIATE_TEST_CASE_P(, CodeLocationForTESTP, Values(0))
#define MOCK_METHOD4(m,...)
std::unique_ptr< folly::IOBuf > makeBuf(uint32_t size)
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
TEST_F(TestInfoTest, Names)
constexpr detail::Map< Move > move
void parse(unique_ptr< IOBuf > input, size_t chunkSize=0)
std::unique_ptr< folly::IOBuf > move()
std::unique_ptr< Codec > codec_
TEST_P(CodeLocationForTESTP, Verify)
int onFieldStart(const string &name, folly::Optional< std::string > filename, std::unique_ptr< HTTPMessage > msg, uint64_t bytesProcessed) override
StrictMock< Mock1867Callback > callback_
int onFieldData(std::unique_ptr< folly::IOBuf > data, uint64_t bytesProcessed) override
constexpr auto size(C const &c) -> decltype(c.size())
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
Encoder::MutableCompressedList list
int onFieldStartImpl(const string &name, const std::string &filename, std::unique_ptr< HTTPMessage > msg, uint64_t bytesProcessed)
FOLLY_CPP14_CONSTEXPR Value value_or(U &&dflt) const &
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
std::unique_ptr< IOBuf > copyBuffer(const folly::IOBuf &buf)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
folly::Function< void()> callback_
#define MOCK_METHOD2(m,...)
static constexpr uint64_t data[1]
internal::ReturnAction< R > Return(R value)
#define MOCK_METHOD0(m,...)