Debian Codegraph @

crt/aws-c-s3/tests/s3_mock_server_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_util.h"
7 #include "aws/s3/s3_client.h"
8 #include "s3_tester.h"
9 #include <aws/io/stream.h>
10 #include <aws/io/uri.h>
11 #include <aws/testing/aws_test_harness.h>
12 #include <inttypes.h>
13
14 #define TEST_CASE(NAME) \
15 AWS_TEST_CASE(NAME, s_test_##NAME); \
16 static int s_test_##NAME(struct aws_allocator *allocator, void *ctx)
17
18 #define DEFINE_HEADER(NAME, VALUE) \
19 { \
20 .name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \
21 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \
22 }
23
24 static int s_validate_time_metrics(struct aws_s3_request_metrics *metrics, bool is_last_attempt) {
25 uint64_t start = 0, end = 0, duration = 0;
26 int error_code = aws_s3_request_metrics_get_error_code(metrics);
27 bool is_success = (error_code == AWS_ERROR_SUCCESS);
28
29 /* Always available */
30 aws_s3_request_metrics_get_s3_request_first_attempt_start_timestamp_ns(metrics, &start);
31 ASSERT_TRUE(start > 0);
32 /* Available on last attempt only */
33 if (is_last_attempt) {
34 ASSERT_SUCCESS(aws_s3_request_metrics_get_s3_request_last_attempt_end_timestamp_ns(metrics, &end));
35 ASSERT_TRUE(end > 0);
36 ASSERT_SUCCESS(aws_s3_request_metrics_get_s3_request_total_duration_ns(metrics, &duration));
37 ASSERT_TRUE(duration > 0);
38 ASSERT_UINT_EQUALS(end - start, duration);
39 } else {
40 ASSERT_FAILS(aws_s3_request_metrics_get_s3_request_last_attempt_end_timestamp_ns(metrics, &end));
41 ASSERT_FAILS(aws_s3_request_metrics_get_s3_request_total_duration_ns(metrics, &end));
42 }
43
44 aws_s3_request_metrics_get_start_timestamp_ns(metrics, &start);
45 ASSERT_TRUE(start > 0);
46 aws_s3_request_metrics_get_end_timestamp_ns(metrics, &end);
47 ASSERT_TRUE(end > 0);
48 aws_s3_request_metrics_get_total_duration_ns(metrics, &duration);
49 ASSERT_TRUE(duration > 0);
50 ASSERT_UINT_EQUALS(end - start, duration);
51
52 /* Available on last attempt with success only */
53 if (is_last_attempt && is_success) {
54 ASSERT_SUCCESS(aws_s3_request_metrics_get_send_start_timestamp_ns(metrics, &start));
55 ASSERT_TRUE(start > 0);
56 ASSERT_SUCCESS(aws_s3_request_metrics_get_send_end_timestamp_ns(metrics, &end));
57 ASSERT_TRUE(end > 0);
58 ASSERT_SUCCESS(aws_s3_request_metrics_get_sending_duration_ns(metrics, &duration));
59 ASSERT_TRUE(duration > 0);
60 ASSERT_UINT_EQUALS(end - start, duration);
61
62 ASSERT_SUCCESS(aws_s3_request_metrics_get_receive_start_timestamp_ns(metrics, &start));
63 ASSERT_TRUE(start > 0);
64 ASSERT_SUCCESS(aws_s3_request_metrics_get_receive_end_timestamp_ns(metrics, &end));
65 ASSERT_TRUE(end > 0);
66 ASSERT_SUCCESS(aws_s3_request_metrics_get_receiving_duration_ns(metrics, &duration));
67 ASSERT_TRUE(duration > 0);
68 ASSERT_UINT_EQUALS(end - start, duration);
69
70 ASSERT_SUCCESS(aws_s3_request_metrics_get_service_call_duration_ns(metrics, &duration));
71 ASSERT_TRUE(duration > 0);
72
73 ASSERT_SUCCESS(aws_s3_request_metrics_get_conn_acquire_start_timestamp_ns(metrics, &start));
74 ASSERT_TRUE(start > 0);
75 ASSERT_SUCCESS(aws_s3_request_metrics_get_conn_acquire_end_timestamp_ns(metrics, &end));
76 ASSERT_TRUE(end > 0);
77 ASSERT_SUCCESS(aws_s3_request_metrics_get_conn_acquire_duration_ns(metrics, &duration));
78 ASSERT_TRUE(duration > 0);
79 ASSERT_UINT_EQUALS(end - start, duration);
80
81 ASSERT_SUCCESS(aws_s3_request_metrics_get_sign_start_timestamp_ns(metrics, &start));
82 ASSERT_TRUE(start > 0);
83 ASSERT_SUCCESS(aws_s3_request_metrics_get_sign_end_timestamp_ns(metrics, &end));
84 ASSERT_TRUE(end > 0);
85 ASSERT_SUCCESS(aws_s3_request_metrics_get_signing_duration_ns(metrics, &duration));
86 ASSERT_TRUE(duration > 0);
87 ASSERT_UINT_EQUALS(end - start, duration);
88
89 if (metrics->req_resp_info_metrics.request_type == AWS_S3_REQUEST_TYPE_GET_OBJECT) {
90 ASSERT_SUCCESS(aws_s3_request_metrics_get_delivery_start_timestamp_ns(metrics, &start));
91 ASSERT_TRUE(start > 0);
92 ASSERT_SUCCESS(aws_s3_request_metrics_get_delivery_end_timestamp_ns(metrics, &end));
93 ASSERT_TRUE(end > 0);
94 ASSERT_SUCCESS(aws_s3_request_metrics_get_delivery_duration_ns(metrics, &duration));
95 ASSERT_TRUE(duration > 0);
96 ASSERT_UINT_EQUALS(end - start, duration);
97 }
98 }
99
100 if (metrics->crt_info_metrics.retry_attempt > 0) {
101 ASSERT_SUCCESS(aws_s3_request_metrics_get_retry_delay_start_timestamp_ns(metrics, &start));
102 ASSERT_TRUE(start > 0);
103 ASSERT_SUCCESS(aws_s3_request_metrics_get_retry_delay_end_timestamp_ns(metrics, &end));
104 ASSERT_TRUE(end > 0);
105 ASSERT_SUCCESS(aws_s3_request_metrics_get_retry_delay_duration_ns(metrics, &duration));
106 ASSERT_TRUE(duration > 0);
107 ASSERT_UINT_EQUALS(end - start, duration);
108 } else {
109 ASSERT_FAILS(aws_s3_request_metrics_get_retry_delay_start_timestamp_ns(metrics, &start));
110 ASSERT_FAILS(aws_s3_request_metrics_get_retry_delay_end_timestamp_ns(metrics, &end));
111 ASSERT_FAILS(aws_s3_request_metrics_get_retry_delay_duration_ns(metrics, &duration));
112 }
113
114 return AWS_OP_SUCCESS;
115 }
116
117 static int s_validate_create_multipart_upload_metrics(struct aws_s3_request_metrics *metrics) {
118 struct aws_http_headers *response_headers = NULL;
119 ASSERT_SUCCESS(aws_s3_request_metrics_get_response_headers(metrics, &response_headers));
120 const struct aws_string *request_id = NULL;
121 ASSERT_SUCCESS(aws_s3_request_metrics_get_request_id(metrics, &request_id));
122 ASSERT_TRUE(aws_string_eq_c_str(request_id, "12345"));
123 const struct aws_string *ip_address = NULL;
124 ASSERT_SUCCESS(aws_s3_request_metrics_get_ip_address(metrics, &ip_address));
125 /* Should be default local ip for ipv6/ipv4 */
126 ASSERT_TRUE(aws_string_eq_c_str(ip_address, "::1") || aws_string_eq_c_str(ip_address, "127.0.0.1"));
127 int response_status = 0;
128 ASSERT_SUCCESS(aws_s3_request_metrics_get_response_status_code(metrics, &response_status));
129 ASSERT_UINT_EQUALS(200, response_status);
130 uint32_t stream_id = 0;
131 ASSERT_SUCCESS(aws_s3_request_metrics_get_request_stream_id(metrics, &stream_id));
132 ASSERT_UINT_EQUALS(1, stream_id);
133 const struct aws_string *request_path_query = NULL;
134 aws_s3_request_metrics_get_request_path_query(metrics, &request_path_query);
135 ASSERT_TRUE(request_path_query->len > 0);
136 const struct aws_string *host_address = NULL;
137 aws_s3_request_metrics_get_host_address(metrics, &host_address);
138 ASSERT_TRUE(host_address->len > 0);
139 aws_thread_id_t thread_id = 0;
140 ASSERT_SUCCESS(aws_s3_request_metrics_get_thread_id(metrics, &thread_id));
141 size_t connection_ptr = 0;
142 ASSERT_SUCCESS(aws_s3_request_metrics_get_connection_id(metrics, &connection_ptr));
143 ASSERT_UINT_EQUALS(AWS_ERROR_SUCCESS, aws_s3_request_metrics_get_error_code(metrics));
144
145 /* Get all those time stamp */
146 ASSERT_SUCCESS(s_validate_time_metrics(metrics, true));
147
148 enum aws_s3_request_type request_type = 0;
149 aws_s3_request_metrics_get_request_type(metrics, &request_type);
150 ASSERT_UINT_EQUALS(AWS_S3_REQUEST_TYPE_CREATE_MULTIPART_UPLOAD, request_type);
151
152 const struct aws_string *operation_name = NULL;
153 ASSERT_SUCCESS(aws_s3_request_metrics_get_operation_name(metrics, &operation_name));
154 ASSERT_STR_EQUALS("CreateMultipartUpload", aws_string_c_str(operation_name));
155
156 return AWS_OP_SUCCESS;
157 }
158
159 static int s_validate_upload_part_metrics(struct aws_s3_request_metrics *metrics, bool is_last_attempt) {
160 struct aws_http_headers *response_headers = NULL;
161 struct aws_byte_cursor header_value;
162 enum aws_s3_request_type request_type = 0;
163 const struct aws_string *operation_name = NULL;
164
165 AWS_ZERO_STRUCT(header_value);
166 response_headers = NULL;
167 if (metrics->req_resp_info_metrics.response_status != -1) {
168 ASSERT_SUCCESS(aws_s3_request_metrics_get_response_headers(metrics, &response_headers));
169 ASSERT_SUCCESS(aws_http_headers_get(response_headers, aws_byte_cursor_from_c_str("ETag"), &header_value));
170 ASSERT_TRUE(aws_byte_cursor_eq_c_str(&header_value, "b54357faf0632cce46e942fa68356b38"));
171 ASSERT_SUCCESS(aws_http_headers_get(response_headers, aws_byte_cursor_from_c_str("Connection"), &header_value));
172 ASSERT_TRUE(aws_byte_cursor_eq_c_str(&header_value, "keep-alive"));
173 }
174
175 request_type = 0;
176 aws_s3_request_metrics_get_request_type(metrics, &request_type);
177 ASSERT_UINT_EQUALS(AWS_S3_REQUEST_TYPE_UPLOAD_PART, request_type);
178 ASSERT_SUCCESS(aws_s3_request_metrics_get_operation_name(metrics, &operation_name));
179 ASSERT_STR_EQUALS("UploadPart", aws_string_c_str(operation_name));
180
181 ASSERT_SUCCESS(s_validate_time_metrics(metrics, is_last_attempt));
182
183 return AWS_OP_SUCCESS;
184 }
185
186 static int s_validate_complete_multipart_upload_metrics(struct aws_s3_request_metrics *metrics) {
187 enum aws_s3_request_type request_type = 0;
188 const struct aws_string *operation_name = NULL;
189
190 aws_s3_request_metrics_get_request_type(metrics, &request_type);
191 ASSERT_UINT_EQUALS(AWS_S3_REQUEST_TYPE_COMPLETE_MULTIPART_UPLOAD, request_type);
192 ASSERT_SUCCESS(aws_s3_request_metrics_get_operation_name(metrics, &operation_name));
193 ASSERT_STR_EQUALS("CompleteMultipartUpload", aws_string_c_str(operation_name));
194
195 ASSERT_SUCCESS(s_validate_time_metrics(metrics, true));
196
197 return AWS_OP_SUCCESS;
198 }
199
200 static int s_validate_abort_multipart_upload_metrics(struct aws_s3_request_metrics *metrics) {
201 enum aws_s3_request_type request_type = 0;
202 const struct aws_string *operation_name = NULL;
203
204 aws_s3_request_metrics_get_request_type(metrics, &request_type);
205 ASSERT_UINT_EQUALS(AWS_S3_REQUEST_TYPE_ABORT_MULTIPART_UPLOAD, request_type);
206 ASSERT_SUCCESS(aws_s3_request_metrics_get_operation_name(metrics, &operation_name));
207 ASSERT_STR_EQUALS("AbortMultipartUpload", aws_string_c_str(operation_name));
208
209 ASSERT_SUCCESS(s_validate_time_metrics(metrics, true));
210
211 return AWS_OP_SUCCESS;
212 }
213
214 static int s_validate_mpu_mock_server_metrics(struct aws_array_list *metrics_list, uint32_t expected_length) {
215 /* Check the size of the metrics should be the same as the number of requests, which should be create MPU, two
216 * upload parts and one complete MPU */
217 ASSERT_UINT_EQUALS(expected_length, aws_array_list_length(metrics_list));
218 struct aws_s3_request_metrics *metrics = NULL;
219
220 /* First metrics should be the CreateMPU */
221 aws_array_list_get_at(metrics_list, (void **)&metrics, 0);
222 ASSERT_SUCCESS(s_validate_create_multipart_upload_metrics(metrics));
223
224 /* All of the middle should be Upload Parts*/
225 for (size_t i = 1; i < aws_array_list_length(metrics_list) - 1; i++) {
226 metrics = NULL;
227 aws_array_list_get_at(metrics_list, (void **)&metrics, i);
228 ASSERT_SUCCESS(s_validate_upload_part_metrics(metrics, true)); /* assuming all requests were success */
229 }
230
231 /* Last metrics should be CompleteMPU*/
232 metrics = NULL;
233 aws_array_list_get_at(metrics_list, (void **)&metrics, aws_array_list_length(metrics_list) - 1);
234 ASSERT_SUCCESS(s_validate_complete_multipart_upload_metrics(metrics));
235
236 return AWS_OP_SUCCESS;
237 }
238
239 static int s_validate_retry_metrics(struct aws_array_list *metrics_list, uint32_t expected_failures, uint32_t parts) {
240 struct aws_s3_request_metrics *metrics = NULL, *metrics2 = NULL;
241
242 /* First metrics should be the CreateMPU */
243 aws_array_list_get_at(metrics_list, (void **)&metrics, 0);
244 ASSERT_SUCCESS(s_validate_create_multipart_upload_metrics(metrics));
245
246 /* All of the middle should be Upload Parts*/
247 /* This check assumes each request fails 'expected_failures' number of times and then succeeds.
248 * So for each part, we would have expected_failures + 1 attempts.
249 * We make sure all of the attempts have the same request_first_attempt_start_time and the last attempt has an end
250 * time. */
251 size_t failed_count = 0;
252 for (size_t i = 1; i < aws_array_list_length(metrics_list) - 1; i = i + expected_failures + 1) {
253 aws_array_list_get_at(metrics_list, &metrics, i);
254 for (size_t j = i; j < i + expected_failures; j++) {
255 aws_array_list_get_at(metrics_list, &metrics2, j + 1);
256 ASSERT_TRUE(metrics->crt_info_metrics.error_code != AWS_ERROR_SUCCESS);
257 failed_count++;
258 aws_array_list_get_at(metrics_list, (void **)&metrics, j);
259 ASSERT_SUCCESS(s_validate_upload_part_metrics(metrics, false));
260 ASSERT_INT_EQUALS(
261 metrics->time_metrics.s3_request_first_attempt_start_timestamp_ns,
262 metrics2->time_metrics.s3_request_first_attempt_start_timestamp_ns);
263 ASSERT_INT_EQUALS(metrics->crt_info_metrics.retry_attempt + 1, metrics2->crt_info_metrics.retry_attempt);
264 ASSERT_TRUE(metrics->crt_info_metrics.request_ptr == metrics2->crt_info_metrics.request_ptr);
265 metrics = metrics2;
266 }
267 ASSERT_SUCCESS(s_validate_upload_part_metrics(metrics, true));
268 }
269
270 ASSERT_UINT_EQUALS(expected_failures * parts, failed_count);
271
272 /* Last metrics should be CompleteMPU*/
273 metrics = NULL;
274 aws_array_list_get_at(metrics_list, (void **)&metrics, aws_array_list_length(metrics_list) - 1);
275 ASSERT_SUCCESS(s_validate_complete_multipart_upload_metrics(metrics));
276
277 return AWS_OP_SUCCESS;
278 }
279
280 static int s_validate_fail_metrics(struct aws_array_list *metrics_list, uint32_t parts) {
281 struct aws_s3_request_metrics *metrics = NULL, *metrics2 = NULL;
282
283 /* First metrics should be the CreateMPU */
284 aws_array_list_get_at(metrics_list, (void **)&metrics, 0);
285 ASSERT_SUCCESS(s_validate_create_multipart_upload_metrics(metrics));
286
287 /* It is difficult to simulate forced failure and be precise about how a request fails if there are multiple
288 * connections. Assuming, the first request itself is failing, all of the other parts are force cancelled. If there
289 * are n parts, we would record n + 5 metrics. 5 retries for the first part alone. */
290
291 /* First part fails 5 times */
292 aws_array_list_get_at(metrics_list, &metrics, 1);
293 ASSERT_TRUE(metrics->crt_info_metrics.error_code != AWS_ERROR_SUCCESS);
294 size_t request_ptr = (size_t)metrics->crt_info_metrics.request_ptr;
295 int64_t request_start_time = metrics->time_metrics.s3_request_first_attempt_start_timestamp_ns;
296 for (size_t i = 1; i < 6; i++) {
297 aws_array_list_get_at(metrics_list, &metrics2, i + 1);
298 ASSERT_INT_EQUALS(
299 metrics->time_metrics.s3_request_first_attempt_start_timestamp_ns,
300 metrics2->time_metrics.s3_request_first_attempt_start_timestamp_ns);
301 ASSERT_INT_EQUALS(metrics->crt_info_metrics.retry_attempt + 1, metrics2->crt_info_metrics.retry_attempt);
302 ASSERT_TRUE(metrics2->crt_info_metrics.error_code != AWS_ERROR_SUCCESS);
303 ASSERT_SUCCESS(s_validate_upload_part_metrics(metrics, false));
304 ASSERT_INT_EQUALS(request_start_time, metrics2->time_metrics.s3_request_first_attempt_start_timestamp_ns);
305 ASSERT_TRUE(request_ptr == (size_t)metrics2->crt_info_metrics.request_ptr);
306 metrics = metrics2;
307 }
308 ASSERT_SUCCESS(s_validate_upload_part_metrics(metrics, true));
309
310 /* Rest of the request should have been cancelled */
311 for (size_t i = 7; i < parts + 6; i++) {
312 aws_array_list_get_at(metrics_list, &metrics, i);
313 ASSERT_TRUE(metrics->crt_info_metrics.error_code == AWS_ERROR_S3_CANCELED);
314 ASSERT_SUCCESS(s_validate_upload_part_metrics(metrics, true));
315 }
316
317 /* Last metrics should be AbortMPU*/
318 metrics = NULL;
319 aws_array_list_get_at(metrics_list, (void **)&metrics, aws_array_list_length(metrics_list) - 1);
320 ASSERT_SUCCESS(s_validate_abort_multipart_upload_metrics(metrics));
321
322 return AWS_OP_SUCCESS;
323 }
324
325 TEST_CASE(multipart_upload_mock_server) {
326 (void)ctx;
327
328 struct aws_s3_tester tester;
329 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
330 struct aws_s3_tester_client_options client_options = {
331 .part_size = MB_TO_BYTES(5),
332 .tls_usage = AWS_S3_TLS_DISABLED,
333 };
334
335 struct aws_s3_client *client = NULL;
336 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
337
338 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
339
340 struct aws_s3_tester_meta_request_options put_options = {
341 .allocator = allocator,
342 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
343 .client = client,
344 .checksum_algorithm = AWS_SCA_CRC32,
345 .validate_get_response_checksum = false,
346 .put_options =
347 {
348 .object_size_mb = 10,
349 .object_path_override = object_path,
350 },
351 .mock_server = true,
352 };
353 struct aws_s3_meta_request_test_results out_results;
354 aws_s3_meta_request_test_results_init(&out_results, allocator);
355 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
356 ASSERT_SUCCESS(
357 s_validate_mpu_mock_server_metrics(&out_results.synced_data.metrics, 4 /*1 create, 1 complete, 2 parts*/));
358 aws_s3_meta_request_test_results_clean_up(&out_results);
359 aws_s3_client_release(client);
360 aws_s3_tester_clean_up(&tester);
361
362 return AWS_OP_SUCCESS;
363 }
364
365 static void s_upload_part_with_n_retries(struct aws_s3_request *request, struct aws_http_message *message) {
366 if (message == NULL) {
367 return;
368 }
369
370 struct aws_s3_meta_request *meta_request = request->meta_request;
371 struct aws_s3_client *client = meta_request->client;
372 struct aws_s3_tester *tester = client->shutdown_callback_user_data; // or similar
373 uint32_t n = (uint32_t)(uintptr_t)tester->user_data;
374
375 if (request->num_times_prepared < n - 1) {
376 struct aws_http_header throttle_header = {
377 .name = aws_byte_cursor_from_c_str("force_throttle"),
378 .value = aws_byte_cursor_from_c_str("true"),
379 };
380 aws_http_message_add_header(message, throttle_header);
381 }
382 }
383
384 TEST_CASE(multipart_upload_with_n_retries_mock_server) {
385 (void)ctx;
386
387 struct aws_s3_tester tester;
388 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
389 tester.user_data = (void *)(uintptr_t)2; /* Fail 3 (n-1) times, succeed on 4th (nth) */
390 int part_size = 5;
391
392 struct aws_s3_tester_client_options client_options = {
393 .part_size = MB_TO_BYTES(part_size),
394 .tls_usage = AWS_S3_TLS_DISABLED,
395 .max_active_connections_override = 1,
396 };
397
398 struct aws_s3_client *client = NULL;
399 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
400 struct aws_s3_client_vtable *patched_client_vtable = aws_s3_tester_patch_client_vtable(&tester, client, NULL);
401 patched_client_vtable->after_prepare_upload_part_finish_stub = s_upload_part_with_n_retries;
402
403 int object_size = 10;
404 int parts = object_size / part_size;
405
406 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
407 {
408 /* 1. Trailer checksum */
409 struct aws_s3_tester_meta_request_options put_options = {
410 .allocator = allocator,
411 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
412 .client = client,
413 .checksum_algorithm = AWS_SCA_CRC32,
414 .validate_get_response_checksum = false,
415 .put_options =
416 {
417 .object_size_mb = object_size,
418 .object_path_override = object_path,
419 },
420 .mock_server = true,
421 };
422
423 struct aws_s3_meta_request_test_results meta_request_test_results;
424
425 // check if number of metrics received for each part is n
426 aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);
427 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));
428 uint32_t expected_failures = (uint32_t)(uintptr_t)tester.user_data - 1;
429 ASSERT_SUCCESS(
430 s_validate_retry_metrics(&meta_request_test_results.synced_data.metrics, expected_failures, parts));
431
432 aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
433 }
434 aws_s3_client_release(client);
435 aws_s3_tester_clean_up(&tester);
436
437 return AWS_OP_SUCCESS;
438 }
439
440 static void s_upload_part_force_fail(struct aws_s3_request *request, struct aws_http_message *message) {
441 (void)request;
442 if (message == NULL) {
443 return;
444 }
445
446 struct aws_http_header throttle_header = {
447 .name = aws_byte_cursor_from_c_str("force_throttle"),
448 .value = aws_byte_cursor_from_c_str("true"),
449 };
450 aws_http_message_add_header(message, throttle_header);
451 }
452
453 TEST_CASE(multipart_upload_failure_with_mock_server) {
454 (void)ctx;
455
456 struct aws_s3_tester tester;
457 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
458 int part_size = 5;
459
460 struct aws_s3_tester_client_options client_options = {
461 .part_size = MB_TO_BYTES(part_size),
462 .tls_usage = AWS_S3_TLS_DISABLED,
463 .max_active_connections_override = 1,
464 };
465
466 struct aws_s3_client *client = NULL;
467 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
468 struct aws_s3_client_vtable *patched_client_vtable = aws_s3_tester_patch_client_vtable(&tester, client, NULL);
469 patched_client_vtable->after_prepare_upload_part_finish_stub = s_upload_part_force_fail;
470
471 int object_size = 10;
472 int parts = object_size / part_size;
473
474 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
475 {
476 struct aws_s3_tester_meta_request_options put_options = {
477 .allocator = allocator,
478 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
479 .client = client,
480 .checksum_algorithm = AWS_SCA_CRC32,
481 .validate_get_response_checksum = false,
482 .put_options =
483 {
484 .object_size_mb = object_size,
485 .object_path_override = object_path,
486 },
487 .mock_server = true,
488 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_NO_VALIDATE,
489 };
490
491 struct aws_s3_meta_request_test_results meta_request_test_results;
492
493 // check if number of metrics received for each part is n
494 aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);
495 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));
496 ASSERT_SUCCESS(s_validate_fail_metrics(&meta_request_test_results.synced_data.metrics, parts));
497
498 aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
499 }
500 aws_s3_client_release(client);
501 aws_s3_tester_clean_up(&tester);
502
503 return AWS_OP_SUCCESS;
504 }
505
506 /* Singleton used by tests in this file */
507 static struct get_requests_header_tester {
508 struct aws_allocator *alloc;
509
510 /* Store the requests headers in the array. Array of struct aws_http_headers * */
511 struct aws_array_list headers_array;
512 struct aws_mutex lock;
513 } s_get_requests_header_tester;
514
515 static int s_get_requests_header_tester_init(struct aws_allocator *alloc) {
516 ASSERT_SUCCESS(aws_array_list_init_dynamic(
517 &s_get_requests_header_tester.headers_array, alloc, 1, sizeof(struct aws_http_headers *)));
518 ASSERT_SUCCESS(aws_mutex_init(&s_get_requests_header_tester.lock));
519 return AWS_OP_SUCCESS;
520 }
521
522 static void s_get_requests_header_tester_clean_up(void) {
523 /* iterate thought the headers array to clean up the headers */
524 for (size_t i = 0; i < aws_array_list_length(&s_get_requests_header_tester.headers_array); ++i) {
525 struct aws_http_headers *headers = NULL;
526 aws_array_list_get_at(&s_get_requests_header_tester.headers_array, &headers, i);
527 aws_http_headers_release(headers);
528 }
529 aws_mutex_clean_up(&s_get_requests_header_tester.lock);
530 aws_array_list_clean_up(&s_get_requests_header_tester.headers_array);
531 }
532
533 struct aws_http_stream *s_get_requests_header_make_request(
534 struct aws_http_connection *client_connection,
535 const struct aws_http_make_request_options *options) {
536 /**
537 * Record the headers in the array.
538 */
539 aws_mutex_lock(&s_get_requests_header_tester.lock);
540 struct aws_http_headers *headers = aws_http_message_get_headers(options->request);
541 /* Keep the headers alive until we clean up the tester. */
542 aws_http_headers_acquire(headers);
543 aws_array_list_push_back(&s_get_requests_header_tester.headers_array, &headers);
544 aws_mutex_unlock(&s_get_requests_header_tester.lock);
545
546 struct aws_http_stream *stream = aws_http_connection_make_request(client_connection, options);
547 return stream;
548 }
549
550 /**
551 * Note: currently (Nov, 2024), S3 don't support create multipart upload anonymously.
552 */
553 TEST_CASE(multipart_upload_unsigned_with_trailer_checksum_mock_server) {
554 (void)ctx;
555
556 struct aws_s3_tester tester;
557 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
558 ASSERT_SUCCESS(s_get_requests_header_tester_init(allocator));
559
560 struct aws_s3_client_config client_config = {
561 .tls_mode = AWS_MR_TLS_DISABLED,
562 };
563
564 ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION));
565 struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config);
566 ASSERT_NOT_NULL(client);
567
568 /* Patch the client vtable to record the request header */
569 struct aws_s3_client_vtable *s3_client_get_requests_header_vtable = client->vtable;
570 s3_client_get_requests_header_vtable->http_connection_make_request = s_get_requests_header_make_request;
571
572 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
573
574 struct aws_s3_tester_meta_request_options put_options = {
575 .allocator = allocator,
576 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
577 .client = client,
578 .checksum_algorithm = AWS_SCA_CRC32,
579 .validate_get_response_checksum = false,
580 .put_options =
581 {
582 .object_size_mb = 10,
583 .object_path_override = object_path,
584 },
585 .mock_server = true,
586 };
587 struct aws_s3_meta_request_test_results out_results;
588 aws_s3_meta_request_test_results_init(&out_results, allocator);
589 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
590 ASSERT_SUCCESS(
591 s_validate_mpu_mock_server_metrics(&out_results.synced_data.metrics, 4 /*1 create, 1 complete, 2 parts*/));
592
593 /**
594 * Check the recorded headers.
595 * 4 requests should be made:
596 * - Create MPU
597 * - 2 Upload Part
598 * - Complete MPU
599 */
600 ASSERT_UINT_EQUALS(4, aws_array_list_length(&s_get_requests_header_tester.headers_array));
601 struct aws_byte_cursor content_sha256_header = aws_byte_cursor_from_c_str("x-amz-content-sha256");
602 struct aws_byte_cursor content_sha256_header_val;
603 AWS_ZERO_STRUCT(content_sha256_header_val);
604 struct aws_byte_cursor authorization_header = aws_byte_cursor_from_c_str("Authorization");
605 struct aws_byte_cursor authorization_header_val;
606 AWS_ZERO_STRUCT(authorization_header_val);
607 /* The first request should be Create MPU, and it should not have x-amz-content-sha256 header. */
608 struct aws_http_headers *headers = NULL;
609 ASSERT_SUCCESS(aws_array_list_get_at(&s_get_requests_header_tester.headers_array, &headers, 0));
610 /* No x-amz-content-sha256 header should be found. */
611 ASSERT_FAILS(aws_http_headers_get(headers, content_sha256_header, &content_sha256_header_val));
612 /* The second and third requests should be Upload Part, and it should have x-amz-content-sha256 header with
613 * STREAMING-UNSIGNED-PAYLOAD-TRAILER. */
614 ASSERT_SUCCESS(aws_array_list_get_at(&s_get_requests_header_tester.headers_array, &headers, 1));
615 /* x-amz-content-sha256 header should be found. */
616 ASSERT_SUCCESS(aws_http_headers_get(headers, content_sha256_header, &content_sha256_header_val));
617 ASSERT_TRUE(
618 aws_byte_cursor_eq(&content_sha256_header_val, &g_aws_signed_body_value_streaming_unsigned_payload_trailer));
619 /* But the Authorization header should not be found, since we are not signing the request. */
620 ASSERT_FAILS(aws_http_headers_get(headers, authorization_header, &authorization_header_val));
621 ASSERT_SUCCESS(aws_array_list_get_at(&s_get_requests_header_tester.headers_array, &headers, 2));
622 /* x-amz-content-sha256 header should be found. */
623 ASSERT_SUCCESS(aws_http_headers_get(headers, content_sha256_header, &content_sha256_header_val));
624 ASSERT_TRUE(
625 aws_byte_cursor_eq(&content_sha256_header_val, &g_aws_signed_body_value_streaming_unsigned_payload_trailer));
626 /* But the Authorization header should not be found, since we are not signing the request. */
627 ASSERT_FAILS(aws_http_headers_get(headers, authorization_header, &authorization_header_val));
628 /* The last request should be Complete MPU, and it should not have x-amz-content-sha256 header. */
629 ASSERT_SUCCESS(aws_array_list_get_at(&s_get_requests_header_tester.headers_array, &headers, 3));
630 /* No x-amz-content-sha256 header should be found. */
631 ASSERT_FAILS(aws_http_headers_get(headers, content_sha256_header, &content_sha256_header_val));
632
633 aws_s3_meta_request_test_results_clean_up(&out_results);
634 aws_s3_client_release(client);
635 aws_s3_tester_clean_up(&tester);
636 s_get_requests_header_tester_clean_up();
637
638 return AWS_OP_SUCCESS;
639 }
640
641 TEST_CASE(single_upload_unsigned_with_trailer_checksum_mock_server) {
642 (void)ctx;
643
644 struct aws_s3_tester tester;
645 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
646 ASSERT_SUCCESS(s_get_requests_header_tester_init(allocator));
647
648 struct aws_s3_client_config client_config = {
649 .tls_mode = AWS_MR_TLS_DISABLED,
650 .part_size = 20 * 1024 * 1024,
651 };
652
653 ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION));
654 struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config);
655 ASSERT_NOT_NULL(client);
656
657 /* Patch the client vtable to record the request header */
658 struct aws_s3_client_vtable *s3_client_get_requests_header_vtable = client->vtable;
659 s3_client_get_requests_header_vtable->http_connection_make_request = s_get_requests_header_make_request;
660
661 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
662
663 struct aws_s3_tester_meta_request_options put_options = {
664 .allocator = allocator,
665 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
666 .client = client,
667 .checksum_algorithm = AWS_SCA_CRC32,
668 .validate_get_response_checksum = false,
669 .put_options =
670 {
671 .object_size_mb = 10,
672 .object_path_override = object_path,
673 },
674 .mock_server = true,
675 };
676 struct aws_s3_meta_request_test_results out_results;
677 aws_s3_meta_request_test_results_init(&out_results, allocator);
678 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
679
680 /**
681 * Check the recorded headers.
682 * 1 request should be made:
683 * - Put Object
684 */
685 ASSERT_UINT_EQUALS(1, aws_array_list_length(&s_get_requests_header_tester.headers_array));
686 struct aws_byte_cursor content_sha256_header = aws_byte_cursor_from_c_str("x-amz-content-sha256");
687 struct aws_byte_cursor content_sha256_header_val;
688 AWS_ZERO_STRUCT(content_sha256_header_val);
689 struct aws_byte_cursor authorization_header = aws_byte_cursor_from_c_str("Authorization");
690 struct aws_byte_cursor authorization_header_val;
691 AWS_ZERO_STRUCT(authorization_header_val);
692 /* The request should be Put Object, and it should have x-amz-content-sha256 header and not Authorization header. */
693 struct aws_http_headers *headers = NULL;
694 ASSERT_SUCCESS(aws_array_list_get_at(&s_get_requests_header_tester.headers_array, &headers, 0));
695 /* x-amz-content-sha256 header should be found. */
696 ASSERT_SUCCESS(aws_http_headers_get(headers, content_sha256_header, &content_sha256_header_val));
697 ASSERT_TRUE(
698 aws_byte_cursor_eq(&content_sha256_header_val, &g_aws_signed_body_value_streaming_unsigned_payload_trailer));
699 /* But the Authorization header should not be found, since we are not signing the request. */
700 ASSERT_FAILS(aws_http_headers_get(headers, authorization_header, &authorization_header_val));
701
702 aws_s3_meta_request_test_results_clean_up(&out_results);
703 aws_s3_client_release(client);
704 aws_s3_tester_clean_up(&tester);
705 s_get_requests_header_tester_clean_up();
706
707 return AWS_OP_SUCCESS;
708 }
709
710 /* Tracks what a `request_body` test observed about the request body as it was being sent. */
711 struct request_body_tester {
712 /* The caller-owned memory that was passed via `request_body`. */
713 struct aws_byte_cursor caller_body;
714 /* Set to true if, on any send attempt, the request body buffer did NOT point at the caller's exact buffer. */
715 bool saw_different_buffer;
716 /* Number of times the request was sent (initial attempt + retries). */
717 size_t send_count;
718 /* If non-zero, inject a `force_throttle` header until this many attempts have been made, to trigger retries. */
719 size_t throttle_until_attempt;
720 /* The Content-Length header value observed on the last outgoing request (SIZE_MAX if the header was absent). */
721 size_t observed_content_length;
722 };
723
724 /* Patched http_connection_make_request that verifies the outgoing request body points at the caller's exact buffer,
725 * and optionally injects a throttle header to force retries.
726 * This fires on every send attempt, so it verifies that retries re-use the caller's same buffer. */
727 static struct aws_http_stream *s_request_body_make_request(
728 struct aws_http_connection *client_connection,
729 const struct aws_http_make_request_options *options) {
730
731 struct aws_s3_connection *connection = options->user_data;
732 struct aws_s3_request *request = connection->request;
733 struct aws_s3_meta_request *meta_request = request->meta_request;
734 /* The tester owns meta_request->user_data, so reach our body-tester via tester->user_data. */
735 struct aws_s3_tester *tester = meta_request->client->shutdown_callback_user_data;
736 struct request_body_tester *body_tester = tester->user_data;
737
738 ++body_tester->send_count;
739
740 /* The request body must point at the caller's exact buffer (same pointer and length). */
741 if (request->request_body.buffer != body_tester->caller_body.ptr ||
742 request->request_body.len != body_tester->caller_body.len) {
743 body_tester->saw_different_buffer = true;
744 }
745
746 /* Record the Content-Length the client put on the wire, so the test can verify it was derived correctly. */
747 struct aws_http_headers *headers = aws_http_message_get_headers(options->request);
748 struct aws_byte_cursor content_length_value;
749 if (aws_http_headers_get(headers, g_content_length_header_name, &content_length_value) == AWS_OP_SUCCESS) {
750 uint64_t parsed = 0;
751 if (aws_byte_cursor_utf8_parse_u64(content_length_value, &parsed) == AWS_OP_SUCCESS) {
752 body_tester->observed_content_length = (size_t)parsed;
753 }
754 } else {
755 body_tester->observed_content_length = SIZE_MAX;
756 }
757
758 /* Optionally force a throttle (503) so the client retries, re-sending the same caller-owned memory. */
759 if (body_tester->send_count <= body_tester->throttle_until_attempt) {
760 struct aws_http_header throttle_header = {
761 .name = aws_byte_cursor_from_c_str("force_throttle"),
762 .value = aws_byte_cursor_from_c_str("true"),
763 };
764 aws_http_message_add_header(options->request, throttle_header);
765 }
766
767 return aws_http_connection_make_request(client_connection, options);
768 }
769
770 /* Shared helper for `request_body` tests. */
771 static int s_request_body_test_helper(
772 struct aws_allocator *allocator,
773 struct aws_byte_cursor body,
774 size_t throttle_until_attempt,
775 bool omit_content_length) {
776 struct aws_s3_tester tester;
777 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
778
779 struct aws_s3_tester_client_options client_options = {
780 .tls_usage = AWS_S3_TLS_DISABLED,
781 .max_active_connections_override = 1,
782 };
783 struct aws_s3_client *client = NULL;
784 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
785
786 /* Patch the client vtable to inspect the body of each outgoing request (and inject throttles). */
787 struct aws_s3_client_vtable *patched_client_vtable = aws_s3_tester_patch_client_vtable(&tester, client, NULL);
788 patched_client_vtable->http_connection_make_request = s_request_body_make_request;
789
790 struct request_body_tester body_tester = {
791 .caller_body = body,
792 .throttle_until_attempt = throttle_until_attempt,
793 /* Sentinel: distinct from any real Content-Length (including 0) so the assertion only passes if the hook
794 * actually observed the header on the wire. */
795 .observed_content_length = SIZE_MAX,
796 };
797 tester.user_data = &body_tester;
798
799 struct aws_uri mock_server;
800 ASSERT_SUCCESS(aws_uri_init_parse(&mock_server, allocator, &g_mock_server_uri));
801 struct aws_byte_cursor host_cursor = *aws_uri_authority(&mock_server);
802 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
803
804 struct aws_http_message *message = aws_s3_test_put_object_request_new_without_body(
805 allocator, &host_cursor, g_test_body_content_type, object_path, body.len, 0 /*flags*/);
806 ASSERT_NOT_NULL(message);
807
808 if (omit_content_length) {
809 aws_http_headers_erase(aws_http_message_get_headers(message), g_content_length_header_name);
810 }
811
812 struct aws_s3_meta_request_options meta_request_options = {
813 .type = AWS_S3_META_REQUEST_TYPE_DEFAULT,
814 .operation_name = aws_byte_cursor_from_c_str("PutObject"),
815 .message = message,
816 .endpoint = &mock_server,
817 .request_body = body,
818 };
819
820 struct aws_s3_meta_request_test_results out_results;
821 aws_s3_meta_request_test_results_init(&out_results, allocator);
822
823 ASSERT_SUCCESS(aws_s3_tester_send_meta_request(
824 &tester, client, &meta_request_options, &out_results, AWS_S3_TESTER_SEND_META_REQUEST_EXPECT_SUCCESS));
825
826 if (body.len > 0) {
827 ASSERT_FALSE(body_tester.saw_different_buffer);
828 }
829 ASSERT_UINT_EQUALS(throttle_until_attempt + 1, body_tester.send_count);
830 ASSERT_UINT_EQUALS(body.len, body_tester.observed_content_length);
831
832 aws_http_message_release(message);
833 aws_uri_clean_up(&mock_server);
834 aws_s3_meta_request_test_results_clean_up(&out_results);
835 aws_s3_client_release(client);
836 aws_s3_tester_clean_up(&tester);
837
838 return AWS_OP_SUCCESS;
839 }
840
841 /* Happy path: a DEFAULT PutObject with `request_body` sends the body from the caller's exact buffer. */
842 TEST_CASE(request_body_mock_server) {
843 (void)ctx;
844 struct aws_byte_cursor body = aws_byte_cursor_from_c_str("test_body");
845 return s_request_body_test_helper(allocator, body, 0 /*throttle_until_attempt*/, false /*omit_content_length*/);
846 }
847
848 /* On retry, the request body still points at the caller's same `request_body` buffer (re-used across attempts). */
849 TEST_CASE(request_body_with_retry_mock_server) {
850 (void)ctx;
851 struct aws_byte_cursor body = aws_byte_cursor_from_c_str("test_body");
852 return s_request_body_test_helper(allocator, body, 2 /*throttle_until_attempt*/, false /*omit_content_length*/);
853 }
854
855 /* Happy path with no Content-Length header: the client must derive the length from `request_body.len`. */
856 TEST_CASE(request_body_no_content_length_mock_server) {
857 (void)ctx;
858 struct aws_byte_cursor body = aws_byte_cursor_from_c_str("test_body");
859 return s_request_body_test_helper(allocator, body, 0 /*throttle_until_attempt*/, true /*omit_content_length*/);
860 }
861
862 /* Happy path: a zero-length `request_body` with a non-NULL pointer. */
863 TEST_CASE(request_body_empty_mock_server) {
864 (void)ctx;
865 uint8_t body_storage[1];
866 struct aws_byte_cursor empty_body = {.ptr = body_storage, .len = 0};
867 return s_request_body_test_helper(
868 allocator, empty_body, 0 /*throttle_until_attempt*/, false /*omit_content_length*/);
869 }
870
871 TEST_CASE(multipart_upload_with_network_interface_names_mock_server) {
872 (void)ctx;
873 #if defined(AWS_OS_WINDOWS)
874 (void)allocator;
875 return AWS_OP_SKIP;
876 #else
877 struct aws_s3_tester tester;
878 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
879 struct aws_byte_cursor *interface_names_array = aws_mem_calloc(allocator, 2, sizeof(struct aws_byte_cursor));
880 char *localhost_interface = "\0";
881 # if defined(AWS_OS_APPLE)
882 localhost_interface = "lo0";
883 # else
884 localhost_interface = "lo";
885 # endif
886 interface_names_array[0] = aws_byte_cursor_from_c_str(localhost_interface);
887 interface_names_array[1] = aws_byte_cursor_from_c_str(localhost_interface);
888
889 struct aws_s3_tester_client_options client_options = {
890 .part_size = MB_TO_BYTES(5),
891 .tls_usage = AWS_S3_TLS_DISABLED,
892 .network_interface_names_array = interface_names_array,
893 .num_network_interface_names = 2,
894 };
895
896 struct aws_s3_client *client = NULL;
897 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
898
899 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
900
901 struct aws_s3_tester_meta_request_options put_options = {
902 .allocator = allocator,
903 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
904 .client = client,
905 .checksum_algorithm = AWS_SCA_CRC32,
906 .validate_get_response_checksum = false,
907 .put_options =
908 {
909 .object_size_mb = 10,
910 .object_path_override = object_path,
911 },
912 .mock_server = true,
913 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_NO_VALIDATE,
914 };
915 struct aws_s3_meta_request_test_results out_results;
916 aws_s3_meta_request_test_results_init(&out_results, allocator);
917 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
918 if (out_results.finished_error_code != 0) {
919 # if !defined(AWS_OS_APPLE) && !defined(AWS_OS_LINUX)
920 if (out_results.finished_error_code == AWS_ERROR_PLATFORM_NOT_SUPPORTED) {
921 return AWS_OP_SKIP;
922 }
923 # endif
924 ASSERT_TRUE(false, "aws_s3_tester_send_meta_request_with_options(() failed");
925 }
926 aws_s3_meta_request_test_results_clean_up(&out_results);
927 aws_s3_client_release(client);
928 aws_s3_tester_clean_up(&tester);
929 aws_mem_release(allocator, interface_names_array);
930
931 return AWS_OP_SUCCESS;
932 #endif
933 }
934
935 /* Total hack to flip the bytes. */
936 static void s_after_prepare_upload_part_finish_stub(struct aws_s3_request *request, struct aws_http_message *message) {
937 (void)message;
938 if (request->num_times_prepared == 0 && message != NULL) {
939 struct aws_http_header throttle_header = {
940 .name = aws_byte_cursor_from_c_str("force_throttle"),
941 .value = aws_byte_cursor_from_c_str("true"),
942 };
943 aws_http_message_add_header(message, throttle_header);
944 }
945 if (request->num_times_prepared > 0) {
946 /* mock that the body buffer was messed up in memory */
947 request->request_body.buffer[1]++;
948 }
949 }
950
951 static void s_after_prepare_upload_part_finish_stub_retry_before_finish_sending(
952 struct aws_s3_request *request,
953 struct aws_http_message *message) {
954 if (request->num_times_prepared == 0 && message != NULL) {
955 struct aws_http_header before_finish_header = {
956 .name = aws_byte_cursor_from_c_str("before_finish"),
957 .value = aws_byte_cursor_from_c_str("true"),
958 };
959 aws_http_message_add_header(message, before_finish_header);
960 struct aws_http_header throttle_header = {
961 .name = aws_byte_cursor_from_c_str("force_throttle"),
962 .value = aws_byte_cursor_from_c_str("true"),
963 };
964 aws_http_message_add_header(message, throttle_header);
965 }
966 if (request->num_times_prepared > 0 && request->request_body.buffer != NULL) {
967 /* mock that the body buffer was messed up in memory */
968 request->request_body.buffer[1]++;
969 }
970 }
971
972 /**
973 * This test is built for
974 * 1. The retry happens before the upload has finished.
975 */
976 TEST_CASE(multipart_upload_checksum_with_retry_before_finish_mock_server) {
977 (void)ctx;
978 struct aws_s3_tester tester;
979 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
980 struct aws_s3_tester_client_options client_options = {
981 .part_size = MB_TO_BYTES(5),
982 .tls_usage = AWS_S3_TLS_DISABLED,
983 };
984
985 struct aws_s3_client *client = NULL;
986 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
987 struct aws_s3_client_vtable *patched_client_vtable = aws_s3_tester_patch_client_vtable(&tester, client, NULL);
988 patched_client_vtable->after_prepare_upload_part_finish_stub =
989 s_after_prepare_upload_part_finish_stub_retry_before_finish_sending;
990
991 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
992 {
993 /* 1. Trailer checksum */
994 struct aws_s3_tester_meta_request_options put_options = {
995 .allocator = allocator,
996 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
997 .client = client,
998 .checksum_algorithm = AWS_SCA_CRC32,
999 .validate_get_response_checksum = false,
1000 .put_options =
1001 {
1002 .object_size_mb = 10,
1003 .object_path_override = object_path,
1004 },
1005 .mock_server = true,
1006 };
1007
1008 struct aws_s3_meta_request_test_results meta_request_test_results;
1009 aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);
1010
1011 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));
1012
1013 ASSERT_INT_EQUALS(meta_request_test_results.upload_review.part_count, 2);
1014 /* Note: the data we currently generate is always the same,
1015 * The retry got the messed up data, while the first run never actually finish reading the bytes, so the messed
1016 * up data checksum got to be sent. */
1017 ASSERT_STR_EQUALS(
1018 "dKYRxA==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[0]));
1019 ASSERT_STR_EQUALS(
1020 "dxV2Sw==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[1]));
1021 aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
1022 }
1023 aws_s3_client_release(client);
1024 aws_s3_tester_clean_up(&tester);
1025
1026 return AWS_OP_SUCCESS;
1027 }
1028
1029 /**
1030 * This test is built for
1031 * 1. We had a memory leak when the retry was triggered and the checksum was calculated.
1032 * The retry will initialize the checksum buffer again, but the previous one was not freed.
1033 * 2. We had a bug where the retry will mangle the data with the error response from server.
1034 * 3. Don't recalculate the checksum when retrying.
1035 */
1036 TEST_CASE(multipart_upload_checksum_with_retry_mock_server) {
1037 (void)ctx;
1038 struct aws_s3_tester tester;
1039 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1040 struct aws_s3_tester_client_options client_options = {
1041 .part_size = MB_TO_BYTES(5),
1042 .tls_usage = AWS_S3_TLS_DISABLED,
1043 };
1044
1045 struct aws_s3_client *client = NULL;
1046 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1047 struct aws_s3_client_vtable *patched_client_vtable = aws_s3_tester_patch_client_vtable(&tester, client, NULL);
1048 patched_client_vtable->after_prepare_upload_part_finish_stub = s_after_prepare_upload_part_finish_stub;
1049
1050 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
1051 {
1052 /* 1. Trailer checksum */
1053 struct aws_s3_tester_meta_request_options put_options = {
1054 .allocator = allocator,
1055 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1056 .client = client,
1057 .checksum_algorithm = AWS_SCA_CRC32,
1058 .validate_get_response_checksum = false,
1059 .put_options =
1060 {
1061 .object_size_mb = 10,
1062 .object_path_override = object_path,
1063 },
1064 .mock_server = true,
1065 };
1066
1067 struct aws_s3_meta_request_test_results meta_request_test_results;
1068 aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);
1069
1070 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));
1071
1072 ASSERT_INT_EQUALS(meta_request_test_results.upload_review.part_count, 2);
1073 /* Note: the data we currently generate is always the same,
1074 * so make sure that retry does not mangle the data by checking the checksum value */
1075 ASSERT_STR_EQUALS(
1076 "7/xUXw==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[0]));
1077 ASSERT_STR_EQUALS(
1078 "PCOjcw==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[1]));
1079 aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
1080 }
1081 {
1082 /* 2. header checksum */
1083 struct aws_s3_tester_meta_request_options put_options = {
1084 .allocator = allocator,
1085 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1086 .client = client,
1087 .checksum_algorithm = AWS_SCA_CRC32,
1088 .checksum_via_header = true,
1089 .validate_get_response_checksum = false,
1090 .put_options =
1091 {
1092 .object_size_mb = 10,
1093 .object_path_override = object_path,
1094 },
1095 .mock_server = true,
1096 };
1097
1098 struct aws_s3_meta_request_test_results meta_request_test_results;
1099 aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);
1100
1101 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));
1102
1103 ASSERT_INT_EQUALS(meta_request_test_results.upload_review.part_count, 2);
1104 /* Note: the data we currently generate is always the same,
1105 * so make sure that retry does not mangle the data by checking the checksum value */
1106 ASSERT_STR_EQUALS(
1107 "7/xUXw==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[0]));
1108 ASSERT_STR_EQUALS(
1109 "PCOjcw==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[1]));
1110 aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
1111 }
1112 aws_s3_client_release(client);
1113 aws_s3_tester_clean_up(&tester);
1114
1115 return AWS_OP_SUCCESS;
1116 }
1117
1118 TEST_CASE(multipart_upload_checksum_fio_with_retry_mock_server) {
1119 (void)ctx;
1120 struct aws_s3_tester tester;
1121 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1122 struct aws_s3_tester_client_options client_options = {
1123 .part_size = MB_TO_BYTES(5),
1124 .tls_usage = AWS_S3_TLS_DISABLED,
1125 };
1126
1127 struct aws_s3_client *client = NULL;
1128 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1129 struct aws_s3_client_vtable *patched_client_vtable = aws_s3_tester_patch_client_vtable(&tester, client, NULL);
1130 patched_client_vtable->after_prepare_upload_part_finish_stub =
1131 s_after_prepare_upload_part_finish_stub_retry_before_finish_sending;
1132 struct aws_s3_file_io_options fio_opts = {
1133 .should_stream = true,
1134 .direct_io = true,
1135 };
1136 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
1137
1138 /* retry with streaming upload. */
1139 struct aws_s3_tester_meta_request_options put_options = {
1140 .allocator = allocator,
1141 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1142 .client = client,
1143 .checksum_algorithm = AWS_SCA_CRC32,
1144 .validate_get_response_checksum = false,
1145 .fio_opts = &fio_opts,
1146 .put_options =
1147 {
1148 .file_on_disk = true,
1149 .object_size_mb = 10,
1150 .object_path_override = object_path,
1151 },
1152 .mock_server = true,
1153 };
1154
1155 struct aws_s3_meta_request_test_results meta_request_test_results;
1156 aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator);
1157
1158 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &meta_request_test_results));
1159
1160 ASSERT_INT_EQUALS(meta_request_test_results.upload_review.part_count, 2);
1161 /* Note: the data we currently generate is always the same,
1162 * so make sure that retry does not mangle the data by checking the checksum value */
1163 ASSERT_STR_EQUALS("7/xUXw==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[0]));
1164 ASSERT_STR_EQUALS("PCOjcw==", aws_string_c_str(meta_request_test_results.upload_review.part_checksums_array[1]));
1165 aws_s3_meta_request_test_results_clean_up(&meta_request_test_results);
1166 aws_s3_client_release(client);
1167 aws_s3_tester_clean_up(&tester);
1168
1169 return AWS_OP_SUCCESS;
1170 }
1171
1172 TEST_CASE(multipart_download_checksum_with_retry_mock_server) {
1173 (void)ctx;
1174 /**
1175 * We had a memory leak after the header of the request received successfully, the request failed.
1176 * We have allocated memory that never frees.
1177 */
1178 struct aws_s3_tester tester;
1179 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1180 struct aws_s3_tester_client_options client_options = {
1181 .part_size = MB_TO_BYTES(5),
1182 .tls_usage = AWS_S3_TLS_DISABLED,
1183 };
1184
1185 struct aws_s3_client *client = NULL;
1186 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1187 /* Mock server will response without fake checksum for the body */
1188 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/get_object_checksum_retry");
1189
1190 struct aws_s3_tester_meta_request_options get_options = {
1191 .allocator = allocator,
1192 .meta_request_type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT,
1193 .client = client,
1194 .expected_validate_checksum_alg = AWS_SCA_CRC32,
1195 .validate_get_response_checksum = true,
1196 .get_options =
1197 {
1198 .object_path = object_path,
1199 },
1200 .default_type_options =
1201 {
1202 .mode = AWS_S3_TESTER_DEFAULT_TYPE_MODE_GET,
1203 .operation_name = aws_byte_cursor_from_c_str("GetObject"),
1204 },
1205 .mock_server = true,
1206 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1207 };
1208
1209 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, NULL));
1210
1211 aws_s3_client_release(client);
1212 aws_s3_tester_clean_up(&tester);
1213
1214 return AWS_OP_SUCCESS;
1215 }
1216
1217 TEST_CASE(async_internal_error_from_complete_multipart_mock_server) {
1218 (void)ctx;
1219
1220 struct aws_s3_tester tester;
1221 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1222 struct aws_s3_tester_client_options client_options = {
1223 .part_size = MB_TO_BYTES(5),
1224 .tls_usage = AWS_S3_TLS_DISABLED,
1225 };
1226
1227 struct aws_s3_client *client = NULL;
1228 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1229
1230 /* Checkout the ./mock_s3_server/CompleteMultipartUpload/async_internal_error.json for the response details */
1231 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/async_internal_error");
1232
1233 struct aws_s3_tester_meta_request_options put_options = {
1234 .allocator = allocator,
1235 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1236 .client = client,
1237 .checksum_algorithm = AWS_SCA_CRC32,
1238 .validate_get_response_checksum = false,
1239 .put_options =
1240 {
1241 .object_size_mb = 10,
1242 .object_path_override = object_path,
1243 },
1244 .mock_server = true,
1245 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1246 };
1247 struct aws_s3_meta_request_test_results out_results;
1248 aws_s3_meta_request_test_results_init(&out_results, allocator);
1249
1250 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1251
1252 /* Internal error will be retried and failed with internal error. */
1253 ASSERT_UINT_EQUALS(AWS_ERROR_S3_INTERNAL_ERROR, out_results.finished_error_code);
1254
1255 aws_s3_meta_request_test_results_clean_up(&out_results);
1256 aws_s3_client_release(client);
1257 aws_s3_tester_clean_up(&tester);
1258
1259 return AWS_OP_SUCCESS;
1260 }
1261
1262 TEST_CASE(async_access_denied_from_complete_multipart_mock_server) {
1263 (void)ctx;
1264
1265 struct aws_s3_tester tester;
1266 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1267 struct aws_s3_tester_client_options client_options = {
1268 .part_size = MB_TO_BYTES(5),
1269 .tls_usage = AWS_S3_TLS_DISABLED,
1270 };
1271
1272 struct aws_s3_client *client = NULL;
1273 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1274
1275 /* Checkout the ./mock_s3_server/CompleteMultipartUpload/async_access_denied_error.json for the response details */
1276 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/async_access_denied_error");
1277
1278 struct aws_s3_tester_meta_request_options put_options = {
1279 .allocator = allocator,
1280 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1281 .client = client,
1282 .checksum_algorithm = AWS_SCA_CRC32,
1283 .validate_get_response_checksum = false,
1284 .put_options =
1285 {
1286 .object_size_mb = 10,
1287 .object_path_override = object_path,
1288 },
1289 .mock_server = true,
1290 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1291 };
1292 struct aws_s3_meta_request_test_results out_results;
1293 aws_s3_meta_request_test_results_init(&out_results, allocator);
1294
1295 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1296
1297 ASSERT_UINT_EQUALS(AWS_ERROR_S3_NON_RECOVERABLE_ASYNC_ERROR, out_results.finished_error_code);
1298 ASSERT_UINT_EQUALS(AWS_HTTP_STATUS_CODE_200_OK, out_results.finished_response_status);
1299 ASSERT_TRUE(out_results.error_response_body.len != 0);
1300 ASSERT_STR_EQUALS("CompleteMultipartUpload", aws_string_c_str(out_results.error_response_operation_name));
1301
1302 aws_s3_meta_request_test_results_clean_up(&out_results);
1303 aws_s3_client_release(client);
1304 aws_s3_tester_clean_up(&tester);
1305
1306 return AWS_OP_SUCCESS;
1307 }
1308
1309 TEST_CASE(get_object_modified_mock_server) {
1310 (void)ctx;
1311
1312 struct aws_s3_tester tester;
1313 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1314 struct aws_s3_tester_client_options client_options = {
1315 .part_size = 64 * 1024,
1316 .tls_usage = AWS_S3_TLS_DISABLED,
1317 };
1318
1319 struct aws_s3_client *client = NULL;
1320 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1321
1322 /* Check the mock server README/GetObject Response for the response that will be received. */
1323 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/get_object_modified");
1324
1325 struct aws_s3_tester_meta_request_options get_options = {
1326 .allocator = allocator,
1327 .meta_request_type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT,
1328 .client = client,
1329 .get_options =
1330 {
1331 .object_path = object_path,
1332 },
1333 .mock_server = true,
1334 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1335 };
1336 struct aws_s3_meta_request_test_results out_results;
1337 aws_s3_meta_request_test_results_init(&out_results, allocator);
1338
1339 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, &out_results));
1340
1341 ASSERT_UINT_EQUALS(AWS_ERROR_S3_OBJECT_MODIFIED, out_results.finished_error_code);
1342 ASSERT_UINT_EQUALS(AWS_HTTP_STATUS_CODE_412_PRECONDITION_FAILED, out_results.finished_response_status);
1343 ASSERT_STR_EQUALS("GetObject", aws_string_c_str(out_results.error_response_operation_name));
1344
1345 aws_s3_meta_request_test_results_clean_up(&out_results);
1346 aws_s3_client_release(client);
1347 aws_s3_tester_clean_up(&tester);
1348
1349 return AWS_OP_SUCCESS;
1350 }
1351
1352 TEST_CASE(get_object_invalid_responses_mock_server) {
1353 (void)ctx;
1354
1355 struct aws_s3_tester tester;
1356 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1357 struct aws_s3_tester_client_options client_options = {
1358 .part_size = 64 * 1024,
1359 .tls_usage = AWS_S3_TLS_DISABLED,
1360 };
1361
1362 struct aws_s3_client *client = NULL;
1363 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1364
1365 /* 1 - Mock server will response without Content-Range */
1366 struct aws_byte_cursor object_path =
1367 aws_byte_cursor_from_c_str("/get_object_invalid_response_missing_content_range");
1368
1369 struct aws_s3_tester_meta_request_options get_options = {
1370 .allocator = allocator,
1371 .meta_request_type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT,
1372 .client = client,
1373 .get_options =
1374 {
1375 .object_path = object_path,
1376 },
1377 .mock_server = true,
1378 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1379 };
1380 struct aws_s3_meta_request_test_results out_results;
1381 aws_s3_meta_request_test_results_init(&out_results, allocator);
1382
1383 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, &out_results));
1384
1385 ASSERT_UINT_EQUALS(AWS_ERROR_S3_MISSING_CONTENT_RANGE_HEADER, out_results.finished_error_code);
1386
1387 /* 2 - Mock server will response without Etags */
1388 object_path = aws_byte_cursor_from_c_str("/get_object_invalid_response_missing_etags");
1389 get_options.get_options.object_path = object_path;
1390 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, &out_results));
1391 ASSERT_UINT_EQUALS(AWS_ERROR_S3_MISSING_ETAG, out_results.finished_error_code);
1392
1393 /* 3 - Mock server will response without Content-Range response for HEAD request */
1394 object_path = aws_byte_cursor_from_c_str("/get_object_invalid_response_missing_content_range");
1395 /* Put together a simple S3 Get Object request. */
1396 struct aws_uri mock_server;
1397 ASSERT_SUCCESS(aws_uri_init_parse(&mock_server, allocator, &g_mock_server_uri));
1398 struct aws_http_message *message =
1399 aws_s3_test_get_object_request_new(allocator, *aws_uri_authority(&mock_server), object_path);
1400 struct aws_http_header range_header = {
1401 .name = g_range_header_name,
1402 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=-1"),
1403 };
1404 ASSERT_SUCCESS(aws_http_message_add_header(message, range_header));
1405 get_options.get_options.object_path = object_path;
1406 get_options.message = message;
1407 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, &out_results));
1408 ASSERT_UINT_EQUALS(AWS_ERROR_S3_MISSING_CONTENT_RANGE_HEADER, out_results.finished_error_code);
1409 aws_uri_clean_up(&mock_server);
1410 aws_http_message_destroy(message);
1411
1412 /* Clean up */
1413 aws_s3_meta_request_test_results_clean_up(&out_results);
1414 aws_s3_client_release(client);
1415 aws_s3_tester_clean_up(&tester);
1416
1417 return AWS_OP_SUCCESS;
1418 }
1419
1420 TEST_CASE(get_object_mismatch_checksum_responses_mock_server) {
1421 (void)ctx;
1422
1423 struct aws_s3_tester tester;
1424 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1425 struct aws_s3_tester_client_options client_options = {
1426 .part_size = 64 * 1024,
1427 .tls_usage = AWS_S3_TLS_DISABLED,
1428 };
1429
1430 struct aws_s3_client *client = NULL;
1431 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1432
1433 /* Mock server will response without fake checksum for the body */
1434 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/get_object_unmatch_checksum_crc32");
1435
1436 struct aws_s3_tester_meta_request_options get_options = {
1437 .allocator = allocator,
1438 .meta_request_type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT,
1439 .client = client,
1440 .expected_validate_checksum_alg = AWS_SCA_CRC32,
1441 .validate_get_response_checksum = true,
1442 .get_options =
1443 {
1444 .object_path = object_path,
1445 },
1446 .default_type_options =
1447 {
1448 .mode = AWS_S3_TESTER_DEFAULT_TYPE_MODE_GET,
1449 },
1450 .mock_server = true,
1451 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1452 };
1453 struct aws_s3_meta_request_test_results out_results;
1454 aws_s3_meta_request_test_results_init(&out_results, allocator);
1455
1456 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, &out_results));
1457
1458 ASSERT_UINT_EQUALS(AWS_ERROR_S3_RESPONSE_CHECKSUM_MISMATCH, out_results.finished_error_code);
1459 ASSERT_UINT_EQUALS(AWS_SCA_CRC32, out_results.algorithm);
1460
1461 aws_s3_meta_request_test_results_clean_up(&out_results);
1462 aws_s3_client_release(client);
1463 aws_s3_tester_clean_up(&tester);
1464
1465 return AWS_OP_SUCCESS;
1466 }
1467
1468 /* Test that the HTTP throughput monitoring's default settings can detect dead (or absurdly slow) connections.
1469 * We trigger this by having the mock server delay 60 seconds before sending the response. */
1470 TEST_CASE(get_object_throughput_failure_mock_server) {
1471 (void)ctx;
1472
1473 struct aws_s3_tester tester;
1474 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1475 struct aws_s3_tester_client_options client_options = {
1476 .part_size = 64 * 1024,
1477 .tls_usage = AWS_S3_TLS_DISABLED,
1478 };
1479
1480 struct aws_s3_client *client = NULL;
1481 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1482
1483 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/get_object_delay_60s");
1484
1485 struct aws_s3_tester_meta_request_options get_options = {
1486 .allocator = allocator,
1487 .meta_request_type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT,
1488 .client = client,
1489 .get_options =
1490 {
1491 .object_path = object_path,
1492 },
1493 .default_type_options =
1494 {
1495 .mode = AWS_S3_TESTER_DEFAULT_TYPE_MODE_GET,
1496 },
1497 .mock_server = true,
1498 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1499 };
1500 struct aws_s3_meta_request_test_results out_results;
1501 aws_s3_meta_request_test_results_init(&out_results, allocator);
1502
1503 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, &out_results));
1504
1505 ASSERT_UINT_EQUALS(AWS_ERROR_HTTP_CHANNEL_THROUGHPUT_FAILURE, out_results.finished_error_code);
1506
1507 aws_s3_meta_request_test_results_clean_up(&out_results);
1508 aws_s3_client_release(client);
1509 aws_s3_tester_clean_up(&tester);
1510
1511 return AWS_OP_SUCCESS;
1512 }
1513
1514 TEST_CASE(get_object_long_error_mock_server) {
1515 (void)ctx;
1516
1517 struct aws_s3_tester tester;
1518 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1519 struct aws_s3_tester_client_options client_options = {
1520 .part_size = 64 * 1024,
1521 .tls_usage = AWS_S3_TLS_DISABLED,
1522 };
1523
1524 struct aws_s3_client *client = NULL;
1525 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1526
1527 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/get_object_long_error");
1528
1529 struct aws_s3_tester_meta_request_options get_options = {
1530 .allocator = allocator,
1531 .meta_request_type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT,
1532 .client = client,
1533 .get_options =
1534 {
1535 .object_path = object_path,
1536 },
1537 .default_type_options =
1538 {
1539 .mode = AWS_S3_TESTER_DEFAULT_TYPE_MODE_GET,
1540 },
1541 .mock_server = true,
1542 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1543 };
1544 struct aws_s3_meta_request_test_results out_results;
1545 aws_s3_meta_request_test_results_init(&out_results, allocator);
1546
1547 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &get_options, &out_results));
1548
1549 ASSERT_UINT_EQUALS(AWS_ERROR_S3_INVALID_RESPONSE_STATUS, out_results.finished_error_code);
1550
1551 aws_s3_meta_request_test_results_clean_up(&out_results);
1552 aws_s3_client_release(client);
1553 aws_s3_tester_clean_up(&tester);
1554
1555 return AWS_OP_SUCCESS;
1556 }
1557
1558 static int s_test_upload_part_invalid_response_mock_server_ex(
1559 struct aws_allocator *allocator,
1560 bool async_input_stream) {
1561
1562 struct aws_s3_tester tester;
1563 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1564 struct aws_s3_tester_client_options client_options = {
1565 .part_size = MB_TO_BYTES(5),
1566 .tls_usage = AWS_S3_TLS_DISABLED,
1567 };
1568
1569 struct aws_s3_client *client = NULL;
1570 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1571
1572 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/missing_etag");
1573
1574 struct aws_s3_tester_meta_request_options put_options = {
1575 .allocator = allocator,
1576 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1577 .client = client,
1578 .checksum_algorithm = AWS_SCA_CRC32,
1579 .validate_get_response_checksum = false,
1580 .put_options =
1581 {
1582 .object_size_mb = 1024, /* big, so it's likely we're still reading when failure happens */
1583 .object_path_override = object_path,
1584 .async_input_stream = async_input_stream,
1585 },
1586 .mock_server = true,
1587 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1588 };
1589 struct aws_s3_meta_request_test_results out_results;
1590 aws_s3_meta_request_test_results_init(&out_results, allocator);
1591
1592 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1593 ASSERT_UINT_EQUALS(AWS_ERROR_S3_MISSING_ETAG, out_results.finished_error_code);
1594
1595 aws_s3_meta_request_test_results_clean_up(&out_results);
1596 aws_s3_client_release(client);
1597 aws_s3_tester_clean_up(&tester);
1598
1599 return AWS_OP_SUCCESS;
1600 }
1601
1602 /* Test an UploadPart failing due to invalid response */
1603 TEST_CASE(upload_part_invalid_response_mock_server) {
1604 (void)ctx;
1605 return s_test_upload_part_invalid_response_mock_server_ex(allocator, false /*async_input_stream*/);
1606 }
1607
1608 /* Test an UploadPart failing due to invalid response, while uploading from an async-input-stream */
1609 TEST_CASE(upload_part_async_invalid_response_mock_server) {
1610 (void)ctx;
1611 return s_test_upload_part_invalid_response_mock_server_ex(allocator, true /*async_input_stream*/);
1612 }
1613
1614 /* Fake a MPU with 4 parts and the 2nd and 3rd have already completed and resume works fine */
1615 TEST_CASE(resume_first_part_not_completed_mock_server) {
1616 (void)ctx;
1617
1618 struct aws_s3_tester tester;
1619 size_t num_parts = 4;
1620 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1621 struct aws_s3_tester_client_options client_options = {
1622 .part_size = MB_TO_BYTES(8),
1623 .tls_usage = AWS_S3_TLS_DISABLED,
1624 };
1625
1626 struct aws_s3_client *client = NULL;
1627 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1628
1629 /* ListParts from mock server will return Etags for the 2nd and 3rd parts */
1630 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/resume_first_part_not_completed");
1631 struct aws_s3_upload_resume_token_options token_options = {
1632 .upload_id = aws_byte_cursor_from_c_str("upload_id"),
1633 .part_size = client_options.part_size,
1634 .total_num_parts = num_parts,
1635 };
1636 struct aws_s3_meta_request_resume_token *token =
1637 aws_s3_meta_request_resume_token_new_upload(allocator, &token_options);
1638
1639 struct aws_s3_tester_meta_request_options put_options = {
1640 .allocator = allocator,
1641 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1642 .client = client,
1643 .checksum_algorithm = AWS_SCA_CRC32,
1644 .validate_get_response_checksum = false,
1645 .put_options =
1646 {
1647 .object_size_mb = (uint32_t)num_parts * 8, /* Make sure we have exactly 4 parts */
1648 .object_path_override = object_path,
1649 .resume_token = token,
1650 },
1651 .mock_server = true,
1652 };
1653 struct aws_s3_meta_request_test_results out_results;
1654 aws_s3_meta_request_test_results_init(&out_results, allocator);
1655
1656 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1657 /* Make Sure we only uploaded 2 parts. */
1658 /* TODO: monitor telemetry ensure this happened */
1659
1660 aws_s3_meta_request_test_results_clean_up(&out_results);
1661 aws_s3_meta_request_resume_token_release(token);
1662 aws_s3_client_release(client);
1663 aws_s3_tester_clean_up(&tester);
1664
1665 return AWS_OP_SUCCESS;
1666 }
1667
1668 /* Fake a MPU with 4 parts and the 2nd and 3rd have already completed and resume works fine with two response of
1669 * ListParts
1670 */
1671 TEST_CASE(resume_multi_page_list_parts_mock_server) {
1672 (void)ctx;
1673
1674 struct aws_s3_tester tester;
1675 size_t num_parts = 4;
1676 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1677 struct aws_s3_tester_client_options client_options = {
1678 .part_size = MB_TO_BYTES(8),
1679 .tls_usage = AWS_S3_TLS_DISABLED,
1680 };
1681
1682 struct aws_s3_client *client = NULL;
1683 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1684
1685 /* ListParts from mock server will return NextPartNumberMarker */
1686 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/multiple_list_parts");
1687 struct aws_s3_upload_resume_token_options token_options = {
1688 .upload_id = aws_byte_cursor_from_c_str("upload_id"),
1689 .part_size = client_options.part_size,
1690 .total_num_parts = num_parts,
1691 };
1692 struct aws_s3_meta_request_resume_token *token =
1693 aws_s3_meta_request_resume_token_new_upload(allocator, &token_options);
1694
1695 struct aws_s3_tester_meta_request_options put_options = {
1696 .allocator = allocator,
1697 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1698 .client = client,
1699 .checksum_algorithm = AWS_SCA_CRC32,
1700 .validate_get_response_checksum = false,
1701 .put_options =
1702 {
1703 .object_size_mb = (uint32_t)num_parts * 8, /* Make sure we have exactly 4 parts */
1704 .object_path_override = object_path,
1705 .resume_token = token,
1706 },
1707 .mock_server = true,
1708 };
1709 struct aws_s3_meta_request_test_results out_results;
1710 aws_s3_meta_request_test_results_init(&out_results, allocator);
1711
1712 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1713 /* Make Sure we only uploaded 2 parts. */
1714 /* TODO: monitor telemetry ensure this happened */
1715
1716 aws_s3_meta_request_test_results_clean_up(&out_results);
1717 aws_s3_meta_request_resume_token_release(token);
1718 aws_s3_client_release(client);
1719 aws_s3_tester_clean_up(&tester);
1720
1721 return AWS_OP_SUCCESS;
1722 }
1723
1724 TEST_CASE(resume_list_parts_failed_mock_server) {
1725 (void)ctx;
1726
1727 struct aws_s3_tester tester;
1728 size_t num_parts = 4;
1729 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1730 struct aws_s3_tester_client_options client_options = {
1731 .part_size = MB_TO_BYTES(8),
1732 .tls_usage = AWS_S3_TLS_DISABLED,
1733 };
1734
1735 struct aws_s3_client *client = NULL;
1736 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1737
1738 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/non-exist");
1739 struct aws_s3_upload_resume_token_options token_options = {
1740 .upload_id = aws_byte_cursor_from_c_str("upload_id"),
1741 .part_size = client_options.part_size,
1742 .total_num_parts = num_parts,
1743 };
1744 struct aws_s3_meta_request_resume_token *token =
1745 aws_s3_meta_request_resume_token_new_upload(allocator, &token_options);
1746
1747 struct aws_s3_tester_meta_request_options put_options = {
1748 .allocator = allocator,
1749 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1750 .client = client,
1751 .checksum_algorithm = AWS_SCA_CRC32,
1752 .validate_get_response_checksum = false,
1753 .put_options =
1754 {
1755 .object_size_mb = (uint32_t)num_parts * 8, /* Make sure we have exactly 4 parts */
1756 .object_path_override = object_path,
1757 .resume_token = token,
1758 },
1759 .mock_server = true,
1760 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1761 };
1762 struct aws_s3_meta_request_test_results out_results;
1763 aws_s3_meta_request_test_results_init(&out_results, allocator);
1764
1765 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1766 ASSERT_UINT_EQUALS(AWS_ERROR_S3_INVALID_RESPONSE_STATUS, out_results.finished_error_code);
1767 ASSERT_UINT_EQUALS(AWS_HTTP_STATUS_CODE_404_NOT_FOUND, out_results.finished_response_status);
1768 ASSERT_STR_EQUALS("ListParts", aws_string_c_str(out_results.error_response_operation_name));
1769
1770 aws_s3_meta_request_test_results_clean_up(&out_results);
1771 aws_s3_meta_request_resume_token_release(token);
1772 aws_s3_client_release(client);
1773 aws_s3_tester_clean_up(&tester);
1774
1775 return AWS_OP_SUCCESS;
1776 }
1777
1778 TEST_CASE(resume_after_finished_mock_server) {
1779 (void)ctx;
1780
1781 struct aws_s3_tester tester;
1782 size_t num_parts = 4;
1783 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1784 struct aws_s3_tester_client_options client_options = {
1785 .part_size = MB_TO_BYTES(8),
1786 .tls_usage = AWS_S3_TLS_DISABLED,
1787 };
1788
1789 struct aws_s3_client *client = NULL;
1790 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1791
1792 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/non-exist");
1793 struct aws_s3_upload_resume_token_options token_options = {
1794 .upload_id = aws_byte_cursor_from_c_str("upload_id"),
1795 .part_size = client_options.part_size,
1796 .total_num_parts = num_parts,
1797 .num_parts_completed = num_parts,
1798 };
1799 struct aws_s3_meta_request_resume_token *token =
1800 aws_s3_meta_request_resume_token_new_upload(allocator, &token_options);
1801
1802 struct aws_s3_tester_meta_request_options put_options = {
1803 .allocator = allocator,
1804 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1805 .client = client,
1806 .checksum_algorithm = AWS_SCA_CRC32,
1807 .validate_get_response_checksum = false,
1808 .put_options =
1809 {
1810 .object_size_mb = (uint32_t)num_parts * 8, /* Make sure we have exactly 4 parts */
1811 .object_path_override = object_path,
1812 .resume_token = token,
1813 },
1814 .mock_server = true,
1815 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_NO_VALIDATE,
1816 };
1817 struct aws_s3_meta_request_test_results out_results;
1818 aws_s3_meta_request_test_results_init(&out_results, allocator);
1819
1820 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1821 /* The error code should be success, but there are no headers and stuff as no request was made. */
1822 ASSERT_UINT_EQUALS(AWS_ERROR_SUCCESS, out_results.finished_error_code);
1823 /* TODO: monitor telemetry to ensure no actual data was sent */
1824
1825 aws_s3_meta_request_test_results_clean_up(&out_results);
1826 aws_s3_meta_request_resume_token_release(token);
1827 aws_s3_client_release(client);
1828 aws_s3_tester_clean_up(&tester);
1829
1830 return AWS_OP_SUCCESS;
1831 }
1832
1833 TEST_CASE(multipart_upload_proxy_mock_server) {
1834 (void)ctx;
1835
1836 struct aws_s3_tester tester;
1837 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1838 struct aws_s3_tester_client_options client_options = {
1839 .part_size = MB_TO_BYTES(5),
1840 .tls_usage = AWS_S3_TLS_DISABLED,
1841 .use_proxy = true,
1842 };
1843
1844 struct aws_s3_client *client = NULL;
1845 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1846
1847 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
1848
1849 struct aws_s3_tester_meta_request_options put_options = {
1850 .allocator = allocator,
1851 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1852 .client = client,
1853 .checksum_algorithm = AWS_SCA_CRC32,
1854 .validate_get_response_checksum = false,
1855 .put_options =
1856 {
1857 .object_size_mb = 10,
1858 .object_path_override = object_path,
1859 },
1860 .mock_server = true,
1861 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_NO_VALIDATE,
1862 };
1863
1864 /* The request can fail if proxy is unavailable. */
1865 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, NULL));
1866
1867 aws_s3_client_release(client);
1868 aws_s3_tester_clean_up(&tester);
1869
1870 return AWS_OP_SUCCESS;
1871 }
1872
1873 TEST_CASE(endpoint_override_mock_server) {
1874 (void)ctx;
1875
1876 struct aws_s3_tester tester;
1877 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1878 struct aws_s3_tester_client_options client_options = {
1879 .part_size = MB_TO_BYTES(5),
1880 .tls_usage = AWS_S3_TLS_DISABLED,
1881 };
1882
1883 struct aws_s3_client *client = NULL;
1884 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1885
1886 /* 1 - Mock server will response without Content-Range */
1887 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default");
1888
1889 struct aws_s3_tester_meta_request_options put_options = {
1890 .allocator = allocator,
1891 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1892 .client = client,
1893 .put_options =
1894 {
1895 .object_size_mb = 5,
1896 .object_path_override = object_path,
1897 },
1898 .mock_server = true,
1899 };
1900
1901 /* Put together a simple S3 Put Object request. */
1902 struct aws_input_stream *input_stream =
1903 aws_s3_test_input_stream_new(allocator, put_options.put_options.object_size_mb);
1904 struct aws_http_message *message =
1905 aws_s3_test_put_object_request_new(allocator, NULL, object_path, g_test_body_content_type, input_stream, 0);
1906 ASSERT_NOT_NULL(message);
1907
1908 /* 1. Create request without host and use endpoint override for the host info */
1909 put_options.message = message;
1910 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, NULL));
1911
1912 /* 2. Create request with host info missmatch endpoint override */
1913 struct aws_http_header host_header = {
1914 .name = g_host_header_name,
1915 .value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bad_host"),
1916 };
1917 ASSERT_SUCCESS(aws_http_message_add_header(message, host_header));
1918 put_options.message = message;
1919 put_options.validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE;
1920 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, NULL));
1921 ASSERT_INT_EQUALS(2, tester.synced_data.meta_request_shutdown_count);
1922
1923 /* Clean up */
1924 aws_http_message_destroy(message);
1925 aws_input_stream_release(input_stream);
1926 aws_s3_client_release(client);
1927 aws_s3_tester_clean_up(&tester);
1928
1929 return AWS_OP_SUCCESS;
1930 }
1931
1932 /* Test that `RequestTimeTooSkewed` will be retried */
1933 TEST_CASE(request_time_too_skewed_mock_server) {
1934 (void)ctx;
1935
1936 struct aws_s3_tester tester;
1937 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1938 struct aws_s3_tester_client_options client_options = {
1939 .part_size = MB_TO_BYTES(5),
1940 .tls_usage = AWS_S3_TLS_DISABLED,
1941 };
1942
1943 struct aws_s3_client *client = NULL;
1944 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1945
1946 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/request_time_too_skewed");
1947 struct aws_s3_meta_request_test_results out_results;
1948 aws_s3_meta_request_test_results_init(&out_results, allocator);
1949
1950 struct aws_s3_tester_meta_request_options put_options = {
1951 .allocator = allocator,
1952 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
1953 .client = client,
1954 .checksum_algorithm = AWS_SCA_CRC32,
1955 .validate_get_response_checksum = false,
1956 .put_options =
1957 {
1958 .object_size_mb = 10,
1959 .object_path_override = object_path,
1960 },
1961 .mock_server = true,
1962 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
1963 };
1964
1965 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
1966
1967 ASSERT_UINT_EQUALS(AWS_ERROR_S3_REQUEST_TIME_TOO_SKEWED, out_results.finished_error_code);
1968
1969 /* The default retry will max out after 5 times. So, in total, it will be 6 requests, first one and 5 retries. */
1970 size_t result_num = aws_array_list_length(&out_results.synced_data.metrics);
1971 ASSERT_UINT_EQUALS(6, result_num);
1972
1973 aws_s3_meta_request_test_results_clean_up(&out_results);
1974 aws_s3_client_release(client);
1975 aws_s3_tester_clean_up(&tester);
1976
1977 return AWS_OP_SUCCESS;
1978 }
1979
1980 TEST_CASE(request_timeout_error_mock_server) {
1981 (void)ctx;
1982
1983 struct aws_s3_tester tester;
1984 ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester));
1985 struct aws_s3_tester_client_options client_options = {
1986 .part_size = MB_TO_BYTES(5),
1987 .tls_usage = AWS_S3_TLS_DISABLED,
1988 };
1989
1990 struct aws_s3_client *client = NULL;
1991 ASSERT_SUCCESS(aws_s3_tester_client_new(&tester, &client_options, &client));
1992
1993 struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/request_timeout");
1994 struct aws_s3_meta_request_test_results out_results;
1995 aws_s3_meta_request_test_results_init(&out_results, allocator);
1996
1997 struct aws_s3_tester_meta_request_options put_options = {
1998 .allocator = allocator,
1999 .meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT,
2000 .client = client,
2001 .checksum_algorithm = AWS_SCA_CRC32,
2002 .validate_get_response_checksum = false,
2003 .put_options =
2004 {
2005 .object_size_mb = 10,
2006 .object_path_override = object_path,
2007 },
2008 .mock_server = true,
2009 .validate_type = AWS_S3_TESTER_VALIDATE_TYPE_EXPECT_FAILURE,
2010 };
2011
2012 ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(&tester, &put_options, &out_results));
2013
2014 ASSERT_UINT_EQUALS(AWS_ERROR_S3_REQUEST_TIMEOUT, out_results.finished_error_code);
2015
2016 /* The default retry will max out after 5 times. So, in total, it will be 6 requests, first one and 5 retries. */
2017 size_t result_num = aws_array_list_length(&out_results.synced_data.metrics);
2018 ASSERT_UINT_EQUALS(6, result_num);
2019
2020 aws_s3_meta_request_test_results_clean_up(&out_results);
2021 aws_s3_client_release(client);
2022 aws_s3_tester_clean_up(&tester);
2023
2024 return AWS_OP_SUCCESS;
2025 }