| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include "aws/s3/private/s3_util.h" |
| 7 |
#include "aws/s3/private/s3express_credentials_provider_impl.h" |
| 8 |
#include "aws/s3/s3_client.h" |
| 9 |
#include "aws/s3/s3express_credentials_provider.h" |
| 10 |
#include "s3_tester.h" |
| 11 |
#include <aws/common/atomics.h> |
| 12 |
#include <aws/common/clock.h> |
| 13 |
#include <aws/common/encoding.h> |
| 14 |
#include <aws/common/lru_cache.h> |
| 15 |
#include <aws/io/stream.h> |
| 16 |
#include <aws/io/uri.h> |
| 17 |
#include <aws/testing/aws_test_harness.h> |
| 18 |
#include <inttypes.h> |
| 19 |
|
| 20 |
#define TEST_CASE(NAME) \ |
| 21 |
AWS_TEST_CASE(NAME, s_test_##NAME); \ |
| 22 |
static int s_test_##NAME(struct aws_allocator *allocator, void *ctx) |
| 23 |
|
| 24 |
#define DEFINE_HEADER(NAME, VALUE) \ |
| 25 |
{ \ |
| 26 |
.name = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(NAME), \ |
| 27 |
.value = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL(VALUE), \ |
| 28 |
} |
| 29 |
|
| 30 |
struct aws_s3express_client_tester { |
| 31 |
struct aws_allocator *allocator; |
| 32 |
struct aws_hash_table saver_cache; |
| 33 |
struct aws_atomic_var provider_requests_made; |
| 34 |
}; |
| 35 |
|
| 36 |
static struct aws_s3express_client_tester s_tester; |
| 37 |
|
| 38 |
static int s_s3express_client_tester_init(struct aws_allocator *allocator) { |
| 39 |
s_tester.allocator = allocator; |
| 40 |
aws_hash_table_init( |
| 41 |
&s_tester.saver_cache, |
| 42 |
allocator, |
| 43 |
100, |
| 44 |
aws_hash_string, |
| 45 |
aws_hash_callback_string_eq, |
| 46 |
aws_hash_callback_string_destroy, |
| 47 |
(aws_hash_callback_destroy_fn *)aws_credentials_release); |
| 48 |
aws_atomic_init_int(&s_tester.provider_requests_made, 0); |
| 49 |
return AWS_OP_SUCCESS; |
| 50 |
} |
| 51 |
|
| 52 |
static int s_s3express_client_tester_cleanup(void) { |
| 53 |
aws_hash_table_clean_up(&s_tester.saver_cache); |
| 54 |
return AWS_OP_SUCCESS; |
| 55 |
} |
| 56 |
|
| 57 |
static int s_create_s3express_request_mock_server( |
| 58 |
struct aws_allocator *allocator, |
| 59 |
struct aws_s3_tester *tester, |
| 60 |
struct aws_s3_client *client) { |
| 61 |
|
| 62 |
struct aws_byte_cursor object_path = aws_byte_cursor_from_c_str("/default"); |
| 63 |
|
| 64 |
struct aws_s3_tester_meta_request_options put_options = { |
| 65 |
.allocator = allocator, |
| 66 |
.meta_request_type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT, |
| 67 |
.client = client, |
| 68 |
.checksum_algorithm = AWS_SCA_CRC32, |
| 69 |
.validate_get_response_checksum = false, |
| 70 |
.put_options = |
| 71 |
{ |
| 72 |
.object_size_mb = 10, |
| 73 |
.object_path_override = object_path, |
| 74 |
}, |
| 75 |
.mock_server = true, |
| 76 |
.use_s3express_signing = true, |
| 77 |
}; |
| 78 |
ASSERT_SUCCESS(aws_s3_tester_send_meta_request_with_options(tester, &put_options, NULL)); |
| 79 |
return AWS_OP_SUCCESS; |
| 80 |
} |
| 81 |
|
| 82 |
TEST_CASE(s3express_client_sanity_test_mock_server) { |
| 83 |
(void)ctx; |
| 84 |
|
| 85 |
struct aws_s3_tester tester; |
| 86 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 87 |
struct aws_s3_client_config client_config = { |
| 88 |
.part_size = MB_TO_BYTES(5), |
| 89 |
.tls_mode = AWS_MR_TLS_DISABLED, |
| 90 |
.enable_s3express = true, |
| 91 |
}; |
| 92 |
|
| 93 |
ASSERT_SUCCESS(aws_s3_tester_bind_client( |
| 94 |
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 95 |
|
| 96 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 97 |
|
| 98 |
ASSERT_SUCCESS(s_create_s3express_request_mock_server(allocator, &tester, client)); |
| 99 |
|
| 100 |
ASSERT_NOT_NULL(client->s3express_provider); |
| 101 |
|
| 102 |
aws_s3_client_release(client); |
| 103 |
aws_s3_tester_clean_up(&tester); |
| 104 |
return AWS_OP_SUCCESS; |
| 105 |
} |
| 106 |
|
| 107 |
static int s_s3express_get_creds_fake( |
| 108 |
struct aws_s3express_credentials_provider *provider, |
| 109 |
const struct aws_credentials *original_credentials, |
| 110 |
const struct aws_credentials_properties_s3express *properties, |
| 111 |
aws_on_get_credentials_callback_fn callback, |
| 112 |
void *user_data) { |
| 113 |
(void)properties; |
| 114 |
(void)provider; |
| 115 |
(void)original_credentials; |
| 116 |
|
| 117 |
struct aws_string *key_1 = aws_string_new_from_c_str(s_tester.allocator, "key_1"); |
| 118 |
struct aws_credentials *credentials = |
| 119 |
aws_credentials_new_from_string(s_tester.allocator, key_1, key_1, key_1, SIZE_MAX); |
| 120 |
if (callback) { |
| 121 |
callback(credentials, AWS_ERROR_SUCCESS, user_data); |
| 122 |
} |
| 123 |
aws_credentials_release(credentials); |
| 124 |
aws_string_destroy(key_1); |
| 125 |
return AWS_OP_SUCCESS; |
| 126 |
} |
| 127 |
|
| 128 |
static void s_s3express_destroy_fake(struct aws_s3express_credentials_provider *provider) { |
| 129 |
provider->shutdown_complete_callback(provider->shutdown_user_data); |
| 130 |
aws_mem_release(provider->allocator, provider); |
| 131 |
} |
| 132 |
|
| 133 |
static struct aws_s3express_credentials_provider_vtable s_fake_s3express_vtable = { |
| 134 |
.get_credentials = s_s3express_get_creds_fake, |
| 135 |
.destroy = s_s3express_destroy_fake, |
| 136 |
}; |
| 137 |
|
| 138 |
struct aws_s3express_credentials_provider *s_s3express_provider_fake_factory( |
| 139 |
struct aws_allocator *allocator, |
| 140 |
struct aws_s3_client *client, |
| 141 |
aws_simple_completion_callback shutdown_complete_callback, |
| 142 |
void *shutdown_user_data, |
| 143 |
void *factory_user_data) { |
| 144 |
|
| 145 |
(void)client; |
| 146 |
(void)factory_user_data; |
| 147 |
struct aws_s3express_credentials_provider *provider = |
| 148 |
aws_mem_calloc(allocator, 1, sizeof(struct aws_s3express_credentials_provider)); |
| 149 |
aws_s3express_credentials_provider_init_base(provider, allocator, &s_fake_s3express_vtable, NULL); |
| 150 |
provider->shutdown_complete_callback = shutdown_complete_callback; |
| 151 |
provider->shutdown_user_data = shutdown_user_data; |
| 152 |
return provider; |
| 153 |
} |
| 154 |
|
| 155 |
TEST_CASE(s3express_client_sanity_override_test_mock_server) { |
| 156 |
(void)ctx; |
| 157 |
|
| 158 |
struct aws_s3_tester tester; |
| 159 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 160 |
s_s3express_client_tester_init(allocator); |
| 161 |
struct aws_s3_client_config client_config = { |
| 162 |
.part_size = MB_TO_BYTES(5), |
| 163 |
.tls_mode = AWS_MR_TLS_DISABLED, |
| 164 |
.enable_s3express = true, |
| 165 |
.s3express_provider_override_factory = s_s3express_provider_fake_factory, |
| 166 |
}; |
| 167 |
|
| 168 |
ASSERT_SUCCESS(aws_s3_tester_bind_client( |
| 169 |
&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_REGION | AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 170 |
|
| 171 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 172 |
|
| 173 |
ASSERT_SUCCESS(s_create_s3express_request_mock_server(allocator, &tester, client)); |
| 174 |
ASSERT_NOT_NULL(client->s3express_provider); |
| 175 |
|
| 176 |
aws_s3_client_release(client); |
| 177 |
s_s3express_client_tester_cleanup(); |
| 178 |
aws_s3_tester_clean_up(&tester); |
| 179 |
return AWS_OP_SUCCESS; |
| 180 |
} |
| 181 |
|
| 182 |
static int s_s3express_put_object_request( |
| 183 |
struct aws_allocator *allocator, |
| 184 |
struct aws_s3_client *client, |
| 185 |
size_t content_length, |
| 186 |
struct aws_s3_tester *tester, |
| 187 |
struct aws_byte_cursor host_cursor, |
| 188 |
struct aws_byte_cursor key_cursor, |
| 189 |
struct aws_byte_cursor region) { |
| 190 |
|
| 191 |
struct aws_input_stream *upload_stream = aws_s3_test_input_stream_new(allocator, content_length); |
| 192 |
|
| 193 |
struct aws_http_message *message = aws_s3_test_put_object_request_new( |
| 194 |
allocator, &host_cursor, key_cursor, g_test_body_content_type, upload_stream, 0); |
| 195 |
|
| 196 |
struct aws_s3_meta_request_options options; |
| 197 |
AWS_ZERO_STRUCT(options); |
| 198 |
options.type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT; |
| 199 |
options.message = message; |
| 200 |
struct aws_signing_config_aws s3express_signing_config = { |
| 201 |
.algorithm = AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, |
| 202 |
.service = g_s3express_service_name, |
| 203 |
.region = region, |
| 204 |
}; |
| 205 |
options.signing_config = &s3express_signing_config; |
| 206 |
struct aws_s3_meta_request_test_results meta_request_test_results; |
| 207 |
aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator); |
| 208 |
|
| 209 |
ASSERT_SUCCESS(aws_s3_tester_bind_meta_request(tester, &options, &meta_request_test_results)); |
| 210 |
|
| 211 |
struct aws_s3_meta_request *meta_request = aws_s3_client_make_meta_request(client, &options); |
| 212 |
ASSERT_TRUE(meta_request != NULL); |
| 213 |
|
| 214 |
aws_s3_tester_wait_for_meta_request_finish(tester); |
| 215 |
|
| 216 |
ASSERT_SUCCESS(aws_s3_tester_validate_put_object_results(&meta_request_test_results, 0)); |
| 217 |
meta_request = aws_s3_meta_request_release(meta_request); |
| 218 |
aws_s3_tester_wait_for_meta_request_shutdown(tester); |
| 219 |
|
| 220 |
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results); |
| 221 |
|
| 222 |
aws_http_message_release(message); |
| 223 |
aws_input_stream_release(upload_stream); |
| 224 |
|
| 225 |
return AWS_OP_SUCCESS; |
| 226 |
} |
| 227 |
|
| 228 |
static int s_s3express_client_put_test_helper(struct aws_allocator *allocator, size_t content_length) { |
| 229 |
|
| 230 |
struct aws_s3_tester tester; |
| 231 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 232 |
|
| 233 |
struct aws_byte_cursor region_cursor = aws_byte_cursor_from_c_str("us-east-1"); |
| 234 |
|
| 235 |
struct aws_byte_cursor key_cursor = aws_byte_cursor_from_c_str("/crt-test"); |
| 236 |
|
| 237 |
struct aws_s3_client_config client_config = { |
| 238 |
.part_size = MB_TO_BYTES(5), |
| 239 |
.enable_s3express = true, |
| 240 |
.region = region_cursor, |
| 241 |
}; |
| 242 |
|
| 243 |
ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 244 |
|
| 245 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 246 |
|
| 247 |
ASSERT_SUCCESS(s_s3express_put_object_request( |
| 248 |
allocator, |
| 249 |
client, |
| 250 |
content_length, |
| 251 |
&tester, |
| 252 |
g_test_s3express_bucket_use1_az4_endpoint, |
| 253 |
key_cursor, |
| 254 |
region_cursor)); |
| 255 |
|
| 256 |
struct aws_byte_cursor west2_region_cursor = aws_byte_cursor_from_c_str("us-west-2"); |
| 257 |
ASSERT_SUCCESS(s_s3express_put_object_request( |
| 258 |
allocator, |
| 259 |
client, |
| 260 |
content_length, |
| 261 |
&tester, |
| 262 |
g_test_s3express_bucket_usw2_az1_endpoint, |
| 263 |
key_cursor, |
| 264 |
west2_region_cursor)); |
| 265 |
|
| 266 |
aws_s3_client_release(client); |
| 267 |
aws_s3_tester_clean_up(&tester); |
| 268 |
return AWS_OP_SUCCESS; |
| 269 |
} |
| 270 |
|
| 271 |
TEST_CASE(s3express_client_put_object) { |
| 272 |
(void)ctx; |
| 273 |
return s_s3express_client_put_test_helper(allocator, MB_TO_BYTES(1)); |
| 274 |
} |
| 275 |
|
| 276 |
TEST_CASE(s3express_client_put_object_multipart) { |
| 277 |
(void)ctx; |
| 278 |
return s_s3express_client_put_test_helper(allocator, MB_TO_BYTES(100)); |
| 279 |
} |
| 280 |
|
| 281 |
TEST_CASE(s3express_client_put_object_multipart_multiple) { |
| 282 |
(void)ctx; |
| 283 |
|
| 284 |
enum s_numbers { NUM_REQUESTS = 100 }; |
| 285 |
|
| 286 |
struct aws_s3_meta_request *meta_requests[NUM_REQUESTS]; |
| 287 |
struct aws_s3_meta_request_test_results meta_request_test_results[NUM_REQUESTS]; |
| 288 |
struct aws_input_stream *input_streams[NUM_REQUESTS]; |
| 289 |
|
| 290 |
struct aws_s3_tester tester; |
| 291 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 292 |
|
| 293 |
struct aws_byte_cursor region_cursor = aws_byte_cursor_from_c_str("us-east-1"); |
| 294 |
|
| 295 |
struct aws_byte_cursor key_cursor = aws_byte_cursor_from_c_str("/crt-test"); |
| 296 |
|
| 297 |
struct aws_byte_cursor west2_region_cursor = aws_byte_cursor_from_c_str("us-west-2"); |
| 298 |
|
| 299 |
struct aws_s3_client_config client_config = { |
| 300 |
.part_size = MB_TO_BYTES(5), |
| 301 |
.enable_s3express = true, |
| 302 |
.region = region_cursor, |
| 303 |
}; |
| 304 |
|
| 305 |
ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 306 |
|
| 307 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 308 |
|
| 309 |
for (size_t i = 0; i < NUM_REQUESTS; ++i) { |
| 310 |
input_streams[i] = aws_s3_test_input_stream_new(allocator, MB_TO_BYTES(10)); |
| 311 |
|
| 312 |
struct aws_byte_cursor request_region = region_cursor; |
| 313 |
struct aws_byte_cursor request_host = g_test_s3express_bucket_use1_az4_endpoint; |
| 314 |
if (i % 2 == 0) { |
| 315 |
|
| 316 |
request_region = west2_region_cursor; |
| 317 |
request_host = g_test_s3express_bucket_usw2_az1_endpoint; |
| 318 |
} |
| 319 |
|
| 320 |
struct aws_http_message *message = aws_s3_test_put_object_request_new( |
| 321 |
allocator, &request_host, key_cursor, g_test_body_content_type, input_streams[i], 0); |
| 322 |
|
| 323 |
struct aws_s3_meta_request_options options; |
| 324 |
AWS_ZERO_STRUCT(options); |
| 325 |
options.type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT; |
| 326 |
options.message = message; |
| 327 |
struct aws_signing_config_aws s3express_signing_config = { |
| 328 |
.algorithm = AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, |
| 329 |
.service = g_s3express_service_name, |
| 330 |
.region = request_region, |
| 331 |
}; |
| 332 |
options.signing_config = &s3express_signing_config; |
| 333 |
aws_s3_meta_request_test_results_init(&meta_request_test_results[i], allocator); |
| 334 |
|
| 335 |
ASSERT_SUCCESS(aws_s3_tester_bind_meta_request(&tester, &options, &meta_request_test_results[i])); |
| 336 |
|
| 337 |
meta_requests[i] = aws_s3_client_make_meta_request(client, &options); |
| 338 |
ASSERT_TRUE(meta_requests[i] != NULL); |
| 339 |
aws_http_message_release(message); |
| 340 |
} |
| 341 |
|
| 342 |
aws_s3_tester_wait_for_meta_request_finish(&tester); |
| 343 |
aws_s3_tester_lock_synced_data(&tester); |
| 344 |
ASSERT_TRUE(tester.synced_data.finish_error_code == AWS_ERROR_SUCCESS); |
| 345 |
aws_s3_tester_unlock_synced_data(&tester); |
| 346 |
|
| 347 |
for (size_t i = 0; i < NUM_REQUESTS; ++i) { |
| 348 |
meta_requests[i] = aws_s3_meta_request_release(meta_requests[i]); |
| 349 |
} |
| 350 |
|
| 351 |
aws_s3_tester_wait_for_meta_request_shutdown(&tester); |
| 352 |
|
| 353 |
for (size_t i = 0; i < NUM_REQUESTS; ++i) { |
| 354 |
aws_s3_tester_validate_put_object_results(&meta_request_test_results[i], 0); |
| 355 |
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results[i]); |
| 356 |
} |
| 357 |
|
| 358 |
for (size_t i = 0; i < NUM_REQUESTS; ++i) { |
| 359 |
aws_input_stream_release(input_streams[i]); |
| 360 |
} |
| 361 |
|
| 362 |
aws_s3_client_release(client); |
| 363 |
aws_s3_tester_clean_up(&tester); |
| 364 |
return AWS_OP_SUCCESS; |
| 365 |
} |
| 366 |
|
| 367 |
void s_meta_request_finished_overhead( |
| 368 |
struct aws_s3_meta_request *meta_request, |
| 369 |
const struct aws_s3_meta_request_result *meta_request_result, |
| 370 |
void *user_data) { |
| 371 |
(void)meta_request; |
| 372 |
(void)meta_request_result; |
| 373 |
(void)user_data; |
| 374 |
aws_atomic_fetch_add(&s_tester.provider_requests_made, 1); |
| 375 |
} |
| 376 |
|
| 377 |
struct aws_s3express_credentials_provider *s_s3express_provider_mock_factory( |
| 378 |
struct aws_allocator *allocator, |
| 379 |
struct aws_s3_client *client, |
| 380 |
aws_simple_completion_callback on_provider_shutdown_callback, |
| 381 |
void *shutdown_user_data, |
| 382 |
void *factory_user_data) { |
| 383 |
(void)factory_user_data; |
| 384 |
|
| 385 |
struct aws_s3express_credentials_provider_default_options options = { |
| 386 |
.client = client, |
| 387 |
.shutdown_complete_callback = on_provider_shutdown_callback, |
| 388 |
.shutdown_user_data = shutdown_user_data, |
| 389 |
}; |
| 390 |
struct aws_s3express_credentials_provider *s3express_provider = |
| 391 |
aws_s3express_credentials_provider_new_default(allocator, &options); |
| 392 |
|
| 393 |
struct aws_s3express_credentials_provider_impl *impl = s3express_provider->impl; |
| 394 |
|
| 395 |
impl->mock_test.meta_request_finished_overhead = s_meta_request_finished_overhead; |
| 396 |
|
| 397 |
return s3express_provider; |
| 398 |
} |
| 399 |
|
| 400 |
|
| 401 |
TEST_CASE(s3express_client_put_object_long_running_session_refresh) { |
| 402 |
(void)ctx; |
| 403 |
|
| 404 |
struct aws_s3_tester tester; |
| 405 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 406 |
s_s3express_client_tester_init(allocator); |
| 407 |
|
| 408 |
size_t num_meta_requests = 7; |
| 409 |
|
| 410 |
struct aws_byte_cursor region_cursor = aws_byte_cursor_from_c_str("us-east-1"); |
| 411 |
|
| 412 |
struct aws_byte_cursor key_cursor = aws_byte_cursor_from_c_str("/crt-test"); |
| 413 |
|
| 414 |
struct aws_s3_client_config client_config = { |
| 415 |
.part_size = MB_TO_BYTES(5), |
| 416 |
.enable_s3express = true, |
| 417 |
.region = region_cursor, |
| 418 |
.s3express_provider_override_factory = s_s3express_provider_mock_factory, |
| 419 |
}; |
| 420 |
|
| 421 |
ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 422 |
|
| 423 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 424 |
|
| 425 |
for (size_t i = 0; i < num_meta_requests; i++) { |
| 426 |
|
| 427 |
struct aws_input_stream *upload_stream = aws_s3_test_input_stream_new(allocator, MB_TO_BYTES(10)); |
| 428 |
|
| 429 |
struct aws_http_message *message = aws_s3_test_put_object_request_new( |
| 430 |
allocator, |
| 431 |
&g_test_s3express_bucket_use1_az4_endpoint, |
| 432 |
key_cursor, |
| 433 |
g_test_body_content_type, |
| 434 |
upload_stream, |
| 435 |
0); |
| 436 |
struct aws_s3_meta_request_options options; |
| 437 |
AWS_ZERO_STRUCT(options); |
| 438 |
options.type = AWS_S3_META_REQUEST_TYPE_PUT_OBJECT; |
| 439 |
options.message = message; |
| 440 |
struct aws_signing_config_aws s3express_signing_config = { |
| 441 |
.algorithm = AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, |
| 442 |
.service = g_s3express_service_name, |
| 443 |
}; |
| 444 |
options.signing_config = &s3express_signing_config; |
| 445 |
|
| 446 |
struct aws_s3_meta_request_test_results meta_request_test_results; |
| 447 |
aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator); |
| 448 |
ASSERT_SUCCESS(aws_s3_tester_bind_meta_request(&tester, &options, &meta_request_test_results)); |
| 449 |
|
| 450 |
struct aws_s3_meta_request *meta_request = aws_s3_client_make_meta_request(client, &options); |
| 451 |
ASSERT_TRUE(meta_request != NULL); |
| 452 |
|
| 453 |
aws_s3_tester_wait_for_meta_request_finish(&tester); |
| 454 |
ASSERT_SUCCESS(aws_s3_tester_validate_put_object_results(&meta_request_test_results, 0)); |
| 455 |
|
| 456 |
meta_request = aws_s3_meta_request_release(meta_request); |
| 457 |
aws_s3_tester_wait_for_meta_request_shutdown(&tester); |
| 458 |
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results); |
| 459 |
aws_http_message_release(message); |
| 460 |
aws_input_stream_release(upload_stream); |
| 461 |
|
| 462 |
|
| 463 |
if (i != num_meta_requests - 1) { |
| 464 |
aws_thread_current_sleep(aws_timestamp_convert(60, AWS_TIMESTAMP_SECS, AWS_TIMESTAMP_NANOS, NULL)); |
| 465 |
} |
| 466 |
} |
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
size_t session_made = aws_atomic_load_int(&s_tester.provider_requests_made); |
| 471 |
ASSERT_TRUE(session_made >= 2); |
| 472 |
|
| 473 |
aws_s3_client_release(client); |
| 474 |
s_s3express_client_tester_cleanup(); |
| 475 |
aws_s3_tester_clean_up(&tester); |
| 476 |
return AWS_OP_SUCCESS; |
| 477 |
} |
| 478 |
|
| 479 |
TEST_CASE(s3express_client_get_object) { |
| 480 |
(void)ctx; |
| 481 |
|
| 482 |
struct aws_s3_tester tester; |
| 483 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 484 |
|
| 485 |
struct aws_byte_cursor region_cursor = aws_byte_cursor_from_c_str("us-east-1"); |
| 486 |
|
| 487 |
struct aws_s3_client_config client_config = { |
| 488 |
.part_size = MB_TO_BYTES(5), |
| 489 |
.enable_s3express = true, |
| 490 |
.region = region_cursor, |
| 491 |
}; |
| 492 |
|
| 493 |
ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 494 |
|
| 495 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 496 |
|
| 497 |
struct aws_http_message *message = aws_s3_test_get_object_request_new( |
| 498 |
allocator, g_test_s3express_bucket_use1_az4_endpoint, g_pre_existing_object_10MB); |
| 499 |
|
| 500 |
struct aws_s3_meta_request_options options; |
| 501 |
AWS_ZERO_STRUCT(options); |
| 502 |
options.type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT; |
| 503 |
options.message = message; |
| 504 |
struct aws_signing_config_aws s3express_signing_config = { |
| 505 |
.algorithm = AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, |
| 506 |
.service = g_s3express_service_name, |
| 507 |
}; |
| 508 |
options.signing_config = &s3express_signing_config; |
| 509 |
struct aws_s3_meta_request_test_results meta_request_test_results; |
| 510 |
aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator); |
| 511 |
|
| 512 |
ASSERT_SUCCESS(aws_s3_tester_bind_meta_request(&tester, &options, &meta_request_test_results)); |
| 513 |
|
| 514 |
struct aws_s3_meta_request *meta_request = aws_s3_client_make_meta_request(client, &options); |
| 515 |
ASSERT_TRUE(meta_request != NULL); |
| 516 |
|
| 517 |
aws_s3_tester_wait_for_meta_request_finish(&tester); |
| 518 |
|
| 519 |
ASSERT_SUCCESS(aws_s3_tester_validate_get_object_results(&meta_request_test_results, 0)); |
| 520 |
meta_request = aws_s3_meta_request_release(meta_request); |
| 521 |
aws_s3_tester_wait_for_meta_request_shutdown(&tester); |
| 522 |
|
| 523 |
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results); |
| 524 |
|
| 525 |
aws_http_message_release(message); |
| 526 |
aws_s3_client_release(client); |
| 527 |
aws_s3_tester_clean_up(&tester); |
| 528 |
return AWS_OP_SUCCESS; |
| 529 |
} |
| 530 |
|
| 531 |
TEST_CASE(s3express_client_get_object_multiple) { |
| 532 |
(void)ctx; |
| 533 |
|
| 534 |
struct aws_s3_meta_request *meta_requests[100]; |
| 535 |
struct aws_s3_meta_request_test_results meta_request_test_results[100]; |
| 536 |
size_t num_meta_requests = AWS_ARRAY_SIZE(meta_requests); |
| 537 |
|
| 538 |
struct aws_s3_tester tester; |
| 539 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 540 |
|
| 541 |
struct aws_byte_cursor region_cursor = aws_byte_cursor_from_c_str("us-east-1"); |
| 542 |
|
| 543 |
struct aws_s3_client_config client_config = { |
| 544 |
.part_size = MB_TO_BYTES(5), |
| 545 |
.enable_s3express = true, |
| 546 |
.region = region_cursor, |
| 547 |
}; |
| 548 |
|
| 549 |
ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 550 |
|
| 551 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 552 |
|
| 553 |
for (size_t i = 0; i < num_meta_requests; ++i) { |
| 554 |
|
| 555 |
struct aws_http_message *message = aws_s3_test_get_object_request_new( |
| 556 |
allocator, g_test_s3express_bucket_use1_az4_endpoint, g_pre_existing_object_10MB); |
| 557 |
|
| 558 |
struct aws_s3_meta_request_options options; |
| 559 |
AWS_ZERO_STRUCT(options); |
| 560 |
options.type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT; |
| 561 |
options.message = message; |
| 562 |
struct aws_signing_config_aws s3express_signing_config = { |
| 563 |
.algorithm = AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, |
| 564 |
.service = g_s3express_service_name, |
| 565 |
}; |
| 566 |
options.signing_config = &s3express_signing_config; |
| 567 |
aws_s3_meta_request_test_results_init(&meta_request_test_results[i], allocator); |
| 568 |
|
| 569 |
ASSERT_SUCCESS(aws_s3_tester_bind_meta_request(&tester, &options, &meta_request_test_results[i])); |
| 570 |
|
| 571 |
meta_requests[i] = aws_s3_client_make_meta_request(client, &options); |
| 572 |
ASSERT_TRUE(meta_requests[i] != NULL); |
| 573 |
|
| 574 |
aws_http_message_release(message); |
| 575 |
} |
| 576 |
|
| 577 |
aws_s3_tester_wait_for_meta_request_finish(&tester); |
| 578 |
aws_s3_tester_lock_synced_data(&tester); |
| 579 |
ASSERT_TRUE(tester.synced_data.finish_error_code == AWS_ERROR_SUCCESS); |
| 580 |
aws_s3_tester_unlock_synced_data(&tester); |
| 581 |
|
| 582 |
for (size_t i = 0; i < num_meta_requests; ++i) { |
| 583 |
meta_requests[i] = aws_s3_meta_request_release(meta_requests[i]); |
| 584 |
} |
| 585 |
|
| 586 |
aws_s3_tester_wait_for_meta_request_shutdown(&tester); |
| 587 |
|
| 588 |
for (size_t i = 0; i < num_meta_requests; ++i) { |
| 589 |
aws_s3_tester_validate_get_object_results(&meta_request_test_results[i], 0); |
| 590 |
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results[i]); |
| 591 |
} |
| 592 |
|
| 593 |
aws_s3_client_release(client); |
| 594 |
aws_s3_tester_clean_up(&tester); |
| 595 |
return AWS_OP_SUCCESS; |
| 596 |
} |
| 597 |
|
| 598 |
TEST_CASE(s3express_client_get_object_create_session_error) { |
| 599 |
(void)ctx; |
| 600 |
|
| 601 |
struct aws_s3_tester tester; |
| 602 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 603 |
|
| 604 |
struct aws_byte_cursor region_cursor = aws_byte_cursor_from_c_str("us-east-1"); |
| 605 |
|
| 606 |
struct aws_s3_client_config client_config = { |
| 607 |
.part_size = MB_TO_BYTES(5), |
| 608 |
.enable_s3express = true, |
| 609 |
.region = region_cursor, |
| 610 |
}; |
| 611 |
|
| 612 |
ASSERT_SUCCESS(aws_s3_tester_bind_client(&tester, &client_config, AWS_S3_TESTER_BIND_CLIENT_SIGNING)); |
| 613 |
|
| 614 |
struct aws_s3_client *client = aws_s3_client_new(allocator, &client_config); |
| 615 |
|
| 616 |
struct aws_byte_cursor my_dummy_endpoint = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL( |
| 617 |
"non-exist-bucket-test--use1-az4--x-s3.s3express-use1-az4.us-east-1.amazonaws.com"); |
| 618 |
|
| 619 |
struct aws_http_message *message = |
| 620 |
aws_s3_test_get_object_request_new(allocator, my_dummy_endpoint, g_pre_existing_object_10MB); |
| 621 |
|
| 622 |
struct aws_s3_meta_request_options options; |
| 623 |
AWS_ZERO_STRUCT(options); |
| 624 |
options.type = AWS_S3_META_REQUEST_TYPE_GET_OBJECT; |
| 625 |
options.message = message; |
| 626 |
struct aws_signing_config_aws s3express_signing_config = { |
| 627 |
.algorithm = AWS_SIGNING_ALGORITHM_V4_S3EXPRESS, |
| 628 |
.service = g_s3express_service_name, |
| 629 |
}; |
| 630 |
options.signing_config = &s3express_signing_config; |
| 631 |
struct aws_s3_meta_request_test_results meta_request_test_results; |
| 632 |
aws_s3_meta_request_test_results_init(&meta_request_test_results, allocator); |
| 633 |
|
| 634 |
ASSERT_SUCCESS(aws_s3_tester_bind_meta_request(&tester, &options, &meta_request_test_results)); |
| 635 |
|
| 636 |
struct aws_s3_meta_request *meta_request = aws_s3_client_make_meta_request(client, &options); |
| 637 |
ASSERT_TRUE(meta_request != NULL); |
| 638 |
|
| 639 |
aws_s3_tester_wait_for_meta_request_finish(&tester); |
| 640 |
ASSERT_UINT_EQUALS(meta_request_test_results.finished_error_code, AWS_ERROR_S3EXPRESS_CREATE_SESSION_FAILED); |
| 641 |
|
| 642 |
meta_request = aws_s3_meta_request_release(meta_request); |
| 643 |
aws_s3_tester_wait_for_meta_request_shutdown(&tester); |
| 644 |
|
| 645 |
aws_s3_meta_request_test_results_clean_up(&meta_request_test_results); |
| 646 |
|
| 647 |
aws_http_message_release(message); |
| 648 |
aws_s3_client_release(client); |
| 649 |
aws_s3_tester_clean_up(&tester); |
| 650 |
return AWS_OP_SUCCESS; |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
TEST_CASE(s3express_client_copy_object) { |
| 657 |
(void)ctx; |
| 658 |
struct aws_s3_tester tester; |
| 659 |
AWS_ZERO_STRUCT(tester); |
| 660 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 661 |
|
| 662 |
struct aws_byte_cursor source_key = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("pre-existing-10MB"); |
| 663 |
struct aws_byte_cursor destination_key = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("copies/destination_10MB"); |
| 664 |
struct aws_byte_cursor source_bucket = |
| 665 |
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("aws-c-s3-test-bucket--usw2-az1--x-s3"); |
| 666 |
struct aws_byte_cursor copy_source_uri; |
| 667 |
AWS_ZERO_STRUCT(copy_source_uri); |
| 668 |
|
| 669 |
ASSERT_SUCCESS(aws_test_s3_copy_object_helper( |
| 670 |
allocator, |
| 671 |
&tester, |
| 672 |
source_bucket, |
| 673 |
source_key, |
| 674 |
g_test_s3express_bucket_usw2_az1_endpoint, |
| 675 |
destination_key, |
| 676 |
AWS_ERROR_SUCCESS, |
| 677 |
AWS_HTTP_STATUS_CODE_200_OK, |
| 678 |
MB_TO_BYTES(10), |
| 679 |
true, |
| 680 |
copy_source_uri)); |
| 681 |
|
| 682 |
aws_s3_tester_clean_up(&tester); |
| 683 |
return AWS_OP_SUCCESS; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
TEST_CASE(s3express_client_copy_object_multipart) { |
| 690 |
(void)ctx; |
| 691 |
struct aws_s3_tester tester; |
| 692 |
AWS_ZERO_STRUCT(tester); |
| 693 |
ASSERT_SUCCESS(aws_s3_tester_init(allocator, &tester)); |
| 694 |
|
| 695 |
struct aws_byte_cursor source_key = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("pre-existing-2GB"); |
| 696 |
struct aws_byte_cursor destination_key = AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("copies/destination_2GB"); |
| 697 |
struct aws_byte_cursor source_bucket = |
| 698 |
AWS_BYTE_CUR_INIT_FROM_STRING_LITERAL("aws-c-s3-test-bucket--usw2-az1--x-s3"); |
| 699 |
struct aws_byte_cursor copy_source_uri; |
| 700 |
AWS_ZERO_STRUCT(copy_source_uri); |
| 701 |
|
| 702 |
ASSERT_SUCCESS(aws_test_s3_copy_object_helper( |
| 703 |
allocator, |
| 704 |
&tester, |
| 705 |
source_bucket, |
| 706 |
source_key, |
| 707 |
g_test_s3express_bucket_usw2_az1_endpoint, |
| 708 |
destination_key, |
| 709 |
AWS_ERROR_SUCCESS, |
| 710 |
AWS_HTTP_STATUS_CODE_200_OK, |
| 711 |
GB_TO_BYTES(2), |
| 712 |
true, |
| 713 |
copy_source_uri)); |
| 714 |
|
| 715 |
aws_s3_tester_clean_up(&tester); |
| 716 |
return AWS_OP_SUCCESS; |
| 717 |
} |
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
TEST_CASE(s3express_hash_key_test) { |
| 723 |
(void)ctx; |
| 724 |
aws_s3_library_init(allocator); |
| 725 |
|
| 726 |
struct aws_string *access_key = aws_string_new_from_c_str(allocator, "AccessKey"); |
| 727 |
struct aws_string *secret_access_key = aws_string_new_from_c_str(allocator, "SecretAccessKey"); |
| 728 |
struct aws_http_headers *headers = aws_http_headers_new(allocator); |
| 729 |
aws_http_headers_add( |
| 730 |
headers, aws_byte_cursor_from_c_str("x-amz-create-session-mode"), aws_byte_cursor_from_c_str("ReadOnly")); |
| 731 |
aws_http_headers_add( |
| 732 |
headers, aws_byte_cursor_from_c_str("x-amz-server-side-encryption"), aws_byte_cursor_from_c_str("aws:kms")); |
| 733 |
aws_http_headers_add( |
| 734 |
headers, |
| 735 |
aws_byte_cursor_from_c_str("x-amz-server-side-encryption-aws-kms-key-id"), |
| 736 |
aws_byte_cursor_from_c_str("kms-key-id")); |
| 737 |
aws_http_headers_add( |
| 738 |
headers, |
| 739 |
aws_byte_cursor_from_c_str("x-amz-server-side-encryption-context"), |
| 740 |
aws_byte_cursor_from_c_str("context")); |
| 741 |
aws_http_headers_add( |
| 742 |
headers, |
| 743 |
aws_byte_cursor_from_c_str("x-amz-server-side-encryption-bucket-key-enabled"), |
| 744 |
aws_byte_cursor_from_c_str("true")); |
| 745 |
aws_http_headers_add( |
| 746 |
headers, |
| 747 |
aws_byte_cursor_from_c_str("header-not-in-allow-list"), |
| 748 |
aws_byte_cursor_from_c_str("should-be-ignored")); |
| 749 |
|
| 750 |
struct aws_credentials *creds = |
| 751 |
aws_credentials_new_from_string(allocator, access_key, secret_access_key, NULL, UINT64_MAX); |
| 752 |
|
| 753 |
struct aws_string *hash_key = |
| 754 |
aws_encode_s3express_hash_key_new(allocator, creds, aws_byte_cursor_from_c_str(""), headers); |
| 755 |
struct aws_byte_cursor hash_cursor = aws_byte_cursor_from_string(hash_key); |
| 756 |
|
| 757 |
struct aws_byte_buf encoded_buf; |
| 758 |
aws_byte_buf_init(&encoded_buf, allocator, 200); |
| 759 |
aws_hex_encode_append_dynamic(&hash_cursor, &encoded_buf); |
| 760 |
|
| 761 |
char *expected_encoded_key = "cabfefee4365e075646ba8928ed9f757481d1062ffcb0a3afe5b9c428dd45800"; |
| 762 |
ASSERT_BIN_ARRAYS_EQUALS(expected_encoded_key, strlen(expected_encoded_key), encoded_buf.buffer, encoded_buf.len); |
| 763 |
|
| 764 |
aws_byte_buf_clean_up(&encoded_buf); |
| 765 |
aws_string_destroy(access_key); |
| 766 |
aws_string_destroy(secret_access_key); |
| 767 |
aws_credentials_release(creds); |
| 768 |
aws_string_destroy(hash_key); |
| 769 |
aws_http_headers_release(headers); |
| 770 |
|
| 771 |
aws_s3_library_clean_up(); |
| 772 |
|
| 773 |
return AWS_OP_SUCCESS; |
| 774 |
} |