|
10 | 10 | #include "s3_tester.h"
|
11 | 11 | #include <aws/common/atomics.h>
|
12 | 12 | #include <aws/common/clock.h>
|
| 13 | +#include <aws/common/encoding.h> |
13 | 14 | #include <aws/common/lru_cache.h>
|
14 | 15 | #include <aws/io/stream.h>
|
15 | 16 | #include <aws/io/uri.h>
|
@@ -714,3 +715,53 @@ TEST_CASE(s3express_client_copy_object_multipart) {
|
714 | 715 | aws_s3_tester_clean_up(&tester);
|
715 | 716 | return AWS_OP_SUCCESS;
|
716 | 717 | }
|
| 718 | + |
| 719 | +/** |
| 720 | + * Test hash of the express cache key |
| 721 | + */ |
| 722 | +TEST_CASE(s3express_hash_key_test) { |
| 723 | + (void)ctx; |
| 724 | + |
| 725 | + struct aws_string *access_key = aws_string_new_from_c_str(allocator, "AccessKey"); |
| 726 | + struct aws_string *secret_access_key = aws_string_new_from_c_str(allocator, "SecretAccessKey"); |
| 727 | + struct aws_http_headers *headers = aws_http_headers_new(allocator); |
| 728 | + aws_http_headers_add( |
| 729 | + headers, aws_byte_cursor_from_c_str("x-amz-server-side-encryption"), aws_byte_cursor_from_c_str("aws:kms")); |
| 730 | + aws_http_headers_add( |
| 731 | + headers, |
| 732 | + aws_byte_cursor_from_c_str("x-amz-server-side-encryption-aws-kms-key-id"), |
| 733 | + aws_byte_cursor_from_c_str("kms-key-id")); |
| 734 | + aws_http_headers_add( |
| 735 | + headers, |
| 736 | + aws_byte_cursor_from_c_str("x-amz-server-side-encryption-context"), |
| 737 | + aws_byte_cursor_from_c_str("context")); |
| 738 | + aws_http_headers_add( |
| 739 | + headers, |
| 740 | + aws_byte_cursor_from_c_str("x-amz-server-side-encryption-bucket-key-enabled"), |
| 741 | + aws_byte_cursor_from_c_str("true")); |
| 742 | + aws_http_headers_add( |
| 743 | + headers, aws_byte_cursor_from_c_str("header-not-allowed"), aws_byte_cursor_from_c_str("should-be-ignored")); |
| 744 | + |
| 745 | + struct aws_credentials *creds = |
| 746 | + aws_credentials_new_from_string(allocator, access_key, secret_access_key, NULL, UINT64_MAX); |
| 747 | + |
| 748 | + struct aws_string *hash_key = |
| 749 | + aws_encode_s3express_hash_key_new(allocator, creds, aws_byte_cursor_from_c_str("host"), headers); |
| 750 | + struct aws_byte_cursor hash_cursor = aws_byte_cursor_from_string(hash_key); |
| 751 | + |
| 752 | + struct aws_byte_buf encoded_buf; |
| 753 | + aws_byte_buf_init(&encoded_buf, allocator, 100); |
| 754 | + aws_hex_encode_append_dynamic(&hash_cursor, &encoded_buf); |
| 755 | + |
| 756 | + char *expected_encoded_key = "686f737498ae6a365790707488b3e85402c9eddf422dc39f096e15eaba0d7cdd45f57ad2"; |
| 757 | + ASSERT_BIN_ARRAYS_EQUALS(expected_encoded_key, strlen(expected_encoded_key), encoded_buf.buffer, encoded_buf.len); |
| 758 | + |
| 759 | + aws_byte_buf_clean_up(&encoded_buf); |
| 760 | + aws_string_destroy(access_key); |
| 761 | + aws_string_destroy(secret_access_key); |
| 762 | + aws_credentials_release(creds); |
| 763 | + aws_string_destroy(hash_key); |
| 764 | + aws_http_headers_release(headers); |
| 765 | + |
| 766 | + return 0; |
| 767 | +} |
0 commit comments