OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 builder.SetFormData(kKey2, kValue2); | 64 builder.SetFormData(kKey2, kValue2); |
65 | 65 |
66 const char kKey3[] = "key-three"; | 66 const char kKey3[] = "key-three"; |
67 const char kValue3[] = "More tests"; | 67 const char kValue3[] = "More tests"; |
68 builder.SetFormData(kKey3, kValue3); | 68 builder.SetFormData(kKey3, kValue3); |
69 | 69 |
70 std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); | 70 std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); |
71 ASSERT_TRUE(body.get()); | 71 ASSERT_TRUE(body.get()); |
72 std::string contents = ReadStreamToString(body.get()); | 72 std::string contents = ReadStreamToString(body.get()); |
73 auto lines = SplitCRLF(contents); | 73 auto lines = SplitCRLF(contents); |
74 ASSERT_EQ(13u, lines.size()); | |
75 auto lines_it = lines.begin(); | 74 auto lines_it = lines.begin(); |
76 | 75 |
77 // The first line is the boundary. All subsequent boundaries must match this. | 76 // The first line is the boundary. All subsequent boundaries must match this. |
78 const std::string& boundary = *lines_it++; | 77 const std::string& boundary = *lines_it++; |
79 EXPECT_GE(boundary.length(), 1u); | 78 EXPECT_GE(boundary.length(), 1u); |
80 EXPECT_LE(boundary.length(), 70u); | 79 EXPECT_LE(boundary.length(), 70u); |
81 | 80 |
82 EXPECT_EQ("Content-Disposition: form-data; name=\"key-three\"", *lines_it++); | 81 EXPECT_EQ("Content-Disposition: form-data; name=\"key-three\"", *lines_it++); |
83 EXPECT_EQ("", *lines_it++); | 82 EXPECT_EQ("", *lines_it++); |
84 EXPECT_EQ(kValue3, *lines_it++); | 83 EXPECT_EQ(kValue3, *lines_it++); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 157 |
159 TEST(HTTPMultipartBuilder, OverwriteFormDataWithEscapedKey) { | 158 TEST(HTTPMultipartBuilder, OverwriteFormDataWithEscapedKey) { |
160 HTTPMultipartBuilder builder; | 159 HTTPMultipartBuilder builder; |
161 const char kKey[] = "a 100% \"silly\"\r\ntest"; | 160 const char kKey[] = "a 100% \"silly\"\r\ntest"; |
162 builder.SetFormData(kKey, "some dummy value"); | 161 builder.SetFormData(kKey, "some dummy value"); |
163 builder.SetFormData(kKey, "overwrite"); | 162 builder.SetFormData(kKey, "overwrite"); |
164 std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); | 163 std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); |
165 ASSERT_TRUE(body.get()); | 164 ASSERT_TRUE(body.get()); |
166 std::string contents = ReadStreamToString(body.get()); | 165 std::string contents = ReadStreamToString(body.get()); |
167 auto lines = SplitCRLF(contents); | 166 auto lines = SplitCRLF(contents); |
168 ASSERT_EQ(5u, lines.size()); | |
169 auto lines_it = lines.begin(); | 167 auto lines_it = lines.begin(); |
170 | 168 |
171 const std::string& boundary = *lines_it++; | 169 const std::string& boundary = *lines_it++; |
172 EXPECT_GE(boundary.length(), 1u); | 170 EXPECT_GE(boundary.length(), 1u); |
173 EXPECT_LE(boundary.length(), 70u); | 171 EXPECT_LE(boundary.length(), 70u); |
174 | 172 |
175 EXPECT_EQ( | 173 EXPECT_EQ( |
176 "Content-Disposition: form-data; name=\"a 100%25 %22silly%22%0d%0atest\"", | 174 "Content-Disposition: form-data; name=\"a 100%25 %22silly%22%0d%0atest\"", |
177 *lines_it++); | 175 *lines_it++); |
178 EXPECT_EQ("", *lines_it++); | 176 EXPECT_EQ("", *lines_it++); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 "minidump.dmp", | 246 "minidump.dmp", |
249 ascii_http_body_path, | 247 ascii_http_body_path, |
250 ""); | 248 ""); |
251 const char kValue2[] = "this is not a file"; | 249 const char kValue2[] = "this is not a file"; |
252 builder.SetFormData("minidump", kValue2); | 250 builder.SetFormData("minidump", kValue2); |
253 | 251 |
254 std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); | 252 std::unique_ptr<HTTPBodyStream> body(builder.GetBodyStream()); |
255 ASSERT_TRUE(body.get()); | 253 ASSERT_TRUE(body.get()); |
256 std::string contents = ReadStreamToString(body.get()); | 254 std::string contents = ReadStreamToString(body.get()); |
257 auto lines = SplitCRLF(contents); | 255 auto lines = SplitCRLF(contents); |
258 ASSERT_EQ(9u, lines.size()); | |
259 auto lines_it = lines.begin(); | 256 auto lines_it = lines.begin(); |
260 | 257 |
261 const std::string& boundary = *lines_it++; | 258 const std::string& boundary = *lines_it++; |
262 EXPECT_GE(boundary.length(), 1u); | 259 EXPECT_GE(boundary.length(), 1u); |
263 EXPECT_LE(boundary.length(), 70u); | 260 EXPECT_LE(boundary.length(), 70u); |
264 | 261 |
265 EXPECT_EQ("Content-Disposition: form-data; name=\"minidump\"", *lines_it++); | 262 EXPECT_EQ("Content-Disposition: form-data; name=\"minidump\"", *lines_it++); |
266 EXPECT_EQ("", *lines_it++); | 263 EXPECT_EQ("", *lines_it++); |
267 EXPECT_EQ(kValue2, *lines_it++); | 264 EXPECT_EQ(kValue2, *lines_it++); |
268 | 265 |
(...skipping 20 matching lines...) Expand all Loading... |
289 builder.SetFileAttachment("", "", base::FilePath(), "<>"), ""); | 286 builder.SetFileAttachment("", "", base::FilePath(), "<>"), ""); |
290 // Invalid but safe: | 287 // Invalid but safe: |
291 builder.SetFileAttachment("", "", base::FilePath(), "0/totally/-invalid.pdf"); | 288 builder.SetFileAttachment("", "", base::FilePath(), "0/totally/-invalid.pdf"); |
292 // Valid and safe: | 289 // Valid and safe: |
293 builder.SetFileAttachment("", "", base::FilePath(), "application/xml+xhtml"); | 290 builder.SetFileAttachment("", "", base::FilePath(), "application/xml+xhtml"); |
294 } | 291 } |
295 | 292 |
296 } // namespace | 293 } // namespace |
297 } // namespace test | 294 } // namespace test |
298 } // namespace crashpad | 295 } // namespace crashpad |
OLD | NEW |