8
8
#include < aws/core/client/ClientConfiguration.h>
9
9
#include < aws/core/client/CoreErrors.h>
10
10
#include < aws/core/client/RetryStrategy.h>
11
+ #include < aws/core/client/DefaultRetryStrategy.h>
11
12
#include < aws/core/http/HttpClientFactory.h>
12
13
#include < aws/core/http/HttpClient.h>
13
14
#include < aws/core/utils/crypto/Cipher.h>
42
43
#include < aws/testing/ProxyConfig.h>
43
44
#include < aws/testing/platform/PlatformTesting.h>
44
45
#include < aws/testing/TestingEnvironment.h>
46
+ #include < aws/testing/mocks/monitoring/TestingMonitoring.h>
45
47
#include < fstream>
46
48
47
49
#ifdef _WIN32
@@ -76,6 +78,7 @@ namespace
76
78
static std::string BASE_EVENT_STREAM_LARGE_FILE_TEST_BUCKET_NAME = " largeeventstream" ;
77
79
static std::string BASE_EVENT_STREAM_ERRORS_IN_EVENT_TEST_BUCKET_NAME = " errorsinevent" ;
78
80
static std::string BASE_CROSS_REGION_BUCKET_NAME = " crossregion" ;
81
+ static std::string BASE_ENDPOINT_OVERRIDE_BUCKET_NAME = " endpointoverride" ;
79
82
static const char * ALLOCATION_TAG = " BucketAndObjectOperationTest" ;
80
83
static const char * TEST_OBJ_KEY = " TestObjectKey" ;
81
84
static const char * TEST_NOT_MODIFIED_OBJ_KEY = " TestNotModifiedObjectKey" ;
@@ -86,6 +89,7 @@ namespace
86
89
// to get around this, this string is url encoded version of "TestUnicode中国Key". At test time, we'll convert it to the unicode string
87
90
static const char * URLENCODED_UNICODE_KEY = " TestUnicode%E4%B8%AD%E5%9B%BDKey" ;
88
91
static const char * URIESCAPE_KEY = " Esc ape+Me$" ;
92
+ static const char * CUSTOM_ENDPOINT_OVERRIDE = " beta.example.com" ;
89
93
90
94
static const int TIMEOUT_MAX = 20 ;
91
95
@@ -113,6 +117,7 @@ namespace
113
117
AppendUUID (BASE_EVENT_STREAM_LARGE_FILE_TEST_BUCKET_NAME);
114
118
AppendUUID (BASE_EVENT_STREAM_ERRORS_IN_EVENT_TEST_BUCKET_NAME);
115
119
AppendUUID (BASE_CROSS_REGION_BUCKET_NAME);
120
+ AppendUUID (BASE_ENDPOINT_OVERRIDE_BUCKET_NAME);
116
121
}
117
122
118
123
class RetryFiveTimesRetryStrategy : public Aws ::Client::RetryStrategy
@@ -176,10 +181,13 @@ namespace
176
181
retryClient = Aws::MakeShared<S3Client>(ALLOCATION_TAG,
177
182
Aws::MakeShared<DefaultAWSCredentialsProviderChain>(ALLOCATION_TAG), config,
178
183
AWSAuthV4Signer::PayloadSigningPolicy::Never /* signPayloads*/ , true /* useVirtualAddressing*/ );
184
+ // Using client side monitoring for endpoint override testing.
185
+ TestingMonitoringManager::InitTestingMonitoring ();
179
186
}
180
187
181
188
static void TearDownTestCase ()
182
189
{
190
+ TestingMonitoringManager::CleanupTestingMonitoring ();
183
191
DeleteBucket (CalculateBucketName (BASE_CREATE_BUCKET_TEST_NAME.c_str ()));
184
192
DeleteBucket (CalculateBucketName (BASE_DNS_UNFRIENDLY_TEST_NAME.c_str ()));
185
193
DeleteBucket (CalculateBucketName (BASE_LOCATION_BUCKET_TEST_NAME.c_str ()));
@@ -1701,6 +1709,115 @@ namespace
1701
1709
ASSERT_TRUE (deleteBucketOutcome.IsSuccess ());
1702
1710
}
1703
1711
1712
+ TEST_F (BucketAndObjectOperationTest, TestCustomEndpointOverride)
1713
+ {
1714
+ // Access Point ARN without dualstack
1715
+ ASSERT_STREQ (" myendpoint-123456789012.beta.example.com" ,
1716
+ S3Endpoint::ForAccessPointArn (S3ARN (" arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint" ), " " , false /* useDualStack */ , " beta.example.com" ).c_str ());
1717
+ // Outpost Access Point ARN without dualstack
1718
+ ASSERT_STREQ (" myaccesspoint-123456789012.op-01234567890123456.beta.example.com" ,
1719
+ S3Endpoint::ForOutpostsArn (S3ARN (" arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint" ), " " ,
1720
+ false /* useDualStack */ , " beta.example.com" ).c_str ());
1721
+
1722
+ Aws::String fullBucketName = CalculateBucketName (BASE_ENDPOINT_OVERRIDE_BUCKET_NAME.c_str ());
1723
+ Aws::StringStream ss;
1724
+
1725
+ // Traditional bucket name with virtual addressing
1726
+ ClientConfiguration config;
1727
+ config.region = Aws::Region::US_WEST_2;
1728
+ config.endpointOverride = CUSTOM_ENDPOINT_OVERRIDE;
1729
+ config.retryStrategy = Aws::MakeShared<Aws::Client::DefaultRetryStrategy>(ALLOCATION_TAG, 0 /* don't retry */ , 25 );
1730
+ S3Client s3ClientWithVirtualAddressing (config, AWSAuthV4Signer::PayloadSigningPolicy::Never, true /* useVirtualAddressing*/ );
1731
+
1732
+ ListObjectsRequest listObjectsRequest;
1733
+ listObjectsRequest.SetBucket (fullBucketName);
1734
+ auto listObjectsOutcome = s3ClientWithVirtualAddressing.ListObjects (listObjectsRequest);
1735
+ ASSERT_FALSE (listObjectsOutcome.IsSuccess ());
1736
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listObjectsOutcome.GetError ().GetResponseCode ());
1737
+ ss << " https://" << fullBucketName << " ." << CUSTOM_ENDPOINT_OVERRIDE;
1738
+ ASSERT_STREQ (ss.str ().c_str (), TestingMonitoringMetrics::s_lastUriString.c_str ());
1739
+ ASSERT_STREQ (" s3" , TestingMonitoringMetrics::s_lastSigningServiceName.c_str ());
1740
+
1741
+ // Access Point Arn with virtual addressing
1742
+ listObjectsRequest.SetBucket (" arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint" );
1743
+ listObjectsOutcome = s3ClientWithVirtualAddressing.ListObjects (listObjectsRequest);
1744
+ ASSERT_FALSE (listObjectsOutcome.IsSuccess ());
1745
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listObjectsOutcome.GetError ().GetResponseCode ());
1746
+ ss.str (" " );
1747
+ ss << " https://myendpoint-123456789012." << CUSTOM_ENDPOINT_OVERRIDE;
1748
+ ASSERT_STREQ (ss.str ().c_str (), TestingMonitoringMetrics::s_lastUriString.c_str ());
1749
+ ASSERT_STREQ (" s3" , TestingMonitoringMetrics::s_lastSigningServiceName.c_str ());
1750
+
1751
+ // Outposts Access Point Arn with virtual addressing
1752
+ listObjectsRequest.SetBucket (" arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint" );
1753
+ listObjectsOutcome = s3ClientWithVirtualAddressing.ListObjects (listObjectsRequest);
1754
+ ASSERT_FALSE (listObjectsOutcome.IsSuccess ());
1755
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listObjectsOutcome.GetError ().GetResponseCode ());
1756
+ ss.str (" " );
1757
+ ss << " https://myaccesspoint-123456789012.op-01234567890123456." << CUSTOM_ENDPOINT_OVERRIDE;
1758
+ ASSERT_STREQ (ss.str ().c_str (), TestingMonitoringMetrics::s_lastUriString.c_str ());
1759
+ ASSERT_STREQ (" s3-outposts" , TestingMonitoringMetrics::s_lastSigningServiceName.c_str ());
1760
+
1761
+ // ListBuckets
1762
+ auto listBucketsOutcome = s3ClientWithVirtualAddressing.ListBuckets ();
1763
+ ASSERT_FALSE (listBucketsOutcome.IsSuccess ());
1764
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listBucketsOutcome.GetError ().GetResponseCode ());
1765
+ ss.str (" " );
1766
+ ss << " https://" << CUSTOM_ENDPOINT_OVERRIDE;
1767
+ ASSERT_STREQ (ss.str ().c_str (), TestingMonitoringMetrics::s_lastUriString.c_str ());
1768
+ ASSERT_STREQ (" s3" , TestingMonitoringMetrics::s_lastSigningServiceName.c_str ());
1769
+
1770
+ // Tradition bucket name with path addressing
1771
+ S3Client s3ClientWithPathAddressing (config, AWSAuthV4Signer::PayloadSigningPolicy::Never, false /* useVirtualAddressing*/ );
1772
+ listObjectsRequest.SetBucket (fullBucketName);
1773
+ listObjectsOutcome = s3ClientWithPathAddressing.ListObjects (listObjectsRequest);
1774
+ ASSERT_FALSE (listObjectsOutcome.IsSuccess ());
1775
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listObjectsOutcome.GetError ().GetResponseCode ());
1776
+ ss.str (" " );
1777
+ ss << " https://" << CUSTOM_ENDPOINT_OVERRIDE << " /" << fullBucketName;
1778
+ ASSERT_STREQ (ss.str ().c_str (), TestingMonitoringMetrics::s_lastUriString.c_str ());
1779
+ ASSERT_STREQ (" s3" , TestingMonitoringMetrics::s_lastSigningServiceName.c_str ());
1780
+
1781
+ // Use arn region, Access Point Arn with virtual addressing
1782
+ Aws::String awsS3UseArnRegion = Aws::Environment::GetEnv (" AWS_S3_USE_ARN_REGION" );
1783
+ Aws::Environment::SetEnv (" AWS_S3_USE_ARN_REGION" , " true" , 1 );
1784
+ config.region = Aws::Region::EU_WEST_1;
1785
+ S3Client s3ClientInEuWest1 (config, AWSAuthV4Signer::PayloadSigningPolicy::Never, true /* useVirtualAddressing*/ );
1786
+ if (awsS3UseArnRegion.empty ())
1787
+ {
1788
+ Aws::Environment::UnSetEnv (" AWS_S3_USE_ARN_REGION" );
1789
+ }
1790
+ else
1791
+ {
1792
+ Aws::Environment::SetEnv (" AWS_S3_USE_ARN_REGION" , awsS3UseArnRegion.c_str (), 1 );
1793
+ }
1794
+ listObjectsRequest.SetBucket (" arn:aws:s3:us-west-2:123456789012:accesspoint:myendpoint" );
1795
+ listObjectsOutcome = s3ClientInEuWest1.ListObjects (listObjectsRequest);
1796
+ ASSERT_FALSE (listObjectsOutcome.IsSuccess ());
1797
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listObjectsOutcome.GetError ().GetResponseCode ());
1798
+ ss.str (" " );
1799
+ ss << " https://myendpoint-123456789012." << CUSTOM_ENDPOINT_OVERRIDE;
1800
+ ASSERT_STREQ (ss.str ().c_str (), TestingMonitoringMetrics::s_lastUriString.c_str ());
1801
+ ASSERT_STREQ (" s3" , TestingMonitoringMetrics::s_lastSigningServiceName.c_str ());
1802
+ ASSERT_STREQ (" us-west-2" , TestingMonitoringMetrics::s_lastSigningRegion.c_str ());
1803
+
1804
+ // Failure case, dualstack endpoint is not compatible with custom endpoint override.
1805
+ config.region = Aws::Region::US_WEST_2;
1806
+ config.useDualStack = true ;
1807
+ S3Client s3ClientWithDualStack (config, AWSAuthV4Signer::PayloadSigningPolicy::Never, true /* useVirtualAddressing*/ );
1808
+ listObjectsRequest.SetBucket (fullBucketName);
1809
+ listObjectsOutcome = s3ClientWithDualStack.ListObjects (listObjectsRequest);
1810
+ ASSERT_FALSE (listObjectsOutcome.IsSuccess ());
1811
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listObjectsOutcome.GetError ().GetResponseCode ());
1812
+ ASSERT_EQ (S3Errors::VALIDATION, listObjectsOutcome.GetError ().GetErrorType ());
1813
+
1814
+ listObjectsRequest.SetBucket (" arn:aws:s3-outposts:us-west-2:123456789012:outpost:op-01234567890123456:accesspoint:myaccesspoint" );
1815
+ listObjectsOutcome = s3ClientWithDualStack.ListObjects (listObjectsRequest);
1816
+ ASSERT_FALSE (listObjectsOutcome.IsSuccess ());
1817
+ ASSERT_EQ (HttpResponseCode::REQUEST_NOT_MADE, listObjectsOutcome.GetError ().GetResponseCode ());
1818
+ ASSERT_EQ (S3Errors::VALIDATION, listObjectsOutcome.GetError ().GetErrorType ());
1819
+ }
1820
+
1704
1821
TEST_F (BucketAndObjectOperationTest, TestS3AccessPointARNValidation)
1705
1822
{
1706
1823
// The followings are examples for valid S3 ARN:
@@ -1837,5 +1954,4 @@ namespace
1837
1954
ASSERT_STREQ (" access-point-name-123456789120.outpost-id.s3-outposts.cn-north-1.amazonaws.com.cn" ,
1838
1955
S3Endpoint::ForOutpostsArn (S3ARN (" arn:aws-cn:s3-outposts:cn-north-1:123456789120:outpost:outpost-id:accesspoint:access-point-name" ), " " ).c_str ());
1839
1956
}
1840
-
1841
1957
}
0 commit comments