Debian Codegraph @

crt/aws-c-s3/tests/s3_request_messages_tests.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include "aws/s3/private/s3_client_impl.h"
7 #include "aws/s3/private/s3_meta_request_impl.h"
8 #include "aws/s3/private/s3_request_messages.h"
9 #include "aws/s3/private/s3_util.h"
10 #include "s3_tester.h"
11 #include <aws/common/atomics.h>
12 #include <aws/common/byte_buf.h>
13 #include <aws/common/clock.h>
14 #include <aws/common/common.h>
15 #include <aws/common/ref_count.h>
16 #include <aws/common/xml_parser.h>
17 #include <aws/http/request_response.h>
18 #include <aws/io/stream.h>
19 #include <aws/io/tls_channel_handler.h>
20 #include <aws/testing/aws_test_harness.h>
21 #include <inttypes.h>
22
23 static const struct aws_http_header get_object_test_headers[] = {
24 {
25 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Host"),
26 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("HostValue"),
27 },
28 {
29 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("If-Match"),
30 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("If-MatchValue"),
31 },
32 {
33 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("If-Modified-Since"),
34 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("If-Modified-SinceValue"),
35 },
36 {
37 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("If-None-Match"),
38 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("If-None-MatchValue"),
39 },
40 {
41 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Range"),
42 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("RangeValue"),
43 },
44 {
45 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-algorithm"),
46 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-algorithmValue"),
47 },
48 {
49 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-key"),
50 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-keyValue"),
51 },
52 {
53 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-key-MD5"),
54 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-key-MD5Value"),
55 },
56 {
57 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-request-payer"),
58 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-request-payerValue"),
59 },
60 {
61 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-expected-bucket-owner"),
62 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-expected-bucket-ownerValue"),
63 },
64 };
65
66 static const struct aws_http_header s_put_object_test_headers[] = {
67 {
68 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-acl"),
69 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ACLValue"),
70 },
71 {
72 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Cache-Control"),
73 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("CacheControlValue"),
74 },
75 {
76 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Disposition"),
77 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ContentDispositionValue"),
78 },
79 {
80 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Encoding"),
81 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ContentEncodingValue"),
82 },
83 {
84 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Language"),
85 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ContentLanguageValue"),
86 },
87 {
88 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Length"),
89 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ContentLengthValue"),
90 },
91 {
92 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-MD5"),
93 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ContentMD5Value"),
94 },
95 {
96 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Type"),
97 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ContentTypeValue"),
98 },
99 {
100 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Expires"),
101 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ExpiresValue"),
102 },
103 {
104 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-grant-full-control"),
105 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("GrantFullControlValue"),
106 },
107 {
108 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-grant-read"),
109 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("GrantReadValue"),
110 },
111 {
112 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-grant-read-acp"),
113 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("GrantReadACPValue"),
114 },
115 {
116 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-grant-write-acp"),
117 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("GrantWriteACPValue"),
118 },
119 {
120 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption"),
121 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ServerSideEncryptionValue"),
122 },
123 {
124 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-storage-class"),
125 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("StorageClassValue"),
126 },
127 {
128 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-website-redirect-location"),
129 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("WebsiteRedirectLocationValue"),
130 },
131 {
132 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-algorithm"),
133 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("SSECustomerAlgorithmValue"),
134 },
135 {
136 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-key"),
137 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("SSECustomerKeyValue"),
138 },
139 {
140 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-customer-key-MD5"),
141 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("SSECustomerKeyMD5Value"),
142 },
143 {
144 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-aws-kms-key-id"),
145 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("SSEKMSKeyIdValue"),
146 },
147 {
148 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-context"),
149 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("SSEKMSEncryptionContextValue"),
150 },
151 {
152 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-server-side-encryption-bucket-key-enabled"),
153 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("BucketKeyEnabledValue"),
154 },
155 {
156 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-request-payer"),
157 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("RequestPayerValue"),
158 },
159 {
160 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-tagging"),
161 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("TaggingValue"),
162 },
163 {
164 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-object-lock-mode"),
165 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ObjectLockModeValue"),
166 },
167 {
168 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-object-lock-retain-until-date"),
169 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ObjectLockRetainUntilDateValue"),
170 },
171 {
172 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-object-lock-legal-hold"),
173 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ObjectLockLegalHoldStatusValue"),
174 },
175 {
176 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-expected-bucket-owner"),
177 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ExpectedBucketOwnerValue"),
178 },
179 {
180 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-checksum-crc32"),
181 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("AAAAAA=="),
182 },
183 };
184
185 static int s_fill_byte_buf(struct aws_byte_buf *buffer, struct aws_allocator *allocator, size_t buffer_size) {
186 ASSERT_TRUE(buffer != NULL);
187 ASSERT_TRUE(allocator != NULL);
188 ASSERT_TRUE(buffer_size > 0);
189
190 ASSERT_SUCCESS(aws_byte_buf_init(buffer, allocator, buffer_size));
191
192 srand(0);
193
194 for (size_t i = 0; i < buffer_size; ++i) {
195 const char single_char = (char)(rand() % (int)('z' - 'a') + (int)'a');
196
197 struct aws_byte_cursor single_char_cursor = {
198 .ptr = (uint8_t *)&single_char,
199 .len = 1,
200 };
201
202 ASSERT_SUCCESS(aws_byte_buf_append(buffer, &single_char_cursor));
203 }
204
205 return AWS_OP_SUCCESS;
206 }
207
208 static const struct aws_byte_cursor s_x_amz_checksum_prefix = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-checksum-");
209
210 static int s_test_http_headers_match(
211 struct aws_allocator *allocator,
212 const struct aws_http_message *message0,
213 const struct aws_http_message *message1,
214
215 /* Headers that we know are in message0, but should NOT be in message1 */
216 const struct aws_byte_cursor *excluded_message0_headers,
217 size_t excluded_message0_headers_count,
218
219 /* Headers in message1 that are okay to be in message1 even if they are in the excluded list or are not in
220 message0.*/
221 const struct aws_byte_cursor *message1_header_exceptions,
222 size_t message1_header_exceptions_count,
223 bool should_exclude_checksum) {
224 ASSERT_TRUE(message0 != NULL);
225 ASSERT_TRUE(message1 != NULL);
226 ASSERT_TRUE(excluded_message0_headers != NULL || excluded_message0_headers_count == 0);
227 ASSERT_TRUE(message1_header_exceptions != NULL || message1_header_exceptions_count == 0);
228
229 const struct aws_http_headers *message0_headers = aws_http_message_get_const_headers(message0);
230 ASSERT_TRUE(message0_headers != NULL);
231
232 const struct aws_http_headers *message1_headers = aws_http_message_get_const_headers(message1);
233 ASSERT_TRUE(message1_headers != NULL);
234
235 struct aws_http_headers *expected_message0_headers = aws_http_headers_new(allocator);
236
237 /* Copy message1 headers to expected_message0_headers. With upcoming adds/removes, it should transform back into
238 * message0.
239 */
240 for (size_t i = 0; i < aws_http_headers_count(message1_headers); ++i) {
241 struct aws_http_header message1_header;
242 AWS_ZERO_STRUCT(message1_header);
243 ASSERT_SUCCESS(aws_http_headers_get_index(message1_headers, i, &message1_header));
244 ASSERT_SUCCESS(aws_http_headers_add(expected_message0_headers, message1_header.name, message1_header.value));
245 }
246
247 /* Go through all of the headers that were originally removed from message1 after it was copied from message0. */
248 for (size_t i = 0; i < excluded_message0_headers_count; ++i) {
249 const struct aws_byte_cursor *excluded_header_name = &excluded_message0_headers[i];
250
251 bool header_existence_is_valid = false;
252
253 /* If the header is in the exception list, it's okay for message1 to have. (It may have been re-added.) */
254 for (size_t j = 0; j < message1_header_exceptions_count; ++j) {
255 if (aws_byte_cursor_eq(excluded_header_name, &message1_header_exceptions[j])) {
256 header_existence_is_valid = true;
257 break;
258 }
259 }
260
261 /* Try to get the header from message1. */
262 struct aws_byte_cursor message1_header_value;
263 AWS_ZERO_STRUCT(message1_header_value);
264 int result = aws_http_headers_get(message1_headers, *excluded_header_name, &message1_header_value);
265
266 if (header_existence_is_valid) {
267
268 /* If this header is allowed to exist in message1, then we don't need to assert on its existence or
269 * non-existence. But we do want to erase it from the expected_message0_headers, since its value may be
270 * different from that in message0. */
271 if (result == AWS_OP_SUCCESS) {
272 ASSERT_SUCCESS(aws_http_headers_erase(expected_message0_headers, *excluded_header_name));
273 }
274
275 } else {
276 /* In this case, message1 should not have the header. */
277 ASSERT_TRUE(result == AWS_OP_ERR && aws_last_error() == AWS_ERROR_HTTP_HEADER_NOT_FOUND);
278 }
279
280 /* At this point, expected_message0_headers should not have the excluded header in it. Add a copy of the header
281 * from message0 to expected_message0_headers to further transform it toward being a copy of message0 headers.
282 */
283 struct aws_byte_cursor message0_header_value;
284 AWS_ZERO_STRUCT(message0_header_value);
285 if (aws_http_headers_get(message0_headers, *excluded_header_name, &message0_header_value) == AWS_OP_SUCCESS) {
286 ASSERT_SUCCESS(
287 aws_http_headers_add(expected_message0_headers, *excluded_header_name, message0_header_value));
288 }
289 }
290
291 if (should_exclude_checksum) {
292 /* Copy any checksum headers if they were on exclude list */
293 for (size_t i = 0; i < aws_http_headers_count(message0_headers); ++i) {
294 struct aws_http_header message0_header;
295 AWS_ZERO_STRUCT(message0_header);
296 ASSERT_SUCCESS(aws_http_headers_get_index(message0_headers, i, &message0_header));
297 if (aws_byte_cursor_starts_with_ignore_case(&message0_header.name, &s_x_amz_checksum_prefix)) {
298 ASSERT_SUCCESS(
299 aws_http_headers_add(expected_message0_headers, message0_header.name, message0_header.value));
300 }
301 }
302 }
303
304 /* message0_headers should now match expected_message0_headers */
305 {
306 ASSERT_TRUE(aws_http_headers_count(message0_headers) == aws_http_headers_count(expected_message0_headers));
307
308 for (size_t i = 0; i < aws_http_headers_count(message0_headers); ++i) {
309 struct aws_http_header message0_header;
310 AWS_ZERO_STRUCT(message0_header);
311 ASSERT_SUCCESS(aws_http_headers_get_index(message0_headers, i, &message0_header));
312
313 struct aws_byte_cursor expected_message0_header_value;
314 AWS_ZERO_STRUCT(expected_message0_header_value);
315 ASSERT_SUCCESS(
316 aws_http_headers_get(expected_message0_headers, message0_header.name, &expected_message0_header_value));
317
318 ASSERT_TRUE(aws_byte_cursor_eq(&message0_header.value, &expected_message0_header_value));
319 }
320 }
321
322 aws_http_headers_release(expected_message0_headers);
323
324 return AWS_OP_SUCCESS;
325 }
326
327 static int s_test_http_messages_match(
328 struct aws_allocator *allocator,
329 const struct aws_http_message *message0,
330 const struct aws_http_message *message1,
331 const struct aws_byte_cursor *excluded_headers,
332 size_t excluded_headers_count,
333 bool should_exclude_checksum) {
334 ASSERT_TRUE(message0 != NULL);
335 ASSERT_TRUE(message1 != NULL);
336 ASSERT_TRUE(excluded_headers != NULL || excluded_headers_count == 0);
337
338 struct aws_byte_cursor request_path;
339 AWS_ZERO_STRUCT(request_path);
340 ASSERT_SUCCESS(aws_http_message_get_request_path(message0, &request_path));
341
342 struct aws_byte_cursor copied_request_path;
343 AWS_ZERO_STRUCT(copied_request_path);
344 ASSERT_SUCCESS(aws_http_message_get_request_path(message1, &copied_request_path));
345
346 ASSERT_TRUE(aws_byte_cursor_eq(&request_path, &copied_request_path));
347
348 struct aws_byte_cursor request_method;
349 AWS_ZERO_STRUCT(request_method);
350 ASSERT_SUCCESS(aws_http_message_get_request_method(message0, &request_method));
351
352 struct aws_byte_cursor copied_request_method;
353 AWS_ZERO_STRUCT(copied_request_method);
354 ASSERT_SUCCESS(aws_http_message_get_request_method(message1, &copied_request_method));
355
356 ASSERT_TRUE(aws_byte_cursor_eq(&request_method, &copied_request_method));
357
358 ASSERT_SUCCESS(s_test_http_headers_match(
359 allocator, message0, message1, excluded_headers, excluded_headers_count, NULL, 0, should_exclude_checksum));
360
361 return AWS_OP_SUCCESS;
362 }
363
364 static struct aws_http_header s_http_header_from_c_str(const char *name, const char *value) {
365 struct aws_http_header header = {
366 .name = aws_byte_cursor_from_c_str(name),
367 .value = aws_byte_cursor_from_c_str(value),
368 };
369 return header;
370 }
371
372 static int s_test_http_message_request_path(
373 struct aws_http_message *message,
374 const struct aws_byte_cursor *request_path) {
375
376 struct aws_byte_cursor message_request_path;
377 AWS_ZERO_STRUCT(message_request_path);
378 ASSERT_SUCCESS(aws_http_message_get_request_path(message, &message_request_path));
379
380 ASSERT_TRUE(aws_byte_cursor_eq(&message_request_path, request_path));
381
382 return AWS_OP_SUCCESS;
383 }
384
385 static int s_test_http_message_request_method(struct aws_http_message *message, const char *method) {
386
387 struct aws_byte_cursor message_request_method;
388 AWS_ZERO_STRUCT(message_request_method);
389 ASSERT_SUCCESS(aws_http_message_get_request_method(message, &message_request_method));
390
391 struct aws_byte_cursor method_cursor = aws_byte_cursor_from_c_str(method);
392
393 ASSERT_TRUE(aws_byte_cursor_eq(&message_request_method, &method_cursor));
394
395 return AWS_OP_SUCCESS;
396 }
397
398 static int s_test_http_message_body_stream(
399 struct aws_allocator *allocator,
400 struct aws_http_message *derived_message,
401 struct aws_byte_buf *expected_stream_contents) {
402 ASSERT_TRUE(derived_message != NULL);
403 ASSERT_TRUE(expected_stream_contents != NULL);
404
405 struct aws_http_headers *headers = aws_http_message_get_headers(derived_message);
406 ASSERT_TRUE(headers != NULL);
407
408 struct aws_input_stream *body_stream = aws_http_message_get_body_stream(derived_message);
409 ASSERT_TRUE(body_stream != NULL);
410
411 /* Check for the content length header. */
412 uint64_t content_length = 0;
413 ASSERT_SUCCESS(aws_s3_tester_get_content_length(headers, &content_length));
414 ASSERT_TRUE(content_length == expected_stream_contents->len);
415
416 /* Check that the stream data is equal to the original buffer data. */
417 struct aws_byte_buf stream_read_buffer;
418 ASSERT_SUCCESS(aws_byte_buf_init(&stream_read_buffer, allocator, expected_stream_contents->len));
419 ASSERT_SUCCESS(aws_input_stream_read(body_stream, &stream_read_buffer));
420 ASSERT_TRUE(aws_byte_buf_eq(expected_stream_contents, &stream_read_buffer));
421 aws_byte_buf_clean_up(&stream_read_buffer);
422
423 /* There should be no data left in the stream. */
424 struct aws_byte_buf stream_overread_buffer;
425 ASSERT_SUCCESS(aws_byte_buf_init(&stream_overread_buffer, allocator, expected_stream_contents->len));
426 ASSERT_SUCCESS(aws_input_stream_read(body_stream, &stream_overread_buffer));
427 ASSERT_TRUE(stream_overread_buffer.len == 0);
428 aws_byte_buf_clean_up(&stream_overread_buffer);
429
430 return AWS_OP_SUCCESS;
431 }
432
433 int s_create_get_object_message(
434 struct aws_allocator *allocator,
435 const struct aws_byte_cursor *path,
436 struct aws_http_message **out_message) {
437 ASSERT_TRUE(out_message != NULL);
438 ASSERT_TRUE(*out_message == NULL);
439
440 struct aws_http_message *message = aws_http_message_new_request(allocator);
441 ASSERT_TRUE(message != NULL);
442
443 ASSERT_SUCCESS(aws_http_message_set_request_path(message, *path));
444 ASSERT_SUCCESS(aws_http_message_set_request_method(message, aws_byte_cursor_from_c_str("GET")));
445
446 for (size_t i = 0; i < AWS_ARRAY_SIZE(get_object_test_headers); ++i) {
447 ASSERT_SUCCESS(aws_http_message_add_header(message, get_object_test_headers[i]));
448 }
449
450 *out_message = message;
451
452 return AWS_OP_SUCCESS;
453 }
454
455 int s_create_put_object_message(
456 struct aws_allocator *allocator,
457 const struct aws_byte_cursor *path,
458 struct aws_http_message **out_message) {
459 ASSERT_TRUE(out_message != NULL);
460 ASSERT_TRUE(*out_message == NULL);
461
462 struct aws_http_message *message = aws_http_message_new_request(allocator);
463 ASSERT_TRUE(message != NULL);
464
465 ASSERT_SUCCESS(aws_http_message_set_request_path(message, *path));
466 ASSERT_SUCCESS(aws_http_message_set_request_method(message, aws_byte_cursor_from_c_str("PUT")));
467
468 for (size_t i = 0; i < AWS_ARRAY_SIZE(s_put_object_test_headers); ++i) {
469 ASSERT_SUCCESS(aws_http_message_add_header(message, s_put_object_test_headers[i]));
470 }
471
472 *out_message = message;
473
474 return AWS_OP_SUCCESS;
475 ;
476 }
477
478 AWS_TEST_CASE(test_s3_copy_http_message, s_test_s3_copy_http_message)
479 static int s_test_s3_copy_http_message(struct aws_allocator *allocator, void *ctx) {
480 (void)ctx;
481
482 const struct aws_byte_cursor request_method = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("RequestMethod");
483 const struct aws_byte_cursor request_path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("RequestPath");
484
485 const struct aws_http_header original_headers[] = {
486 s_http_header_from_c_str("IncludedHeader", "IncludedHeaderValue"),
487 s_http_header_from_c_str("ExcludedHeader", "ExcludedHeaderValue"),
488 s_http_header_from_c_str("x-amz-meta-MyMetadata", "MyMetadataValue"),
489 };
490
491 const struct aws_byte_cursor excluded_headers[] = {
492 aws_byte_cursor_from_c_str("ExcludedHeader"),
493 };
494
495 struct aws_http_message *message = aws_http_message_new_request(allocator);
496 ASSERT_TRUE(message != NULL);
497 ASSERT_SUCCESS(aws_http_message_set_request_method(message, request_method));
498 ASSERT_SUCCESS(aws_http_message_set_request_path(message, request_path));
499 ASSERT_SUCCESS(aws_http_message_add_header_array(message, original_headers, AWS_ARRAY_SIZE(original_headers)));
500
501 { /* copy message, include "x-amz-meta-" */
502 struct aws_http_message *copied_message = aws_s3_message_util_copy_http_message_no_body_filter_headers(
503 allocator,
504 message,
505 excluded_headers,
506 AWS_ARRAY_SIZE(excluded_headers),
507 false /*exclude_x_amz_meta*/,
508 true /*exclude_x_amz_checksum*/);
509 ASSERT_TRUE(copied_message != NULL);
510
511 ASSERT_SUCCESS(s_test_http_messages_match(
512 allocator, message, copied_message, excluded_headers, AWS_ARRAY_SIZE(excluded_headers), true));
513
514 aws_http_message_release(copied_message);
515 }
516
517 { /* copy message, exclude "x-amz-meta-" */
518 struct aws_http_message *copied_message = aws_s3_message_util_copy_http_message_no_body_filter_headers(
519 allocator,
520 message,
521 excluded_headers,
522 AWS_ARRAY_SIZE(excluded_headers),
523 true /*exclude_x_amz_meta*/,
524 true /*exclude_x_amz_checksum*/);
525 ASSERT_TRUE(copied_message != NULL);
526
527 const struct aws_byte_cursor expected_excluded_headers[] = {
528 aws_byte_cursor_from_c_str("ExcludedHeader"),
529 aws_byte_cursor_from_c_str("x-amz-meta-MyMetadata"),
530 };
531
532 ASSERT_SUCCESS(s_test_http_messages_match(
533 allocator,
534 message,
535 copied_message,
536 expected_excluded_headers,
537 AWS_ARRAY_SIZE(expected_excluded_headers),
538 true));
539
540 aws_http_message_release(copied_message);
541 }
542
543 aws_http_message_release(message);
544
545 return 0;
546 }
547
548 AWS_TEST_CASE(test_s3_message_util_assign_body, s_test_s3_message_util_assign_body)
549 static int s_test_s3_message_util_assign_body(struct aws_allocator *allocator, void *ctx) {
550 (void)ctx;
551
552 struct aws_http_message *message = aws_http_message_new_request(allocator);
553 aws_http_message_set_request_method(message, aws_http_method_get);
554
555 const size_t test_buffer_size = 42;
556 struct aws_byte_buf test_buffer;
557 ASSERT_SUCCESS(s_fill_byte_buf(&test_buffer, allocator, test_buffer_size));
558
559 struct aws_input_stream *input_stream =
560 aws_s3_message_util_assign_body(allocator, &test_buffer, NULL /*body_stream*/, message, NULL);
561 ASSERT_TRUE(input_stream != NULL);
562
563 ASSERT_TRUE(aws_http_message_get_body_stream(message) == input_stream);
564 ASSERT_SUCCESS(s_test_http_message_body_stream(allocator, message, &test_buffer));
565
566 aws_byte_buf_clean_up(&test_buffer);
567 aws_http_message_release(message);
568
569 return 0;
570 }
571
572 AWS_TEST_CASE(test_s3_ranged_get_object_message_new, s_test_s3_ranged_get_object_message_new)
573 static int s_test_s3_ranged_get_object_message_new(struct aws_allocator *allocator, void *ctx) {
574 (void)ctx;
575
576 const struct aws_byte_cursor test_path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath");
577
578 struct aws_http_message *original_message = NULL;
579 ASSERT_SUCCESS(s_create_get_object_message(allocator, &test_path, &original_message));
580 ASSERT_TRUE(original_message != NULL);
581
582 {
583 char expected_range_value_buffer[128] = "bytes=42-83";
584 struct aws_byte_cursor expected_range_value_cursor = aws_byte_cursor_from_c_str(expected_range_value_buffer);
585
586 struct aws_http_message *get_object_message =
587 aws_s3_ranged_get_object_message_new(allocator, original_message, 42, 83);
588 ASSERT_TRUE(get_object_message != NULL);
589
590 struct aws_http_headers *headers = aws_http_message_get_headers(get_object_message);
591 ASSERT_TRUE(headers != NULL);
592
593 struct aws_byte_cursor range_header_value;
594 AWS_ZERO_STRUCT(range_header_value);
595 ASSERT_SUCCESS(aws_http_headers_get(headers, g_range_header_name, &range_header_value));
596
597 ASSERT_TRUE(aws_byte_cursor_eq(&range_header_value, &expected_range_value_cursor));
598
599 s_test_http_message_request_method(get_object_message, "GET");
600
601 aws_http_message_release(get_object_message);
602 }
603
604 aws_http_message_release(original_message);
605
606 return 0;
607 }
608
609 AWS_TEST_CASE(test_s3_set_multipart_request_path, s_test_s3_set_multipart_request_path)
610 static int s_test_s3_set_multipart_request_path(struct aws_allocator *allocator, void *ctx) {
611 (void)ctx;
612
613 #define TEST_PATH "/TestPath"
614 #define TEST_PATH_WITH_PARAMS "/TestPath?arg=value"
615 #define UPLOAD_ID "test_upload_id"
616 #define UPLOAD_ID_PARAM "uploadId=test_upload_id"
617 #define PART_NUMBER 4
618 #define UPLOADS_PARAM "uploads"
619
620 const struct aws_byte_cursor test_path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(TEST_PATH);
621 const struct aws_byte_cursor test_path_with_params = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(TEST_PATH_WITH_PARAMS);
622
623 struct aws_byte_cursor test_path_permutations[] = {
624 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath"),
625 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?uploads"),
626 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?partNumber=4"),
627 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?partNumber=4&uploads"),
628 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?uploadId=test_upload_id"),
629 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?uploadId=test_upload_id&uploads"),
630 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?partNumber=4&uploadId=test_upload_id"),
631 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?partNumber=4&uploadId=test_upload_id&uploads"),
632 };
633
634 struct aws_byte_cursor test_path_with_params_permutations[] = {
635 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value"),
636 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value&uploads"),
637 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value&partNumber=4"),
638 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value&partNumber=4&uploads"),
639 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value&uploadId=test_upload_id"),
640 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value&uploadId=test_upload_id&uploads"),
641 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value&partNumber=4&uploadId=test_upload_id"),
642 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?arg=value&partNumber=4&uploadId=test_upload_id&uploads"),
643 };
644
645 const uint32_t num_permutations = 8;
646
647 for (uint32_t i = 0; i < num_permutations; ++i) {
648 struct aws_string *upload_id = NULL;
649 uint32_t part_number = 0;
650 bool uploads_param = false;
651
652 if (i & 0x4) {
653 upload_id = aws_string_new_from_c_str(allocator, UPLOAD_ID);
654 }
655
656 if (i & 0x2) {
657 part_number = PART_NUMBER;
658 }
659
660 if (i & 0x1) {
661 uploads_param = true;
662 }
663
664 {
665 struct aws_http_message *message = NULL;
666 ASSERT_SUCCESS(s_create_put_object_message(allocator, &test_path, &message));
667
668 ASSERT_SUCCESS(aws_s3_message_util_set_multipart_request_path(
669 allocator, upload_id, part_number, uploads_param, message));
670
671 ASSERT_SUCCESS(s_test_http_message_request_path(message, &test_path_permutations[i]));
672
673 aws_http_message_release(message);
674 }
675
676 {
677 struct aws_http_message *message_with_params = NULL;
678 ASSERT_SUCCESS(s_create_put_object_message(allocator, &test_path_with_params, &message_with_params));
679
680 ASSERT_SUCCESS(aws_s3_message_util_set_multipart_request_path(
681 allocator, upload_id, part_number, uploads_param, message_with_params));
682
683 ASSERT_SUCCESS(
684 s_test_http_message_request_path(message_with_params, &test_path_with_params_permutations[i]));
685
686 aws_http_message_release(message_with_params);
687 }
688
689 aws_string_destroy(upload_id);
690 }
691
692 #undef TEST_PATH
693 #undef TEST_PATH_WITH_PARAMS
694 #undef UPLOAD_ID
695 #undef UPLOAD_ID_PARAM
696 #undef PART_NUMBER
697 #undef UPLOADS_PARAM
698
699 return 0;
700 }
701
702 AWS_TEST_CASE(test_s3_create_multipart_upload_message_new, s_test_s3_create_multipart_upload_message_new)
703 static int s_test_s3_create_multipart_upload_message_new(struct aws_allocator *allocator, void *ctx) {
704 (void)ctx;
705
706 struct aws_byte_cursor path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath");
707 struct aws_byte_cursor expected_create_path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("/TestPath?uploads");
708
709 struct aws_http_message *original_message = NULL;
710 ASSERT_SUCCESS(s_create_put_object_message(allocator, &path, &original_message));
711 ASSERT_TRUE(original_message != NULL);
712
713 struct aws_http_message *create_multipart_upload_message =
714 aws_s3_create_multipart_upload_message_new(allocator, original_message, NULL);
715 ASSERT_TRUE(create_multipart_upload_message != NULL);
716
717 ASSERT_SUCCESS(s_test_http_message_request_method(create_multipart_upload_message, "POST"));
718 ASSERT_SUCCESS(s_test_http_message_request_path(create_multipart_upload_message, &expected_create_path));
719
720 const struct aws_byte_cursor header_exclude_exceptions[] = {
721 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Length"),
722 };
723 ASSERT_SUCCESS(s_test_http_headers_match(
724 allocator,
725 original_message,
726 create_multipart_upload_message,
727 g_s3_create_multipart_upload_excluded_headers,
728 g_s3_create_multipart_upload_excluded_headers_count,
729 header_exclude_exceptions,
730 AWS_ARRAY_SIZE(header_exclude_exceptions),
731 true));
732
733 aws_http_message_release(create_multipart_upload_message);
734 aws_http_message_release(original_message);
735
736 return 0;
737 }
738
739 AWS_TEST_CASE(test_s3_upload_part_message_new, s_test_s3_upload_part_message_new)
740 static int s_test_s3_upload_part_message_new(struct aws_allocator *allocator, void *ctx) {
741 (void)ctx;
742
743 #define STRINGIFY_HELPER(x) #x
744 #define STRINGIFY(x) STRINGIFY_HELPER(x)
745 #define TEST_PATH "/TestPath"
746 #define UPLOAD_ID "test_upload_id"
747 #define PART_NUMBER 4
748 #define PART_NUMBER_STR "?partNumber=" STRINGIFY(PART_NUMBER)
749 #define EXPECTED_UPLOAD_PART_PATH TEST_PATH PART_NUMBER_STR "&uploadId=" UPLOAD_ID
750
751 const struct aws_byte_cursor header_exclude_exceptions[] = {
752 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Length"),
753 };
754
755 struct aws_byte_cursor path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(TEST_PATH);
756 struct aws_byte_cursor expected_create_path = aws_byte_cursor_from_c_str(EXPECTED_UPLOAD_PART_PATH);
757
758 struct aws_http_message *original_message = NULL;
759 ASSERT_SUCCESS(s_create_put_object_message(allocator, &path, &original_message));
760 ASSERT_TRUE(original_message != NULL);
761
762 const size_t part_buffer_size = 42;
763 struct aws_byte_buf part_buffer;
764 AWS_ZERO_STRUCT(part_buffer);
765 s_fill_byte_buf(&part_buffer, allocator, part_buffer_size);
766
767 struct aws_string *upload_id = aws_string_new_from_c_str(allocator, UPLOAD_ID);
768
769 struct aws_http_message *upload_part_message =
770 aws_s3_upload_part_message_new(allocator, original_message, &part_buffer, PART_NUMBER, upload_id, false, NULL);
771 ASSERT_TRUE(upload_part_message != NULL);
772
773 ASSERT_SUCCESS(s_test_http_message_request_method(upload_part_message, "PUT"));
774 ASSERT_SUCCESS(s_test_http_message_request_path(upload_part_message, &expected_create_path));
775 ASSERT_SUCCESS(s_test_http_headers_match(
776 allocator,
777 original_message,
778 upload_part_message,
779 g_s3_upload_part_excluded_headers,
780 g_s3_upload_part_excluded_headers_count,
781 header_exclude_exceptions,
782 AWS_ARRAY_SIZE(header_exclude_exceptions),
783 true));
784
785 ASSERT_SUCCESS(s_test_http_message_body_stream(allocator, upload_part_message, &part_buffer));
786
787 aws_string_destroy(upload_id);
788 aws_byte_buf_clean_up(&part_buffer);
789
790 aws_http_message_release(upload_part_message);
791 aws_http_message_release(original_message);
792
793 #undef STRINGIFY_HELPER
794 #undef STRINGIFY
795 #undef TEST_PATH
796 #undef UPLOAD_ID
797 #undef PART_NUMBER
798 #undef PART_NUMBER_STR
799 #undef EXPECTED_UPLOAD_PART_PATH
800
801 return 0;
802 }
803
804 AWS_TEST_CASE(test_s3_upload_part_message_fail, s_test_s3_upload_part_message_fail)
805 static int s_test_s3_upload_part_message_fail(struct aws_allocator *allocator, void *ctx) {
806 (void)ctx;
807
808 #define UPLOAD_ID "test_upload_id"
809 #define PART_NUMBER 4
810
811 struct aws_http_message *original_message = aws_http_message_new_request(allocator);
812 ASSERT_NOT_NULL(original_message);
813
814 const size_t part_buffer_size = 42;
815 struct aws_byte_buf part_buffer;
816 AWS_ZERO_STRUCT(part_buffer);
817 s_fill_byte_buf(&part_buffer, allocator, part_buffer_size);
818
819 struct aws_string *upload_id = aws_string_new_from_c_str(allocator, UPLOAD_ID);
820
821 struct aws_http_message *upload_part_message =
822 aws_s3_upload_part_message_new(allocator, original_message, &part_buffer, PART_NUMBER, upload_id, false, NULL);
823 ASSERT_NULL(upload_part_message);
824
825 aws_string_destroy(upload_id);
826 aws_byte_buf_clean_up(&part_buffer);
827
828 aws_http_message_release(upload_part_message);
829 aws_http_message_release(original_message);
830
831 #undef UPLOAD_ID
832 #undef PART_NUMBER
833
834 return 0;
835 }
836
837 struct complete_multipart_upload_xml_test_data {
838 struct aws_byte_cursor etag_value;
839 struct aws_byte_cursor part_number_value;
840 bool found_etag;
841 bool found_part_number;
842 };
843
844 static int s_complete_multipart_upload_traverse_xml_node(struct aws_xml_node *node, void *user_data) {
845
846 const struct aws_byte_cursor complete_multipar_upload_tag_name =
847 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("CompleteMultipartUpload");
848 const struct aws_byte_cursor part_tag_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Part");
849 const struct aws_byte_cursor etag_tag_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("ETag");
850 const struct aws_byte_cursor part_number_tag_name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("PartNumber");
851
852 struct complete_multipart_upload_xml_test_data *test_data = user_data;
853
854 struct aws_byte_cursor node_name = aws_xml_node_get_name(node);
855 if (aws_byte_cursor_eq(&node_name, &complete_multipar_upload_tag_name)) {
856 if (aws_xml_node_traverse(node, s_complete_multipart_upload_traverse_xml_node, user_data)) {
857 return AWS_OP_ERR;
858 }
859 } else if (aws_byte_cursor_eq(&node_name, &part_tag_name)) {
860 if (aws_xml_node_traverse(node, s_complete_multipart_upload_traverse_xml_node, user_data)) {
861 return AWS_OP_ERR;
862 }
863 } else if (aws_byte_cursor_eq(&node_name, &etag_tag_name)) {
864
865 struct aws_byte_cursor node_body;
866 AWS_ZERO_STRUCT(node_body);
867 if (aws_xml_node_as_body(node, &node_body)) {
868 return AWS_OP_ERR;
869 }
870
871 test_data->found_etag = aws_byte_cursor_eq(&node_body, &test_data->etag_value);
872 } else if (aws_byte_cursor_eq(&node_name, &part_number_tag_name)) {
873
874 struct aws_byte_cursor node_body;
875 AWS_ZERO_STRUCT(node_body);
876 if (aws_xml_node_as_body(node, &node_body)) {
877 return AWS_OP_ERR;
878 }
879
880 test_data->found_part_number = aws_byte_cursor_eq(&node_body, &test_data->part_number_value);
881 }
882
883 return AWS_OP_SUCCESS;
884 }
885
886 AWS_TEST_CASE(test_s3_complete_multipart_message_new, s_test_s3_complete_multipart_message_new)
887 static int s_test_s3_complete_multipart_message_new(struct aws_allocator *allocator, void *ctx) {
888 (void)ctx;
889
890 #define TEST_PATH "/TestPath"
891 #define UPLOAD_ID "test_upload_id"
892 #define EXPECTED_UPLOAD_PART_PATH TEST_PATH "?uploadId=" UPLOAD_ID
893 #define ETAG_VALUE "etag_value"
894
895 struct aws_array_list parts;
896 ASSERT_SUCCESS(aws_array_list_init_dynamic(&parts, allocator, 1, sizeof(struct aws_s3_mpu_part_info *)));
897 struct aws_s3_mpu_part_info *part = aws_mem_calloc(allocator, 1, sizeof(struct aws_s3_mpu_part_info));
898 part->etag = aws_string_new_from_c_str(allocator, ETAG_VALUE);
899 ASSERT_SUCCESS(aws_array_list_push_back(&parts, &part));
900
901 const struct aws_byte_cursor header_exclude_exceptions[] = {
902 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Length"),
903 AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("x-amz-mp-object-size"),
904 };
905
906 struct aws_byte_cursor path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(TEST_PATH);
907 struct aws_byte_cursor expected_create_path = aws_byte_cursor_from_c_str(EXPECTED_UPLOAD_PART_PATH);
908
909 struct aws_http_message *original_message = NULL;
910 ASSERT_SUCCESS(s_create_put_object_message(allocator, &path, &original_message));
911 ASSERT_TRUE(original_message != NULL);
912
913 struct aws_string *upload_id = aws_string_new_from_c_str(allocator, UPLOAD_ID);
914
915 struct aws_byte_buf body_buffer;
916 aws_byte_buf_init(&body_buffer, allocator, 64);
917
918 struct aws_http_message *complete_multipart_message =
919 aws_s3_complete_multipart_message_new(allocator, original_message, &body_buffer, upload_id, &parts, NULL);
920
921 ASSERT_SUCCESS(s_test_http_message_request_method(complete_multipart_message, "POST"));
922 ASSERT_SUCCESS(s_test_http_message_request_path(complete_multipart_message, &expected_create_path));
923 ASSERT_SUCCESS(s_test_http_headers_match(
924 allocator,
925 original_message,
926 complete_multipart_message,
927 g_s3_complete_multipart_upload_excluded_headers,
928 g_s3_complete_multipart_upload_excluded_headers_count,
929 header_exclude_exceptions,
930 AWS_ARRAY_SIZE(header_exclude_exceptions),
931 false));
932
933 {
934 struct complete_multipart_upload_xml_test_data xml_user_data = {
935 .etag_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(ETAG_VALUE),
936 .part_number_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("1"),
937 .found_etag = false,
938 .found_part_number = false,
939 };
940
941 struct aws_xml_parser_options parser_options = {
942 .doc = aws_byte_cursor_from_buf(&body_buffer),
943 .on_root_encountered = s_complete_multipart_upload_traverse_xml_node,
944 .user_data = &xml_user_data,
945 };
946 ASSERT_SUCCESS(aws_xml_parse(allocator, &parser_options));
947
948 ASSERT_TRUE(xml_user_data.found_etag);
949 ASSERT_TRUE(xml_user_data.found_part_number);
950 }
951
952 aws_byte_buf_clean_up(&body_buffer);
953 aws_string_destroy(upload_id);
954
955 aws_http_message_release(complete_multipart_message);
956 aws_http_message_release(original_message);
957
958 aws_string_destroy(part->etag);
959 aws_mem_release(allocator, part);
960 aws_array_list_clean_up(&parts);
961 #undef TEST_PATH
962 #undef UPLOAD_ID
963 #undef EXPECTED_UPLOAD_PART_PATH
964 #undef ETAG_VALUE
965
966 return 0;
967 }
968
969 AWS_TEST_CASE(test_s3_abort_multipart_upload_message_new, s_test_s3_abort_multipart_upload_message_newt)
970 static int s_test_s3_abort_multipart_upload_message_newt(struct aws_allocator *allocator, void *ctx) {
971 (void)ctx;
972
973 #define TEST_PATH "/TestPath"
974 #define UPLOAD_ID "test_upload_id"
975 #define EXPECTED_UPLOAD_PART_PATH TEST_PATH "?uploadId=" UPLOAD_ID
976
977 struct aws_byte_cursor path = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(TEST_PATH);
978 struct aws_byte_cursor expected_create_path = aws_byte_cursor_from_c_str(EXPECTED_UPLOAD_PART_PATH);
979
980 struct aws_http_message *original_message = NULL;
981 ASSERT_SUCCESS(s_create_put_object_message(allocator, &path, &original_message));
982 ASSERT_TRUE(original_message != NULL);
983
984 struct aws_string *upload_id = aws_string_new_from_c_str(allocator, UPLOAD_ID);
985
986 struct aws_http_message *abort_upload_message =
987 aws_s3_abort_multipart_upload_message_new(allocator, original_message, upload_id);
988 ASSERT_TRUE(abort_upload_message != NULL);
989
990 ASSERT_SUCCESS(s_test_http_message_request_method(abort_upload_message, "DELETE"));
991 ASSERT_SUCCESS(s_test_http_message_request_path(abort_upload_message, &expected_create_path));
992 ASSERT_SUCCESS(s_test_http_headers_match(
993 allocator,
994 original_message,
995 abort_upload_message,
996 g_s3_abort_multipart_upload_excluded_headers,
997 g_s3_abort_multipart_upload_excluded_headers_count,
998 NULL,
999 0,
1000 true));
1001
1002 aws_string_destroy(upload_id);
1003
1004 aws_http_message_release(abort_upload_message);
1005 aws_http_message_release(original_message);
1006
1007 #undef TEST_PATH
1008 #undef UPLOAD_ID
1009 #undef EXPECTED_UPLOAD_PART_PATH
1010
1011 return 0;
1012 }