From ca96abd09129c887559ce0683c48d2d5c2b9baea Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 31 Jul 2024 13:45:04 -0700 Subject: [PATCH 1/4] add test --- tests/CMakeLists.txt | 1 + ...dentials_provider_sts_web_identity_tests.c | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1f0aa560..1912f9ec 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -72,6 +72,7 @@ add_test_case(credentials_provider_x509_real_new_destroy) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_parameters) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_env) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_config) +add_net_test_case(credentials_provider_sts_web_identity_fail_with_empty_config_or_env) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_cached_config) add_net_test_case(credentials_provider_sts_web_identity_new_failed_without_env_and_config) add_net_test_case(credentials_provider_sts_web_identity_connect_failure) diff --git a/tests/credentials_provider_sts_web_identity_tests.c b/tests/credentials_provider_sts_web_identity_tests.c index 73bf434e..9edb52f3 100644 --- a/tests/credentials_provider_sts_web_identity_tests.c +++ b/tests/credentials_provider_sts_web_identity_tests.c @@ -504,6 +504,55 @@ AWS_TEST_CASE( credentials_provider_sts_web_identity_new_destroy_from_config, s_credentials_provider_sts_web_identity_new_destroy_from_config); +AWS_STATIC_STRING_FROM_LITERAL( + s_basic_config_file, + "[profile foo]\n" + "region=us-east-1\n"); + +static int s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env(struct aws_allocator *allocator, void *ctx) { + (void)ctx; + + s_aws_sts_web_identity_tester_init(allocator); + + + struct aws_byte_buf content_buf = + aws_byte_buf_from_c_str(aws_string_c_str(s_basic_config_file)); + + struct aws_string *config_file_contents = aws_string_new_from_array(allocator, content_buf.buffer, content_buf.len); + ASSERT_TRUE(config_file_contents != NULL); + aws_byte_buf_clean_up(&content_buf); + + s_aws_sts_web_identity_test_init_config_profile(allocator, config_file_contents); + aws_string_destroy(config_file_contents); + + s_aws_sts_web_identity_test_init_env_parameters( + allocator, + "", + "", + "", + ""); + + + struct aws_credentials_provider_sts_web_identity_options options = { + .bootstrap = NULL, + .tls_ctx = s_tester.tls_ctx, + .function_table = &s_mock_function_table, + .shutdown_options = + { + .shutdown_callback = s_on_shutdown_complete, + .shutdown_user_data = NULL, + }, + }; + + ASSERT_NULL(aws_credentials_provider_new_sts_web_identity(allocator, &options)); + s_aws_sts_web_identity_tester_cleanup(); + return 0; +} +AWS_TEST_CASE( + credentials_provider_sts_web_identity_fail_with_empty_config_or_env, + s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env); + + static int s_credentials_provider_sts_web_identity_new_destroy_from_cached_config( struct aws_allocator *allocator, void *ctx) { From ce4a4ea860f7f443d794870bf76203f30dfda2c1 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 31 Jul 2024 13:49:08 -0700 Subject: [PATCH 2/4] fix it --- source/credentials_provider_sts_web_identity.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/credentials_provider_sts_web_identity.c b/source/credentials_provider_sts_web_identity.c index 5aaafe78..f42244b8 100644 --- a/source/credentials_provider_sts_web_identity.c +++ b/source/credentials_provider_sts_web_identity.c @@ -924,6 +924,7 @@ static void s_check_or_get_with_profile_config( if ((!(*target) || !(*target)->len)) { if (*target) { aws_string_destroy(*target); + *target = NULL; } const struct aws_profile_property *property = aws_profile_get_property(profile, config_key); if (property) { From 8eb5bafb4c79b8b7ead3264315842db88bcc4b42 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 31 Jul 2024 13:50:59 -0700 Subject: [PATCH 3/4] lint --- ...redentials_provider_sts_web_identity_tests.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/credentials_provider_sts_web_identity_tests.c b/tests/credentials_provider_sts_web_identity_tests.c index 9edb52f3..c76f9d5d 100644 --- a/tests/credentials_provider_sts_web_identity_tests.c +++ b/tests/credentials_provider_sts_web_identity_tests.c @@ -509,14 +509,14 @@ AWS_STATIC_STRING_FROM_LITERAL( "[profile foo]\n" "region=us-east-1\n"); -static int s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env(struct aws_allocator *allocator, void *ctx) { +static int s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env( + struct aws_allocator *allocator, + void *ctx) { (void)ctx; s_aws_sts_web_identity_tester_init(allocator); - - struct aws_byte_buf content_buf = - aws_byte_buf_from_c_str(aws_string_c_str(s_basic_config_file)); + struct aws_byte_buf content_buf = aws_byte_buf_from_c_str(aws_string_c_str(s_basic_config_file)); struct aws_string *config_file_contents = aws_string_new_from_array(allocator, content_buf.buffer, content_buf.len); ASSERT_TRUE(config_file_contents != NULL); @@ -525,13 +525,7 @@ static int s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env s_aws_sts_web_identity_test_init_config_profile(allocator, config_file_contents); aws_string_destroy(config_file_contents); - s_aws_sts_web_identity_test_init_env_parameters( - allocator, - "", - "", - "", - ""); - + s_aws_sts_web_identity_test_init_env_parameters(allocator, "", "", "", ""); struct aws_credentials_provider_sts_web_identity_options options = { .bootstrap = NULL, @@ -552,7 +546,6 @@ AWS_TEST_CASE( credentials_provider_sts_web_identity_fail_with_empty_config_or_env, s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env); - static int s_credentials_provider_sts_web_identity_new_destroy_from_cached_config( struct aws_allocator *allocator, void *ctx) { From 7789cae41d0e95b005de1e4b7273163c0664a2dd Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 31 Jul 2024 13:54:23 -0700 Subject: [PATCH 4/4] rename test --- tests/CMakeLists.txt | 2 +- tests/credentials_provider_sts_web_identity_tests.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1912f9ec..adc2151e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -72,7 +72,7 @@ add_test_case(credentials_provider_x509_real_new_destroy) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_parameters) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_env) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_config) -add_net_test_case(credentials_provider_sts_web_identity_fail_with_empty_config_or_env) +add_net_test_case(credentials_provider_sts_web_identity_fail_with_empty_config_and_env) add_net_test_case(credentials_provider_sts_web_identity_new_destroy_from_cached_config) add_net_test_case(credentials_provider_sts_web_identity_new_failed_without_env_and_config) add_net_test_case(credentials_provider_sts_web_identity_connect_failure) diff --git a/tests/credentials_provider_sts_web_identity_tests.c b/tests/credentials_provider_sts_web_identity_tests.c index c76f9d5d..80b18580 100644 --- a/tests/credentials_provider_sts_web_identity_tests.c +++ b/tests/credentials_provider_sts_web_identity_tests.c @@ -509,7 +509,7 @@ AWS_STATIC_STRING_FROM_LITERAL( "[profile foo]\n" "region=us-east-1\n"); -static int s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env( +static int s_credentials_provider_sts_web_identity_fail_with_empty_config_and_env( struct aws_allocator *allocator, void *ctx) { (void)ctx; @@ -543,8 +543,8 @@ static int s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env return 0; } AWS_TEST_CASE( - credentials_provider_sts_web_identity_fail_with_empty_config_or_env, - s_credentials_provider_sts_web_identity_fail_with_empty_config_or_env); + credentials_provider_sts_web_identity_fail_with_empty_config_and_env, + s_credentials_provider_sts_web_identity_fail_with_empty_config_and_env); static int s_credentials_provider_sts_web_identity_new_destroy_from_cached_config( struct aws_allocator *allocator,