| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#include <aws/testing/aws_test_harness.h> |
| 7 |
|
| 8 |
#include <aws/common/string.h> |
| 9 |
#include <aws/sdkutils/aws_profile.h> |
| 10 |
|
| 11 |
static int s_do_aws_profile_fatal_parse_test( |
| 12 |
struct aws_allocator *allocator, |
| 13 |
const struct aws_string *profile_contents) { |
| 14 |
struct aws_byte_cursor contents = aws_byte_cursor_from_string(profile_contents); |
| 15 |
struct aws_byte_buf buffer; |
| 16 |
aws_byte_buf_init_copy_from_cursor(&buffer, allocator, contents); |
| 17 |
|
| 18 |
struct aws_profile_collection *profile_collection = |
| 19 |
aws_profile_collection_new_from_buffer(allocator, &buffer, AWS_PST_NONE); |
| 20 |
|
| 21 |
aws_byte_buf_clean_up(&buffer); |
| 22 |
|
| 23 |
ASSERT_TRUE(profile_collection == NULL); |
| 24 |
|
| 25 |
return 0; |
| 26 |
} |
| 27 |
|
| 28 |
#define AWS_PROFILE_PARSE_FAILURE_TEST(test_name, content_string) \ |
| 29 |
static int s_##test_name(struct aws_allocator *allocator, void *ctx) { \ |
| 30 |
(void)ctx; \ |
| 31 |
return s_do_aws_profile_fatal_parse_test(allocator, content_string); \ |
| 32 |
} \ |
| 33 |
AWS_TEST_CASE(test_name, s_##test_name); |
| 34 |
|
| 35 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 36 |
s_early_property_profile_file, |
| 37 |
"bad=value\n" |
| 38 |
"[default]\r\n" |
| 39 |
"good=value\r\n"); |
| 40 |
|
| 41 |
AWS_PROFILE_PARSE_FAILURE_TEST(aws_profile_early_property_parse_failure_test, s_early_property_profile_file) |
| 42 |
|
| 43 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 44 |
s_missing_bracket_profile_file, |
| 45 |
"[default \r\n" |
| 46 |
"good=value\r\n"); |
| 47 |
|
| 48 |
AWS_PROFILE_PARSE_FAILURE_TEST(aws_profile_missing_bracket_parse_failure_test, s_missing_bracket_profile_file) |
| 49 |
|
| 50 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 51 |
s_missing_assignment_profile_file, |
| 52 |
"[default] \r\n" |
| 53 |
"bad\r\n"); |
| 54 |
|
| 55 |
AWS_PROFILE_PARSE_FAILURE_TEST(aws_profile_missing_assignment_parse_failure_test, s_missing_assignment_profile_file) |
| 56 |
|
| 57 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 58 |
s_missing_property_key_profile_file, |
| 59 |
"[default] ; hello\r\n" |
| 60 |
"=bad\r\n"); |
| 61 |
|
| 62 |
AWS_PROFILE_PARSE_FAILURE_TEST(aws_profile_missing_property_key_parse_failure_test, s_missing_property_key_profile_file) |
| 63 |
|
| 64 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 65 |
s_early_continuation_profile_file, |
| 66 |
"[default]\r\n" |
| 67 |
" continuation\n"); |
| 68 |
|
| 69 |
AWS_PROFILE_PARSE_FAILURE_TEST(aws_profile_early_continuation_parse_failure_test, s_early_continuation_profile_file) |
| 70 |
|
| 71 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 72 |
s_illegal_continuation1_profile_file, |
| 73 |
"[default]\r\n" |
| 74 |
"s3 =\n" |
| 75 |
" badcontinuation\n"); |
| 76 |
|
| 77 |
AWS_PROFILE_PARSE_FAILURE_TEST( |
| 78 |
aws_profile_illegal_continuation1_parse_failure_test, |
| 79 |
s_illegal_continuation1_profile_file) |
| 80 |
|
| 81 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 82 |
s_illegal_continuation2_profile_file, |
| 83 |
"[default]\r\n" |
| 84 |
"s3 =\n" |
| 85 |
" ^^badcontinuation\n"); |
| 86 |
|
| 87 |
AWS_PROFILE_PARSE_FAILURE_TEST( |
| 88 |
aws_profile_illegal_continuation2_parse_failure_test, |
| 89 |
s_illegal_continuation2_profile_file) |
| 90 |
|
| 91 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 92 |
s_illegal_continuation3_profile_file, |
| 93 |
"[default]\r\n" |
| 94 |
"s3 =\n" |
| 95 |
" =value\n"); |
| 96 |
|
| 97 |
AWS_PROFILE_PARSE_FAILURE_TEST( |
| 98 |
aws_profile_illegal_continuation3_parse_failure_test, |
| 99 |
s_illegal_continuation3_profile_file) |
| 100 |
|
| 101 |
AWS_STATIC_STRING_FROM_LITERAL( |
| 102 |
s_continuation_reset_on_new_profile_file, |
| 103 |
"[profile foo]\nname = value\n[profile foo]\n -continued"); |
| 104 |
|
| 105 |
AWS_PROFILE_PARSE_FAILURE_TEST( |
| 106 |
aws_profile_continuation_reset_on_new_profile_parse_failure_test, |
| 107 |
s_continuation_reset_on_new_profile_file) |