File: s3_endpoint_resolver_tests.c

package info (click to toggle)
aws-crt-python 0.20.4%2Bdfsg-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 72,656 kB
  • sloc: ansic: 381,805; python: 23,008; makefile: 6,251; sh: 4,536; cpp: 699; ruby: 208; java: 77; perl: 73; javascript: 46; xml: 11
file content (112 lines) | stat: -rw-r--r-- 5,467 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */
#include <aws/sdkutils/endpoints_rule_engine.h>
#include <aws/testing/aws_test_harness.h>

#ifdef AWS_ENABLE_S3_ENDPOINT_RESOLVER
#    include <aws/s3/s3_endpoint_resolver.h>
#    include <aws/sdkutils/endpoints_rule_engine.h>

AWS_TEST_CASE(test_s3_endpoint_resolver_resolve_endpoint, s_test_s3_endpoint_resolver_resolve_endpoint)
static int s_test_s3_endpoint_resolver_resolve_endpoint(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    aws_s3_library_init(allocator);

    struct aws_endpoints_rule_engine *rule_engine = aws_s3_endpoint_resolver_new(allocator);
    ASSERT_NOT_NULL(rule_engine);
    struct aws_endpoints_request_context *context = aws_endpoints_request_context_new(allocator);
    ASSERT_NOT_NULL(context);
    ASSERT_SUCCESS(aws_endpoints_request_context_add_string(
        allocator, context, aws_byte_cursor_from_c_str("Region"), aws_byte_cursor_from_c_str("us-west-2")));
    ASSERT_SUCCESS(aws_endpoints_request_context_add_string(
        allocator, context, aws_byte_cursor_from_c_str("Bucket"), aws_byte_cursor_from_c_str("s3-bucket-test")));

    struct aws_endpoints_resolved_endpoint *resolved_endpoint;
    ASSERT_SUCCESS(aws_endpoints_rule_engine_resolve(rule_engine, context, &resolved_endpoint));

    ASSERT_INT_EQUALS(AWS_ENDPOINTS_RESOLVED_ENDPOINT, aws_endpoints_resolved_endpoint_get_type(resolved_endpoint));

    struct aws_byte_cursor url_cur;
    ASSERT_SUCCESS(aws_endpoints_resolved_endpoint_get_url(resolved_endpoint, &url_cur));

    ASSERT_CURSOR_VALUE_CSTRING_EQUALS(url_cur, "https://s3-bucket-test.s3.us-west-2.amazonaws.com");

    aws_endpoints_resolved_endpoint_release(resolved_endpoint);
    aws_endpoints_request_context_release(context);
    aws_endpoints_rule_engine_release(rule_engine);

    aws_s3_library_clean_up();
    return 0;
}

AWS_TEST_CASE(test_s3_endpoint_resolver_resolve_endpoint_fips, s_test_s3_endpoint_resolver_resolve_endpoint_fips)
static int s_test_s3_endpoint_resolver_resolve_endpoint_fips(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    aws_s3_library_init(allocator);

    struct aws_endpoints_rule_engine *rule_engine = aws_s3_endpoint_resolver_new(allocator);
    ASSERT_NOT_NULL(rule_engine);
    struct aws_endpoints_request_context *context = aws_endpoints_request_context_new(allocator);
    ASSERT_NOT_NULL(context);
    ASSERT_SUCCESS(aws_endpoints_request_context_add_string(
        allocator, context, aws_byte_cursor_from_c_str("Region"), aws_byte_cursor_from_c_str("us-east-1")));
    ASSERT_SUCCESS(aws_endpoints_request_context_add_string(
        allocator, context, aws_byte_cursor_from_c_str("Bucket"), aws_byte_cursor_from_c_str("s3-bucket-test")));
    ASSERT_SUCCESS(
        aws_endpoints_request_context_add_boolean(allocator, context, aws_byte_cursor_from_c_str("UseFIPS"), true));
    struct aws_endpoints_resolved_endpoint *resolved_endpoint;
    ASSERT_SUCCESS(aws_endpoints_rule_engine_resolve(rule_engine, context, &resolved_endpoint));

    ASSERT_INT_EQUALS(AWS_ENDPOINTS_RESOLVED_ENDPOINT, aws_endpoints_resolved_endpoint_get_type(resolved_endpoint));

    struct aws_byte_cursor url_cur;
    ASSERT_SUCCESS(aws_endpoints_resolved_endpoint_get_url(resolved_endpoint, &url_cur));

    ASSERT_CURSOR_VALUE_CSTRING_EQUALS(url_cur, "https://s3-bucket-test.s3-fips.us-east-1.amazonaws.com");

    aws_endpoints_resolved_endpoint_release(resolved_endpoint);
    aws_endpoints_request_context_release(context);
    aws_endpoints_rule_engine_release(rule_engine);

    aws_s3_library_clean_up();
    return 0;
}

AWS_TEST_CASE(
    test_s3_endpoint_resolver_resolve_endpoint_force_path_style,
    s_test_s3_endpoint_resolver_resolve_endpoint_force_path_style)
static int s_test_s3_endpoint_resolver_resolve_endpoint_force_path_style(struct aws_allocator *allocator, void *ctx) {
    (void)ctx;
    aws_s3_library_init(allocator);

    struct aws_endpoints_rule_engine *rule_engine = aws_s3_endpoint_resolver_new(allocator);
    ASSERT_NOT_NULL(rule_engine);
    struct aws_endpoints_request_context *context = aws_endpoints_request_context_new(allocator);
    ASSERT_NOT_NULL(context);
    ASSERT_SUCCESS(aws_endpoints_request_context_add_string(
        allocator, context, aws_byte_cursor_from_c_str("Region"), aws_byte_cursor_from_c_str("us-east-1")));
    ASSERT_SUCCESS(aws_endpoints_request_context_add_string(
        allocator, context, aws_byte_cursor_from_c_str("Bucket"), aws_byte_cursor_from_c_str("s3-bucket-test")));
    ASSERT_SUCCESS(aws_endpoints_request_context_add_boolean(
        allocator, context, aws_byte_cursor_from_c_str("ForcePathStyle"), true));
    struct aws_endpoints_resolved_endpoint *resolved_endpoint;
    ASSERT_SUCCESS(aws_endpoints_rule_engine_resolve(rule_engine, context, &resolved_endpoint));

    ASSERT_INT_EQUALS(AWS_ENDPOINTS_RESOLVED_ENDPOINT, aws_endpoints_resolved_endpoint_get_type(resolved_endpoint));

    struct aws_byte_cursor url_cur;
    ASSERT_SUCCESS(aws_endpoints_resolved_endpoint_get_url(resolved_endpoint, &url_cur));

    ASSERT_CURSOR_VALUE_CSTRING_EQUALS(url_cur, "https://s3.us-east-1.amazonaws.com/s3-bucket-test");

    aws_endpoints_resolved_endpoint_release(resolved_endpoint);
    aws_endpoints_request_context_release(context);
    aws_endpoints_rule_engine_release(rule_engine);

    aws_s3_library_clean_up();
    return 0;
}

#endif