| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <aws/sdkutils/endpoints_rule_engine.h> |
| 6 |
#include <aws/testing/aws_test_harness.h> |
| 7 |
|
| 8 |
#ifdef AWS_ENABLE_S3_ENDPOINT_RESOLVER |
| 9 |
# include <aws/s3/s3_endpoint_resolver.h> |
| 10 |
# include <aws/sdkutils/endpoints_rule_engine.h> |
| 11 |
|
| 12 |
AWS_TEST_CASE(test_s3_endpoint_resolver_resolve_endpoint, s_test_s3_endpoint_resolver_resolve_endpoint) |
| 13 |
static int s_test_s3_endpoint_resolver_resolve_endpoint(struct aws_allocator *allocator, void *ctx) { |
| 14 |
(void)ctx; |
| 15 |
aws_s3_library_init(allocator); |
| 16 |
|
| 17 |
struct aws_endpoints_rule_engine *rule_engine = aws_s3_endpoint_resolver_new(allocator); |
| 18 |
ASSERT_NOT_NULL(rule_engine); |
| 19 |
struct aws_endpoints_request_context *context = aws_endpoints_request_context_new(allocator); |
| 20 |
ASSERT_NOT_NULL(context); |
| 21 |
ASSERT_SUCCESS(aws_endpoints_request_context_add_string( |
| 22 |
allocator, context, aws_byte_cursor_from_c_str("Region"), aws_byte_cursor_from_c_str("us-west-2"))); |
| 23 |
ASSERT_SUCCESS(aws_endpoints_request_context_add_string( |
| 24 |
allocator, context, aws_byte_cursor_from_c_str("Bucket"), aws_byte_cursor_from_c_str("s3-bucket-test"))); |
| 25 |
|
| 26 |
struct aws_endpoints_resolved_endpoint *resolved_endpoint; |
| 27 |
ASSERT_SUCCESS(aws_endpoints_rule_engine_resolve(rule_engine, context, &resolved_endpoint)); |
| 28 |
|
| 29 |
ASSERT_INT_EQUALS(AWS_ENDPOINTS_RESOLVED_ENDPOINT, aws_endpoints_resolved_endpoint_get_type(resolved_endpoint)); |
| 30 |
|
| 31 |
struct aws_byte_cursor url_cur; |
| 32 |
ASSERT_SUCCESS(aws_endpoints_resolved_endpoint_get_url(resolved_endpoint, &url_cur)); |
| 33 |
|
| 34 |
ASSERT_CURSOR_VALUE_CSTRING_EQUALS(url_cur, "https://s3-bucket-test.s3.us-west-2.amazonaws.com"); |
| 35 |
|
| 36 |
aws_endpoints_resolved_endpoint_release(resolved_endpoint); |
| 37 |
aws_endpoints_request_context_release(context); |
| 38 |
aws_endpoints_rule_engine_release(rule_engine); |
| 39 |
|
| 40 |
aws_s3_library_clean_up(); |
| 41 |
return 0; |
| 42 |
} |
| 43 |
|
| 44 |
AWS_TEST_CASE(test_s3_endpoint_resolver_resolve_endpoint_fips, s_test_s3_endpoint_resolver_resolve_endpoint_fips) |
| 45 |
static int s_test_s3_endpoint_resolver_resolve_endpoint_fips(struct aws_allocator *allocator, void *ctx) { |
| 46 |
(void)ctx; |
| 47 |
aws_s3_library_init(allocator); |
| 48 |
|
| 49 |
struct aws_endpoints_rule_engine *rule_engine = aws_s3_endpoint_resolver_new(allocator); |
| 50 |
ASSERT_NOT_NULL(rule_engine); |
| 51 |
struct aws_endpoints_request_context *context = aws_endpoints_request_context_new(allocator); |
| 52 |
ASSERT_NOT_NULL(context); |
| 53 |
ASSERT_SUCCESS(aws_endpoints_request_context_add_string( |
| 54 |
allocator, context, aws_byte_cursor_from_c_str("Region"), aws_byte_cursor_from_c_str("us-east-1"))); |
| 55 |
ASSERT_SUCCESS(aws_endpoints_request_context_add_string( |
| 56 |
allocator, context, aws_byte_cursor_from_c_str("Bucket"), aws_byte_cursor_from_c_str("s3-bucket-test"))); |
| 57 |
ASSERT_SUCCESS( |
| 58 |
aws_endpoints_request_context_add_boolean(allocator, context, aws_byte_cursor_from_c_str("UseFIPS"), true)); |
| 59 |
struct aws_endpoints_resolved_endpoint *resolved_endpoint; |
| 60 |
ASSERT_SUCCESS(aws_endpoints_rule_engine_resolve(rule_engine, context, &resolved_endpoint)); |
| 61 |
|
| 62 |
ASSERT_INT_EQUALS(AWS_ENDPOINTS_RESOLVED_ENDPOINT, aws_endpoints_resolved_endpoint_get_type(resolved_endpoint)); |
| 63 |
|
| 64 |
struct aws_byte_cursor url_cur; |
| 65 |
ASSERT_SUCCESS(aws_endpoints_resolved_endpoint_get_url(resolved_endpoint, &url_cur)); |
| 66 |
|
| 67 |
ASSERT_CURSOR_VALUE_CSTRING_EQUALS(url_cur, "https://s3-bucket-test.s3-fips.us-east-1.amazonaws.com"); |
| 68 |
|
| 69 |
aws_endpoints_resolved_endpoint_release(resolved_endpoint); |
| 70 |
aws_endpoints_request_context_release(context); |
| 71 |
aws_endpoints_rule_engine_release(rule_engine); |
| 72 |
|
| 73 |
aws_s3_library_clean_up(); |
| 74 |
return 0; |
| 75 |
} |
| 76 |
|
| 77 |
AWS_TEST_CASE( |
| 78 |
test_s3_endpoint_resolver_resolve_endpoint_force_path_style, |
| 79 |
s_test_s3_endpoint_resolver_resolve_endpoint_force_path_style) |
| 80 |
static int s_test_s3_endpoint_resolver_resolve_endpoint_force_path_style(struct aws_allocator *allocator, void *ctx) { |
| 81 |
(void)ctx; |
| 82 |
aws_s3_library_init(allocator); |
| 83 |
|
| 84 |
struct aws_endpoints_rule_engine *rule_engine = aws_s3_endpoint_resolver_new(allocator); |
| 85 |
ASSERT_NOT_NULL(rule_engine); |
| 86 |
struct aws_endpoints_request_context *context = aws_endpoints_request_context_new(allocator); |
| 87 |
ASSERT_NOT_NULL(context); |
| 88 |
ASSERT_SUCCESS(aws_endpoints_request_context_add_string( |
| 89 |
allocator, context, aws_byte_cursor_from_c_str("Region"), aws_byte_cursor_from_c_str("us-east-1"))); |
| 90 |
ASSERT_SUCCESS(aws_endpoints_request_context_add_string( |
| 91 |
allocator, context, aws_byte_cursor_from_c_str("Bucket"), aws_byte_cursor_from_c_str("s3-bucket-test"))); |
| 92 |
ASSERT_SUCCESS(aws_endpoints_request_context_add_boolean( |
| 93 |
allocator, context, aws_byte_cursor_from_c_str("ForcePathStyle"), true)); |
| 94 |
struct aws_endpoints_resolved_endpoint *resolved_endpoint; |
| 95 |
ASSERT_SUCCESS(aws_endpoints_rule_engine_resolve(rule_engine, context, &resolved_endpoint)); |
| 96 |
|
| 97 |
ASSERT_INT_EQUALS(AWS_ENDPOINTS_RESOLVED_ENDPOINT, aws_endpoints_resolved_endpoint_get_type(resolved_endpoint)); |
| 98 |
|
| 99 |
struct aws_byte_cursor url_cur; |
| 100 |
ASSERT_SUCCESS(aws_endpoints_resolved_endpoint_get_url(resolved_endpoint, &url_cur)); |
| 101 |
|
| 102 |
ASSERT_CURSOR_VALUE_CSTRING_EQUALS(url_cur, "https://s3.us-east-1.amazonaws.com/s3-bucket-test"); |
| 103 |
|
| 104 |
aws_endpoints_resolved_endpoint_release(resolved_endpoint); |
| 105 |
aws_endpoints_request_context_release(context); |
| 106 |
aws_endpoints_rule_engine_release(rule_engine); |
| 107 |
|
| 108 |
aws_s3_library_clean_up(); |
| 109 |
return 0; |
| 110 |
} |
| 111 |
|
| 112 |
#endif |