diff --git a/.gitignore b/.gitignore index 6a8a3686..8b120dc3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ Release *# *.iml tags +.vscode #vim swap file *.swp diff --git a/include/aws/auth/private/credentials_utils.h b/include/aws/auth/private/credentials_utils.h index 269789e9..041023b0 100644 --- a/include/aws/auth/private/credentials_utils.h +++ b/include/aws/auth/private/credentials_utils.h @@ -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( @@ -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( diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2f9bf6a..b884191d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -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) diff --git a/tests/credentials_provider_sts_tests.c b/tests/credentials_provider_sts_tests.c index f3896db8..277f4fef 100644 --- a/tests/credentials_provider_sts_tests.c +++ b/tests/credentials_provider_sts_tests.c @@ -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"; @@ -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); @@ -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" @@ -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); @@ -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" @@ -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); @@ -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" @@ -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); @@ -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" @@ -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); @@ -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" @@ -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); diff --git a/tests/credentials_utils_tests.c b/tests/credentials_utils_tests.c new file mode 100644 index 00000000..ecca94f9 --- /dev/null +++ b/tests/credentials_utils_tests.c @@ -0,0 +1,60 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include +#include + +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); +