Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Sep 16, 2024
1 parent 47e0aa0 commit aecf6ca
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Release
*#
*.iml
tags
.vscode

#vim swap file
*.swp
Expand Down
4 changes: 2 additions & 2 deletions include/aws/auth/private/credentials_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void aws_credentials_provider_invoke_shutdown_callback(struct aws_credentials_pr
* A valid credentials must have "access key" and "secrete access key".
* For some services, token and expiration are not required.
* So in this API, the keys are provided by callers and this API will
* performe a case insensitive search.
* perform a case insensitive search.
*/
AWS_AUTH_API
struct aws_credentials *aws_parse_credentials_from_aws_json_object(
Expand All @@ -154,7 +154,7 @@ struct aws_credentials *aws_parse_credentials_from_aws_json_object(

/**
* This API is similar to aws_parse_credentials_from_aws_json_object,
* except it accpets a char buffer json document as it's input.
* except it accepts a char buffer json document as it's input.
*/
AWS_AUTH_API
struct aws_credentials *aws_parse_credentials_from_json_document(
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ add_test_case(credentials_file_path_environment_test)
add_test_case(profile_override_test)
add_test_case(profile_environment_test)

add_test_case(credentials_utils_construct_endpoint_test)

add_test_case(sigv4_skip_xray_header_test)
add_test_case(sigv4_skip_user_agent_header_test)
add_test_case(sigv4_skip_custom_header_test)
Expand Down
26 changes: 13 additions & 13 deletions tests/credentials_provider_sts_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,7 @@ AWS_TEST_CASE(
s_credentials_provider_sts_from_profile_config_with_chain_fn)

AWS_STATIC_STRING_FROM_LITERAL(s_ecs_creds_env_relative_uri, "AWS_CONTAINER_CREDENTIALS_RELATIVE_URI");
static const char *s_soure_credentials_ecs_config_file = "[default]\n"
static const char *s_source_credentials_ecs_config_file = "[default]\n"
"role_arn=arn:aws:iam::67895:role/test_role\n"
"credential_source=EcsContainer\n"
"role_session_name=test_session\n";
Expand All @@ -1290,9 +1290,9 @@ static int s_credentials_provider_sts_from_profile_config_with_ecs_credentials_s
ASSERT_SUCCESS(aws_set_environment_value(s_ecs_creds_env_relative_uri, relative_uri_str));

s_aws_sts_tester_init(allocator);
/* one for ecs provdier and one for sts provider */
/* one for ecs provider and one for sts provider */
s_tester.expected_connection_manager_shutdown_callback_count = 2;
struct aws_string *config_contents = aws_string_new_from_c_str(allocator, s_soure_credentials_ecs_config_file);
struct aws_string *config_contents = aws_string_new_from_c_str(allocator, s_source_credentials_ecs_config_file);

struct aws_string *config_file_str = aws_create_process_unique_file_name(allocator);
struct aws_string *creds_file_str = aws_create_process_unique_file_name(allocator);
Expand Down Expand Up @@ -1378,7 +1378,7 @@ AWS_TEST_CASE(
credentials_provider_sts_from_profile_config_with_ecs_credentials_source,
s_credentials_provider_sts_from_profile_config_with_ecs_credentials_source_fn)

static const char *s_soure_profile_chain_and_profile_config_file = "[default]\n"
static const char *s_source_profile_chain_and_profile_config_file = "[default]\n"
"aws_access_key_id=BLAHBLAH\n"
"aws_secret_access_key=BLAHBLAHBLAH\n"
"\n"
Expand Down Expand Up @@ -1408,7 +1408,7 @@ static int s_credentials_provider_sts_from_profile_config_with_chain_and_profile
s_aws_sts_tester_init(allocator);
s_tester.expected_connection_manager_shutdown_callback_count = 2;
struct aws_string *config_contents =
aws_string_new_from_c_str(allocator, s_soure_profile_chain_and_profile_config_file);
aws_string_new_from_c_str(allocator, s_source_profile_chain_and_profile_config_file);

struct aws_string *config_file_str = aws_create_process_unique_file_name(allocator);
struct aws_string *creds_file_str = aws_create_process_unique_file_name(allocator);
Expand Down Expand Up @@ -1487,7 +1487,7 @@ AWS_TEST_CASE(
credentials_provider_sts_from_profile_config_with_chain_and_profile_creds,
s_credentials_provider_sts_from_profile_config_with_chain_and_profile_creds_fn)

static const char *s_soure_profile_chain_and_partial_profile_config_file =
static const char *s_source_profile_chain_and_partial_profile_config_file =
"[default]\n"
"aws_access_key_id=BLAHBLAH\n"
"aws_secret_access_key=BLAHBLAHBLAH\n"
Expand Down Expand Up @@ -1517,7 +1517,7 @@ static int s_credentials_provider_sts_from_profile_config_with_chain_and_partial
s_aws_sts_tester_init(allocator);
s_tester.expected_connection_manager_shutdown_callback_count = 2;
struct aws_string *config_contents =
aws_string_new_from_c_str(allocator, s_soure_profile_chain_and_partial_profile_config_file);
aws_string_new_from_c_str(allocator, s_source_profile_chain_and_partial_profile_config_file);

struct aws_string *config_file_str = aws_create_process_unique_file_name(allocator);
struct aws_string *creds_file_str = aws_create_process_unique_file_name(allocator);
Expand Down Expand Up @@ -1558,7 +1558,7 @@ AWS_TEST_CASE(
credentials_provider_sts_from_profile_config_with_chain_and_partial_profile_creds,
s_credentials_provider_sts_from_profile_config_with_chain_and_partial_profile_creds_fn)

static const char *s_soure_profile_self_assume_role_config_file = "[default]\n"
static const char *s_source_profile_self_assume_role_config_file = "[default]\n"
"aws_access_key_id=BLAHBLAH\n"
"aws_secret_access_key=BLAHBLAHBLAH\n"
"\n"
Expand All @@ -1577,7 +1577,7 @@ static int s_credentials_provider_sts_from_self_referencing_profile_fn(struct aw

s_aws_sts_tester_init(allocator);
struct aws_string *config_contents =
aws_string_new_from_c_str(allocator, s_soure_profile_self_assume_role_config_file);
aws_string_new_from_c_str(allocator, s_source_profile_self_assume_role_config_file);

struct aws_string *config_file_str = aws_create_process_unique_file_name(allocator);
struct aws_string *creds_file_str = aws_create_process_unique_file_name(allocator);
Expand Down Expand Up @@ -1651,7 +1651,7 @@ AWS_TEST_CASE(
credentials_provider_sts_from_self_referencing_profile,
s_credentials_provider_sts_from_self_referencing_profile_fn)

static const char *s_soure_profile_chain_cycle_config_file = "[default]\n"
static const char *s_source_profile_chain_cycle_config_file = "[default]\n"
"aws_access_key_id=BLAHBLAH\n"
"aws_secret_access_key=BLAHBLAHBLAH\n"
"\n"
Expand Down Expand Up @@ -1679,7 +1679,7 @@ static int s_credentials_provider_sts_from_profile_config_with_chain_cycle_fn(

s_aws_sts_tester_init(allocator);

struct aws_string *config_contents = aws_string_new_from_c_str(allocator, s_soure_profile_chain_cycle_config_file);
struct aws_string *config_contents = aws_string_new_from_c_str(allocator, s_source_profile_chain_cycle_config_file);

struct aws_string *config_file_str = aws_create_process_unique_file_name(allocator);
struct aws_string *creds_file_str = aws_create_process_unique_file_name(allocator);
Expand Down Expand Up @@ -1712,7 +1712,7 @@ AWS_TEST_CASE(
credentials_provider_sts_from_profile_config_with_chain_cycle,
s_credentials_provider_sts_from_profile_config_with_chain_cycle_fn)

static const char *s_soure_profile_chain_cycle_and_static_creds_config_file =
static const char *s_source_profile_chain_cycle_and_static_creds_config_file =
"[roletest]\n"
"role_arn=arn:aws:iam::67895:role/test_role\n"
"source_profile=roletest2\n"
Expand Down Expand Up @@ -1740,7 +1740,7 @@ static int s_credentials_provider_sts_from_profile_config_with_chain_cycle_and_p
s_aws_sts_tester_init(allocator);

struct aws_string *config_contents =
aws_string_new_from_c_str(allocator, s_soure_profile_chain_cycle_and_static_creds_config_file);
aws_string_new_from_c_str(allocator, s_source_profile_chain_cycle_and_static_creds_config_file);

struct aws_string *config_file_str = aws_create_process_unique_file_name(allocator);
struct aws_string *creds_file_str = aws_create_process_unique_file_name(allocator);
Expand Down
60 changes: 60 additions & 0 deletions tests/credentials_utils_tests.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/testing/aws_test_harness.h>
#include <aws/auth/private/credentials_utils.h>

static int s_credentials_utils_construct_endpoint_test(struct aws_allocator *allocator, void *ctx) {
(void)ctx;

struct aws_string *service_name = aws_string_new_from_c_str("sts");

struct aws_string *endpoint;
struct aws_string *region;

region = aws_string_new_from_c_str("us-east-2");
ASSERT_SUCCESS(aws_credentials_provider_construct_regional_endpoint(allocator, &endpoint, aws_region, service_name));
ASSERT_STR_EQUALS("sts.us-east-2.amazonaws.com", aws_string_c_str(endpoint));
aws_string_destroy(endpoint);
aws_string_destroy(region);

region = aws_string_new_from_c_str("cn-northwest-1");
ASSERT_SUCCESS(aws_credentials_provider_construct_regional_endpoint(allocator, &endpoint, aws_region, service_name));
ASSERT_STR_EQUALS("sts.cn-northwest-1.amazonaws.com.cn", aws_string_c_str(endpoint));
aws_string_destroy(endpoint);
aws_string_destroy(region);

region = aws_string_new_from_c_str("us-iso-east-1");
ASSERT_SUCCESS(aws_credentials_provider_construct_regional_endpoint(allocator, &endpoint, aws_region, service_name));
ASSERT_STR_EQUALS("sts.us-iso-east-1.c2s.is.gov", aws_string_c_str(endpoint));
aws_string_destroy(endpoint);
aws_string_destroy(region);

region = aws_string_new_from_c_str("us-isob-east-1");
ASSERT_SUCCESS(aws_credentials_provider_construct_regional_endpoint(allocator, &endpoint, aws_region, service_name));
ASSERT_STR_EQUALS("sts.us-isob-east-1.sc2s.sgov.gov", aws_string_c_str(endpoint));
aws_string_destroy(endpoint);
aws_string_destroy(region);

region = aws_string_new_from_c_str("eu-isoe-west-1");
ASSERT_SUCCESS(aws_credentials_provider_construct_regional_endpoint(allocator, &endpoint, aws_region, service_name));
ASSERT_STR_EQUALS("sts.eu-isoe-west-1.cloud.adc-e.uk", aws_string_c_str(endpoint));
aws_string_destroy(endpoint);
aws_string_destroy(region);

region = aws_string_new_from_c_str("us-isof-south-1");
ASSERT_SUCCESS(aws_credentials_provider_construct_regional_endpoint(allocator, &endpoint, aws_region, service_name));
ASSERT_STR_EQUALS("sts.us-isof-south-1.csp.hci.ic.gov", aws_string_c_str(endpoint));
aws_string_destroy(endpoint);
aws_string_destroy(region);

aws_string_destroy(service_name);
aws_string_destroy(endpoint);

return 0;
}

AWS_TEST_CASE(credentials_utils_construct_endpoint_test, s_credentials_utils_construct_endpoint_test);

0 comments on commit aecf6ca

Please sign in to comment.