Debian Codegraph @

crt/aws-c-auth/tests/credentials_provider_x509_tests.c

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <aws/testing/aws_test_harness.h>
7
8 #include <aws/auth/credentials.h>
9 #include <aws/auth/private/credentials_utils.h>
10 #include <aws/common/clock.h>
11 #include <aws/common/condition_variable.h>
12 #include <aws/common/date_time.h>
13 #include <aws/common/environment.h>
14 #include <aws/common/string.h>
15 #include <aws/common/thread.h>
16 #include <aws/http/request_response.h>
17 #include <aws/io/channel_bootstrap.h>
18 #include <aws/io/event_loop.h>
19 #include <aws/io/logging.h>
20 #include <aws/io/socket.h>
21 #include <aws/io/tls_channel_handler.h>
22
23 struct aws_mock_x509_tester {
24 struct aws_byte_buf request_uri;
25
26 struct aws_array_list response_data_callbacks;
27 bool is_connection_acquire_successful;
28 bool is_request_successful;
29
30 struct aws_mutex lock;
31 struct aws_condition_variable signal;
32
33 struct aws_credentials *credentials;
34 bool has_received_credentials_callback;
35 bool has_received_shutdown_callback;
36 int error_code;
37
38 struct aws_tls_ctx *ctx;
39 struct aws_tls_connection_options tls_connection_options;
40
41 struct proxy_env_var_settings *proxy_config;
42 };
43
44 static struct aws_mock_x509_tester s_tester;
45
46 static void s_on_shutdown_complete(void *user_data) {
47 (void)user_data;
48
49 aws_mutex_lock(&s_tester.lock);
50 s_tester.has_received_shutdown_callback = true;
51 aws_mutex_unlock(&s_tester.lock);
52
53 aws_condition_variable_notify_one(&s_tester.signal);
54 }
55
56 static bool s_has_tester_received_shutdown_callback(void *user_data) {
57 (void)user_data;
58
59 return s_tester.has_received_shutdown_callback;
60 }
61
62 static void s_aws_wait_for_provider_shutdown_callback(void) {
63 aws_mutex_lock(&s_tester.lock);
64 aws_condition_variable_wait_pred(&s_tester.signal, &s_tester.lock, s_has_tester_received_shutdown_callback, NULL);
65 aws_mutex_unlock(&s_tester.lock);
66 }
67
68 static struct aws_http_connection_manager *s_aws_http_connection_manager_new_mock(
69 struct aws_allocator *allocator,
70 const struct aws_http_connection_manager_options *options) {
71
72 (void)allocator;
73 (void)options;
74
75 if (s_tester.proxy_config != NULL) {
76 AWS_FATAL_ASSERT(options->proxy_ev_settings->env_var_type == s_tester.proxy_config->env_var_type);
77 AWS_FATAL_ASSERT(options->proxy_ev_settings->connection_type == s_tester.proxy_config->connection_type);
78 AWS_FATAL_ASSERT(options->proxy_ev_settings->tls_options == s_tester.proxy_config->tls_options);
79 }
80
81 return (struct aws_http_connection_manager *)1;
82 }
83
84 static void s_aws_http_connection_manager_release_mock(struct aws_http_connection_manager *manager) {
85 (void)manager;
86
87 s_on_shutdown_complete(NULL);
88 }
89
90 static void s_aws_http_connection_manager_acquire_connection_mock(
91 struct aws_http_connection_manager *manager,
92 aws_http_connection_manager_on_connection_setup_fn *callback,
93 void *user_data) {
94
95 (void)manager;
96 (void)callback;
97 (void)user_data;
98
99 if (s_tester.is_connection_acquire_successful) {
100 callback((struct aws_http_connection *)1, AWS_OP_SUCCESS, user_data);
101 } else {
102 aws_raise_error(AWS_ERROR_HTTP_UNKNOWN);
103 callback(NULL, AWS_OP_ERR, user_data);
104 }
105 }
106
107 static int s_aws_http_connection_manager_release_connection_mock(
108 struct aws_http_connection_manager *manager,
109 struct aws_http_connection *connection) {
110
111 (void)manager;
112 (void)connection;
113
114 return AWS_OP_SUCCESS;
115 }
116
117 static void s_invoke_mock_request_callbacks(
118 const struct aws_http_make_request_options *options,
119 struct aws_array_list *data_callbacks,
120 bool is_request_successful) {
121
122 size_t data_callback_count = aws_array_list_length(data_callbacks);
123
124 struct aws_http_header headers[1];
125 AWS_ZERO_ARRAY(headers);
126
127 headers[0].name = aws_byte_cursor_from_c_str("some-header");
128 headers[0].value = aws_byte_cursor_from_c_str("value");
129
130 options->on_response_headers(
131 (struct aws_http_stream *)1, AWS_HTTP_HEADER_BLOCK_MAIN, headers, 1, options->user_data);
132
133 if (options->on_response_header_block_done) {
134 options->on_response_header_block_done(
135 (struct aws_http_stream *)1, data_callback_count > 0, options->user_data);
136 }
137
138 for (size_t i = 0; i < data_callback_count; ++i) {
139 struct aws_byte_cursor data_callback_cursor;
140 if (aws_array_list_get_at(data_callbacks, &data_callback_cursor, i)) {
141 continue;
142 }
143
144 options->on_response_body((struct aws_http_stream *)1, &data_callback_cursor, options->user_data);
145 }
146
147 options->on_complete(
148 (struct aws_http_stream *)1,
149 is_request_successful ? AWS_ERROR_SUCCESS : AWS_ERROR_HTTP_UNKNOWN,
150 options->user_data);
151 }
152
153 static struct aws_http_stream *s_aws_http_connection_make_request_mock(
154 struct aws_http_connection *client_connection,
155 const struct aws_http_make_request_options *options) {
156
157 (void)client_connection;
158 (void)options;
159
160 struct aws_byte_cursor path;
161 AWS_ZERO_STRUCT(path);
162 aws_http_message_get_request_path(options->request, &path);
163
164 aws_byte_buf_append_dynamic(&s_tester.request_uri, &path);
165 s_invoke_mock_request_callbacks(options, &s_tester.response_data_callbacks, s_tester.is_request_successful);
166
167 return (struct aws_http_stream *)1;
168 }
169
170 static int s_aws_http_stream_activate_mock(struct aws_http_stream *stream) {
171 (void)stream;
172 return AWS_OP_SUCCESS;
173 }
174
175 static int s_aws_http_stream_get_incoming_response_status_mock(
176 const struct aws_http_stream *stream,
177 int *out_status_code) {
178 (void)stream;
179
180 *out_status_code = 200;
181
182 return AWS_OP_SUCCESS;
183 }
184
185 static void s_aws_http_stream_release_mock(struct aws_http_stream *stream) {
186 (void)stream;
187 }
188
189 static void s_aws_http_connection_close_mock(struct aws_http_connection *connection) {
190 (void)connection;
191 }
192
193 static struct aws_auth_http_system_vtable s_mock_function_table = {
194 .aws_http_connection_manager_new = s_aws_http_connection_manager_new_mock,
195 .aws_http_connection_manager_release = s_aws_http_connection_manager_release_mock,
196 .aws_http_connection_manager_acquire_connection = s_aws_http_connection_manager_acquire_connection_mock,
197 .aws_http_connection_manager_release_connection = s_aws_http_connection_manager_release_connection_mock,
198 .aws_http_connection_make_request = s_aws_http_connection_make_request_mock,
199 .aws_http_stream_activate = s_aws_http_stream_activate_mock,
200 .aws_http_stream_get_incoming_response_status = s_aws_http_stream_get_incoming_response_status_mock,
201 .aws_http_stream_release = s_aws_http_stream_release_mock,
202 .aws_http_connection_close = s_aws_http_connection_close_mock};
203
204 static int s_aws_x509_tester_init(struct aws_allocator *allocator) {
205 aws_auth_library_init(allocator);
206
207 if (aws_array_list_init_dynamic(&s_tester.response_data_callbacks, allocator, 10, sizeof(struct aws_byte_cursor))) {
208 return AWS_OP_ERR;
209 }
210
211 if (aws_byte_buf_init(&s_tester.request_uri, allocator, 100)) {
212 return AWS_OP_ERR;
213 }
214
215 if (aws_mutex_init(&s_tester.lock)) {
216 return AWS_OP_ERR;
217 }
218
219 if (aws_condition_variable_init(&s_tester.signal)) {
220 return AWS_OP_ERR;
221 }
222
223 AWS_ZERO_STRUCT(s_tester.tls_connection_options);
224 struct aws_tls_ctx_options tls_options;
225 aws_tls_ctx_options_init_default_client(&tls_options, allocator);
226 s_tester.ctx = aws_tls_client_ctx_new(allocator, &tls_options);
227 aws_tls_ctx_options_clean_up(&tls_options);
228 aws_tls_connection_options_init_from_ctx(&s_tester.tls_connection_options, s_tester.ctx);
229
230 /* default to everything successful */
231 s_tester.is_connection_acquire_successful = true;
232 s_tester.is_request_successful = true;
233
234 return AWS_OP_SUCCESS;
235 }
236
237 static void s_aws_x509_tester_cleanup(void) {
238 aws_array_list_clean_up(&s_tester.response_data_callbacks);
239 aws_byte_buf_clean_up(&s_tester.request_uri);
240 aws_condition_variable_clean_up(&s_tester.signal);
241 aws_mutex_clean_up(&s_tester.lock);
242 aws_credentials_release(s_tester.credentials);
243 aws_tls_ctx_release(s_tester.ctx);
244 s_tester.ctx = NULL;
245
246 aws_tls_connection_options_clean_up(&s_tester.tls_connection_options);
247 aws_auth_library_clean_up();
248 }
249
250 static bool s_has_tester_received_credentials_callback(void *user_data) {
251 (void)user_data;
252
253 return s_tester.has_received_credentials_callback;
254 }
255
256 static void s_aws_wait_for_credentials_result(void) {
257 aws_mutex_lock(&s_tester.lock);
258 aws_condition_variable_wait_pred(
259 &s_tester.signal, &s_tester.lock, s_has_tester_received_credentials_callback, NULL);
260 aws_mutex_unlock(&s_tester.lock);
261 }
262
263 static void s_get_credentials_callback(struct aws_credentials *credentials, int error_code, void *user_data) {
264 (void)user_data;
265
266 aws_mutex_lock(&s_tester.lock);
267 s_tester.has_received_credentials_callback = true;
268 s_tester.error_code = error_code;
269 s_tester.credentials = credentials;
270 aws_credentials_acquire(credentials);
271 aws_condition_variable_notify_one(&s_tester.signal);
272 aws_mutex_unlock(&s_tester.lock);
273 }
274
275 static int s_credentials_provider_x509_new_destroy(struct aws_allocator *allocator, void *ctx) {
276 (void)ctx;
277
278 s_aws_x509_tester_init(allocator);
279
280 struct aws_credentials_provider_x509_options options = {
281 .bootstrap = NULL,
282 .function_table = &s_mock_function_table,
283 .shutdown_options =
284 {
285 .shutdown_callback = s_on_shutdown_complete,
286 .shutdown_user_data = NULL,
287 },
288 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
289 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
290 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
291 .tls_connection_options = &s_tester.tls_connection_options,
292 };
293
294 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
295 aws_credentials_provider_release(provider);
296
297 s_aws_wait_for_provider_shutdown_callback();
298
299 /* Because we mock the http connection manager, we never get a callback back from it */
300 aws_mem_release(provider->allocator, provider);
301
302 s_aws_x509_tester_cleanup();
303
304 return 0;
305 }
306
307 AWS_TEST_CASE(credentials_provider_x509_new_destroy, s_credentials_provider_x509_new_destroy);
308
309 static int s_credentials_provider_x509_connect_failure(struct aws_allocator *allocator, void *ctx) {
310 (void)ctx;
311
312 s_aws_x509_tester_init(allocator);
313 s_tester.is_connection_acquire_successful = false;
314
315 struct aws_credentials_provider_x509_options options = {
316 .bootstrap = NULL,
317 .function_table = &s_mock_function_table,
318 .shutdown_options =
319 {
320 .shutdown_callback = s_on_shutdown_complete,
321 .shutdown_user_data = NULL,
322 },
323 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
324 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
325 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
326 .tls_connection_options = &s_tester.tls_connection_options,
327 };
328
329 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
330
331 aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);
332
333 s_aws_wait_for_credentials_result();
334
335 ASSERT_TRUE(s_tester.has_received_credentials_callback == true);
336 ASSERT_TRUE(s_tester.credentials == NULL);
337
338 aws_credentials_provider_release(provider);
339
340 s_aws_wait_for_provider_shutdown_callback();
341
342 /* Because we mock the http connection manager, we never get a callback back from it */
343 aws_mem_release(provider->allocator, provider);
344
345 s_aws_x509_tester_cleanup();
346
347 return 0;
348 }
349
350 AWS_TEST_CASE(credentials_provider_x509_connect_failure, s_credentials_provider_x509_connect_failure);
351
352 AWS_STATIC_STRING_FROM_LITERAL(s_expected_x509_role_alias_path, "/role-aliases/my_test_role_alias/credentials");
353
354 static int s_credentials_provider_x509_request_failure(struct aws_allocator *allocator, void *ctx) {
355 (void)ctx;
356
357 s_aws_x509_tester_init(allocator);
358 s_tester.is_request_successful = false;
359
360 struct aws_credentials_provider_x509_options options = {
361 .bootstrap = NULL,
362 .function_table = &s_mock_function_table,
363 .shutdown_options =
364 {
365 .shutdown_callback = s_on_shutdown_complete,
366 .shutdown_user_data = NULL,
367 },
368 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
369 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
370 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
371 .tls_connection_options = &s_tester.tls_connection_options,
372 };
373 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
374
375 aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);
376
377 s_aws_wait_for_credentials_result();
378
379 ASSERT_BIN_ARRAYS_EQUALS(
380 s_tester.request_uri.buffer,
381 s_tester.request_uri.len,
382 s_expected_x509_role_alias_path->bytes,
383 s_expected_x509_role_alias_path->len);
384 ASSERT_TRUE(s_tester.has_received_credentials_callback == true);
385 ASSERT_TRUE(s_tester.credentials == NULL);
386
387 aws_credentials_provider_release(provider);
388
389 s_aws_wait_for_provider_shutdown_callback();
390
391 /* Because we mock the http connection manager, we never get a callback back from it */
392 aws_mem_release(provider->allocator, provider);
393
394 s_aws_x509_tester_cleanup();
395
396 return 0;
397 }
398
399 AWS_TEST_CASE(credentials_provider_x509_request_failure, s_credentials_provider_x509_request_failure);
400
401 AWS_STATIC_STRING_FROM_LITERAL(s_bad_document_response, "{\"NotTheExpectedDocumentFormat\":\"Error\"}");
402
403 static int s_credentials_provider_x509_bad_document_failure(struct aws_allocator *allocator, void *ctx) {
404 (void)ctx;
405
406 s_aws_x509_tester_init(allocator);
407
408 struct aws_byte_cursor bad_document_cursor = aws_byte_cursor_from_string(s_bad_document_response);
409 aws_array_list_push_back(&s_tester.response_data_callbacks, &bad_document_cursor);
410
411 struct aws_credentials_provider_x509_options options = {
412 .bootstrap = NULL,
413 .function_table = &s_mock_function_table,
414 .shutdown_options =
415 {
416 .shutdown_callback = s_on_shutdown_complete,
417 .shutdown_user_data = NULL,
418 },
419 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
420 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
421 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
422 .tls_connection_options = &s_tester.tls_connection_options,
423 };
424
425 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
426
427 aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);
428
429 s_aws_wait_for_credentials_result();
430
431 ASSERT_BIN_ARRAYS_EQUALS(
432 s_tester.request_uri.buffer,
433 s_tester.request_uri.len,
434 s_expected_x509_role_alias_path->bytes,
435 s_expected_x509_role_alias_path->len);
436
437 ASSERT_TRUE(s_tester.has_received_credentials_callback == true);
438 ASSERT_TRUE(s_tester.credentials == NULL);
439
440 aws_credentials_provider_release(provider);
441
442 s_aws_wait_for_provider_shutdown_callback();
443
444 /* Because we mock the http connection manager, we never get a callback back from it */
445 aws_mem_release(provider->allocator, provider);
446
447 s_aws_x509_tester_cleanup();
448
449 return 0;
450 }
451
452 AWS_TEST_CASE(credentials_provider_x509_bad_document_failure, s_credentials_provider_x509_bad_document_failure);
453
454 AWS_STATIC_STRING_FROM_LITERAL(
455 s_good_response,
456 "{\"Credentials\": {\"AccessKeyId\":\"SuccessfulAccessKey\", \n \"SecretAccessKey\":\"SuccessfulSecret\", \n "
457 "\"SessionToken\":\"TokenSuccess\", \n \"Expiration\":\"2020-02-25T06:03:31Z\"}}");
458 AWS_STATIC_STRING_FROM_LITERAL(s_good_access_key_id, "SuccessfulAccessKey");
459 AWS_STATIC_STRING_FROM_LITERAL(s_good_secret_access_key, "SuccessfulSecret");
460 AWS_STATIC_STRING_FROM_LITERAL(s_good_session_token, "TokenSuccess");
461 AWS_STATIC_STRING_FROM_LITERAL(s_good_response_expiration, "2020-02-25T06:03:31Z");
462
463 static int s_credentials_provider_x509_basic_success(struct aws_allocator *allocator, void *ctx) {
464 (void)ctx;
465
466 s_aws_x509_tester_init(allocator);
467
468 struct aws_byte_cursor good_response_cursor = aws_byte_cursor_from_string(s_good_response);
469 aws_array_list_push_back(&s_tester.response_data_callbacks, &good_response_cursor);
470
471 struct aws_credentials_provider_x509_options options = {
472 .bootstrap = NULL,
473 .function_table = &s_mock_function_table,
474 .shutdown_options =
475 {
476 .shutdown_callback = s_on_shutdown_complete,
477 .shutdown_user_data = NULL,
478 },
479 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
480 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
481 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
482 .tls_connection_options = &s_tester.tls_connection_options,
483 };
484
485 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
486
487 aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);
488
489 s_aws_wait_for_credentials_result();
490
491 ASSERT_BIN_ARRAYS_EQUALS(
492 s_tester.request_uri.buffer,
493 s_tester.request_uri.len,
494 s_expected_x509_role_alias_path->bytes,
495 s_expected_x509_role_alias_path->len);
496
497 ASSERT_TRUE(s_tester.has_received_credentials_callback == true);
498 ASSERT_TRUE(s_tester.credentials != NULL);
499 ASSERT_CURSOR_VALUE_STRING_EQUALS(aws_credentials_get_access_key_id(s_tester.credentials), s_good_access_key_id);
500 ASSERT_CURSOR_VALUE_STRING_EQUALS(
501 aws_credentials_get_secret_access_key(s_tester.credentials), s_good_secret_access_key);
502 ASSERT_CURSOR_VALUE_STRING_EQUALS(aws_credentials_get_session_token(s_tester.credentials), s_good_session_token);
503
504 struct aws_date_time expiration;
505 struct aws_byte_cursor date_cursor = aws_byte_cursor_from_string(s_good_response_expiration);
506 aws_date_time_init_from_str_cursor(&expiration, &date_cursor, AWS_DATE_FORMAT_ISO_8601);
507 ASSERT_TRUE(
508 aws_credentials_get_expiration_timepoint_seconds(s_tester.credentials) == (uint64_t)expiration.timestamp);
509
510 aws_credentials_provider_release(provider);
511
512 s_aws_wait_for_provider_shutdown_callback();
513
514 /* Because we mock the http connection manager, we never get a callback back from it */
515 aws_mem_release(provider->allocator, provider);
516
517 s_aws_x509_tester_cleanup();
518
519 return 0;
520 }
521
522 AWS_TEST_CASE(credentials_provider_x509_basic_success, s_credentials_provider_x509_basic_success);
523
524 AWS_STATIC_STRING_FROM_LITERAL(
525 s_good_response_first_part,
526 "{\"Credentials\": {\"AccessKeyId\":\"SuccessfulAccessKey\", \n \"Secret");
527 AWS_STATIC_STRING_FROM_LITERAL(
528 s_good_response_second_part,
529 "AccessKey\":\"SuccessfulSecret\", \n \"SessionToken\":\"Token");
530 AWS_STATIC_STRING_FROM_LITERAL(s_good_response_third_part, "Success\", \n \"Expiration\":\"2020-02-25T06:03:31Z\"}}");
531
532 static int s_credentials_provider_x509_success_multi_part_doc(struct aws_allocator *allocator, void *ctx) {
533 (void)ctx;
534
535 s_aws_x509_tester_init(allocator);
536
537 struct aws_byte_cursor good_response_cursor1 = aws_byte_cursor_from_string(s_good_response_first_part);
538 struct aws_byte_cursor good_response_cursor2 = aws_byte_cursor_from_string(s_good_response_second_part);
539 struct aws_byte_cursor good_response_cursor3 = aws_byte_cursor_from_string(s_good_response_third_part);
540 aws_array_list_push_back(&s_tester.response_data_callbacks, &good_response_cursor1);
541 aws_array_list_push_back(&s_tester.response_data_callbacks, &good_response_cursor2);
542 aws_array_list_push_back(&s_tester.response_data_callbacks, &good_response_cursor3);
543
544 struct aws_credentials_provider_x509_options options = {
545 .bootstrap = NULL,
546 .function_table = &s_mock_function_table,
547 .shutdown_options =
548 {
549 .shutdown_callback = s_on_shutdown_complete,
550 .shutdown_user_data = NULL,
551 },
552 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
553 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
554 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
555 .tls_connection_options = &s_tester.tls_connection_options,
556 };
557
558 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
559
560 aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);
561
562 s_aws_wait_for_credentials_result();
563
564 ASSERT_BIN_ARRAYS_EQUALS(
565 s_tester.request_uri.buffer,
566 s_tester.request_uri.len,
567 s_expected_x509_role_alias_path->bytes,
568 s_expected_x509_role_alias_path->len);
569
570 ASSERT_TRUE(s_tester.has_received_credentials_callback == true);
571 ASSERT_TRUE(s_tester.credentials != NULL);
572 ASSERT_CURSOR_VALUE_STRING_EQUALS(aws_credentials_get_access_key_id(s_tester.credentials), s_good_access_key_id);
573 ASSERT_CURSOR_VALUE_STRING_EQUALS(
574 aws_credentials_get_secret_access_key(s_tester.credentials), s_good_secret_access_key);
575 ASSERT_CURSOR_VALUE_STRING_EQUALS(aws_credentials_get_session_token(s_tester.credentials), s_good_session_token);
576
577 struct aws_date_time expiration;
578 struct aws_byte_cursor date_cursor = aws_byte_cursor_from_string(s_good_response_expiration);
579 aws_date_time_init_from_str_cursor(&expiration, &date_cursor, AWS_DATE_FORMAT_ISO_8601);
580 ASSERT_TRUE(
581 aws_credentials_get_expiration_timepoint_seconds(s_tester.credentials) == (uint64_t)expiration.timestamp);
582
583 aws_credentials_provider_release(provider);
584
585 s_aws_wait_for_provider_shutdown_callback();
586
587 /* Because we mock the http connection manager, we never get a callback back from it */
588 aws_mem_release(provider->allocator, provider);
589
590 s_aws_x509_tester_cleanup();
591
592 return 0;
593 }
594
595 AWS_TEST_CASE(credentials_provider_x509_success_multi_part_doc, s_credentials_provider_x509_success_multi_part_doc);
596
597 static int s_credentials_provider_x509_real_new_destroy(struct aws_allocator *allocator, void *ctx) {
598 (void)ctx;
599
600 aws_auth_library_init(allocator);
601
602 struct aws_logger_standard_options logger_options = {
603 .level = AWS_LOG_LEVEL_TRACE,
604 .file = stderr,
605 };
606
607 struct aws_logger logger;
608 ASSERT_SUCCESS(aws_logger_init_standard(&logger, allocator, &logger_options));
609 aws_logger_set(&logger);
610
611 s_aws_x509_tester_init(allocator);
612
613 struct aws_event_loop_group *el_group = aws_event_loop_group_new_default(allocator, 1, NULL);
614
615 struct aws_host_resolver_default_options resolver_options = {
616 .el_group = el_group,
617 .max_entries = 8,
618 };
619 struct aws_host_resolver *resolver = aws_host_resolver_new_default(allocator, &resolver_options);
620
621 struct aws_client_bootstrap_options bootstrap_options = {
622 .event_loop_group = el_group,
623 .host_resolver = resolver,
624 };
625 struct aws_client_bootstrap *bootstrap = aws_client_bootstrap_new(allocator, &bootstrap_options);
626
627 struct aws_credentials_provider_x509_options options = {
628 .bootstrap = bootstrap,
629 .shutdown_options =
630 {
631 .shutdown_callback = s_on_shutdown_complete,
632 .shutdown_user_data = NULL,
633 },
634 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
635 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
636 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
637 .tls_connection_options = &s_tester.tls_connection_options,
638 };
639
640 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
641
642 aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);
643
644 s_aws_wait_for_credentials_result();
645
646 aws_credentials_provider_release(provider);
647
648 s_aws_wait_for_provider_shutdown_callback();
649
650 aws_client_bootstrap_release(bootstrap);
651 aws_host_resolver_release(resolver);
652 aws_event_loop_group_release(el_group);
653
654 s_aws_x509_tester_cleanup();
655
656 aws_auth_library_clean_up();
657
658 aws_logger_set(NULL);
659 aws_logger_clean_up(&logger);
660
661 return 0;
662 }
663
664 AWS_TEST_CASE(credentials_provider_x509_real_new_destroy, s_credentials_provider_x509_real_new_destroy);
665
666 static int s_credentials_provider_x509_proxy_routing_enabled_test(struct aws_allocator *allocator, void *ctx) {
667 (void)ctx;
668
669 s_aws_x509_tester_init(allocator);
670
671 struct proxy_env_var_settings proxy_config = {
672 .env_var_type = AWS_HPEV_ENABLE,
673 };
674
675 s_tester.proxy_config = &proxy_config;
676
677 struct aws_credentials_provider_x509_options options = {
678 .bootstrap = NULL,
679 .function_table = &s_mock_function_table,
680 .shutdown_options =
681 {
682 .shutdown_callback = s_on_shutdown_complete,
683 .shutdown_user_data = NULL,
684 },
685 .endpoint = aws_byte_cursor_from_c_str("c2sakl5huz0afv.credentials.iot.us-east-1.amazonaws.com"),
686 .thing_name = aws_byte_cursor_from_c_str("my_iot_thing_name"),
687 .role_alias = aws_byte_cursor_from_c_str("my_test_role_alias"),
688 .tls_connection_options = &s_tester.tls_connection_options,
689 .proxy_ev_settings = &proxy_config,
690 };
691
692 struct aws_credentials_provider *provider = aws_credentials_provider_new_x509(allocator, &options);
693
694 aws_credentials_provider_get_credentials(provider, s_get_credentials_callback, NULL);
695
696 s_aws_wait_for_credentials_result();
697
698 ASSERT_TRUE(s_tester.credentials == NULL);
699
700 aws_credentials_provider_release(provider);
701
702 s_aws_wait_for_provider_shutdown_callback();
703
704 aws_mem_release(provider->allocator, provider);
705
706 s_aws_x509_tester_cleanup();
707
708 return 0;
709 }
710 AWS_TEST_CASE(
711 credentials_provider_x509_proxy_routing_enabled_test,
712 s_credentials_provider_x509_proxy_routing_enabled_test);