| 1 |
|
| 2 |
|
| 3 |
|
| 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_util.h" |
| 9 |
#include "s3_tester.h" |
| 10 |
#include <aws/common/byte_buf.h> |
| 11 |
#include <aws/common/clock.h> |
| 12 |
#include <aws/common/common.h> |
| 13 |
#include <aws/common/environment.h> |
| 14 |
#include <aws/common/ref_count.h> |
| 15 |
#include <aws/http/request_response.h> |
| 16 |
#include <aws/io/channel_bootstrap.h> |
| 17 |
#include <aws/io/event_loop.h> |
| 18 |
#include <aws/io/host_resolver.h> |
| 19 |
#include <aws/io/stream.h> |
| 20 |
#include <aws/io/tls_channel_handler.h> |
| 21 |
#include <aws/testing/aws_test_harness.h> |
| 22 |
#include <inttypes.h> |
| 23 |
#include <stdio.h> |
| 24 |
|
| 25 |
|
| 26 |
AWS_TEST_CASE(test_s3_library_init_cleanup_init_cleanup, s_test_s3_library_init_cleanup_init_cleanup) |
| 27 |
static int s_test_s3_library_init_cleanup_init_cleanup(struct aws_allocator *allocator, void *ctx) { |
| 28 |
(void)ctx; |
| 29 |
|
| 30 |
aws_s3_library_init(allocator); |
| 31 |
aws_s3_library_clean_up(); |
| 32 |
|
| 33 |
aws_s3_library_init(allocator); |
| 34 |
aws_s3_library_clean_up(); |
| 35 |
|
| 36 |
return 0; |
| 37 |
} |
| 38 |
|
| 39 |
AWS_TEST_CASE(test_s3_request_type_operation_name, s_test_s3_request_type_operation_name) |
| 40 |
static int s_test_s3_request_type_operation_name(struct aws_allocator *allocator, void *ctx) { |
| 41 |
(void)ctx; |
| 42 |
aws_s3_library_init(allocator); |
| 43 |
|
| 44 |
|
| 45 |
ASSERT_STR_EQUALS("HeadObject", aws_s3_request_type_operation_name(AWS_S3_REQUEST_TYPE_HEAD_OBJECT)); |
| 46 |
|
| 47 |
|
| 48 |
for (enum aws_s3_request_type type = AWS_S3_REQUEST_TYPE_UNKNOWN + 1; type < AWS_S3_REQUEST_TYPE_MAX; ++type) { |
| 49 |
const char *operation_name = aws_s3_request_type_operation_name(type); |
| 50 |
ASSERT_NOT_NULL(operation_name); |
| 51 |
ASSERT_TRUE(strlen(operation_name) > 1); |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
ASSERT_NOT_NULL(aws_s3_request_type_operation_name(AWS_S3_REQUEST_TYPE_UNKNOWN)); |
| 56 |
ASSERT_STR_EQUALS("", aws_s3_request_type_operation_name(AWS_S3_REQUEST_TYPE_UNKNOWN)); |
| 57 |
ASSERT_STR_EQUALS("", aws_s3_request_type_operation_name(AWS_S3_REQUEST_TYPE_MAX)); |
| 58 |
ASSERT_STR_EQUALS("", aws_s3_request_type_operation_name(-1)); |
| 59 |
|
| 60 |
aws_s3_library_clean_up(); |
| 61 |
return 0; |
| 62 |
} |
| 63 |
|
| 64 |
AWS_TEST_CASE(test_s3_request_type_from_operation_name, s_test_s3_request_type_from_operation_name) |
| 65 |
static int s_test_s3_request_type_from_operation_name(struct aws_allocator *allocator, void *ctx) { |
| 66 |
(void)ctx; |
| 67 |
aws_s3_library_init(allocator); |
| 68 |
|
| 69 |
|
| 70 |
ASSERT_INT_EQUALS( |
| 71 |
AWS_S3_REQUEST_TYPE_HEAD_OBJECT, |
| 72 |
aws_s3_request_type_from_operation_name(aws_byte_cursor_from_c_str("HeadObject"))); |
| 73 |
|
| 74 |
|
| 75 |
ASSERT_INT_EQUALS( |
| 76 |
AWS_S3_REQUEST_TYPE_HEAD_OBJECT, |
| 77 |
aws_s3_request_type_from_operation_name(aws_byte_cursor_from_c_str("headobject"))); |
| 78 |
|
| 79 |
|
| 80 |
for (enum aws_s3_request_type type = AWS_S3_REQUEST_TYPE_UNKNOWN + 1; type < AWS_S3_REQUEST_TYPE_MAX; ++type) { |
| 81 |
const char *operation_name = aws_s3_request_type_operation_name(type); |
| 82 |
ASSERT_NOT_NULL(operation_name); |
| 83 |
ASSERT_TRUE(strlen(operation_name) > 1); |
| 84 |
|
| 85 |
ASSERT_INT_EQUALS(type, aws_s3_request_type_from_operation_name(aws_byte_cursor_from_c_str(operation_name))); |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
ASSERT_INT_EQUALS( |
| 90 |
AWS_S3_REQUEST_TYPE_UNKNOWN, |
| 91 |
aws_s3_request_type_from_operation_name(aws_byte_cursor_from_c_str("MyFakeOperationName"))); |
| 92 |
ASSERT_INT_EQUALS( |
| 93 |
AWS_S3_REQUEST_TYPE_UNKNOWN, aws_s3_request_type_from_operation_name(aws_byte_cursor_from_c_str(""))); |
| 94 |
ASSERT_INT_EQUALS( |
| 95 |
AWS_S3_REQUEST_TYPE_UNKNOWN, aws_s3_request_type_from_operation_name(aws_byte_cursor_from_array(NULL, 0))); |
| 96 |
|
| 97 |
aws_s3_library_clean_up(); |
| 98 |
return 0; |
| 99 |
} |
| 100 |
|
| 101 |
AWS_TEST_CASE(test_s3_replace_quote_entities, s_test_s3_replace_quote_entities) |
| 102 |
static int s_test_s3_replace_quote_entities(struct aws_allocator *allocator, void *ctx) { |
| 103 |
(void)ctx; |
| 104 |
|
| 105 |
struct test_case { |
| 106 |
struct aws_byte_cursor test_string; |
| 107 |
const char *expected_result; |
| 108 |
}; |
| 109 |
|
| 110 |
struct test_case test_cases[] = { |
| 111 |
{ |
| 112 |
.test_string = aws_byte_cursor_from_c_str(""testtest"), |
| 113 |
.expected_result = "\"testtest", |
| 114 |
}, |
| 115 |
{ |
| 116 |
.test_string = aws_byte_cursor_from_c_str("testtest""), |
| 117 |
.expected_result = "testtest\"", |
| 118 |
}, |
| 119 |
{ |
| 120 |
.test_string = aws_byte_cursor_from_c_str(""""), |
| 121 |
.expected_result = "\"\"", |
| 122 |
}, |
| 123 |
{ |
| 124 |
.test_string = aws_byte_cursor_from_c_str("testtest"), |
| 125 |
.expected_result = "testtest", |
| 126 |
}, |
| 127 |
{ |
| 128 |
.test_string = aws_byte_cursor_from_c_str(""), |
| 129 |
.expected_result = "", |
| 130 |
}, |
| 131 |
}; |
| 132 |
|
| 133 |
for (size_t i = 0; i < AWS_ARRAY_SIZE(test_cases); ++i) { |
| 134 |
struct test_case *test_case = &test_cases[i]; |
| 135 |
|
| 136 |
struct aws_byte_buf result_byte_buf; |
| 137 |
aws_byte_buf_init(&result_byte_buf, allocator, 20); |
| 138 |
ASSERT_SUCCESS(aws_byte_buf_append_unescaped_xml(allocator, test_case->test_string, &result_byte_buf)); |
| 139 |
|
| 140 |
struct aws_byte_cursor result_byte_cursor = aws_byte_cursor_from_buf(&result_byte_buf); |
| 141 |
|
| 142 |
ASSERT_CURSOR_VALUE_CSTRING_EQUALS(result_byte_cursor, test_case->expected_result); |
| 143 |
|
| 144 |
aws_byte_buf_clean_up(&result_byte_buf); |
| 145 |
} |
| 146 |
|
| 147 |
return 0; |
| 148 |
} |
| 149 |
|
| 150 |
AWS_TEST_CASE(test_s3_strip_quotes, s_test_s3_strip_quotes) |
| 151 |
static int s_test_s3_strip_quotes(struct aws_allocator *allocator, void *ctx) { |
| 152 |
(void)ctx; |
| 153 |
|
| 154 |
struct test_case { |
| 155 |
struct aws_byte_cursor test_cursor; |
| 156 |
struct aws_byte_cursor expected_result; |
| 157 |
}; |
| 158 |
|
| 159 |
struct test_case test_cases[] = { |
| 160 |
{ |
| 161 |
.test_cursor = aws_byte_cursor_from_c_str("\"test\""), |
| 162 |
.expected_result = aws_byte_cursor_from_c_str("test"), |
| 163 |
}, |
| 164 |
{ |
| 165 |
.test_cursor = aws_byte_cursor_from_c_str("test\""), |
| 166 |
.expected_result = aws_byte_cursor_from_c_str("test\""), |
| 167 |
}, |
| 168 |
{ |
| 169 |
.test_cursor = aws_byte_cursor_from_c_str("\"test"), |
| 170 |
.expected_result = aws_byte_cursor_from_c_str("\"test"), |
| 171 |
}, |
| 172 |
{ |
| 173 |
.test_cursor = aws_byte_cursor_from_c_str("test"), |
| 174 |
.expected_result = aws_byte_cursor_from_c_str("test"), |
| 175 |
}, |
| 176 |
{ |
| 177 |
.test_cursor = aws_byte_cursor_from_c_str(""), |
| 178 |
.expected_result = aws_byte_cursor_from_c_str(""), |
| 179 |
}, |
| 180 |
}; |
| 181 |
|
| 182 |
for (size_t i = 0; i < AWS_ARRAY_SIZE(test_cases); ++i) { |
| 183 |
struct test_case *test_case = &test_cases[i]; |
| 184 |
|
| 185 |
struct aws_byte_buf result_byte_buf; |
| 186 |
AWS_ZERO_STRUCT(result_byte_buf); |
| 187 |
|
| 188 |
struct aws_string *result = aws_strip_quotes(allocator, test_case->test_cursor); |
| 189 |
|
| 190 |
struct aws_byte_cursor result_byte_cursor = aws_byte_cursor_from_string(result); |
| 191 |
|
| 192 |
ASSERT_TRUE(aws_byte_cursor_eq(&test_case->expected_result, &result_byte_cursor)); |
| 193 |
|
| 194 |
aws_byte_buf_clean_up(&result_byte_buf); |
| 195 |
aws_string_destroy(result); |
| 196 |
} |
| 197 |
|
| 198 |
return 0; |
| 199 |
} |
| 200 |
|
| 201 |
AWS_TEST_CASE(test_s3_parse_request_range_header, s_test_s3_parse_request_range_header) |
| 202 |
static int s_test_s3_parse_request_range_header(struct aws_allocator *allocator, void *ctx) { |
| 203 |
|
| 204 |
(void)ctx; |
| 205 |
|
| 206 |
struct range_header_example { |
| 207 |
struct aws_byte_cursor header_value; |
| 208 |
|
| 209 |
bool has_start_range; |
| 210 |
bool has_end_range; |
| 211 |
uint64_t range_start; |
| 212 |
uint64_t range_end; |
| 213 |
}; |
| 214 |
|
| 215 |
const struct range_header_example valid_range_examples[] = { |
| 216 |
{ |
| 217 |
.header_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=5-10"), |
| 218 |
.has_start_range = true, |
| 219 |
.has_end_range = true, |
| 220 |
.range_start = 5, |
| 221 |
.range_end = 10, |
| 222 |
}, |
| 223 |
{ |
| 224 |
.header_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=0-0"), |
| 225 |
.has_start_range = true, |
| 226 |
.has_end_range = true, |
| 227 |
.range_start = 0, |
| 228 |
.range_end = 0, |
| 229 |
}, |
| 230 |
{ |
| 231 |
.header_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=0-"), |
| 232 |
.has_start_range = true, |
| 233 |
.has_end_range = false, |
| 234 |
.range_start = 0, |
| 235 |
.range_end = 0, |
| 236 |
}, |
| 237 |
{ |
| 238 |
.header_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=5-"), |
| 239 |
.has_start_range = true, |
| 240 |
.has_end_range = false, |
| 241 |
.range_start = 5, |
| 242 |
.range_end = 0, |
| 243 |
}, |
| 244 |
{ |
| 245 |
.header_value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=-10"), |
| 246 |
.has_start_range = false, |
| 247 |
.has_end_range = true, |
| 248 |
.range_start = 0, |
| 249 |
.range_end = 10, |
| 250 |
}, |
| 251 |
}; |
| 252 |
|
| 253 |
const struct aws_byte_cursor invalid_range_header_values[] = { |
| 254 |
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=-"), |
| 255 |
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes=10-5"), |
| 256 |
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("byts=0-5"), |
| 257 |
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("5-10"), |
| 258 |
}; |
| 259 |
bool has_start_range = false; |
| 260 |
bool has_end_range = false; |
| 261 |
uint64_t range_start = 0; |
| 262 |
uint64_t range_end = 0; |
| 263 |
|
| 264 |
struct aws_http_headers *headers = aws_http_headers_new(allocator); |
| 265 |
|
| 266 |
ASSERT_FAILS( |
| 267 |
aws_s3_parse_request_range_header(headers, &has_start_range, &has_end_range, &range_start, &range_end)); |
| 268 |
|
| 269 |
|
| 270 |
for (size_t i = 0; i < AWS_ARRAY_SIZE(valid_range_examples); ++i) { |
| 271 |
printf("valid example [%zu]: " PRInSTR "\n", i, AWS_BYTE_CURSOR_PRI(valid_range_examples[i].header_value)); |
| 272 |
|
| 273 |
aws_http_headers_set(headers, g_range_header_name, valid_range_examples[i].header_value); |
| 274 |
|
| 275 |
ASSERT_SUCCESS( |
| 276 |
aws_s3_parse_request_range_header(headers, &has_start_range, &has_end_range, &range_start, &range_end)); |
| 277 |
|
| 278 |
ASSERT_INT_EQUALS(valid_range_examples[i].has_start_range, has_start_range); |
| 279 |
ASSERT_INT_EQUALS(valid_range_examples[i].has_end_range, has_end_range); |
| 280 |
ASSERT_INT_EQUALS(valid_range_examples[i].range_start, range_start); |
| 281 |
ASSERT_INT_EQUALS(valid_range_examples[i].range_end, range_end); |
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
for (size_t i = 0; i < AWS_ARRAY_SIZE(invalid_range_header_values); ++i) { |
| 286 |
printf("invalid example [%zu]: " PRInSTR "\n", i, AWS_BYTE_CURSOR_PRI(invalid_range_header_values[i])); |
| 287 |
|
| 288 |
aws_http_headers_set(headers, g_range_header_name, invalid_range_header_values[i]); |
| 289 |
|
| 290 |
ASSERT_FAILS( |
| 291 |
aws_s3_parse_request_range_header(headers, &has_start_range, &has_end_range, &range_start, &range_end)); |
| 292 |
} |
| 293 |
|
| 294 |
aws_http_headers_release(headers); |
| 295 |
|
| 296 |
return 0; |
| 297 |
} |
| 298 |
|
| 299 |
AWS_TEST_CASE(test_s3_parse_content_range_response_header, s_test_s3_parse_content_range_response_header) |
| 300 |
static int s_test_s3_parse_content_range_response_header(struct aws_allocator *allocator, void *ctx) { |
| 301 |
(void)ctx; |
| 302 |
|
| 303 |
const struct aws_http_header content_range_header = { |
| 304 |
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Range"), |
| 305 |
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes 55-100/12345"), |
| 306 |
}; |
| 307 |
|
| 308 |
const struct aws_http_header invalid_content_range_header = { |
| 309 |
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Range"), |
| 310 |
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("bytes 55-100/"), |
| 311 |
}; |
| 312 |
|
| 313 |
struct aws_http_headers *response_headers = aws_http_headers_new(allocator); |
| 314 |
|
| 315 |
|
| 316 |
{ |
| 317 |
uint64_t object_size = 0ULL; |
| 318 |
|
| 319 |
ASSERT_FAILS(aws_s3_parse_content_range_response_header(response_headers, NULL, NULL, &object_size)); |
| 320 |
ASSERT_TRUE(aws_last_error() == AWS_ERROR_S3_MISSING_CONTENT_RANGE_HEADER); |
| 321 |
} |
| 322 |
|
| 323 |
aws_http_headers_add_header(response_headers, &content_range_header); |
| 324 |
|
| 325 |
|
| 326 |
{ |
| 327 |
uint64_t object_size = 0ULL; |
| 328 |
uint64_t range_start = 0ULL; |
| 329 |
uint64_t range_end = 0ULL; |
| 330 |
|
| 331 |
ASSERT_SUCCESS( |
| 332 |
aws_s3_parse_content_range_response_header(response_headers, &range_start, &range_end, &object_size)); |
| 333 |
ASSERT_TRUE(range_start == 55ULL); |
| 334 |
ASSERT_TRUE(range_end == 100ULL); |
| 335 |
ASSERT_TRUE(object_size == 12345ULL); |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
{ |
| 340 |
uint64_t object_size = 0ULL; |
| 341 |
|
| 342 |
ASSERT_SUCCESS(aws_s3_parse_content_range_response_header(response_headers, NULL, NULL, &object_size)); |
| 343 |
ASSERT_TRUE(object_size == 12345ULL); |
| 344 |
} |
| 345 |
|
| 346 |
aws_http_headers_set(response_headers, invalid_content_range_header.name, invalid_content_range_header.value); |
| 347 |
|
| 348 |
|
| 349 |
{ |
| 350 |
uint64_t object_size = 0ULL; |
| 351 |
ASSERT_FAILS(aws_s3_parse_content_range_response_header(response_headers, NULL, NULL, &object_size)); |
| 352 |
ASSERT_TRUE(aws_last_error() == AWS_ERROR_S3_INVALID_CONTENT_RANGE_HEADER); |
| 353 |
} |
| 354 |
|
| 355 |
aws_http_headers_release(response_headers); |
| 356 |
|
| 357 |
return 0; |
| 358 |
} |
| 359 |
|
| 360 |
AWS_TEST_CASE(test_s3_parse_content_length_response_header, s_test_s3_parse_content_length_response_header) |
| 361 |
static int s_test_s3_parse_content_length_response_header(struct aws_allocator *allocator, void *ctx) { |
| 362 |
(void)ctx; |
| 363 |
|
| 364 |
struct aws_http_headers *response_headers = aws_http_headers_new(allocator); |
| 365 |
|
| 366 |
const struct aws_http_header valid_content_length_header = { |
| 367 |
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Length"), |
| 368 |
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("12345"), |
| 369 |
}; |
| 370 |
|
| 371 |
const struct aws_http_header invalid_content_length_header = { |
| 372 |
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("Content-Length"), |
| 373 |
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(""), |
| 374 |
}; |
| 375 |
|
| 376 |
|
| 377 |
{ |
| 378 |
uint64_t content_length = 0ULL; |
| 379 |
ASSERT_FAILS(aws_s3_parse_content_length_response_header(allocator, response_headers, &content_length)); |
| 380 |
ASSERT_TRUE(aws_last_error() == AWS_ERROR_S3_MISSING_CONTENT_LENGTH_HEADER); |
| 381 |
} |
| 382 |
|
| 383 |
aws_http_headers_add_header(response_headers, &valid_content_length_header); |
| 384 |
|
| 385 |
|
| 386 |
{ |
| 387 |
uint64_t content_length = 0ULL; |
| 388 |
ASSERT_SUCCESS(aws_s3_parse_content_length_response_header(allocator, response_headers, &content_length)); |
| 389 |
ASSERT_TRUE(content_length == 12345ULL); |
| 390 |
} |
| 391 |
|
| 392 |
aws_http_headers_set(response_headers, invalid_content_length_header.name, invalid_content_length_header.value); |
| 393 |
|
| 394 |
|
| 395 |
{ |
| 396 |
uint64_t content_length = 0ULL; |
| 397 |
ASSERT_FAILS(aws_s3_parse_content_length_response_header(allocator, response_headers, &content_length)); |
| 398 |
ASSERT_TRUE(aws_last_error() == AWS_ERROR_S3_INVALID_CONTENT_LENGTH_HEADER); |
| 399 |
} |
| 400 |
|
| 401 |
aws_http_headers_release(response_headers); |
| 402 |
|
| 403 |
return 0; |
| 404 |
} |
| 405 |
|
| 406 |
static int s_validate_part_ranges( |
| 407 |
uint64_t object_range_start, |
| 408 |
uint64_t object_range_end, |
| 409 |
size_t part_size, |
| 410 |
uint32_t num_parts, |
| 411 |
const uint64_t *part_ranges) { |
| 412 |
ASSERT_TRUE(part_ranges != NULL); |
| 413 |
uint64_t aligned_first_part_size = part_size - (object_range_start % part_size); |
| 414 |
for (uint32_t i = 0; i < num_parts; ++i) { |
| 415 |
uint64_t part_range_start = 0ULL; |
| 416 |
uint64_t part_range_end = 0ULL; |
| 417 |
|
| 418 |
aws_s3_calculate_auto_ranged_get_part_range( |
| 419 |
object_range_start, |
| 420 |
object_range_end, |
| 421 |
part_size, |
| 422 |
aligned_first_part_size, |
| 423 |
i + 1, |
| 424 |
&part_range_start, |
| 425 |
&part_range_end); |
| 426 |
|
| 427 |
ASSERT_TRUE(part_range_start == part_ranges[i * 2]); |
| 428 |
ASSERT_TRUE(part_range_end == part_ranges[i * 2 + 1]); |
| 429 |
} |
| 430 |
|
| 431 |
return AWS_OP_SUCCESS; |
| 432 |
} |
| 433 |
|
| 434 |
AWS_TEST_CASE(test_s3_get_num_parts_and_get_part_range, s_test_s3_get_num_parts_and_get_part_range) |
| 435 |
static int s_test_s3_get_num_parts_and_get_part_range(struct aws_allocator *allocator, void *ctx) { |
| 436 |
(void)allocator; |
| 437 |
(void)ctx; |
| 438 |
|
| 439 |
const size_t part_size = 16 * 1024; |
| 440 |
|
| 441 |
|
| 442 |
{ |
| 443 |
const uint32_t expected_num_parts = 1; |
| 444 |
const uint64_t object_range_start = 0; |
| 445 |
const uint64_t object_range_end = 0; |
| 446 |
|
| 447 |
ASSERT_INT_EQUALS( |
| 448 |
aws_s3_calculate_auto_ranged_get_num_parts(part_size, 0, object_range_start, object_range_end), |
| 449 |
expected_num_parts); |
| 450 |
} |
| 451 |
|
| 452 |
|
| 453 |
{ |
| 454 |
const uint32_t expected_num_parts = 2; |
| 455 |
const uint64_t first_part_size = 2; |
| 456 |
const uint64_t object_range_start = 0; |
| 457 |
const uint64_t object_range_end = 5; |
| 458 |
|
| 459 |
const uint64_t part_ranges[] = { |
| 460 |
0, |
| 461 |
1, |
| 462 |
|
| 463 |
2, |
| 464 |
5, |
| 465 |
}; |
| 466 |
|
| 467 |
ASSERT_INT_EQUALS( |
| 468 |
aws_s3_calculate_auto_ranged_get_num_parts( |
| 469 |
part_size, first_part_size, object_range_start, object_range_end), |
| 470 |
expected_num_parts); |
| 471 |
|
| 472 |
uint64_t part_range_start, part_range_end; |
| 473 |
aws_s3_calculate_auto_ranged_get_part_range( |
| 474 |
object_range_start, object_range_end, part_size, first_part_size, 1, &part_range_start, &part_range_end); |
| 475 |
|
| 476 |
ASSERT_INT_EQUALS(part_range_start, part_ranges[0]); |
| 477 |
ASSERT_INT_EQUALS(part_range_end, part_ranges[1]); |
| 478 |
|
| 479 |
aws_s3_calculate_auto_ranged_get_part_range( |
| 480 |
object_range_start, object_range_end, part_size, first_part_size, 2, &part_range_start, &part_range_end); |
| 481 |
|
| 482 |
ASSERT_INT_EQUALS(part_range_start, part_ranges[2]); |
| 483 |
ASSERT_INT_EQUALS(part_range_end, part_ranges[3]); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
{ |
| 488 |
const uint32_t expected_num_parts = 2; |
| 489 |
const uint64_t object_range_start = 0; |
| 490 |
const uint64_t object_range_end = |
| 491 |
(object_range_start + (uint64_t)part_size * (uint64_t)expected_num_parts) - 1ULL; |
| 492 |
|
| 493 |
const uint64_t part_ranges[] = { |
| 494 |
0, |
| 495 |
(uint64_t)part_size - 1ULL, |
| 496 |
|
| 497 |
(uint64_t)part_size, |
| 498 |
(uint64_t)part_size * 2ULL - 1ULL, |
| 499 |
}; |
| 500 |
|
| 501 |
ASSERT_TRUE( |
| 502 |
aws_s3_calculate_auto_ranged_get_num_parts(part_size, part_size, object_range_start, object_range_end) == |
| 503 |
expected_num_parts); |
| 504 |
|
| 505 |
ASSERT_SUCCESS( |
| 506 |
s_validate_part_ranges(object_range_start, object_range_end, part_size, expected_num_parts, part_ranges)); |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
{ |
| 511 |
const uint32_t expected_num_parts = 3; |
| 512 |
const uint64_t half_part_size = part_size >> 1ULL; |
| 513 |
const uint64_t object_range_start = half_part_size; |
| 514 |
const uint64_t object_range_end = (object_range_start + half_part_size + (uint64_t)part_size * 2ULL) - 1ULL; |
| 515 |
uint64_t aligned_first_part_size = part_size - (object_range_start % part_size); |
| 516 |
|
| 517 |
const uint64_t part_ranges[] = { |
| 518 |
object_range_start, |
| 519 |
object_range_start + half_part_size - 1, |
| 520 |
|
| 521 |
object_range_start + half_part_size, |
| 522 |
object_range_start + half_part_size + (uint64_t)part_size - 1ULL, |
| 523 |
|
| 524 |
object_range_start + half_part_size + (uint64_t)part_size, |
| 525 |
object_range_start + half_part_size + (uint64_t)part_size * 2ULL - 1ULL, |
| 526 |
}; |
| 527 |
|
| 528 |
ASSERT_TRUE( |
| 529 |
aws_s3_calculate_auto_ranged_get_num_parts( |
| 530 |
part_size, aligned_first_part_size, object_range_start, object_range_end) == expected_num_parts); |
| 531 |
|
| 532 |
ASSERT_SUCCESS( |
| 533 |
s_validate_part_ranges(object_range_start, object_range_end, part_size, expected_num_parts, part_ranges)); |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
{ |
| 538 |
const uint32_t expected_num_parts = 4; |
| 539 |
const uint64_t half_part_size = part_size >> 1ULL; |
| 540 |
const uint64_t object_range_start = half_part_size; |
| 541 |
const uint64_t object_range_end = |
| 542 |
(object_range_start + half_part_size + (uint64_t)part_size * 2ULL + half_part_size) - 1ULL; |
| 543 |
uint64_t aligned_first_part_size = part_size - (object_range_start % part_size); |
| 544 |
|
| 545 |
const uint64_t part_ranges[] = { |
| 546 |
object_range_start, |
| 547 |
object_range_start + half_part_size - 1, |
| 548 |
|
| 549 |
object_range_start + half_part_size, |
| 550 |
object_range_start + half_part_size + (uint64_t)part_size - 1ULL, |
| 551 |
|
| 552 |
object_range_start + half_part_size + (uint64_t)part_size, |
| 553 |
object_range_start + half_part_size + (uint64_t)part_size * 2ULL - 1ULL, |
| 554 |
|
| 555 |
object_range_start + half_part_size + (uint64_t)part_size * 2ULL, |
| 556 |
object_range_start + half_part_size + (uint64_t)part_size * 2ULL + half_part_size - 1ULL, |
| 557 |
}; |
| 558 |
|
| 559 |
ASSERT_TRUE( |
| 560 |
aws_s3_calculate_auto_ranged_get_num_parts( |
| 561 |
part_size, aligned_first_part_size, object_range_start, object_range_end) == expected_num_parts); |
| 562 |
|
| 563 |
ASSERT_SUCCESS( |
| 564 |
s_validate_part_ranges(object_range_start, object_range_end, part_size, expected_num_parts, part_ranges)); |
| 565 |
} |
| 566 |
|
| 567 |
|
| 568 |
{ |
| 569 |
const uint32_t expected_num_parts = 1; |
| 570 |
const uint64_t object_range_start = 8; |
| 571 |
const uint64_t object_range_end = 8; |
| 572 |
uint64_t aligned_first_part_size = part_size - (object_range_start % part_size); |
| 573 |
|
| 574 |
const uint64_t part_ranges[] = {8, 8}; |
| 575 |
|
| 576 |
ASSERT_TRUE( |
| 577 |
aws_s3_calculate_auto_ranged_get_num_parts( |
| 578 |
part_size, aligned_first_part_size, object_range_start, object_range_end) == expected_num_parts); |
| 579 |
|
| 580 |
ASSERT_SUCCESS( |
| 581 |
s_validate_part_ranges(object_range_start, object_range_end, part_size, expected_num_parts, part_ranges)); |
| 582 |
} |
| 583 |
|
| 584 |
return 0; |
| 585 |
} |
| 586 |
|
| 587 |
struct s3_request_part_config_example { |
| 588 |
const char *name; |
| 589 |
uint64_t content_length; |
| 590 |
size_t client_part_size; |
| 591 |
uint64_t client_max_part_size; |
| 592 |
size_t expected_part_size; |
| 593 |
uint32_t expected_num_parts; |
| 594 |
}; |
| 595 |
|
| 596 |
AWS_TEST_CASE(test_s3_mpu_get_part_size_and_num_parts, s_test_s3_mpu_get_part_size_and_num_parts) |
| 597 |
static int s_test_s3_mpu_get_part_size_and_num_parts(struct aws_allocator *allocator, void *ctx) { |
| 598 |
(void)allocator; |
| 599 |
(void)ctx; |
| 600 |
uint64_t default_max_part_size = 5368709120ULL; |
| 601 |
|
| 602 |
const struct s3_request_part_config_example valid_request_part_config[] = { |
| 603 |
{ |
| 604 |
.name = "simple case", |
| 605 |
.content_length = MB_TO_BYTES((uint64_t)10000), |
| 606 |
.client_part_size = MB_TO_BYTES(5), |
| 607 |
.client_max_part_size = default_max_part_size, |
| 608 |
.expected_part_size = 5242880, |
| 609 |
.expected_num_parts = 2000, |
| 610 |
}, |
| 611 |
{ |
| 612 |
.name = "large content length with small part size", |
| 613 |
.content_length = MB_TO_BYTES((uint64_t)990000), |
| 614 |
.client_part_size = MB_TO_BYTES(5), |
| 615 |
.client_max_part_size = default_max_part_size, |
| 616 |
.expected_part_size = 103809024, |
| 617 |
.expected_num_parts = 10000, |
| 618 |
}, |
| 619 |
{ |
| 620 |
|
| 621 |
.name = "large content length with large part size", |
| 622 |
.content_length = MB_TO_BYTES((uint64_t)1000000), |
| 623 |
.client_part_size = MB_TO_BYTES(500), |
| 624 |
.client_max_part_size = default_max_part_size, |
| 625 |
.expected_part_size = MB_TO_BYTES(500), |
| 626 |
.expected_num_parts = 2000, |
| 627 |
}, |
| 628 |
{ |
| 629 |
.name = "large odd content length", |
| 630 |
.content_length = 1044013645824, |
| 631 |
.client_part_size = 5242880, |
| 632 |
.client_max_part_size = default_max_part_size, |
| 633 |
.expected_part_size = 104401365, |
| 634 |
.expected_num_parts = 10000, |
| 635 |
}, |
| 636 |
{ |
| 637 |
.name = "10k parts", |
| 638 |
.content_length = MB_TO_BYTES((uint64_t)50000), |
| 639 |
.client_part_size = MB_TO_BYTES(5), |
| 640 |
.client_max_part_size = default_max_part_size, |
| 641 |
.expected_part_size = MB_TO_BYTES(5), |
| 642 |
.expected_num_parts = 10000, |
| 643 |
}, |
| 644 |
{ |
| 645 |
.name = "10k - 1 parts", |
| 646 |
.content_length = 49995, |
| 647 |
.client_part_size = 5, |
| 648 |
.client_max_part_size = default_max_part_size, |
| 649 |
.expected_part_size = 5, |
| 650 |
.expected_num_parts = 9999, |
| 651 |
}, |
| 652 |
{ |
| 653 |
.name = "10k with small last part", |
| 654 |
.content_length = 49998, |
| 655 |
.client_part_size = 5, |
| 656 |
.client_max_part_size = default_max_part_size, |
| 657 |
.expected_part_size = 5, |
| 658 |
.expected_num_parts = 10000, |
| 659 |
}, |
| 660 |
{ |
| 661 |
.name = "10k + 1 parts", |
| 662 |
.content_length = 50001, |
| 663 |
.client_part_size = 5, |
| 664 |
.client_max_part_size = default_max_part_size, |
| 665 |
.expected_part_size = 6, |
| 666 |
.expected_num_parts = 8334, |
| 667 |
|
| 668 |
}, |
| 669 |
{ |
| 670 |
.name = "bump content length", |
| 671 |
.content_length = 100000, |
| 672 |
.client_part_size = 5, |
| 673 |
.client_max_part_size = default_max_part_size, |
| 674 |
.expected_part_size = 10, |
| 675 |
.expected_num_parts = 10000, |
| 676 |
}, |
| 677 |
{ |
| 678 |
.name = "bump content length with non-zero mod", |
| 679 |
.content_length = 999999, |
| 680 |
.client_part_size = 5, |
| 681 |
.client_max_part_size = default_max_part_size, |
| 682 |
.expected_part_size = 100, |
| 683 |
.expected_num_parts = 10000, |
| 684 |
}, |
| 685 |
{ |
| 686 |
.name = "5 tb content length", |
| 687 |
.content_length = MB_TO_BYTES((uint64_t)5 * 1024 * 1024), |
| 688 |
.client_part_size = MB_TO_BYTES((uint64_t)5), |
| 689 |
.client_max_part_size = default_max_part_size, |
| 690 |
.expected_part_size = 549755814, |
| 691 |
.expected_num_parts = 10000, |
| 692 |
}, |
| 693 |
}; |
| 694 |
for (size_t i = 0; i < AWS_ARRAY_SIZE(valid_request_part_config); ++i) { |
| 695 |
AWS_LOGF_INFO(AWS_LS_S3_GENERAL, "valid example [%zu]: %s\n", i, valid_request_part_config[i].name); |
| 696 |
|
| 697 |
uint64_t content_length = valid_request_part_config[i].content_length; |
| 698 |
size_t part_size; |
| 699 |
uint32_t num_parts; |
| 700 |
|
| 701 |
ASSERT_SUCCESS(aws_s3_calculate_optimal_mpu_part_size_and_num_parts( |
| 702 |
content_length, |
| 703 |
valid_request_part_config[i].client_part_size, |
| 704 |
valid_request_part_config[i].client_max_part_size, |
| 705 |
&part_size, |
| 706 |
&num_parts)); |
| 707 |
ASSERT_INT_EQUALS(valid_request_part_config[i].expected_part_size, part_size); |
| 708 |
ASSERT_INT_EQUALS(valid_request_part_config[i].expected_num_parts, num_parts); |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
const struct s3_request_part_config_example invalid_request_part_config[] = {{ |
| 713 |
.name = "max part < required part size", |
| 714 |
.content_length = 900000, |
| 715 |
.client_part_size = 5, |
| 716 |
.client_max_part_size = 10, |
| 717 |
}}; |
| 718 |
|
| 719 |
for (size_t i = 0; i < AWS_ARRAY_SIZE(invalid_request_part_config); ++i) { |
| 720 |
printf("invalid example [%zu]: %s\n", i, invalid_request_part_config[i].name); |
| 721 |
size_t part_size; |
| 722 |
uint32_t num_parts; |
| 723 |
ASSERT_FAILS(aws_s3_calculate_optimal_mpu_part_size_and_num_parts( |
| 724 |
invalid_request_part_config[i].content_length, |
| 725 |
invalid_request_part_config[i].client_part_size, |
| 726 |
invalid_request_part_config[i].client_max_part_size, |
| 727 |
&part_size, |
| 728 |
&num_parts)); |
| 729 |
} |
| 730 |
return AWS_OP_SUCCESS; |
| 731 |
} |
| 732 |
|
| 733 |
AWS_TEST_CASE(test_s3_aws_xml_get_body_at_path, s_test_s3_aws_xml_get_body_at_path) |
| 734 |
static int s_test_s3_aws_xml_get_body_at_path(struct aws_allocator *allocator, void *ctx) { |
| 735 |
(void)allocator; |
| 736 |
(void)ctx; |
| 737 |
|
| 738 |
struct aws_byte_cursor example_error_body = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL( |
| 739 |
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" |
| 740 |
"<Error>\n" |
| 741 |
"<Code>AccessDenied</Code>\n" |
| 742 |
"<Message>Access Denied</Message>\n" |
| 743 |
"<RequestId>656c76696e6727732072657175657374</RequestId>\n" |
| 744 |
"<HostId>Uuag1LuByRx9e6j5Onimru9pO4ZVKnJ2Qz7/C1NPcfTWAtRPfTaOFg==</HostId>\n" |
| 745 |
"</Error>"); |
| 746 |
|
| 747 |
|
| 748 |
{ |
| 749 |
struct aws_byte_cursor error_code = {0}; |
| 750 |
const char *xml_path[] = {"Error", "Code", NULL}; |
| 751 |
|
| 752 |
ASSERT_SUCCESS(aws_xml_get_body_at_path(allocator, example_error_body, xml_path, &error_code)); |
| 753 |
ASSERT_CURSOR_VALUE_CSTRING_EQUALS(error_code, "AccessDenied"); |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
{ |
| 758 |
struct aws_byte_cursor error_code = {0}; |
| 759 |
const char *xml_path[] = {"ObviouslyInvalidName", "Code", NULL}; |
| 760 |
ASSERT_ERROR( |
| 761 |
AWS_ERROR_STRING_MATCH_NOT_FOUND, |
| 762 |
aws_xml_get_body_at_path(allocator, example_error_body, xml_path, &error_code)); |
| 763 |
} |
| 764 |
|
| 765 |
|
| 766 |
{ |
| 767 |
struct aws_byte_cursor error_code = {0}; |
| 768 |
const char *xml_path[] = {"Error", "ObviouslyInvalidName", NULL}; |
| 769 |
ASSERT_ERROR( |
| 770 |
AWS_ERROR_STRING_MATCH_NOT_FOUND, |
| 771 |
aws_xml_get_body_at_path(allocator, example_error_body, xml_path, &error_code)); |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
{ |
| 776 |
struct aws_byte_cursor error_code = {0}; |
| 777 |
const char *xml_path[] = {"Error", "Code", NULL}; |
| 778 |
ASSERT_ERROR( |
| 779 |
AWS_ERROR_INVALID_XML, |
| 780 |
aws_xml_get_body_at_path( |
| 781 |
allocator, aws_byte_cursor_from_c_str("Obviously invalid XML document"), xml_path, &error_code)); |
| 782 |
} |
| 783 |
return AWS_OP_SUCCESS; |
| 784 |
} |
| 785 |
|
| 786 |
AWS_TEST_CASE(test_s3_calculate_client_optimal_range_size, s_test_s3_calculate_client_optimal_range_size) |
| 787 |
static int s_test_s3_calculate_client_optimal_range_size(struct aws_allocator *allocator, void *ctx) { |
| 788 |
(void)ctx; |
| 789 |
aws_s3_library_init(allocator); |
| 790 |
|
| 791 |
uint64_t client_optimal_range_size = 0; |
| 792 |
|
| 793 |
|
| 794 |
{ |
| 795 |
uint64_t memory_limit = GB_TO_BYTES(1); |
| 796 |
uint32_t max_connections = 10; |
| 797 |
|
| 798 |
ASSERT_SUCCESS( |
| 799 |
aws_s3_calculate_client_optimal_range_size(memory_limit, max_connections, &client_optimal_range_size)); |
| 800 |
|
| 801 |
|
| 802 |
uint64_t memory_constrained = memory_limit / max_connections / 3; |
| 803 |
uint64_t expected = |
| 804 |
(memory_constrained < g_default_part_size_fallback) ? g_default_part_size_fallback : memory_constrained; |
| 805 |
ASSERT_UINT_EQUALS(expected, client_optimal_range_size); |
| 806 |
} |
| 807 |
|
| 808 |
|
| 809 |
{ |
| 810 |
uint64_t memory_limit = MB_TO_BYTES(100); |
| 811 |
uint32_t max_connections = 10; |
| 812 |
|
| 813 |
ASSERT_SUCCESS( |
| 814 |
aws_s3_calculate_client_optimal_range_size(memory_limit, max_connections, &client_optimal_range_size)); |
| 815 |
|
| 816 |
|
| 817 |
uint64_t expected = g_default_part_size_fallback; |
| 818 |
ASSERT_UINT_EQUALS(expected, client_optimal_range_size); |
| 819 |
} |
| 820 |
|
| 821 |
|
| 822 |
{ |
| 823 |
uint64_t memory_limit = GB_TO_BYTES(1); |
| 824 |
uint32_t max_connections = 50; |
| 825 |
|
| 826 |
ASSERT_SUCCESS( |
| 827 |
aws_s3_calculate_client_optimal_range_size(memory_limit, max_connections, &client_optimal_range_size)); |
| 828 |
|
| 829 |
|
| 830 |
uint64_t expected = g_default_part_size_fallback; |
| 831 |
ASSERT_UINT_EQUALS(expected, client_optimal_range_size); |
| 832 |
} |
| 833 |
|
| 834 |
|
| 835 |
{ |
| 836 |
uint64_t memory_limit = MB_TO_BYTES(300); |
| 837 |
uint32_t max_connections = 10; |
| 838 |
|
| 839 |
ASSERT_SUCCESS( |
| 840 |
aws_s3_calculate_client_optimal_range_size(memory_limit, max_connections, &client_optimal_range_size)); |
| 841 |
|
| 842 |
|
| 843 |
uint64_t memory_constrained = memory_limit / max_connections / 3; |
| 844 |
uint64_t expected = |
| 845 |
(memory_constrained < g_default_part_size_fallback) ? g_default_part_size_fallback : memory_constrained; |
| 846 |
ASSERT_UINT_EQUALS(expected, client_optimal_range_size); |
| 847 |
} |
| 848 |
|
| 849 |
|
| 850 |
{ |
| 851 |
uint64_t memory_limit = 0; |
| 852 |
uint32_t max_connections = 10; |
| 853 |
|
| 854 |
ASSERT_ERROR( |
| 855 |
AWS_ERROR_INVALID_ARGUMENT, |
| 856 |
aws_s3_calculate_client_optimal_range_size(memory_limit, max_connections, &client_optimal_range_size)); |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
{ |
| 861 |
uint64_t memory_limit = GB_TO_BYTES(1); |
| 862 |
uint32_t max_connections = 0; |
| 863 |
|
| 864 |
ASSERT_ERROR( |
| 865 |
AWS_ERROR_INVALID_ARGUMENT, |
| 866 |
aws_s3_calculate_client_optimal_range_size(memory_limit, max_connections, &client_optimal_range_size)); |
| 867 |
} |
| 868 |
|
| 869 |
aws_s3_library_clean_up(); |
| 870 |
return 0; |
| 871 |
} |
| 872 |
|
| 873 |
AWS_TEST_CASE(test_s3_calculate_request_optimal_range_size, s_test_s3_calculate_request_optimal_range_size) |
| 874 |
static int s_test_s3_calculate_request_optimal_range_size(struct aws_allocator *allocator, void *ctx) { |
| 875 |
(void)ctx; |
| 876 |
aws_s3_library_init(allocator); |
| 877 |
|
| 878 |
uint64_t request_optimal_range_size = 0; |
| 879 |
|
| 880 |
|
| 881 |
{ |
| 882 |
uint64_t client_optimal_range_size = MB_TO_BYTES(160); |
| 883 |
uint64_t estimated_part_size = MB_TO_BYTES(200); |
| 884 |
|
| 885 |
ASSERT_SUCCESS(aws_s3_calculate_request_optimal_range_size( |
| 886 |
client_optimal_range_size, estimated_part_size, false, &request_optimal_range_size)); |
| 887 |
|
| 888 |
|
| 889 |
uint64_t expected = client_optimal_range_size; |
| 890 |
ASSERT_UINT_EQUALS(expected, request_optimal_range_size); |
| 891 |
} |
| 892 |
|
| 893 |
|
| 894 |
{ |
| 895 |
uint64_t client_optimal_range_size = MB_TO_BYTES(64); |
| 896 |
uint64_t estimated_part_size = MB_TO_BYTES(50); |
| 897 |
|
| 898 |
ASSERT_SUCCESS(aws_s3_calculate_request_optimal_range_size( |
| 899 |
client_optimal_range_size, estimated_part_size, false, &request_optimal_range_size)); |
| 900 |
|
| 901 |
|
| 902 |
uint64_t smaller_size = estimated_part_size; |
| 903 |
uint64_t expected = (smaller_size < g_default_part_size_fallback) ? g_default_part_size_fallback : smaller_size; |
| 904 |
ASSERT_UINT_EQUALS(expected, request_optimal_range_size); |
| 905 |
} |
| 906 |
|
| 907 |
|
| 908 |
{ |
| 909 |
uint64_t client_optimal_range_size = MB_TO_BYTES(160); |
| 910 |
uint64_t estimated_part_size = MB_TO_BYTES(1); |
| 911 |
|
| 912 |
ASSERT_SUCCESS(aws_s3_calculate_request_optimal_range_size( |
| 913 |
client_optimal_range_size, estimated_part_size, false, &request_optimal_range_size)); |
| 914 |
|
| 915 |
|
| 916 |
uint64_t expected = g_default_part_size_fallback; |
| 917 |
ASSERT_UINT_EQUALS(expected, request_optimal_range_size); |
| 918 |
} |
| 919 |
|
| 920 |
|
| 921 |
{ |
| 922 |
uint64_t client_optimal_range_size = MB_TO_BYTES(160); |
| 923 |
uint64_t estimated_part_size = 0; |
| 924 |
|
| 925 |
ASSERT_SUCCESS(aws_s3_calculate_request_optimal_range_size( |
| 926 |
client_optimal_range_size, estimated_part_size, false, &request_optimal_range_size)); |
| 927 |
|
| 928 |
|
| 929 |
uint64_t expected = client_optimal_range_size; |
| 930 |
ASSERT_UINT_EQUALS(expected, request_optimal_range_size); |
| 931 |
} |
| 932 |
|
| 933 |
|
| 934 |
{ |
| 935 |
uint64_t client_optimal_range_size = MB_TO_BYTES(40); |
| 936 |
uint64_t estimated_part_size = MB_TO_BYTES(9); |
| 937 |
|
| 938 |
ASSERT_SUCCESS(aws_s3_calculate_request_optimal_range_size( |
| 939 |
client_optimal_range_size, estimated_part_size, false, &request_optimal_range_size)); |
| 940 |
|
| 941 |
|
| 942 |
uint64_t smaller_size = estimated_part_size; |
| 943 |
uint64_t expected = (smaller_size < g_default_part_size_fallback) ? g_default_part_size_fallback : smaller_size; |
| 944 |
ASSERT_UINT_EQUALS(expected, request_optimal_range_size); |
| 945 |
} |
| 946 |
|
| 947 |
|
| 948 |
{ |
| 949 |
uint64_t client_optimal_range_size = 0; |
| 950 |
uint64_t estimated_part_size = MB_TO_BYTES(100); |
| 951 |
|
| 952 |
ASSERT_ERROR( |
| 953 |
AWS_ERROR_INVALID_ARGUMENT, |
| 954 |
aws_s3_calculate_request_optimal_range_size( |
| 955 |
client_optimal_range_size, estimated_part_size, false, &request_optimal_range_size)); |
| 956 |
} |
| 957 |
|
| 958 |
aws_s3_library_clean_up(); |
| 959 |
return 0; |
| 960 |
} |
| 961 |
|
| 962 |
AWS_TEST_CASE(test_s3_extract_parts_from_etag, s_test_s3_extract_parts_from_etag) |
| 963 |
static int s_test_s3_extract_parts_from_etag(struct aws_allocator *allocator, void *ctx) { |
| 964 |
(void)ctx; |
| 965 |
aws_s3_library_init(allocator); |
| 966 |
|
| 967 |
uint32_t num_parts = 0; |
| 968 |
|
| 969 |
|
| 970 |
{ |
| 971 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("\"d41d8cd98f00b204e9800998ecf8427e\""); |
| 972 |
ASSERT_SUCCESS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 973 |
ASSERT_UINT_EQUALS(1, num_parts); |
| 974 |
} |
| 975 |
|
| 976 |
|
| 977 |
{ |
| 978 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("d41d8cd98f00b204e9800998ecf8427e"); |
| 979 |
ASSERT_SUCCESS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 980 |
ASSERT_UINT_EQUALS(1, num_parts); |
| 981 |
} |
| 982 |
|
| 983 |
|
| 984 |
{ |
| 985 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("\"d41d8cd98f00b204e9800998ecf8427e-5\""); |
| 986 |
ASSERT_SUCCESS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 987 |
ASSERT_UINT_EQUALS(5, num_parts); |
| 988 |
} |
| 989 |
|
| 990 |
|
| 991 |
{ |
| 992 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("d41d8cd98f00b204e9800998ecf8427e-123"); |
| 993 |
ASSERT_SUCCESS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 994 |
ASSERT_UINT_EQUALS(123, num_parts); |
| 995 |
} |
| 996 |
|
| 997 |
|
| 998 |
{ |
| 999 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("d41d8cd98f00b204e9800998ecf8427e-10000"); |
| 1000 |
ASSERT_SUCCESS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1001 |
ASSERT_UINT_EQUALS(10000, num_parts); |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
{ |
| 1006 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str(""); |
| 1007 |
ASSERT_FAILS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1008 |
} |
| 1009 |
|
| 1010 |
|
| 1011 |
{ |
| 1012 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("d41d8cd98f00b204e9800998ecf8427e-5-extra"); |
| 1013 |
ASSERT_FAILS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1014 |
} |
| 1015 |
|
| 1016 |
|
| 1017 |
{ |
| 1018 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("d41d8cd98f00b204e9800998ecf8427e-abc"); |
| 1019 |
ASSERT_FAILS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1020 |
} |
| 1021 |
|
| 1022 |
|
| 1023 |
{ |
| 1024 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("d41d8cd98f00b204e9800998ecf8427e-0"); |
| 1025 |
ASSERT_FAILS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
{ |
| 1030 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("d41d8cd98f00b204e9800998ecf8427e-10001"); |
| 1031 |
ASSERT_FAILS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1032 |
} |
| 1033 |
|
| 1034 |
|
| 1035 |
{ |
| 1036 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("\"\""); |
| 1037 |
ASSERT_FAILS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1038 |
} |
| 1039 |
|
| 1040 |
|
| 1041 |
{ |
| 1042 |
struct aws_byte_cursor etag = aws_byte_cursor_from_c_str("\""); |
| 1043 |
ASSERT_FAILS(aws_s3_extract_parts_from_etag(etag, &num_parts)); |
| 1044 |
} |
| 1045 |
|
| 1046 |
aws_s3_library_clean_up(); |
| 1047 |
return 0; |
| 1048 |
} |
| 1049 |
|
| 1050 |
AWS_TEST_CASE(test_s3_checksum_header, s_test_s3_checksum_header) |
| 1051 |
static int s_test_s3_checksum_header(struct aws_allocator *allocator, void *ctx) { |
| 1052 |
(void)ctx; |
| 1053 |
aws_s3_library_init(allocator); |
| 1054 |
|
| 1055 |
ASSERT_TRUE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("x-amz-checksum-crc32"))); |
| 1056 |
ASSERT_TRUE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("x-amz-checksum-foo"))); |
| 1057 |
ASSERT_TRUE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("x-amz-checksum-md5"))); |
| 1058 |
|
| 1059 |
ASSERT_FALSE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("x-amz-checksum-type"))); |
| 1060 |
ASSERT_FALSE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("x-amz-checksum-mode"))); |
| 1061 |
ASSERT_FALSE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("x-amz-checksum-algorithm"))); |
| 1062 |
ASSERT_FALSE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("x-amz-cHeCKsuM-tYpE"))); |
| 1063 |
ASSERT_FALSE(aws_s3_is_checksum_value_header_name(aws_byte_cursor_from_c_str("X-AMZ-CHECKSUM-ALGORITHM"))); |
| 1064 |
|
| 1065 |
aws_s3_library_clean_up(); |
| 1066 |
return 0; |
| 1067 |
} |