From b18eb92d3916f612f63ab2461804a9c53b154e24 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 14:36:17 -0800 Subject: [PATCH 01/13] add a new section --- include/aws/sdkutils/aws_profile.h | 1 + source/aws_profile.c | 73 +++++++++++++++++------------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/include/aws/sdkutils/aws_profile.h b/include/aws/sdkutils/aws_profile.h index 8964069..801af07 100644 --- a/include/aws/sdkutils/aws_profile.h +++ b/include/aws/sdkutils/aws_profile.h @@ -43,6 +43,7 @@ enum aws_profile_source_type { AWS_PST_NONE, AWS_PST_CONFIG, AWS_PST_CREDENTIALS enum aws_profile_section_type { AWS_PROFILE_SECTION_TYPE_PROFILE, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, + AWS_PROFILE_SECTION_TYPE_SERVICES, AWS_PROFILE_SECTION_TYPE_COUNT, }; diff --git a/source/aws_profile.c b/source/aws_profile.c index 1128bf7..7bb192b 100644 --- a/source/aws_profile.c +++ b/source/aws_profile.c @@ -612,6 +612,7 @@ static void s_aws_profile_collection_destroy_internal(struct aws_profile_collect AWS_STATIC_STRING_FROM_LITERAL(s_profile_token, "profile"); AWS_STATIC_STRING_FROM_LITERAL(s_sso_session_token, "sso-session"); +AWS_STATIC_STRING_FROM_LITERAL(s_services_token, "services"); const struct aws_profile *aws_profile_collection_get_profile( const struct aws_profile_collection *profile_collection, @@ -635,7 +636,7 @@ static int s_profile_collection_add_profile( struct aws_profile_collection *profile_collection, const enum aws_profile_section_type section_type, const struct aws_byte_cursor *profile_name, - bool has_prefix, + bool has_profile_prefix, const struct profile_file_parse_context *context, struct aws_profile **current_profile_out) { @@ -660,7 +661,7 @@ static int s_profile_collection_add_profile( /* * In a config file, "profile default" always supercedes "default" */ - if (!has_prefix && existing_profile && existing_profile->has_profile_prefix) { + if (!has_profile_prefix && existing_profile && existing_profile->has_profile_prefix) { /* * existing one supercedes: ignore this (and its properties) completely by failing the add * which sets the current profile to NULL @@ -673,7 +674,7 @@ static int s_profile_collection_add_profile( return AWS_OP_SUCCESS; } - if (has_prefix && existing_profile && !existing_profile->has_profile_prefix) { + if (has_profile_prefix && existing_profile && !existing_profile->has_profile_prefix) { /* * stomp over existing: remove it, then proceed with add * element destroy function will clean up the profile and key @@ -692,7 +693,7 @@ static int s_profile_collection_add_profile( return AWS_OP_SUCCESS; } - struct aws_profile *new_profile = aws_profile_new(profile_collection->allocator, profile_name, has_prefix); + struct aws_profile *new_profile = aws_profile_new(profile_collection->allocator, profile_name, has_profile_prefix); if (new_profile == NULL) { goto on_aws_profile_new_failure; } @@ -862,6 +863,29 @@ static struct aws_byte_cursor s_trim_trailing_whitespace_comment(const struct aw return trimmed; } +static int s_parse_section_declaration_prefix(struct aws_byte_cursor *profile_cursor, + enum aws_profile_section_type *out_section_type) { + /* check profile prefix */ + if(s_parse_by_token(profile_cursor, s_profile_token, NULL) && + s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + *out_section_type = AWS_PROFILE_SECTION_TYPE_PROFILE; + return AWS_OP_SUCCESS; + } + /* check sso-session prefix */ + if(s_parse_by_token(profile_cursor, s_sso_session_token, NULL) && s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + *out_section_type = AWS_PROFILE_SECTION_TYPE_SSO_SESSION; + return AWS_OP_SUCCESS; + } + /* check services prefix */ + if(s_parse_by_token(profile_cursor, s_services_token, NULL) && + s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + *out_section_type = AWS_PROFILE_SECTION_TYPE_SERVICES; + return AWS_OP_SUCCESS; + } + + return aws_raise_error(AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE); +} + /** * Attempts to parse profile declaration lines * @@ -892,24 +916,25 @@ static bool s_parse_profile_declaration( context->current_property = NULL; s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 0); - enum aws_profile_section_type section_type = AWS_PROFILE_SECTION_TYPE_PROFILE; + + enum aws_profile_section_type section_type; + /* - * Check if the profile name starts with the 'profile' keyword. We need to check for - * "profile" and at least one whitespace character. A partial match + * Check if the profile name starts with a valid prefix. We need to check for + * prefix and at least one whitespace character. A partial match like * ("[profilefoo]" for example) should rewind and use the whole name properly. */ struct aws_byte_cursor backtrack_cursor = profile_cursor; - bool has_profile_prefix = s_parse_by_token(&profile_cursor, s_profile_token, NULL) && - s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 1); - bool has_sso_session_prefix = !has_profile_prefix && s_parse_by_token(&profile_cursor, s_sso_session_token, NULL) && - s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 1); - - if (has_profile_prefix) { + bool valid_section_declation_prefix = false; + if(s_parse_section_declaration_prefix(&profile_cursor, §ion_type) != AWS_OP_SUCCESS) { + profile_cursor = backtrack_cursor; + } else { + valid_section_declation_prefix = true; if (context->profile_collection->profile_source == AWS_PST_CREDENTIALS) { AWS_LOGF_WARN( AWS_LS_SDKUTILS_PROFILE, - "Profile declarations in credentials files are not allowed to begin with the \"profile\" keyword"); + "Profile declarations in credentials files are not allowed to begin with the section-type keyword"); s_log_parse_context(AWS_LL_WARN, context); context->parse_error = AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE; @@ -917,20 +942,7 @@ static bool s_parse_profile_declaration( } s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 0); - } else if (has_sso_session_prefix) { - if (context->profile_collection->profile_source == AWS_PST_CREDENTIALS) { - AWS_LOGF_WARN(AWS_LS_SDKUTILS_PROFILE, "sso-session declarations in credentials files are not allowed"); - s_log_parse_context(AWS_LL_WARN, context); - - context->parse_error = AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE; - return true; - } - section_type = AWS_PROFILE_SECTION_TYPE_SSO_SESSION; - s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 0); - } else { - profile_cursor = backtrack_cursor; - } - + } struct aws_byte_cursor profile_name; if (!s_parse_by_character_predicate(&profile_cursor, s_is_identifier, &profile_name, 0)) { AWS_LOGF_WARN(AWS_LS_SDKUTILS_PROFILE, "Profile declarations must contain a valid identifier for a name"); @@ -940,8 +952,7 @@ static bool s_parse_profile_declaration( return true; } - if (context->profile_collection->profile_source == AWS_PST_CONFIG && !has_profile_prefix && - !s_is_default_profile_name(&profile_name) && !has_sso_session_prefix) { + if (context->profile_collection->profile_source == AWS_PST_CONFIG && !valid_section_declation_prefix && !s_is_default_profile_name(&profile_name)) { AWS_LOGF_WARN( AWS_LS_SDKUTILS_PROFILE, "Non-default profile declarations in config files must use the \"profile\" keyword"); @@ -989,7 +1000,7 @@ static bool s_parse_profile_declaration( context->profile_collection, section_type, &profile_name, - has_profile_prefix, + valid_section_declation_prefix && section_type == AWS_PROFILE_SECTION_TYPE_PROFILE, context, &context->current_profile)) { AWS_LOGF_ERROR(AWS_LS_SDKUTILS_PROFILE, "Failed to add profile to profile collection"); From 84c731f998bc46e4f51b4b71eeaddd4cd213ae15 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 14:38:31 -0800 Subject: [PATCH 02/13] fix 3 defines --- tests/aws_profile_tests.c | 341 ++++++++++++++++++-------------------- 1 file changed, 164 insertions(+), 177 deletions(-) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index 7f18221..c9251eb 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -9,22 +9,26 @@ #include #include -#define EXPECT_PROFILE_COUNT(profile_collection, profile_count) \ - { ASSERT_TRUE(aws_profile_collection_get_profile_count(profile_collection) == (profile_count)); } +#define EXPECT_SECTION_COUNT(profile_collection, section_type, section_count) \ + { \ + ASSERT_TRUE(aws_profile_collection_get_section_count(profile_collection, section_type) == (section_count)); \ + } -#define EXPECT_PROFILE(profile_collection, profile_name) \ +#define EXPECT_SECTION(profile_collection, section_type, section_name) \ { \ - struct aws_string *profile_name_str = aws_string_new_from_c_str(allocator, profile_name); \ - const struct aws_profile *profile = aws_profile_collection_get_profile(profile_collection, profile_name_str); \ - aws_string_destroy(profile_name_str); \ + struct aws_string *section_name_str = aws_string_new_from_c_str(allocator, section_name); \ + const struct aws_profile *profile = \ + aws_profile_collection_get_section(profile_collection, section_type, section_name_str); \ + aws_string_destroy(section_name_str); \ ASSERT_TRUE(profile != NULL); \ } -#define EXPECT_PROPERTY_COUNT(profile_collection, profile_name, expected_property_count) \ +#define EXPECT_PROPERTY_COUNT(profile_collection, section_type, section_name, expected_property_count) \ { \ - struct aws_string *profile_name_str = aws_string_new_from_c_str(allocator, profile_name); \ - const struct aws_profile *profile = aws_profile_collection_get_profile(profile_collection, profile_name_str); \ - aws_string_destroy(profile_name_str); \ + struct aws_string *section_name_str = aws_string_new_from_c_str(allocator, section_name); \ + const struct aws_profile *profile = \ + aws_profile_collection_get_section(profile_collection, section_type, section_name_str); \ + aws_string_destroy(section_name_str); \ ASSERT_TRUE(aws_profile_get_property_count(profile) == (expected_property_count)); \ } @@ -68,30 +72,6 @@ ASSERT_TRUE(strcmp(expected_sub_property_value, aws_string_c_str(sub_property_value)) == 0); \ } -#define EXPECT_SSO_SESSION_COUNT(profile_collection, sso_session_count) \ - { \ - ASSERT_TRUE( \ - aws_profile_collection_get_section_count(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION) == \ - (sso_session_count)); \ - } - -#define EXPECT_SSO_SESSION(profile_collection, sso_session_name) \ - { \ - struct aws_string *sso_session_name_str = aws_string_new_from_c_str(allocator, sso_session_name); \ - const struct aws_profile *sso_session = aws_profile_collection_get_section( \ - profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, sso_session_name_str); \ - aws_string_destroy(sso_session_name_str); \ - ASSERT_TRUE(sso_session != NULL); \ - } -#define EXPECT_SSO_SESSION_PROPERTY_COUNT(profile_collection, sso_session_name, expected_sso_session_count) \ - { \ - struct aws_string *sso_session_name_str = aws_string_new_from_c_str(allocator, sso_session_name); \ - const struct aws_profile *sso_session = aws_profile_collection_get_section( \ - profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, sso_session_name_str); \ - aws_string_destroy(sso_session_name_str); \ - ASSERT_TRUE(aws_profile_get_property_count(sso_session) == (expected_sso_session_count)); \ - } - #define EXPECT_SSO_SESSION_PROPERTY(profile_collection, sso_session_name, property_name, expected_property_value) \ { \ struct aws_string *sso_session_name_str = aws_string_new_from_c_str(allocator, sso_session_name); \ @@ -206,7 +186,7 @@ static int s_aws_profile_empty_test(struct aws_allocator *allocator, void *ctx) aws_prepare_profile_test(allocator, s_empty_string, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); aws_profile_collection_destroy(profile_collection); @@ -227,9 +207,9 @@ static int s_aws_profile_empty_profile_test(struct aws_allocator *allocator, voi aws_prepare_profile_test(allocator, s_empty_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 0); aws_profile_collection_destroy(profile_collection); @@ -250,9 +230,9 @@ static int s_aws_profile_whitespace_empty_profile_test(struct aws_allocator *all aws_prepare_profile_test(allocator, s_whitespace_empty_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 0); aws_profile_collection_destroy(profile_collection); @@ -273,9 +253,9 @@ static int s_aws_profile_tab_empty_profile_test(struct aws_allocator *allocator, aws_prepare_profile_test(allocator, s_tab_empty_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 0); aws_profile_collection_destroy(profile_collection); @@ -296,9 +276,9 @@ static int s_aws_profile_single_simple_property_profile_test(struct aws_allocato aws_prepare_profile_test(allocator, s_single_simple_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -320,9 +300,9 @@ static int s_aws_profile_equal_containing_property_profile_test(struct aws_alloc aws_prepare_profile_test(allocator, s_equal_containing_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "val=ue"); aws_profile_collection_destroy(profile_collection); @@ -344,9 +324,9 @@ static int s_aws_profile_unicode_containing_property_profile_test(struct aws_all aws_prepare_profile_test(allocator, s_unicode_containing_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "\xF0\x9F\x98\x82"); aws_profile_collection_destroy(profile_collection); @@ -370,9 +350,9 @@ static int s_aws_profile_multiple_property_profile_test(struct aws_allocator *al aws_prepare_profile_test(allocator, s_multiple_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 2); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); EXPECT_PROPERTY(profile_collection, "foo", "name2", "value2"); @@ -395,9 +375,9 @@ static int s_aws_profile_trimmable_property_profile_test(struct aws_allocator *a aws_prepare_profile_test(allocator, s_trimmable_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -419,9 +399,9 @@ static int s_aws_profile_empty_property_profile_test(struct aws_allocator *alloc aws_prepare_profile_test(allocator, s_empty_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", ""); aws_profile_collection_destroy(profile_collection); @@ -443,11 +423,11 @@ static int s_aws_profile_multiple_empty_profile_test(struct aws_allocator *alloc aws_prepare_profile_test(allocator, s_multiple_empty_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 2); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 0); - EXPECT_PROFILE(profile_collection, "bar"); - EXPECT_PROPERTY_COUNT(profile_collection, "bar", 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 0); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 0); aws_profile_collection_destroy(profile_collection); @@ -468,12 +448,12 @@ static int s_aws_profile_multiple_profile_test(struct aws_allocator *allocator, aws_prepare_profile_test(allocator, s_multiple_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 2); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); - EXPECT_PROFILE(profile_collection, "bar"); - EXPECT_PROPERTY_COUNT(profile_collection, "bar", 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 1); EXPECT_PROPERTY(profile_collection, "bar", "name2", "value2"); aws_profile_collection_destroy(profile_collection); @@ -498,17 +478,17 @@ static int s_aws_profile_multiple_profile_with_sso_session_test(struct aws_alloc aws_prepare_profile_test(allocator, s_credentials_sso_session, AWS_PST_CONFIG); ASSERT_NOT_NULL(profile_collection); - EXPECT_PROFILE_COUNT(profile_collection, 2); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); - EXPECT_PROFILE(profile_collection, "bar"); - EXPECT_PROPERTY_COUNT(profile_collection, "bar", 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 1); EXPECT_PROPERTY(profile_collection, "bar", "name2", "value2"); - EXPECT_SSO_SESSION_COUNT(profile_collection, 1); - EXPECT_SSO_SESSION(profile_collection, "session"); - EXPECT_SSO_SESSION_PROPERTY_COUNT(profile_collection, "session", 2); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 2); EXPECT_SSO_SESSION_PROPERTY(profile_collection, "session", "name3", "value3"); EXPECT_SSO_SESSION_SUB_PROPERTY_COUNT(profile_collection, "session", "s3", 1); EXPECT_SSO_SESSION_SUB_PROPERTY(profile_collection, "session", "s3", "name4", "value4"); @@ -533,8 +513,8 @@ static int s_aws_profile_sso_session_in_credentials_test(struct aws_allocator *a aws_prepare_profile_test(allocator, s_sso_session_in_credentials, AWS_PST_CREDENTIALS); ASSERT_NOT_NULL(profile_collection); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_SSO_SESSION_COUNT(profile_collection, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); aws_profile_collection_destroy(profile_collection); return 0; @@ -554,10 +534,10 @@ static int s_aws_profile_sso_session_without_name_test(struct aws_allocator *all aws_prepare_profile_test(allocator, s_sso_session_without_name, AWS_PST_CONFIG); ASSERT_NOT_NULL(profile_collection); - EXPECT_PROFILE_COUNT(profile_collection, 0); - EXPECT_SSO_SESSION_COUNT(profile_collection, 1); - EXPECT_SSO_SESSION(profile_collection, "session"); - EXPECT_SSO_SESSION_PROPERTY_COUNT(profile_collection, "session", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 1); EXPECT_SSO_SESSION_PROPERTY(profile_collection, "session", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -580,12 +560,12 @@ static int s_aws_profile_blank_lines_ignored_test(struct aws_allocator *allocato aws_prepare_profile_test(allocator, s_blank_lines_ignored_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 2); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); - EXPECT_PROFILE(profile_collection, "bar"); - EXPECT_PROPERTY_COUNT(profile_collection, "bar", 0); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 0); aws_profile_collection_destroy(profile_collection); @@ -608,9 +588,9 @@ static int s_aws_profile_pound_comments_ignored_test(struct aws_allocator *alloc aws_prepare_profile_test(allocator, s_pound_comments_ignored_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -634,9 +614,9 @@ static int s_aws_profile_semicolon_comments_ignored_test(struct aws_allocator *a aws_prepare_profile_test(allocator, s_semicolon_comments_ignored_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -660,9 +640,9 @@ static int s_aws_profile_mixed_comments_ignored_test(struct aws_allocator *alloc aws_prepare_profile_test(allocator, s_mixed_comments_ignored_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -684,9 +664,9 @@ static int s_aws_profile_empty_comments_ignored_test(struct aws_allocator *alloc aws_prepare_profile_test(allocator, s_empty_comments_ignored_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -710,11 +690,11 @@ static int s_aws_profile_profile_adjacent_comment_test(struct aws_allocator *all aws_prepare_profile_test(allocator, s_profile_adjacent_comment_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 2); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 0); - EXPECT_PROFILE(profile_collection, "bar"); - EXPECT_PROPERTY_COUNT(profile_collection, "bar", 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 0); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 0); aws_profile_collection_destroy(profile_collection); @@ -737,9 +717,9 @@ static int s_aws_profile_value_adjacent_comment_test(struct aws_allocator *alloc aws_prepare_profile_test(allocator, s_value_adjacent_comment_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 2); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); EXPECT_PROPERTY(profile_collection, "foo", "name", "value; Adjacent semicolons"); EXPECT_PROPERTY(profile_collection, "foo", "name2", "value# Adjacent pound signs"); @@ -762,9 +742,9 @@ static int s_aws_profile_continued_property_value_test(struct aws_allocator *all aws_prepare_profile_test(allocator, s_continued_property_value_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued"); aws_profile_collection_destroy(profile_collection); @@ -788,9 +768,9 @@ static int s_aws_profile_multiline_continued_property_value_test(struct aws_allo aws_prepare_profile_test(allocator, s_multiline_continued_property_value_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued\n-and-continued"); aws_profile_collection_destroy(profile_collection); @@ -816,9 +796,9 @@ static int s_aws_profile_continued_property_value_trim_test(struct aws_allocator aws_prepare_profile_test(allocator, s_continued_property_value_trim_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued"); aws_profile_collection_destroy(profile_collection); @@ -842,9 +822,9 @@ static int s_aws_profile_continued_property_value_pound_comment_test(struct aws_ aws_prepare_profile_test(allocator, s_continued_property_value_pound_comment_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued # Comment"); aws_profile_collection_destroy(profile_collection); @@ -870,9 +850,9 @@ static int s_aws_profile_continued_property_value_semicolon_comment_test(struct aws_prepare_profile_test(allocator, s_continued_property_value_semicolon_comment_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued ; Comment"); aws_profile_collection_destroy(profile_collection); @@ -899,15 +879,15 @@ static int s_aws_profile_duplicate_profiles_merge_test(struct aws_allocator *all aws_prepare_profile_test(allocator, s_duplicate_profiles_merge_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 2); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); EXPECT_PROPERTY(profile_collection, "foo", "name2", "value2"); - EXPECT_SSO_SESSION_COUNT(profile_collection, 1); - EXPECT_SSO_SESSION(profile_collection, "foo"); - EXPECT_SSO_SESSION_PROPERTY_COUNT(profile_collection, "foo", 2); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo", 2); EXPECT_SSO_SESSION_PROPERTY(profile_collection, "foo", "name3", "value3"); EXPECT_SSO_SESSION_PROPERTY(profile_collection, "foo", "name4", "value4"); @@ -932,9 +912,9 @@ static int s_aws_profile_duplicate_properties_last_property_value_test(struct aw aws_prepare_profile_test(allocator, s_duplicate_properties_last_property_value_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value2"); aws_profile_collection_destroy(profile_collection); @@ -960,9 +940,9 @@ static int s_aws_profile_duplicate_profiles_last_property_value_test(struct aws_ aws_prepare_profile_test(allocator, s_duplicate_profiles_last_property_value_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value2"); aws_profile_collection_destroy(profile_collection); @@ -990,9 +970,9 @@ static int s_aws_profile_duplicate_default_profiles_property_resolution1_test( aws_prepare_profile_test(allocator, s_duplicate_default_profiles_property_resolution1_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "default"); - EXPECT_PROPERTY_COUNT(profile_collection, "default", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", 1); EXPECT_PROPERTY(profile_collection, "default", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -1020,9 +1000,9 @@ static int s_aws_profile_duplicate_default_profiles_property_resolution2_test( aws_prepare_profile_test(allocator, s_duplicate_default_profiles_property_resolution2_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "default"); - EXPECT_PROPERTY_COUNT(profile_collection, "default", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", 1); EXPECT_PROPERTY(profile_collection, "default", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -1047,7 +1027,7 @@ static int s_aws_profile_invalid_profile_names_merge_test(struct aws_allocator * allocator, s_invalid_profile_names_config_profile, s_invalid_profile_names_credentials_profile); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); aws_profile_collection_destroy(profile_collection); @@ -1068,9 +1048,9 @@ static int s_aws_profile_invalid_property_names_ignored_test(struct aws_allocato aws_prepare_profile_test(allocator, s_invalid_property_names_ignored_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 0); aws_profile_collection_destroy(profile_collection); @@ -1093,9 +1073,16 @@ static int s_aws_profile_all_valid_profile_characters_test(struct aws_allocator aws_prepare_profile_test(allocator, s_all_valid_profile_characters_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); - EXPECT_PROPERTY_COUNT(profile_collection, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION( + profile_collection, + AWS_PROFILE_SECTION_TYPE_PROFILE, + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); + EXPECT_PROPERTY_COUNT( + profile_collection, + AWS_PROFILE_SECTION_TYPE_PROFILE, + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", + 0); aws_profile_collection_destroy(profile_collection); @@ -1118,9 +1105,9 @@ static int s_aws_profile_all_valid_property_characters_test(struct aws_allocator aws_prepare_profile_test(allocator, s_all_valid_property_characters_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY( profile_collection, "foo", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "value"); @@ -1143,9 +1130,9 @@ static int s_aws_profile_basic_sub_property_test(struct aws_allocator *allocator aws_prepare_profile_test(allocator, s_basic_sub_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nname = value"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 1); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); @@ -1170,9 +1157,9 @@ static int s_aws_profile_empty_sub_property_test(struct aws_allocator *allocator aws_prepare_profile_test(allocator, s_empty_sub_property_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nname ="); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 1); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", ""); @@ -1197,9 +1184,9 @@ static int s_aws_profile_invalid_sub_property_name_test(struct aws_allocator *al aws_prepare_profile_test(allocator, s_invalid_sub_property_name_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nin valid = value"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 0); @@ -1225,9 +1212,9 @@ static int s_aws_profile_sub_property_blank_line_test(struct aws_allocator *allo aws_prepare_profile_test(allocator, s_sub_property_blank_line_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nname = value\nname2 = value2"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 2); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); @@ -1253,9 +1240,9 @@ static int s_aws_profile_basic_duplicate_merge_test(struct aws_allocator *alloca allocator, s_basic_duplicate_config_profile, s_basic_duplicate_credentials_profile); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 2); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); EXPECT_PROPERTY(profile_collection, "foo", "name2", "value2"); @@ -1281,9 +1268,9 @@ static int s_aws_profile_mixed_prefix_default_test(struct aws_allocator *allocat aws_prepare_profile_test(allocator, s_mixed_prefix_default_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "default"); - EXPECT_PROPERTY_COUNT(profile_collection, "default", 2); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", 2); EXPECT_PROPERTY(profile_collection, "default", "name", "value"); EXPECT_PROPERTY(profile_collection, "default", "name3", "value3"); @@ -1308,9 +1295,9 @@ static int s_aws_profile_override_duplicate_merge_test(struct aws_allocator *all allocator, s_override_duplicate_config_profile, s_override_duplicate_credentials_profile); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 1); - EXPECT_PROFILE(profile_collection, "foo"); - EXPECT_PROPERTY_COUNT(profile_collection, "foo", 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, "foo", "name", "value2"); aws_profile_collection_destroy(profile_collection); @@ -1333,7 +1320,7 @@ static int s_aws_profile_no_prefix_nondefault_test(struct aws_allocator *allocat aws_prepare_profile_test(allocator, s_no_prefix_nondefault_profile, AWS_PST_CONFIG); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); aws_profile_collection_destroy(profile_collection); @@ -1355,7 +1342,7 @@ static int s_aws_profile_prefix_credentials_test(struct aws_allocator *allocator aws_prepare_profile_test(allocator, s_prefix_credentials_profile, AWS_PST_CREDENTIALS); ASSERT_TRUE(profile_collection != NULL); - EXPECT_PROFILE_COUNT(profile_collection, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); aws_profile_collection_destroy(profile_collection); From eb5d0dd94838a9ebe930d963ac31be94086e200d Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 14:46:08 -0800 Subject: [PATCH 03/13] 3rd change --- tests/aws_profile_tests.c | 118 ++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 62 deletions(-) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index c9251eb..4825887 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -31,15 +31,15 @@ aws_string_destroy(section_name_str); \ ASSERT_TRUE(aws_profile_get_property_count(profile) == (expected_property_count)); \ } - -#define EXPECT_PROPERTY(profile_collection, profile_name, property_name, expected_property_value) \ +#define EXPECT_PROPERTY(profile_collection, section_type, section_name, property_name, expected_property_value) \ { \ - struct aws_string *profile_name_str = aws_string_new_from_c_str(allocator, profile_name); \ - const struct aws_profile *profile = aws_profile_collection_get_profile(profile_collection, profile_name_str); \ + struct aws_string *section_name_str = aws_string_new_from_c_str(allocator, section_name); \ + const struct aws_profile *profile = \ + aws_profile_collection_get_section(profile_collection, section_type, section_name_str); \ struct aws_string *property_name_str = aws_string_new_from_c_str(allocator, property_name); \ const struct aws_profile_property *property = aws_profile_get_property(profile, property_name_str); \ aws_string_destroy(property_name_str); \ - aws_string_destroy(profile_name_str); \ + aws_string_destroy(section_name_str); \ ASSERT_TRUE( \ property != NULL && \ strcmp(expected_property_value, aws_string_c_str(aws_profile_property_get_value(property))) == 0); \ @@ -72,20 +72,6 @@ ASSERT_TRUE(strcmp(expected_sub_property_value, aws_string_c_str(sub_property_value)) == 0); \ } -#define EXPECT_SSO_SESSION_PROPERTY(profile_collection, sso_session_name, property_name, expected_property_value) \ - { \ - struct aws_string *sso_session_name_str = aws_string_new_from_c_str(allocator, sso_session_name); \ - const struct aws_profile *sso_session = aws_profile_collection_get_section( \ - profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, sso_session_name_str); \ - struct aws_string *property_name_str = aws_string_new_from_c_str(allocator, property_name); \ - const struct aws_profile_property *property = aws_profile_get_property(sso_session, property_name_str); \ - aws_string_destroy(property_name_str); \ - aws_string_destroy(sso_session_name_str); \ - ASSERT_TRUE( \ - property != NULL && \ - strcmp(expected_property_value, aws_string_c_str(aws_profile_property_get_value(property))) == 0); \ - } - #define EXPECT_SSO_SESSION_SUB_PROPERTY_COUNT( \ profile_collection, sso_session_name, property_name, expected_sub_property_count) \ { \ @@ -279,7 +265,7 @@ static int s_aws_profile_single_simple_property_profile_test(struct aws_allocato EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -303,7 +289,7 @@ static int s_aws_profile_equal_containing_property_profile_test(struct aws_alloc EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "val=ue"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "val=ue"); aws_profile_collection_destroy(profile_collection); @@ -327,7 +313,7 @@ static int s_aws_profile_unicode_containing_property_profile_test(struct aws_all EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "\xF0\x9F\x98\x82"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "\xF0\x9F\x98\x82"); aws_profile_collection_destroy(profile_collection); @@ -353,8 +339,8 @@ static int s_aws_profile_multiple_property_profile_test(struct aws_allocator *al EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); - EXPECT_PROPERTY(profile_collection, "foo", "name2", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name2", "value2"); aws_profile_collection_destroy(profile_collection); @@ -378,7 +364,7 @@ static int s_aws_profile_trimmable_property_profile_test(struct aws_allocator *a EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -402,7 +388,7 @@ static int s_aws_profile_empty_property_profile_test(struct aws_allocator *alloc EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", ""); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", ""); aws_profile_collection_destroy(profile_collection); @@ -451,10 +437,10 @@ static int s_aws_profile_multiple_profile_test(struct aws_allocator *allocator, EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 1); - EXPECT_PROPERTY(profile_collection, "bar", "name2", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", "name2", "value2"); aws_profile_collection_destroy(profile_collection); @@ -481,15 +467,15 @@ static int s_aws_profile_multiple_profile_with_sso_session_test(struct aws_alloc EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 1); - EXPECT_PROPERTY(profile_collection, "bar", "name2", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", "name2", "value2"); EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 2); - EXPECT_SSO_SESSION_PROPERTY(profile_collection, "session", "name3", "value3"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "name3", "value3"); EXPECT_SSO_SESSION_SUB_PROPERTY_COUNT(profile_collection, "session", "s3", 1); EXPECT_SSO_SESSION_SUB_PROPERTY(profile_collection, "session", "s3", "name4", "value4"); aws_profile_collection_destroy(profile_collection); @@ -538,7 +524,8 @@ static int s_aws_profile_sso_session_without_name_test(struct aws_allocator *all EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 1); - EXPECT_SSO_SESSION_PROPERTY(profile_collection, "session", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "name", "value"); + aws_profile_collection_destroy(profile_collection); return 0; @@ -563,7 +550,7 @@ static int s_aws_profile_blank_lines_ignored_test(struct aws_allocator *allocato EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 2); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 0); @@ -591,7 +578,7 @@ static int s_aws_profile_pound_comments_ignored_test(struct aws_allocator *alloc EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -617,7 +604,7 @@ static int s_aws_profile_semicolon_comments_ignored_test(struct aws_allocator *a EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -643,7 +630,7 @@ static int s_aws_profile_mixed_comments_ignored_test(struct aws_allocator *alloc EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -667,7 +654,7 @@ static int s_aws_profile_empty_comments_ignored_test(struct aws_allocator *alloc EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -720,8 +707,9 @@ static int s_aws_profile_value_adjacent_comment_test(struct aws_allocator *alloc EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value; Adjacent semicolons"); - EXPECT_PROPERTY(profile_collection, "foo", "name2", "value# Adjacent pound signs"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value; Adjacent semicolons"); + EXPECT_PROPERTY( + profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name2", "value# Adjacent pound signs"); aws_profile_collection_destroy(profile_collection); @@ -745,7 +733,7 @@ static int s_aws_profile_continued_property_value_test(struct aws_allocator *all EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value\n-continued"); aws_profile_collection_destroy(profile_collection); @@ -771,7 +759,8 @@ static int s_aws_profile_multiline_continued_property_value_test(struct aws_allo EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued\n-and-continued"); + EXPECT_PROPERTY( + profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value\n-continued\n-and-continued"); aws_profile_collection_destroy(profile_collection); @@ -799,7 +788,7 @@ static int s_aws_profile_continued_property_value_trim_test(struct aws_allocator EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value\n-continued"); aws_profile_collection_destroy(profile_collection); @@ -825,7 +814,7 @@ static int s_aws_profile_continued_property_value_pound_comment_test(struct aws_ EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued # Comment"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value\n-continued # Comment"); aws_profile_collection_destroy(profile_collection); @@ -853,7 +842,7 @@ static int s_aws_profile_continued_property_value_semicolon_comment_test(struct EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value\n-continued ; Comment"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value\n-continued ; Comment"); aws_profile_collection_destroy(profile_collection); @@ -882,14 +871,14 @@ static int s_aws_profile_duplicate_profiles_merge_test(struct aws_allocator *all EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); - EXPECT_PROPERTY(profile_collection, "foo", "name2", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name2", "value2"); EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo", 2); - EXPECT_SSO_SESSION_PROPERTY(profile_collection, "foo", "name3", "value3"); - EXPECT_SSO_SESSION_PROPERTY(profile_collection, "foo", "name4", "value4"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo", "name3", "value3"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo", "name4", "value4"); aws_profile_collection_destroy(profile_collection); @@ -915,7 +904,7 @@ static int s_aws_profile_duplicate_properties_last_property_value_test(struct aw EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value2"); aws_profile_collection_destroy(profile_collection); @@ -943,7 +932,7 @@ static int s_aws_profile_duplicate_profiles_last_property_value_test(struct aws_ EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value2"); aws_profile_collection_destroy(profile_collection); @@ -973,7 +962,7 @@ static int s_aws_profile_duplicate_default_profiles_property_resolution1_test( EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", 1); - EXPECT_PROPERTY(profile_collection, "default", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -1003,7 +992,7 @@ static int s_aws_profile_duplicate_default_profiles_property_resolution2_test( EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", 1); - EXPECT_PROPERTY(profile_collection, "default", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -1109,7 +1098,11 @@ static int s_aws_profile_all_valid_property_characters_test(struct aws_allocator EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY( - profile_collection, "foo", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", "value"); + profile_collection, + AWS_PROFILE_SECTION_TYPE_PROFILE, + "foo", + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", + "value"); aws_profile_collection_destroy(profile_collection); @@ -1133,7 +1126,7 @@ static int s_aws_profile_basic_sub_property_test(struct aws_allocator *allocator EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nname = value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname = value"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 1); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); @@ -1160,7 +1153,7 @@ static int s_aws_profile_empty_sub_property_test(struct aws_allocator *allocator EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nname ="); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname ="); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 1); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", ""); @@ -1187,7 +1180,7 @@ static int s_aws_profile_invalid_sub_property_name_test(struct aws_allocator *al EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nin valid = value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nin valid = value"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 0); aws_profile_collection_destroy(profile_collection); @@ -1215,7 +1208,8 @@ static int s_aws_profile_sub_property_blank_line_test(struct aws_allocator *allo EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "s3", "\nname = value\nname2 = value2"); + EXPECT_PROPERTY( + profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname = value\nname2 = value2"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 2); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name2", "value2"); @@ -1243,8 +1237,8 @@ static int s_aws_profile_basic_duplicate_merge_test(struct aws_allocator *alloca EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 2); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value"); - EXPECT_PROPERTY(profile_collection, "foo", "name2", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name2", "value2"); aws_profile_collection_destroy(profile_collection); @@ -1271,8 +1265,8 @@ static int s_aws_profile_mixed_prefix_default_test(struct aws_allocator *allocat EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", 2); - EXPECT_PROPERTY(profile_collection, "default", "name", "value"); - EXPECT_PROPERTY(profile_collection, "default", "name3", "value3"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", "name", "value"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "default", "name3", "value3"); aws_profile_collection_destroy(profile_collection); @@ -1298,7 +1292,7 @@ static int s_aws_profile_override_duplicate_merge_test(struct aws_allocator *all EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); - EXPECT_PROPERTY(profile_collection, "foo", "name", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value2"); aws_profile_collection_destroy(profile_collection); From 767d9a96d8f33e3de554298d9ef9bf99f6565d9f Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 14:55:43 -0800 Subject: [PATCH 04/13] fix tests --- source/aws_profile.c | 30 ++++++++++++++++-------------- tests/aws_profile_tests.c | 7 +++---- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/source/aws_profile.c b/source/aws_profile.c index 7bb192b..1e8ee1b 100644 --- a/source/aws_profile.c +++ b/source/aws_profile.c @@ -863,26 +863,28 @@ static struct aws_byte_cursor s_trim_trailing_whitespace_comment(const struct aw return trimmed; } -static int s_parse_section_declaration_prefix(struct aws_byte_cursor *profile_cursor, - enum aws_profile_section_type *out_section_type) { +static int s_parse_section_declaration_prefix( + struct aws_byte_cursor *profile_cursor, + enum aws_profile_section_type *out_section_type) { /* check profile prefix */ - if(s_parse_by_token(profile_cursor, s_profile_token, NULL) && - s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + if (s_parse_by_token(profile_cursor, s_profile_token, NULL) && + s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { *out_section_type = AWS_PROFILE_SECTION_TYPE_PROFILE; return AWS_OP_SUCCESS; } /* check sso-session prefix */ - if(s_parse_by_token(profile_cursor, s_sso_session_token, NULL) && s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + if (s_parse_by_token(profile_cursor, s_sso_session_token, NULL) && + s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { *out_section_type = AWS_PROFILE_SECTION_TYPE_SSO_SESSION; return AWS_OP_SUCCESS; - } + } /* check services prefix */ - if(s_parse_by_token(profile_cursor, s_services_token, NULL) && - s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + if (s_parse_by_token(profile_cursor, s_services_token, NULL) && + s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { *out_section_type = AWS_PROFILE_SECTION_TYPE_SERVICES; return AWS_OP_SUCCESS; } - + return aws_raise_error(AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE); } @@ -917,8 +919,7 @@ static bool s_parse_profile_declaration( s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 0); - enum aws_profile_section_type section_type; - + enum aws_profile_section_type section_type = AWS_PROFILE_SECTION_TYPE_PROFILE; /* * Check if the profile name starts with a valid prefix. We need to check for @@ -927,7 +928,7 @@ static bool s_parse_profile_declaration( */ struct aws_byte_cursor backtrack_cursor = profile_cursor; bool valid_section_declation_prefix = false; - if(s_parse_section_declaration_prefix(&profile_cursor, §ion_type) != AWS_OP_SUCCESS) { + if (s_parse_section_declaration_prefix(&profile_cursor, §ion_type) != AWS_OP_SUCCESS) { profile_cursor = backtrack_cursor; } else { valid_section_declation_prefix = true; @@ -942,7 +943,7 @@ static bool s_parse_profile_declaration( } s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 0); - } + } struct aws_byte_cursor profile_name; if (!s_parse_by_character_predicate(&profile_cursor, s_is_identifier, &profile_name, 0)) { AWS_LOGF_WARN(AWS_LS_SDKUTILS_PROFILE, "Profile declarations must contain a valid identifier for a name"); @@ -952,7 +953,8 @@ static bool s_parse_profile_declaration( return true; } - if (context->profile_collection->profile_source == AWS_PST_CONFIG && !valid_section_declation_prefix && !s_is_default_profile_name(&profile_name)) { + if (context->profile_collection->profile_source == AWS_PST_CONFIG && !valid_section_declation_prefix && + !s_is_default_profile_name(&profile_name)) { AWS_LOGF_WARN( AWS_LS_SDKUTILS_PROFILE, "Non-default profile declarations in config files must use the \"profile\" keyword"); diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index 4825887..e7704dc 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -472,7 +472,7 @@ static int s_aws_profile_multiple_profile_with_sso_session_test(struct aws_alloc EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", "name2", "value2"); - EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 2); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "name3", "value3"); @@ -500,7 +500,7 @@ static int s_aws_profile_sso_session_in_credentials_test(struct aws_allocator *a ASSERT_NOT_NULL(profile_collection); EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); - EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, 0); aws_profile_collection_destroy(profile_collection); return 0; @@ -520,8 +520,7 @@ static int s_aws_profile_sso_session_without_name_test(struct aws_allocator *all aws_prepare_profile_test(allocator, s_sso_session_without_name, AWS_PST_CONFIG); ASSERT_NOT_NULL(profile_collection); - EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); - EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "name", "value"); From 2eb78d12cf5c2eb22f76d29dc343e221c26eb3ee Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 15:00:26 -0800 Subject: [PATCH 05/13] one more replace --- tests/aws_profile_tests.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index e7704dc..c005fb3 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -45,14 +45,16 @@ strcmp(expected_property_value, aws_string_c_str(aws_profile_property_get_value(property))) == 0); \ } -#define EXPECT_SUB_PROPERTY_COUNT(profile_collection, profile_name, property_name, expected_sub_property_count) \ +#define EXPECT_SUB_PROPERTY_COUNT( \ + profile_collection, section_type, section_name, property_name, expected_sub_property_count) \ { \ - struct aws_string *profile_name_str = aws_string_new_from_c_str(allocator, profile_name); \ - const struct aws_profile *profile = aws_profile_collection_get_profile(profile_collection, profile_name_str); \ + struct aws_string *section_name_str = aws_string_new_from_c_str(allocator, section_name); \ + const struct aws_profile *profile = \ + aws_profile_collection_get_section(profile_collection, section_type, section_name_str); \ struct aws_string *property_name_str = aws_string_new_from_c_str(allocator, property_name); \ const struct aws_profile_property *property = aws_profile_get_property(profile, property_name_str); \ aws_string_destroy(property_name_str); \ - aws_string_destroy(profile_name_str); \ + aws_string_destroy(section_name_str); \ ASSERT_UINT_EQUALS((expected_sub_property_count), aws_profile_property_get_sub_property_count(property)); \ } @@ -72,19 +74,6 @@ ASSERT_TRUE(strcmp(expected_sub_property_value, aws_string_c_str(sub_property_value)) == 0); \ } -#define EXPECT_SSO_SESSION_SUB_PROPERTY_COUNT( \ - profile_collection, sso_session_name, property_name, expected_sub_property_count) \ - { \ - struct aws_string *sso_session_name_str = aws_string_new_from_c_str(allocator, sso_session_name); \ - const struct aws_profile *sso_session = aws_profile_collection_get_section( \ - profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, sso_session_name_str); \ - struct aws_string *property_name_str = aws_string_new_from_c_str(allocator, property_name); \ - const struct aws_profile_property *property = aws_profile_get_property(sso_session, property_name_str); \ - aws_string_destroy(property_name_str); \ - aws_string_destroy(sso_session_name_str); \ - ASSERT_UINT_EQUALS((expected_sub_property_count), aws_profile_property_get_sub_property_count(property)); \ - } - #define EXPECT_SSO_SESSION_SUB_PROPERTY( \ profile_collection, sso_session_name, property_name, sub_property_name, expected_sub_property_value) \ { \ @@ -476,7 +465,7 @@ static int s_aws_profile_multiple_profile_with_sso_session_test(struct aws_alloc EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 2); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "name3", "value3"); - EXPECT_SSO_SESSION_SUB_PROPERTY_COUNT(profile_collection, "session", "s3", 1); + EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "s3", 1); EXPECT_SSO_SESSION_SUB_PROPERTY(profile_collection, "session", "s3", "name4", "value4"); aws_profile_collection_destroy(profile_collection); @@ -1126,7 +1115,7 @@ static int s_aws_profile_basic_sub_property_test(struct aws_allocator *allocator EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname = value"); - EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 1); + EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", 1); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -1153,7 +1142,7 @@ static int s_aws_profile_empty_sub_property_test(struct aws_allocator *allocator EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname ="); - EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 1); + EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", 1); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", ""); aws_profile_collection_destroy(profile_collection); @@ -1180,7 +1169,7 @@ static int s_aws_profile_invalid_sub_property_name_test(struct aws_allocator *al EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nin valid = value"); - EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 0); + EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", 0); aws_profile_collection_destroy(profile_collection); @@ -1209,7 +1198,7 @@ static int s_aws_profile_sub_property_blank_line_test(struct aws_allocator *allo EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY( profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname = value\nname2 = value2"); - EXPECT_SUB_PROPERTY_COUNT(profile_collection, "foo", "s3", 2); + EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", 2); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name2", "value2"); From 97ca1eef0af9335e3b53b95d0d476c97b4348d2f Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 15:02:38 -0800 Subject: [PATCH 06/13] last one --- tests/aws_profile_tests.c | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index c005fb3..8cb0413 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -59,10 +59,11 @@ } #define EXPECT_SUB_PROPERTY( \ - profile_collection, profile_name, property_name, sub_property_name, expected_sub_property_value) \ + profile_collection, section_type, profile_name, property_name, sub_property_name, expected_sub_property_value) \ { \ struct aws_string *profile_name_str = aws_string_new_from_c_str(allocator, profile_name); \ - const struct aws_profile *profile = aws_profile_collection_get_profile(profile_collection, profile_name_str); \ + const struct aws_profile *profile = \ + aws_profile_collection_get_section(profile_collection, section_type, profile_name_str); \ struct aws_string *property_name_str = aws_string_new_from_c_str(allocator, property_name); \ const struct aws_profile_property *property = aws_profile_get_property(profile, property_name_str); \ struct aws_string *sub_property_name_str = aws_string_new_from_c_str(allocator, sub_property_name); \ @@ -74,23 +75,6 @@ ASSERT_TRUE(strcmp(expected_sub_property_value, aws_string_c_str(sub_property_value)) == 0); \ } -#define EXPECT_SSO_SESSION_SUB_PROPERTY( \ - profile_collection, sso_session_name, property_name, sub_property_name, expected_sub_property_value) \ - { \ - struct aws_string *sso_session_name_str = aws_string_new_from_c_str(allocator, sso_session_name); \ - const struct aws_profile *sso_session = aws_profile_collection_get_section( \ - profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, sso_session_name_str); \ - struct aws_string *property_name_str = aws_string_new_from_c_str(allocator, property_name); \ - const struct aws_profile_property *property = aws_profile_get_property(sso_session, property_name_str); \ - struct aws_string *sub_property_name_str = aws_string_new_from_c_str(allocator, sub_property_name); \ - const struct aws_string *sub_property_value = \ - aws_profile_property_get_sub_property(property, sub_property_name_str); \ - aws_string_destroy(sub_property_name_str); \ - aws_string_destroy(property_name_str); \ - aws_string_destroy(sso_session_name_str); \ - ASSERT_TRUE(strcmp(expected_sub_property_value, aws_string_c_str(sub_property_value)) == 0); \ - } - /* * profile collection setup */ @@ -466,7 +450,7 @@ static int s_aws_profile_multiple_profile_with_sso_session_test(struct aws_alloc EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 2); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "name3", "value3"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "s3", 1); - EXPECT_SSO_SESSION_SUB_PROPERTY(profile_collection, "session", "s3", "name4", "value4"); + EXPECT_SUB_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "s3", "name4", "value4"); aws_profile_collection_destroy(profile_collection); return 0; @@ -1116,7 +1100,7 @@ static int s_aws_profile_basic_sub_property_test(struct aws_allocator *allocator EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname = value"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", 1); - EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); + EXPECT_SUB_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "name", "value"); aws_profile_collection_destroy(profile_collection); @@ -1143,7 +1127,7 @@ static int s_aws_profile_empty_sub_property_test(struct aws_allocator *allocator EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname ="); EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", 1); - EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", ""); + EXPECT_SUB_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "name", ""); aws_profile_collection_destroy(profile_collection); @@ -1199,8 +1183,8 @@ static int s_aws_profile_sub_property_blank_line_test(struct aws_allocator *allo EXPECT_PROPERTY( profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "\nname = value\nname2 = value2"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", 2); - EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name", "value"); - EXPECT_SUB_PROPERTY(profile_collection, "foo", "s3", "name2", "value2"); + EXPECT_SUB_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "name", "value"); + EXPECT_SUB_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "s3", "name2", "value2"); aws_profile_collection_destroy(profile_collection); From bdfd71a26b042b2f89f2c2e49b3a59c4465bc326 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 15:36:03 -0800 Subject: [PATCH 07/13] Add tests --- tests/CMakeLists.txt | 5 +-- tests/aws_profile_tests.c | 70 +++++++++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b7aba08..32c6e9e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,9 +29,10 @@ add_test_case(aws_profile_trimmable_property_profile_test) add_test_case(aws_profile_empty_property_profile_test) add_test_case(aws_profile_multiple_empty_profile_test) add_test_case(aws_profile_multiple_profile_test) -add_test_case(aws_profile_multiple_profile_with_sso_session_test) -add_test_case(aws_profile_sso_session_in_credentials_test) +add_test_case(aws_profile_multiple_sections) +add_test_case(aws_profile_sections_in_credentials_test) add_test_case(aws_profile_sso_session_without_name_test) +add_test_case(aws_profile_services_without_name_test) add_test_case(aws_profile_blank_lines_ignored_test) add_test_case(aws_profile_pound_comments_ignored_test) add_test_case(aws_profile_semicolon_comments_ignored_test) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index 8cb0413..52841bb 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -427,10 +427,11 @@ AWS_TEST_CASE(aws_profile_multiple_profile_test, s_aws_profile_multiple_profile_ */ AWS_STATIC_STRING_FROM_LITERAL( s_credentials_sso_session, - "[profile foo]\nname = value\n[profile bar]\nname2 = value2\n[sso-session session]\nname3 = value3\ns3 =\n name4 = " - "value4"); + "[profile foo]\nname = value\n[profile bar]\nname2 = value2\n" + "[sso-session session]\nname3 = value3\ns3 =\n name4 = value4\n" + "[services test-service]\nname4 = value4\ns3 =\n name5 = value5\n"); -static int s_aws_profile_multiple_profile_with_sso_session_test(struct aws_allocator *allocator, void *ctx) { +static int s_aws_profile_multiple_sections(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_profile_collection *profile_collection = @@ -451,41 +452,52 @@ static int s_aws_profile_multiple_profile_with_sso_session_test(struct aws_alloc EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "name3", "value3"); EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "s3", 1); EXPECT_SUB_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", "s3", "name4", "value4"); + + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", 2); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", "name4", "value4"); + EXPECT_SUB_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", "s3", 1); + EXPECT_SUB_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", "s3", "name5", "value5"); + aws_profile_collection_destroy(profile_collection); return 0; } -AWS_TEST_CASE(aws_profile_multiple_profile_with_sso_session_test, s_aws_profile_multiple_profile_with_sso_session_test); +AWS_TEST_CASE(aws_profile_multiple_sections, s_aws_profile_multiple_sections); /* - * SSO-Session in credentials file is ignored + * sections in credentials file are ignored */ AWS_STATIC_STRING_FROM_LITERAL( s_sso_session_in_credentials, - "[foo]\nname = value\n[sso-session session]\nname3 = value3"); + "[profile foo]\nname = value\n" + "[sso-session session]\nname2 = value2\n" + "[services test-service]\nname3 = value3\n" + ); -static int s_aws_profile_sso_session_in_credentials_test(struct aws_allocator *allocator, void *ctx) { +static int s_aws_profile_sections_in_credentials_test(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_profile_collection *profile_collection = aws_prepare_profile_test(allocator, s_sso_session_in_credentials, AWS_PST_CREDENTIALS); ASSERT_NOT_NULL(profile_collection); - EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, 0); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, 0); aws_profile_collection_destroy(profile_collection); return 0; } -AWS_TEST_CASE(aws_profile_sso_session_in_credentials_test, s_aws_profile_sso_session_in_credentials_test); +AWS_TEST_CASE(aws_profile_sections_in_credentials_test, s_aws_profile_sections_in_credentials_test); /* * sso-session without name is ignored */ AWS_STATIC_STRING_FROM_LITERAL(s_sso_session_without_name, "[sso-session session]\nname = value\n[sso-session ]"); -//"[profile foo]\nname = value\n[sso-session session]\nname3 = value3"); static int s_aws_profile_sso_session_without_name_test(struct aws_allocator *allocator, void *ctx) { (void)ctx; @@ -505,6 +517,28 @@ static int s_aws_profile_sso_session_without_name_test(struct aws_allocator *all AWS_TEST_CASE(aws_profile_sso_session_without_name_test, s_aws_profile_sso_session_without_name_test); +/* + * services without name is ignored + */ +AWS_STATIC_STRING_FROM_LITERAL(s_services_without_name, "[services test-service]\nname = value\n[services ]"); +static int s_aws_profile_services_without_name_test(struct aws_allocator *allocator, void *ctx) { + (void)ctx; + + struct aws_profile_collection *profile_collection = + aws_prepare_profile_test(allocator, s_services_without_name, AWS_PST_CONFIG); + + ASSERT_NOT_NULL(profile_collection); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", 1); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", "name", "value"); + + aws_profile_collection_destroy(profile_collection); + + return 0; +} + +AWS_TEST_CASE(aws_profile_services_without_name_test, s_aws_profile_services_without_name_test); /* * Blank lines are ignored */ @@ -826,12 +860,14 @@ AWS_TEST_CASE( s_aws_profile_continued_property_value_semicolon_comment_test); /* - * duplicate profiles and sso-session merge properties + * duplicate profiles, sso-session, services merge properties */ AWS_STATIC_STRING_FROM_LITERAL( s_duplicate_profiles_merge_profile, - "[profile foo]\nname = value\n[profile foo]\nname2 = value2\n[sso-session foo]\nname3 = value-3\n[sso-session " - "foo]\nname3 = value3\nname4 = value4"); + "[profile foo]\nname = value\n[profile foo]\nname2 = value2\n" + "[sso-session foo]\nname3 = value-3\n[sso-session foo]\nname3 = value3\nname4 = value4\n" + "[services test-service]\nname5 = value-5\n[services test-service]\nname5 = value5\nname6 = value6\n" + ); static int s_aws_profile_duplicate_profiles_merge_test(struct aws_allocator *allocator, void *ctx) { (void)ctx; @@ -846,12 +882,18 @@ static int s_aws_profile_duplicate_profiles_merge_test(struct aws_allocator *all EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name2", "value2"); - EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 1); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo", 2); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo", "name3", "value3"); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "foo", "name4", "value4"); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, 1); + EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service"); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", 2); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", "name5", "value5"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, "test-service", "name6", "value6"); + aws_profile_collection_destroy(profile_collection); return 0; From 2cf2a3abfa1273fd863826f8120b3dd5a8ed8466 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 15:36:34 -0800 Subject: [PATCH 08/13] lint --- tests/aws_profile_tests.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index 52841bb..0f409d8 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -10,9 +10,7 @@ #include #define EXPECT_SECTION_COUNT(profile_collection, section_type, section_count) \ - { \ - ASSERT_TRUE(aws_profile_collection_get_section_count(profile_collection, section_type) == (section_count)); \ - } + { ASSERT_TRUE(aws_profile_collection_get_section_count(profile_collection, section_type) == (section_count)); } #define EXPECT_SECTION(profile_collection, section_type, section_name) \ { \ @@ -474,8 +472,7 @@ AWS_STATIC_STRING_FROM_LITERAL( s_sso_session_in_credentials, "[profile foo]\nname = value\n" "[sso-session session]\nname2 = value2\n" - "[services test-service]\nname3 = value3\n" - ); + "[services test-service]\nname3 = value3\n"); static int s_aws_profile_sections_in_credentials_test(struct aws_allocator *allocator, void *ctx) { (void)ctx; @@ -866,8 +863,7 @@ AWS_STATIC_STRING_FROM_LITERAL( s_duplicate_profiles_merge_profile, "[profile foo]\nname = value\n[profile foo]\nname2 = value2\n" "[sso-session foo]\nname3 = value-3\n[sso-session foo]\nname3 = value3\nname4 = value4\n" - "[services test-service]\nname5 = value-5\n[services test-service]\nname5 = value5\nname6 = value6\n" - ); + "[services test-service]\nname5 = value-5\n[services test-service]\nname5 = value5\nname6 = value6\n"); static int s_aws_profile_duplicate_profiles_merge_test(struct aws_allocator *allocator, void *ctx) { (void)ctx; From 10da04f8c470580167ada0c884dda81da99044e4 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 15:39:07 -0800 Subject: [PATCH 09/13] renames --- source/aws_profile.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/aws_profile.c b/source/aws_profile.c index 1e8ee1b..bb39cd1 100644 --- a/source/aws_profile.c +++ b/source/aws_profile.c @@ -863,7 +863,7 @@ static struct aws_byte_cursor s_trim_trailing_whitespace_comment(const struct aw return trimmed; } -static int s_parse_section_declaration_prefix( +static int s_parse_section_type_prefix( struct aws_byte_cursor *profile_cursor, enum aws_profile_section_type *out_section_type) { /* check profile prefix */ @@ -927,11 +927,11 @@ static bool s_parse_profile_declaration( * ("[profilefoo]" for example) should rewind and use the whole name properly. */ struct aws_byte_cursor backtrack_cursor = profile_cursor; - bool valid_section_declation_prefix = false; - if (s_parse_section_declaration_prefix(&profile_cursor, §ion_type) != AWS_OP_SUCCESS) { + bool has_valid_section_type_prefix = false; + if (s_parse_section_type_prefix(&profile_cursor, §ion_type) != AWS_OP_SUCCESS) { profile_cursor = backtrack_cursor; } else { - valid_section_declation_prefix = true; + has_valid_section_type_prefix = true; if (context->profile_collection->profile_source == AWS_PST_CREDENTIALS) { AWS_LOGF_WARN( AWS_LS_SDKUTILS_PROFILE, @@ -953,7 +953,7 @@ static bool s_parse_profile_declaration( return true; } - if (context->profile_collection->profile_source == AWS_PST_CONFIG && !valid_section_declation_prefix && + if (context->profile_collection->profile_source == AWS_PST_CONFIG && !has_valid_section_type_prefix && !s_is_default_profile_name(&profile_name)) { AWS_LOGF_WARN( AWS_LS_SDKUTILS_PROFILE, @@ -1002,7 +1002,7 @@ static bool s_parse_profile_declaration( context->profile_collection, section_type, &profile_name, - valid_section_declation_prefix && section_type == AWS_PROFILE_SECTION_TYPE_PROFILE, + has_valid_section_type_prefix && section_type == AWS_PROFILE_SECTION_TYPE_PROFILE, context, &context->current_profile)) { AWS_LOGF_ERROR(AWS_LS_SDKUTILS_PROFILE, "Failed to add profile to profile collection"); From ac2b4243db71280f54e30a4569e2c9c801429cb7 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 15:46:09 -0800 Subject: [PATCH 10/13] update test --- source/aws_profile.c | 1 - tests/aws_profile_tests.c | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/aws_profile.c b/source/aws_profile.c index bb39cd1..6d1dac7 100644 --- a/source/aws_profile.c +++ b/source/aws_profile.c @@ -918,7 +918,6 @@ static bool s_parse_profile_declaration( context->current_property = NULL; s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 0); - enum aws_profile_section_type section_type = AWS_PROFILE_SECTION_TYPE_PROFILE; /* diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index 0f409d8..08d82ad 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -425,7 +425,7 @@ AWS_TEST_CASE(aws_profile_multiple_profile_test, s_aws_profile_multiple_profile_ */ AWS_STATIC_STRING_FROM_LITERAL( s_credentials_sso_session, - "[profile foo]\nname = value\n[profile bar]\nname2 = value2\n" + "[profile foo]\nname = value\n[profile bar]\nname2 = value2\nservices = test-service\n" "[sso-session session]\nname3 = value3\ns3 =\n name4 = value4\n" "[services test-service]\nname4 = value4\ns3 =\n name5 = value5\n"); @@ -441,8 +441,9 @@ static int s_aws_profile_multiple_sections(struct aws_allocator *allocator, void EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", 1); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "foo", "name", "value"); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar"); - EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 1); + EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", 2); EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", "name2", "value2"); + EXPECT_PROPERTY(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, "bar", "services", "test-service"); EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); From db8625aea8c38861d1005fe7869cc63909ba454b Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Mon, 6 Jan 2025 15:53:03 -0800 Subject: [PATCH 11/13] missing line --- tests/aws_profile_tests.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index 08d82ad..a2cddea 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -503,6 +503,7 @@ static int s_aws_profile_sso_session_without_name_test(struct aws_allocator *all aws_prepare_profile_test(allocator, s_sso_session_without_name, AWS_PST_CONFIG); ASSERT_NOT_NULL(profile_collection); + EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_PROFILE, 0); EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, 1); EXPECT_SECTION(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session"); EXPECT_PROPERTY_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SSO_SESSION, "session", 1); From 04f412978a6fcb5034925cb1056d858bd4082374 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 7 Jan 2025 16:04:01 -0800 Subject: [PATCH 12/13] Fix edge case --- source/aws_profile.c | 32 +++++++++++++++++++------------- tests/CMakeLists.txt | 2 +- tests/aws_profile_tests.c | 13 +++++++++---- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/source/aws_profile.c b/source/aws_profile.c index 6d1dac7..556efb1 100644 --- a/source/aws_profile.c +++ b/source/aws_profile.c @@ -867,24 +867,30 @@ static int s_parse_section_type_prefix( struct aws_byte_cursor *profile_cursor, enum aws_profile_section_type *out_section_type) { /* check profile prefix */ - if (s_parse_by_token(profile_cursor, s_profile_token, NULL) && - s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { - *out_section_type = AWS_PROFILE_SECTION_TYPE_PROFILE; - return AWS_OP_SUCCESS; + if (s_parse_by_token(profile_cursor, s_profile_token, NULL)) { + if (s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + *out_section_type = AWS_PROFILE_SECTION_TYPE_PROFILE; + return AWS_OP_SUCCESS; + } + return aws_raise_error(AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE); } + /* check sso-session prefix */ - if (s_parse_by_token(profile_cursor, s_sso_session_token, NULL) && - s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { - *out_section_type = AWS_PROFILE_SECTION_TYPE_SSO_SESSION; - return AWS_OP_SUCCESS; + if (s_parse_by_token(profile_cursor, s_sso_session_token, NULL)) { + if (s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + *out_section_type = AWS_PROFILE_SECTION_TYPE_SSO_SESSION; + return AWS_OP_SUCCESS; + } + return aws_raise_error(AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE); } /* check services prefix */ - if (s_parse_by_token(profile_cursor, s_services_token, NULL) && - s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { - *out_section_type = AWS_PROFILE_SECTION_TYPE_SERVICES; - return AWS_OP_SUCCESS; + if (s_parse_by_token(profile_cursor, s_services_token, NULL)) { + if (s_parse_by_character_predicate(profile_cursor, s_is_whitespace, NULL, 1)) { + *out_section_type = AWS_PROFILE_SECTION_TYPE_SERVICES; + return AWS_OP_SUCCESS; + } + return aws_raise_error(AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE); } - return aws_raise_error(AWS_ERROR_SDKUTILS_PARSE_RECOVERABLE); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 32c6e9e..ab4e06c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,7 @@ add_test_case(aws_profile_multiple_profile_test) add_test_case(aws_profile_multiple_sections) add_test_case(aws_profile_sections_in_credentials_test) add_test_case(aws_profile_sso_session_without_name_test) -add_test_case(aws_profile_services_without_name_test) +add_test_case(aws_profile_services_invalid_prefix_test) add_test_case(aws_profile_blank_lines_ignored_test) add_test_case(aws_profile_pound_comments_ignored_test) add_test_case(aws_profile_semicolon_comments_ignored_test) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index a2cddea..fd46b55 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -519,12 +519,17 @@ AWS_TEST_CASE(aws_profile_sso_session_without_name_test, s_aws_profile_sso_sessi /* * services without name is ignored */ -AWS_STATIC_STRING_FROM_LITERAL(s_services_without_name, "[services test-service]\nname = value\n[services ]"); -static int s_aws_profile_services_without_name_test(struct aws_allocator *allocator, void *ctx) { +AWS_STATIC_STRING_FROM_LITERAL(s_services_with_invali_prefix, + "[services test-service]\nname = value\n" + "[services ]\n" + "[profilesso-sessionservices test]\nname = value\n" + "[services\rtest-service]\nname = value\n" + ); +static int s_aws_profile_services_invalid_prefix_test(struct aws_allocator *allocator, void *ctx) { (void)ctx; struct aws_profile_collection *profile_collection = - aws_prepare_profile_test(allocator, s_services_without_name, AWS_PST_CONFIG); + aws_prepare_profile_test(allocator, s_services_with_invali_prefix, AWS_PST_CONFIG); ASSERT_NOT_NULL(profile_collection); EXPECT_SECTION_COUNT(profile_collection, AWS_PROFILE_SECTION_TYPE_SERVICES, 1); @@ -537,7 +542,7 @@ static int s_aws_profile_services_without_name_test(struct aws_allocator *alloca return 0; } -AWS_TEST_CASE(aws_profile_services_without_name_test, s_aws_profile_services_without_name_test); +AWS_TEST_CASE(aws_profile_services_invalid_prefix_test, s_aws_profile_services_invalid_prefix_test); /* * Blank lines are ignored */ From 718c19bee22de30ef9ad15830ca662f8cbefc00f Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Tue, 7 Jan 2025 16:12:17 -0800 Subject: [PATCH 13/13] lint, how should I really setup up my precommit action --- tests/aws_profile_tests.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/aws_profile_tests.c b/tests/aws_profile_tests.c index fd46b55..a8026b8 100644 --- a/tests/aws_profile_tests.c +++ b/tests/aws_profile_tests.c @@ -519,12 +519,12 @@ AWS_TEST_CASE(aws_profile_sso_session_without_name_test, s_aws_profile_sso_sessi /* * services without name is ignored */ -AWS_STATIC_STRING_FROM_LITERAL(s_services_with_invali_prefix, - "[services test-service]\nname = value\n" - "[services ]\n" - "[profilesso-sessionservices test]\nname = value\n" - "[services\rtest-service]\nname = value\n" - ); +AWS_STATIC_STRING_FROM_LITERAL( + s_services_with_invali_prefix, + "[services test-service]\nname = value\n" + "[services ]\n" + "[profilesso-sessionservices test]\nname = value\n" + "[services\rtest-service]\nname = value\n"); static int s_aws_profile_services_invalid_prefix_test(struct aws_allocator *allocator, void *ctx) { (void)ctx;