Skip to content

Commit

Permalink
Add a bad host test
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed May 8, 2024
1 parent c1ad3e6 commit c8ab029
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ add_test_case(credentials_provider_ecs_new_destroy)
add_test_case(credentials_provider_ecs_connect_failure)
add_test_case(credentials_provider_ecs_request_failure)
add_test_case(credentials_provider_ecs_bad_document_failure)
add_test_case(credentials_provider_ecs_bad_host_failure)
add_test_case(credentials_provider_ecs_basic_success)
add_test_case(credentials_provider_ecs_basic_success_token_file)
add_test_case(credentials_provider_ecs_basic_success_uri_env)
Expand Down
43 changes: 43 additions & 0 deletions tests/credentials_provider_ecs_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,49 @@ static int s_credentials_provider_ecs_bad_document_failure(struct aws_allocator

AWS_TEST_CASE(credentials_provider_ecs_bad_document_failure, s_credentials_provider_ecs_bad_document_failure);

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

s_aws_ecs_tester_init(allocator);

struct aws_credentials_provider_ecs_options options = {
.bootstrap = s_tester.bootstrap,
.function_table = &s_mock_function_table,
.shutdown_options =
{
.shutdown_callback = s_on_shutdown_complete,
.shutdown_user_data = NULL,
},
.host = aws_byte_cursor_from_c_str("www.google.com"),
.path_and_query = aws_byte_cursor_from_c_str("/path/to/resource/?a=b&c=d"),
.auth_token = aws_byte_cursor_from_c_str("test-token-1234-abcd"),
};

struct aws_credentials_provider *provider = aws_credentials_provider_new_ecs(allocator, &options);

aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);

s_aws_wait_for_credentials_result();

aws_mutex_lock(&s_tester.lock);
ASSERT_NULL(s_tester.credentials);
ASSERT_INT_EQUALS(AWS_AUTH_CREDENTIALS_PROVIDER_ECS_INVALID_HOST, s_tester.error_code);
aws_mutex_unlock(&s_tester.lock);

aws_credentials_provider_release(provider);

s_aws_wait_for_provider_shutdown_callback();

/* Because we mock the http connection manager, we never get a callback back from it */
aws_mem_release(provider->allocator, provider);

s_aws_ecs_tester_cleanup();

return 0;
}

AWS_TEST_CASE(credentials_provider_ecs_bad_host_failure, s_credentials_provider_ecs_bad_host_failure);

AWS_STATIC_STRING_FROM_LITERAL(
s_good_response,
"{\"AccessKeyId\":\"SuccessfulAccessKey\", \n \"SecretAccessKey\":\"SuccessfulSecret\", \n "
Expand Down

0 comments on commit c8ab029

Please sign in to comment.